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