Fix file system racing and ext2 directory insertion (#58)
[lunaix-os.git] / lunaix-os / arch / x86 / syscall64.S
1 #define __ASM__
2 #include <lunaix/syscall.h>
3 #include "asm/variants/interrupt64.S.inc"
4
5 .section .text
6     .type syscall_hndlr, @function
7     .global syscall_hndlr
8     syscall_hndlr:
9         pushq   %rbp
10         movq    %rsp, %rbp
11         pushq   %rbx
12         
13         movq    %rdi, %rbx          // struct hart_state*
14
15         movq    irax(%rbx), %rax          /* rax: call code as well as the return value from syscall */
16         cmpq    $__SYSCALL_MAX, %rax
17         jae     2f
18
19         shlq    $3, %rax               // %rax * 8
20         movabsq $__syscall_table, %r8
21         addq    %r8, %rax
22         cmpq    $0, (%rax)
23         jne     1f
24     2:    
25         negq    %rax
26         popq    %rbx
27         movq    %rbp, %rsp
28         popq    %rbp
29
30         ret
31
32     1:
33         movq    (%rax),     %rdi
34         movq    irbx(%rbx), %rsi    /* rbx -> rsi #1 arg */
35         movq    ircx(%rbx), %rdx    /* rcx -> rdx #2 arg */
36         movq    irdx(%rbx), %rcx    /* rdx -> rcx #3 arg */
37         movq    irdi(%rbx), %r8     /* rdi -> r8  #4 arg */
38         movq    irsi(%rbx), %r9     /* rsi -> r9  #5 arg */
39         
40         call    dispatch_syscall
41         
42         movq    %rax, irax(%rbx)    /* save the return value */
43         
44         popq    %rbx
45         movq    %rbp,  %rsp
46         popq    %rbp
47         
48         ret