From fe157268a376f5b945f1d64629e051340b06e6f2 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 19 Aug 2022 23:13:53 -0700 Subject: New allocation --- src/kernel.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/kernel.rs') diff --git a/src/kernel.rs b/src/kernel.rs index 3f10849..19c4e5f 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -12,10 +12,14 @@ #![feature(panic_info_message)] #![feature(trait_alias)] #![feature(exclusive_range_pattern)] +#![feature(default_alloc_error_handler)] #![no_main] #![no_std] -mod alloc; +extern crate alloc; +use alloc::boxed::Box; + +mod mem; mod console; mod cpu; mod panic_wait; @@ -23,7 +27,8 @@ mod print; mod sync; mod uart; use crate::console::console; -use crate::alloc::*; +use crate::mem::alloc::*; +//use crate::sync::interface::Mutex; /// # Initialization Code /// @@ -36,6 +41,10 @@ use crate::alloc::*; unsafe fn kernel_init() -> ! { console().init().unwrap(); U64_QUEUE_ALLOCATOR.init(); + ALLOCATOR.init(); + //ALLOCATOR.lock(|qa| { + // qa.init(); + //}); kernel_main() } @@ -43,16 +52,28 @@ unsafe fn kernel_init() -> ! { /// /// TODO: Figure out what to do here fn kernel_main() -> ! { - for idx in 0..30 { + for idx in 0..5 { if let Some(cell) = U64_QUEUE_ALLOCATOR.alloc() { let inner = cell.inner(); *inner = idx; - println!("SUCCESS: Allocated a char! {:?}", cell); + println!("SUCCESS: Allocated a char! {:?} {:?}", cell, U64_QUEUE_ALLOCATOR); U64_QUEUE_ALLOCATOR.free(cell); } else { - println!("ERROR: No more chars remaining!"); + println!("ERROR: No more chars remaining! {:?}", U64_QUEUE_ALLOCATOR); } } println!("I should be able to print {} here!", 5); + { + let a: Box = Box::new(5); + println!("{:?}", a); + let b: Box = Box::new(7); + println!("{:?}", b); + } + { + let a: Box = Box::new(8); + println!("{:?}", a); + let b: Box = Box::new(9); + println!("{:?}", b); + } loop { } } -- cgit v1.2.1