aa64: finalise context switch, page fault handler and syscall
[lunaix-os.git] / lunaix-os / arch / aarch64 / exception / syscall.c
1 #include <lunaix/syscall.h>
2 #include <lunaix/status.h>
3
4 #include <asm/hart.h>
5 #include "asm/aa64_exception.h"
6
7 extern ptr_t syscall_table[__SYSCALL_MAX];
8
9 void
10 aa64_syscall(struct hart_state* hstate)
11 {
12     unsigned int call_id;
13
14     call_id = esr_iss(hstate->execp.syndrome);
15     call_id = call_id & 0xffff;
16
17     if (call_id >= __SYSCALL_MAX) {
18         return EINVAL;
19     }
20
21     if (!syscall_table[call_id]) {
22         return EINVAL;
23     }
24
25     register reg_t param0 asm("x0") = hstate->registers.x[0];
26     register reg_t param1 asm("x1") = hstate->registers.x[1];
27     register reg_t param2 asm("x2") = hstate->registers.x[2];
28     register reg_t param3 asm("x3") = hstate->registers.x[3];
29     register reg_t param4 asm("x4") = hstate->registers.x[4];
30
31     asm volatile (
32         "blr %[call_fn]"
33         :
34         "=r"(param0)
35         :
36         [call_fn] "r"(syscall_table[call_id]),
37         "r"(param0),
38         "r"(param1),
39         "r"(param2),
40         "r"(param3),
41         "r"(param4)
42     );
43     
44     hstate->registers.x[0] = param0;
45 }