From 9cc125fb3cfdc2c8ae7153b5ae0fe705980835fb Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 6 Jan 2022 23:39:12 +0200 Subject: 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) --- arch/riscv64/conf/apos.its | 48 ++++++++++++++++++++++++++++++++++++++++ arch/riscv64/conf/boot.cmd | 4 ++++ arch/riscv64/conf/init | Bin 0 -> 968 bytes arch/riscv64/conf/init-link.S | 31 ++++++++++++++++++++++++++ arch/riscv64/conf/initrd | Bin 0 -> 1536 bytes arch/riscv64/conf/kernel-link.S | 26 ++++++++++++++++++++++ arch/riscv64/conf/mkimage.sh | 31 ++++++++++++++++++++++++++ arch/riscv64/conf/rmimage.sh | 9 ++++++++ arch/riscv64/conf/rootfs.fd | 9 ++++++++ arch/riscv64/conf/s.S | 4 ++++ 10 files changed, 162 insertions(+) create mode 100644 arch/riscv64/conf/apos.its create mode 100644 arch/riscv64/conf/boot.cmd create mode 100755 arch/riscv64/conf/init create mode 100644 arch/riscv64/conf/init-link.S create mode 100644 arch/riscv64/conf/initrd create mode 100644 arch/riscv64/conf/kernel-link.S create mode 100755 arch/riscv64/conf/mkimage.sh create mode 100755 arch/riscv64/conf/rmimage.sh create mode 100644 arch/riscv64/conf/rootfs.fd create mode 100644 arch/riscv64/conf/s.S (limited to 'arch/riscv64/conf') diff --git a/arch/riscv64/conf/apos.its b/arch/riscv64/conf/apos.its new file mode 100644 index 0000000..da48860 --- /dev/null +++ b/arch/riscv64/conf/apos.its @@ -0,0 +1,48 @@ +/dts-v1/; + +/ { + description = "FUCK"; +#address-cells = <1>; + + images { + kernel { + description = "Garbaggio"; + data = /incbin/("../../../apos.bin"); + type = "kernel"; + arch = "riscv"; + os = "apos"; + compression = "none"; + load = <0x80080000>; + entry = <0x80080000>; + hash-1 { + algo = "sha1"; + }; + }; + + initrd { + description = "Gargabbio initrd"; + data = /incbin/("initrd"); + type = "ramdisk"; + arch = "riscv"; + os = "apos"; + compression = "none"; + load = <0x88300000>; + hash-1 { + algo = "sha1"; + }; + }; + }; + + configurations { + default = "config"; + + config { + description = "Default configuration"; + kernel = "kernel"; + ramdisk = "initrd"; + hash-1 { + algo = "sha1"; + }; + }; + }; +}; diff --git a/arch/riscv64/conf/boot.cmd b/arch/riscv64/conf/boot.cmd new file mode 100644 index 0000000..a7517fd --- /dev/null +++ b/arch/riscv64/conf/boot.cmd @@ -0,0 +1,4 @@ +fdt move ${fdt_addr} ${fdt_addr_r} +fdt addr ${fdt_addr_r} +load ${devtype} ${devnum} ${kernel_addr_r} apos.itb +bootm ${kernel_addr_r} ${kernel_addr_r} ${fdt_addr_r} diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init new file mode 100755 index 0000000..f05254f Binary files /dev/null and b/arch/riscv64/conf/init differ diff --git a/arch/riscv64/conf/init-link.S b/arch/riscv64/conf/init-link.S new file mode 100644 index 0000000..baabcc6 --- /dev/null +++ b/arch/riscv64/conf/init-link.S @@ -0,0 +1,31 @@ +OUTPUT_ARCH(riscv) +ENTRY(_start) + +SECTIONS { + . = ABSOLUTE(PM_KERN_BASE); + __init_start = .; + + /* objcopy only copies these three sections (as far as I'm aware) into the + produces binary, so __init_end should point to the correct location in the + final binary + */ + .text ALIGN(4K) : AT(0) { + *(.init.start) + *(.text*); + } + + .rodata : { + *(.rodata*) + } + + .data : { + *(.data*) + } + + .bss : { + *(.sbss*) *(.bss*) *(COMMON) + } + + __init_end = . ; + __kernel_size = ; +} diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd new file mode 100644 index 0000000..90344c1 Binary files /dev/null and b/arch/riscv64/conf/initrd differ diff --git a/arch/riscv64/conf/kernel-link.S b/arch/riscv64/conf/kernel-link.S new file mode 100644 index 0000000..c6a910a --- /dev/null +++ b/arch/riscv64/conf/kernel-link.S @@ -0,0 +1,26 @@ +OUTPUT_ARCH(riscv) +ENTRY(main) + +SECTIONS { + . = ABSOLUTE(VM_KERN); + __kernel_start = .; + + .text ALIGN(4K) : AT(0) { + *(.kernel.start); + *(.text*); + } + + .rodata : { + *(.rodata*) + } + + .data : { + *(.data*) + } + + .bss : { + *(.sbss*) *(.bss*) *(COMMON) + } + + __kernel_end = .; +} diff --git a/arch/riscv64/conf/mkimage.sh b/arch/riscv64/conf/mkimage.sh new file mode 100755 index 0000000..d097248 --- /dev/null +++ b/arch/riscv64/conf/mkimage.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +if [ ! -e fs ]; then + mkdir fs +fi + +if [ ! -e rootfs.img ]; then + virt-make-fs --partition=mbr --type=vfat --size=10M fs rootfs.img +fi + + +SSIZE=$(fdisk -l rootfs.img | awk '$1=="Units:" {print $8}') +OFFSET=$(fdisk -l rootfs.img | awk '$1=="rootfs.img1" {print $2}') +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/riscv64/conf/apos.its fs/apos.itb +../u-boot-apos/tools/mkimage -A riscv -O apos -T script \ + -d arch/riscv64/conf/boot.cmd fs/boot.scr + +umount -l fs + +qemu-system-riscv64 -machine virt \ + -kernel ../u-boot-apos/u-boot \ + -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf \ + -device virtio-blk-device,drive=hd0 \ + -drive file=rootfs.img,format=raw,id=hd0 \ + -S -s -m 2G \ + -serial stdio diff --git a/arch/riscv64/conf/rmimage.sh b/arch/riscv64/conf/rmimage.sh new file mode 100755 index 0000000..8d6457f --- /dev/null +++ b/arch/riscv64/conf/rmimage.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -e fs ]; then + rm -r fs +fi + +if [ -e rootfs.img ]; then + rm rootfs.img +fi diff --git a/arch/riscv64/conf/rootfs.fd b/arch/riscv64/conf/rootfs.fd new file mode 100644 index 0000000..59fb5f8 --- /dev/null +++ b/arch/riscv64/conf/rootfs.fd @@ -0,0 +1,9 @@ +label: gpt +label-id: DBD1F99F-BFA3-D448-828F-0B505DF81F17 +device: rootfs.img +unit: sectors +first-lba: 2048 +last-lba: 20446 +sector-size: 512 + +rootfs.img1 : start= 2048, size= 18399, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B129DB0D-F225-5C48-AA6D-DD8C049FA72C diff --git a/arch/riscv64/conf/s.S b/arch/riscv64/conf/s.S new file mode 100644 index 0000000..80a3a11 --- /dev/null +++ b/arch/riscv64/conf/s.S @@ -0,0 +1,4 @@ +.text +.global _start +_start: +ecall -- cgit v1.3