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