fix typos, some refinements
[lunaix-os.git] / lunaix-os / arch / x86 / syscall32.S
1 #define __ASM__
2 #include <lunaix/syscall.h>
3 #include "syscall_nr.inc"
4
5 .section .text
6     .type syscall_hndlr, @function
7     .global syscall_hndlr
8     syscall_hndlr:
9         pushl   %ebp
10         movl    %esp, %ebp
11         movl    8(%esp), %ebx          // struct hart_state*
12
13         addl    $4, %ebx
14         movl    (%ebx), %eax          /* eax: call code as well as the return value from syscall */
15         cmpl    $__SYSCALL_MAX, %eax
16         jae     2f
17
18         shll    $2, %eax
19         addl    $syscall_table, %eax
20         cmpl    $0, (%eax)
21         jne     1f
22     2:    
23         neg     %eax
24         movl    %ebp, %esp
25         popl    %ebp
26         ret
27
28     1:
29         pushl   %ebx
30         pushl   24(%ebx)      /* esi - #5 arg */
31         pushl   16(%ebx)      /* edi - #4 arg */
32         pushl   12(%ebx)      /* edx - #3 arg */
33         pushl   8(%ebx)       /* ecx - #2 arg */
34         pushl   4(%ebx)       /* ebx - #1 arg */
35         pushl    (%eax)
36         
37         call    dispatch_syscall
38
39         addl    $24, %esp      /* remove the parameters from stack */
40         
41         popl    %ebx
42         movl    %eax, (%ebx)    /* save the return value */
43         
44         movl    %ebp, %esp
45         popl    %ebp
46         
47         ret