diff options
| author | Christian Cunningham <c@localhost> | 2022-08-22 21:39:16 -0700 |
|---|---|---|
| committer | Christian Cunningham <c@localhost> | 2022-08-22 21:39:16 -0700 |
| commit | 3a0752f734f4370a05e45958499ddd9c3a4b3919 (patch) | |
| tree | 5ee9794f7f9804ef961b9d5126ea0171b8739668 /src/kernel.rs | |
| parent | c238b2ea1dff60a5be6a796f44e533e89a346199 (diff) | |
Modularize
Diffstat (limited to 'src/kernel.rs')
| -rw-r--r-- | src/kernel.rs | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/src/kernel.rs b/src/kernel.rs index cf594cd..514596d 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -9,28 +9,17 @@ #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] +mod qemu; +mod serial; mod sync; +mod tests; mod vga; -mod serial; -use vga::*; +use qemu::*; use serial::*; +use tests::*; +use vga::*; use core::panic::PanicInfo; -pub trait Testable { - fn run(&self) -> (); -} - -impl<T> Testable for T -where - T: Fn(), -{ - fn run(&self) { - serial_print!("{}...\t", core::any::type_name::<T>()); - self(); - serial_println!("[ok]"); - } -} - /// This function is called on panic. #[cfg(test)] #[panic_handler] @@ -49,11 +38,15 @@ fn panic(info: &PanicInfo) -> ! { loop {} } +/// # Initialization +/// +/// Provides serial and VGA initialization. fn kernel_init() { WRITER.init(); SERIAL1.init(); } +/// # x86_64 Kernel #[no_mangle] pub extern "C" fn _start() -> ! { kernel_init(); @@ -70,33 +63,3 @@ pub extern "C" fn _start() -> ! { loop {} } - -#[cfg(test)] -fn test_runner(tests: &[&dyn Testable]) { - serial_println!("Running {} tests", tests.len()); - for test in tests { - test.run(); - } - exit_qemu(QemuExitCode::Success); -} - -#[test_case] -fn trivial_assertion() { - assert_eq!(1, 1); -} - -#[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::port::Port; - - unsafe { - let mut port = Port::new(0xf4); - port.write(exit_code as u32); - } -} |
