summaryrefslogtreecommitdiff
path: root/src/kernel.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel.rs')
-rw-r--r--src/kernel.rs57
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);
- }
-}