From 41208c1e15eeffdf5f92af4b0a9655e134a22516 Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Sun, 16 Jun 2024 23:39:04 +0800 Subject: [PATCH] feat: root: add dummy root server --- Makefile | 2 +- root/.gitignore | 3 +++ root/Makefile | 21 +++++++++++++++++++++ root/link.ld | 16 ++++++++++++++++ root/root.S | 19 +++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 root/.gitignore create mode 100644 root/Makefile create mode 100644 root/link.ld create mode 100644 root/root.S diff --git a/Makefile b/Makefile index 9ee62c0..78033f6 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ QEMU = qemu-system-$(ARCH) QEMU_ARGS = -nographic -serial mon:stdio -smp 1 QEMU_ARGS += -machine virt # TODO: override by $(BOARD) QEMU_ARGS += -kernel target/$(BUILD_TARGET)/$(MODE)/kernel -QEMU_ARGS += -initrd build/init.cpio +QEMU_ARGS += -initrd root/init.cpio QEMU_ARGS += -append "loglevel=4" kernel: diff --git a/root/.gitignore b/root/.gitignore new file mode 100644 index 0000000..584858d --- /dev/null +++ b/root/.gitignore @@ -0,0 +1,3 @@ +*.cpio +*.o +root diff --git a/root/Makefile b/root/Makefile new file mode 100644 index 0000000..6b89509 --- /dev/null +++ b/root/Makefile @@ -0,0 +1,21 @@ +AS = riscv64-elf-as +LD = riscv64-elf-ld + +ASFLAGS += -march=rv64imac -mabi=lp64 + +.PHONY: all clean + +all: init.cpio + +%.o: %.S + $(AS) $(ASFLAGS) -c $< -o $@ + +root: root.o + $(LD) -Tlink.ld $^ -o $@ + +init.cpio: root + find . -type f -not -name "*.cpio" | cpio -ov -H crc > init.cpio + +clean: + rm -f *.o root + rm -f init.cpio diff --git a/root/link.ld b/root/link.ld new file mode 100644 index 0000000..6827996 --- /dev/null +++ b/root/link.ld @@ -0,0 +1,16 @@ +OUTPUT_ARCH(riscv) +ENTRY(_start) + +PHDRS { + text PT_LOAD FLAGS (5); + rodata PT_LOAD FLAGS (4); + data PT_LOAD FLAGS (6); +} + +SECTIONS { + . = 0x400000; + .text : { *(.text .text.* ); . = ALIGN(4096); } : text + .rodata : { *(.rodata .rodata.*); . = ALIGN(4096); } : rodata + .data : { *(.data .data.* ); . = ALIGN(4096); } : data + .bss : { *(.bss .bss.* ); . = ALIGN(4096); } : data +} \ No newline at end of file diff --git a/root/root.S b/root/root.S new file mode 100644 index 0000000..095fa72 --- /dev/null +++ b/root/root.S @@ -0,0 +1,19 @@ +.macro syscall msg ptr + li a0, \msg + li a1, \ptr + ecall +.endm + +.text + .global _start +_start: + la t0, msg +.loop: + lb a2, 0(t0) + beqz a2, _start # print forever + syscall (1<<12 | 1), 1 # see uapi/syscall.rs + addi t0, t0, 1 + j .loop + +.data + msg : .string "Hello, world!\n\0"