From 0090db3c3cc7eb4b468333b6f738383c5c5e5f5d Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 20 Aug 2022 16:19:53 -0700 Subject: Standardize initialization reference --- src/kernel.rs | 11 ++--------- src/mem/alloc.rs | 7 +++++++ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/kernel.rs b/src/kernel.rs index 2dde7ac..28d8f87 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -17,7 +17,6 @@ #![no_std] extern crate alloc; -use alloc::boxed::Box; mod console; mod cpu; @@ -29,7 +28,7 @@ mod sync; mod uart; use crate::console::console; use crate::console::interface::Statistics; -use crate::mem::alloc::*; +use crate::mem::alloc::alloc; /// # Initialization Code /// @@ -41,7 +40,7 @@ use crate::mem::alloc::*; /// the regular main. unsafe fn kernel_init() -> ! { console().init().unwrap(); - ALLOCATOR.init(); + alloc().init(); kernel_main() } @@ -56,12 +55,6 @@ fn kernel_main() -> ! { println!("\x1b[91mInitialized\x1b[0m \x1b[92m{}\x1b[0m \x1b[93mv{}\x1b[0m", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); println!("\x1b[94mAuthors:\x1b[0m \x1b[95m{}\x1b[0m", env!("CARGO_PKG_AUTHORS")); - println!("Testing out allocations!"); - { - let a: Box = Box::new(u8::MAX); - let b: Box = Box::new(5); - println!("{:?} {:?}", a, b); - } println!("Characters written to UART: \x1b[91m{}\x1b[0m", console().chars_written()); loop { } } diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index 4d02ddd..fcd33c2 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -478,3 +478,10 @@ unsafe impl GlobalAlloc for GrandAllocator { /// The allocator of allocators. It hands out fixed sized memory chunks. #[global_allocator] pub static ALLOCATOR: GrandAllocator = GrandAllocator{}; + +/// # Global Allocator +/// +/// Returns a borrow for the Global Allocator +pub fn alloc() -> &'static crate::mem::alloc::GrandAllocator { + &crate::mem::alloc::ALLOCATOR +} -- cgit v1.2.1