diff --git a/posts/DRAFT-paging.md b/posts/DRAFT-paging.md index 0190d3bf..a088a6c2 100644 --- a/posts/DRAFT-paging.md +++ b/posts/DRAFT-paging.md @@ -13,7 +13,8 @@ TODO Let's create a basic `memory/paging/mod.rs` module: ```rust -pub const PAGE_SIZE: usize = 4096; +use memory::PAGE_SIZE; + const ENTRY_COUNT: usize = 512; pub type PhysicalAddress = usize; @@ -23,7 +24,7 @@ pub struct Page { number: usize, } ``` -We define constants for the page size and the number of entries per table. To make future function signatures more expressive, we can use the type aliases `PhysicalAddress` and `VirtualAddress`. The `Page` struct is similar to the `Frame` struct in the [previous post], but represents a virtual page instead of a physical frame. +We import the `PAGE_SIZE` and define a constant for the number of entries per table. To make future function signatures more expressive, we can use the type aliases `PhysicalAddress` and `VirtualAddress`. The `Page` struct is similar to the `Frame` struct in the [previous post], but represents a virtual page instead of a physical frame. [previous post]: {{ page.previous.url }} diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 9badb5a4..471bf876 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -1,5 +1,5 @@ use core::ptr::Unique; -use memory::{Frame, FrameAllocator}; +use memory::{PAGE_SIZE, Frame, FrameAllocator}; use self::table::{Table, Level4}; use self::entry::*; @@ -30,7 +30,6 @@ pub fn test(frame_allocator: &mut A) mapping::map(&Page::containing_address(0x0), PRESENT, frame_allocator); } -pub const PAGE_SIZE: usize = 4096; const ENTRY_COUNT: usize = 512; pub type PhysicalAddress = usize; diff --git a/src/memory/paging/translate.rs b/src/memory/paging/translate.rs index af5b69ff..73dda190 100644 --- a/src/memory/paging/translate.rs +++ b/src/memory/paging/translate.rs @@ -1,7 +1,7 @@ -use super::{VirtualAddress, PhysicalAddress, Page, PAGE_SIZE, ENTRY_COUNT}; +use super::{VirtualAddress, PhysicalAddress, Page, ENTRY_COUNT}; use super::table::P4; use super::entry::HUGE_PAGE; -use memory::Frame; +use memory::{PAGE_SIZE, Frame}; pub fn translate(virtual_address: VirtualAddress) -> Option { let offset = virtual_address % PAGE_SIZE;