Merge branch 'master' of github.com:Minep/lunaix-os
[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         2:
26         .rept __SYSCALL_MAX - (2b - 1b)/4
27             .long 0
28         .endr
29
30 .global syscall_hndlr
31
32 .section .text
33     syscall_hndlr:
34         pushl %ebp
35         movl 8(%esp), %ebp
36
37         movl  (%ebp), %eax          /* eax: call code as well as the return value from syscall */
38         cmpl  $__SYSCALL_MAX, %eax
39         jae 2f
40
41         shll $2, %eax
42         addl $syscall_table, %eax
43         cmpl $0, (%eax)
44         jne 1f
45     2:    
46         neg   %eax
47         popl  %ebp
48         ret
49     1:
50         pushl 24(%ebp)      /* esi - #6 arg */
51         pushl 20(%ebp)      /* ebp - #5 arg */
52         pushl 16(%ebp)      /* edi - #4 arg */
53         pushl 12(%ebp)      /* edx - #3 arg */
54         pushl 8(%ebp)       /* ecx - #2 arg */
55         pushl 4(%ebp)       /* ebx - #1 arg */
56         
57         call (%eax)
58
59         movl %eax, (%ebp)    /* save the return value */
60
61         addl $24, %esp      /* remove the parameters from stack */
62
63         popl %ebp
64         
65         ret