Skip to content

Commit de91ee2

Browse files
Merge pull request #307 from rust-embedded/rvrt-asm
`riscv-rt`: copy hart ID to `a0` in M-mode
2 parents d19af19 + 5396943 commit de91ee2

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
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: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ _abs_start:
6464
csrw sip, 0",
6565
#[cfg(not(feature = "s-mode"))]
6666
"csrw mie, 0
67-
csrw mip, 0",
67+
csrw mip, 0
68+
csrr a0, mhartid", // Make sure that the hart ID is in a0 in M-mode
6869
// Set pre-init trap vector
6970
"la t0, _pre_init_trap",
7071
#[cfg(feature = "s-mode")]
@@ -89,11 +90,8 @@ cfg_global_asm!(
8990
);
9091
#[cfg(not(feature = "single-hart"))]
9192
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)
93+
"mv t2, a0
94+
lui t0, %hi(_max_hart_id)
9795
add t0, t0, %lo(_max_hart_id)
9896
bgtu t2, t0, abort
9997
lui t0, %hi(_hart_stack_size)
@@ -131,18 +129,12 @@ cfg_global_asm!(
131129
sd a2, 8 * 2(sp)",
132130
);
133131

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

0 commit comments

Comments
 (0)