Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
syscall.asm
Go to the documentation of this file.
1%macro pushall 0
2 push rax
3 push rbx
4 push rcx
5 push rdx
6 push rsi
7 push rdi
8 push rbp
9 push r8
10 push r9
11 push r10
12 push r11
13 push r12
14 push r13
15 push r14
16 push r15
17%endmacro
18
19%macro popall 0
20 pop r15
21 pop r14
22 pop r13
23 pop r12
24 pop r11
25 pop r10
26 pop r9
27 pop r8
28 pop rbp
29 pop rdi
30 pop rsi
31 pop rdx
32 pop rcx
33 pop rbx
34 pop rax
35%endmacro
36
37global syscall_entry
38extern syscall_dispatch
39
40syscall_entry:
41 swapgs
42 mov [gs:0x18], rsp
43 mov rsp, [gs:0x10]
44
45 ; IRET frame
46 push qword 0x43 ; SS
47 push qword [gs:0x18] ; RSP
48 push r11 ; RFLAGS
49 push qword 0x4B ; CS
50 push rcx ; RIP
51
52 push qword 0 ; err_code
53 push qword 0x80 ; int_no (Syscall)
54
55 pushall
56
57 mov rdi, rsp
58 call syscall_dispatch
59
60 popall
61
62 add rsp, 16 ; int_no, err_code
63
64 mov rcx, [rsp] ; RIP
65 mov r11, [rsp + 16] ; RFLAGS
66
67 cli
68 cmp qword [gs:0x20], 1
69 je .to_user
70
71 swapgs
72 iretq
73
74.to_user:
75 mov rsp, [rsp + 24] ; user RSP — must be last before sysretq
76 swapgs
77 o64 sysret
78