obkrnl/vm/
x86_64.rs

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