forked from AbleOS/ableos
Threw stuff from the microkernel. Start of moving core parts there.
This commit is contained in:
parent
d31f17f07e
commit
4812e59c09
|
@ -1,4 +1,4 @@
|
|||
use kernel::device_interface::CharacterDevice;
|
||||
use crate::device_interface::CharacterDevice;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DevNull;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use kernel::device_interface::CharacterDevice;
|
||||
use crate::device_interface::CharacterDevice;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DevUnicode {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use kernel::device_interface::CharacterDevice;
|
||||
use crate::device_interface::CharacterDevice;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DevZero;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<spin::Mutex<DeviceTable>> =
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use kernel::device_interface::CharacterDevice;
|
||||
use crate::device_interface::CharacterDevice;
|
||||
|
||||
pub struct Serial {
|
||||
pub base: usize,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<MemoryRegion>; 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")
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
*/
|
|
@ -1,6 +0,0 @@
|
|||
//! Architecture-specific code.
|
||||
|
||||
/// X86 specific code
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[path = "x86_64/mod.rs"]
|
||||
pub mod arch;
|
|
@ -1,9 +0,0 @@
|
|||
///
|
||||
|
||||
pub fn sloop() {
|
||||
loop {
|
||||
unsafe {
|
||||
core::arch::asm!("hlt");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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") }
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
//! Panic-related stuff
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use log::error;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic_handler(info: &PanicInfo) -> ! {
|
||||
error!("{}", info);
|
||||
|
||||
loop {}
|
||||
}
|
|
@ -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,
|
||||
}
|
|
@ -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,
|
||||
}
|
|
@ -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,
|
||||
}
|
Loading…
Reference in a new issue