proc_quit () and proc_test () syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 43s

This commit is contained in:
2026-01-03 12:21:56 +01:00
parent 124a7f7215
commit cf04e3db18
13 changed files with 130 additions and 7 deletions

View File

@@ -175,6 +175,8 @@ static void amd64_intr_exception (struct saved_regs* regs) {
void amd64_intr_handler (void* stack_ptr) {
struct saved_regs* regs = stack_ptr;
amd64_load_kernel_cr3 ();
if (regs->trap <= 31) {
amd64_intr_exception (regs);
} else {

View File

@@ -15,16 +15,31 @@
amd64_intr ## n:; \
x(n); \
cli; \
;\
push_regs; \
;\
cld; \
;\
movq %rsp, %rdi; \
;\
movq %cr3, %rax; \
pushq %rax; \
;\
movq %rsp, %rbp; \
;\
subq $8, %rsp; \
andq $~0xF, %rsp; \
;\
callq amd64_intr_handler; \
;\
movq %rbp, %rsp; \
;\
popq %rax; \
movq %rax, %cr3; \
;\
pop_regs; \
addq $16, %rsp; \
;\
iretq;

View File

@@ -9,6 +9,6 @@
void do_sched (struct proc* proc) {
thiscpu->tss.rsp0 = proc->pdata.kernel_stack;
thiscpu->syscall_kernel_stack = proc->pdata.kernel_stack;
amd64_wrmsr (MSR_GS_BASE, proc->pdata.gs_base);
amd64_wrmsr (MSR_GS_BASE, (uint64_t)proc->pdata.gs_base);
amd64_do_sched ((void*)&proc->pdata.regs, (void*)proc->pd.cr3_paddr);
}

View File

@@ -1,14 +1,37 @@
#include <amd64/gdt.h>
#include <amd64/intr.h>
#include <amd64/mm.h>
#include <amd64/msr-index.h>
#include <amd64/msr.h>
#include <proc/proc.h>
#include <sys/debug.h>
#include <sys/smp.h>
#include <syscall/defs.h>
#include <syscall/syscall.h>
extern void amd64_syscall_entry (void);
void amd64_syscall_dispatch (void* stack_ptr) {
int amd64_syscall_dispatch (void* stack_ptr) {
struct saved_regs* regs = stack_ptr;
DEBUG ("hello syscall\n");
amd64_load_kernel_cr3 ();
int syscall_num = regs->rax;
syscall_handler_func_t func = syscall_find_handler (syscall_num);
if (func == NULL)
return -SR_SYSCALL_NOT_FOUND;
struct proc* caller = thiscpu->proc_current;
__asm__ volatile ("sti");
int result = func (caller, regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8, regs->r9);
__asm__ volatile ("cli");
return 0;
/* return result; */
}
void syscall_init (void) {

View File

@@ -2,9 +2,6 @@
.extern amd64_syscall_dispatch
dupa:
jmp dupa
.global amd64_syscall_entry
amd64_syscall_entry:
cli
@@ -20,21 +17,41 @@ amd64_syscall_entry:
pushq %rcx
pushq $0
pushq $0
push_regs
swapgs
cld
movq %rsp, %rdi
movq %cr3, %rax
pushq %rax
movq %rsp, %rbp
subq $8, %rsp
andq $~0xF, %rsp
callq amd64_syscall_dispatch
movq %rbp, %rsp
popq %rax
movq %rax, %cr3
pop_regs
cli
swapgs
addq $16, %rsp
popq %rcx
addq $8, %rsp
popq %r11
addq $16, %rsp
movq %gs:0, %rsp
swapgs
sysretq