@@ -42,16 +42,16 @@ unsafe extern "C" fn start() -> ! {
42
42
li t1, {stack_protect_pmp_address_end}
43
43
csrw pmpaddr1, t1
44
44
li t2, {stack_protect_pmp_flags}
45
- csrw pmpcfg1, t2" ,
46
- " sfence.vma x0, x0" ,
45
+ csrw pmpcfg0, t2" ,
47
46
" call {main}" ,
48
47
stack = sym STACK ,
49
48
hart_stack_size = const LEN_STACK_MCU ,
50
49
trap_entry = sym trap_vectored,
51
50
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 ,
55
55
main = sym main,
56
56
)
57
57
}
@@ -91,17 +91,21 @@ unsafe extern "C" fn start() -> ! {
91
91
" la t0, {trap_entry}
92
92
ori t0, t0, {trap_mode}
93
93
csrw mtvec, t0" ,
94
- " li t1, {stack_protect_pmp_address }
94
+ " li t1, {stack_protect_pmp_address_begin }
95
95
csrw pmpaddr0, t1
96
+ li t1, {stack_protect_pmp_address_end}
97
+ csrw pmpaddr1, t1
96
98
li t2, {stack_protect_pmp_flags}
97
99
csrw pmpcfg0, t2" ,
98
100
" call {main}" ,
99
101
stack = sym STACK ,
100
102
hart_stack_size = const LEN_STACK_DSP ,
101
103
trap_entry = sym trap_vectored,
102
104
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 ,
105
109
main = sym main,
106
110
)
107
111
}
@@ -209,10 +213,7 @@ unsafe extern "C" fn reserved() -> ! {
209
213
unsafe { core:: arch:: naked_asm!( "1: j 1b" ) }
210
214
}
211
215
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" ) ) ) ]
216
217
unsafe extern "C" {
217
218
fn exceptions ( tf : & mut crate :: arch:: rvi:: TrapFrame ) ;
218
219
}
0 commit comments