2ea22d499124c94bd60e974cd5bd0ee974851d54
[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         .dc.l 0
10         .dc.l dup_proc
11         .dc.l schedule
12         .dc.l terminate_process
13         .dc.l _syscall_sbrk
14         .dc.l _syscall_brk
15
16 .global syscall_hndlr
17
18 .section .text
19     syscall_hndlr:
20         pushl %ebp
21         movl %esp, %ebp
22         addl $0x8, %ebp
23         movl (%ebp), %ebp
24
25         movl  (%ebp), %eax
26         cmpl  $__SYSCALL_MAX, %eax
27         jb 1f
28         neg   %eax
29         popl  %ebp
30         ret
31     1:
32         pushl 24(%ebp)    /* esi - #6 arg */
33         pushl 20(%ebp)    /* ebp - #5 arg */
34         pushl 16(%ebp)    /* edi - #4 arg */
35         pushl 12(%ebp)    /* edx - #3 arg */
36         pushl 8(%ebp)    /* ecx - #2 arg */
37         pushl 4(%ebp)    /* ebx - #1 arg */
38         shll $2, %eax
39         addl $syscall_table, %eax
40
41         call (%eax)
42
43         addl $24, %esp
44
45         popl %ebp
46         ret
47
48