Skip to content

Commit fa35340

Browse files
committed
Add pre_init_trap
1 parent f5a2da9 commit fa35340

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

riscv-rt/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `pre_init_trap` to detect early errors during the boot process.
13+
1014
### Changed
1115

1216
- Moved all the assembly code to `asm.rs`

riscv-rt/src/asm.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ _abs_start:
6666
.option norelax
6767
.cfi_startproc
6868
.cfi_undefined ra",
69+
// Disable interrupts
6970
#[cfg(feature = "s-mode")]
7071
"csrw sie, 0
7172
csrw sip, 0",
7273
#[cfg(not(feature = "s-mode"))]
7374
"csrw mie, 0
7475
csrw mip, 0",
76+
// Set pre-init trap vector
77+
"la t0, pre_init_trap",
78+
#[cfg(feature = "s-mode")]
79+
"csrw stvec, t0",
80+
#[cfg(not(feature = "s-mode"))]
81+
"csrw mtvec, t0",
7582
);
7683

7784
// ZERO OUT GENERAL-PURPOSE REGISTERS
@@ -280,10 +287,14 @@ trap_handler!(
280287
(a0, 8), (a1, 9), (a2, 10), (a3, 11), (a4, 12), (a5, 13), (a6, 14), (a7, 15)]
281288
);
282289

283-
// Make sure there is an abort when linking
290+
#[rustfmt::skip]
284291
global_asm!(
285292
".section .text.abort
286-
.globl abort
287-
abort:
288-
j abort"
293+
.global abort
294+
abort: // make sure there is an abort symbol when linking
295+
j abort
296+
297+
.align 2
298+
pre_init_trap: // if you end up here, there is a bug in the boot code
299+
j pre_init_trap"
289300
);

0 commit comments

Comments
 (0)