Use XLEN macro for these sources as well.
[riscv-tests.git] / debug / programs / mprv.S
1 #include "../../env/encoding.h"
2 #define PGSHIFT 12
3
4 .global main
5
6 .section .text
7 main:
8 # Set up a page table entry that maps 0x0... to 0x8...
9 la t0, page_table
10 srli t0, t0, PGSHIFT
11 csrw CSR_SPTBR, t0
12
13 # update mstatus
14 csrr t1, CSR_MSTATUS
15 #if XLEN == 32
16 li t0, (MSTATUS_MPRV | (VM_SV32 << 24))
17 #else
18 li t0, (MSTATUS_MPRV | (VM_SV39 << 24))
19 #endif
20 #li t0, ((VM_SV39 << 24))
21 or t1, t0, t1
22 csrw CSR_MSTATUS, t1
23
24 la t0, (loop - 0x80000000)
25 csrw CSR_MEPC, t0
26
27 # Exit supervisor mode, entering user mode at loop.
28 mret
29
30 loop:
31 la t0, data
32 lw t1, 0(t0)
33 j loop
34
35 .section .data
36 data:
37 .word 0xbead
38
39 .balign 0x1000
40 page_table:
41 #if XLEN == 32
42 .word ((0x80000000 >> 2) | PTE_V | PTE_R | PTE_W | PTE_X | PTE_G | PTE_U)
43 #else
44 .word ((0x80000000 >> 2) | PTE_V | PTE_R | PTE_W | PTE_X | PTE_G | PTE_U)
45 .word 0
46 #endif