Commit 6bbd187f authored by Nifou's avatar Nifou

Add some constants for memory addresses

parent 9e2a0ba8
......@@ -15,12 +15,14 @@
* along with this program. If not, see https://www.gnu.org/licenses.
*/
//! Physical memory's frames allocator
use super::area::Areas;
use x86_64::{
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},
PhysAddr,
};
use super::area::Areas;
use super::heap::{HEAP_START_PHYS, HEAP_SIZE};
/// An allocator which gives frames of physical memory
#[derive(Debug, Clone)]
pub struct NextFrameAllocator {
......@@ -40,7 +42,7 @@ impl NextFrameAllocator {
Self {
areas: areas,
current_area: 0,
next: PhysFrame::containing_address(PhysAddr::new(super::KERNEL_START_PHYS + super::KERNEL_SIZE)),
next: PhysFrame::containing_address(PhysAddr::new(HEAP_START_PHYS + HEAP_SIZE as u64)),
}
}
......
......@@ -17,10 +17,13 @@
//! Heap allocator
use linked_list_allocator::LockedHeap;
use super::{MULTIBOOT_START_VIRT, MULTIBOOT_SIZE};
use super::{MULTIBOOT_START_VIRT, MULTIBOOT_START_PHYS, MULTIBOOT_SIZE};
/// The start of the kernel's heap in virtual memory
pub const HEAP_START_VIRT: u64 = MULTIBOOT_START_VIRT + MULTIBOOT_SIZE + 4096;
/// The start of the kernel's heap (Virtual)
pub const HEAP_START_VIRT: u64 = MULTIBOOT_START_VIRT + MULTIBOOT_SIZE;
/// The start of the kernel's heap (Physical)
pub const HEAP_START_PHYS: u64 = MULTIBOOT_START_PHYS + MULTIBOOT_SIZE;
/// The size of the kernel's heap
pub const HEAP_SIZE: usize = 4 * 1024 * 1024;
......
......@@ -44,7 +44,7 @@ use x86_64::{
use area::Areas;
use frame_allocator::NextFrameAllocator;
use self::table::ProcessPageTable;
use self::heap::{HEAP_START_VIRT, HEAP_SIZE};
use self::heap::{HEAP_START_VIRT, HEAP_START_PHYS, HEAP_SIZE};
/// The address of the temporary page
pub const TMP_PAGE_ADDR: u64 = HEAP_START_VIRT as u64 + HEAP_SIZE as u64 + 4096;
......@@ -61,7 +61,7 @@ pub const KERNEL_SIZE: u64 = 0x800000;
/// The start of the multiboot information structure (Virtual)
pub const MULTIBOOT_START_VIRT: u64 = KERNEL_START_VIRT + KERNEL_SIZE;
/// The start of the multiboot information structure (Virtual)
/// The start of the multiboot information structure (Physical)
pub const MULTIBOOT_START_PHYS: u64 = KERNEL_START_PHYS + KERNEL_SIZE;
/// The size of the multiboot information structure
......@@ -90,12 +90,7 @@ pub fn init(areas: Areas) {
init_allocator(areas);
init_mapper();
let frame = FRAME_ALLOCATOR
.r#try()
.unwrap()
.lock()
.allocate_frame()
.unwrap();
let frame = PhysFrame::from_start_address(PhysAddr::new(MULTIBOOT_START_PHYS)).unwrap();
let mapper = remap_kernel(frame);
......@@ -141,16 +136,11 @@ fn remap_kernel(frame: PhysFrame) -> RecursivePageTable<'static> {
}
// Map the kernel heap
for page in Page::<Size4KiB>::range_inclusive(
for (i, page) in Page::<Size4KiB>::range_inclusive(
Page::containing_address(VirtAddr::new(HEAP_START_VIRT)),
Page::containing_address(VirtAddr::new(HEAP_START_VIRT + HEAP_SIZE as u64))
) {
let frame = FRAME_ALLOCATOR
.r#try()
.unwrap()
.lock()
.allocate_frame()
.expect("cannot allocate frame");
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(HEAP_START_PHYS + i as u64 * 4096));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
......
......@@ -73,7 +73,7 @@ impl ProcessMemory {
Page::containing_address(VirtAddr::new(memory::heap::HEAP_START_VIRT as u64)),
Page::containing_address(VirtAddr::new(memory::heap::HEAP_START_VIRT as u64 + memory::heap::HEAP_SIZE as u64))
).enumerate() {
let frame = PhysFrame::containing_address(PhysAddr::new(memory::MULTIBOOT_START_PHYS + memory::MULTIBOOT_SIZE + i as u64 * 4096));
let frame = PhysFrame::containing_address(PhysAddr::new(memory::heap::HEAP_START_PHYS + i as u64 * 4096));
unsafe { mapper.map_to(page, frame, Flags::PRESENT | Flags::WRITABLE, &mut *memory::FRAME_ALLOCATOR.r#try().unwrap().lock()).unwrap().ignore(); }
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment