diff --git a/Cargo.lock b/Cargo.lock index 850b6b4..32c5f2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,6 +384,7 @@ dependencies = [ name = "kernel" version = "0.1.2" dependencies = [ + "linked_list_allocator", "log", "versioning", ] diff --git a/ableos/src/arch/x86_64/drivers/allocator.rs b/ableos/src/arch/x86_64/drivers/allocator.rs index b1057be..14da406 100644 --- a/ableos/src/arch/x86_64/drivers/allocator.rs +++ b/ableos/src/arch/x86_64/drivers/allocator.rs @@ -1,4 +1,4 @@ -use crate::allocator::{HEAP_SIZE, HEAP_START}; +use kernel::allocator::{HEAP_SIZE, HEAP_START}; use alloc::alloc::{GlobalAlloc, Layout}; use core::ptr::null_mut; use x86_64::{ @@ -39,7 +39,7 @@ pub fn init_heap( } unsafe { - crate::allocator::ALLOCATOR + kernel::allocator::ALLOCATOR .lock() .init(HEAP_START, HEAP_SIZE); } diff --git a/ableos/src/experiments/kinfo.rs b/ableos/src/experiments/kinfo.rs index 46646db..fdacbb2 100644 --- a/ableos/src/experiments/kinfo.rs +++ b/ableos/src/experiments/kinfo.rs @@ -1,6 +1,7 @@ use super::systeminfo::SystemMemory; -use crate::{arch::drivers::sysinfo::master, ALLOCATOR}; +use crate::arch::drivers::sysinfo::master; use core::fmt::Display; +use kernel::allocator::ALLOCATOR; use versioning::Version; use x86_64::instructions::interrupts::{disable, enable}; diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 911b3e3..98892da 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -40,7 +40,6 @@ pub mod print; #[macro_use] pub mod serial_print; -pub mod allocator; pub mod boot_conf; pub mod devices; pub mod driver_traits; @@ -68,7 +67,6 @@ mod unicode_utils; #[prelude_import] pub use prelude::rust_2021::*; -pub use allocator::*; pub use driver_traits::*; pub use experiments::*; pub use graphics::*; diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index aae557b..7886826 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -2,13 +2,13 @@ use crate::arch::drivers::sysinfo::master; use crate::filesystem::FILE_SYSTEM; use crate::time::fetch_time; use crate::wasm_jumploader::interp; -use crate::ALLOCATOR; use crate::{ arch::{shutdown, sloop}, systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, KERNEL_STATE, }; use genfs::{Fs, OpenOptions}; +use kernel::allocator::ALLOCATOR; use rhai::Engine; use spin::Lazy; use x86_64::instructions::interrupts::{disable, enable}; diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index b6b5df2..8a86d74 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -4,7 +4,8 @@ name = "kernel" version = "0.1.2" [dependencies] +linked_list_allocator = "0.9" log = "0.4.14" [dependencies.versioning] -git = "https://git.ablecorp.us/able/aos_userland" \ No newline at end of file +git = "https://git.ablecorp.us/able/aos_userland" diff --git a/kernel/src/allocator.rs b/kernel/src/allocator.rs new file mode 100644 index 0000000..3c177d4 --- /dev/null +++ b/kernel/src/allocator.rs @@ -0,0 +1,24 @@ +//! Memory allocator + +use linked_list_allocator::LockedHeap; + +/// +pub const HEAP_START: usize = 0x_4444_4444_0000; + +/// +pub const HEAP_MULTIPLIER: usize = 100000; + +/// +pub const HEAP_BASE: usize = 100; + +/// +pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER; + +/// Global allocator +#[global_allocator] +pub static ALLOCATOR: LockedHeap = LockedHeap::empty(); + +#[alloc_error_handler] +fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { + panic!("allocation error: {:?}", layout) +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 4290210..53f1f73 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,10 +1,14 @@ //! The ableOS kernel. -#![deny(missing_docs)] -#![no_std] -#![feature(prelude_import)] +#![feature(alloc_error_handler)] #![feature(arbitrary_enum_discriminant)] +#![feature(prelude_import)] +#![no_std] +#![deny(missing_docs)] +extern crate alloc; + +pub mod allocator; pub mod device_interface; pub mod messaging; pub mod panic;