Skip to content

Commit 50e72b9

Browse files
Merge pull request #308 from rust-embedded/rvrt-asm
`riscv-rt`: validate hard ID earlier and allow `abort` to be located anywhere
2 parents de91ee2 + f652ef5 commit 50e72b9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12-
- Main function no longer needs to be close to _start. A linker script may copy
13-
all code to RAM and keep .init in flash/ROM.
12+
- `main` function no longer needs to be close to `_start`. A linker script may copy
13+
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.
1616
- In M-mode, the hart ID is moved to `a0` at the beginning of the runtime.
17+
- `abort` function no longer needs to be close to `_start`.
18+
- In multi-hart targets, the hart ID is now validated earlier in the boot process.
1719

1820
### Fixed
1921

riscv-rt/src/asm.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ _abs_start:
7272
"csrw stvec, t0",
7373
#[cfg(not(feature = "s-mode"))]
7474
"csrw mtvec, t0",
75+
// If multi-hart, assert that hart ID is valid
76+
#[cfg(not(feature = "single-hart"))]
77+
"lui t0, %hi(_max_hart_id)
78+
add t0, t0, %lo(_max_hart_id)
79+
bgeu t0, a0, 1f
80+
la t0, abort // If hart_id > _max_hart_id, jump to abort
81+
jr t0
82+
1:", // only valid harts reach this point
7583
);
7684

7785
// ZERO OUT GENERAL-PURPOSE REGISTERS
@@ -91,9 +99,6 @@ cfg_global_asm!(
9199
#[cfg(not(feature = "single-hart"))]
92100
cfg_global_asm!(
93101
"mv t2, a0
94-
lui t0, %hi(_max_hart_id)
95-
add t0, t0, %lo(_max_hart_id)
96-
bgtu t2, t0, abort
97102
lui t0, %hi(_hart_stack_size)
98103
add t0, t0, %lo(_hart_stack_size)",
99104
#[cfg(riscvm)]

0 commit comments

Comments
 (0)