127 lines
3.1 KiB
ArmAsm
127 lines
3.1 KiB
ArmAsm
.section .data
|
|
.align 12 # All tables must be 4KB aligned
|
|
|
|
# --- Level 2: Root Table (At 0x80001000) ---
|
|
l2_table:
|
|
.quad 0
|
|
.quad 0
|
|
# Points to l1_table (0x80002000).
|
|
# PPN is 0x80002. Shifted left by 10 = 0x20000800. Flag V=1.
|
|
.quad (0x80002 << 10) | 0x1
|
|
.fill 509, 8, 0
|
|
|
|
# --- Level 1: Middle Table (At 0x80002000) ---
|
|
l1_table:
|
|
# Points to l0_table (0x80003000).
|
|
# PPN is 0x80003. Shifted left by 10 = 0x20000C00. Flag V=1.
|
|
.quad (0x80003 << 10) | 0x1
|
|
.fill 511, 8, 0
|
|
|
|
# --- Level 0: Leaf Table (At 0x80003000) ---
|
|
l0_table:
|
|
# Maps the actual code/data at 0x80000000.
|
|
# PPN is 0x80000. Flags: D A G U R W X V (0xCF)
|
|
.quad (0x80000 << 10) | 0xCF
|
|
.fill 511, 8, 0
|
|
|
|
.section .text
|
|
.globl _start
|
|
.align 4
|
|
_start:
|
|
# 1. Setup satp to point to the L2 (Root) table
|
|
cllc ca0, l2_table
|
|
cgetaddr t0, ca0
|
|
srli t0, t0, 12 # PPN of the root
|
|
li t1, (8 << 60) # Sv39 mode
|
|
or t0, t0, t1
|
|
csrw satp, t0 # ENABLE PAGING
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
cspecialr ct0, pcc
|
|
|
|
# Use csetaddr to build a stack capability
|
|
li t0, 0x80002100 # fixed top-of-stack address
|
|
csetaddr csp, ct0, t0
|
|
|
|
# bound it to 8 bytes (size of dword)
|
|
li t2, 8
|
|
csetbounds csp, csp, t2
|
|
# li t5, 4
|
|
# cincoffsetimm csp, csp, 10
|
|
|
|
# Read bounds
|
|
# cgetbase t3, csp
|
|
ld t0, 0(csp)
|
|
|
|
# ----------------------------------------------------------------
|
|
|
|
# Use csetaddr to build a stack capability
|
|
li t1, 0x80006000 # fixed top-of-stack address
|
|
csetaddr ca1, ct0, t1
|
|
|
|
# bound it to 8 bytes (size of dword)
|
|
li t1, 8
|
|
csetbounds ca1, ca1, t1
|
|
# cincoffsetimm ca1, ca1, 8
|
|
|
|
# Read bounds
|
|
# cgetbase t3, csp
|
|
ld t0, 0(ca1)
|
|
|
|
# ----------------------------------------------------------------
|
|
|
|
# Use csetaddr to build a stack capability
|
|
li t1, 0x80008000 # fixed top-of-stack address
|
|
csetaddr ca2, ct0, t1
|
|
|
|
# bound it to 8 bytes (size of dword)
|
|
li t1, 8
|
|
csetbounds ca2, ca2, t1
|
|
# cincoffsetimm ca2, ca2, 6
|
|
|
|
# Read bounds
|
|
# cgetbase t3, csp
|
|
ld t0, 0(ca2)
|
|
|
|
# ----------------------------------------------------------------
|
|
|
|
# Use csetaddr to build a stack capability
|
|
li t1, 0x80009000 # fixed top-of-stack address
|
|
csetaddr ca3, ct0, t1
|
|
|
|
# bound it to 8 bytes (size of dword)
|
|
li t1, 8
|
|
csetbounds ca3, ca3, t1
|
|
# cincoffsetimm ca3, ca3, 6
|
|
|
|
# Read bounds
|
|
# cgetbase t3, csp
|
|
ld t0, 0(ca3)
|
|
|
|
# ----------------------------------------------------------------
|
|
# Use csetaddr to build a stack capability
|
|
li t1, 0x80002000 # fixed top-of-stack address
|
|
csetaddr ca4, ct0, t1
|
|
|
|
# bound it to 8 bytes (size of dword)
|
|
li t1, 8
|
|
csetbounds ca4, ca4, t1
|
|
# cincoffsetimm ca4, ca4, 1
|
|
|
|
# Read bounds
|
|
# cgetbase t3, csp
|
|
ld t0, 0(ca4)
|
|
|
|
# ----------------------------------------------------------------
|
|
|
|
|
|
# derive capability from PCC
|
|
# csetaddr c1, ct0, t0
|
|
|
|
# la t0, tohost
|
|
li t1, 1
|
|
csd t1, 0(c1)
|
|
|
|
|