Skip to content

Commit

Permalink
Fix random memory issues (#573)
Browse files Browse the repository at this point in the history
* Move AmlContext

* Add more information for already mapped pages

* Increase stack size for ACPI shutdown

* Refactor phys_to_virt
  • Loading branch information
vinc authored Feb 8, 2024
1 parent a511647 commit 13aeaeb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/sys/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ pub fn shutdown() {
let slp_len = 1 << 13;

log!("ACPI Shutdown\n");
let handler = Box::new(MorosAmlHandler);
let mut aml = AmlContext::new(handler, DebugVerbosity::None);
let res = unsafe { AcpiTables::search_for_rsdp_bios(MorosAcpiHandler) };
match res {
Ok(acpi) => {
Expand All @@ -36,6 +34,8 @@ pub fn shutdown() {
let table = unsafe {
core::slice::from_raw_parts(ptr , dsdt.length as usize)
};
let handler = Box::new(MorosAmlHandler);
let mut aml = AmlContext::new(handler, DebugVerbosity::None);
if aml.parse_table(table).is_ok() {
let name = AmlName::from_str("\\_S5").unwrap();
let res = aml.namespace.get_by_path(&name);
Expand All @@ -45,21 +45,22 @@ pub fn shutdown() {
}
}
} else {
debug!("ACPI Failed to parse AML in DSDT");
debug!("ACPI: Could not parse AML in DSDT");
// FIXME: AML parsing works on QEMU and Bochs but not
// on VirtualBox at the moment, so we use the following
// hardcoded value:
slp_typa = (5 & 7) << 10;
}
} else {
debug!("ACPI: Could not find DSDT in BIOS");
}
}
Err(_e) => {
debug!("ACPI Could not find RDSP in BIOS\n");
debug!("ACPI: Could not find RDSP in BIOS");
}
};

let mut port: Port<u16> = Port::new(pm1a_control_block as u16);
//debug!("ACPI shutdown");
unsafe {
port.write(slp_typa | slp_len);
}
Expand Down
3 changes: 3 additions & 0 deletions src/sys/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub fn alloc_pages(
mapping.flush();
} else {
debug!("Could not map {:?} to {:?}", page, frame);
if let Ok(old_frame) = mapper.translate_page(page) {
debug!("Aleardy mapped to {:?}", old_frame);
}
return Err(());
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use x86_64::structures::gdt::{
use x86_64::structures::tss::TaskStateSegment;
use x86_64::VirtAddr;

const STACK_SIZE: usize = 1024 * 8;
const STACK_SIZE: usize = 1024 * 8 * 16;
pub const DOUBLE_FAULT_IST: u16 = 0;
pub const PAGE_FAULT_IST: u16 = 1;
pub const GENERAL_PROTECTION_FAULT_IST: u16 = 2;
Expand Down
4 changes: 3 additions & 1 deletion src/sys/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ pub fn memory_size() -> u64 {
}

pub fn phys_to_virt(addr: PhysAddr) -> VirtAddr {
let phys_mem_offset = unsafe { PHYS_MEM_OFFSET.unwrap() };
let phys_mem_offset = unsafe {
PHYS_MEM_OFFSET.unwrap()
};
VirtAddr::new(addr.as_u64() + phys_mem_offset)
}

Expand Down

0 comments on commit 13aeaeb

Please sign in to comment.