From 0d2ddecc9aeb232746b76b4eebdb1381053a8951 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Mon, 27 Jan 2025 02:05:07 +0000 Subject: checkpoint. we can fake syscall with the dummy gdt --- service/Makefile | 4 ++-- service/kjarna.c | 14 +++++--------- service/lib/posix.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 service/lib/posix.c (limited to 'service') diff --git a/service/Makefile b/service/Makefile index 09ff0be..b78cac3 100644 --- a/service/Makefile +++ b/service/Makefile @@ -4,7 +4,7 @@ LDFLAGS += -z max-page-size=4096 --export-dynamic -pic \ -z separate-code -pie -Bsymbolic -shared \ -z noexecstack -g -VPATH := ../lib arch/x86_64/ +VPATH := ../lib arch/x86_64/ lib TARGET := kjarna.os .DEFAULT: $(TARGET) @@ -15,7 +15,7 @@ CFLAGS += -fPIC -fvisibility=hidden -mgeneral-regs-only LDSCRIPT := kjarna.ld -CRT_OBJS := start.o rtld_link.o dynamic.o elf64.o kjarna.o +CRT_OBJS := start.o rtld_link.o dynamic.o elf64.o kjarna.o posix.o LIB_OBJS := memcmp.o memcpy.o memmove.o memset.o string.o stdio.o \ printf.o heap.o APP_OBJS := main.o diff --git a/service/kjarna.c b/service/kjarna.c index 1240c97..ce9ec54 100644 --- a/service/kjarna.c +++ b/service/kjarna.c @@ -4,19 +4,15 @@ struct kjarna_entry_params *entry_params; extern int main(int argc, char **argv); -int kjarna_entry(struct kjarna_entry_params *params) +int kjarna_entry() { - entry_params = params; - - __asm__ ("leaq kc_image_base(%%rip), %%rax" ::: "rax"); + uint64_t image_base; + __asm__ ("leaq kc_image_base(%%rip), %0" : "=r"(image_base) :: ); bool wait = true; - while(wait) - { - __asm__ volatile("hlt"); - } + while(wait); - return main(params->argc, params->argv); + return main(0, nullptr); } diff --git a/service/lib/posix.c b/service/lib/posix.c new file mode 100644 index 0000000..a912977 --- /dev/null +++ b/service/lib/posix.c @@ -0,0 +1,19 @@ +#include + +ssize_t write(int fd, const void *buffer, size_t length) +{ + ssize_t result; + + __asm__ ( + "movq %0, %%rdi\n" + "movq %1, %%rsi\n" + "movq %2, %%rdx\n" + "movq $1, %%rax\n" + "syscall" + : "=a"(result) + : "g"(fd), "g"(buffer), "g"(length) + : "rdi", "rsi","rdx"); + + return result; +} + -- cgit v1.3.1-1-g115d