Newer
Older
#![deny(
clippy::complexity,
clippy::correctness,
clippy::nursery,
clippy::pedantic,
clippy::perf,
clippy::restriction,
clippy::blanket_clippy_restriction_lints,
clippy::else_if_without_else,
clippy::exhaustive_enums,
clippy::exhaustive_structs,
clippy::match_same_arms,
clippy::match_wildcard_for_single_variants,
clippy::missing_trait_methods,
clippy::mod_module_files,
clippy::panic_in_result_fn,
clippy::pattern_type_mismatch,
clippy::separated_literal_suffix,
clippy::shadow_reuse,
clippy::shadow_unrelated,
clippy::unreachable,
clippy::unwrap_in_result,
clippy::wildcard_in_or_patterns,
const_item_mutation
)]
#![cfg_attr(
test,
allow(
clippy::assertions_on_result_states,
clippy::enum_glob_use,
clippy::indexing_slicing,
clippy::non_ascii_literal,
clippy::too_many_lines,
clippy::unwrap_used,
#![no_std]
#![no_main]
#![feature(abi_x86_interrupt)]
#![feature(alloc_error_handler)]
#![feature(const_convert)]
#![feature(const_mut_refs)]
#![feature(const_trait_impl)]
#![feature(custom_test_frameworks)]
#![feature(no_coverage)]
#![feature(once_cell)]
#![feature(strict_provenance)]
#![reexport_test_harness_main = "test_main"]
#![test_runner(test::runner)]
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
extern crate alloc;
mod encoding;
mod kernel;
mod macros;
mod user;
#[cfg(test)]
mod test;
use core::alloc::Layout;
use bootloader_api::config::{Mapping, Mappings};
use bootloader_api::{entry_point, BootInfo, BootloaderConfig};
use x86_64::instructions;
/// Configuration of the bootloader
///
/// The only change from the default configuration is the dynamic mapping to the physical memory
const BOOTLOADER_CONFIG: BootloaderConfig = {
let mut config = BootloaderConfig::new_default();
config.mappings = Mappings::new_default();
config.mappings.page_table_recursive = Some(Mapping::Dynamic);
config
};
/// Main function of the kernel
#[no_coverage]
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
kernel::init(boot_info);
#[cfg(test)]
test_main();
loop {
instructions::hlt();
}
}
/// Panic prints on screen the reason
#[panic_handler]
#[no_coverage]
fn panic(info: &core::panic::PanicInfo) -> ! {
#[cfg(not(test))]
{
println!("kernel panic: {:#?}", info);
loop {
instructions::hlt();
}
}
#[cfg(test)]
{
use qemu_exit::QEMUExit;
println!("[failed]\n");
println!("Error: {}\n", info);
qemu_exit::X86::new(0xf4, 13).exit_failure();
}
}
/// Allocation failure handler
#[alloc_error_handler]
#[no_coverage]
fn alloc_error_handler(layout: Layout) -> ! {
panic!("allocation error: {:?}", layout);
}
entry_point!(kernel_main, config = &BOOTLOADER_CONFIG);