minor changes & work on threading
This commit is contained in:
@@ -7,12 +7,17 @@
|
|||||||
> - [ ] write a script to run tests
|
> - [ ] write a script to run tests
|
||||||
> - [ ] a release should only be published if all tests pass
|
> - [ ] a release should only be published if all tests pass
|
||||||
|
|
||||||
|
> [!todo] Memory
|
||||||
|
> - [ ] make sure page tables are correct. we're still getting the annoying page fault errors for the APIC
|
||||||
|
> - [ ] page allocator
|
||||||
|
> - [ ] e
|
||||||
|
|
||||||
> [!todo] Allocator
|
> [!todo] Allocator
|
||||||
> - [ ] learn about several allocator designs and decide on the optimal one
|
> - [x] learn about several allocator designs and decide on the optimal one
|
||||||
> - [ ] implementation
|
> - [x] implementation
|
||||||
> - [ ] implement an allocate method
|
> - [x] implement an allocate method
|
||||||
> - [ ] implement a deallocate method
|
> - [x] implement a deallocate method
|
||||||
> - [ ] set the global allocator
|
> - [x] set the global allocator
|
||||||
> - [ ] testing
|
> - [ ] testing
|
||||||
> - [ ] write unit tests
|
> - [ ] write unit tests
|
||||||
> - [ ] many allocations
|
> - [ ] many allocations
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ pub unsafe fn alloc_stack(
|
|||||||
) -> Result<StackBounds, mapper::MapToError<Size4KiB>> { unsafe {
|
) -> Result<StackBounds, mapper::MapToError<Size4KiB>> { unsafe {
|
||||||
use x86_64::structures::paging::PageTableFlags as Flags;
|
use x86_64::structures::paging::PageTableFlags as Flags;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let guard_page = reserve_stack_memory(size_in_pages + 1);
|
let guard_page = reserve_stack_memory(size_in_pages + 1);
|
||||||
let stack_start = guard_page + 1;
|
let stack_start = guard_page + 1;
|
||||||
let stack_end = stack_start + size_in_pages;
|
let stack_end = stack_start + size_in_pages;
|
||||||
|
|||||||
@@ -58,24 +58,18 @@ pub struct FoundryOSFrameAllocator {
|
|||||||
next: usize,
|
next: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_frame_allocator(memory_map: &'static MemoryMapResponse) {
|
|
||||||
unsafe {
|
|
||||||
FRAME_ALLOCATOR.call_once(|| Mutex::new(FoundryOSFrameAllocator::init(memory_map)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FoundryOSFrameAllocator {
|
impl FoundryOSFrameAllocator {
|
||||||
/// Creates a new `FoundryOSFrameAllocator` from a memory map.
|
/// Creates a new `FoundryOSFrameAllocator` from a memory map.
|
||||||
///
|
///
|
||||||
/// This function takes a reference to a `MemoryMapResponse` and initializes a
|
/// This function takes a reference to a `MemoryMapResponse` and initializes a
|
||||||
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
|
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
|
||||||
/// the first frame to be allocated is the first frame in the memory map.
|
/// the first frame to be allocated is the first frame in the memory map.
|
||||||
pub const unsafe fn init(memory_map: &'static MemoryMapResponse) -> Self {
|
pub unsafe fn init(memory_map: &'static MemoryMapResponse) { unsafe {
|
||||||
Self {
|
FRAME_ALLOCATOR.call_once(|| Mutex::new(Self {
|
||||||
memory_map,
|
memory_map,
|
||||||
next: 0,
|
next: 0,
|
||||||
}
|
}));
|
||||||
}
|
}}
|
||||||
|
|
||||||
pub fn count_usable_frames(&self) -> u32 {
|
pub fn count_usable_frames(&self) -> u32 {
|
||||||
self.usable_frames().count() as u32
|
self.usable_frames().count() as u32
|
||||||
@@ -89,11 +83,8 @@ impl FoundryOSFrameAllocator {
|
|||||||
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + use<> {
|
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + use<> {
|
||||||
let regions = self.memory_map.entries().iter();
|
let regions = self.memory_map.entries().iter();
|
||||||
let usable_regions = regions.filter(|region| region.entry_type == EntryType::USABLE);
|
let usable_regions = regions.filter(|region| region.entry_type == EntryType::USABLE);
|
||||||
|
|
||||||
let addr_ranges = usable_regions.map(|region| region.base..region.base + region.length);
|
let addr_ranges = usable_regions.map(|region| region.base..region.base + region.length);
|
||||||
|
|
||||||
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
|
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
|
||||||
|
|
||||||
frame_addresses.map(|addr| PhysFrame::from_start_address(PhysAddr::new(addr)).unwrap())
|
frame_addresses.map(|addr| PhysFrame::from_start_address(PhysAddr::new(addr)).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,36 +105,4 @@ unsafe impl FrameAllocator<Size4KiB> for FoundryOSFrameAllocator {
|
|||||||
self.next += 1;
|
self.next += 1;
|
||||||
frame
|
frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub unsafe fn translate_addr(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
|
|
||||||
// translate_addr_inner(addr, physical_memory_offset)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn translate_addr_inner(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
|
|
||||||
// let (l4_table_frame, _) = Cr3::read();
|
|
||||||
|
|
||||||
// let table_indexes = [
|
|
||||||
// addr.p4_index(),
|
|
||||||
// addr.p3_index(),
|
|
||||||
// addr.p2_index(),
|
|
||||||
// addr.p1_index(),
|
|
||||||
// ];
|
|
||||||
// let mut frame = l4_table_frame;
|
|
||||||
|
|
||||||
// for &i in &table_indexes {
|
|
||||||
// let virt = physical_memory_offset + frame.start_address().as_u64();
|
|
||||||
// let table_ptr: *const PageTable = virt.as_ptr();
|
|
||||||
// let table = unsafe { &*table_ptr };
|
|
||||||
|
|
||||||
// let entry = &table[i];
|
|
||||||
|
|
||||||
// frame = match entry.frame() {
|
|
||||||
// Ok(frame) => frame,
|
|
||||||
// Err(FrameError::FrameNotPresent) => return None,
|
|
||||||
// Err(FrameError::HugeFrame) => panic!("huge frames are not supported!"),
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Some(frame.start_address() + u64::from(addr.page_offset()))
|
|
||||||
// }
|
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod async_io;
|
pub mod async_io;
|
||||||
pub mod threading;
|
pub mod threading;
|
||||||
|
mod taskrunner;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
|
pub struct Task {
|
||||||
|
pid: usize,
|
||||||
|
task: Box<dyn Fn() + Send + 'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Task {
|
||||||
|
pub fn new() {}
|
||||||
|
|
||||||
|
pub fn run() {}
|
||||||
|
}
|
||||||
+3
-2
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::x86_64::memory::{init_frame_allocator, init_page_table},
|
arch::x86_64::memory::init_page_table,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use arch::x86_64::memory::allocation::heap_alloc::init_heap;
|
use arch::x86_64::memory::allocation::heap_alloc::init_heap;
|
||||||
@@ -21,6 +21,7 @@ use arch::x86_64::memory::memory_map;
|
|||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
use limine::BaseRevision;
|
use limine::BaseRevision;
|
||||||
use x86_64::VirtAddr;
|
use x86_64::VirtAddr;
|
||||||
|
use crate::arch::x86_64::memory::FoundryOSFrameAllocator;
|
||||||
|
|
||||||
pub mod arch;
|
pub mod arch;
|
||||||
pub mod resources;
|
pub mod resources;
|
||||||
@@ -89,7 +90,7 @@ pub fn boot() -> Result<(), &'static str> {
|
|||||||
println_log!("[Success]");
|
println_log!("[Success]");
|
||||||
|
|
||||||
print_log!(" Setting Up Page Table... ");
|
print_log!(" Setting Up Page Table... ");
|
||||||
init_frame_allocator(memory_map);
|
unsafe { FoundryOSFrameAllocator::init(memory_map) };
|
||||||
println_log!("[Success]");
|
println_log!("[Success]");
|
||||||
|
|
||||||
print_log!(" Initialising Heap... ");
|
print_log!(" Initialising Heap... ");
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub mod window;
|
|||||||
pub trait Application {
|
pub trait Application {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
async fn run(&mut self, args: Vec<String>) -> Result<Self::Output, Error>;
|
fn run(&mut self, args: Vec<String>) -> impl Future<Output = Result<Self::Output, Error>> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -47,6 +47,32 @@ pub fn include_font(item: TokenStream) -> TokenStream {
|
|||||||
|
|
||||||
struct Font([[u8; 16]; 512]);
|
struct Font([[u8; 16]; 512]);
|
||||||
|
|
||||||
|
struct FontData {
|
||||||
|
width: u8,
|
||||||
|
height: u8,
|
||||||
|
length: u16,
|
||||||
|
data: Vec<Glyph>,
|
||||||
|
unicode_table: [[u8; 2]; 512],
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Glyph {
|
||||||
|
bytes: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum FontBuilder {
|
||||||
|
Psf1,
|
||||||
|
Psf2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FontBuilder {
|
||||||
|
const PSF1_MAGIC: u16 = 0x3604;
|
||||||
|
const PSF2_MAGIC: u32 = 0x72b54a86;
|
||||||
|
|
||||||
|
pub fn load() -> Option<Self> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Font {
|
impl Font {
|
||||||
const MAGIC: u16 = 0x3604;
|
const MAGIC: u16 = 0x3604;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user