From 4812e59c09ac07dbd5a1488184fba2ed685a31a6 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 7 Nov 2022 20:29:42 +0100 Subject: [PATCH] Threw stuff from the microkernel. Start of moving core parts there. --- .../src/device_interface/block.rs | 0 .../src/device_interface/character/mod.rs | 0 .../src/device_interface/mod.rs | 0 ableos/src/devices/character_devs/dev_null.rs | 2 +- .../src/devices/character_devs/dev_unicode.rs | 2 +- ableos/src/devices/character_devs/dev_zero.rs | 2 +- ableos/src/devices/character_devs/mod.rs | 2 +- ableos/src/devices/dev_vterm.rs | 2 +- ableos/src/devices/mod.rs | 2 +- ableos/src/driver_traits/serial.rs | 2 +- ableos/src/lib.rs | 1 + ableos/src/stdio.rs | 2 +- kernel/src/aalloc/aalloc.rs | 122 ------------------ kernel/src/aalloc/mod.rs | 12 -- kernel/src/arch/mod.rs | 6 - kernel/src/arch/x86_64/mod.rs | 9 -- kernel/src/lib.rs | 27 +--- kernel/src/panic.rs | 11 -- kernel/src/proccess.rs | 14 -- kernel/src/syscalls.rs | 26 ---- kernel/src/time.rs | 10 -- 21 files changed, 10 insertions(+), 244 deletions(-) rename {kernel => ableos}/src/device_interface/block.rs (100%) rename {kernel => ableos}/src/device_interface/character/mod.rs (100%) rename {kernel => ableos}/src/device_interface/mod.rs (100%) delete mode 100644 kernel/src/aalloc/aalloc.rs delete mode 100644 kernel/src/aalloc/mod.rs delete mode 100644 kernel/src/arch/mod.rs delete mode 100644 kernel/src/arch/x86_64/mod.rs delete mode 100644 kernel/src/panic.rs delete mode 100644 kernel/src/proccess.rs delete mode 100644 kernel/src/syscalls.rs delete mode 100644 kernel/src/time.rs diff --git a/kernel/src/device_interface/block.rs b/ableos/src/device_interface/block.rs similarity index 100% rename from kernel/src/device_interface/block.rs rename to ableos/src/device_interface/block.rs diff --git a/kernel/src/device_interface/character/mod.rs b/ableos/src/device_interface/character/mod.rs similarity index 100% rename from kernel/src/device_interface/character/mod.rs rename to ableos/src/device_interface/character/mod.rs diff --git a/kernel/src/device_interface/mod.rs b/ableos/src/device_interface/mod.rs similarity index 100% rename from kernel/src/device_interface/mod.rs rename to ableos/src/device_interface/mod.rs diff --git a/ableos/src/devices/character_devs/dev_null.rs b/ableos/src/devices/character_devs/dev_null.rs index 7688875..1643b49 100644 --- a/ableos/src/devices/character_devs/dev_null.rs +++ b/ableos/src/devices/character_devs/dev_null.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::CharacterDevice; +use crate::device_interface::CharacterDevice; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DevNull; diff --git a/ableos/src/devices/character_devs/dev_unicode.rs b/ableos/src/devices/character_devs/dev_unicode.rs index 995e037..c3aafef 100644 --- a/ableos/src/devices/character_devs/dev_unicode.rs +++ b/ableos/src/devices/character_devs/dev_unicode.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::CharacterDevice; +use crate::device_interface::CharacterDevice; #[derive(Debug)] pub struct DevUnicode { diff --git a/ableos/src/devices/character_devs/dev_zero.rs b/ableos/src/devices/character_devs/dev_zero.rs index 07508b5..b6a6844 100644 --- a/ableos/src/devices/character_devs/dev_zero.rs +++ b/ableos/src/devices/character_devs/dev_zero.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::CharacterDevice; +use crate::device_interface::CharacterDevice; #[derive(Debug)] pub struct DevZero; diff --git a/ableos/src/devices/character_devs/mod.rs b/ableos/src/devices/character_devs/mod.rs index f63a064..806d284 100644 --- a/ableos/src/devices/character_devs/mod.rs +++ b/ableos/src/devices/character_devs/mod.rs @@ -2,4 +2,4 @@ pub mod dev_null; pub mod dev_unicode; pub mod dev_zero; -pub use kernel::device_interface::CharacterDevice; +pub use crate::device_interface::CharacterDevice; diff --git a/ableos/src/devices/dev_vterm.rs b/ableos/src/devices/dev_vterm.rs index e807cb4..ec4082c 100644 --- a/ableos/src/devices/dev_vterm.rs +++ b/ableos/src/devices/dev_vterm.rs @@ -1,9 +1,9 @@ // ! A virtual terminal device. +use crate::device_interface::CharacterDevice; use core::ops::Not; use core::sync::atomic::AtomicU32; use core::sync::atomic::Ordering; -use kernel::device_interface::CharacterDevice; use crate::pixel_format::Rgba64; diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index ea102d6..d69885c 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -6,10 +6,10 @@ pub mod pci; pub use self::Device::*; +use crate::device_interface::{BlockDevice, CharacterDevice}; use crate::devices::dev_vterm::VTerm; use character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero}; use hashbrown::HashMap; -use kernel::device_interface::{BlockDevice, CharacterDevice}; use spin::Lazy; pub static DEVICE_TABLE: Lazy> = diff --git a/ableos/src/driver_traits/serial.rs b/ableos/src/driver_traits/serial.rs index 118f32f..336442e 100644 --- a/ableos/src/driver_traits/serial.rs +++ b/ableos/src/driver_traits/serial.rs @@ -1,4 +1,4 @@ -use kernel::device_interface::CharacterDevice; +use crate::device_interface::CharacterDevice; pub struct Serial { pub base: usize, diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 308e631..985e40f 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -57,6 +57,7 @@ pub mod print; pub mod serial_print; pub mod boot_conf; +pub mod device_interface; pub mod devices; pub mod driver_traits; pub mod experiments; diff --git a/ableos/src/stdio.rs b/ableos/src/stdio.rs index c5b127d..f94360d 100644 --- a/ableos/src/stdio.rs +++ b/ableos/src/stdio.rs @@ -1,7 +1,7 @@ use { + crate::device_interface::CharacterDevice, crate::devices::Device::{Block, Character, Vterm}, core::fmt::{Arguments, Error, Write}, - kernel::device_interface::CharacterDevice, }; #[derive(Debug, Clone)] diff --git a/kernel/src/aalloc/aalloc.rs b/kernel/src/aalloc/aalloc.rs deleted file mode 100644 index 54d5598..0000000 --- a/kernel/src/aalloc/aalloc.rs +++ /dev/null @@ -1,122 +0,0 @@ -//! The allocator to be implemented by ableOS -//! -//! NOTE: All memory regions are taken from https://wiki.osdev.org/Memory_Map_(x86) - -#![allow(missing_docs)] - -use alloc::alloc::{GlobalAlloc, Layout}; -use core::{fmt::Display, ptr::null_mut}; -use log::{debug, info}; - -// const HEAP_START: usize = 600_000_000; -const HEAP_START: usize = 0x00100000; -const BLOCK_SIZE: usize = 1024; -const BLOCK_COUNT: usize = 512; - -#[derive(Debug, Clone, Copy)] -pub struct MemoryRegion { - start: usize, - end: usize, -} -impl Display for MemoryRegion { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - writeln!( - f, - "MemoryRegion {{ start: {}, end: {}, size: {} bytes}}", - self.start, - self.end, - self.end - self.start - ) - } -} -impl MemoryRegion { - pub fn new(start: usize, end: usize) -> MemoryRegion { - MemoryRegion { start, end } - } - pub fn test_region(&self) -> bool { - unsafe { - let mutptr = self.start as *mut u8; - - core::ptr::write(mutptr, 0xFF); - // trace!("{}", core::ptr::read(mutptr)); - } - - true - } -} - -#[derive(Debug, Clone, Copy)] -pub struct AAlloc { - current_region: usize, - memory_regions: [Option; 512], -} - -impl AAlloc { - fn test_regions(&self) { - for x in 0..self.current_region { - if let Some(region) = self.memory_regions[x] { - debug!("Region {}: {:?}", x, region); - } - } - } - - pub fn add_region(&mut self, mem: MemoryRegion) { - self.memory_regions[self.current_region] = Some(mem); - self.current_region += 1; - } - - pub fn intialize() { - info!("Heap Start: {}", HEAP_START); - info!("Heap Size: {}", BLOCK_SIZE * BLOCK_COUNT); - info!("Heap End: {}", HEAP_START + BLOCK_SIZE * BLOCK_COUNT); - - let mut aalloc = AAlloc { - current_region: 0, - memory_regions: [None; 512], - }; - - // BS MEMORY REGION - aalloc.add_region(MemoryRegion::new(HEAP_START, HEAP_START + 10)); - - aalloc.add_region(MemoryRegion::new(0x00007E00, 0x0007FFFF)); - - aalloc.add_region(MemoryRegion::new(0x00100000, 0x00EFFFFF)); - - // ISA Memory Hole - aalloc.add_region(MemoryRegion::new(0x00F00000, 0x00FFFFFF)); - - aalloc.add_region(MemoryRegion::new(0x0000000100000000, 0x0000000100000000)); - - aalloc.memory_regions[0].unwrap().test_region(); - debug!("{}", aalloc); - } -} - -impl Display for AAlloc { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - write!(f, "AAlloc {{\n\tcurrent_region: {},\n", self.current_region)?; - - for x in 0..self.current_region { - if let Some(region) = self.memory_regions[x] { - write!(f, "\tRegion {}: {}", x, region)?; - } - } - write!(f, "}}")?; - Ok(()) - } -} - -unsafe impl GlobalAlloc for AAlloc { - unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { - info!("Allocating memory"); - - info!("{}", _layout.size()); - info!("{}", _layout.align()); - - null_mut() - } - - unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { - panic!("dealloc should be never called") - } -} diff --git a/kernel/src/aalloc/mod.rs b/kernel/src/aalloc/mod.rs deleted file mode 100644 index 74ba352..0000000 --- a/kernel/src/aalloc/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(missing_docs)] - -pub mod aalloc; -pub use aalloc::*; -/* -#[alloc_error_handler] -fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { - panic!("allocation error: {:?}", layout) -} - - -*/ diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs deleted file mode 100644 index 1947fbc..0000000 --- a/kernel/src/arch/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Architecture-specific code. - -/// X86 specific code -#[cfg(target_arch = "x86_64")] -#[path = "x86_64/mod.rs"] -pub mod arch; diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs deleted file mode 100644 index eee7ced..0000000 --- a/kernel/src/arch/x86_64/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -/// - -pub fn sloop() { - loop { - unsafe { - core::arch::asm!("hlt"); - } - } -} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 8cb4d0e..20de4ad 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,44 +1,19 @@ //! The ableOS kernel. -#![feature(alloc_error_handler, arbitrary_enum_discriminant, prelude_import)] +#![feature(alloc_error_handler, prelude_import)] #![no_std] #![deny(missing_docs)] extern crate alloc; -pub mod aalloc; pub mod allocator; -pub mod arch; -pub mod device_interface; -// pub mod panic; -pub mod proccess; -pub mod syscalls; pub mod task; -pub mod time; -use core::arch::asm; use versioning::Version; -/// The number of ticks since the first CPU was started -// pub static TICK: AtomicU64 = AtomicU64::new(0); - /// Kernel's version pub const KERNEL_VERSION: Version = Version { major: 0, minor: 1, patch: 2, }; - -/* -/// called by arch specific timers to tick up all kernel related functions -pub fn tick() { - let mut data = TICK.load(Relaxed); - data = data.wrapping_add(1); - - TICK.store(data, Relaxed) -} -*/ -/// Cause a software interrupt -pub fn software_int() { - unsafe { asm!("int 54") } -} diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs deleted file mode 100644 index 2da2b00..0000000 --- a/kernel/src/panic.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Panic-related stuff - -use core::panic::PanicInfo; -use log::error; - -#[panic_handler] -fn panic_handler(info: &PanicInfo) -> ! { - error!("{}", info); - - loop {} -} diff --git a/kernel/src/proccess.rs b/kernel/src/proccess.rs deleted file mode 100644 index e8f94ce..0000000 --- a/kernel/src/proccess.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Platform agnostic process - -/// A process ID -pub type PID = u64; - -/// Signals that can be sent to a process -#[repr(C)] -pub enum Signals { - /// Terminate the process - Terminate, - - /// Shutdown the process and allow it to shutdown cleanly - Quit, -} diff --git a/kernel/src/syscalls.rs b/kernel/src/syscalls.rs deleted file mode 100644 index 924201d..0000000 --- a/kernel/src/syscalls.rs +++ /dev/null @@ -1,26 +0,0 @@ -//! - -use crate::proccess::{Signals, PID}; - -/// All possible system calls -pub enum Syscall { - /// Create a new process and return its PID - CreateProcess, - - /// Send a signal to a process - SendSignal(PID, Signals), - - /// Get the current process ID - GetPID, - - /// Get the current time - GetTime, - - /// Set the time - SetTime, - // ListInodes, - // CreateInode, - // RemoveInode, - // OpenInode, - // CloseInode, -} diff --git a/kernel/src/time.rs b/kernel/src/time.rs deleted file mode 100644 index f4f1ed9..0000000 --- a/kernel/src/time.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Time - -/// An internal structure that is used to keep track of the time -pub struct Time { - /// The number of seconds since the kernel was started - pub seconds: u64, - - /// The number of nanoseconds since the kernel was started - pub nanoseconds: u32, -}