71 lines
1.4 KiB
NASM
71 lines
1.4 KiB
NASM
; Calcite, src/kernel/syscalls.asm
|
|
; Copyright 2025 Benji Dial
|
|
;
|
|
; This program is free software: you can redistribute it and/or modify
|
|
; it under the terms of the GNU General Public License as published by
|
|
; the Free Software Foundation, either version 3 of the License, or
|
|
; (at your option) any later version.
|
|
;
|
|
; This program is distributed in the hope that it will be useful, but
|
|
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
; for more details.
|
|
;
|
|
; You should have received a copy of the GNU General Public License along
|
|
; with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
bits 64
|
|
|
|
extern syscall_entry_c
|
|
|
|
section .bss
|
|
|
|
;this should have guard pages blah blah blah
|
|
resb 16 << 20
|
|
syscall_stack_top:
|
|
|
|
section .text
|
|
|
|
;system call number is in rax.
|
|
;system call arguments are in rdi, rsi, rdx.
|
|
;system call returns a value in rax.
|
|
syscall_entry:
|
|
mov qword [syscall_stack_top - 8], rsp
|
|
mov rsp, syscall_stack_top - 8
|
|
push r11
|
|
push rcx
|
|
|
|
mov rcx, rax
|
|
call syscall_entry_c
|
|
|
|
pop rcx
|
|
pop r11
|
|
pop rsp
|
|
o64 sysret
|
|
|
|
global init_syscalls
|
|
init_syscalls:
|
|
|
|
mov ecx, 0xc0000080
|
|
rdmsr
|
|
or al, 0x01
|
|
wrmsr
|
|
|
|
mov edx, 0x00130028
|
|
xor eax, eax
|
|
mov ecx, 0xc0000081
|
|
wrmsr
|
|
|
|
mov rdx, syscall_entry
|
|
mov eax, edx
|
|
shr rdx, 32
|
|
mov ecx, 0xc0000082
|
|
wrmsr
|
|
|
|
xor edx, edx
|
|
xor eax, eax
|
|
mov ecx, 0xc0000084
|
|
wrmsr
|
|
|
|
ret
|