Implemented a basic syscall handler

This commit is contained in:
2025-05-07 13:25:18 +02:00
parent d6035dff80
commit 024dcfffcc
11 changed files with 110 additions and 42 deletions
+9 -34
View File
@@ -1,5 +1,6 @@
#include <bootloader.h>
#include <kmalloc.h>
#include <syscall.h>
#include <kernel.h>
#include <paging.h>
#include <serial.h>
@@ -10,20 +11,16 @@
#include <pmm.h>
#include <tty.h>
void test(void);
__noreturn
void kmain(void* ptr, uint32_t magic) {
if (boot_init_mb1(ptr, magic) != 0) panic("Unsupported bootloader.");
// Serial console for debugging
if (serial_init(COM1) != 0) panic("Failed to initialize Serial driver.");
debugf("\x1b[H\x1b[J\x1b[0mkern. \x1b[36m(serial console)\x1b[0m\n\n");
// Load structures from bootloader
if (boot_init_mb1(ptr, magic) != 0) panic("Unsupported bootloader.");
// System init
if (gdt_init() != 0) panic("Failed to initalize GDT.");
debugf("[gdt] Segment selectors: NULL: 0x%04x, KCODE: 0x%04x, KDATA: 0x%04x, UCODE: 0x%04x, UDATA: 0x%04x, TSS: 0x%04x\n",
GDT_NULL, GDT_KERNEL_CODE, GDT_KERNEL_DATA, GDT_USER_CODE, GDT_USER_DATA, GDT_TSS);
if (isr_init() != 0) panic("Failed to initalize ISRs.");
if (pag_init() != 0) panic("Failed to initalize Paging.");
@@ -36,38 +33,16 @@ void kmain(void* ptr, uint32_t magic) {
tty_puts("kern.\n\n");
if (timer_init() != 0) panic("Failed to initialize timer.");
if (syscall_init() != 0) panic("Failed to initialize syscalls.");
if (task_init() != 0) panic("Failed to initialize tasking.");
// Create a temporary test task
task_create(task_create_id(), (uint32_t)test, 1, pag_get_pagedir(), 0, NULL);
char* s = "Hello, World!";
__asm__ volatile("int $0x80" :: "a"(SYS_TEST), "b"(s));
size_t delay = 0;
while (1) {
delay++;
if (delay < 0x1FFFFFF) continue;
delay = 0;
tty_puts("[kernel] Hello!\n");
}
// TODO: Syscalls
// TODO: Interprocess communication
// TODO: Load & run /sbin/init
panic("kmain() reached end.");
}
// An imaginary second task
void test(void) {
size_t delay = 0;
while (1) {
delay++;
if (delay < 0x2FFFFFF) continue;
delay = 0;
tty_puts("[test] Hello!\n");
}
// We don't want to halt
while (1);
}