proc_quit () and proc_test () syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 43s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 43s
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
_start:
|
||||
pushq $123
|
||||
addq $8, %rsp
|
||||
|
||||
movq $2, %rax
|
||||
syscall
|
||||
|
||||
movq $1, %rax
|
||||
syscall
|
||||
|
||||
jmp _start
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
#define PACKED __attribute__ ((packed))
|
||||
#define ALIGNED(N) __attribute__ ((aligned ((N))))
|
||||
#define SECTION(name) __attribute__ ((section (name)))
|
||||
#define UNUSED __attribute__ ((unused))
|
||||
|
||||
#endif // _KERNEL_AUX_COMPILER_H
|
||||
|
||||
@@ -7,3 +7,4 @@ include uACPI/src.mk
|
||||
include irq/src.mk
|
||||
include rd/src.mk
|
||||
include proc/src.mk
|
||||
include syscall/src.mk
|
||||
|
||||
1
kernel/syscall/.gitignore
vendored
Normal file
1
kernel/syscall/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.o
|
||||
10
kernel/syscall/defs.h
Normal file
10
kernel/syscall/defs.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _KERNEL_SYSCALL_DEFS_H
|
||||
#define _KERNEL_SYSCALL_DEFS_H
|
||||
|
||||
#define SYS_PROC_QUIT 1
|
||||
#define SYS_PROC_TEST 2
|
||||
|
||||
#define SR_OK 0
|
||||
#define SR_SYSCALL_NOT_FOUND 1
|
||||
|
||||
#endif // _KERNEL_SYSCALL_DEFS_H
|
||||
3
kernel/syscall/src.mk
Normal file
3
kernel/syscall/src.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
c += syscall/syscall.c
|
||||
|
||||
o += syscall/syscall.o
|
||||
34
kernel/syscall/syscall.c
Normal file
34
kernel/syscall/syscall.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <aux/compiler.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sys/debug.h>
|
||||
#include <syscall/defs.h>
|
||||
#include <syscall/syscall.h>
|
||||
|
||||
#define DEFINE_SYSCALL(name) \
|
||||
int name (struct proc* proc, uintptr_t UNUSED a1, uintptr_t UNUSED a2, uintptr_t UNUSED a3, \
|
||||
uintptr_t UNUSED a4, uintptr_t UNUSED a5, uintptr_t UNUSED a6)
|
||||
|
||||
DEFINE_SYSCALL (sys_proc_quit) {
|
||||
proc_kill (proc);
|
||||
proc_sched ();
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
DEFINE_SYSCALL (sys_proc_test) {
|
||||
DEBUG ("test syscall message!\n");
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_PROC_QUIT] = &sys_proc_quit,
|
||||
[SYS_PROC_TEST] = &sys_proc_test,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
if (!(syscall_num >= 0 && syscall_num < (sizeof (handler_table) / sizeof (handler_table[0])))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return handler_table[syscall_num];
|
||||
}
|
||||
12
kernel/syscall/syscall.h
Normal file
12
kernel/syscall/syscall.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_SYSCALL_SYSCALL_H
|
||||
#define _KERNEL_SYSCALL_SYSCALL_H
|
||||
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
|
||||
typedef int (*syscall_handler_func_t) (struct proc* proc, uintptr_t a1, uintptr_t a2, uintptr_t a3,
|
||||
uintptr_t a4, uintptr_t a5, uintptr_t a6);
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num);
|
||||
|
||||
#endif // _KERNEL_SYSCALL_SYSCALL_H
|
||||
Reference in New Issue
Block a user