diff options
| author | Ada Christine <adachristine18@gmail.com> | 2025-01-27 02:05:07 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2025-01-27 02:05:07 +0000 |
| commit | 0d2ddecc9aeb232746b76b4eebdb1381053a8951 (patch) | |
| tree | 31fe2fc38ead88a0d982b06b3783aae4f094b8ad /service | |
| parent | 6faeb8d3aed797ddfac66ecc21fc8a717d5e848a (diff) | |
checkpoint. we can fake syscall with the dummy gdt
Diffstat (limited to 'service')
| -rw-r--r-- | service/Makefile | 4 | ||||
| -rw-r--r-- | service/kjarna.c | 14 | ||||
| -rw-r--r-- | service/lib/posix.c | 19 |
3 files changed, 26 insertions, 11 deletions
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 <unistd.h> + +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; +} + |
