|
6 | 6 |
|
7 | 7 | .include "assembly-helpers.s" |
8 | 8 |
|
| 9 | +# Symbolic names for the satck high water mark registers until |
| 10 | +# the assembler knows about them. |
| 11 | + |
| 12 | +/** |
| 13 | + * Machine-mode stack high water mark CSR |
| 14 | + */ |
| 15 | +#define CSR_MSHWM 0xbc1 |
| 16 | +/** |
| 17 | + * Machine mode stack high water mark stack base CSR |
| 18 | + */ |
| 19 | +#define CSR_MSHWMB 0xbc2 |
| 20 | + |
9 | 21 | #define MAX_FAULTS_PER_COMPARTMENT_CALL 1024 |
10 | 22 |
|
11 | 23 | # Global for the sealing key. Stored in the switcher's code section. |
@@ -182,21 +194,21 @@ compartment_switcher_entry: |
182 | 194 | sub s1, s0, s1 |
183 | 195 | csetboundsexact ct2, csp, s1 |
184 | 196 | csetaddr csp, ct2, s0 |
185 | | -#ifdef CONFIG_MSLWM |
186 | | - // read and align the stack low water mark |
187 | | - csrr gp, 0xbc1 // mslwm |
| 197 | +#ifdef CONFIG_MSHWM |
| 198 | + // read and align the stack high water mark |
| 199 | + csrr gp, CSR_MSHWM |
188 | 200 | and gp, gp, ~0xf |
189 | | - // skip zeroing if low water mark >= stack poitner |
| 201 | + // skip zeroing if high water mark >= stack poitner |
190 | 202 | bge t2, sp, after_zero |
191 | | - // use stack low water mark as base address for zeroing |
| 203 | + // use stack high water mark as base address for zeroing |
192 | 204 | // XXX could be out of bounds / unrepresentable if bad csp? |
193 | 205 | csetaddr ct2, csp, gp |
194 | 206 | #endif |
195 | 207 | zero_stack t2, s0, gp |
196 | 208 | after_zero: |
197 | | -#ifdef CONFIG_MSLWM |
198 | | - // store new stack top as stack low water mark |
199 | | - csrw 0xbc1, sp // mslwm |
| 209 | +#ifdef CONFIG_MSHWM |
| 210 | + // store new stack top as stack high water mark |
| 211 | + csrw CSR_MSHWM, sp |
200 | 212 | #endif |
201 | 213 | #endif // CONFIG_NO_SWITCHER_SAFETY |
202 | 214 | .Lout: |
@@ -330,11 +342,11 @@ exception_entry_asm: |
330 | 342 | csc ct0, TrustedStack_offset_mepcc(csp) |
331 | 343 | csrr t1, mstatus |
332 | 344 | csw t1, TrustedStack_offset_mstatus(csp) |
333 | | -#ifdef CONFIG_MSLWM |
334 | | - csrr t1, 0xbc1 // mslwm |
335 | | - csw t1, TrustedStack_offset_mslwm(csp) |
336 | | - csrr t1, 0xbc2 // mslwmb |
337 | | - csw t1, TrustedStack_offset_mslwmb(csp) |
| 345 | +#ifdef CONFIG_MSHWM |
| 346 | + csrr t1, CSR_MSHWM |
| 347 | + csw t1, TrustedStack_offset_mshwm(csp) |
| 348 | + csrr t1, CSR_MSHWMB |
| 349 | + csw t1, TrustedStack_offset_mshwmb(csp) |
338 | 350 | #endif |
339 | 351 | csrr t1, mcause |
340 | 352 | csw t1, TrustedStack_offset_mcause(csp) |
@@ -415,11 +427,11 @@ exception_entry_asm: |
415 | 427 | .Linstall_context: |
416 | 428 | clw x1, TrustedStack_offset_mstatus(csp) |
417 | 429 | csrw mstatus, x1 |
418 | | -#ifdef CONFIG_MSLWM |
419 | | - clw x1, TrustedStack_offset_mslwm(csp) |
420 | | - csrw 0xbc1, x1 // mslwm |
421 | | - clw x1, TrustedStack_offset_mslwmb(csp) |
422 | | - csrw 0xbc2, x1 // mslwmb |
| 430 | +#ifdef CONFIG_MSHWM |
| 431 | + clw x1, TrustedStack_offset_mshwm(csp) |
| 432 | + csrw CSR_MSHWM, x1 |
| 433 | + clw x1, TrustedStack_offset_mshwmb(csp) |
| 434 | + csrw CSR_MSHWMB, x1 |
423 | 435 | #endif |
424 | 436 | cspecialw mepcc, ct2 |
425 | 437 | csb zero, TrustedStack_offset_inForcedUnwind(csp) |
@@ -721,21 +733,21 @@ exception_entry_asm: |
721 | 733 | // Update the current frame offset. |
722 | 734 | csw t2, TrustedStack_offset_frameoffset(ctp) |
723 | 735 | #ifndef CONFIG_NO_SWITCHER_SAFETY |
724 | | -#ifdef CONFIG_MSLWM |
725 | | - // read and align the stack low water mark |
| 736 | +#ifdef CONFIG_MSHWM |
| 737 | + // read and align the stack high water mark |
726 | 738 | // we will use this as base address for stack clearing |
727 | 739 | // note that it cannot be greater than stack top as we |
728 | 740 | // we set it to stack top when we pushed to trusted stack frame |
729 | | - csrr tp, 0xbc1 //mslwm |
| 741 | + csrr tp, CSR_MSHWM |
730 | 742 | and tp, tp, ~0xf |
731 | 743 | #else |
732 | 744 | cgetbase tp, csp |
733 | 745 | #endif |
734 | 746 | cgetaddr t1, csp |
735 | 747 | csetaddr ct2, csp, tp |
736 | 748 | zero_stack t2, t1, tp |
737 | | -#ifdef CONFIG_MSLWM |
738 | | - csrw 0xbc1, sp // mslwm |
| 749 | +#ifdef CONFIG_MSHWM |
| 750 | + csrw CSR_MSHWM, sp |
739 | 751 | #endif |
740 | 752 | #endif // CONFIG_NO_SWITCHER_SAFETY |
741 | 753 | cret |
0 commit comments