|
21 | 21 | #include "vmpu_mpu.h" |
22 | 22 | #include "vmpu_unpriv_access.h" |
23 | 23 |
|
| 24 | +extern int vmpu_fault_recovery_mpu(uint32_t pc, uint32_t sp, uint32_t fault_addr, uint32_t fault_status); |
| 25 | + |
24 | 26 | uint32_t vmpu_unpriv_access(uint32_t addr, uint32_t size, uint32_t data) |
25 | 27 | { |
26 | | - // This operation could be slow since we are scanning all the regions defined for the box |
27 | | - // an implementation using the TTA command is faster but causes misses since it works with the MPU |
28 | | - if (vmpu_buffer_access_is_ok(g_active_box, (const void *) addr, UVISOR_UNPRIV_ACCESS_SIZE(size))){ |
29 | | - switch(size) { |
30 | | - case UVISOR_UNPRIV_ACCESS_READ(1): |
31 | | - return *((uint8_t *) addr); |
32 | | - case UVISOR_UNPRIV_ACCESS_READ(2): |
33 | | - return *((uint16_t *) addr); |
34 | | - case UVISOR_UNPRIV_ACCESS_READ(4): |
35 | | - return *((uint32_t *) addr); |
36 | | - case UVISOR_UNPRIV_ACCESS_WRITE(1): |
37 | | - *((uint8_t *) addr) = (uint8_t) data; |
38 | | - return 0; |
39 | | - case UVISOR_UNPRIV_ACCESS_WRITE(2): |
40 | | - *((uint16_t *) addr) = (uint16_t) data; |
41 | | - return 0; |
42 | | - case UVISOR_UNPRIV_ACCESS_WRITE(4): |
43 | | - *((uint32_t *) addr) = data; |
44 | | - return 0; |
45 | | - default: |
46 | | - break; |
| 28 | + unsigned int tries = 0; |
| 29 | + while(1) { |
| 30 | + // This operation could be slow since we are scanning all the regions defined for the box |
| 31 | + // an implementation using the TTA command is faster but causes misses since it works with the MPU |
| 32 | + if (vmpu_buffer_access_is_ok(g_active_box, (const void *) addr, UVISOR_UNPRIV_ACCESS_SIZE(size))){ |
| 33 | + switch(size) { |
| 34 | + case UVISOR_UNPRIV_ACCESS_READ(1): |
| 35 | + return *((uint8_t *) addr); |
| 36 | + case UVISOR_UNPRIV_ACCESS_READ(2): |
| 37 | + return *((uint16_t *) addr); |
| 38 | + case UVISOR_UNPRIV_ACCESS_READ(4): |
| 39 | + return *((uint32_t *) addr); |
| 40 | + case UVISOR_UNPRIV_ACCESS_WRITE(1): |
| 41 | + *((uint8_t *) addr) = (uint8_t) data; |
| 42 | + return 0; |
| 43 | + case UVISOR_UNPRIV_ACCESS_WRITE(2): |
| 44 | + *((uint16_t *) addr) = (uint16_t) data; |
| 45 | + return 0; |
| 46 | + case UVISOR_UNPRIV_ACCESS_WRITE(4): |
| 47 | + *((uint32_t *) addr) = data; |
| 48 | + return 0; |
| 49 | + default: |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + if (++tries > 1 || !vmpu_fault_recovery_mpu(0, 0, addr, 0)) { |
| 55 | + break; |
47 | 56 | } |
48 | 57 | } |
49 | | - |
| 58 | + |
50 | 59 | HALT_ERROR(PERMISSION_DENIED, "Access to restricted resource denied"); |
51 | 60 | return 0; |
52 | 61 | } |
0 commit comments