pmp_fetch.asm
1 _start: 2 la x1, trap_handler 3 csrw mtvec, x1 4 5 # PMP Entry 0: [0, 0x10000), TOR, RWX 6 li x1, 0x10000 >> 2 7 csrw pmpaddr0, x1 8 li x1, 0b00001111 9 csrw pmpcfg0, x1 10 11 li x1, 0b11 << 11 12 csrc mstatus, x1 # Set transfer to User mode to mpp 13 14 la x1, user_code 15 csrw mepc, x1 16 mret # Go to user_code in user mode 17 18 user_code: 19 li x1, 0x20000 20 jalr x0, x1, 0 # Jump to address outside PMP region 21 j fail 22 23 trap_handler: 24 csrr x1, mcause 25 li x2, 1 26 bne x1, x2, fail # Check if it is a ACCESS fault 27 j pass 28 29 fail: 30 j fail 31 32 pass: 33 li x1, 1 34 j pass