OS Hello world
This commit is contained in:
1
os/.gitignore
vendored
Normal file
1
os/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build/
|
31
os/boot.S
Normal file
31
os/boot.S
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
.option norvc
|
||||||
|
|
||||||
|
.section .init
|
||||||
|
|
||||||
|
.equ UART_BASE, 0x10000000
|
||||||
|
|
||||||
|
.global kstart
|
||||||
|
kstart:
|
||||||
|
la a0, _str
|
||||||
|
call _println
|
||||||
|
|
||||||
|
_halt:
|
||||||
|
wfi
|
||||||
|
j _halt
|
||||||
|
|
||||||
|
_println:
|
||||||
|
li t0, UART_BASE
|
||||||
|
_println_loop:
|
||||||
|
lb t1, 0(a0)
|
||||||
|
beqz t1, _end_println_loop
|
||||||
|
sb t1, 0(t0)
|
||||||
|
addi a0, a0, 1
|
||||||
|
j _println_loop
|
||||||
|
_end_println_loop:
|
||||||
|
li t1, '\n'
|
||||||
|
sb t1, 0(t0)
|
||||||
|
ret
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
|
||||||
|
_str: .string "Hello, world!"
|
7
os/build.bat
Normal file
7
os/build.bat
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
IF NOT EXIST build mkdir build
|
||||||
|
|
||||||
|
clang --target=riscv32 -march=rv32im -nostdlib boot.S -c -o build\boot.o
|
||||||
|
|
||||||
|
ld.lld -T linker.ld build\boot.o -o build\kernel.elf
|
23
os/linker.ld
Normal file
23
os/linker.ld
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
ENTRY(kstart);
|
||||||
|
|
||||||
|
MEMORY {
|
||||||
|
ram (wxa) : ORIGIN = 0x80000000, LENGTH = 128M
|
||||||
|
}
|
||||||
|
|
||||||
|
PHDRS {
|
||||||
|
text PT_LOAD;
|
||||||
|
rodata PT_LOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
.text : ALIGN(4K) {
|
||||||
|
*(.init);
|
||||||
|
*(.text);
|
||||||
|
} >ram AT>ram :text
|
||||||
|
|
||||||
|
.rodata : ALIGN(4K) {
|
||||||
|
*(.rodata);
|
||||||
|
} >ram AT>ram :rodata
|
||||||
|
}
|
||||||
|
|
||||||
|
# @Todo .bss (clear), .data, etc
|
32
os/notes.txt
Normal file
32
os/notes.txt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
qemu-system-riscv32 -machine virt -cpu rv32 -smp 1 -m 128M -nographic -serial mon:stdio -bios none -kernel kernel.elf
|
||||||
|
|
||||||
|
qemu-system-riscv32 -machine virt -cpu rv32 -smp 1 -m 128M -bios none -kernel kernel.elf
|
||||||
|
|
||||||
|
cmd /c exit
|
||||||
|
|
||||||
|
clang --target=riscv32 -march=rv32im -nostdlib boot.S -c -o boot.o
|
||||||
|
|
||||||
|
ld.lld -T linker.ld boot.o -o kernel.elf
|
||||||
|
|
||||||
|
static const MemMapEntry virt_memmap[] = {
|
||||||
|
[VIRT_DEBUG] = { 0x0, 0x100 },
|
||||||
|
[VIRT_MROM] = { 0x1000, 0xf000 },
|
||||||
|
[VIRT_TEST] = { 0x100000, 0x1000 },
|
||||||
|
[VIRT_RTC] = { 0x101000, 0x1000 },
|
||||||
|
[VIRT_CLINT] = { 0x2000000, 0x10000 },
|
||||||
|
[VIRT_ACLINT_SSWI] = { 0x2F00000, 0x4000 },
|
||||||
|
[VIRT_PCIE_PIO] = { 0x3000000, 0x10000 },
|
||||||
|
[VIRT_PLATFORM_BUS] = { 0x4000000, 0x2000000 },
|
||||||
|
[VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) },
|
||||||
|
[VIRT_APLIC_M] = { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) },
|
||||||
|
[VIRT_APLIC_S] = { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) },
|
||||||
|
[VIRT_UART0] = { 0x10000000, 0x100 },
|
||||||
|
[VIRT_VIRTIO] = { 0x10001000, 0x1000 },
|
||||||
|
[VIRT_FW_CFG] = { 0x10100000, 0x18 },
|
||||||
|
[VIRT_FLASH] = { 0x20000000, 0x4000000 },
|
||||||
|
[VIRT_IMSIC_M] = { 0x24000000, VIRT_IMSIC_MAX_SIZE },
|
||||||
|
[VIRT_IMSIC_S] = { 0x28000000, VIRT_IMSIC_MAX_SIZE },
|
||||||
|
[VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 },
|
||||||
|
[VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 },
|
||||||
|
[VIRT_DRAM] = { 0x80000000, 0x0 },
|
||||||
|
};
|
5
os/run.bat
Normal file
5
os/run.bat
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
qemu-system-riscv32 -machine virt -cpu rv32 -smp 1 -m 128M -nographic -serial mon:stdio -bios none -kernel build\kernel.elf
|
||||||
|
|
||||||
|
cmd /c exit
|
Reference in New Issue
Block a user