Kernel address space isolation and make the kernel heap global to all processes.
[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         .dc.l 0
11         .dc.l dup_proc
12         .dc.l schedule
13         .dc.l terminate_process
14         .dc.l _syscall_sbrk
15         .dc.l _syscall_brk
16         2:
17         .rept __SYSCALL_MAX - (2b - 1b)/4
18             .dc.l 0
19         .endr
20
21 .global syscall_hndlr
22
23 .section .text
24     syscall_hndlr:
25         pushl %ebp
26         movl %esp, %ebp
27         addl $0x8, %ebp
28         movl (%ebp), %ebp
29
30         movl  (%ebp), %eax
31         cmpl  $__SYSCALL_MAX, %eax
32         jae 2f
33
34         shll $2, %eax
35         addl $syscall_table, %eax
36         cmpl $0, (%eax)
37         jne 1f
38     2:    
39         neg   %eax
40         popl  %ebp
41         ret
42     1:
43         pushl 24(%ebp)    /* esi - #6 arg */
44         pushl 20(%ebp)    /* ebp - #5 arg */
45         pushl 16(%ebp)    /* edi - #4 arg */
46         pushl 12(%ebp)    /* edx - #3 arg */
47         pushl 8(%ebp)    /* ecx - #2 arg */
48         pushl 4(%ebp)    /* ebx - #1 arg */
49         
50         call (%eax)
51
52         addl $24, %esp
53
54         popl %ebp
55         
56         ret
57
58