-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.s
More file actions
38 lines (30 loc) · 1.23 KB
/
boot.s
File metadata and controls
38 lines (30 loc) · 1.23 KB
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
# Target architecture: RISC-V 64-bit with General and Compressed extensions.
.attribute arch, "rv64gc"
# We place this code in a special section defined in our linker script
# to ensure it sits at the very beginning of the executable.
.section .text.init
# Disable compressed instructions for the boot sequence to ensure
# predictable instruction alignment.
.option norvc
.global _start
_start:
# --- Multicore Management ---
# Read the 'mhartid' (Machine Hart ID) Control and Status Register.
# Each CPU core (hart) has a unique ID, starting from 0.
csrr t0, mhartid
# If the ID is not 0, send the core to the 'park' loop.
# We only want the primary core to perform system initialization.
bnez t0, park
# --- Stack Setup ---
# Load the address of '_stack_top' into the Stack Pointer (sp).
# This symbol is defined at the end of our linker script.
la sp, _stack_top
# --- Transfer to Rust ---
# Jump to the 'kmain' function in our Rust code.
# Since 'kmain' never returns, we don't use 'call' (which would save a return address).
j kmain
park:
# Core parking loop: Wait For Interrupt (wfi) to save power,
# then jump back to itself if it ever wakes up.
wfi
j park