TOML config|moved a ton of boiler plate to prelude

This commit is contained in:
Able 2022-03-11 13:51:47 -06:00
parent 05ce9f61c7
commit 0379a34a59
49 changed files with 300 additions and 355 deletions

70
ableos/Cargo.lock generated
View file

@ -34,7 +34,7 @@ dependencies = [
"externc-libm", "externc-libm",
"facepalm", "facepalm",
"genfs", "genfs",
"hashbrown", "hashbrown 0.11.2",
"kernel", "kernel",
"lazy_static", "lazy_static",
"libwasm", "libwasm",
@ -43,7 +43,6 @@ dependencies = [
"log", "log",
"logos", "logos",
"pc-beeper", "pc-beeper",
"pci",
"pic8259", "pic8259",
"picorand", "picorand",
"pretty-hex", "pretty-hex",
@ -51,10 +50,10 @@ dependencies = [
"rhai", "rhai",
"rkyv", "rkyv",
"serde", "serde",
"serde_json",
"shadeable", "shadeable",
"smoltcp", "smoltcp",
"spin 0.5.2", "spin 0.5.2",
"toml",
"uart_16550", "uart_16550",
"unicode-width", "unicode-width",
"vga", "vga",
@ -75,6 +74,12 @@ dependencies = [
"rsdp", "rsdp",
] ]
[[package]]
name = "ahash"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"
@ -247,13 +252,23 @@ dependencies = [
"wasi", "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]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [ dependencies = [
"ahash", "ahash 0.7.6",
] ]
[[package]] [[package]]
@ -265,17 +280,12 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]] [[package]]
name = "kernel" name = "kernel"
version = "0.1.2" version = "0.1.2"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log",
"versioning", "versioning",
] ]
@ -303,7 +313,7 @@ checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]] [[package]]
name = "libwasm" name = "libwasm"
version = "0.1.0" 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]] [[package]]
name = "linked_list_allocator" name = "linked_list_allocator"
@ -440,14 +450,6 @@ dependencies = [
"x86_64", "x86_64",
] ]
[[package]]
name = "pci"
version = "0.0.1"
source = "git+https://gitlab.com/robigalia/pci#4e2fddc61825568b1d14d09fdc669389e6c43f02"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "pic8259" name = "pic8259"
version = "0.10.2" version = "0.10.2"
@ -540,7 +542,7 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49c94fda0280985896ed6d8bf0b43bbb5a7f0e39ccc8728ac907ddb4f06dae94" checksum = "49c94fda0280985896ed6d8bf0b43bbb5a7f0e39ccc8728ac907ddb4f06dae94"
dependencies = [ dependencies = [
"ahash", "ahash 0.7.6",
"core-error", "core-error",
"instant", "instant",
"libm", "libm",
@ -568,7 +570,7 @@ version = "0.7.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439655b8d657bcb28264da8e5380d55549e34ffc4149bea9e3521890a122a7bd" checksum = "439655b8d657bcb28264da8e5380d55549e34ffc4149bea9e3521890a122a7bd"
dependencies = [ dependencies = [
"hashbrown", "hashbrown 0.11.2",
"ptr_meta", "ptr_meta",
"rkyv_derive", "rkyv_derive",
"seahash", "seahash",
@ -600,12 +602,6 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "ryu"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -638,17 +634,6 @@ dependencies = [
"syn", "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]] [[package]]
name = "shadeable" name = "shadeable"
version = "0.1.0" version = "0.1.0"
@ -736,6 +721,15 @@ dependencies = [
"crunchy", "crunchy",
] ]
[[package]]
name = "toml"
version = "0.5.6"
source = "git+https://github.com/diondokter/toml-rs#c4161aa70202b3992dbec79b76e7a8659713b604"
dependencies = [
"hashbrown 0.7.2",
"serde",
]
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.14.0" version = "0.14.0"

View file

@ -9,6 +9,9 @@ panic = "abort"
[package.metadata.bootimage] [package.metadata.bootimage]
run-args = [ run-args = [
"--nodefaults",
"-cpu", "-cpu",
"Broadwell-v3", "Broadwell-v3",
@ -17,28 +20,24 @@ run-args = [
"-smp", "-smp",
"cores=2", "cores=2",
# An example gpu used with ableOS
"-device",
# "virtio-gpu",
"ati-vga",
# An example disk used with ableOS "-device", #"ati-vga",
"-device", "cirrus-vga",
"virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4",
# "-device",
# "virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4",
# A simple example of a boot image # A simple example of a boot image
"-drive", # "-drive",
"file=disk.qcow2,if=none,id=drive0", # "file=disk.qcow2,if=none,id=drive0",
# "-device",
# "virtio-rng",
# "-qmp",
# "unix:../qmp-sock,server,nowait"
"-device",
"virtio-rng",
"-qmp",
"unix:../qmp-sock,server,nowait"
] ]
test-args = [ test-args = [
@ -52,7 +51,6 @@ test-args = [
linked_list_allocator = "0.9.0" linked_list_allocator = "0.9.0"
lliw = "0.2.0" lliw = "0.2.0"
# qoi_rs = "*" # qoi_rs = "*"
@ -70,7 +68,7 @@ genfs = "0.1.0"
pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"} pc-beeper = {git = "https://github.com/AbleOS/pc-beeper"}
rhai = "1.5" 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"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0" acpi = "4.1.0"
@ -93,10 +91,7 @@ version = "*"
default-features = false default-features = false
features = ["derive", "alloc"] features = ["derive", "alloc"]
[dependencies.serde_json]
version = "*"
default-features = false
features = ["alloc"]
[dependencies.hashbrown] [dependencies.hashbrown]
version = "0.11.2" version = "0.11.2"
@ -118,6 +113,15 @@ git = "https://git.ablecorp.us:443/able/y-compositor-protocol.git"
[dependencies.ext2] [dependencies.ext2]
git = "https://git.ablecorp.us:443/able/ext2-rs.git" 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] [dependencies.shadeable]
path = "../shadeable" path = "../shadeable"

12
ableos/assets/kernel.toml Normal file
View file

@ -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

View file

@ -1,7 +0,0 @@
{
"logging_level": "Trace",
"logger_padding": 10,
"run_tests": false,
"run_demos": false,
"run_shader_tests": false
}

View file

@ -1,4 +1,3 @@
use alloc::string::{String, ToString};
use hashbrown::HashMap; use hashbrown::HashMap;
lazy_static::lazy_static! { lazy_static::lazy_static! {

View file

@ -9,6 +9,11 @@ pub struct AAloc;
unsafe impl GlobalAlloc for AAloc { unsafe impl GlobalAlloc for AAloc {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
println!("Allocating memory");
println!("{}", _layout.size());
println!("{}", _layout.align());
null_mut() null_mut()
} }

View file

@ -8,13 +8,7 @@ pub const HEAP_MULTIPLIER: usize = 100000;
pub const HEAP_BASE: usize = 100; pub const HEAP_BASE: usize = 100;
pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER; 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; use linked_list_allocator::LockedHeap;
#[global_allocator] #[global_allocator]
@ -22,5 +16,7 @@ pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
#[alloc_error_handler] #[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
// error!("allocation error: {:?}", layout);
panic!("allocation error: {:?}", layout) panic!("allocation error: {:?}", layout)
} }

View file

@ -1,5 +1,5 @@
use alloc::alloc::{GlobalAlloc, Layout}; use alloc::alloc::{GlobalAlloc, Layout};
// use core::alloc::{GlobalAlloc, Layout};
use crate::allocator::{HEAP_SIZE, HEAP_START}; use crate::allocator::{HEAP_SIZE, HEAP_START};
use core::ptr::null_mut; use core::ptr::null_mut;
use x86_64::{ use x86_64::{

View file

@ -5,6 +5,12 @@ use super::{gdt, interrupts};
/// x86_64 initialization /// x86_64 initialization
pub fn init() { 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(); let result = logger::init();
match result { match result {
Ok(_) => {} Ok(_) => {}

View file

@ -1,5 +1,4 @@
use log::LevelFilter; use log::LevelFilter;
// use rkyv::{Deserialize, Serialize};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Debug, Deserialize)] #[derive(Serialize, Debug, Deserialize)]
@ -19,29 +18,21 @@ pub enum LogLevel {
} }
#[derive(Serialize, Debug, Deserialize)] #[derive(Serialize, Debug, Deserialize)]
pub struct BootConfig { pub struct KernelConfig {
pub logging_level: LogLevel, pub boot: BootConfig,
pub logger_padding: usize, pub logging: LoggingConfig,
pub run_tests: bool, pub tests: TestsConfig,
pub run_demos: bool,
pub run_shader_tests: bool,
} }
impl BootConfig { impl KernelConfig {
pub fn new() -> Self { pub fn new() -> Self {
let data = include_str!("../assets/kernel_config.json"); let p: KernelConfig = toml::from_str(include_str!("../assets/kernel.toml")).unwrap();
// 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);
p p
} }
pub fn log_level(&self) -> LevelFilter { pub fn log_level(&self) -> LevelFilter {
use LevelFilter::*; use LevelFilter::*;
match self.logging_level { match self.logging.level {
LogLevel::Off => Off, LogLevel::Off => Off,
LogLevel::Error => Error, LogLevel::Error => Error,
LogLevel::Warn => Warn, 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<String>,
}

View file

@ -1,12 +1,15 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Vendor { pub enum Vendor {
Unknown = 0, Unknown = 0,
Ati = 4098,
Ati = 1002,
} }
pub fn match_vendor(id: u16) -> Vendor { pub fn match_vendor(id: u16) -> Vendor {
use Vendor::*;
match id { match id {
4098 => Vendor::Ati, 1002 => Ati,
_ => Vendor::Unknown,
_ => Unknown,
} }
} }

View file

@ -2,12 +2,7 @@ pub mod character_devs;
pub mod id; pub mod id;
pub mod pci_inner; pub mod pci_inner;
use alloc::{
boxed::Box,
string::{String, ToString},
};
use hashbrown::HashMap; use hashbrown::HashMap;
use pci::PCIDevice;
use kernel::device_interface::character::CharacterDevice; use kernel::device_interface::character::CharacterDevice;
@ -15,7 +10,6 @@ use kernel::device_interface::character::CharacterDevice;
// #[derive(Debug)] // #[derive(Debug)]
pub enum Device { pub enum Device {
Character(Box<dyn CharacterDevice>), Character(Box<dyn CharacterDevice>),
Pci(PCIDevice),
} }
unsafe impl Sync for Device {} unsafe impl Sync for Device {}
unsafe impl Send for Device {} unsafe impl Send for Device {}

View file

@ -1,86 +1,55 @@
//! map the DeviceClass via <https://pci-ids.ucw.cz/read/PD> //! map the DeviceClass via <https://pci-ids.ucw.cz/read/PD>
//!
//!
use pci::PortOps; #[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] fn scan_pci_bus() {}
pub enum DeviceClass {
UnclassifiedDevice = 0,
MassStorageController = 0x01,
NetworkController = 0x02,
DisplayController = 0x03,
MultimediaController = 0x04,
MemoryController = 0x05,
BridgeDevice = 0x06,
CommunicationController = 0x07, pub enum Vendors {
GenericSystemPeripheral = 0x08, ThreeDfxInteractiveInc = 0x121a,
InputDevice = 0x09, ThreeDLabs = 0x3d3d,
DockingStation = 0x0a, AllianceSemiconductorCorp = 0x1142,
Processor = 0x0b, ARKLogicInc = 0xedd8,
SerialBusController = 0x0c, ATITechnologiesInc = 0x1002,
WirelessController = 0x0d, AvanceLogicIncALI = 0x1005,
IntelligentController = 0x0e, ChipsandTechnologies = 0x102c,
SatelliteCommunicationController = 0x0f, CirrusLogic = 0x1013,
EncryptionController = 0x10, Compaq = 0x0e11,
SignalProcessingController = 0x11, CyrixCorp = 0x1078,
DiamondMultimediaSystems = 0x1092,
// 14 DigitalEquipmentCorp = 0x1011,
// 15 Iit = 0x1061,
// 16 IntegratedMicroSolutionsInc = 0x10e0,
Coprocessor = 40, IntelCorp = 0x8086,
// 64 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 struct PciDevice {
pub fn from_u8(val: u8) -> DeviceClass { pub vendor: Vendors,
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);
}
} }

View file

@ -65,7 +65,7 @@ pub fn colorify(eval: &str) {
} }
} }
} }
use alloc::string::String;
use logos::Logos; use logos::Logos;
#[derive(Logos, Debug, PartialEq)] #[derive(Logos, Debug, PartialEq)]
@ -85,7 +85,7 @@ pub enum Token {
Error, Error,
} }
pub fn colorify_2(eval: &str) { pub fn colorify_2(eval: &str) {
let mut lexer = Token::lexer(eval); let lexer = Token::lexer(eval);
for token in lexer { for token in lexer {
use Token::*; use Token::*;
match token { match token {
@ -99,7 +99,7 @@ pub fn colorify_2(eval: &str) {
kprint!("{}", text); kprint!("{}", text);
} }
err => { err => {
error!("Error parsing"); error!("Error parsing {:?}", err);
} }
} }
} }

View file

@ -1,7 +1,5 @@
use core::time::Duration; use core::time::Duration;
use alloc::vec::Vec;
// pub struct Duration {} // pub struct Duration {}
pub struct AtomicU32(u32); pub struct AtomicU32(u32);

View file

@ -1,4 +1,3 @@
#![feature(asm)]
#![cfg_attr( #![cfg_attr(
not(any(target_arch = "x86_64", target_arch = "x86")), not(any(target_arch = "x86_64", target_arch = "x86")),
allow(dead_code) allow(dead_code)

View file

@ -1,8 +1,5 @@
use crate::driver_traits::graphics::Point; use crate::driver_traits::graphics::Point;
use alloc::string::String;
use alloc::vec::Vec;
pub struct MenuOption { pub struct MenuOption {
symbol: char, symbol: char,
} }

View file

@ -1,13 +1,10 @@
use { use ext2::{
alloc::{format, string::String, vec::Vec}, fs::{
ext2::{ sync::{Inode, Synced},
fs::{ Ext2,
sync::{Inode, Synced},
Ext2,
},
sector::{SectorSize, Size1024},
volume::Volume,
}, },
sector::{SectorSize, Size1024},
volume::Volume,
}; };
fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> { fn load_fs() -> Synced<Ext2<Size1024, Vec<u8>>> {

View file

@ -1,6 +1,6 @@
use crate::vga_e::VGAE; use crate::vga_e::VGAE;
use ab_glyph::{Font, FontRef, Glyph}; use ab_glyph::{Font, FontRef, Glyph};
use alloc::{boxed::Box, vec, vec::Vec};
use shadeable::{evaluate_shader, pixel_format::Rgba64}; use shadeable::{evaluate_shader, pixel_format::Rgba64};
use spin; use spin;
use vga::{colors::Color16, writers::GraphicsWriter}; use vga::{colors::Color16, writers::GraphicsWriter};
@ -126,7 +126,6 @@ impl ScreenBuffer {
// TODO force clear // TODO force clear
pub fn force_redraw(&mut self) { pub fn force_redraw(&mut self) {
use shadeable::pixel_format::into_vga_16;
VGAE.lock().clear_screen(vga::colors::Color16::Black); VGAE.lock().clear_screen(vga::colors::Color16::Black);
} }

View file

@ -1,4 +1,3 @@
use alloc::string::{String, ToString};
use lazy_static::lazy_static; use lazy_static::lazy_static;
lazy_static! { lazy_static! {

View file

@ -1,15 +1,12 @@
#![allow(clippy::empty_loop)] #![allow(clippy::empty_loop)]
use acpi::AcpiTables;
use x86_64::instructions::interrupts::{disable, enable}; use x86_64::instructions::interrupts::{disable, enable};
use crate::scratchpad; use crate::{boot_conf::KernelConfig, scratchpad};
use { use {
crate::{ crate::{
arch::{init, sloop}, arch::{init, sloop},
boot_conf,
boot_conf::BootConfig,
capabilities::FileAccess, capabilities::FileAccess,
experiments::{ experiments::{
info::master, info::master,
@ -20,29 +17,27 @@ use {
scheduler::SCHEDULER, scheduler::SCHEDULER,
VgaBuffer, SCREEN_BUFFER, VgaBuffer, SCREEN_BUFFER,
}, },
alloc::{
format,
string::{String, ToString},
vec,
},
core::sync::atomic::{AtomicU64, Ordering::*},
facepalm::start_facepalm, facepalm::start_facepalm,
lazy_static::lazy_static, lazy_static::lazy_static,
log::*,
shadeable::pixel_format::from_vga_16, shadeable::pixel_format::from_vga_16,
vga::colors::Color16, vga::colors::Color16,
}; };
lazy_static! { lazy_static! {
// TODO: Change this structure to allow for multiple cores loaded // 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 /// The main entry point of the kernel
#[no_mangle] #[no_mangle]
pub fn kernel_main() -> ! { pub fn kernel_main() -> ! {
init::init(); 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(); let mut scheduler = SCHEDULER.lock();
@ -74,16 +69,6 @@ pub fn kernel_main() -> ! {
mode.copy_to_buffer(); 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(); start_facepalm();
scratchpad(); scratchpad();
@ -148,7 +133,7 @@ impl acpi::AcpiHandler for AcpiStruct {
todo!("map_physical_region"); todo!("map_physical_region");
} }
fn unmap_physical_region<T>(region: &acpi::PhysicalMapping<Self, T>) { fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
todo!("unmap_physical_region"); todo!("unmap_physical_region");
} }
} }

View file

@ -12,7 +12,8 @@
exclusive_range_pattern, exclusive_range_pattern,
lang_items, lang_items,
naked_functions, naked_functions,
slice_pattern slice_pattern,
prelude_import
)] )]
/// Contains architecture specific code for aarch64. /// Contains architecture specific code for aarch64.
@ -33,6 +34,7 @@ pub mod arch;
#[macro_use] #[macro_use]
pub mod print; pub mod print;
pub mod devices; pub mod devices;
pub mod port_io;
pub mod rhai_shell; pub mod rhai_shell;
pub mod wasm_jumploader; pub mod wasm_jumploader;
@ -43,7 +45,6 @@ pub extern crate log;
// Modules // // Modules //
///////////// /////////////
pub mod allocator; pub mod allocator;
pub mod boot_conf;
pub mod driver_traits; pub mod driver_traits;
pub mod experiments; pub mod experiments;
pub mod graphics; pub mod graphics;
@ -66,7 +67,6 @@ pub extern crate externc_libm as libm;
// Re-exports /// // Re-exports ///
//////////////// ////////////////
pub use allocator::*; pub use allocator::*;
pub use boot_conf::*;
pub use driver_traits::*; pub use driver_traits::*;
pub use experiments::*; pub use experiments::*;
pub use graphics::*; pub use graphics::*;
@ -79,7 +79,7 @@ pub use scheduler::*;
pub use utils::*; pub use utils::*;
pub use vga_e::*; pub use vga_e::*;
pub use wasm::*; pub use wasm::*;
pub mod boot_conf;
pub mod virtio; pub mod virtio;
pub use virtio::*; pub use virtio::*;
@ -99,3 +99,8 @@ pub mod filesystem;
pub use kernel; pub use kernel;
pub use kernel::messaging; pub use kernel::messaging;
pub use kernel::panic; pub use kernel::panic;
pub mod prelude;
#[prelude_import]
pub use prelude::rust_2021::*;

View file

@ -1,9 +1,10 @@
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use crate::network::socket::{SimpleSock, Socket};
use crate::serial_println; use crate::serial_println;
use kernel::TICK; use kernel::TICK;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
pub use log::{debug, info, trace, warn};
use log::{Level, Metadata, Record}; use log::{Level, Metadata, Record};
struct SimpleLogger; struct SimpleLogger;
@ -29,7 +30,13 @@ impl log::Log for SimpleLogger {
log::Level::Debug => color = (Fg::Blue, "$BLUE$"), log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"), log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
} }
let msg = format!(
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
color.1,
record.level(),
time_float,
record.args()
);
serial_println!( serial_println!(
"[{}{}{}][{}{}{}] {}", "[{}{}{}][{}{}{}] {}",
color.0, color.0,
@ -40,6 +47,14 @@ impl log::Log for SimpleLogger {
Reset, Reset,
record.args(), 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 /// Clear the log buffer

16
ableos/src/port_io.rs Normal file
View file

@ -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) }
}

View file

@ -0,0 +1 @@
pub mod rust_2021;

View file

@ -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::*};

View file

@ -19,8 +19,7 @@ impl core::fmt::Write for Stdout {
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> { fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::{experiments::absi::colorify_2, kprint}; use crate::kprint;
// colorify_2(s);
kprint!("{}", s); kprint!("{}", s);
Ok(()) Ok(())
} }

View file

@ -1,7 +1,5 @@
use core::fmt; use core::fmt;
use alloc::{string::String, vec, vec::Vec};
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct PathRep { pub struct PathRep {
pub location: FileLocations, pub location: FileLocations,

View file

@ -15,11 +15,6 @@
//! The file table is not thread safe. //! The file table is not thread safe.
//! The file table is not persistent. //! The file table is not persistent.
use alloc::{
string::{String, ToString},
vec::Vec,
};
use hashbrown::HashMap; use hashbrown::HashMap;
pub mod contain; pub mod contain;

View file

@ -1,9 +1,3 @@
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};
/* /*
clparse clparse
* A simple command line parser for ableOS * A simple command line parser for ableOS

View file

@ -1,5 +1,3 @@
use alloc::boxed::Box;
pub struct BinCodeWriter { pub struct BinCodeWriter {
pub stream: Box<u8>, pub stream: Box<u8>,
} }

View file

@ -1,6 +1,3 @@
use alloc::vec;
use alloc::vec::Vec;
pub fn encode(bytes: &[u8]) -> Vec<u8> { pub fn encode(bytes: &[u8]) -> Vec<u8> {
let mut encoding; let mut encoding;

View file

@ -1,7 +1,3 @@
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
pub type Stream = Vec<u8>; pub type Stream = Vec<u8>;
#[derive(Debug)] #[derive(Debug)]

View file

@ -1,5 +1,3 @@
use alloc::vec::Vec;
pub fn rhai_shell() { pub fn rhai_shell() {
let engine = engine_construction(); let engine = engine_construction();
let mut scope = rhai::Scope::new(); let mut scope = rhai::Scope::new();
@ -32,7 +30,6 @@ lazy_static::lazy_static!(
; ;
); );
use alloc::string::String;
use rhai::Engine; use rhai::Engine;
use x86_64::instructions::interrupts::{disable, enable}; use x86_64::instructions::interrupts::{disable, enable};
@ -84,12 +81,15 @@ fn engine_construction() -> Engine {
engine.register_fn("poke", poke_memory); engine.register_fn("poke", poke_memory);
engine.register_fn("sloop", sloop); engine.register_fn("sloop", sloop);
engine.register_fn("wasm", interp); engine.register_fn("wasm", interp);
engine.register_fn("log_dump", log_dump);
engine engine
} }
/// Examine a memory pointer /// Examine a memory pointer
pub fn peek_memory(ptr: i64) -> u8 { pub fn peek_memory(ptr: i64) -> u8 {
let ptr: usize = ptr as usize; let ptr: usize = ptr as usize;
println!(">:(");
unsafe { *(ptr as *const u8) } unsafe { *(ptr as *const u8) }
} }
@ -97,3 +97,26 @@ pub fn poke_memory(ptr: i64, val: u8) {
let ptr: usize = ptr as usize; let ptr: usize = ptr as usize;
unsafe { *(ptr as *mut u8) = val } 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"),
}
}

View file

@ -1,4 +1,4 @@
use alloc::vec::Vec; #![allow(missing_docs)]
use crate::file::PathRep; use crate::file::PathRep;

View file

@ -1,4 +1,4 @@
#![warn(missing_docs)] // #![warn(missing_docs)]
//! The standard ableOS scheduler named //! The standard ableOS scheduler named
//! //!
@ -6,8 +6,6 @@
//! The scheduler is also responsible for choosing the priority of a process. //! The scheduler is also responsible for choosing the priority of a process.
//! The scheduler is responsible for choosing which process to execute next. //! The scheduler is responsible for choosing which process to execute next.
use alloc::{string::ToString, vec::Vec};
pub mod capabilities; pub mod capabilities;
pub mod proc; pub mod proc;

View file

@ -1,5 +1,3 @@
use alloc::{string::ToString, vec::Vec};
use crate::{ use crate::{
capabilities::Capabilities, capabilities::Capabilities,
kmain::generate_process_pass, kmain::generate_process_pass,

View file

@ -1,7 +1,5 @@
//! Process definition and general utilities surrounding them //! Process definition and general utilities surrounding them
use alloc::string::String;
use super::{capabilities::Capabilities, Priority}; use super::{capabilities::Capabilities, Priority};
/// Process Identification /// Process Identification

View file

@ -1,63 +1,19 @@
use { use acpi::AcpiTables;
crate::{
devices::{ use crate::{kmain::AcpiStruct, rhai_shell::rhai_shell};
id::match_vendor,
pci_inner::{DeviceClass, PciIO},
Device, DEVICE_TABLE,
},
rhai_shell::rhai_shell,
},
alloc::{format, vec::Vec},
};
/// Experimental scratchpad for testing. /// Experimental scratchpad for testing.
pub fn scratchpad() { pub fn scratchpad() {
let mut dev_list = Vec::new(); pci_fun();
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);
*/
rhai_shell(); rhai_shell();
} }
pub fn pci_fun() {}
pub fn acpi() {
let acpi_handler = AcpiStruct {};
let _table;
unsafe {
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
}
}

View file

@ -1,8 +1,3 @@
use alloc::{
format,
string::{String, ToString},
vec,
};
use picorand::PicoRandGenerate; use picorand::PicoRandGenerate;
use rkyv::{ser::serializers::AllocSerializer, Deserialize}; use rkyv::{ser::serializers::AllocSerializer, Deserialize};
use shadeable::pixel_format::from_vga_16; use shadeable::pixel_format::from_vga_16;
@ -10,14 +5,14 @@ use vga::colors::Color16;
use y_compositor_protocol::Version; use y_compositor_protocol::Version;
use crate::{ use crate::{
kmain::BOOT_CONF, kmain::KERNEL_CONF,
network::socket::{SimpleSock, Socket, SocketReturns}, network::socket::{SimpleSock, Socket, SocketReturns},
num_to_vga16, vga_e, VgaBuffer, SCREEN_BUFFER, num_to_vga16, VgaBuffer, SCREEN_BUFFER,
}; };
use kernel::TICK; use kernel::TICK;
pub fn run_tests() { pub fn run_tests() {
if BOOT_CONF.run_tests { if KERNEL_CONF.tests.run_tests {
// quick and dirty testing framework // quick and dirty testing framework
screen_writer_test(); screen_writer_test();
socket_test(); socket_test();
@ -26,11 +21,11 @@ pub fn run_tests() {
socket_test_rng(); socket_test_rng();
} }
if BOOT_CONF.run_demos { if KERNEL_CONF.tests.run_demos {
graphics_api_demo(); graphics_api_demo();
} }
if BOOT_CONF.run_shader_tests { if KERNEL_CONF.tests.run_shader_tests {
shader_tests(); shader_tests();
} }
} }

View file

@ -1,13 +1,6 @@
use shadeable::pixel_format::Rgba64; use vga::{
colors::Color16,
use crate::SCREEN_BUFFER; writers::{Graphics640x480x16, GraphicsWriter},
use {
ab_glyph::{Font, FontRef, Glyph},
vga::{
colors::Color16,
writers::{Graphics640x480x16, GraphicsWriter},
},
}; };
lazy_static::lazy_static! { lazy_static::lazy_static! {

View file

@ -1,5 +1,3 @@
use alloc::vec::Vec;
/// `NULL a s m` as an array of 4 bytes /// `NULL a s m` as an array of 4 bytes
pub const WASM_BINARY_MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6d]; pub const WASM_BINARY_MAGIC: [u8; 4] = [0x00, 0x61, 0x73, 0x6d];
/// `1 0 0 0` as an array of 4 bytes /// `1 0 0 0` as an array of 4 bytes

View file

@ -1,4 +1,3 @@
use alloc::format;
use wasmi::{ use wasmi::{
Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue, Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue,
Signature, Trap, ValueType, Signature, Trap, ValueType,
@ -54,7 +53,6 @@ impl HostExternals {
ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)), ADD_FUNC_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)), SEND_SIGNAL_INDEX => (&[ValueType::I32, ValueType::I32], Some(ValueType::I32)),
GET_TIME_INDEX => (&[], Some(ValueType::I32)), GET_TIME_INDEX => (&[], Some(ValueType::I32)),
_ => return false, _ => return false,
}; };
signature.params() == params && signature.return_type() == ret_ty signature.params() == params && signature.return_type() == ret_ty

View file

@ -3,7 +3,6 @@ pub mod host_functions;
extern crate wasmi; extern crate wasmi;
// extern crate wabt; // extern crate wabt;
use alloc::vec::Vec;
use genfs::{Fs, OpenOptions}; use genfs::{Fs, OpenOptions};
use wasmi::{ImportsBuilder, ModuleInstance}; use wasmi::{ImportsBuilder, ModuleInstance};

View file

@ -0,0 +1,2 @@
[build]
target = "./json_targets/x86_64-ableos.json"

View file

@ -5,6 +5,8 @@ version = "0.1.2"
[dependencies] [dependencies]
log = "0.4.14"
[dependencies.lazy_static] [dependencies.lazy_static]
version = "1.4.0" version = "1.4.0"
default-features = false default-features = false

View file

@ -1,5 +1,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![no_std] #![no_std]
#![feature(prelude_import)]
//! The ableOS kernel. //! The ableOS kernel.
pub mod device_interface; pub mod device_interface;

View file

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

View file

@ -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::{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 log::{debug, info};
use rhai::Engine; use rhai::Engine;
@ -7,13 +7,13 @@ use rhai::Engine;
pub fn engine_startup() -> Engine { pub fn engine_startup() -> Engine {
let mut engine = Engine::new(); 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 // Any function or closure that takes a '&str', an 'Option<&str>' and a 'Position' argument
// can be used to override 'debug'. // can be used to override 'debug'.
engine.on_debug(|x, src, pos| { engine.on_debug(|x, src, pos| {
let src = src.unwrap_or("unknown"); let src = src.unwrap_or("unknown");
// debug!("SHADER DEBUG of {} at {:?}: {}", src, pos, x) debug!("SHADER DEBUG of {} at {:?}: {}", src, pos, x);
}); });
engine engine