summaryrefslogtreecommitdiff
path: root/src/asm/boot.S
blob: bd50b4cbcc8891f9cd53cb1d21152201fe26fb27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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