summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/Makefile4
-rw-r--r--service/kjarna.c14
-rw-r--r--service/lib/posix.c19
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;
+}
+