Skip to content

Commit 7b5929c

Browse files
authored
fix(rt): correct PMP entry for bl808 (#24)
Signed-off-by: Junxing Zhu <jakezhu9@gmail.com>
1 parent c0ac465 commit 7b5929c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

bouffalo-rt/src/soc/bl808.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ unsafe extern "C" fn start() -> ! {
4242
li t1, {stack_protect_pmp_address_end}
4343
csrw pmpaddr1, t1
4444
li t2, {stack_protect_pmp_flags}
45-
csrw pmpcfg1, t2",
46-
" sfence.vma x0, x0",
45+
csrw pmpcfg0, t2",
4746
" call {main}",
4847
stack = sym STACK,
4948
hart_stack_size = const LEN_STACK_MCU,
5049
trap_entry = sym trap_vectored,
5150
trap_mode = const 1, // RISC-V standard vectored trap
52-
stack_protect_pmp_address_begin = const {0x61030000},
53-
stack_protect_pmp_address_end = const {0x62030000},
54-
stack_protect_pmp_flags = const 0b00001000, // -r, -w, -x, tor, not locked
51+
// Set PMP entry to block U/S-mode stack access (TOR, no R/W/X permissions)
52+
stack_protect_pmp_address_begin = const {0x62030000 >> 2},
53+
stack_protect_pmp_address_end = const {(0x62030000 + 160 * 1024) >> 2},
54+
stack_protect_pmp_flags = const 0b00001000 << 8,
5555
main = sym main,
5656
)
5757
}
@@ -91,17 +91,21 @@ unsafe extern "C" fn start() -> ! {
9191
" la t0, {trap_entry}
9292
ori t0, t0, {trap_mode}
9393
csrw mtvec, t0",
94-
" li t1, {stack_protect_pmp_address}
94+
" li t1, {stack_protect_pmp_address_begin}
9595
csrw pmpaddr0, t1
96+
li t1, {stack_protect_pmp_address_end}
97+
csrw pmpaddr1, t1
9698
li t2, {stack_protect_pmp_flags}
9799
csrw pmpcfg0, t2",
98100
" call {main}",
99101
stack = sym STACK,
100102
hart_stack_size = const LEN_STACK_DSP,
101103
trap_entry = sym trap_vectored,
102104
trap_mode = const 1, // RISC-V standard vectored trap
103-
stack_protect_pmp_address = const {(0x3E000000 >> 2) + (16 * 1024 * 1024 >> 3) - 1},
104-
stack_protect_pmp_flags = const 0b00011000, // -r, -w, -x, napot, not locked
105+
// Set PMP entry to block U/S-mode stack access (TOR, no R/W/X permissions)
106+
stack_protect_pmp_address_begin = const {0x3F000000 >> 2},
107+
stack_protect_pmp_address_end = const {(0x3F000000 + 32 * 1024) >> 2},
108+
stack_protect_pmp_flags = const 0b00001000 << 8,
105109
main = sym main,
106110
)
107111
}
@@ -209,10 +213,7 @@ unsafe extern "C" fn reserved() -> ! {
209213
unsafe { core::arch::naked_asm!("1: j 1b") }
210214
}
211215

212-
#[cfg(any(
213-
all(feature = "bl808-mcu", target_arch = "riscv32"),
214-
all(feature = "bl808-dsp", target_arch = "riscv64")
215-
))]
216+
#[cfg(any(all(feature = "bl808-dsp", target_arch = "riscv64")))]
216217
unsafe extern "C" {
217218
fn exceptions(tf: &mut crate::arch::rvi::TrapFrame);
218219
}

0 commit comments

Comments
 (0)