From 5e9190ff1a7d35e812b42c5bb9cbb742c2d313fb Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Mon, 5 Feb 2024 14:04:25 +0100 Subject: MM: add modules for memory management --- src/arch/x86_64/asm/e820.s | 2 ++ src/arch/x86_64/linker.ld | 1 + src/arch/x86_64/mem.rs | 16 ++++++++++++++++ src/arch/x86_64/mod.rs | 1 + 4 files changed, 20 insertions(+) create mode 100644 src/arch/x86_64/asm/e820.s create mode 100644 src/arch/x86_64/mem.rs (limited to 'src/arch') diff --git a/src/arch/x86_64/asm/e820.s b/src/arch/x86_64/asm/e820.s new file mode 100644 index 0000000..59c672a --- /dev/null +++ b/src/arch/x86_64/asm/e820.s @@ -0,0 +1,2 @@ +; getting an E820 memory map, code from osdev wiki. +; this only works in real mode ... how to do it in long mode? diff --git a/src/arch/x86_64/linker.ld b/src/arch/x86_64/linker.ld index 7a03770..ae77deb 100644 --- a/src/arch/x86_64/linker.ld +++ b/src/arch/x86_64/linker.ld @@ -71,4 +71,5 @@ SECTIONS *(".debug_aranges") } */ + PROVIDE (KERNEL_END = .); } diff --git a/src/arch/x86_64/mem.rs b/src/arch/x86_64/mem.rs new file mode 100644 index 0000000..52ccdec --- /dev/null +++ b/src/arch/x86_64/mem.rs @@ -0,0 +1,16 @@ +// to detect available memory to initialize PMA +// https://wiki.osdev.org/Detecting_Memory_(x86) +use core::arch::asm; +use crate::io::*; + +extern "C" { + fn do_e820(start: usize) -> u32; +} + +// Getting an E820 Memory Map -- osdev wiki +pub fn prob_mem_bios(){ + unsafe { + let res = do_e820(0x8000); + println!("res is {}", res) + } +} diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 9429c8f..c3b226e 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -2,3 +2,4 @@ pub mod cpu; pub mod interrupt; pub mod io_port; pub mod misc; +pub mod mem; -- cgit v1.2.3-70-g09d2