Skip to content

Commit ecf9ebd

Browse files
committed
Copy hart ID to a0 in M-mode
1 parent d19af19 commit ecf9ebd

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
all code to RAM and keep .init in flash/ROM.
1414
- By default, the stack is now split into equal parts based on the number of
1515
harts.
16+
- In M-mode, the hart ID is moved to `a0` at the beginning of the runtime.
1617

1718
### Fixed
1819

riscv-rt/src/asm.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ _abs_start:
7171
"csrw stvec, t0",
7272
#[cfg(not(feature = "s-mode"))]
7373
"csrw mtvec, t0",
74+
// Make sure that a0 contains the hart ID also in M-mode
75+
#[cfg(not(feature = "s-mode"))]
76+
"csrr a0, mhartid",
7477
);
7578

7679
// ZERO OUT GENERAL-PURPOSE REGISTERS
@@ -89,11 +92,8 @@ cfg_global_asm!(
8992
);
9093
#[cfg(not(feature = "single-hart"))]
9194
cfg_global_asm!(
92-
#[cfg(feature = "s-mode")]
93-
"mv t2, a0 // the hartid is passed as parameter by SMODE",
94-
#[cfg(not(feature = "s-mode"))]
95-
"csrr t2, mhartid",
96-
"lui t0, %hi(_max_hart_id)
95+
"mv t2, a0
96+
lui t0, %hi(_max_hart_id)
9797
add t0, t0, %lo(_max_hart_id)
9898
bgtu t2, t0, abort
9999
lui t0, %hi(_hart_stack_size)
@@ -131,18 +131,12 @@ cfg_global_asm!(
131131
sd a2, 8 * 2(sp)",
132132
);
133133

134-
// SKIP RAM INITIALIZATION IF CURRENT HART IS NOT THE BOOT HART
135-
#[cfg(not(feature = "single-hart"))]
134+
// CALL __pre_init (IF ENABLED) AND INITIALIZE RAM
136135
cfg_global_asm!(
137-
#[cfg(not(feature = "s-mode"))]
138-
"csrr a0, mhartid",
136+
#[cfg(not(feature = "single-hart"))]
137+
// Skip RAM initialization if current hart is not the boot hart
139138
"call _mp_hook
140-
mv t0, a0
141-
142139
beqz a0, 4f",
143-
);
144-
// IF CURRENT HART IS THE BOOT HART CALL __pre_init (IF ENABLED) AND INITIALIZE RAM
145-
cfg_global_asm!(
146140
#[cfg(feature = "pre-init")]
147141
"call __pre_init",
148142
"// Copy .data from flash to RAM

0 commit comments

Comments
 (0)