feat: new syscall: sigpending, sigsuspend
[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         .long __lxsys_sigreturn
22         .long __lxsys_sigprocmask
23         .long __lxsys_signal
24         .long __lxsys_pause
25         .long __lxsys_kill          /* 15 */
26         .long __lxsys_alarm
27         .long __lxsys_sigpending
28         .long __lxsys_sigsuspend
29         2:
30         .rept __SYSCALL_MAX - (2b - 1b)/4
31             .long 0
32         .endr
33
34 .global syscall_hndlr
35
36 .section .text
37     syscall_hndlr:
38         pushl %ebp
39         movl 8(%esp), %ebp
40
41         movl  (%ebp), %eax          /* eax: call code as well as the return value from syscall */
42         cmpl  $__SYSCALL_MAX, %eax
43         jae 2f
44
45         shll $2, %eax
46         addl $syscall_table, %eax
47         cmpl $0, (%eax)
48         jne 1f
49     2:    
50         neg   %eax
51         popl  %ebp
52         ret
53     1:
54         pushl 24(%ebp)      /* esi - #6 arg */
55         pushl 20(%ebp)      /* ebp - #5 arg */
56         pushl 16(%ebp)      /* edi - #4 arg */
57         pushl 12(%ebp)      /* edx - #3 arg */
58         pushl 8(%ebp)       /* ecx - #2 arg */
59         pushl 4(%ebp)       /* ebx - #1 arg */
60         
61         call (%eax)
62
63         movl %eax, (%ebp)    /* save the return value */
64
65         addl $24, %esp      /* remove the parameters from stack */
66
67         popl %ebp
68         
69         ret