summaryrefslogtreecommitdiffhomepage
path: root/src/rv64/rv64-boot.s
blob: 1c480339f3b9496da676b52551d1689e6f699446 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# // Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
# // Distributed under the Apache Software License, Version 2.0. (See accompanying
# // file LICENSE_1_0.txt or copy at http://www.apache.org/licenses/LICENSE-2.0)
# // Official repository: https://github.com/nekernel-org/neboot


/* Code starts at 8M, everything below is memory mapped hardware. */

.option norvc

.extern cb_start_exec

.global cb_reset_vector
.global cb_hart_present

.section .init
.align 4

cb_reset_vector:
	.cfi_startproc

	csrr t0, mhartid
	beqz t0, cb_start_exec_asm

	j cb_start_other

	.cfi_endproc

cb_start_exec_asm:
	lw t0, __nb_hart_counter
	lw t1, cb_boot_processor_ready

	not t0, t0

	addi t1, zero, 1

.option push
.option norelax

	la gp, cb_global_pointer

.option pop

	la sp, cb_stack_end

	la t5, _bss_start
	la t6, _bss_end

crt0_bss_clear:
	sd zero, (t5)
	addi t5, t5, 8
	bgeu t5, t6, crt0_bss_clear


	j cb_start_exec
	j cb_hang

cb_start_other:
	lw t1, cb_boot_processor_ready

cb_start_other_wait:
	beq t1, zero, cb_start_other_wait

	la t0, cb_stack_list
	ld t1, cb_stack_align
	mv sp, t0
	add t0, zero, t1
	j cb_hang

.global cb_start_rom
.global cb_start_context

cb_start_context:
	mv ra, zero
	add ra, zero, a1
	mret

.equ NB_BOOT_ADDR, 0x80020000

cb_start_rom:
	li x5, NB_BOOT_ADDR
	mv ra, zero
	add ra, zero, t0
	mret

cb_hang:
	j cb_start_exec
L0:
	wfi
	j L0

.bss

.align 4
cb_hart_present:
	.long 0

.data

.align 4
cb_stack_list:
	.long cb_memory_end

cb_stack_align:
	.word 0x8000

__nb_max_harts:
	.word 2