This commit is contained in:
parent
6aa70f2012
commit
f930bb2fd0
6 changed files with 46 additions and 32 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -64,7 +64,7 @@ dependencies = [
|
|||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.91",
|
||||
"syn 2.0.92",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -102,9 +102,6 @@ name = "buddy_system_allocator"
|
|||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1a0108968a3a2dab95b089c0fc3f1afa7759aa5ebe6f1d86d206d6f7ba726eb"
|
||||
dependencies = [
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
|
@ -320,7 +317,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 2.0.91",
|
||||
"syn 2.0.92",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -354,9 +351,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
@ -423,15 +420,6 @@ version = "1.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static-alloc"
|
||||
version = "0.2.5"
|
||||
|
@ -454,9 +442,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.91"
|
||||
version = "2.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
|
||||
checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -502,7 +490,7 @@ checksum = "9b24e77d3fc1e617051e630f99da24bcae6328abab37b8f9216bb68d06804f9a"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.91",
|
||||
"syn 2.0.92",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -5,14 +5,14 @@ edition = "2021"
|
|||
license = "Unlicense"
|
||||
|
||||
[dependencies]
|
||||
acpi = {version = "5.1.0", default-features = false}
|
||||
acpica-rs = {path = "../lib/acpica-rs"}
|
||||
acpi = { version = "5.1.0", default-features = false }
|
||||
acpica-rs = { path = "../lib/acpica-rs" }
|
||||
bitfield = "0.17.0"
|
||||
bitvec = {version = "1.0.1", default-features = false, features = ["alloc", "atomic"]}
|
||||
buddy_system_allocator = "0.11.0"
|
||||
elf = {version = "0.7.4", default-features = false}
|
||||
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "atomic"] }
|
||||
buddy_system_allocator = { version = "0.11.0", default-features = false }
|
||||
elf = { version = "0.7.4", default-features = false }
|
||||
embedded-graphics = "0.8.1"
|
||||
kernel-common = {path = "../lib/kernel-common"}
|
||||
kernel-common = { path = "../lib/kernel-common" }
|
||||
lock_api = "0.4.12"
|
||||
log = "0.4.22"
|
||||
raw-cpuid = "11.2.0"
|
||||
|
|
|
@ -14,7 +14,6 @@ use core::{
|
|||
use acpi::AcpiTables;
|
||||
use acpica_rs::{AcpiEnableSubsystem, AcpiInitializeObjects, AcpiInitializeSubsystem, AcpiInitializeTables, AcpiLoadTables, ACPI_FULL_INITIALIZATION};
|
||||
use alloc::format;
|
||||
use buddy_system_allocator::LockedHeap;
|
||||
use cpu::{cpu::set_cpu_flags, gdt::setup_gdt, idt::setup_idt, paging::setup_paging};
|
||||
use kernel_common::{
|
||||
instructions::{cli, hlt},
|
||||
|
@ -23,7 +22,10 @@ use kernel_common::{
|
|||
paging::{KERNEL_HEAP_INITIAL_SIZE, KERNEL_HEAP_START},
|
||||
};
|
||||
use log::{error, info};
|
||||
use misc::display::{setup_display, PANIC_DISPLAY};
|
||||
use misc::{
|
||||
alloc::ALLOCATOR,
|
||||
display::{setup_display, PANIC_DISPLAY},
|
||||
};
|
||||
use sys::{
|
||||
acpica_osl::AE_OK,
|
||||
early_acpi::EarlyACPIHandler,
|
||||
|
@ -42,8 +44,6 @@ mod cpu;
|
|||
mod misc;
|
||||
mod sys;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: LockedHeap<32> = LockedHeap::empty();
|
||||
pub static RSDP_ADDRESS: AtomicU64 = AtomicU64::new(0);
|
||||
static LOADER_STRUCT: Spinlock<LoaderStruct> = Spinlock::new(LoaderStruct {
|
||||
magic: 0,
|
||||
|
@ -74,7 +74,7 @@ const INIT_BINARY: &[u8] = include_bytes!("../../target/x86_64-unknown-os/releas
|
|||
#[no_mangle]
|
||||
extern "C" fn early_main(temp_loader_struct: *const LoaderStruct) -> ! {
|
||||
unsafe {
|
||||
ALLOC.lock().init(KERNEL_HEAP_START as usize, KERNEL_HEAP_INITIAL_SIZE);
|
||||
ALLOCATOR.heap.lock().init(KERNEL_HEAP_START as usize, KERNEL_HEAP_INITIAL_SIZE);
|
||||
}
|
||||
let mut loader_struct = LOADER_STRUCT.lock();
|
||||
unsafe {
|
||||
|
|
25
kernel/src/misc/alloc.rs
Normal file
25
kernel/src/misc/alloc.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use core::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
ptr::NonNull,
|
||||
};
|
||||
|
||||
use buddy_system_allocator::Heap;
|
||||
|
||||
use crate::sys::locks::Spinlock;
|
||||
|
||||
pub struct KernelAllocator {
|
||||
pub heap: Spinlock<Heap<32>>,
|
||||
}
|
||||
|
||||
unsafe impl GlobalAlloc for KernelAllocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
self.heap.lock().alloc(layout).unwrap().as_ptr()
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
self.heap.lock().dealloc(NonNull::new(ptr).unwrap(), layout);
|
||||
}
|
||||
}
|
||||
|
||||
#[global_allocator]
|
||||
pub static ALLOCATOR: KernelAllocator = KernelAllocator { heap: Spinlock::new(Heap::new()) };
|
|
@ -1,3 +1,4 @@
|
|||
pub mod alloc;
|
||||
pub mod display;
|
||||
mod draw_target;
|
||||
pub mod elf;
|
||||
|
|
|
@ -5,8 +5,8 @@ edition = "2021"
|
|||
license = "Unlicense"
|
||||
|
||||
[dependencies]
|
||||
elf = {version = "0.7.4", default-features = false}
|
||||
kernel-common = {path = "../lib/kernel-common"}
|
||||
elf = { version = "0.7.4", default-features = false }
|
||||
kernel-common = { path = "../lib/kernel-common" }
|
||||
log = "0.4.22"
|
||||
raw-cpuid = "11.2.0"
|
||||
static-alloc = "0.2.5"
|
||||
|
|
Loading…
Add table
Reference in a new issue