From dbffb7f5fa23e97434bef27935eedb59e22cb5a3 Mon Sep 17 00:00:00 2001 From: xamidev Date: Thu, 2 Apr 2026 19:11:37 +0200 Subject: [PATCH] userland HELLO WORLD --- src/arch/x86/syscall.c | 46 +++++++++++++++++++++++++++++++++++++----- user/hello.S | 14 ++++++++++++- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/arch/x86/syscall.c b/src/arch/x86/syscall.c index 544c2a6..8adb178 100644 --- a/src/arch/x86/syscall.c +++ b/src/arch/x86/syscall.c @@ -4,21 +4,57 @@ * @license GPL-3.0-only */ +#include "sched/scheduler.h" #include #include +#include +#include +void sys_write(unsigned int fd, const char* buf, size_t count) +{ + switch (fd) { + case 1: //stdout + for (size_t i=0; i - CPU state after system call + */ struct cpu_status* syscall_handler(struct cpu_status* regs) { - DEBUG("Syscall %lx with argument %lx", regs->rdi, regs->rsi); + DEBUG("Syscall %lx with (arg0=%lx arg1=%lx)", regs->rax, regs->rdi, regs->rsi); - switch (regs->rdi) + switch (regs->rax) { - case 0: + case 0: //sys_read break; - case 1: + case 1: //sys_write + sys_write(regs->rdi, (char*)regs->rsi, regs->rdx); break; default: - regs->rsi = 0xdeadbeef; + regs->rax = 0xbad515ca11; break; } diff --git a/user/hello.S b/user/hello.S index 2520195..d3e94f7 100644 --- a/user/hello.S +++ b/user/hello.S @@ -1,4 +1,16 @@ bits 64 +section .data + hi db "hi from userland :) we did it man", 0 + +section .text + hello: - mov rax, 0xcafebabe \ No newline at end of file + mov rax, 0x1 ;sys_write + mov rdi, 0x1 ;stdout + lea rsi, [rel hi] ;char* buf + mov rdx, 33 ;count + int 0x80 + +.loop: + jmp .loop \ No newline at end of file