diff options
Diffstat (limited to 'src/asm/boot.S')
| -rw-r--r-- | src/asm/boot.S | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/asm/boot.S b/src/asm/boot.S new file mode 100644 index 0000000..bd50b4c --- /dev/null +++ b/src/asm/boot.S @@ -0,0 +1,42 @@ +# bootloader for my kernel +.option norvc +.section .data +.section .text.init +.global _start +_start: + # any harts not bootstrapping need to wait for an IPI + csrr t0, mhartid + bnez t0, 3f + # satp should be zero, but make sure + csrw satp, zero +.option push +.option norelax + la gp, __global_pointer$ +.option pop + # clear bss + la a0, _bss_start + la a1, _bss_end + bgeu a0, a1, 2f +1: + sd zero, (a0) + addi a0, a0, 8 + bltu a0, a1, 1b +2: + # set up stack + la sp, _stack_end + # set kmain to the return address and then return + li t0, (0b11 << 11) | (1 << 7) | (1 << 3) + la t1, kmain + la t2, asm_trap_vector + li t3, 0 # (1 << 3) | (1 << 7) | (1 << 11) + csrw mstatus, t0 + csrw mepc, t1 + csrw mtvec, t2 + csrw mie, t3 + mret + + +# wait for interrupt +3: + wfi + j 3b |
