diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-01-06 23:39:12 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-01-07 14:05:06 +0200 |
| commit | 9cc125fb3cfdc2c8ae7153b5ae0fe705980835fb (patch) | |
| tree | a1974f9513458acab0bd8d09758259b24b6d7d8c /arch | |
| parent | f0eba93472e0afecc57180fc0d638eeef8e6f3c6 (diff) | |
| download | kmi-9cc125fb3cfdc2c8ae7153b5ae0fe705980835fb.tar.gz kmi-9cc125fb3cfdc2c8ae7153b5ae0fe705980835fb.zip | |
Allow building with clang
+ Release mode is sort of broken, as lto doesn't work with linker
relaxation and turning the relaxation off causes issues with the jump
from init to kernel (as I've currently implemented it, could probably
be fixed with a manual jump from assembly, I'll add it to my TODO
list)
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/riscv/init/start.S | 5 | ||||
| -rw-r--r-- | arch/riscv/source.mk | 10 | ||||
| -rw-r--r-- | arch/riscv64/conf/apos.its (renamed from arch/riscv/conf/apos.its) | 0 | ||||
| -rw-r--r-- | arch/riscv64/conf/boot.cmd (renamed from arch/riscv/conf/boot.cmd) | 0 | ||||
| -rwxr-xr-x | arch/riscv64/conf/init (renamed from arch/riscv/conf/init) | bin | 968 -> 968 bytes | |||
| -rw-r--r-- | arch/riscv64/conf/init-link.S (renamed from arch/riscv/conf/init-link.S) | 2 | ||||
| -rw-r--r-- | arch/riscv64/conf/initrd (renamed from arch/riscv/conf/initrd) | bin | 1536 -> 1536 bytes | |||
| -rw-r--r-- | arch/riscv64/conf/kernel-link.S (renamed from arch/riscv/conf/kernel-link.S) | 2 | ||||
| -rwxr-xr-x | arch/riscv64/conf/mkimage.sh (renamed from arch/riscv/conf/mkimage.sh) | 4 | ||||
| -rwxr-xr-x | arch/riscv64/conf/rmimage.sh (renamed from arch/riscv/conf/rmimage.sh) | 0 | ||||
| -rw-r--r-- | arch/riscv64/conf/rootfs.fd (renamed from arch/riscv/conf/rootfs.fd) | 0 | ||||
| -rw-r--r-- | arch/riscv64/conf/s.S (renamed from arch/riscv/conf/s.S) | 0 | ||||
| -rw-r--r-- | arch/riscv64/config.h (renamed from arch/riscv/config.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/include/csr.h (renamed from arch/riscv/include/csr.h) | 8 | ||||
| -rw-r--r-- | arch/riscv64/include/lock.h (renamed from arch/riscv/include/lock.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/include/pages.h (renamed from arch/riscv/include/pages.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/include/sbi.h (renamed from arch/riscv/include/sbi.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/include/tcb.h (renamed from arch/riscv/include/tcb.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/include/vmem.h (renamed from arch/riscv/include/vmem.h) | 0 | ||||
| -rw-r--r-- | arch/riscv64/init/init.c (renamed from arch/riscv/init/init.c) | 4 | ||||
| -rw-r--r-- | arch/riscv64/init/start.S | 12 | ||||
| -rw-r--r-- | arch/riscv64/ipc.txt (renamed from arch/riscv/ipc.txt) | 0 | ||||
| -rw-r--r-- | arch/riscv64/kernel/cpu.c (renamed from arch/riscv/kernel/cpu.c) | 0 | ||||
| -rw-r--r-- | arch/riscv64/kernel/irq.c (renamed from arch/riscv/kernel/irq.c) | 0 | ||||
| -rw-r--r-- | arch/riscv64/kernel/main.c (renamed from arch/riscv/kernel/main.c) | 0 | ||||
| -rw-r--r-- | arch/riscv64/kernel/pmem.c (renamed from arch/riscv/kernel/pmem.c) | 0 | ||||
| -rw-r--r-- | arch/riscv64/kernel/proc.c (renamed from arch/riscv/kernel/proc.c) | 4 | ||||
| -rw-r--r-- | arch/riscv64/kernel/vmem.c (renamed from arch/riscv/kernel/vmem.c) | 4 | ||||
| -rw-r--r-- | arch/riscv64/mm.txt (renamed from arch/riscv/mm.txt) | 0 | ||||
| -rw-r--r-- | arch/riscv64/proc.txt (renamed from arch/riscv/proc.txt) | 0 | ||||
| -rw-r--r-- | arch/riscv64/source.mk | 17 |
31 files changed, 44 insertions, 28 deletions
diff --git a/arch/riscv/init/start.S b/arch/riscv/init/start.S deleted file mode 100644 index f9bfb92..0000000 --- a/arch/riscv/init/start.S +++ /dev/null @@ -1,5 +0,0 @@ -.section .init.start -.global _start -_start: -li sp, PM_STACK_TOP -jal init diff --git a/arch/riscv/source.mk b/arch/riscv/source.mk deleted file mode 100644 index e50880c..0000000 --- a/arch/riscv/source.mk +++ /dev/null @@ -1,10 +0,0 @@ -KERNEL_LOCAL != echo arch/riscv/kernel/*.[cS] -KERNEL_SOURCES += $(KERNEL_LOCAL) -INIT_SOURCES += arch/riscv/init/*.[cS] - -CLEANUP_CMD := ./arch/riscv/conf/rmimage.sh - -ARCH_FLAGS := -mcmodel=medany - -run: - ./arch/riscv/conf/mkimage.sh diff --git a/arch/riscv/conf/apos.its b/arch/riscv64/conf/apos.its index da48860..da48860 100644 --- a/arch/riscv/conf/apos.its +++ b/arch/riscv64/conf/apos.its diff --git a/arch/riscv/conf/boot.cmd b/arch/riscv64/conf/boot.cmd index a7517fd..a7517fd 100644 --- a/arch/riscv/conf/boot.cmd +++ b/arch/riscv64/conf/boot.cmd diff --git a/arch/riscv/conf/init b/arch/riscv64/conf/init Binary files differindex f05254f..f05254f 100755 --- a/arch/riscv/conf/init +++ b/arch/riscv64/conf/init diff --git a/arch/riscv/conf/init-link.S b/arch/riscv64/conf/init-link.S index ce53e5e..baabcc6 100644 --- a/arch/riscv/conf/init-link.S +++ b/arch/riscv64/conf/init-link.S @@ -23,7 +23,7 @@ SECTIONS { } .bss : { - *(.bss*) *(COMMON) + *(.sbss*) *(.bss*) *(COMMON) } __init_end = . ; diff --git a/arch/riscv/conf/initrd b/arch/riscv64/conf/initrd Binary files differindex 90344c1..90344c1 100644 --- a/arch/riscv/conf/initrd +++ b/arch/riscv64/conf/initrd diff --git a/arch/riscv/conf/kernel-link.S b/arch/riscv64/conf/kernel-link.S index d3b1223..c6a910a 100644 --- a/arch/riscv/conf/kernel-link.S +++ b/arch/riscv64/conf/kernel-link.S @@ -19,7 +19,7 @@ SECTIONS { } .bss : { - *(.bss*) *(COMMON) + *(.sbss*) *(.bss*) *(COMMON) } __kernel_end = .; diff --git a/arch/riscv/conf/mkimage.sh b/arch/riscv64/conf/mkimage.sh index 5a22d01..d097248 100755 --- a/arch/riscv/conf/mkimage.sh +++ b/arch/riscv64/conf/mkimage.sh @@ -16,9 +16,9 @@ mount -o loop,offset=$((${SSIZE}*${OFFSET})) rootfs.img fs # not entirely pleased with this solution, although eventually I should probably # move `run` out of the kernel repo and into some `aposos` repo with a runtime # and proper initrd etc. so this is good enough for now -../u-boot-apos/tools/mkimage -f arch/riscv/conf/apos.its fs/apos.itb +../u-boot-apos/tools/mkimage -f arch/riscv64/conf/apos.its fs/apos.itb ../u-boot-apos/tools/mkimage -A riscv -O apos -T script \ - -d arch/riscv/conf/boot.cmd fs/boot.scr + -d arch/riscv64/conf/boot.cmd fs/boot.scr umount -l fs diff --git a/arch/riscv/conf/rmimage.sh b/arch/riscv64/conf/rmimage.sh index 8d6457f..8d6457f 100755 --- a/arch/riscv/conf/rmimage.sh +++ b/arch/riscv64/conf/rmimage.sh diff --git a/arch/riscv/conf/rootfs.fd b/arch/riscv64/conf/rootfs.fd index 59fb5f8..59fb5f8 100644 --- a/arch/riscv/conf/rootfs.fd +++ b/arch/riscv64/conf/rootfs.fd diff --git a/arch/riscv/conf/s.S b/arch/riscv64/conf/s.S index 80a3a11..80a3a11 100644 --- a/arch/riscv/conf/s.S +++ b/arch/riscv64/conf/s.S diff --git a/arch/riscv/config.h b/arch/riscv64/config.h index 0ef22fa..0ef22fa 100644 --- a/arch/riscv/config.h +++ b/arch/riscv64/config.h diff --git a/arch/riscv/include/csr.h b/arch/riscv64/include/csr.h index b309f0b..52db9c1 100644 --- a/arch/riscv/include/csr.h +++ b/arch/riscv64/include/csr.h @@ -49,15 +49,15 @@ #endif #define csr_read(csr, res)\ - __asm__ ("csrr %0, " __ASM_STR(csr) : "=r" (res) : : "memory") + __asm__ volatile ("csrr %0, " __ASM_STR(csr) : "=r" (res) : : "memory") #define csr_write(csr, val)\ - __asm__ ("csrw " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") + __asm__ volatile ("csrw " __ASM_STR(csr) ", %0" : : "r" (val) : "memory") #define csr_set(csr, val)\ - __asm__ ("csrs " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") + __asm__ volatile ("csrs " __ASM_STR(csr) ", %0" : : "r" (val) : "memory") #define csr_clear(csr, val)\ - __asm__ ("csrc " __ASM_STR(csr) ", %0" : : "rK" (val) : "memory") + __asm__ volatile ("csrc " __ASM_STR(csr) ", %0" : : "r" (val) : "memory") #endif /* APOS_CSR_H */ diff --git a/arch/riscv/include/lock.h b/arch/riscv64/include/lock.h index 4f71344..4f71344 100644 --- a/arch/riscv/include/lock.h +++ b/arch/riscv64/include/lock.h diff --git a/arch/riscv/include/pages.h b/arch/riscv64/include/pages.h index 362499a..362499a 100644 --- a/arch/riscv/include/pages.h +++ b/arch/riscv64/include/pages.h diff --git a/arch/riscv/include/sbi.h b/arch/riscv64/include/sbi.h index 609849d..609849d 100644 --- a/arch/riscv/include/sbi.h +++ b/arch/riscv64/include/sbi.h diff --git a/arch/riscv/include/tcb.h b/arch/riscv64/include/tcb.h index d1e0717..d1e0717 100644 --- a/arch/riscv/include/tcb.h +++ b/arch/riscv64/include/tcb.h diff --git a/arch/riscv/include/vmem.h b/arch/riscv64/include/vmem.h index 228b24b..228b24b 100644 --- a/arch/riscv/include/vmem.h +++ b/arch/riscv64/include/vmem.h diff --git a/arch/riscv/init/init.c b/arch/riscv64/init/init.c index 23dcadd..7aecfb5 100644 --- a/arch/riscv/init/init.c +++ b/arch/riscv64/init/init.c @@ -60,11 +60,13 @@ void move_kernel() void init(void *fdt) { extern char *__init_end; + extern void jump_to_kernel(void *k, void *fdt); void (*kernel_main)(void *fdt) = (void (*)(void *))(VM_KERN); init_bootmem(); move_kernel(); __va_reg(sp); __va_reg(fp); __va_reg(gp); - kernel_main(__va(fdt)); + jump_to_kernel((void *)VM_KERN, __va(fdt)); + //kernel_main(__va(fdt)); } diff --git a/arch/riscv64/init/start.S b/arch/riscv64/init/start.S new file mode 100644 index 0000000..7842946 --- /dev/null +++ b/arch/riscv64/init/start.S @@ -0,0 +1,12 @@ +.section .init.start +.global _start +_start: +li sp, PM_STACK_TOP +call init + +.section .text +.global jump_to_kernel +jump_to_kernel: +mv a2, a0 // store kernel addr +mv a0, a1 // move fdt pointer to first argument +jr a2 // jump to kernel diff --git a/arch/riscv/ipc.txt b/arch/riscv64/ipc.txt index 21d758e..21d758e 100644 --- a/arch/riscv/ipc.txt +++ b/arch/riscv64/ipc.txt diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv64/kernel/cpu.c index 6ae4ee7..6ae4ee7 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv64/kernel/cpu.c diff --git a/arch/riscv/kernel/irq.c b/arch/riscv64/kernel/irq.c index f844dd1..f844dd1 100644 --- a/arch/riscv/kernel/irq.c +++ b/arch/riscv64/kernel/irq.c diff --git a/arch/riscv/kernel/main.c b/arch/riscv64/kernel/main.c index 9ce256e..9ce256e 100644 --- a/arch/riscv/kernel/main.c +++ b/arch/riscv64/kernel/main.c diff --git a/arch/riscv/kernel/pmem.c b/arch/riscv64/kernel/pmem.c index 45b8eeb..45b8eeb 100644 --- a/arch/riscv/kernel/pmem.c +++ b/arch/riscv64/kernel/pmem.c diff --git a/arch/riscv/kernel/proc.c b/arch/riscv64/kernel/proc.c index 6120c2d..b696912 100644 --- a/arch/riscv/kernel/proc.c +++ b/arch/riscv64/kernel/proc.c @@ -5,8 +5,8 @@ void jump_to_userspace(struct tcb *t, int argc, char **argv) { csr_write(CSR_SEPC, t->entry); - __asm__("mv sp, %0\n" : "=r" (t->proc_stack) :: "memory"); - __asm__("sret\n" ::: "memory"); + __asm__ volatile ("mv sp, %0\n" : "=r" (t->proc_stack) :: "memory"); + __asm__ volatile ("sret\n" ::: "memory"); } void return_to_userspace(struct tcb *t) diff --git a/arch/riscv/kernel/vmem.c b/arch/riscv64/kernel/vmem.c index 1f1f44a..bc1a74e 100644 --- a/arch/riscv/kernel/vmem.c +++ b/arch/riscv64/kernel/vmem.c @@ -125,12 +125,12 @@ void unmap_vmem(struct vm_branch *branch, vm_t vaddr) void flush_tlb() { - __asm__("sfence.vma %0\n" :: "rk" (cpu_id()) : "memory"); + __asm__ volatile ("sfence.vma %0\n" :: "r" (cpu_id()) : "memory"); } void flush_tlb_all() { - __asm__("sfence.vma\n" ::: "memory"); + __asm__ volatile ("sfence.vma\n" ::: "memory"); } static void start_vmem(struct vm_branch *branch, enum mm_mode m) diff --git a/arch/riscv/mm.txt b/arch/riscv64/mm.txt index e5c52cb..e5c52cb 100644 --- a/arch/riscv/mm.txt +++ b/arch/riscv64/mm.txt diff --git a/arch/riscv/proc.txt b/arch/riscv64/proc.txt index 29b2e92..29b2e92 100644 --- a/arch/riscv/proc.txt +++ b/arch/riscv64/proc.txt diff --git a/arch/riscv64/source.mk b/arch/riscv64/source.mk new file mode 100644 index 0000000..d1986d4 --- /dev/null +++ b/arch/riscv64/source.mk @@ -0,0 +1,17 @@ +KERNEL_LOCAL != echo arch/riscv64/kernel/*.[cS] +KERNEL_SOURCES += $(KERNEL_LOCAL) +INIT_SOURCES += arch/riscv64/init/*.[cS] + +CLEANUP_CMD := ./arch/riscv64/conf/rmimage.sh + +ARCH_FLAGS := -mcmodel=medany + +# 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 + +run: + ./arch/riscv64/conf/mkimage.sh |
