From d8b6105f36dbd69404ecdbf8cb99fe7f568ad404 Mon Sep 17 00:00:00 2001 From: Victor Cornille Date: Sun, 8 Sep 2024 20:53:03 +0200 Subject: [PATCH] + | syscall triggers GPF --- drivers/Makefile | 11 +++++++++-- drivers/syscall/syscall.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/syscall/syscall.h | 9 +++++++++ kernel/kernel.c | 5 +++++ kernel/kernel.h | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 drivers/syscall/syscall.c create mode 100644 drivers/syscall/syscall.h diff --git a/drivers/Makefile b/drivers/Makefile index 0460b25..a7040f9 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -6,6 +6,9 @@ VGA_OBJ = vga/vga.o PIT_SRC = pit/pit.c PIT_OBJ = pit/pit.o +SYS_SRC = syscall/syscall.c +SYS_OBJ = syscall/syscall.o + DES_SRC = descriptor/idt.c descriptor/irq.c descriptor/isr.c descriptor/interrupt_handlers.s descriptor/gdt.c DES_OBJ = descriptor/idt.o descriptor/irq.o descriptor/isr.o descriptor/interrupt_handlers.o descriptor/gdt.o @@ -21,12 +24,15 @@ FLAGS = -ffreestanding \ all: $(DRIVERS) -$(DRIVERS): $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) - $(AR) $@ $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) +$(DRIVERS): $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) $(SYS_OBJ) + $(AR) $@ $(VGA_OBJ) $(DES_OBJ) $(KEY_OBJ) $(PIT_OBJ) $(SYS_OBJ) $(VGA_OBJ): $(VGA_SRC) $(CC) $(FLAGS) -c $^ -o $@ +$(SYS_OBJ): $(SYS_SRC) + $(CC) $(FLAGS) -c $^ -o $@ + $(PIT_OBJ): $(PIT_SRC) $(CC) $(FLAGS) -c $^ -o $@ @@ -41,6 +47,7 @@ keyboard/%.o: keyboard/%.c clean: rm -rf $(VGA_OBJ) + rm -rf $(SYS_OBJ) rm -rf $(DES_OBJ) rm -rf $(KEY_OBJ) rm -rf $(PIT_OBJ) diff --git a/drivers/syscall/syscall.c b/drivers/syscall/syscall.c new file mode 100644 index 0000000..cee05b1 --- /dev/null +++ b/drivers/syscall/syscall.c @@ -0,0 +1,38 @@ +#include "syscall.h" + +void sys_read(registers_t* r) { + printf("Syscall read : eax == %d\n", r->eax); +} + +void sys_write(registers_t* r) { + printf("Syscall write: eax == %d\n", r->eax); +} + +void sys_open(registers_t* r) { + printf("Syscall open : eax == %d\n", r->eax); +} + +void sys_close(registers_t* r) { + printf("Syscall close: eax == %d\n", r->eax); +} + +void sys_stat(registers_t* r) { + printf("Syscall stat : eax == %d\n", r->eax); +} + +isr_t syscall_tab[] = { + sys_read, + sys_write, + sys_open, + sys_close, + sys_stat + // Write all handlers here based on Linux system call table +}; + +void syscall_callback(registers_t* r) { + syscall_tab[r->eax](r); +} + +void init_syscall() { + register_interrupt_handler(SYSCALL_INTERRUPT_NUMBER, &syscall_callback); +} diff --git a/drivers/syscall/syscall.h b/drivers/syscall/syscall.h new file mode 100644 index 0000000..8414fd1 --- /dev/null +++ b/drivers/syscall/syscall.h @@ -0,0 +1,9 @@ +#ifndef SYSCALL_H +# define SYSCALL_H + +#include "../descriptor/descriptor.h" + +# define SYSCALL_INTERRUPT_NUMBER 0x80 +void init_syscall(); + +#endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 7680c37..b65bcc0 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -37,6 +37,11 @@ void kernel_main(uint32_t magic, uint32_t addr) { isr_install(); init_keyboard(); init_timer(50); + init_syscall(); + asm volatile( + "mov $1, %eax\n" + "int $80" + ); pmm_init(mem_size, bitmap); for (size_t i = 0; i < 15; i++) { diff --git a/kernel/kernel.h b/kernel/kernel.h index 3957071..3dd41d0 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -7,6 +7,7 @@ #include "../drivers/descriptor/descriptor.h" #include "../drivers/keyboard/keyboard.h" #include "../drivers/pit/pit.h" +#include "../drivers/syscall/syscall.h" #include "../multiboot/multiboot.h" #include "../memory/pmm/pmm.h" #include "../memory/vmm/vmm.h"