From beba2ae0ad95fef87ee9ab119bd3cca78bbba0ff Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 2 Mar 2022 08:38:22 -0600 Subject: [PATCH] modularizing the kernel --- ableos/Cargo.lock | 8 +++++++- ableos/src/devices/character_devs/dev_null.rs | 12 +++++++++--- ableos/src/devices/character_devs/dev_unicode.rs | 11 ++++++++++- ableos/src/devices/character_devs/dev_zero.rs | 8 +++++++- ableos/src/devices/character_devs/mod.rs | 2 ++ ableos/src/devices/mod.rs | 2 +- ableos/src/driver_traits/mod.rs | 2 -- kernel/Cargo.lock | 8 +++++++- kernel/Cargo.toml | 9 +++++++-- kernel/src/device_interface/block/mod.rs | 1 + .../src/device_interface/character/mod.rs | 7 +++++++ kernel/src/device_interface/mod.rs | 4 ++++ kernel/src/lib.rs | 16 ++++++++++++---- kernel/src/messaging.rs | 6 +++--- kernel/src/panic.rs | 2 +- kernel/src/{kernel_time.rs => time.rs} | 0 16 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 kernel/src/device_interface/block/mod.rs rename ableos/src/driver_traits/character_device.rs => kernel/src/device_interface/character/mod.rs (67%) create mode 100644 kernel/src/device_interface/mod.rs rename kernel/src/{kernel_time.rs => time.rs} (100%) diff --git a/ableos/Cargo.lock b/ableos/Cargo.lock index 5f0e17a8..59af6be1 100644 --- a/ableos/Cargo.lock +++ b/ableos/Cargo.lock @@ -273,9 +273,10 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "kernel" -version = "0.1.1" +version = "0.1.2" dependencies = [ "lazy_static", + "versioning", ] [[package]] @@ -775,6 +776,11 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "versioning" +version = "0.1.2" +source = "git+https://git.ablecorp.us/able/versioning#ef472283e6e7a2e395ee56434087b3a6fad53ff2" + [[package]] name = "vga" version = "0.2.7" diff --git a/ableos/src/devices/character_devs/dev_null.rs b/ableos/src/devices/character_devs/dev_null.rs index 405fb2fa..cb9dff76 100644 --- a/ableos/src/devices/character_devs/dev_null.rs +++ b/ableos/src/devices/character_devs/dev_null.rs @@ -1,6 +1,4 @@ -use alloc::string::String; - -use crate::character_device::CharacterDevice; +use kernel::device_interface::character::CharacterDevice; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -22,4 +20,12 @@ impl CharacterDevice for DevNull { fn write_char(&mut self, _: char) -> bool { true } + + fn reset(&mut self) { + todo!() + } + + fn initialize(&mut self) -> bool { + todo!() + } } diff --git a/ableos/src/devices/character_devs/dev_unicode.rs b/ableos/src/devices/character_devs/dev_unicode.rs index aa25ca0f..0ba03190 100644 --- a/ableos/src/devices/character_devs/dev_unicode.rs +++ b/ableos/src/devices/character_devs/dev_unicode.rs @@ -1,4 +1,4 @@ -use crate::character_device::CharacterDevice; +use kernel::device_interface::character::CharacterDevice; #[derive(Debug)] pub struct DevUnicode { @@ -29,6 +29,15 @@ impl CharacterDevice for DevUnicode { true } + + fn reset(&mut self) { + self.next_write_char = 0x00 as char; + self.next_read_char = 0x00 as char; + } + + fn initialize(&mut self) -> bool { + true + } } fn add1_char(c: char) -> char { diff --git a/ableos/src/devices/character_devs/dev_zero.rs b/ableos/src/devices/character_devs/dev_zero.rs index 09a1ad44..f5cc3b6c 100644 --- a/ableos/src/devices/character_devs/dev_zero.rs +++ b/ableos/src/devices/character_devs/dev_zero.rs @@ -1,4 +1,4 @@ -use crate::character_device::CharacterDevice; +use kernel::device_interface::character::CharacterDevice; #[derive(Debug)] pub struct DevZero; @@ -19,4 +19,10 @@ impl CharacterDevice for DevZero { fn write_char(&mut self, _: char) -> bool { true } + + fn reset(&mut self) {} + + fn initialize(&mut self) -> bool { + true + } } diff --git a/ableos/src/devices/character_devs/mod.rs b/ableos/src/devices/character_devs/mod.rs index 061ae6e0..9a2f2948 100644 --- a/ableos/src/devices/character_devs/mod.rs +++ b/ableos/src/devices/character_devs/mod.rs @@ -1,3 +1,5 @@ pub mod dev_null; pub mod dev_unicode; pub mod dev_zero; + +pub use kernel::device_interface::character::CharacterDevice; diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index 5631399d..ba340d21 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -9,7 +9,7 @@ use alloc::{ use hashbrown::HashMap; use pci::PCIDevice; -use crate::character_device::CharacterDevice; +use kernel::device_interface::character::CharacterDevice; // FIXME: This is a hack to hold a device. // #[derive(Debug)] diff --git a/ableos/src/driver_traits/mod.rs b/ableos/src/driver_traits/mod.rs index ec4063f2..b832ebf9 100644 --- a/ableos/src/driver_traits/mod.rs +++ b/ableos/src/driver_traits/mod.rs @@ -1,4 +1,2 @@ pub mod graphics; pub mod serial; - -pub mod character_device; diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 852bf6ce..b2f29bf8 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -4,9 +4,10 @@ version = 3 [[package]] name = "kernel" -version = "0.1.1" +version = "0.1.2" dependencies = [ "lazy_static", + "versioning", ] [[package]] @@ -14,3 +15,8 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "versioning" +version = "0.1.2" +source = "git+https://git.ablecorp.us/able/versioning#ef472283e6e7a2e395ee56434087b3a6fad53ff2" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 8f8ecbd7..d2f8b150 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -1,8 +1,13 @@ [package] edition = "2021" name = "kernel" -version = "0.1.1" +version = "0.1.2" [dependencies] -lazy_static = "*" \ No newline at end of file +[dependencies.lazy_static] +version = "1.4.0" +default-features = false + +[dependencies.versioning] +git = "https://git.ablecorp.us/able/versioning" \ No newline at end of file diff --git a/kernel/src/device_interface/block/mod.rs b/kernel/src/device_interface/block/mod.rs new file mode 100644 index 00000000..9d0f028e --- /dev/null +++ b/kernel/src/device_interface/block/mod.rs @@ -0,0 +1 @@ +//! diff --git a/ableos/src/driver_traits/character_device.rs b/kernel/src/device_interface/character/mod.rs similarity index 67% rename from ableos/src/driver_traits/character_device.rs rename to kernel/src/device_interface/character/mod.rs index d128c72f..443d12a5 100644 --- a/ableos/src/driver_traits/character_device.rs +++ b/kernel/src/device_interface/character/mod.rs @@ -1,3 +1,6 @@ +//! + +/// Character device interface. pub trait CharacterDevice { /// Returns true if the device can be read from. fn can_read(&self) -> bool; @@ -7,4 +10,8 @@ pub trait CharacterDevice { fn read_char(&mut self) -> Option; /// Writes a single character to the device and returns true if the write was successful fn write_char(&mut self, c: char) -> bool; + /// Reset the device to its initial state + fn reset(&mut self); + /// initializes the device, returns true if successful + fn initialize(&mut self) -> bool; } diff --git a/kernel/src/device_interface/mod.rs b/kernel/src/device_interface/mod.rs new file mode 100644 index 00000000..7fe7faaf --- /dev/null +++ b/kernel/src/device_interface/mod.rs @@ -0,0 +1,4 @@ +//! Platform Agnostic Device + +pub mod block; +pub mod character; diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 2a5d6934..0d4f1304 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -2,15 +2,16 @@ #![no_std] //! The ableOS kernel. -pub mod kernel_time; +pub mod device_interface; pub mod messaging; -pub mod proccess; - -// #[cfg(no_std)] pub mod panic; +pub mod proccess; +pub mod time; use core::sync::atomic::{AtomicU64, Ordering::Relaxed}; +use versioning::Version; + /// called by arch specific timers to tick up all kernel related functions pub fn tick() { let mut data = TICK.load(Relaxed); @@ -23,3 +24,10 @@ lazy_static::lazy_static! { /// The number of ticks since the first CPU was started pub static ref TICK: AtomicU64 = AtomicU64::new(0); } + +/// +pub const KERNEL_VERSION: Version = Version { + major: 0, + minor: 1, + patch: 2, +}; diff --git a/kernel/src/messaging.rs b/kernel/src/messaging.rs index 4d3535b4..6584d41d 100644 --- a/kernel/src/messaging.rs +++ b/kernel/src/messaging.rs @@ -1,14 +1,14 @@ //! Interprocess communication. -use crate::{kernel_time::Time, proccess::PID}; +use crate::{proccess::PID, time::Time}; /// 128 Bytes pub type Tiny = [u8; 128]; -/// 1 KibiByte +/// 1 KiB pub type Small = [u8; 1024]; -/// 65.536 KibiBytes +/// 65.536 KiB pub type Medium = [u8; 65536]; /// 1MiB diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs index e3761be6..0f1323ae 100644 --- a/kernel/src/panic.rs +++ b/kernel/src/panic.rs @@ -3,6 +3,6 @@ use core::panic::PanicInfo; #[panic_handler] -fn panic(_info: &PanicInfo) -> ! { +fn panic_handler(_info: &PanicInfo) -> ! { loop {} } diff --git a/kernel/src/kernel_time.rs b/kernel/src/time.rs similarity index 100% rename from kernel/src/kernel_time.rs rename to kernel/src/time.rs