feat: root: add dummy root server

This commit is contained in:
Paul Pan 2024-06-16 23:39:04 +08:00
parent 2ec3859da7
commit 41208c1e15
5 changed files with 60 additions and 1 deletions

View File

@ -31,7 +31,7 @@ QEMU = qemu-system-$(ARCH)
QEMU_ARGS = -nographic -serial mon:stdio -smp 1 QEMU_ARGS = -nographic -serial mon:stdio -smp 1
QEMU_ARGS += -machine virt # TODO: override by $(BOARD) QEMU_ARGS += -machine virt # TODO: override by $(BOARD)
QEMU_ARGS += -kernel target/$(BUILD_TARGET)/$(MODE)/kernel 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" QEMU_ARGS += -append "loglevel=4"
kernel: kernel:

3
root/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.cpio
*.o
root

21
root/Makefile Normal file
View File

@ -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

16
root/link.ld Normal file
View File

@ -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
}

19
root/root.S Normal file
View File

@ -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"