Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Commit 4da463e

Browse files
Merge pull request #129 from ivq/sp_align
Ensure sp is 16-byte aligned
2 parents 7fe4dc3 + 30c1b93 commit 4da463e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
- `start_trap_rust` is now marked as `unsafe`
2222
- Implement `r0` as inline assembly
2323
- mhartid CSR is no longer read in single-hart mode, assumed zero
24+
- Ensure stack pointer is 16-byte aligned before jumping to Rust entry point
2425

2526
## [v0.11.0] - 2023-01-18
2627

src/asm.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ _abs_start:
108108
addi t1, t1, -1
109109
bnez t1, 1b
110110
2: ",
111-
"la sp, _stack_start",
111+
"la t1, _stack_start",
112112
#[cfg(not(feature = "single-hart"))]
113-
"sub sp, sp, t0",
114-
"// Set frame pointer
113+
"sub t1, t1, t0",
114+
"andi sp, t1, -16 // Force 16-byte alignment
115+
// Set frame pointer
115116
add s0, sp, zero
116117
117118
jal zero, _start_rust
@@ -135,6 +136,8 @@ _abs_start:
135136
#[rustfmt::skip]
136137
macro_rules! trap_handler {
137138
($STORE:ident, $LOAD:ident, $BYTES:literal, $TRAP_SIZE:literal, [$(($REG:ident, $LOCATION:literal)),*]) => {
139+
// ensure we do not break that sp is 16-byte aligned
140+
const _: () = assert!(($TRAP_SIZE * $BYTES) % 16 == 0);
138141
global_asm!(
139142
"
140143
.section .trap, \"ax\"

0 commit comments

Comments
 (0)