summaryrefslogtreecommitdiff
path: root/sys/kern/entry.S
blob: 9bf72ea39c6c106681c95fa047503dbb87c0e92c (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
.section ".text.init"

// entrypoint for boot hart(s). a0: hartid, a1: *fdt
.globl _start


// entrypoint for other harts. a0: hartid, a1: unused for now
.global _mpentry 

_start: 
        /* disable interrupts and paging */ 
        csrw       satp, zero
        csrw       sie, zero
        csrw       sip, zero

        .option push
        .option norelax
        la         gp, __global_pointer$
        .option pop

        /* setup stack. 
	 * stack grows toward lower address so sp will mark end of frame.
	 */
        addi       t0, a0, 1
        li         t1, PAGE_SIZE 
        la         sp, __stack_start
        mul        t1, t1, t0
        add        sp, sp, t1

        /* setup thread pointer */ 
        mv        tp, a0

        /* the label _boot_hart is shared between threads. after the first atomic swap, all other harts will branch to mpentry */ 
        li         a2, 1
        lla        a3, _boot_hart
        amoswap.w  a3, a2, (a3)
        bnez       a3, _mpentry

        /* clear the bss section */  
        la         a2, __bss_start
        la         a3, __bss_end
1:
        sd	   zero, (a2)
        addi       a2, a2, __SIZEOF_POINTER__
        blt        a2, a3, 1b 
2:
        call       init
        j          _spin

_mpentry:
	/* satp = 0, sstatus.sie = 0, a0 = hartid, a1 = opaque	*/

	call	 mpinit
	/* shouldn't reach this point */
	j 	_spin

_spin:
	wfi
	j 	_spin

.section ".data"
_boot_hart: 
        .word 0

.section ".rodata"
/* linker imports */
.globl HEAP_START
HEAP_START: .dword __heap_start