Skip to content

feat(hal): enable riscv64 Sv39 MMU with an identity page table - #146

Merged
kernalix7 merged 1 commit into
mainfrom
feat/riscv64-sv39-identity-mmu
Jul 15, 2026
Merged

feat(hal): enable riscv64 Sv39 MMU with an identity page table#146
kernalix7 merged 1 commit into
mainfrom
feat/riscv64-sv39-identity-mmu

Conversation

@kernalix7

Copy link
Copy Markdown
Owner

The riscv64 boot ran with paging off (satp=0). Build a minimal Sv39 identity map and enable it (mirrors aarch64 #142).

Sv39 root (L2) table maps 1 GiB gigapages; _start populates a BSS-resident 4 KiB-aligned __riscv_root_pt with two identity leaf PTEs (flags V|R|W|X|A|D = 0xCF):

  • L2[0] → 0x0000_0000..0x4000_0000 — device MMIO (CLINT 0x0200_0000, PLIC 0x0C00_0000, NS16550 0x1000_0000)
  • L2[2] → 0x8000_0000..0xC000_0000 — RAM (OpenSBI + kernel @ 0x8020_0000)

then satp = MODE_SV39 | (root >> 12) with sfence.vma before/after.

Verified (qemu-system-riscv64 -M virt -bios default): boots with paging ON to the halt loop (UART/PLIC/timer all reached through the identity map), zero S-mode page faults under qemu -d int (remaining illegal-insn traps are pre-existing OpenSBI HPM probing, unrelated). x86_64/aarch64 unaffected.

The riscv64 boot ran with paging off (satp = 0). Build a minimal Sv39
identity map and turn it on, mirroring the aarch64 #142 approach. Sv39's
root (L2) table maps 1 GiB gigapages; _start populates a BSS-resident,
4 KiB-aligned root table (__riscv_root_pt) with two identity leaf PTEs
(flags V|R|W|X|A|D = 0xCF):
  L2[0] -> 0x0000_0000..0x4000_0000  device MMIO (CLINT 0x0200_0000,
           PLIC 0x0C00_0000, NS16550 0x1000_0000)
  L2[2] -> 0x8000_0000..0xC000_0000  RAM (OpenSBI + kernel at 0x8020_0000)
then sets satp = MODE_SV39 | (root >> 12) with sfence.vma before/after.

Verified: 'qemu-system-riscv64 -M virt -bios default' boots with paging
ON all the way to the halt loop (UART/PLIC/timer all reached through the
identity map), with zero S-mode page faults under 'qemu -d int' (the
remaining illegal-insn traps are pre-existing OpenSBI-firmware HPM
probing, unrelated). x86_64/aarch64 unaffected.
@kernalix7
kernalix7 merged commit 07e68bb into main Jul 15, 2026
2 checks passed
@kernalix7
kernalix7 deleted the feat/riscv64-sv39-identity-mmu branch July 15, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant