Skip to content

Commit 5b42896

Browse files
rmn30ronorton
authored andcommitted
Fixes from review.
- Change xmake config option into part of board config json. - Rename low water mark to high water mark - Introduce macros for CSR numbers in entry.S - Formatting in tstack.h
1 parent ba9b79c commit 5b42896

File tree

5 files changed

+52
-43
lines changed

5 files changed

+52
-43
lines changed

sdk/core/loader/boot.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,9 @@ namespace
819819
threadTStack->mstatus =
820820
(priv::MSTATUS_MPIE |
821821
(priv::MSTATUS_PRV_M << priv::MSTATUS_MPP_SHIFT));
822-
#ifdef CONFIG_MSLWM
823-
threadTStack->mslwm = stack.top();
824-
threadTStack->mslwmb = stack.base();
822+
#ifdef CONFIG_MSHWM
823+
threadTStack->mshwm = stack.top();
824+
threadTStack->mshwmb = stack.base();
825825
#endif
826826
threadTStack->frameoffset = offsetof(TrustedStack, frames[1]);
827827
threadTStack->frames[0].calleeExportTable =

sdk/core/switcher/entry.S

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
.include "assembly-helpers.s"
88

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+
921
#define MAX_FAULTS_PER_COMPARTMENT_CALL 1024
1022

1123
# Global for the sealing key. Stored in the switcher's code section.
@@ -182,21 +194,21 @@ compartment_switcher_entry:
182194
sub s1, s0, s1
183195
csetboundsexact ct2, csp, s1
184196
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
188200
and gp, gp, ~0xf
189-
// skip zeroing if low water mark >= stack poitner
201+
// skip zeroing if high water mark >= stack poitner
190202
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
192204
// XXX could be out of bounds / unrepresentable if bad csp?
193205
csetaddr ct2, csp, gp
194206
#endif
195207
zero_stack t2, s0, gp
196208
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
200212
#endif
201213
#endif // CONFIG_NO_SWITCHER_SAFETY
202214
.Lout:
@@ -330,11 +342,11 @@ exception_entry_asm:
330342
csc ct0, TrustedStack_offset_mepcc(csp)
331343
csrr t1, mstatus
332344
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)
338350
#endif
339351
csrr t1, mcause
340352
csw t1, TrustedStack_offset_mcause(csp)
@@ -415,11 +427,11 @@ exception_entry_asm:
415427
.Linstall_context:
416428
clw x1, TrustedStack_offset_mstatus(csp)
417429
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
423435
#endif
424436
cspecialw mepcc, ct2
425437
csb zero, TrustedStack_offset_inForcedUnwind(csp)
@@ -721,21 +733,21 @@ exception_entry_asm:
721733
// Update the current frame offset.
722734
csw t2, TrustedStack_offset_frameoffset(ctp)
723735
#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
726738
// we will use this as base address for stack clearing
727739
// note that it cannot be greater than stack top as we
728740
// we set it to stack top when we pushed to trusted stack frame
729-
csrr tp, 0xbc1 //mslwm
741+
csrr tp, CSR_MSHWM
730742
and tp, tp, ~0xf
731743
#else
732744
cgetbase tp, csp
733745
#endif
734746
cgetaddr t1, csp
735747
csetaddr ct2, csp, tp
736748
zero_stack t2, t1, tp
737-
#ifdef CONFIG_MSLWM
738-
csrw 0xbc1, sp // mslwm
749+
#ifdef CONFIG_MSHWM
750+
csrw CSR_MSHWM, sp
739751
#endif
740752
#endif // CONFIG_NO_SWITCHER_SAFETY
741753
cret

sdk/core/switcher/trusted-stack-assembly.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ EXPORT_ASSEMBLY_OFFSET(TrustedStack, c14, 14 * 8)
2121
EXPORT_ASSEMBLY_OFFSET(TrustedStack, c15, 15 * 8)
2222
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mstatus, 16 * 8)
2323
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mcause, (16 * 8) + 4)
24-
#ifdef CONFIG_MSLWM
25-
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mslwm, 17 * 8)
26-
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mslwmb, (17 * 8) + 4)
24+
#ifdef CONFIG_MSHWM
25+
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mshwm, 17 * 8)
26+
EXPORT_ASSEMBLY_OFFSET(TrustedStack, mshwmb, (17 * 8) + 4)
2727

2828
// Size of everything up to this point
2929
#define TSTACK_REGFRAME_SZ (18 * 8)

sdk/core/switcher/tstack.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ struct TrustedStackGeneric
6262
void *c15;
6363
size_t mstatus;
6464
size_t mcause;
65-
#ifdef CONFIG_MSLWM
66-
uint32_t mslwm;
67-
uint32_t mslwmb;
65+
#ifdef CONFIG_MSHWM
66+
uint32_t mshwm;
67+
uint32_t mshwmb;
6868
#endif
6969
uint16_t frameoffset;
7070
/**
@@ -73,12 +73,13 @@ struct TrustedStackGeneric
7373
*/
7474
uint8_t inForcedUnwind;
7575
// Padding up to multiple of 16-bytes.
76-
#ifdef CONFIG_MSLWM
77-
# define TRUSTED_STACK_PADDING 13
76+
uint8_t padding[
77+
#ifdef CONFIG_MSHWM
78+
13
7879
#else
79-
# define TRUSTED_STACK_PADDING 5
80+
5
8081
#endif
81-
uint8_t padding[TRUSTED_STACK_PADDING];
82+
];
8283
/**
8384
* The trusted stack. There is always one frame, describing the entry
8485
* point. If this is popped then we have run off the stack and the thread

sdk/xmake.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ option("scheduler-accounting")
1616
set_description("Track per-thread cycle counts in the scheduler");
1717
set_showmenu(true)
1818

19-
option("stack-low-water-mark")
20-
set_default(false)
21-
set_description("Build with support for stack low water mark");
22-
set_showmenu(true)
23-
2419
function debugOption(name)
2520
option("debug-" .. name)
2621
set_default(false)
@@ -237,8 +232,9 @@ rule("firmware")
237232
add_defines("SIMULATION")
238233
end
239234

240-
if get_config("stack-low-water-mark") then
241-
add_defines("CONFIG_MSLWM")
235+
if board.stack_high_water_mark then
236+
print("using stack high water mark")
237+
add_defines("CONFIG_MSHWM")
242238
end
243239

244240
-- Build the MMIO space for the board

0 commit comments

Comments
 (0)