diff options
| -rw-r--r-- | api/libc/stdio.h | 18 | ||||
| -rw-r--r-- | api/posix/fcntl.h | 4 | ||||
| -rw-r--r-- | api/posix/sys/types.h | 1 | ||||
| -rw-r--r-- | api/posix/unistd.h | 5 | ||||
| -rwxr-xr-x | debug.sh | 11 | ||||
| -rw-r--r-- | kjarna/efi/start.c | 2 | ||||
| -rw-r--r-- | kjarna_runtime/Makefile | 4 | ||||
| -rw-r--r-- | kjarna_runtime/kjarna.c | 13 | ||||
| -rw-r--r-- | kjarna_runtime/main.c | 14 |
9 files changed, 49 insertions, 23 deletions
diff --git a/api/libc/stdio.h b/api/libc/stdio.h new file mode 100644 index 0000000..1edec4a --- /dev/null +++ b/api/libc/stdio.h @@ -0,0 +1,18 @@ +#pragma once + +#include <libc/string.h> + +#include <stdarg.h> + +typedef struct FILE FILE; + +extern FILE *stdout; +extern FILE *stderr; + +extern int fputc(int c, FILE *f); + +int vfprintf(FILE *f, const char *restrict format, va_list arguments); +int fprintf(FILE *f, const char *restrict format, ...); +int vprintf(const char *restrict format, va_list arguments); +int printf(const char *restrict format, ...); + diff --git a/api/posix/fcntl.h b/api/posix/fcntl.h index 7e55e02..8a6ee7a 100644 --- a/api/posix/fcntl.h +++ b/api/posix/fcntl.h @@ -1,4 +1,8 @@ #pragma once +#include "sys/types.h" + #define O_RDONLY 0 +int open(const char *path, int flags, mode_t mode); + diff --git a/api/posix/sys/types.h b/api/posix/sys/types.h index 2be0ef8..81a5f13 100644 --- a/api/posix/sys/types.h +++ b/api/posix/sys/types.h @@ -4,4 +4,5 @@ typedef int64_t ssize_t; typedef int64_t off_t; +typedef int mode_t; diff --git a/api/posix/unistd.h b/api/posix/unistd.h index e440a4a..7487001 100644 --- a/api/posix/unistd.h +++ b/api/posix/unistd.h @@ -1,5 +1,8 @@ #pragma once +#include <stddef.h> +#include "sys/types.h" + #define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 @@ -11,3 +14,5 @@ enum seek_whence SEEK_END }; +ssize_t write(int fd, const void *buf, size_t length); + @@ -1,17 +1,16 @@ #!/usr/bin/env bash -make -C kc/core && -make -C kc/boot && -make -C loader && +make -C kjarna_runtime && +make -C kjarna && BOOT_DIR=EFI/BOOT BOOT_FILE=BOOTX64.EFI SYS_DIR=adasoft/sophia OVMF_DIR=/usr/share/ovmf/x64 -LOADER_FILE=loader/loader.efi +LOADER_FILE=kjarna/kjarna.efi +SHIM_FILE=kjarna_runtime/kjarna.os -SHIM_FILE=kc/boot/efi.os KERNEL_FILE=kc/core/kernel.os tempdir=$(mktemp -d) && @@ -21,7 +20,7 @@ cp ${OVMF_DIR}/OVMF_VARS.fd ${tempdir} && mkdir -p ${rundir}/${BOOT_DIR} ${rundir}/${SYS_DIR} && cp ${LOADER_FILE} ${rundir}/${BOOT_DIR}/${BOOT_FILE} && -cp ${SHIM_FILE} ${KERNEL_FILE} ${rundir}/${SYS_DIR} && +cp ${LOADER_FILE} ${SHIM_FILE} ${rundir}/${SYS_DIR} && qemu-system-x86_64 -d int \ -drive if=pflash,format=raw,unit=0,file=/usr/share/ovmf/x64/OVMF_CODE.fd,readonly=on \ diff --git a/kjarna/efi/start.c b/kjarna/efi/start.c index ebeb67d..1c15c2c 100644 --- a/kjarna/efi/start.c +++ b/kjarna/efi/start.c @@ -19,8 +19,6 @@ EFI_STATUS _start(EFI_HANDLE handle, EFI_SYSTEM_TABLE *system_table) struct efi_context app_context = { handle, system_table }; efi_context = &app_context; - efi_write(1, "hello, efi world!\r\n", -1); - if (main(0, nullptr) != 0) { efi_errno = EFI_ABORTED; diff --git a/kjarna_runtime/Makefile b/kjarna_runtime/Makefile index be3cd90..caffc79 100644 --- a/kjarna_runtime/Makefile +++ b/kjarna_runtime/Makefile @@ -9,14 +9,14 @@ VPATH := ../lib TARGET := kjarna.os .DEFAULT: $(TARGET) -CPPFLAGS += -I../api -I. +CPPFLAGS += -I../api/posix -I../api/libc -I../api -I. CFLAGS += -fPIC -fvisibility=hidden -mgeneral-regs-only LDSCRIPT := kc.ld CRT_OBJS := start_x86_64.o dynamic_x86_64.o elf64.o -LIB_OBJS := memcmp.o memcpy.o memmove.o memset.o string.o +LIB_OBJS := kjarna.o memcmp.o memcpy.o memmove.o memset.o string.o APP_OBJS := main.o OBJS := $(CRT_OBJS) $(LIB_OBJS) $(APP_OBJS) diff --git a/kjarna_runtime/kjarna.c b/kjarna_runtime/kjarna.c new file mode 100644 index 0000000..6b37d1e --- /dev/null +++ b/kjarna_runtime/kjarna.c @@ -0,0 +1,13 @@ +#include <kjarna/interface.h> + +struct kjarna_entry_params *entry_params; + +extern int main(int argc, char **argv); + +int kjarna_entry(struct kjarna_entry_params *params) +{ + entry_params = params; + + return main(params->argc, params->argv); +} + diff --git a/kjarna_runtime/main.c b/kjarna_runtime/main.c index acfcdc1..248958b 100644 --- a/kjarna_runtime/main.c +++ b/kjarna_runtime/main.c @@ -1,6 +1,4 @@ -#include <kjarna/interface.h> - -extern int write(int, void *, size_t); +#include <unistd.h> int main(int argc, char **argv) { @@ -14,13 +12,3 @@ int main(int argc, char **argv) return 0; } -struct kjarna_entry_params *entry_params; - -int kjarna_entry(struct kjarna_entry_params *params) -{ - entry_params = params; - entry_params->interface->write(1, "hello, entry world\r\n", -1); - - return main(params->argc, params->argv); -} - |
