forked from rust-osdev/bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_boot_info.rs
50 lines (40 loc) · 1.61 KB
/
check_boot_info.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points
use bootloader_api::{entry_point, info::PixelFormat, BootInfo};
use test_kernel_pie::{exit_qemu, QemuExitCode};
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
// check memory regions
assert!(boot_info.memory_regions.len() > 4);
// check framebuffer
let framebuffer = boot_info.framebuffer.as_ref().unwrap();
assert_eq!(framebuffer.info().byte_len, framebuffer.buffer().len());
if ![3, 4].contains(&framebuffer.info().bytes_per_pixel) {
panic!(
"unexpected bytes_per_pixel `{}`",
framebuffer.info().bytes_per_pixel
);
}
assert_eq!(framebuffer.info().pixel_format, PixelFormat::Bgr);
assert_eq!(
framebuffer.buffer().len(),
framebuffer.info().stride * framebuffer.info().height * framebuffer.info().bytes_per_pixel
);
// check defaults for optional features
assert_eq!(boot_info.physical_memory_offset.into_option(), None);
assert_eq!(boot_info.recursive_index.into_option(), None);
// check rsdp_addr
let rsdp = boot_info.rsdp_addr.into_option().unwrap();
assert!(rsdp > 0x000E0000);
// the test kernel has no TLS template
assert_eq!(boot_info.tls_template.into_option(), None);
exit_qemu(QemuExitCode::Success);
}
/// This function is called on panic.
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;
let _ = writeln!(test_kernel_pie::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}