summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel.rs57
-rw-r--r--src/qemu/mod.rs31
-rw-r--r--src/tests.rs43
-rw-r--r--src/vga/.buffer.rs.swpbin20480 -> 0 bytes
4 files changed, 84 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);
- }
-}
diff --git a/src/qemu/mod.rs b/src/qemu/mod.rs
new file mode 100644
index 0000000..4c1ab37
--- /dev/null
+++ b/src/qemu/mod.rs
@@ -0,0 +1,31 @@
+//! # QEMU Crate
+//!
+//! Provide QEMU bindings
+
+/// # QEMU Exit Codes
+///
+/// Provides QEMU exit codes
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[repr(u32)]
+pub enum QemuExitCode {
+ /// # Success
+ ///
+ /// Exit QEMU successfully
+ Success = 0x10,
+ /// # Failure
+ ///
+ /// Exit QEMU with error
+ Failed = 0x11,
+}
+
+/// # Exit QEMU
+///
+/// Exit QEMU with an exit code
+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);
+ }
+}
diff --git a/src/tests.rs b/src/tests.rs
new file mode 100644
index 0000000..e26c87a
--- /dev/null
+++ b/src/tests.rs
@@ -0,0 +1,43 @@
+use crate::{serial_print,serial_println};
+use crate::qemu::*;
+
+/// # Testable trait
+///
+/// Trait for test functions
+pub trait Testable {
+ fn run(&self) -> ();
+}
+
+impl<T> Testable for T
+where
+ T: Fn(),
+{
+ /// # Default run
+ ///
+ /// Run each test and print results to output
+ fn run(&self) {
+ serial_print!("{}...\t", core::any::type_name::<T>());
+ self();
+ serial_println!("[ok]");
+ }
+}
+
+/// # Run tests
+///
+/// Run each of the tests
+#[cfg(test)]
+pub fn test_runner(tests: &[&dyn Testable]) {
+ serial_println!("Running {} tests", tests.len());
+ for test in tests {
+ test.run();
+ }
+ exit_qemu(QemuExitCode::Success);
+}
+
+/// # Trivial test
+///
+/// This test ought to succeed no matter what
+#[test_case]
+fn trivial_assertion() {
+ assert_eq!(1, 1);
+}
diff --git a/src/vga/.buffer.rs.swp b/src/vga/.buffer.rs.swp
deleted file mode 100644
index 012b7b1..0000000
--- a/src/vga/.buffer.rs.swp
+++ /dev/null
Binary files differ