summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2025-01-23 00:24:57 +0000
committerAda Christine <adachristine18@gmail.com>2025-01-23 00:24:57 +0000
commitd855c0a219a180497c2e50f9bc19bfce69b937a6 (patch)
tree1ff8523d41b222fb356fb3404d2a53c26a7d6a3d /service
parentedd52bd1464ee9ae4f0cdf7ff90a20ca175580fe (diff)
it printfs with the efi interface
Diffstat (limited to 'service')
-rw-r--r--service/Makefile2
-rw-r--r--service/arch/x86_64/rtld_link.S2
-rw-r--r--service/config.h6
-rw-r--r--service/kjarna.c9
-rw-r--r--service/main.c39
5 files changed, 54 insertions, 4 deletions
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 <unistd.h>
#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
-#define KJARNA_REVISION 1
+#include "config.h"
+#include <lib/elf.h>
+
+/*
+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;
}