A repository for a long-term OS project titled DasOS (named after the Greek for "forest")
1use alloc::fmt::Debug;
2use limine::response::HhdmResponse;
3use crate::limine_requests::HHDM_REQUEST;
4
5/// A wrapper around u64 that represents the actual HHDM offset, and cannot be accidentally made.
6/// Remember though that even though this wraps unsafeness in safeness, it is only safe if the
7/// assumption that all available memory is mapped in the current Cr3 value according to the HHDM
8/// offset (and cache is not invalid)
9#[derive(Clone, Copy)]
10pub struct HhdmOffset(u64);
11
12impl Debug for HhdmOffset {
13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 write!(f, "HhdmOffset(0x{:X})", self.0)
15 }
16}
17
18impl From<&'static HhdmResponse> for HhdmOffset {
19 fn from(value: &'static HhdmResponse) -> Self {
20 Self(value.offset())
21 }
22}
23
24pub fn hhdm_offset() -> HhdmOffset {
25 HHDM_REQUEST.get_response().unwrap().into()
26}
27
28impl From<HhdmOffset> for u64 {
29 fn from(value: HhdmOffset) -> Self {
30 value.0
31 }
32}