massive memory problem averted: we were just being stupid like usual
This commit is contained in:
parent
d382b623a4
commit
ae7c97a77d
12 changed files with 67 additions and 16 deletions
|
|
@ -11,7 +11,6 @@ start:
|
||||||
push ebx
|
push ebx
|
||||||
|
|
||||||
call check_multiboot
|
call check_multiboot
|
||||||
|
|
||||||
call set_up_page_tables
|
call set_up_page_tables
|
||||||
|
|
||||||
; load the new gdt
|
; load the new gdt
|
||||||
|
|
@ -36,6 +35,10 @@ set_up_page_tables:
|
||||||
mov eax, 0b10000011 ; huge + present + writable
|
mov eax, 0b10000011 ; huge + present + writable
|
||||||
mov [p2_table], eax ; map first entry
|
mov [p2_table], eax ; map first entry
|
||||||
|
|
||||||
|
mov eax, 0b10000011 ; huge + present + writable
|
||||||
|
or eax, 0x400000 ; 4MB
|
||||||
|
mov [p2_table + 4], eax ; map second entry
|
||||||
|
|
||||||
mov eax, p2_table
|
mov eax, p2_table
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
ret
|
ret
|
||||||
|
|
@ -55,7 +58,7 @@ align 4096
|
||||||
p2_table:
|
p2_table:
|
||||||
resb 4096
|
resb 4096
|
||||||
stack_bottom:
|
stack_bottom:
|
||||||
resb 4096 * 4
|
resb 4096 * 3
|
||||||
stack_top:
|
stack_top:
|
||||||
|
|
||||||
section .gdt
|
section .gdt
|
||||||
|
|
|
||||||
|
|
@ -53,5 +53,6 @@ pub fn init() {
|
||||||
// .expect("could not allocate double fault stack");
|
// .expect("could not allocate double fault stack");
|
||||||
// println!("DF stack: {:#?}", double_fault_stack);
|
// println!("DF stack: {:#?}", double_fault_stack);
|
||||||
// flush!();
|
// flush!();
|
||||||
|
|
||||||
IDT.load();
|
IDT.load();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,9 @@ pub extern "x86-interrupt" fn page_fault(
|
||||||
println!("Error code: {:?}", code);
|
println!("Error code: {:?}", code);
|
||||||
println!("{:#?}", stack_frame);
|
println!("{:#?}", stack_frame);
|
||||||
flush!();
|
flush!();
|
||||||
|
unsafe {
|
||||||
|
asm!("hlt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exception!(x87_fpu, {});
|
exception!(x87_fpu, {});
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,6 @@ SECTIONS {
|
||||||
. = ALIGN(4K);
|
. = ALIGN(4K);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bss :
|
|
||||||
{
|
|
||||||
*(.bss .bss.*)
|
|
||||||
. = ALIGN(4K);
|
|
||||||
}
|
|
||||||
|
|
||||||
.gdt :
|
.gdt :
|
||||||
{
|
{
|
||||||
*(.gdt)
|
*(.gdt)
|
||||||
|
|
@ -66,4 +60,10 @@ SECTIONS {
|
||||||
*(.got.plt)
|
*(.got.plt)
|
||||||
. = ALIGN(4K);
|
. = ALIGN(4K);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bss :
|
||||||
|
{
|
||||||
|
*(.bss .bss.*)
|
||||||
|
. = ALIGN(4K);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ pub unsafe extern "C" fn x86_rust_start(multiboot_info_addr: usize) {
|
||||||
// parse multiboot2 info
|
// parse multiboot2 info
|
||||||
let boot_info = multiboot2::load(multiboot_info_addr);
|
let boot_info = multiboot2::load(multiboot_info_addr);
|
||||||
|
|
||||||
|
// println!("{:?}", boot_info);
|
||||||
|
// flush!();
|
||||||
|
// asm!("hlt");
|
||||||
|
|
||||||
// ACPI must be intialized BEFORE paging is active
|
// ACPI must be intialized BEFORE paging is active
|
||||||
if let Some(rsdp) = boot_info.rsdp_v2_tag() {
|
if let Some(rsdp) = boot_info.rsdp_v2_tag() {
|
||||||
acpi::load(rsdp).expect("ACPI failed");
|
acpi::load(rsdp).expect("ACPI failed");
|
||||||
|
|
@ -26,15 +30,28 @@ pub unsafe extern "C" fn x86_rust_start(multiboot_info_addr: usize) {
|
||||||
acpi::init().expect("ACPI failed");
|
acpi::init().expect("ACPI failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill and load idt (exceptions + irqs)
|
|
||||||
idt::init();
|
|
||||||
|
|
||||||
// set up physical allocator
|
// set up physical allocator
|
||||||
::memory::init(&boot_info);
|
::memory::init(&boot_info);
|
||||||
|
|
||||||
// set up virtual mapping
|
// let memory_map_tag = boot_info.memory_map_tag().expect("Memory map tag required");
|
||||||
|
// println!("memory areas:");
|
||||||
|
// for area in memory_map_tag.memory_areas() {
|
||||||
|
// println!(
|
||||||
|
// " start: {:#x}, end: {:#x} length: {:#x}",
|
||||||
|
// area.start_address(),
|
||||||
|
// area.end_address(),
|
||||||
|
// area.size()
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// flush!();
|
||||||
|
// asm!("hlt");
|
||||||
|
|
||||||
|
// set up virtual addressing (paging)
|
||||||
let mut active_table = paging::init(&boot_info);
|
let mut active_table = paging::init(&boot_info);
|
||||||
|
|
||||||
|
// fill and load idt (exceptions + irqs)
|
||||||
|
idt::init();
|
||||||
|
|
||||||
// set up heap
|
// set up heap
|
||||||
::allocator::init(&mut active_table);
|
::allocator::init(&mut active_table);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use super::table::RecTable;
|
||||||
pub const P2: *mut PageTable = 0xffff_f000 as *mut _;
|
pub const P2: *mut PageTable = 0xffff_f000 as *mut _;
|
||||||
|
|
||||||
pub struct Mapper {
|
pub struct Mapper {
|
||||||
p2: Unique<PageTable>,
|
pub p2: Unique<PageTable>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mapper {
|
impl Mapper {
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,12 @@ impl InactivePageTable {
|
||||||
temporary_page: &mut TemporaryPage,
|
temporary_page: &mut TemporaryPage,
|
||||||
) -> InactivePageTable {
|
) -> InactivePageTable {
|
||||||
{
|
{
|
||||||
|
println!("mapping temp page:");
|
||||||
|
println!("frame: {:?}", frame);
|
||||||
|
flush!();
|
||||||
|
// unsafe {
|
||||||
|
// asm!("hlt");
|
||||||
|
// }
|
||||||
let table = temporary_page.map_table_frame(frame.clone(), active_table);
|
let table = temporary_page.map_table_frame(frame.clone(), active_table);
|
||||||
|
|
||||||
table.zero();
|
table.zero();
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ fn print_line(line: &[u8], address: usize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print the kernel stack
|
/// Print the kernel stack
|
||||||
fn print_stack() -> Result<(), &'static str> {
|
pub fn print_stack() -> Result<(), &'static str> {
|
||||||
let esp: usize;
|
let esp: usize;
|
||||||
let ebp: usize;
|
let ebp: usize;
|
||||||
unsafe { asm!("" : "={esp}"(esp), "={ebp}"(ebp):::) };
|
unsafe { asm!("" : "={esp}"(esp), "={ebp}"(ebp):::) };
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line:
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const HEAP_START: usize = (1 << 22); //first entry of p2
|
pub const HEAP_START: usize = (2 << 22); //third entry of p2
|
||||||
pub const HEAP_SIZE: usize = 10 * 4096 * 8; //~ 100 KiB
|
pub const HEAP_SIZE: usize = 10 * 4096 * 8; //~ 100 KiB
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,12 @@ impl FrameAllocator for BumpFrameAllocator {
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
// println!("allocate {}", count);
|
||||||
|
// println!("kstart {:?}", self.kernel_start);
|
||||||
|
// println!("kend {:?}", self.kernel_end);
|
||||||
|
// println!("multiboot start {:?}", self.multiboot_start);
|
||||||
|
// println!("multiboot end {:?}", self.multiboot_end);
|
||||||
|
// flush!();
|
||||||
if let Some(area) = self.current_area {
|
if let Some(area) = self.current_area {
|
||||||
let start_frame = PhysFrame {
|
let start_frame = PhysFrame {
|
||||||
number: self.next_free_frame.number,
|
number: self.next_free_frame.number,
|
||||||
|
|
@ -68,6 +74,7 @@ impl FrameAllocator for BumpFrameAllocator {
|
||||||
|
|
||||||
let current_area_last_frame =
|
let current_area_last_frame =
|
||||||
PhysFrame::containing_address(PhysAddr::new(area.end_address() as u32));
|
PhysFrame::containing_address(PhysAddr::new(area.end_address() as u32));
|
||||||
|
|
||||||
if end_frame > current_area_last_frame {
|
if end_frame > current_area_last_frame {
|
||||||
// all frames are taken in this area
|
// all frames are taken in this area
|
||||||
self.choose_next_area();
|
self.choose_next_area();
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,20 @@ pub fn init(boot_info: &multiboot2::BootInformation) {
|
||||||
memory_map_tag.memory_areas(),
|
memory_map_tag.memory_areas(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
println!("memory areas from the f allocator:");
|
||||||
|
for area in memory_map_tag.memory_areas() {
|
||||||
|
println!(
|
||||||
|
" start: {:#x}, end: {:#x} length: {:#x}",
|
||||||
|
area.start_address(),
|
||||||
|
area.end_address(),
|
||||||
|
area.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
flush!();
|
||||||
|
// unsafe {
|
||||||
|
// asm!("hlt");
|
||||||
|
// }
|
||||||
|
|
||||||
let frame_allocator = RecycleAllocator::new(bump_allocator);
|
let frame_allocator = RecycleAllocator::new(bump_allocator);
|
||||||
|
|
||||||
// let stack_allocator = {
|
// let stack_allocator = {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit b61535ecda89a6588a2c092dfa3bfbcc7f841575
|
Subproject commit ae98bfcd4f30217a4bfe944549d222bb07f81deb
|
||||||
Loading…
Reference in a new issue