From 9f20e71740cac40b0ff0e1a2edc0944e7eff1505 Mon Sep 17 00:00:00 2001 From: nub31 Date: Thu, 26 Jun 2025 13:59:02 +0200 Subject: [PATCH] ... --- src/runtime/.gitignore | 3 ++- src/runtime/makefile | 16 +++++++++++++--- src/runtime/platform/{x86_64.s => x64.s} | 7 +++++-- src/runtime/{ => runtime}/runtime.c | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) rename src/runtime/platform/{x86_64.s => x64.s} (77%) rename src/runtime/{ => runtime}/runtime.c (94%) diff --git a/src/runtime/.gitignore b/src/runtime/.gitignore index 1530978..80f93b0 100644 --- a/src/runtime/.gitignore +++ b/src/runtime/.gitignore @@ -1 +1,2 @@ -*.o \ No newline at end of file +*.o +out \ No newline at end of file diff --git a/src/runtime/makefile b/src/runtime/makefile index c0aed79..5cc587b 100644 --- a/src/runtime/makefile +++ b/src/runtime/makefile @@ -1,5 +1,15 @@ -x86_64: - gcc -nostdlib -ffreestanding -c platform/x86_64.s runtime.c +CC = gcc +CFLAGS = -nostdlib -ffreestanding -Wall -Werror -Wextra + +x64: runtime.o x64.o + mkdir -p out + ar rcs out/libruntime.a runtime.o x64.o + +runtime.o: runtime/runtime.c + $(CC) $(CFLAGS) -c runtime/runtime.c -o runtime.o + +x64.o: runtime.o platform/x64.s + $(CC) $(CFLAGS) -c platform/x64.s -o x64.o clean: - rm runtime.o + rm -r out runtime.o x64.o diff --git a/src/runtime/platform/x86_64.s b/src/runtime/platform/x64.s similarity index 77% rename from src/runtime/platform/x86_64.s rename to src/runtime/platform/x64.s index 78ef7ad..e9f94b5 100644 --- a/src/runtime/platform/x86_64.s +++ b/src/runtime/platform/x64.s @@ -4,9 +4,12 @@ .globl nub_write_string # void nub_write_string(const char* str) nub_write_string: - mov rsi, rdi - mov rdi, 1 + push rdi + call nub_cstring_length + mov rdx, rax + pop rsi mov rax, 1 + mov rdi, 1 syscall .text diff --git a/src/runtime/runtime.c b/src/runtime/runtime/runtime.c similarity index 94% rename from src/runtime/runtime.c rename to src/runtime/runtime/runtime.c index a9b8729..b940f17 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime/runtime.c @@ -45,11 +45,11 @@ void nub_panic_oom() nub_exit(NUB_PANIC_ERROR_CODE); } -extern int main(); +extern uint64_t main(); __attribute__((noreturn)) void _start() { - int exit_code = main(); + uint64_t exit_code = main(); nub_exit(exit_code); __builtin_unreachable(); }