Skip to content

Commit

Permalink
Merge pull request #2255 from silabs-hfegran/dev_hf_wfe_test_updates
Browse files Browse the repository at this point in the history
Updated wfe test to work correctly without user-mode/PMP, added flags…
  • Loading branch information
silabs-robin authored Oct 23, 2023
2 parents 99767cd + e6db7d8 commit 7c2a400
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cv32e40s/regress/cv32e40s_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ tests:
cmd: make test TEST=debug_test_0_triggers

wfe_test:
description: Short directed wfe test
description: Short directed wfe test (needs PMP support)
builds: [ uvmt_cv32e40s_clic, uvmt_cv32e40s ]
dir: cv32e40s/sim/uvmt
cmd: make test TEST=wfe_test
Expand Down
52 changes: 52 additions & 0 deletions cv32e40s/tests/programs/custom/wfe_test/wfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

#define WFE_INSTR 0x8c000073

#define MARCHID_CV32E40X 0x14
#define MARCHID_CV32E40S 0x15

// __FUNCTION__ is C99 and newer, -Wpedantic flags a warning that
// this is not ISO C, thus we wrap this instatiation in a macro
// ignoring this GCC warning to avoid a long list of warnings during
Expand Down Expand Up @@ -228,6 +231,13 @@ void set_pmpcfg(pmpsubcfg_t pmpsubcfg, uint32_t reg_no);
*/
void increment_mepc(volatile uint32_t incr_val);

/*
* has_pmp_configured
*
* Returns 1 if pmp is enabled/supported else returns 0
*/
uint32_t has_pmp_configured(void);

/*
* Non-standard illegal instruction and ecall handlers
*/
Expand Down Expand Up @@ -316,6 +326,36 @@ int get_result(uint32_t res, uint32_t (* volatile ptr[])(uint32_t, uint8_t)){

// -----------------------------------------------------------------------------

uint32_t has_pmp_configured(void) {
volatile uint32_t pmpaddr0 = 0xffffffff;
volatile uint32_t pmpaddr0_backup = 0;
volatile uint32_t marchid = 0x0;

__asm__ volatile (R"(
csrrs %[marchid], marchid, zero
)":[marchid] "=r"(marchid));

// CV32E40X does not support PMP, skip
switch (marchid) {
case (MARCHID_CV32E40X):
return 0;
break;
case (MARCHID_CV32E40S):
;; // Do nothing and continue execution
break;
}

__asm__ volatile (R"(
csrrw %[pmpaddr0_backup] , pmpaddr0, %[pmpaddr0]
csrrw %[pmpaddr0], pmpaddr0, %[pmpaddr0_backup]
)" :[pmpaddr0_backup] "+r"(pmpaddr0_backup),
[pmpaddr0] "+r"(pmpaddr0));

return (pmpaddr0 != 0);
}

// -----------------------------------------------------------------------------

void set_mseccfg(mseccfg_t mseccfg){

__asm__ volatile ( R"(
Expand Down Expand Up @@ -711,6 +751,12 @@ uint32_t wfe_wakeup_umode(uint32_t index, uint8_t report_name){
return 0;
}

// Check if there user mode support
if (!has_pmp_configured()) {
cvprintf(V_LOW, "Skipping test: User mode/PMP not supported\n");
return 0;
}

// Setup PMP access for u-mode (otherwise all deny)
set_mseccfg((mseccfg_t){
.fields.mml = 0,
Expand Down Expand Up @@ -793,6 +839,12 @@ uint32_t wfi_mstatus_tw_umode_illegal(uint32_t index, uint8_t report_name){
return 0;
}

// Check if there user mode support
if (!has_pmp_configured()) {
cvprintf(V_LOW, "Skipping test: User mode/pmp not supported\n");
return 0;
}

// Set timeout wait (mstatus.tw)
mstatus.fields.tw = 1;
__asm__ volatile ( R"(
Expand Down

0 comments on commit 7c2a400

Please sign in to comment.