mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Rewrite bump allocator and integrate it in main crate
This commit is contained in:
40
src/lib.rs
40
src/lib.rs
@@ -13,9 +13,13 @@
|
||||
#![feature(asm)]
|
||||
#![feature(naked_functions)]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
#![feature(const_unique_new)]
|
||||
#![feature(const_unique_new, const_atomic_usize_new)]
|
||||
#![feature(allocator_api)]
|
||||
#![feature(global_allocator)]
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
extern crate rlibc;
|
||||
extern crate volatile;
|
||||
extern crate spin;
|
||||
@@ -25,25 +29,15 @@ extern crate bitflags;
|
||||
extern crate x86_64;
|
||||
#[macro_use]
|
||||
extern crate once;
|
||||
extern crate bit_field;
|
||||
extern crate linked_list_allocator;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
extern crate hole_list_allocator as allocator;
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
|
||||
extern crate bit_field;
|
||||
#[macro_use]
|
||||
mod vga_buffer;
|
||||
mod memory;
|
||||
|
||||
mod interrupts;
|
||||
|
||||
|
||||
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
|
||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// ATTENTION: we have a very small stack and no guard page
|
||||
@@ -57,9 +51,13 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// set up guard page and map the heap pages
|
||||
let mut memory_controller = memory::init(boot_info);
|
||||
|
||||
unsafe {
|
||||
HEAP_ALLOCATOR.lock().init(HEAP_START, HEAP_START + HEAP_SIZE);
|
||||
}
|
||||
|
||||
// initialize our IDT
|
||||
interrupts::init(&mut memory_controller);
|
||||
|
||||
|
||||
fn stack_overflow() {
|
||||
stack_overflow(); // for each recursion, the return address is pushed
|
||||
}
|
||||
@@ -67,6 +65,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// trigger a stack overflow
|
||||
stack_overflow();
|
||||
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
}
|
||||
@@ -101,8 +100,13 @@ pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line:
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _Unwind_Resume() -> ! {
|
||||
loop {}
|
||||
}
|
||||
pub extern "C" fn _Unwind_Resume() -> ! { loop {} }
|
||||
|
||||
use linked_list_allocator::LockedHeap;
|
||||
|
||||
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
|
||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||
|
||||
#[global_allocator]
|
||||
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||
|
||||
Reference in New Issue
Block a user