-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test to check usable memory is writable
split out the write check from the lower_memory_free test. Those 2 aren't really related
- Loading branch information
Showing
7 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "test_kernel_write_usable_memory" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bootloader_api = { path = "../../../api" } | ||
x86_64 = { version = "0.14.7", default-features = false, features = [ | ||
"instructions", | ||
"inline_asm", | ||
] } | ||
uart_16550 = "0.2.10" |
42 changes: 42 additions & 0 deletions
42
tests/test_kernels/write_usable_memory/src/bin/write_usable_memory.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#![no_std] // don't link the Rust standard library | ||
#![no_main] // disable all Rust-level entry points | ||
|
||
use bootloader_api::{ | ||
config::Mapping, entry_point, info::MemoryRegionKind, BootInfo, BootloaderConfig, | ||
}; | ||
use test_kernel_write_usable_memory::{exit_qemu, QemuExitCode}; | ||
|
||
pub const BOOTLOADER_CONFIG: BootloaderConfig = { | ||
let mut config = BootloaderConfig::new_default(); | ||
config.mappings.physical_memory = Some(Mapping::FixedAddress(0x0000_4000_0000_0000)); | ||
config | ||
}; | ||
|
||
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG); | ||
|
||
fn kernel_main(boot_info: &'static mut BootInfo) -> ! { | ||
let phys_mem_offset = boot_info.physical_memory_offset.into_option().unwrap(); | ||
|
||
for region in boot_info.memory_regions.iter() { | ||
if region.kind == MemoryRegionKind::Usable { | ||
// ensure region is actually writable | ||
let addr = phys_mem_offset + region.start; | ||
let size = region.end - region.start; | ||
unsafe { | ||
core::ptr::write_bytes(addr as *mut u8, 0xff, size as usize); | ||
} | ||
} | ||
} | ||
|
||
exit_qemu(QemuExitCode::Success); | ||
} | ||
|
||
/// This function is called on panic. | ||
#[panic_handler] | ||
#[cfg(not(test))] | ||
fn panic(info: &core::panic::PanicInfo) -> ! { | ||
use core::fmt::Write; | ||
|
||
let _ = writeln!(test_kernel_write_usable_memory::serial(), "PANIC: {}", info); | ||
exit_qemu(QemuExitCode::Failed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![no_std] | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
#[repr(u32)] | ||
pub enum QemuExitCode { | ||
Success = 0x10, | ||
Failed = 0x11, | ||
} | ||
|
||
pub fn exit_qemu(exit_code: QemuExitCode) -> ! { | ||
use x86_64::instructions::{nop, port::Port}; | ||
|
||
unsafe { | ||
let mut port = Port::new(0xf4); | ||
port.write(exit_code as u32); | ||
} | ||
|
||
loop { | ||
nop(); | ||
} | ||
} | ||
|
||
pub fn serial() -> uart_16550::SerialPort { | ||
let mut port = unsafe { uart_16550::SerialPort::new(0x3F8) }; | ||
port.init(); | ||
port | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use bootloader_test_runner::run_test_kernel; | ||
#[test] | ||
fn lower_memory_free() { | ||
run_test_kernel(env!( | ||
"CARGO_BIN_FILE_TEST_KERNEL_WRITE_USABLE_MEMORY_write_usable_memory" | ||
)); | ||
} |