obkrnl/vm/x86_64.rs
1use super::VmPage;
2use crate::config::PAGE_SIZE;
3use core::arch::asm;
4use krt::{phys_vaddr, phys_vsize};
5
6/// See `pmap_kextract` on the Orbis for a reference.
7///
8/// # Reference offsets
9/// | Version | Offset |
10/// |---------|--------|
11/// |PS4 11.00|0x1145F0|
12pub unsafe fn kaddr_to_phys(va: usize) -> usize {
13 let dmap = phys_vaddr();
14 let dend = dmap + phys_vsize().get();
15
16 if va >= dmap && va < dend {
17 va - dmap
18 } else {
19 todo!()
20 }
21}
22
23impl VmPage {
24 /// See `pagezero` on the Orbis for a reference.
25 ///
26 /// # Safety
27 /// The caller must have exclusive access to this page and no any references to the data within
28 /// this page.
29 ///
30 /// # Reference offsets
31 /// | Version | Offset |
32 /// |---------|--------|
33 /// |PS4 11.00|0x2DDD70|
34 pub unsafe fn fill_with_zeros(&self) {
35 // The Orbis also check if the address within the stack but I don't think we need that.
36 let addr = phys_vaddr() + self.addr;
37
38 unsafe {
39 asm!(
40 "sub {addr}, {i}",
41 "xor eax, eax",
42 "2:",
43 "movnti [{addr} + {i}], rax",
44 "movnti [{addr} + {i} + 0x08], rax",
45 "movnti [{addr} + {i} + 0x10], rax",
46 "movnti [{addr} + {i} + 0x18], rax",
47 "add {i}, 0x20",
48 "jnz 2b",
49 "sfence",
50 addr = inout(reg) addr => _,
51 i = inout(reg) { -(PAGE_SIZE.get() as isize) } => _,
52 out("rax") _)
53 };
54 }
55}