From d855c0a219a180497c2e50f9bc19bfce69b937a6 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Thu, 23 Jan 2025 00:24:57 +0000 Subject: it printfs with the efi interface --- service/Makefile | 2 +- service/arch/x86_64/rtld_link.S | 2 ++ service/config.h | 6 ++++++ service/kjarna.c | 9 +++++++++ service/main.c | 39 ++++++++++++++++++++++++++++++++++++--- 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 service/config.h (limited to 'service') diff --git a/service/Makefile b/service/Makefile index 0917b8c..09ff0be 100644 --- a/service/Makefile +++ b/service/Makefile @@ -17,7 +17,7 @@ LDSCRIPT := kjarna.ld CRT_OBJS := start.o rtld_link.o dynamic.o elf64.o kjarna.o LIB_OBJS := memcmp.o memcpy.o memmove.o memset.o string.o stdio.o \ - printf.o + printf.o heap.o APP_OBJS := main.o OBJS := $(CRT_OBJS) $(LIB_OBJS) $(APP_OBJS) diff --git a/service/arch/x86_64/rtld_link.S b/service/arch/x86_64/rtld_link.S index 7300a18..9f86030 100644 --- a/service/arch/x86_64/rtld_link.S +++ b/service/arch/x86_64/rtld_link.S @@ -2,6 +2,8 @@ .extern kc_dynamic_link +// TODO: investigate whether saving r9, r8, rcx and rdx is actually necessary here + .hidden _rtld_link .global _rtld_link .type _rtld_link, @function diff --git a/service/config.h b/service/config.h new file mode 100644 index 0000000..18aa6f8 --- /dev/null +++ b/service/config.h @@ -0,0 +1,6 @@ +#pragma once + +#define KJARNA_REVISION 2 + +const char * const HAL_PATH = "/system/kernel.os"; + diff --git a/service/kjarna.c b/service/kjarna.c index 6b37d1e..1240c97 100644 --- a/service/kjarna.c +++ b/service/kjarna.c @@ -8,6 +8,15 @@ int kjarna_entry(struct kjarna_entry_params *params) { entry_params = params; + __asm__ ("leaq kc_image_base(%%rip), %%rax" ::: "rax"); + + bool wait = true; + + while(wait) + { + __asm__ volatile("hlt"); + } + return main(params->argc, params->argv); } diff --git a/service/main.c b/service/main.c index 12a5522..c022b87 100644 --- a/service/main.c +++ b/service/main.c @@ -1,7 +1,42 @@ #include #include +#include +#include -#define KJARNA_REVISION 1 +#include "config.h" +#include + +/* +static int open_kernel(void) +{ + int kernel_fd = open(HAL_PATH, 0, 0); + + printf("kernel path: %s\n", HAL_PATH); + + if (kernel_fd < 0) + { + printf("error: could not open kernel core\n"); + return -1; + } + + Elf64_Ehdr ehdr; + + if (!elf64_validate_fd(kernel_fd, ET_DYN, EM_X86_64)) + { + printf("error: could not validate elf header\n"); + close(kernel_fd); + return -1; + } + + printf("kernel: elf x86_64 dynamic object found\r\n"); + + ssize_t kernel_size = elf64_size_fd(fd); + + printf("kernel image size %zd\n", kernel_size); + + return kernel_fd; +} +*/ int main(int argc, char **argv) { @@ -10,8 +45,6 @@ int main(int argc, char **argv) printf("kjarna %d\n", KJARNA_REVISION); - while (1); - return 0; } -- cgit v1.3.1-1-g115d