feat: The waitpid family!
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / syscall.S
1 #define __ASM__
2 #include <lunaix/syscall.h>
3
4 .section .data
5     /*
6         注意,这里的顺序非常重要。每个系统调用在这个地址表里的索引等于其调用号。
7     */
8     syscall_table:
9         1:
10         .long 0
11         .long __lxsys_fork          /* 1 */
12         .long __lxsys_yield
13         .long __lxsys_sbrk
14         .long __lxsys_brk
15         .long __lxsys_getpid        /* 5 */
16         .long __lxsys_getppid
17         .long __lxsys_sleep
18         .long __lxsys_exit
19         .long __lxsys_wait          
20         .long __lxsys_waitpid       /* 10 */
21         2:
22         .rept __SYSCALL_MAX - (2b - 1b)/4
23             .long 0
24         .endr
25
26 .global syscall_hndlr
27
28 .section .text
29     syscall_hndlr:
30         pushl %ebp
31         movl 8(%esp), %ebp
32
33         movl  (%ebp), %eax          /* eax: call code as well as the return value from syscall */
34         cmpl  $__SYSCALL_MAX, %eax
35         jae 2f
36
37         shll $2, %eax
38         addl $syscall_table, %eax
39         cmpl $0, (%eax)
40         jne 1f
41     2:    
42         neg   %eax
43         popl  %ebp
44         ret
45     1:
46         pushl 24(%ebp)      /* esi - #6 arg */
47         pushl 20(%ebp)      /* ebp - #5 arg */
48         pushl 16(%ebp)      /* edi - #4 arg */
49         pushl 12(%ebp)      /* edx - #3 arg */
50         pushl 8(%ebp)       /* ecx - #2 arg */
51         pushl 4(%ebp)       /* ebx - #1 arg */
52         
53         call (%eax)
54
55         movl %eax, (%ebp)    /* save the return value */
56
57         addl $24, %esp      /* remove the parameters from stack */
58
59         popl %ebp
60         
61         ret
62
63