From 0379a34a5977836199ef5c259655e7d60c53c7b6 Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 11 Mar 2022 13:51:47 -0600 Subject: [PATCH] TOML config|moved a ton of boiler plate to prelude --- ableos/Cargo.lock | 70 +++++----- ableos/Cargo.toml | 52 +++---- ableos/assets/kernel.toml | 12 ++ ableos/assets/kernel_config.json | 7 - ableos/src/alias_table/mod.rs | 1 - ableos/src/allocator/aalloc.rs | 5 + ableos/src/allocator/mod.rs | 8 +- ableos/src/arch/x86_64/drivers/allocator.rs | 2 +- ableos/src/arch/x86_64/init.rs | 6 + ableos/src/boot_conf.rs | 40 +++--- ableos/src/devices/id.rs | 9 +- ableos/src/devices/mod.rs | 6 - ableos/src/devices/pci_inner.rs | 129 +++++++----------- ableos/src/experiments/absi.rs | 6 +- ableos/src/experiments/futex.rs | 2 - ableos/src/experiments/info.rs | 1 - ableos/src/experiments/y_compositor/window.rs | 3 - ableos/src/filesystem/mod.rs | 15 +- ableos/src/graphics/mod.rs | 3 +- ableos/src/kernel_state.rs | 1 - ableos/src/kmain.rs | 33 ++--- ableos/src/lib.rs | 13 +- ableos/src/logger.rs | 19 ++- ableos/src/port_io.rs | 16 +++ ableos/src/prelude/mod.rs | 1 + ableos/src/prelude/rust_2021.rs | 8 ++ ableos/src/print.rs | 3 +- ableos/src/proto_filetable/file.rs | 2 - ableos/src/proto_filetable/mod.rs | 5 - ableos/src/relib/clparse/mod.rs | 6 - ableos/src/relib/encoding/bin.rs | 2 - ableos/src/relib/encoding/rle.rs | 3 - ableos/src/relib/network/socket.rs | 4 - ableos/src/rhai_shell/mod.rs | 29 +++- ableos/src/scheduler/capabilities.rs | 2 +- ableos/src/scheduler/mod.rs | 4 +- ableos/src/scheduler/new_sched.rs | 2 - ableos/src/scheduler/proc.rs | 2 - ableos/src/scratchpad.rs | 72 ++-------- ableos/src/tests.rs | 15 +- ableos/src/vga_e.rs | 13 +- ableos/src/wasm/mod.rs | 2 - ableos/src/wasm_jumploader/host_functions.rs | 2 - ableos/src/wasm_jumploader/mod.rs | 1 - kernel/.cargo/config.toml | 2 + kernel/Cargo.toml | 2 + kernel/src/lib.rs | 2 + kernel/src/panic.rs | 6 +- shadeable/src/engine_internals.rs | 6 +- 49 files changed, 300 insertions(+), 355 deletions(-) create mode 100644 ableos/assets/kernel.toml delete mode 100644 ableos/assets/kernel_config.json create mode 100644 ableos/src/port_io.rs create mode 100644 ableos/src/prelude/mod.rs create mode 100644 ableos/src/prelude/rust_2021.rs create mode 100644 kernel/.cargo/config.toml diff --git a/ableos/Cargo.lock b/ableos/Cargo.lock index 59af6be1..0d66aa29 100644 --- a/ableos/Cargo.lock +++ b/ableos/Cargo.lock @@ -34,7 +34,7 @@ dependencies = [ "externc-libm", "facepalm", "genfs", - "hashbrown", + "hashbrown 0.11.2", "kernel", "lazy_static", "libwasm", @@ -43,7 +43,6 @@ dependencies = [ "log", "logos", "pc-beeper", - "pci", "pic8259", "picorand", "pretty-hex", @@ -51,10 +50,10 @@ dependencies = [ "rhai", "rkyv", "serde", - "serde_json", "shadeable", "smoltcp", "spin 0.5.2", + "toml", "uart_16550", "unicode-width", "vga", @@ -75,6 +74,12 @@ dependencies = [ "rsdp", ] +[[package]] +name = "ahash" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" + [[package]] name = "ahash" version = "0.7.6" @@ -247,13 +252,23 @@ dependencies = [ "wasi", ] +[[package]] +name = "hashbrown" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf" +dependencies = [ + "ahash 0.3.8", + "autocfg", +] + [[package]] name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ - "ahash", + "ahash 0.7.6", ] [[package]] @@ -265,17 +280,12 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "itoa" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" - [[package]] name = "kernel" version = "0.1.2" dependencies = [ "lazy_static", + "log", "versioning", ] @@ -303,7 +313,7 @@ checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" [[package]] name = "libwasm" version = "0.1.0" -source = "git+https://git.ablecorp.us/able/libwasm.git#a89b8fc701ba0196cc9cca9989d9beb93d02a317" +source = "git+https://git.ablecorp.us/able/libwasm.git#dedbb769ba01a4b75992437e52ca9a5c2bb9e0f9" [[package]] name = "linked_list_allocator" @@ -440,14 +450,6 @@ dependencies = [ "x86_64", ] -[[package]] -name = "pci" -version = "0.0.1" -source = "git+https://gitlab.com/robigalia/pci#4e2fddc61825568b1d14d09fdc669389e6c43f02" -dependencies = [ - "bitflags", -] - [[package]] name = "pic8259" version = "0.10.2" @@ -540,7 +542,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49c94fda0280985896ed6d8bf0b43bbb5a7f0e39ccc8728ac907ddb4f06dae94" dependencies = [ - "ahash", + "ahash 0.7.6", "core-error", "instant", "libm", @@ -568,7 +570,7 @@ version = "0.7.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439655b8d657bcb28264da8e5380d55549e34ffc4149bea9e3521890a122a7bd" dependencies = [ - "hashbrown", + "hashbrown 0.11.2", "ptr_meta", "rkyv_derive", "seahash", @@ -600,12 +602,6 @@ dependencies = [ "log", ] -[[package]] -name = "ryu" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" - [[package]] name = "scopeguard" version = "1.1.0" @@ -638,17 +634,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085" -dependencies = [ - "itoa", - "ryu", - "serde", -] - [[package]] name = "shadeable" version = "0.1.0" @@ -736,6 +721,15 @@ dependencies = [ "crunchy", ] +[[package]] +name = "toml" +version = "0.5.6" +source = "git+https://github.com/diondokter/toml-rs#c4161aa70202b3992dbec79b76e7a8659713b604" +dependencies = [ + "hashbrown 0.7.2", + "serde", +] + [[package]] name = "ttf-parser" version = "0.14.0" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 283ff547..138e966a 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -9,6 +9,9 @@ panic = "abort" [package.metadata.bootimage] run-args = [ + "--nodefaults", + + "-cpu", "Broadwell-v3", @@ -17,28 +20,24 @@ run-args = [ "-smp", "cores=2", - # An example gpu used with ableOS - "-device", - # "virtio-gpu", - "ati-vga", - # An example disk used with ableOS - "-device", - "virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4", + "-device", #"ati-vga", + "cirrus-vga", + + + + + # "-device", + # "virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4", # A simple example of a boot image - "-drive", - "file=disk.qcow2,if=none,id=drive0", + # "-drive", + # "file=disk.qcow2,if=none,id=drive0", + # "-device", + # "virtio-rng", - - - "-device", -"virtio-rng", - - -"-qmp", - "unix:../qmp-sock,server,nowait" - + # "-qmp", + # "unix:../qmp-sock,server,nowait" ] test-args = [ @@ -52,7 +51,6 @@ test-args = [ - linked_list_allocator = "0.9.0" lliw = "0.2.0" # qoi_rs = "*" @@ -70,7 +68,7 @@ genfs = "0.1.0" pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"} rhai = "1.5" -pci = {git="https://gitlab.com/robigalia/pci"} +# pci = {git="https://gitlab.com/robigalia/pci"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} acpi = "4.1.0" @@ -93,10 +91,7 @@ version = "*" default-features = false features = ["derive", "alloc"] -[dependencies.serde_json] -version = "*" -default-features = false -features = ["alloc"] + [dependencies.hashbrown] version = "0.11.2" @@ -118,6 +113,15 @@ git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git" [dependencies.ext2] git = "https://git.ablecorp.us:443/able/ext2-rs.git" + + + +[dependencies.toml] +git = "https://github.com/diondokter/toml-rs" +# version = "0.5.8" +default-features = false + + [dependencies.shadeable] path = "../shadeable" diff --git a/ableos/assets/kernel.toml b/ableos/assets/kernel.toml new file mode 100644 index 00000000..b666058d --- /dev/null +++ b/ableos/assets/kernel.toml @@ -0,0 +1,12 @@ +[boot] +system_processes = [] +user_processes = ["shell"] + +[logging] +enabled = false +level = "Trace" + +[tests] +run_tests = false +run_demos = false +run_shader_tests = false \ No newline at end of file diff --git a/ableos/assets/kernel_config.json b/ableos/assets/kernel_config.json deleted file mode 100644 index 88b0866c..00000000 --- a/ableos/assets/kernel_config.json +++ /dev/null @@ -1,7 +0,0 @@ - { - "logging_level": "Trace", - "logger_padding": 10, - "run_tests": false, - "run_demos": false, - "run_shader_tests": false - } \ No newline at end of file diff --git a/ableos/src/alias_table/mod.rs b/ableos/src/alias_table/mod.rs index 36d3d1d8..3457b66b 100644 --- a/ableos/src/alias_table/mod.rs +++ b/ableos/src/alias_table/mod.rs @@ -1,4 +1,3 @@ -use alloc::string::{String, ToString}; use hashbrown::HashMap; lazy_static::lazy_static! { diff --git a/ableos/src/allocator/aalloc.rs b/ableos/src/allocator/aalloc.rs index 652c74a8..f67e60f4 100644 --- a/ableos/src/allocator/aalloc.rs +++ b/ableos/src/allocator/aalloc.rs @@ -9,6 +9,11 @@ pub struct AAloc; unsafe impl GlobalAlloc for AAloc { unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { + println!("Allocating memory"); + + println!("{}", _layout.size()); + println!("{}", _layout.align()); + null_mut() } diff --git a/ableos/src/allocator/mod.rs b/ableos/src/allocator/mod.rs index 45a1f21f..d5806982 100644 --- a/ableos/src/allocator/mod.rs +++ b/ableos/src/allocator/mod.rs @@ -8,13 +8,7 @@ pub const HEAP_MULTIPLIER: usize = 100000; pub const HEAP_BASE: usize = 100; pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER; -// X86 alloc should be in arch/drivers/x86/alloc.rs -/* -use crate::arch::drivers::allocator::Dummy; -#[global_allocator] -static ALLOCATOR: Dummy = Dummy; -*/ use linked_list_allocator::LockedHeap; #[global_allocator] @@ -22,5 +16,7 @@ pub static ALLOCATOR: LockedHeap = LockedHeap::empty(); #[alloc_error_handler] fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { + // error!("allocation error: {:?}", layout); + panic!("allocation error: {:?}", layout) } diff --git a/ableos/src/arch/x86_64/drivers/allocator.rs b/ableos/src/arch/x86_64/drivers/allocator.rs index 2b8c708b..353e0e02 100644 --- a/ableos/src/arch/x86_64/drivers/allocator.rs +++ b/ableos/src/arch/x86_64/drivers/allocator.rs @@ -1,5 +1,5 @@ use alloc::alloc::{GlobalAlloc, Layout}; -// use core::alloc::{GlobalAlloc, Layout}; + use crate::allocator::{HEAP_SIZE, HEAP_START}; use core::ptr::null_mut; use x86_64::{ diff --git a/ableos/src/arch/x86_64/init.rs b/ableos/src/arch/x86_64/init.rs index ea104668..75faf68c 100644 --- a/ableos/src/arch/x86_64/init.rs +++ b/ableos/src/arch/x86_64/init.rs @@ -5,6 +5,12 @@ use super::{gdt, interrupts}; /// x86_64 initialization pub fn init() { + use crate::network::socket::SimpleSock; + use crate::relib::network::socket::Socket; + + let mut log_socket_id = SimpleSock::new(); + log_socket_id.register_protocol("Logger".to_string()); + let result = logger::init(); match result { Ok(_) => {} diff --git a/ableos/src/boot_conf.rs b/ableos/src/boot_conf.rs index 1678a8c8..e7112878 100644 --- a/ableos/src/boot_conf.rs +++ b/ableos/src/boot_conf.rs @@ -1,5 +1,4 @@ use log::LevelFilter; -// use rkyv::{Deserialize, Serialize}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Debug, Deserialize)] @@ -19,29 +18,21 @@ pub enum LogLevel { } #[derive(Serialize, Debug, Deserialize)] -pub struct BootConfig { - pub logging_level: LogLevel, - pub logger_padding: usize, - pub run_tests: bool, - pub run_demos: bool, - pub run_shader_tests: bool, +pub struct KernelConfig { + pub boot: BootConfig, + pub logging: LoggingConfig, + pub tests: TestsConfig, } -impl BootConfig { +impl KernelConfig { pub fn new() -> Self { - let data = include_str!("../assets/kernel_config.json"); - - // Parse the string of data into a Person object. This is exactly the - // same function as the one that produced serde_json::Value above, but - // now we are asking it for a Person as output. - let p: BootConfig = serde_json::from_str(data).unwrap(); - // info!("{:?}", p); + let p: KernelConfig = toml::from_str(include_str!("../assets/kernel.toml")).unwrap(); p } pub fn log_level(&self) -> LevelFilter { use LevelFilter::*; - match self.logging_level { + match self.logging.level { LogLevel::Off => Off, LogLevel::Error => Error, LogLevel::Warn => Warn, @@ -51,3 +42,20 @@ impl BootConfig { } } } + +#[derive(Serialize, Debug, Deserialize)] +pub struct LoggingConfig { + pub enabled: bool, + pub level: LogLevel, +} +#[derive(Serialize, Debug, Deserialize)] +pub struct TestsConfig { + pub run_tests: bool, + pub run_demos: bool, + pub run_shader_tests: bool, +} + +#[derive(Serialize, Debug, Deserialize)] +pub struct BootConfig { + pub processes: Vec, +} diff --git a/ableos/src/devices/id.rs b/ableos/src/devices/id.rs index 6323a5d1..f2f286dd 100644 --- a/ableos/src/devices/id.rs +++ b/ableos/src/devices/id.rs @@ -1,12 +1,15 @@ #[derive(Debug)] pub enum Vendor { Unknown = 0, - Ati = 4098, + + Ati = 1002, } pub fn match_vendor(id: u16) -> Vendor { + use Vendor::*; match id { - 4098 => Vendor::Ati, - _ => Vendor::Unknown, + 1002 => Ati, + + _ => Unknown, } } diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index ba340d21..fb6d0042 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -2,12 +2,7 @@ pub mod character_devs; pub mod id; pub mod pci_inner; -use alloc::{ - boxed::Box, - string::{String, ToString}, -}; use hashbrown::HashMap; -use pci::PCIDevice; use kernel::device_interface::character::CharacterDevice; @@ -15,7 +10,6 @@ use kernel::device_interface::character::CharacterDevice; // #[derive(Debug)] pub enum Device { Character(Box), - Pci(PCIDevice), } unsafe impl Sync for Device {} unsafe impl Send for Device {} diff --git a/ableos/src/devices/pci_inner.rs b/ableos/src/devices/pci_inner.rs index c78c9a45..a85c8325 100644 --- a/ableos/src/devices/pci_inner.rs +++ b/ableos/src/devices/pci_inner.rs @@ -1,86 +1,55 @@ //! map the DeviceClass via +//! +//! -use pci::PortOps; -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum DeviceClass { - UnclassifiedDevice = 0, - MassStorageController = 0x01, - NetworkController = 0x02, - DisplayController = 0x03, - MultimediaController = 0x04, - MemoryController = 0x05, - BridgeDevice = 0x06, +#[allow(dead_code)] +fn scan_pci_bus() {} - CommunicationController = 0x07, - GenericSystemPeripheral = 0x08, - InputDevice = 0x09, - DockingStation = 0x0a, - Processor = 0x0b, - SerialBusController = 0x0c, - WirelessController = 0x0d, - IntelligentController = 0x0e, - SatelliteCommunicationController = 0x0f, - EncryptionController = 0x10, - SignalProcessingController = 0x11, - - // 14 - // 15 - // 16 - Coprocessor = 40, - // 64 +pub enum Vendors { + ThreeDfxInteractiveInc = 0x121a, + ThreeDLabs = 0x3d3d, + AllianceSemiconductorCorp = 0x1142, + ARKLogicInc = 0xedd8, + ATITechnologiesInc = 0x1002, + AvanceLogicIncALI = 0x1005, + ChipsandTechnologies = 0x102c, + CirrusLogic = 0x1013, + Compaq = 0x0e11, + CyrixCorp = 0x1078, + DiamondMultimediaSystems = 0x1092, + DigitalEquipmentCorp = 0x1011, + Iit = 0x1061, + IntegratedMicroSolutionsInc = 0x10e0, + IntelCorp = 0x8086, + IntergraphicsSystems = 0x10ea, + MacronixInc = 0x10d9, + MatroxGraphicsInc = 0x102b, + MiroComputersProductsAG = 0x1031, + NationalSemiconductorCorp = 0x100b, + NeoMagicCorp = 0x10c8, + Number9ComputerCompany = 0x105d, + NVidiaCorporation = 0x10de, + NVidiaSgsthomson = 0x12d2, + OakTechnologyInc = 0x104e, + QuantumDesignsHKLtd = 0x1098, + Real3D = 0x003d, + Rendition = 0x1163, + S3Inc = 0x5333, + SierraSemiconductor = 0x10a8, + SiliconIntegratedSystemsSiS = 0x1039, + SiliconMotionInc = 0x126f, + STBSystemsInc = 0x10b4, + TexasInstruments = 0x104c, + ToshibaAmericaInfoSystems = 0x1179, + TridentMicrosystems = 0x1023, + TsengLabsInc = 0x100c, + TundraSemiconductorCorp = 0x10e3, + VIATechnologiesInc = 0x1106, + VMWareInc = 0x15ad, + Weitek = 0x100e, + Unknown = 0xffff, } -impl DeviceClass { - pub fn from_u8(val: u8) -> DeviceClass { - match val { - 0x00 => DeviceClass::UnclassifiedDevice, - 0x01 => DeviceClass::MassStorageController, - 0x02 => DeviceClass::NetworkController, - 0x03 => DeviceClass::DisplayController, - 0x04 => DeviceClass::MultimediaController, - 0x05 => DeviceClass::MemoryController, - 0x06 => DeviceClass::BridgeDevice, - 0x07 => DeviceClass::CommunicationController, - 0x08 => DeviceClass::GenericSystemPeripheral, - 0x09 => DeviceClass::InputDevice, - 0x0a => DeviceClass::DockingStation, - 0x0b => DeviceClass::Processor, - 0x0c => DeviceClass::SerialBusController, - 0x0d => DeviceClass::WirelessController, - 0x0e => DeviceClass::IntelligentController, - 0x0f => DeviceClass::SatelliteCommunicationController, - 0x10 => DeviceClass::EncryptionController, - 0x11 => DeviceClass::SignalProcessingController, - 0x40 => DeviceClass::Coprocessor, - _ => DeviceClass::UnclassifiedDevice, - } - } -} - -pub struct PciIO {} - -impl PortOps for PciIO { - unsafe fn read8(&self, port: u16) -> u8 { - cpuio::inb(port as u16) - } - - unsafe fn read16(&self, port: u16) -> u16 { - cpuio::inw(port as u16) - } - - unsafe fn read32(&self, port: u16) -> u32 { - cpuio::inl(port as u16) - } - - unsafe fn write8(&self, port: u16, val: u8) { - cpuio::outb(val, port as u16); - } - - unsafe fn write16(&self, port: u16, val: u16) { - cpuio::outw(val, port as u16); - } - - unsafe fn write32(&self, port: u16, val: u32) { - cpuio::outl(val, port as u16); - } +pub struct PciDevice { + pub vendor: Vendors, } diff --git a/ableos/src/experiments/absi.rs b/ableos/src/experiments/absi.rs index d4aecfb7..97c4689e 100644 --- a/ableos/src/experiments/absi.rs +++ b/ableos/src/experiments/absi.rs @@ -65,7 +65,7 @@ pub fn colorify(eval: &str) { } } } -use alloc::string::String; + use logos::Logos; #[derive(Logos, Debug, PartialEq)] @@ -85,7 +85,7 @@ pub enum Token { Error, } pub fn colorify_2(eval: &str) { - let mut lexer = Token::lexer(eval); + let lexer = Token::lexer(eval); for token in lexer { use Token::*; match token { @@ -99,7 +99,7 @@ pub fn colorify_2(eval: &str) { kprint!("{}", text); } err => { - error!("Error parsing"); + error!("Error parsing {:?}", err); } } } diff --git a/ableos/src/experiments/futex.rs b/ableos/src/experiments/futex.rs index 13b1ac89..6453a5f5 100644 --- a/ableos/src/experiments/futex.rs +++ b/ableos/src/experiments/futex.rs @@ -1,7 +1,5 @@ use core::time::Duration; -use alloc::vec::Vec; - // pub struct Duration {} pub struct AtomicU32(u32); diff --git a/ableos/src/experiments/info.rs b/ableos/src/experiments/info.rs index 901a3d4f..3455af3d 100644 --- a/ableos/src/experiments/info.rs +++ b/ableos/src/experiments/info.rs @@ -1,4 +1,3 @@ -#![feature(asm)] #![cfg_attr( not(any(target_arch = "x86_64", target_arch = "x86")), allow(dead_code) diff --git a/ableos/src/experiments/y_compositor/window.rs b/ableos/src/experiments/y_compositor/window.rs index 683cfb76..6e4a44f7 100644 --- a/ableos/src/experiments/y_compositor/window.rs +++ b/ableos/src/experiments/y_compositor/window.rs @@ -1,8 +1,5 @@ use crate::driver_traits::graphics::Point; -use alloc::string::String; -use alloc::vec::Vec; - pub struct MenuOption { symbol: char, } diff --git a/ableos/src/filesystem/mod.rs b/ableos/src/filesystem/mod.rs index b842d649..9eceb517 100644 --- a/ableos/src/filesystem/mod.rs +++ b/ableos/src/filesystem/mod.rs @@ -1,13 +1,10 @@ -use { - alloc::{format, string::String, vec::Vec}, - ext2::{ - fs::{ - sync::{Inode, Synced}, - Ext2, - }, - sector::{SectorSize, Size1024}, - volume::Volume, +use ext2::{ + fs::{ + sync::{Inode, Synced}, + Ext2, }, + sector::{SectorSize, Size1024}, + volume::Volume, }; fn load_fs() -> Synced>> { diff --git a/ableos/src/graphics/mod.rs b/ableos/src/graphics/mod.rs index 3be4afcb..0894ab52 100644 --- a/ableos/src/graphics/mod.rs +++ b/ableos/src/graphics/mod.rs @@ -1,6 +1,6 @@ use crate::vga_e::VGAE; use ab_glyph::{Font, FontRef, Glyph}; -use alloc::{boxed::Box, vec, vec::Vec}; + use shadeable::{evaluate_shader, pixel_format::Rgba64}; use spin; use vga::{colors::Color16, writers::GraphicsWriter}; @@ -126,7 +126,6 @@ impl ScreenBuffer { // TODO force clear pub fn force_redraw(&mut self) { - use shadeable::pixel_format::into_vga_16; VGAE.lock().clear_screen(vga::colors::Color16::Black); } diff --git a/ableos/src/kernel_state.rs b/ableos/src/kernel_state.rs index e4a99bf8..78f8d148 100644 --- a/ableos/src/kernel_state.rs +++ b/ableos/src/kernel_state.rs @@ -1,4 +1,3 @@ -use alloc::string::{String, ToString}; use lazy_static::lazy_static; lazy_static! { diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 4ce7390f..8916bb97 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,15 +1,12 @@ #![allow(clippy::empty_loop)] -use acpi::AcpiTables; use x86_64::instructions::interrupts::{disable, enable}; -use crate::scratchpad; +use crate::{boot_conf::KernelConfig, scratchpad}; use { crate::{ arch::{init, sloop}, - boot_conf, - boot_conf::BootConfig, capabilities::FileAccess, experiments::{ info::master, @@ -20,29 +17,27 @@ use { scheduler::SCHEDULER, VgaBuffer, SCREEN_BUFFER, }, - alloc::{ - format, - string::{String, ToString}, - vec, - }, - core::sync::atomic::{AtomicU64, Ordering::*}, facepalm::start_facepalm, lazy_static::lazy_static, - log::*, shadeable::pixel_format::from_vga_16, vga::colors::Color16, }; lazy_static! { // TODO: Change this structure to allow for multiple cores loaded - pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new(); + pub static ref KERNEL_CONF: KernelConfig = KernelConfig::new(); } /// The main entry point of the kernel #[no_mangle] pub fn kernel_main() -> ! { init::init(); - log::set_max_level(BOOT_CONF.log_level()); + + if KERNEL_CONF.logging.enabled { + log::set_max_level(KERNEL_CONF.log_level()); + } else { + log::set_max_level(log::LevelFilter::Off); + } let mut scheduler = SCHEDULER.lock(); @@ -74,16 +69,6 @@ pub fn kernel_main() -> ! { mode.copy_to_buffer(); } - // TODO: create a scratchpad module - if false { - // Currently not implemented - let acpi_handler = AcpiStruct {}; - let mut table; - unsafe { - table = AcpiTables::search_for_rsdp_bios(acpi_handler); - } - } - start_facepalm(); scratchpad(); @@ -148,7 +133,7 @@ impl acpi::AcpiHandler for AcpiStruct { todo!("map_physical_region"); } - fn unmap_physical_region(region: &acpi::PhysicalMapping) { + fn unmap_physical_region(_region: &acpi::PhysicalMapping) { todo!("unmap_physical_region"); } } diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 283e4220..b7826aed 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -12,7 +12,8 @@ exclusive_range_pattern, lang_items, naked_functions, - slice_pattern + slice_pattern, + prelude_import )] /// Contains architecture specific code for aarch64. @@ -33,6 +34,7 @@ pub mod arch; #[macro_use] pub mod print; pub mod devices; +pub mod port_io; pub mod rhai_shell; pub mod wasm_jumploader; @@ -43,7 +45,6 @@ pub extern crate log; // Modules // ///////////// pub mod allocator; -pub mod boot_conf; pub mod driver_traits; pub mod experiments; pub mod graphics; @@ -66,7 +67,6 @@ pub extern crate externc_libm as libm; // Re-exports /// //////////////// pub use allocator::*; -pub use boot_conf::*; pub use driver_traits::*; pub use experiments::*; pub use graphics::*; @@ -79,7 +79,7 @@ pub use scheduler::*; pub use utils::*; pub use vga_e::*; pub use wasm::*; - +pub mod boot_conf; pub mod virtio; pub use virtio::*; @@ -99,3 +99,8 @@ pub mod filesystem; pub use kernel; pub use kernel::messaging; pub use kernel::panic; + +pub mod prelude; + +#[prelude_import] +pub use prelude::rust_2021::*; diff --git a/ableos/src/logger.rs b/ableos/src/logger.rs index ee6bdb1e..ccbba62e 100644 --- a/ableos/src/logger.rs +++ b/ableos/src/logger.rs @@ -1,9 +1,10 @@ use core::sync::atomic::Ordering; +use crate::network::socket::{SimpleSock, Socket}; use crate::serial_println; + use kernel::TICK; use lliw::{Fg, Reset}; -pub use log::{debug, info, trace, warn}; use log::{Level, Metadata, Record}; struct SimpleLogger; @@ -29,7 +30,13 @@ impl log::Log for SimpleLogger { log::Level::Debug => color = (Fg::Blue, "$BLUE$"), log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), } - + let msg = format!( + "[{}{}$RESET$][$GREEN${}$RESET$]{}\n", + color.1, + record.level(), + time_float, + record.args() + ); serial_println!( "[{}{}{}][{}{}{}] {}", color.0, @@ -40,6 +47,14 @@ impl log::Log for SimpleLogger { Reset, record.args(), ); + + let log_socket_id = SimpleSock::grab_socket("Logger".to_string()); + match log_socket_id { + Some(mut log_socket_id) => { + log_socket_id.write(msg.as_bytes().to_vec()); + } + None => warn!("No socket found for Logger"), + } } } /// Clear the log buffer diff --git a/ableos/src/port_io.rs b/ableos/src/port_io.rs new file mode 100644 index 00000000..15b6d666 --- /dev/null +++ b/ableos/src/port_io.rs @@ -0,0 +1,16 @@ +use cpuio::{inb, inl, outb, outl}; + +pub fn read32(reg: u16) -> u32 { + unsafe { inl(reg) } +} +pub fn read8(reg: u16) -> u8 { + unsafe { inb(reg) } +} + +pub fn write32(reg: u16, val: u32) { + unsafe { outl(val, reg) } +} + +pub fn write8(reg: u16, val: u8) { + unsafe { outb(val, reg) } +} diff --git a/ableos/src/prelude/mod.rs b/ableos/src/prelude/mod.rs new file mode 100644 index 00000000..77dad8eb --- /dev/null +++ b/ableos/src/prelude/mod.rs @@ -0,0 +1 @@ +pub mod rust_2021; diff --git a/ableos/src/prelude/rust_2021.rs b/ableos/src/prelude/rust_2021.rs new file mode 100644 index 00000000..dc001f50 --- /dev/null +++ b/ableos/src/prelude/rust_2021.rs @@ -0,0 +1,8 @@ +pub use core::arch::asm; +pub use core::prelude::rust_2021::*; +pub use core::prelude::v1::*; + +pub use crate::print::*; +pub use log::{debug, info, trace, warn}; + +pub use alloc::{boxed::Box, format, string::*, vec, vec::*}; diff --git a/ableos/src/print.rs b/ableos/src/print.rs index 65b05527..f481b0ae 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -19,8 +19,7 @@ impl core::fmt::Write for Stdout { } #[cfg(target_arch = "x86_64")] fn write_str(&mut self, s: &str) -> Result<(), Error> { - use crate::{experiments::absi::colorify_2, kprint}; - // colorify_2(s); + use crate::kprint; kprint!("{}", s); Ok(()) } diff --git a/ableos/src/proto_filetable/file.rs b/ableos/src/proto_filetable/file.rs index 4e0f0bea..eb3889ed 100644 --- a/ableos/src/proto_filetable/file.rs +++ b/ableos/src/proto_filetable/file.rs @@ -1,7 +1,5 @@ use core::fmt; -use alloc::{string::String, vec, vec::Vec}; - #[derive(Debug, PartialEq, Clone)] pub struct PathRep { pub location: FileLocations, diff --git a/ableos/src/proto_filetable/mod.rs b/ableos/src/proto_filetable/mod.rs index 51103af3..030c3a50 100644 --- a/ableos/src/proto_filetable/mod.rs +++ b/ableos/src/proto_filetable/mod.rs @@ -15,11 +15,6 @@ //! The file table is not thread safe. //! The file table is not persistent. -use alloc::{ - string::{String, ToString}, - vec::Vec, -}; - use hashbrown::HashMap; pub mod contain; diff --git a/ableos/src/relib/clparse/mod.rs b/ableos/src/relib/clparse/mod.rs index c71a1886..818d27b8 100644 --- a/ableos/src/relib/clparse/mod.rs +++ b/ableos/src/relib/clparse/mod.rs @@ -1,9 +1,3 @@ -use alloc::{ - string::{String, ToString}, - vec, - vec::Vec, -}; - /* clparse * A simple command line parser for ableOS diff --git a/ableos/src/relib/encoding/bin.rs b/ableos/src/relib/encoding/bin.rs index 3d2b2d96..ad3cb143 100644 --- a/ableos/src/relib/encoding/bin.rs +++ b/ableos/src/relib/encoding/bin.rs @@ -1,5 +1,3 @@ -use alloc::boxed::Box; - pub struct BinCodeWriter { pub stream: Box, } diff --git a/ableos/src/relib/encoding/rle.rs b/ableos/src/relib/encoding/rle.rs index ef9f767c..fcd4e8ce 100644 --- a/ableos/src/relib/encoding/rle.rs +++ b/ableos/src/relib/encoding/rle.rs @@ -1,6 +1,3 @@ -use alloc::vec; -use alloc::vec::Vec; - pub fn encode(bytes: &[u8]) -> Vec { let mut encoding; diff --git a/ableos/src/relib/network/socket.rs b/ableos/src/relib/network/socket.rs index 414e0b5e..9e35600e 100644 --- a/ableos/src/relib/network/socket.rs +++ b/ableos/src/relib/network/socket.rs @@ -1,7 +1,3 @@ -use alloc::string::String; -use alloc::vec; -use alloc::vec::Vec; - pub type Stream = Vec; #[derive(Debug)] diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index d611973f..cf7773fa 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -1,5 +1,3 @@ -use alloc::vec::Vec; - pub fn rhai_shell() { let engine = engine_construction(); let mut scope = rhai::Scope::new(); @@ -32,7 +30,6 @@ lazy_static::lazy_static!( ; ); -use alloc::string::String; use rhai::Engine; use x86_64::instructions::interrupts::{disable, enable}; @@ -84,12 +81,15 @@ fn engine_construction() -> Engine { engine.register_fn("poke", poke_memory); engine.register_fn("sloop", sloop); engine.register_fn("wasm", interp); + engine.register_fn("log_dump", log_dump); + engine } /// Examine a memory pointer pub fn peek_memory(ptr: i64) -> u8 { let ptr: usize = ptr as usize; + println!(">:("); unsafe { *(ptr as *const u8) } } @@ -97,3 +97,26 @@ pub fn poke_memory(ptr: i64, val: u8) { let ptr: usize = ptr as usize; unsafe { *(ptr as *mut u8) = val } } + +pub fn log_dump() { + use crate::network::socket::SimpleSock; + use crate::relib::network::socket::Socket; + let log_socket_id = SimpleSock::grab_socket("Logger".to_string()); + match log_socket_id { + Some(mut log_socket_id) => { + let log = log_socket_id.peek(); + + match log { + crate::network::socket::SocketReturns::ReadOk(ok) => { + for x in ok.iter() { + print!("{}", *x as char); + } + } + + crate::network::socket::SocketReturns::ReadIndexOutOfBounds => todo!(), + crate::network::socket::SocketReturns::WriteOk => todo!(), + } + } + None => warn!("No socket found for Logger"), + } +} diff --git a/ableos/src/scheduler/capabilities.rs b/ableos/src/scheduler/capabilities.rs index 0ba1b87a..0a000706 100644 --- a/ableos/src/scheduler/capabilities.rs +++ b/ableos/src/scheduler/capabilities.rs @@ -1,4 +1,4 @@ -use alloc::vec::Vec; +#![allow(missing_docs)] use crate::file::PathRep; diff --git a/ableos/src/scheduler/mod.rs b/ableos/src/scheduler/mod.rs index cf63235e..a3b52097 100644 --- a/ableos/src/scheduler/mod.rs +++ b/ableos/src/scheduler/mod.rs @@ -1,4 +1,4 @@ -#![warn(missing_docs)] +// #![warn(missing_docs)] //! The standard ableOS scheduler named //! @@ -6,8 +6,6 @@ //! The scheduler is also responsible for choosing the priority of a process. //! The scheduler is responsible for choosing which process to execute next. -use alloc::{string::ToString, vec::Vec}; - pub mod capabilities; pub mod proc; diff --git a/ableos/src/scheduler/new_sched.rs b/ableos/src/scheduler/new_sched.rs index 1192c3ed..cb68144c 100644 --- a/ableos/src/scheduler/new_sched.rs +++ b/ableos/src/scheduler/new_sched.rs @@ -1,5 +1,3 @@ -use alloc::{string::ToString, vec::Vec}; - use crate::{ capabilities::Capabilities, kmain::generate_process_pass, diff --git a/ableos/src/scheduler/proc.rs b/ableos/src/scheduler/proc.rs index 1d3955a2..ee135a81 100644 --- a/ableos/src/scheduler/proc.rs +++ b/ableos/src/scheduler/proc.rs @@ -1,7 +1,5 @@ //! Process definition and general utilities surrounding them -use alloc::string::String; - use super::{capabilities::Capabilities, Priority}; /// Process Identification diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 6062b358..768a0b43 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -1,63 +1,19 @@ -use { - crate::{ - devices::{ - id::match_vendor, - pci_inner::{DeviceClass, PciIO}, - Device, DEVICE_TABLE, - }, - rhai_shell::rhai_shell, - }, - alloc::{format, vec::Vec}, -}; +use acpi::AcpiTables; + +use crate::{kmain::AcpiStruct, rhai_shell::rhai_shell}; /// Experimental scratchpad for testing. pub fn scratchpad() { - let mut dev_list = Vec::new(); - let bus_scan; - unsafe { - bus_scan = pci::scan_bus(&PciIO {}, pci::CSpaceAccessMethod::IO); - } - for dev in bus_scan { - dev_list.push(dev); - } - - let device_table = &mut *DEVICE_TABLE.lock(); - - for x in dev_list { - let vendor_id_name = match_vendor(x.id.vendor_id); - use crate::devices::id::Vendor::*; - match vendor_id_name { - Unknown => {} - Ati => unsafe { - x.cspace_access_method.write32(&PciIO {}, x.loc, 0x0260, 1); - - x.cspace_access_method - .write32(&PciIO {}, x.loc, 0x0230, 0x00_ff_0000); - - // 0x0260 - }, - } - - let device_name = format!( - "{:?}-{:?}-{}", - vendor_id_name, - DeviceClass::from_u8(x.id.class), - x.id.device_id - ); - // println!("{}", device_name); - - device_table - .devices - .insert(device_name.clone(), Device::Pci(x)); - } - - /* - let message = "Hello, world!"; - - let xyz = ProcessMessage::new_from_string(PID(123), PID(0), message.to_string()); - - print!("{:?}", xyz); - */ - + pci_fun(); rhai_shell(); } + +pub fn pci_fun() {} + +pub fn acpi() { + let acpi_handler = AcpiStruct {}; + let _table; + unsafe { + _table = AcpiTables::search_for_rsdp_bios(acpi_handler); + } +} diff --git a/ableos/src/tests.rs b/ableos/src/tests.rs index 043e7bad..07ce4401 100644 --- a/ableos/src/tests.rs +++ b/ableos/src/tests.rs @@ -1,8 +1,3 @@ -use alloc::{ - format, - string::{String, ToString}, - vec, -}; use picorand::PicoRandGenerate; use rkyv::{ser::serializers::AllocSerializer, Deserialize}; use shadeable::pixel_format::from_vga_16; @@ -10,14 +5,14 @@ use vga::colors::Color16; use y_compositor_protocol::Version; use crate::{ - kmain::BOOT_CONF, + kmain::KERNEL_CONF, network::socket::{SimpleSock, Socket, SocketReturns}, - num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER, + num_to_vga16, VgaBuffer, SCREEN_BUFFER, }; use kernel::TICK; pub fn run_tests() { - if BOOT_CONF.run_tests { + if KERNEL_CONF.tests.run_tests { // quick and dirty testing framework screen_writer_test(); socket_test(); @@ -26,11 +21,11 @@ pub fn run_tests() { socket_test_rng(); } - if BOOT_CONF.run_demos { + if KERNEL_CONF.tests.run_demos { graphics_api_demo(); } - if BOOT_CONF.run_shader_tests { + if KERNEL_CONF.tests.run_shader_tests { shader_tests(); } } diff --git a/ableos/src/vga_e.rs b/ableos/src/vga_e.rs index 3f333ba0..440be286 100644 --- a/ableos/src/vga_e.rs +++ b/ableos/src/vga_e.rs @@ -1,13 +1,6 @@ -use shadeable::pixel_format::Rgba64; - -use crate::SCREEN_BUFFER; - -use { - ab_glyph::{Font, FontRef, Glyph}, - vga::{ - colors::Color16, - writers::{Graphics640x480x16, GraphicsWriter}, - }, +use vga::{ + colors::Color16, + writers::{Graphics640x480x16, GraphicsWriter}, }; lazy_static::lazy_static! { diff --git a/ableos/src/wasm/mod.rs b/ableos/src/wasm/mod.rs index 58c4ca0c..9d77b9f2 100644 --- a/ableos/src/wasm/mod.rs +++ b/ableos/src/wasm/mod.rs @@ -1,5 +1,3 @@ -use alloc::vec::Vec; - /// `NULL a s m` as an array of 4 bytes pub const WASM_BINARY_MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6d]; /// `1 0 0 0` as an array of 4 bytes diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index 13a7d088..52140c33 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -1,4 +1,3 @@ -use alloc::format; use wasmi::{ Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue, Signature, Trap, ValueType, @@ -54,7 +53,6 @@ impl HostExternals { ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)), SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)), GET_TIME_INDEX => (&[], Some(ValueType::I32)), - _ => return false, }; signature.params() == params && signature.return_type() == ret_ty diff --git a/ableos/src/wasm_jumploader/mod.rs b/ableos/src/wasm_jumploader/mod.rs index e379b01d..02c06a40 100644 --- a/ableos/src/wasm_jumploader/mod.rs +++ b/ableos/src/wasm_jumploader/mod.rs @@ -3,7 +3,6 @@ pub mod host_functions; extern crate wasmi; // extern crate wabt; -use alloc::vec::Vec; use genfs::{Fs, OpenOptions}; use wasmi::{ImportsBuilder, ModuleInstance}; diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml new file mode 100644 index 00000000..02774937 --- /dev/null +++ b/kernel/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "./json_targets/x86_64-ableos.json" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index d2f8b150..7c1c003d 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -5,6 +5,8 @@ version = "0.1.2" [dependencies] +log = "0.4.14" + [dependencies.lazy_static] version = "1.4.0" default-features = false diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 0d4f1304..7ed790e9 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,5 +1,7 @@ #![deny(missing_docs)] #![no_std] +#![feature(prelude_import)] + //! The ableOS kernel. pub mod device_interface; diff --git a/kernel/src/panic.rs b/kernel/src/panic.rs index 0f1323ae..74602f66 100644 --- a/kernel/src/panic.rs +++ b/kernel/src/panic.rs @@ -1,8 +1,12 @@ //! - use core::panic::PanicInfo; +// #[macro_use] +// use log; + #[panic_handler] fn panic_handler(_info: &PanicInfo) -> ! { + // error!("{}", _info); + loop {} } diff --git a/shadeable/src/engine_internals.rs b/shadeable/src/engine_internals.rs index 1013c873..960a2545 100644 --- a/shadeable/src/engine_internals.rs +++ b/shadeable/src/engine_internals.rs @@ -1,5 +1,5 @@ use crate::pixel_format::{get_a, get_b, get_g, get_r, set_a, set_b, set_g, set_r}; -use crate::pixel_format::{new_rgba64, rgba_div, Rgba64}; +use crate::pixel_format::{rgba_div, Rgba64}; use log::{debug, info}; use rhai::Engine; @@ -7,13 +7,13 @@ use rhai::Engine; pub fn engine_startup() -> Engine { let mut engine = Engine::new(); - // engine.on_print(|x| info!("PRINTED FROM SHADER: {}", x)); + engine.on_print(|x| info!("PRINTED FROM SHADER: {}", x)); // Any function or closure that takes a '&str', an 'Option<&str>' and a 'Position' argument // can be used to override 'debug'. engine.on_debug(|x, src, pos| { let src = src.unwrap_or("unknown"); - // debug!("SHADER DEBUG of {} at {:?}: {}", src, pos, x) + debug!("SHADER DEBUG of {} at {:?}: {}", src, pos, x); }); engine