seperate the core kernel into its own directory

This commit is contained in:
Able 2022-02-28 08:54:41 -06:00
parent c21b1a75f5
commit 6c3a67e6b5
20 changed files with 164 additions and 148 deletions

1
.gitignore vendored
View file

@ -5,4 +5,5 @@ facepalm/target
shadeable/target
qprofiler
userland/*/target
kernel/target

8
ableos/Cargo.lock generated
View file

@ -35,6 +35,7 @@ dependencies = [
"facepalm",
"genfs",
"hashbrown",
"kernel",
"lazy_static",
"libwasm",
"linked_list_allocator",
@ -270,6 +271,13 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "kernel"
version = "0.1.1"
dependencies = [
"lazy_static",
]
[[package]]
name = "lazy_static"
version = "1.4.0"

View file

@ -49,6 +49,10 @@ test-args = [
]
[dependencies]
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
# qoi_rs = "*"
@ -81,6 +85,8 @@ version = "0.8.1"
default-features = false
[dependencies.kernel]
path = "../kernel"
[dependencies.serde]
version = "*"

View file

@ -67,7 +67,7 @@ extern "x86-interrupt" fn double_fault_handler(
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
crate::kmain::tick();
kernel::tick();
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());

View file

@ -35,7 +35,6 @@ use {
lazy_static! {
// TODO: Change this structure to allow for multiple cores loaded
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
}
@ -107,19 +106,6 @@ pub fn kernel_main() -> ! {
sloop()
}
/// 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);
crate::kernel_state::KERNEL_STATE.lock().update_state();
// let mut scheduler = SCHEDULER.lock();
// scheduler.bump_exec();
// drop(scheduler);
TICK.store(data, Relaxed)
}
pub fn cpu_socket_startup() {
let mut cpu_info_socket = SimpleSock::new();
cpu_info_socket.register_protocol("CPU_INFO".to_string());

View file

@ -51,7 +51,6 @@ pub mod kernel_state;
pub mod keyboard;
pub mod kmain;
pub mod logger;
pub mod panic;
pub mod proto_filetable;
pub mod relib;
pub mod scheduler;
@ -74,7 +73,6 @@ pub use graphics::*;
pub use kernel_state::*;
pub use keyboard::*;
pub use logger::*;
pub use panic::*;
pub use proto_filetable::*;
pub use relib::*;
pub use scheduler::*;
@ -82,7 +80,6 @@ pub use utils::*;
pub use vga_e::*;
pub use wasm::*;
//////////////////
pub mod virtio;
pub use virtio::*;
@ -91,11 +88,14 @@ pub use alias_table::*;
pub mod tests;
pub use tests::*;
/*pub mod syscalls;
pub use syscalls::*;
*/
pub mod scratchpad;
pub use scratchpad::*;
pub mod filesystem;
pub mod messaging;
///////////////
/// Kernel ///
/////////////
pub use kernel;
pub use kernel::messaging;
pub use kernel::panic;

View file

@ -1,7 +1,7 @@
use core::sync::atomic::Ordering;
use crate::kmain::TICK;
use crate::serial_println;
use kernel::TICK;
use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn};
use log::{Level, Metadata, Record};

View file

@ -1,100 +0,0 @@
use {
crate::{kmain::TICK, proc::PID},
alloc::string::String,
core::{
fmt::{Display, Formatter, Result as FmtResult},
result::Result,
sync::atomic::Ordering::Relaxed,
},
libwasm::syscalls::time_calls::SecondsTime,
x86_64::instructions::interrupts::{disable, enable},
};
#[derive(Debug)]
pub enum MessagingError {
MessageTooLarge,
}
impl Display for MessagingError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
match self {
MessagingError::MessageTooLarge => write!(f, "Message too large"),
}
}
}
/// Not properly implemented
pub fn fetch_time() -> SecondsTime {
disable();
let time = TICK.load(Relaxed);
enable();
SecondsTime {
seconds: time,
milliseconds: 0,
}
}
pub type MessageSmall = [u8; 2048];
pub type MessageLarge = [u8; 16384];
pub enum Message {
Small(MessageSmall),
Large(MessageLarge),
}
pub struct ProcessMessage {
pub to_pid: PID,
pub from_pid: PID,
pub message: Message,
pub sender_time: SecondsTime,
}
impl ProcessMessage {
pub fn new(to_pid: PID, from_pid: PID, message: Message) -> Self {
Self {
to_pid,
from_pid,
message,
sender_time: fetch_time(),
}
}
pub fn new_from_string(
to_pid: PID,
from_pid: PID,
string: String,
) -> Result<Self, MessagingError> {
let mut mssg = Message::Small([0u8; 2048]);
match string.len() {
0..=2047 => {
let mut message = [0u8; 2048];
for (i, c) in string.chars().enumerate() {
message[i] = c as u8;
}
mssg = Message::Small(message);
}
2048..=16383 => {
let mut message = [0u8; 16384];
for (i, c) in string.chars().enumerate() {
message[i] = c as u8;
}
mssg = Message::Large(message);
}
_ => return Err(MessagingError::MessageTooLarge),
}
Ok(Self {
to_pid,
from_pid,
message: mssg,
sender_time: fetch_time(),
})
}
}
pub fn send_sync_message(message: ProcessMessage) {}
pub fn send_async_message(message: ProcessMessage) {}
pub fn recv_sync_message() {}
pub fn recv_async_message() {}

View file

@ -1,22 +0,0 @@
use {crate::arch::sloop, core::panic::PanicInfo};
/// A function to handle a panic in the kernel.
/// # Example
/// ```
/// use ableos::panic::panic;
/// panic!("This is a panic!");
/// ```
///
/// # Safety
/// This function is unsafe because it does not guarantee that the panic is handled.
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
error!("{}", info);
// help me use facepalm::start_facepalm;
sloop()
}
pub fn test_panic() {
panic!("test panic!");
}

View file

@ -39,10 +39,10 @@ use x86_64::instructions::interrupts::{disable, enable};
use crate::wasm_jumploader::interp;
use crate::{
arch::{shutdown, sloop},
kmain::{tick, TICK},
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
KERNEL_STATE,
};
use kernel::TICK;
pub fn afetch() {
let kstate = KERNEL_STATE.lock();

View file

@ -10,10 +10,11 @@ use vga::colors::Color16;
use y_compositor_protocol::Version;
use crate::{
kmain::{BOOT_CONF, TICK},
kmain::BOOT_CONF,
network::socket::{SimpleSock, Socket, SocketReturns},
num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER,
};
use kernel::TICK;
pub fn run_tests() {
if BOOT_CONF.run_tests {

View file

@ -37,7 +37,7 @@ impl Externals for HostExternals {
use core::sync::atomic::Ordering::*;
x86_64::instructions::interrupts::disable();
let tick_time = crate::kmain::TICK.load(Relaxed);
let tick_time = kernel::TICK.load(Relaxed);
x86_64::instructions::interrupts::enable();
let ret = RuntimeValue::I64(tick_time.try_into().unwrap());

16
kernel/Cargo.lock generated Normal file
View file

@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "kernel"
version = "0.1.1"
dependencies = [
"lazy_static",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"

8
kernel/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
edition = "2021"
name = "kernel"
version = "0.1.1"
[dependencies]
lazy_static = "*"

10
kernel/src/kernel_time.rs Normal file
View file

@ -0,0 +1,10 @@
//! 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,
}

25
kernel/src/lib.rs Normal file
View file

@ -0,0 +1,25 @@
#![deny(missing_docs)]
#![no_std]
//! The ableOS kernel.
pub mod kernel_time;
pub mod messaging;
pub mod proccess;
// #[cfg(no_std)]
pub mod panic;
use core::sync::atomic::{AtomicU64, Ordering::Relaxed};
/// 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)
}
lazy_static::lazy_static! {
/// The number of ticks since the first CPU was started
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
}

65
kernel/src/messaging.rs Normal file
View file

@ -0,0 +1,65 @@
//! Interprocess communication.
use crate::{kernel_time::Time, proccess::PID};
/// 128 Bytes
pub type Tiny = [u8; 128];
/// 1 KibiByte
pub type Small = [u8; 1024];
/// 65.536 KibiBytes
pub type Medium = [u8; 65536];
/// 1MiB
pub type Large = [u8; 1048576];
/// 16MiB
pub type Huge = [u8; 16777216];
/// An internal message to be held in a process message
pub enum Message {
/// A Tiny message
///
/// The message is 128 bytes long
Tiny(Tiny),
/// A Small message
///
/// The message is 1 KiB long
Small(Small),
/// A Medium message
///
/// The message is 65.536 KiB long
Medium(Medium),
/// A Large message
///
/// The message is 1 MiB long
Large(Large),
/// A Huge message
///
/// The message is 16 MiB long
Huge(Huge),
}
/// A message that can be sent between processes
pub struct ProcessMessage {
/// The sender of the message
pub to_pid: PID,
/// The receiver of the message
pub from_pid: PID,
/// The message
pub message: Message,
/// The time the message was sent
pub sender_time: Time,
/// The time the message was received
pub receiver_time: Time,
}
#[derive(Debug)]
/// An enum of all possible errors that can occur when sending a message
pub enum MessagingError {
/// The message is too large to be sent
MessageTooLarge,
/// The reciever of the message is not valid
ProcessNonExistant,
}

8
kernel/src/panic.rs Normal file
View file

@ -0,0 +1,8 @@
//!
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

4
kernel/src/proccess.rs Normal file
View file

@ -0,0 +1,4 @@
//! Platform agnostic process
/// A process ID
pub type PID = u64;