Skip to content

Commit 0c8a15b

Browse files
committed
Add test that lower memory is actually writable
The "lower_mem_free" test will now also try to write to all usable regions below 1GB. This way we ensure that regions below 1Mb are writable and that bios and uefi bootloader correctly mark regions as used.
1 parent c9d6d11 commit 0c8a15b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/test_kernels/lower_memory_free/src/bin/lower_memory_free.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
#![no_std] // don't link the Rust standard library
22
#![no_main] // disable all Rust-level entry points
33

4-
use bootloader_api::{entry_point, info::MemoryRegionKind, BootInfo};
4+
use bootloader_api::{
5+
config::Mapping, entry_point, info::MemoryRegionKind, BootInfo, BootloaderConfig,
6+
};
57
use test_kernel_lower_memory_free::{exit_qemu, QemuExitCode};
68

79
const LOWER_MEMORY_END_PAGE: u64 = 0x0010_0000;
810

9-
entry_point!(kernel_main);
11+
pub const BOOTLOADER_CONFIG: BootloaderConfig = {
12+
let mut config = BootloaderConfig::new_default();
13+
config.mappings.physical_memory = Some(Mapping::FixedAddress(0x0000_4000_0000_0000));
14+
config
15+
};
16+
17+
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);
1018

1119
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
1220
use core::fmt::Write;
1321
use test_kernel_lower_memory_free::serial;
1422

23+
let phys_mem_offset = boot_info.physical_memory_offset.into_option().unwrap();
24+
1525
let mut count = 0;
1626
for region in boot_info.memory_regions.iter() {
1727
writeln!(
@@ -24,6 +34,14 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
2434
.unwrap();
2535
if region.kind == MemoryRegionKind::Usable && region.start < LOWER_MEMORY_END_PAGE {
2636
let end = core::cmp::min(region.end, LOWER_MEMORY_END_PAGE);
37+
38+
// ensure region is actually writable
39+
let addr = phys_mem_offset + region.start;
40+
let size = end - region.start;
41+
unsafe {
42+
core::ptr::write_bytes(addr as *mut u8, 0xff, size as usize);
43+
}
44+
2745
let pages = (end - region.start) / 4096;
2846
count += pages;
2947
}

0 commit comments

Comments
 (0)