diff options
| author | Tianhao Wang <wth@riseup.net> | 2024-02-25 05:01:22 +0100 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:13:39 +0200 |
| commit | bef6d67f63125310dee0bb437175d660eaeab4a3 (patch) | |
| tree | 1137dc68c0fdf2b0c9b9fc002f1b8228b16245e9 /src/defs.rs | |
| parent | dbefd9336cc808e76f8e9d8d238f5a348d14604a (diff) | |
define memory layout (if there was a layout)
Diffstat (limited to 'src/defs.rs')
| -rw-r--r-- | src/defs.rs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/defs.rs b/src/defs.rs index 3c1ff57..cec17c9 100644 --- a/src/defs.rs +++ b/src/defs.rs @@ -1,13 +1,47 @@ pub struct Mem; +pub struct VAddr(u64); + impl Mem { // units pub const K: usize = 1024; pub const M: usize = 1024 * Mem::K; pub const G: usize = 1024 * Mem::M; - // physical memory - pub const PHY_TOP: usize = 128 * Mem::M; // qemu defaults to 128 MiB phy Memory + // physical memory layout: qemu defaults to 128 MiB phy Memory + pub const PHY_TOP: usize = 128 * Mem::M; + // 4 lv 4K paging pub const PAGE_SIZE: usize = 0x1000; pub const PAGE_SHIFT: usize = 12; - pub const PHY_PAGES: usize = Mem::PHY_TOP >> Mem::PAGE_SHIFT; pub const PAGE_MASK: u64 = 0xfff; + pub const L0_SHIFT: u8 = 39; + pub const L0_MASK: u64 = 0x1ff << Mem::L0_SHIFT; + pub const L1_SHIFT: u8 = 30; + pub const L1_MASK: u64 = 0x1ff << Mem::L1_SHIFT; + pub const L2_SHIFT: u8 = 21; + pub const L2_MASK: u64 = 0x1ff << Mem::L2_SHIFT; + pub const L3_SHIFT: u8 = 12; + pub const L3_MASK: u64 = 0x1ff << Mem::L3_SHIFT; + pub const PHY_PAGES: usize = Mem::PHY_TOP >> Mem::PAGE_SHIFT; + // size of frame allocator bitmap: number of physical frames / 8 for 128M + // memory (37268) 4k pages, 37268 bits are needed, hence + // 4096 bytes, exactly one page! + pub const PHY_BM_SIZE: usize = Mem::PHY_PAGES >> 3; +} + +impl VAddr { + pub fn roundup_4k(&self) { + todo!() + } + pub fn rounddown_4k(&self) { + todo!() + } + pub fn page_number(&self) -> u64 { + self.0 >> Mem::PAGE_SHIFT + } } + +// PHY_TOP 128M +// ~ free frames +// PMA::bitmap + PHY_BM_SIZE +// ~ ___KERNEL_END__ +// KERNEL IMAGE +// KERNEL START 1 M |
