diff --git a/Kernel/Kernel.c b/Kernel/Kernel.c index 82faf73..5f70283 100644 --- a/Kernel/Kernel.c +++ b/Kernel/Kernel.c @@ -121,7 +121,6 @@ void task2(void) { return; } void task3(void) { - // Test syscall asm volatile( "mov $2, %%rax\n" // SYS_WRITE "mov $1, %%rbx\n" // stdout @@ -132,7 +131,7 @@ void task3(void) { : "r"("Syscall test!") : "rax", "rbx", "rcx", "r8" ); - + while (1) { PrintKernelAt("T3 syscall", 12, 0); for(volatile int i = 0; i < 50000; i++); diff --git a/Kernel/Syscall.c b/Kernel/Syscall.c index a0a4e53..70d887a 100644 --- a/Kernel/Syscall.c +++ b/Kernel/Syscall.c @@ -4,10 +4,13 @@ #include "Idt.h" extern void SyscallEntry(void); uint64_t SyscallHandler(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, uint64_t arg3) { + Process* current = GetCurrentProcess(); switch (syscall_num) { case SYS_EXIT: // Terminate current process - GetCurrentProcess()->state = PROC_TERMINATED; + if (current) { + current->state = PROC_TERMINATED; + } Schedule(); // Switch to next process return 0; @@ -32,7 +35,7 @@ uint64_t SyscallHandler(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, uint return 0; case SYS_GETPID: - return GetCurrentProcess()->pid; + return current ? current->pid : -1; default: return -1; @@ -41,5 +44,5 @@ uint64_t SyscallHandler(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, uint void SyscallInit(void) { // Install syscall interrupt (0x80) - IdtSetGate(0x80, (uint64_t)SyscallEntry, 0x08, 0x8E); + IdtSetGate(0x80, (uint64_t)SyscallEntry, SYSCALL_INTERRUPT_VECTOR, IDT_INTERRUPT_GATE_KERNEL); } \ No newline at end of file diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 5703153..e6a2552 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -8,7 +8,8 @@ #define SYS_WRITE 2 #define SYS_READ 3 #define SYS_GETPID 4 - +#define SYSCALL_INTERRUPT_VECTOR 0x08 +#define IDT_INTERRUPT_GATE_KERNEL 0x8E // System call handler void SyscallInit(void); uint64_t SyscallHandler(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, uint64_t arg3); diff --git a/meson.build b/meson.build index c56115c..1987608 100644 --- a/meson.build +++ b/meson.build @@ -101,5 +101,5 @@ iso = custom_target('VoidFrame.iso', # Run target run_target('run', - command : ['qemu-system-x86_64', '-cdrom', iso, '-m', '1G'] + command : ['qemu-system-x86_64', '-cdrom', 'VoidFrame.iso', '-m', '1G'] ) \ No newline at end of file