Skip to content

Commit

Permalink
DNM(TODO) allow testing execute access
Browse files Browse the repository at this point in the history
  • Loading branch information
wsipak committed Jan 8, 2025
1 parent cdaece9 commit 8a3ba0a
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions testbench/tests/pmp_random/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ void __attribute__((noinline)) test_write (const uint32_t* pattern, uint32_t* ta
memcpy((void*)target, pattern, size);
}

void __attribute__((noinline, section(".area.code"))) test_exec () {
printf(" hello from .area\n");
void __attribute__((noinline, optimize("O0"), section(".area.code"))) test_exec () {
return 0;
}

// ============================================================================
Expand Down Expand Up @@ -145,10 +145,11 @@ enum RegionType {

uint32_t reconcile_address(uint32_t address) {
uint32_t area_end = ((uint32_t)&_area) + 0x40;
while (((address < (uint32_t)&_stack_hi && address > (uint32_t)&_stack_lo)
|(address < (uint32_t)&_text && address > (uint32_t)&_text_end)
|(address < (uint32_t)&_data && address > (uint32_t)&_data_end)
|(address < (uint32_t)&_area && address > area_end)
while (((address < (uint32_t)&_stack_hi && address >= (uint32_t)&_stack_lo)
|(address >= (uint32_t)&_text && address < (uint32_t)&_text_end)
|(address >= (uint32_t)&_data && address < (uint32_t)&_data_end)
|(address >= (uint32_t)&_area && address < area_end)
|(address >= 0x10000000 && address < 0x20000000) // csrs
|(address == mailbox_addr))
& address != 0
) {
Expand Down Expand Up @@ -193,14 +194,10 @@ uint32_t legalize_config(uint32_t config) {
* does not influence PMPADDR access. Setting L would interfere with the
* test.
*/
// temporarily enforce NA4
config &= ~(PMP_NAPOT);
config |= PMP_NA4;

// if ((config & PMP_NAPOT) == PMP_NAPOT) {
// config &= ~(PMP_NAPOT);
// config |= PMP_NA4;
// }
if ((config & PMP_TOR) == PMP_TOR) {
// config &= ~(PMP_NAPOT);
config |= PMP_NAPOT;
}
// while((config & (PMP_NAPOT | PMP_NA4 | PMP_TOR) == 0) && config != 0) {
// // if not enabled, shift right until it's a valid enabled region.
// // if it's 0, give up.
Expand Down Expand Up @@ -290,6 +287,7 @@ int main () {
printf("test %d/%d\n", rand_test_i, RANDOM_ITERATIONS);
size_t i = rand_test_i;

printf(" using random data (%d)...\n", rand_test_i);
// hold the value to be written to cfg register
uint32_t config = legalize_config(rand_config[i]);
uint32_t address = rand_address[i];
Expand Down Expand Up @@ -341,7 +339,6 @@ int main () {
// Use the next region for random data (from the range 6..15)
region_for_rand_data = (region_for_rand_data < 15) ? region_for_rand_data+1 : 6;

printf(" using random data (%d)...\n", rand_test_i);
random_entry.cfg = config;
random_entry.addr = address;
pmp_entry_write(region_for_rand_data, &random_entry);
Expand Down Expand Up @@ -420,26 +417,36 @@ int main () {
any_fail = 1;
}

// Call a function placed in the designated area
// printf(" testing X...\n");
// TRY {
// test_exec();
// if (x_eff) {
// printf(" pass\n");
// } else {
// printf(" fail\n");
// any_fail = 1;
// }
// }
// CATCH {
// if (x_eff) {
// printf(" fail\n");
// any_fail = 1;
// } else {
// printf(" pass\n");
// }
// }
// END_TRY;
void (*copied_test_exec)();

if (test_size >= 16) { // TODO get size of the test_exec function

// Copy `test_exec` into the region
// TODO this collides with the concept that we first test read and write
memcpy((void*)addr_lo, &test_exec, 16);
copied_test_exec = (void(*)())addr_lo;

// Call a function placed in the designated area
printf(" testing X...\n");
TRY {
test_exec();
if (x_eff) {
printf(" pass\n");
} else {
printf(" fail\n");
any_fail = 1;
}
}
CATCH {
if (x_eff) {
printf(" fail\n");
any_fail = 1;
} else {
printf(" pass\n");
}
}
END_TRY;
}

// Count fails
failed += any_fail;
Expand Down

0 comments on commit 8a3ba0a

Please sign in to comment.