Files
Toooba/Tests/isa/CheriPage.S
2026-01-14 15:29:03 +00:00

130 lines
2.8 KiB
ArmAsm

.option norvc
.option norelax
# ==================================================
# Text section
# ==================================================
.section .text
.globl _start
_start:
vm_boot:
# Only hart 0 runs
csrr a0, mhartid
bnez a0, hang
# --------------------------------------------------
# root_pt[0] -> l1_pt
# --------------------------------------------------
cllc c0, l1_pt
li t2, 4096
csetbounds c0, c0, t2
cgetaddr t0, c0
srli t0, t0, 12
slli t0, t0, 10
ori t0, t0, 0x1 # V bit
cllc c1, root_pt
li t2, 4096
csetbounds c1, c1, t2
sd t0, 0(c1)
# --------------------------------------------------
# l1_pt[0] -> l0_pt
# --------------------------------------------------
cllc c0, l0_pt
li t2, 4096
csetbounds c0, c0, t2
cgetaddr t0, c0
srli t0, t0, 12
slli t0, t0, 10
ori t0, t0, 0x1 # V bit
cllc c1, l1_pt
li t2, 4096
csetbounds c1, c1, t2
sd t0, 0(c1)
# --------------------------------------------------
# l0_pt[0] -> leaf (RWX)
# --------------------------------------------------
li t0, (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<6) # V R W X A
cllc c1, l0_pt
li t2, 4096
csetbounds c1, c1, t2
sd t0, 0(c1)
# --------------------------------------------------
# Enable Sv39 paging
# --------------------------------------------------
cllc c0, root_pt
li t2, 4096
csetbounds c0, c0, t2
cgetaddr t0, c0
srli t0, t0, 12
li t1, (8 << 60) # MODE = Sv39
or t0, t0, t1
csrw satp, t0
sfence.vma zero, zero
# --------------------------------------------------
# Safe data access
# --------------------------------------------------
cllc c2, test_buf
li t2, 16
csetbounds c2, c2, t2
li t3, 0x1122334455667788
sd t3, 0(c2)
ld t4, 0(c2)
bne t3, t4, hang
# --------------------------------------------------
# Signal success
# --------------------------------------------------
cllc c0, tohost
li t2, 8
csetbounds c0, c0, t2
li t1, 1
sd t1, 0(c0)
hang:
wfi
j hang
# ==================================================
# Data section (aligned, contiguous, no .org)
# ==================================================
.section .data
.align 12
.globl root_pt
root_pt:
.zero 4096 # Root page table
.align 12
.globl l1_pt
l1_pt:
.zero 4096 # Level 1 page table
.align 12
.globl l0_pt
l0_pt:
.zero 4096 # Level 0 page table
.align 3
.globl test_buf
test_buf:
.zero 16 # Test buffer
.globl tohost
tohost:
.dword 0
.globl fromhost
fromhost:
.dword 0