Properly round MMIO page addresses
This commit is contained in:
parent
50322be602
commit
65c36cfa60
@ -141,8 +141,6 @@ unsafe extern "C" fn main() -> ! {
|
|||||||
log_info!("Hypervisor: {:?}", string.identify());
|
log_info!("Hypervisor: {:?}", string.identify());
|
||||||
}
|
}
|
||||||
|
|
||||||
SERIAL_3F8.lock().log_write("hi");
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
arch::asm::nop();
|
arch::asm::nop();
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,22 @@ lazy_static! {
|
|||||||
.expect("Bootloader did not supply memory map");
|
.expect("Bootloader did not supply memory map");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn round_up_to(multiple: usize, input: usize) -> usize {
|
||||||
|
if input % multiple == 0 {
|
||||||
|
input
|
||||||
|
} else {
|
||||||
|
input - (input % multiple) + multiple
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn round_down_to(multiple: usize, input: usize) -> usize {
|
||||||
|
if input % multiple == 0 {
|
||||||
|
input
|
||||||
|
} else {
|
||||||
|
input - (input % multiple)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deallocate_usable() -> Result<(), AllocError> {
|
pub fn deallocate_usable() -> Result<(), AllocError> {
|
||||||
init_statics();
|
init_statics();
|
||||||
let mut any_error: Option<AllocError> = None;
|
let mut any_error: Option<AllocError> = None;
|
||||||
@ -58,31 +74,19 @@ pub fn deallocate_hardware() -> Result<(), AllocError> {
|
|||||||
| (entry.entry_type == EntryType::FRAMEBUFFER)
|
| (entry.entry_type == EntryType::FRAMEBUFFER)
|
||||||
{
|
{
|
||||||
if let Err(error) = {
|
if let Err(error) = {
|
||||||
// Special handling for regions that are too small
|
let base: usize = round_down_to(PAGE_SIZE, entry.base as usize);
|
||||||
// TODO: fix
|
let mut length = entry.length as usize + (entry.base as usize - base);
|
||||||
let adjusted_base = if (entry.length as usize) < PAGE_SIZE {
|
length = round_up_to(PAGE_SIZE, length);
|
||||||
entry.base as usize - (PAGE_SIZE - entry.length as usize)
|
let range = PageRange::from_start_len(base, length);
|
||||||
} else {
|
|
||||||
entry.base as usize
|
|
||||||
};
|
|
||||||
let adjusted_length = if (entry.length as usize) < PAGE_SIZE {
|
|
||||||
PAGE_SIZE
|
|
||||||
} else {
|
|
||||||
entry.length as usize
|
|
||||||
};
|
|
||||||
let range = PageRange::from_start_len(adjusted_base, adjusted_length);
|
|
||||||
log_trace!(
|
|
||||||
"Deallocating 0x{:x} @ 0x{:x} hardware reserved memory",
|
|
||||||
adjusted_length,
|
|
||||||
adjusted_base
|
|
||||||
);
|
|
||||||
match range {
|
match range {
|
||||||
Ok(range_inner) => unsafe { HW_FREELIST.lock().deallocate(range_inner) },
|
Ok(range_inner) => unsafe { HW_FREELIST.lock().deallocate(range_inner) },
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log_error!(
|
log_error!(
|
||||||
"Failed to convert range 0x{:x} @ 0x{:x}: {}",
|
"Failed to convert range 0x{:x} @ 0x{:x} (original: 0x{:x} @ 0x{:x}): {}",
|
||||||
adjusted_length,
|
length,
|
||||||
adjusted_base,
|
base,
|
||||||
|
entry.length,
|
||||||
|
entry.base,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -170,6 +174,7 @@ pub fn log_memory() {
|
|||||||
);
|
);
|
||||||
log_trace!("Deallocating available memory...");
|
log_trace!("Deallocating available memory...");
|
||||||
let _ = deallocate_usable();
|
let _ = deallocate_usable();
|
||||||
|
log_trace!("Deallocating hardware reserved memory...");
|
||||||
let _ = deallocate_hardware();
|
let _ = deallocate_hardware();
|
||||||
let free_bytes = { FREELIST.lock().free_space() };
|
let free_bytes = { FREELIST.lock().free_space() };
|
||||||
log_info!(
|
log_info!(
|
||||||
|
Loading…
Reference in New Issue
Block a user