From 0d061dac9e31831e4fe426a0df777463043868d7 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 19 Aug 2022 20:20:16 -0700 Subject: Generic Allocation Scheme --- src/kernel.rs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/kernel.rs') diff --git a/src/kernel.rs b/src/kernel.rs index 9377eb5..3f10849 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -1,4 +1,10 @@ -//! Kernel Code +//! # Kernel Code +//! +//! ## Initializes the peripherals +//! - UART +//! - Allocators + +#![doc(html_logo_url = "https://raw.githubusercontent.com/rust-embedded/wg/master/assets/logo/ewg-logo-blue-white-on-transparent.png")] #![allow(non_snake_case)] #![allow(clippy::upper_case_acronyms,dead_code)] @@ -17,24 +23,34 @@ mod print; mod sync; mod uart; use crate::console::console; -use crate::alloc::CHAR_ALLOCATOR; +use crate::alloc::*; -/// Initialization Code +/// # Initialization Code +/// +/// Initializes +/// - Allocators +/// - UART +/// +/// After initialization, jump to +/// the regular main. unsafe fn kernel_init() -> ! { console().init().unwrap(); - CHAR_ALLOCATOR.init(); + U64_QUEUE_ALLOCATOR.init(); kernel_main() } -/// Post init +/// # Post-initialization +/// +/// TODO: Figure out what to do here fn kernel_main() -> ! { for idx in 0..30 { - if let Some(cell) = CHAR_ALLOCATOR.alloc() { - cell.data = ('0' as u8 + idx as u8) as char; - println!("SUCCESS: Allocated a char! {:?} {:?}", cell, CHAR_ALLOCATOR); - CHAR_ALLOCATOR.free(cell); + if let Some(cell) = U64_QUEUE_ALLOCATOR.alloc() { + let inner = cell.inner(); + *inner = idx; + println!("SUCCESS: Allocated a char! {:?}", cell); + U64_QUEUE_ALLOCATOR.free(cell); } else { - println!("ERROR: No more chars remaining! {:?}", CHAR_ALLOCATOR); + println!("ERROR: No more chars remaining!"); } } println!("I should be able to print {} here!", 5); -- cgit v1.2.1