7 #include "sw/device/lib/runtime/irq.h"
8 #include "sw/device/lib/runtime/pmp.h"
9 #include "sw/device/lib/testing/test_framework/check.h"
15 #define PMP_LOAD_REGION_ID 7
17 #define PMP_LOAD_RANGE_BUFFER_SIZE 1024
18 #define PMP_LOAD_RANGE_SIZE 512
19 #define PMP_LOAD_RANGE_BOTTOM_OFFSET 0
20 #define PMP_LOAD_RANGE_TOP_OFFSET \
21 (PMP_LOAD_RANGE_BOTTOM_OFFSET + PMP_LOAD_RANGE_SIZE - 1)
27 static volatile bool pmp_load_exception;
32 __attribute__((aligned(PMP_LOAD_RANGE_SIZE)))
33 static volatile char pmp_load_store_test_data[PMP_LOAD_RANGE_BUFFER_SIZE];
38 void ottf_load_store_fault_handler(uint32_t *exc_info) {
39 pmp_load_exception =
true;
42 static void pmp_configure_load_napot(
void) {
43 uintptr_t load_range_start =
44 (uintptr_t)&pmp_load_store_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
47 .
lock = kPmpRegionLockLocked,
48 .permissions = kPmpRegionPermissionsNone,
51 pmp_region_configure_napot_result_t result = pmp_region_configure_napot(
52 PMP_LOAD_REGION_ID, config, load_range_start, PMP_LOAD_RANGE_SIZE);
53 CHECK(result == kPmpRegionConfigureNapotOk,
54 "Load configuration failed, error code = %d", result);
57 OTTF_DEFINE_TEST_CONFIG();
61 pmp_region_configure_result_t result =
62 pmp_region_is_configured(PMP_LOAD_REGION_ID, &configured);
63 CHECK(result == kPmpRegionConfigureOk,
64 "PMP region %d cfg read failed, error code = %d", PMP_LOAD_REGION_ID,
66 CHECK(!configured,
"PMP region %d is already configured", PMP_LOAD_REGION_ID);
68 pmp_load_exception =
false;
69 char load = pmp_load_store_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
70 CHECK(!pmp_load_exception,
"Load access violation before PMP configuration");
72 pmp_configure_load_napot();
74 pmp_load_exception =
false;
75 load = pmp_load_store_test_data[PMP_LOAD_RANGE_BOTTOM_OFFSET];
76 CHECK(pmp_load_exception,
77 "No load access violation on the bottom of the range load");
79 pmp_load_exception =
false;
80 load = pmp_load_store_test_data[PMP_LOAD_RANGE_TOP_OFFSET];
81 CHECK(pmp_load_exception,
82 "No load access violation on the top of the range load");
84 pmp_load_exception =
false;
85 load = pmp_load_store_test_data[PMP_LOAD_RANGE_TOP_OFFSET + 1];
86 CHECK(!pmp_load_exception,
"Load access violation on top of the range + 1");