diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-05 23:19:42 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-05 23:19:42 +0300 |
| commit | 5fb1af3ab12880331fb1e2150aa23b1278e60ddd (patch) | |
| tree | 3e905ee027369f01611edbc1b1a1a00e9a30dc41 | |
| parent | 9273c16434316a8ab60dc78ee65a03e68031203a (diff) | |
| download | kmi-5fb1af3ab12880331fb1e2150aa23b1278e60ddd.tar.gz kmi-5fb1af3ab12880331fb1e2150aa23b1278e60ddd.zip | |
riscv64 boots with clang (sort of)
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | TODO.txt | 3 | ||||
| -rw-r--r-- | arch/riscv64/gen/asm-offsets.c | 2 | ||||
| -rw-r--r-- | arch/riscv64/gen/source.mk | 4 | ||||
| -rw-r--r-- | arch/riscv64/source.mk | 18 | ||||
| -rw-r--r-- | common/main.c | 2 | ||||
| -rw-r--r-- | common/tcb.c | 3 | ||||
| -rw-r--r-- | common/timer.c | 9 | ||||
| -rw-r--r-- | common/uapi/dispatch.c | 2 | ||||
| -rw-r--r-- | common/uapi/proc.c | 8 | ||||
| -rw-r--r-- | common/uapi/timers.c | 5 | ||||
| -rw-r--r-- | include/apos/syscalls.h | 2 | ||||
| -rw-r--r-- | include/apos/timer.h | 2 | ||||
| -rw-r--r-- | include/apos/uapi.h | 2 |
15 files changed, 40 insertions, 26 deletions
@@ -4,5 +4,6 @@ *.elf *.ld include/apos/gen/* +include/arch/*/gen/* deps.mk *.img @@ -9,7 +9,8 @@ CFLAGS = -ffreestanding -nostdlib -std=c17 -Wall -Wextra -Wvla DEPFLAGS = -MT $@ -MMD -MP -MF $@.d LINTFLAGS = -fsyntax-only PREPROCESS = -E -LDFLAGS = -static-libgcc -lgcc +LDFLAGS != [ $(LLVM) ] \ + || echo -static-libgcc -lgcc BUILD = build ARCH_BUILD = $(BUILD)/arch/$(ARCH) @@ -66,3 +66,6 @@ cpu starts its own process manager with a timer of some sort? + More const correctness, possibly better assembly but don't count on it. + Create some gdb scripts to ease debugging, sort of annoying to have to constantly switch between physical and virtual ram ++ Save floating point registers? ++ Come up with a list of requirements for arch to be supported, from what I can +tell there has to be timers and at least two tiered memory paging. diff --git a/arch/riscv64/gen/asm-offsets.c b/arch/riscv64/gen/asm-offsets.c index d78e0ec..6920245 100644 --- a/arch/riscv64/gen/asm-offsets.c +++ b/arch/riscv64/gen/asm-offsets.c @@ -3,7 +3,7 @@ /* largely based on linux */ #define DEFINE(sym, val) \ - __asm__ volatile("\n-> " #sym " %0 " #val "\n" ::"i"(val)) + __asm__ volatile("\n#-> " #sym " %0 " #val "\n" ::"i"(val)) #define OFFSETOF(m, s) DEFINE(offsetof_##m, offsetof(s, m)) #define SIZEOF(n, s) DEFINE(sizeof_##n, sizeof(s)) diff --git a/arch/riscv64/gen/source.mk b/arch/riscv64/gen/source.mk index d291983..596255f 100644 --- a/arch/riscv64/gen/source.mk +++ b/arch/riscv64/gen/source.mk @@ -1,8 +1,8 @@ $(ARCH_SOURCE)/include/gen/asm-offsets.h: $(ARCH_SOURCE)/gen/asm-offsets.c echo "#ifndef APOS_ASM_OFFSETS_H" > $@ echo "#define APOS_ASM_OFFSETS_H" >> $@ - $(COMPILER) $(INCLUDE_FLAGS) -S $< -o - |\ - awk '($$1 == "->") { print "#define " $$2 " " $$3 }' >> $@ + $(COMPILER) $(DEPFLAGS) $(INCLUDE_FLAGS) -S $< -o - |\ + awk '($$1 == "#->") { print "#define " $$2 " " $$3 }' >> $@ echo "#endif /* APOS_ASM_OFFSETS_H */" >> $@ CLEANUP += $(ARCH_SOURCE)/include/gen/* diff --git a/arch/riscv64/source.mk b/arch/riscv64/source.mk index 8c1dfcb..fcb7f69 100644 --- a/arch/riscv64/source.mk +++ b/arch/riscv64/source.mk @@ -3,17 +3,17 @@ KERNEL_SOURCES += $(KERNEL_LOCAL) INIT_SOURCES += $(ARCH_SOURCE)/init/*.[cS] # this doesn't work for rv32, but fine for now */ -CLEANUP_CMD := $(ARCH_SOURCE)/conf/rmimage.sh - ARCH_CFLAGS := -mcmodel=medany -ARCH_LDFLAGS := +ARCH_LDFLAGS := -fuse-ld=bfd + +# slightly hacky but bfd is currently the only compiler that correctly handles +# riscv relocations, but it doesn't recognise LLVM lto files, so if we're +# doing an LLVM compilation, remove lto support +DEBUGFLAGS != [ $(LLVM) ] && echo $(DEBUGFLAGS:-flto=) || echo $(DEBUGFLAGS) -# llvm compilation doesn't seem to work, either bfd reads the object files wrong -# and outputs incorrect symbols or lld handles relocations in a dumb way. Only -# GCC compiles the kernel correctly at the moment (on RISCV, at least). I'll -# look into this later, but for now I'll just use GCC. The code does _compile_ -# with clang, it just won't link. -#LINKFLAGS := -fuse-ld=bfd +# llvm-objcopy is buggy, use gnu tools instead +# christ, not much LLVM tooling available for RISCV :D +OBJCOPY := $(CROSS_COMPILE)-objcopy run: $(ARCH_SOURCE)/conf/mkimage.sh diff --git a/common/main.c b/common/main.c index 0e33ecc..7168aeb 100644 --- a/common/main.c +++ b/common/main.c @@ -1,4 +1,5 @@ #include <apos/mem_nodes.h> +#include <apos/timer.h> #include <apos/attrs.h> #include <apos/proc.h> #include <apos/debug.h> @@ -23,5 +24,6 @@ void __main main(void *fdt) setup_io_dbg(b); init_irq(fdt); + init_timer(fdt); init_proc(fdt, b); } diff --git a/common/tcb.c b/common/tcb.c index 326d9ac..bb1bcec 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -57,7 +57,8 @@ struct tcb *new_thread() /* move tcb to top of kernel stack, keeping alignment in check * (hopefully) */ /* TODO: check alignment */ - struct tcb *t = (struct tcb *)align_down(bottom + __o_size(MM_O0) - sizeof(struct tcb), sizeof(long)); + struct tcb *t = (struct tcb *)align_down( + bottom + __o_size(MM_O0) - sizeof(struct tcb), sizeof(long)); memset(t, 0, sizeof(struct tcb)); id_t tid = __alloc_tid(t); diff --git a/common/timer.c b/common/timer.c index 2006a6c..da4fd11 100644 --- a/common/timer.c +++ b/common/timer.c @@ -130,3 +130,12 @@ ticks_t nsecs_to_ticks(tunit_t nsecs) ticks_t t = (nsecs * ticks_per_sec) / 1000000000; return t == 0 ? 1 : t; } + +/* call to this function from exception handlers */ +void update_timers() +{ + struct timer *t = newest_timer(); + remove_timer(t); + + /* TODO: handle timer thread ID */ +} diff --git a/common/uapi/dispatch.c b/common/uapi/dispatch.c index 5522c9f..92fa954 100644 --- a/common/uapi/dispatch.c +++ b/common/uapi/dispatch.c @@ -10,6 +10,7 @@ static const sys_t syscall_table[] = { [SYS_FREE_MEM] = sys_free_mem, /* timers */ + [SYS_TIMEBASE] = sys_timebase, [SYS_REQ_REL_TIMER] = sys_req_rel_timer, [SYS_REQ_ABS_TIMER] = sys_req_abs_timer, [SYS_FREE_TIMER] = sys_free_timer, @@ -24,7 +25,6 @@ static const sys_t syscall_table[] = { [SYS_EXEC] = sys_exec, [SYS_SIGNAL] = sys_signal, [SYS_SWITCH] = sys_switch, - [SYS_SYNC] = sys_sync, /* conf */ [SYS_CONF] = sys_conf, diff --git a/common/uapi/proc.c b/common/uapi/proc.c index 7c0a69d..a5ce839 100644 --- a/common/uapi/proc.c +++ b/common/uapi/proc.c @@ -34,11 +34,3 @@ SYSCALL_DEFINE1(switch)(vm_t pid) /* TODO: switch to process */ return 0; } - -SYSCALL_DEFINE2(sync)(vm_t buf, vm_t size) -{ - /* check that only the process manager can use this syscall, otherwise - * just dump process info into the buffer (I guess, not sure if this - * will be quite required */ - return 0; -} diff --git a/common/uapi/timers.c b/common/uapi/timers.c index 66f6533..5ce596f 100644 --- a/common/uapi/timers.c +++ b/common/uapi/timers.c @@ -11,6 +11,11 @@ static ticks_t scaled_ticks(vm_t ticks, vm_t repeat) #endif } +SYSCALL_DEFINE0(timebase)() +{ + return secs_to_ticks(1); +} + SYSCALL_DEFINE2(req_rel_timer)(vm_t ticks, vm_t repeat) { return new_rel_timer(cur_tcb()->tid, scaled_ticks(ticks, repeat)); diff --git a/include/apos/syscalls.h b/include/apos/syscalls.h index 6f9e312..b8553bc 100644 --- a/include/apos/syscalls.h +++ b/include/apos/syscalls.h @@ -15,6 +15,7 @@ enum { SYS_FREE_MEM, /* free memory */ /* timers */ + SYS_TIMEBASE, SYS_REQ_REL_TIMER, SYS_REQ_ABS_TIMER, SYS_FREE_TIMER, @@ -32,7 +33,6 @@ enum { SYS_EXEC, /* execute new binary in process space */ SYS_SIGNAL, /* send signal to process (kill etc.) */ SYS_SWITCH, /* switch running process */ - SYS_SYNC, /* used by init process to synchronize running processes, maybe not used */ /* kernel management */ SYS_CONF, /* config system parameters (stack size etc.) */ diff --git a/include/apos/timer.h b/include/apos/timer.h index e68009a..b506c45 100644 --- a/include/apos/timer.h +++ b/include/apos/timer.h @@ -17,7 +17,7 @@ struct timer { ticks_t ticks; }; -void init_timer(); +void init_timer(const void *fdt); /* set up timer interrupt ticks from now */ id_t new_rel_timer(id_t tid, ticks_t ticks); diff --git a/include/apos/uapi.h b/include/apos/uapi.h index a6fc2b7..b4a3c6f 100644 --- a/include/apos/uapi.h +++ b/include/apos/uapi.h @@ -71,6 +71,7 @@ SYSCALL_DECLARE(req_sharedmem); SYSCALL_DECLARE(free_mem); /* timers */ +SYSCALL_DECLARE(timebase); SYSCALL_DECLARE(req_rel_timer); SYSCALL_DECLARE(req_abs_timer); SYSCALL_DECLARE(free_timer); @@ -85,7 +86,6 @@ SYSCALL_DECLARE(fork); SYSCALL_DECLARE(exec); SYSCALL_DECLARE(signal); SYSCALL_DECLARE(switch); -SYSCALL_DECLARE(sync); /* conf */ SYSCALL_DECLARE(conf); |
