From 84c337e6f006222970ea57d74057dbe9b7e03595 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 13 Apr 2017 17:59:12 +0200 Subject: [PATCH] Create a memory module with a Frame struct and FrameAllocator trait --- src/lib.rs | 1 + src/memory/mod.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/memory/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 4c9185e..71d2229 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,7 @@ extern crate multiboot2; #[macro_use] mod vga_buffer; +mod memory; #[no_mangle] pub extern fn rust_main(multiboot_information_address: usize) { diff --git a/src/memory/mod.rs b/src/memory/mod.rs new file mode 100644 index 0000000..553a0d5 --- /dev/null +++ b/src/memory/mod.rs @@ -0,0 +1,17 @@ +pub const PAGE_SIZE: usize = 4096; + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Frame { + number: usize, +} + +impl Frame { + fn containing_address(address: usize) -> Frame { + Frame{ number: address / PAGE_SIZE } + } +} + +pub trait FrameAllocator { + fn allocate_frame(&mut self) -> Option; + fn deallocate_frame(&mut self, frame: Frame); +}