- added a new libary libm containing procedural macros for the kernel.
these should be used to include external files and resources in the kernel binary
at compile time.
- libm currently supports loading psf-1 formatted fonts
- added two fonts that are included in the binary at compile time
- refactored libk to make the crate structure more organised and maintainable in future.
new structure:
- drivers (hardware interaction)
- resources (consts and statics included either manually or via macros)
- std (standard functions for higher level interaction with the os, for example creating windows)
- added geometry.rs
- provides the Vec2<T> struct for use with dimensions, coordinates etc.
- added window.rs
- provides the Window struct for rendering the state of an application to the screen
- added application.rs
- provides the Application trait for custom programs to implement in order to run
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
use linked_list_allocator::LockedHeap;
|
||||
use x86_64::{
|
||||
VirtAddr,
|
||||
structures::paging::{
|
||||
FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError,
|
||||
},
|
||||
};
|
||||
|
||||
/// We are currently using a linked list heap allocator which uses our underlying page allocator.
|
||||
pub type FoundryAllocator = LockedHeap;
|
||||
|
||||
#[global_allocator]
|
||||
/// This is now Rust's global allocator, so we can use stuff requiring heap allocations.
|
||||
static ALLOCATOR: FoundryAllocator = FoundryAllocator::empty();
|
||||
|
||||
pub const HEAP_START: usize = 0x4444_4444_0000;
|
||||
pub const HEAP_SIZE: usize = 1000 * 1024;
|
||||
|
||||
/// Sets up the heap using the backing page frame allocator.
|
||||
pub fn init_heap(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
|
||||
) -> Result<(), MapToError<Size4KiB>> {
|
||||
let range = {
|
||||
let heap_start = VirtAddr::new(HEAP_START as u64);
|
||||
let heap_end = heap_start + HEAP_SIZE as u64 - 1u64;
|
||||
let heap_start_page = Page::<Size4KiB>::containing_address(heap_start);
|
||||
let heap_end_page = Page::<Size4KiB>::containing_address(heap_end);
|
||||
Page::range_inclusive(heap_start_page, heap_end_page)
|
||||
};
|
||||
|
||||
for page in range {
|
||||
let frame = frame_allocator
|
||||
.allocate_frame()
|
||||
.ok_or(MapToError::FrameAllocationFailed)?;
|
||||
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_SIZE);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user