Merge branch 'master' into riscv

This commit is contained in:
Able 2022-03-11 14:16:15 -06:00
commit a857253314
84 changed files with 1773 additions and 1208 deletions

165
ableos/Cargo.lock generated
View file

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ab_glyph"
version = "0.2.13"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61caed9aec6daeee1ea38ccf5fb225e4f96c1eeead1b4a5c267324a63cf02326"
checksum = "24606928a235e73cdef55a0c909719cadd72fce573e5713d58cb2952d8f5794c"
dependencies = [
"ab_glyph_rasterizer",
"libm",
@ -24,7 +24,7 @@ dependencies = [
[[package]]
name = "ableos"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"ab_glyph",
"acpi",
@ -35,13 +35,14 @@ dependencies = [
"facepalm",
"genfs",
"hashbrown 0.11.2",
"kernel",
"lazy_static",
"libwasm",
"linked_list_allocator",
"lliw",
"log",
"logos",
"pc-beeper",
"pci",
"pic8259",
"picorand",
"pretty-hex",
@ -50,9 +51,9 @@ dependencies = [
"riscv",
"rkyv",
"serde",
"serde_json",
"shadeable",
"spin 0.5.2",
"toml",
"uart_16550",
"unicode-width",
"volatile 0.2.7",
@ -73,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"
@ -106,6 +113,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fe8f5a8a398345e52358e18ff07cc17a568fbca5c6f73873d3a62056309603"
[[package]]
name = "beef"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bed554bd50246729a1ec158d08aa3235d1b69d94ad120ebe187e28894787e736"
[[package]]
name = "bit_field"
version = "0.10.1"
@ -120,9 +133,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bootloader"
version = "0.9.21"
version = "0.9.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a62c8f6168cd106687ee36a2b71a46c4144d73399f72814104d33094b8092fd2"
checksum = "de78decc37247c7cfac5dbf3495c7298c6ac97cb355161caa7e15969c6648e6c"
[[package]]
name = "cfg-if"
@ -204,6 +217,12 @@ dependencies = [
"log",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "genfs"
version = "0.1.4"
@ -212,15 +231,25 @@ checksum = "65b9e52a0ffd4c2f11f9f84e8885a40cb99f490971eee78bbd7ddffd6ac023d6"
[[package]]
name = "getrandom"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
dependencies = [
"cfg-if",
"libc",
"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"
@ -233,7 +262,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758"
dependencies = [
"ahash",
"ahash 0.7.6",
]
[[package]]
@ -246,10 +275,13 @@ dependencies = [
]
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
name = "kernel"
version = "0.1.2"
dependencies = [
"lazy_static",
"log",
"versioning",
]
[[package]]
name = "lazy_static"
@ -262,9 +294,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.118"
version = "0.2.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
[[package]]
name = "libm"
@ -275,7 +307,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"
@ -310,6 +342,30 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "logos"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427e2abca5be13136da9afdbf874e6b34ad9001dd70f2b103b083a85daa7b345"
dependencies = [
"logos-derive",
]
[[package]]
name = "logos-derive"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56a7d287fd2ac3f75b11f19a1c8a874a7d55744bd91f7a1b3e7cf87d4343c36d"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
"syn",
"utf8-ranges",
]
[[package]]
name = "memchr"
version = "2.4.1"
@ -361,15 +417,15 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.9.0"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "owned_ttf_parser"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef05f2882a8b3e7acc10c153ade2631f7bfc8ce00d2bf3fb8f4e9d2ae6ea5c3"
checksum = "4fb1e509cfe7a12db2a90bfa057dfcdbc55a347f5da677c506b53dd099cfec9d"
dependencies = [
"ttf-parser",
]
@ -388,14 +444,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"
@ -478,9 +526,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.5.4"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [
"aho-corasick",
"memchr",
@ -499,7 +547,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",
@ -544,9 +592,9 @@ dependencies = [
[[package]]
name = "rkyv"
version = "0.7.32"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3791595bf1ee951356964271bea7dafd1e1730e8be812f44a31afc38fa7bba"
checksum = "2cdcf5caf69bcc87b1e3f5427b4f21a32fdd53c2847687bdf9861abb1cdaa0d8"
dependencies = [
"hashbrown 0.12.0",
"ptr_meta",
@ -556,9 +604,9 @@ dependencies = [
[[package]]
name = "rkyv_derive"
version = "0.7.32"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca655472e721430bfb5c995a5602278e089c329cde96a0a53e1f711e3ba39c55"
checksum = "a6cf557da1f81b8c7e889c59c9c3abaf6978f7feb156b9579e4f8bf6d7a2bada"
dependencies = [
"proc-macro2",
"quote",
@ -580,12 +628,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"
@ -618,17 +660,6 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "shadeable"
version = "0.1.0"
@ -646,9 +677,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "smartstring"
version = "0.2.9"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31aa6a31c0c2b21327ce875f7e8952322acfcfd0c27569a6e18a647281352c9b"
checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e"
dependencies = [
"static_assertions",
]
@ -703,11 +734,20 @@ 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"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ccbe8381883510b6a2d8f1e32905bddd178c11caef8083086d0c0c9ab0ac281"
checksum = "c74c96594835e10fa545e2a51e8709f30b173a092bfd6036ef2cec53376244f3"
[[package]]
name = "uart_16550"
@ -731,12 +771,23 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "utf8-ranges"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "versioning"
version = "0.1.2"
source = "git+https://git.ablecorp.us/able/versioning#ef472283e6e7a2e395ee56434087b3a6fad53ff2"
[[package]]
name = "volatile"
version = "0.2.7"

View file

@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "ableos"
version = "0.1.0"
version = "0.1.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
@ -9,6 +9,9 @@ panic = "abort"
[package.metadata.bootimage]
run-args = [
"--nodefaults",
"-cpu",
"Broadwell-v3",
@ -17,27 +20,24 @@ run-args = [
"-smp",
"cores=2",
# An example gpu used with ableOS
"-device",
"virtio-gpu",
# 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 = [
@ -48,6 +48,9 @@ test-args = [
]
[dependencies]
linked_list_allocator = "0.9.0"
lliw = "0.2.0"
# qoi_rs = "*"
@ -65,15 +68,14 @@ genfs = "0.1.0"
# pc-beeper = "0.1.0"
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"
# [dependencies.ockam]
# version = "0.46.0"
# no-default-features = false
# features = ["alloc"]
[dependencies.logos]
version = "0.12.0"
default-features = false
features = ["export_derive"]
[dependencies.rdrand]
@ -81,16 +83,15 @@ version = "0.8.1"
default-features = false
[dependencies.kernel]
path = "../kernel"
[dependencies.serde]
version = "*"
default-features = false
features = ["derive", "alloc"]
[dependencies.serde_json]
version = "*"
default-features = false
features = ["alloc"]
[dependencies.hashbrown]
version = "0.11.2"
@ -113,6 +114,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"

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

@ -0,0 +1,17 @@
pub struct KeyEvent{
lctrl 1
rctrl 2
lalt 3
ralt 4
lsup 5
rsup 6
lshift 7
rshift 8
caps 9
down 10
# Keycodes
key 11-32
}

View file

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

View file

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

View file

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

View file

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

View file

@ -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(_) => {}

View file

@ -1,9 +1,11 @@
use crate::{
arch::{drivers::vga::WRITER, gdt},
kernel_state::KERNEL_STATE,
print, println, KEYBUFF,
print, println,
rhai_shell::KEYBUFF,
};
use cpuio::outb;
use lazy_static::lazy_static;
use pic8259::ChainedPics;
use spin;
@ -19,6 +21,8 @@ pub static PICS: spin::Mutex<ChainedPics> =
pub enum InterruptIndex {
Timer = PIC_1_OFFSET,
Keyboard,
// SecondInterrupt = PIC_2_OFFSET,
Cmos = 0x70,
}
impl InterruptIndex {
fn as_u8(self) -> u8 {
@ -37,10 +41,18 @@ lazy_static! {
idt.breakpoint.set_handler_fn(breakpoint_handler);
unsafe {
idt.double_fault.set_handler_fn(double_fault_handler)
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX); // new
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
}
// This gives fast interrupts
set_pit_frequency(1000);
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_usize()] .set_handler_fn(keyboard_interrupt_handler);
idt[6].set_handler_fn(floppy_disk_interrupt_handler);
idt
};
}
@ -55,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());
@ -90,6 +102,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
// Backspace
8 => {
WRITER.lock().backspace();
KEYBUFF.lock().push(8_u8 as _);
// print!(" ");
// WRITER.lock().backspace();
}
@ -126,16 +139,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}
}
/*
extern "x86-interrupt" fn page_fault_handler(
stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode,
) {
use x86_64::registers::control::Cr2;
println!["Exception: Page Fault"];
println!["Address: {:?}", Cr2::read()];
println!["Error Code: {:?}", error_code];
println!["{:#?}", stack_frame];
sloop();
extern "x86-interrupt" fn floppy_disk_interrupt_handler(_stack_frame: InterruptStackFrame) {
println!("EXCEPTION: FLOPPY DISK");
}
fn set_pit_frequency(freq: u32) {
let divisor: u16 = (1193180 / freq).try_into().unwrap();
unsafe {
outb(0x36, 0x43);
outb((divisor & 0xFF) as u8, 0x40);
outb((divisor >> 8) as u8, 0x40);
}
}
*/

View file

@ -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<String>,
}

View file

@ -1,6 +1,4 @@
use alloc::string::String;
use crate::character_device::CharacterDevice;
use kernel::device_interface::character::CharacterDevice;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -22,4 +20,12 @@ impl CharacterDevice for DevNull {
fn write_char(&mut self, _: char) -> bool {
true
}
fn reset(&mut self) {
todo!()
}
fn initialize(&mut self) -> bool {
todo!()
}
}

View file

@ -1,4 +1,4 @@
use crate::character_device::CharacterDevice;
use kernel::device_interface::character::CharacterDevice;
#[derive(Debug)]
pub struct DevUnicode {
@ -29,6 +29,15 @@ impl CharacterDevice for DevUnicode {
true
}
fn reset(&mut self) {
self.next_write_char = 0x00 as char;
self.next_read_char = 0x00 as char;
}
fn initialize(&mut self) -> bool {
true
}
}
fn add1_char(c: char) -> char {

View file

@ -1,4 +1,4 @@
use crate::character_device::CharacterDevice;
use kernel::device_interface::character::CharacterDevice;
#[derive(Debug)]
pub struct DevZero;
@ -19,4 +19,10 @@ impl CharacterDevice for DevZero {
fn write_char(&mut self, _: char) -> bool {
true
}
fn reset(&mut self) {}
fn initialize(&mut self) -> bool {
true
}
}

View file

@ -1,3 +1,5 @@
pub mod dev_null;
pub mod dev_unicode;
pub mod dev_zero;
pub use kernel::device_interface::character::CharacterDevice;

15
ableos/src/devices/id.rs Normal file
View file

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

View file

@ -1,20 +1,15 @@
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 crate::character_device::CharacterDevice;
use kernel::device_interface::character::CharacterDevice;
// FIXME: This is a hack to hold a device.
// #[derive(Debug)]
pub enum Device {
Character(Box<dyn CharacterDevice>),
Pci(PCIDevice),
}
unsafe impl Sync for Device {}
unsafe impl Send for Device {}

View file

@ -1,56 +1,55 @@
//! map the DeviceClass via <https://pci-ids.ucw.cz/read/PD>
#[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,
//!
//!
CommunicationController = 0x07,
GenericSystemPeripheral = 0x08,
InputDevice = 0x09,
DockingStation = 0x0a,
Processor = 0x0b,
SerialBusController = 0x0c,
WirelessController = 0x0d,
IntelligentController = 0x0e,
SatelliteCommunicationController = 0x0f,
EncryptionController = 0x10,
SignalProcessingController = 0x11,
#[allow(dead_code)]
fn scan_pci_bus() {}
// 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 PciDevice {
pub vendor: Vendors,
}

View file

@ -1,4 +1,2 @@
pub mod graphics;
pub mod serial;
pub mod character_device;

View file

@ -1,5 +1,3 @@
/*
// TODO improve tokenizer/parser
pub fn colorify(eval: &str) {
let y = eval.split("$");
@ -63,8 +61,48 @@ pub fn colorify(eval: &str) {
}
}
use logos::Logos;
#[derive(Logos, Debug, PartialEq)]
pub enum Token {
// Hex(u32),
#[regex(r"\$RED\$")]
Red,
#[regex(r"\$RESET\$")]
Reset,
*/
pub fn colorify(eval: &str) {}
#[regex("[a-zA-Z!@#$%^&*\">()\n ]+", parse_text, priority = 2)]
Text(String),
#[error]
#[regex(r"[ \t\n\f]+", logos::skip)]
Error,
}
pub fn colorify_2(eval: &str) {
let lexer = Token::lexer(eval);
for token in lexer {
use Token::*;
match token {
Red => {
set_vga_color(Color::Red, Color::Black);
}
Reset => {
set_vga_color(Color::White, Color::Black);
}
Text(text) => {
kprint!("{}", text);
}
err => {
error!("Error parsing {:?}", err);
}
}
}
}
use logos::Lexer;
use crate::kprint;
fn parse_text(lex: &mut Lexer<Token>) -> Option<String> {
let slice = lex.slice();
Some(String::from(slice))
}

View file

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

View file

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

View file

@ -1,3 +1,3 @@
//!
pub mod window;
pub mod compositor;
pub mod window;

View file

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

View file

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

View file

@ -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,8 +126,7 @@ 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);
VGAE.lock().clear_screen(vga::colors::Color16::Black);
}
/// Draw a glyph on the screen at the given position

View file

@ -1,4 +1,3 @@
use alloc::string::{String, ToString};
use lazy_static::lazy_static;
lazy_static! {
@ -7,7 +6,7 @@ lazy_static! {
}
pub struct KernelInternalState {
hostname: String,
pub hostname: String,
should_shutdown: bool,
}

View file

@ -1,4 +1,6 @@
use crate::{KeyCode, ScancodeSet, DecodeState, KeyEvent, Error, KeyState, keyboard::EXTENDED_KEY_CODE};
use crate::{
keyboard::EXTENDED_KEY_CODE, DecodeState, Error, KeyCode, KeyEvent, KeyState, ScancodeSet,
};
pub struct CustomScancodeSet {
single_byte: [Option<KeyCode>; 256],

View file

@ -78,8 +78,7 @@ impl LayoutEntry {
}
#[must_use]
pub fn common(self, c: impl Into<DecodedKey> + Clone) -> Self {
self
.unshifted(c.clone())
self.unshifted(c.clone())
.shifted(c.clone())
.locked(c.clone())
.locked_shifted(c)
@ -94,8 +93,7 @@ impl LayoutEntry {
}
#[must_use]
pub fn all(self, c: impl Into<DecodedKey> + Clone) -> Self {
self
.unshifted(c.clone())
self.unshifted(c.clone())
.shifted(c.clone())
.locked(c.clone())
.locked_shifted(c.clone())

View file

@ -1,7 +1,5 @@
#![allow(clippy::empty_loop)]
use crate::scheduler::SCHEDULER;
// use acpi::AcpiTables;
// use x86_64::instructions::interrupts::{disable, enable};
@ -10,11 +8,7 @@ use crate::scheduler::SCHEDULER;
use {
crate::{
arch::{init, sloop},
boot_conf,
boot_conf::BootConfig,
// capabilities::FileAccess,
experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
// file::PathRep,
relib::network::socket::{SimpleSock, Socket},
// scheduler::SCHEDULER,
// VgaBuffer,
@ -23,30 +17,25 @@ use {
// SCHEDULER,
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 TICK: AtomicU64 = AtomicU64::new(0);
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();
/*
@ -86,6 +75,7 @@ pub fn kernel_main() -> ! {
}
// mode.copy_to_buffer();
}
<<<<<<< HEAD
*/
/*
// TODO: create a scratchpad module
@ -98,6 +88,13 @@ pub fn kernel_main() -> ! {
}
}
=======
mode.copy_to_buffer();
}
start_facepalm();
scratchpad();
>>>>>>> master
*/
// start_facepalm();
@ -126,19 +123,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 += 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());
@ -184,7 +168,7 @@ impl acpi::AcpiHandler for AcpiStruct {
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");
}
}

View file

@ -12,7 +12,8 @@
exclusive_range_pattern,
lang_items,
naked_functions,
slice_pattern
slice_pattern,
prelude_import
)]
/// Contains architecture specific code for aarch64.
@ -32,8 +33,10 @@ pub mod arch;
#[macro_use]
pub mod print;
// pub mod devices;
// pub mod wasm_jumploader;
pub mod devices;
pub mod port_io;
pub mod rhai_shell;
pub mod wasm_jumploader;
#[macro_use]
pub extern crate log;
@ -42,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;
@ -50,8 +52,7 @@ pub mod kernel_state;
pub mod keyboard;
pub mod kmain;
pub mod logger;
pub mod panic;
// pub mod proto_filetable;
pub mod proto_filetable;
pub mod relib;
pub mod scheduler;
mod unicode_utils;
@ -66,34 +67,40 @@ 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::*;
pub use kernel_state::*;
pub use keyboard::*;
pub use logger::*;
pub use panic::*;
// pub use proto_filetable::*;
pub use proto_filetable::*;
pub use relib::*;
// pub use scheduler::*;
pub use utils::*;
// pub use vga_e::*;
pub use wasm::*;
//////////////////
pub mod boot_conf;
pub mod virtio;
pub use virtio::*;
// pub mod alias_table;
// 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 filesystem;
///////////////
/// Kernel ///
/////////////
pub use kernel;
pub use kernel::messaging;
pub use kernel::panic;
pub mod prelude;
#[prelude_import]
pub use prelude::rust_2021::*;

View file

@ -1,17 +1,12 @@
use core::sync::atomic::Ordering;
use crate::kmain::TICK;
// use crate::println;
use alloc::format;
// use alloc::fmt;
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};
// use crate::arch::drivers::timer::TIMER_INTERRUPT_HERTZ;
pub const TIMER_INTERRUPT_HERTZ: f64 = 100.0;
struct SimpleLogger;
// TODO: Rebuild this to take advantage of sockets
// DETAIL: Log to a socket instead of the screen
@ -26,7 +21,7 @@ impl log::Log for SimpleLogger {
let color;
let time = TICK.load(Ordering::Relaxed) as f64;
let time_float = time / TIMER_INTERRUPT_HERTZ;
let time_float = time;
match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"),
@ -35,7 +30,14 @@ impl log::Log for SimpleLogger {
log::Level::Debug => color = (Fg::Blue, "$BLUE$"),
log::Level::Trace => color = (Fg::Yellow, "$YELLOW$"),
}
let xyz = format!(
let msg = format!(
"[{}{}$RESET$][$GREEN${}$RESET$]{}\n",
color.1,
record.level(),
time_float,
record.args()
);
serial_println!(
"[{}{}{}][{}{}{}] {}",
color.0,
record.level(),
@ -45,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

View file

@ -1,30 +0,0 @@
use alloc::string::ToString;
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;
let uart_data = 0x10000000 as *mut u8;
for c in b"panic" {
unsafe { uart_data.write_volatile(*c) };
}
sloop()
}
pub fn test_panic() {
panic!("test panic!");
}

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

@ -1 +1,51 @@
// TODO: refactor this file
// TODO: make STDOUT redirect to a socket owned
// by the process named "stdout"
pub struct Stdout;
use core::fmt::{Arguments, Error};
impl Stdout {
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
{
let _ = core::fmt::Write::write_fmt(self, arg);
// Ok(())
}
}
impl core::fmt::Write for Stdout {
#[cfg(target_arch = "aarch64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
// Don't actually print anything yet lmao
Ok(())
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
use crate::kprint;
kprint!("{}", s);
Ok(())
}
#[cfg(target_arch = "riscv64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
Ok(())
}
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> core::fmt::Result {
core::fmt::write(&mut self, args)
}
}
#[macro_export]
macro_rules! print {
() => {
::core::writeln!($crate::print::Stdout, "")
};
($($tt:tt)*) => {
::core::write!($crate::print::Stdout, $($tt)*)
};
}
#[macro_export]
macro_rules! println {
($($tt:tt)*) => {
::core::writeln!($crate::print::Stdout, $($tt)*)
// panic![];
};
}

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,3 @@
use alloc::vec;
use alloc::vec::Vec;
pub fn encode(bytes: &[u8]) -> Vec<u8> {
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>;
#[derive(Debug)]

View file

@ -0,0 +1,122 @@
pub fn rhai_shell() {
let engine = engine_construction();
let mut scope = rhai::Scope::new();
let mut buf = String::new();
print!("> ");
loop {
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
Some('\n') => {
match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
Ok(o) => println!("{o}"),
Err(e) => println!("Eval error: {e}"),
};
buf.clear();
print!("> ");
}
Some('\u{0008}') => {
buf.pop();
}
Some(chr) => buf.push(chr),
None => (),
}
}
}
lazy_static::lazy_static!(
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
Vec::new())
;
);
use rhai::Engine;
use x86_64::instructions::interrupts::{disable, enable};
use crate::wasm_jumploader::interp;
use crate::{
arch::{shutdown, sloop},
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
KERNEL_STATE,
};
use kernel::TICK;
pub fn afetch() {
let kstate = KERNEL_STATE.lock();
use core::sync::atomic::Ordering::*;
disable();
let tick_time = TICK.load(Relaxed);
println!(
"OS: AbleOS
Host: {}
Kernel: AKern-{}-v{}
Uptime: {}",
kstate.hostname, RELEASE_TYPE, KERNEL_VERSION, tick_time
);
enable();
drop(kstate);
}
pub fn set_hostname(name: String) {
let mut kstate = KERNEL_STATE.lock();
kstate.hostname = name;
}
fn engine_construction() -> Engine {
let mut engine = rhai::Engine::new();
engine.on_print(|x| println!("{}", x));
engine.on_debug(|x, src, pos| {
let src = src.unwrap_or("unknown");
println!("DEBUG: {} at {:?}: {}", src, pos, x);
debug!("{} at {:?}: {}", src, pos, x);
});
engine.register_fn("afetch", afetch);
engine.register_fn("set_hostname", set_hostname);
engine.register_fn("shutdown", shutdown);
engine.register_fn("peek", peek_memory);
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) }
}
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"),
}
}

View file

@ -1,4 +1,4 @@
use alloc::vec::Vec;
#![allow(missing_docs)]
pub type SoundCardID = u8;
pub type DeviceID = u8;

View file

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

View file

@ -1,10 +1,8 @@
use crate::kmain::generate_process_pass;
use alloc::{string::ToString, vec::Vec};
use super::{
capabilities::Capabilities,
proc::{Process, PID},
Priority,
use crate::{
kmain::generate_process_pass,
scheduler::capabilities::Capabilities,
scheduler::proc::{Process, PID},
scheduler::Priority,
};
/// Add additional wake conditions to the list
pub enum WakeCondition {

View file

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

View file

@ -1,108 +1,37 @@
use alloc::{format, vec::Vec};
use acpi::AcpiTables;
use crate::rhai_shell::rhai_shell;
/// Experimental scratchpad for testing.
pub fn scratchpad() {
/*
let mut dev_list = Vec::new();
pci_fun();
rhai_shell();
}
let bus_scan;
pub fn pci_fun() {}
pub fn acpi() {
let acpi_handler = AcpiStruct {};
let _table;
unsafe {
bus_scan = pci::scan_bus(&PciIO {}, pci::CSpaceAccessMethod::IO);
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
}
for dev in bus_scan {
dev_list.push(dev);
}
let device_table = &mut *DEVICE_TABLE.lock();
for x in dev_list {
let device_name = format!("{:?}-{}", DeviceClass::from_u8(x.id.class), x.id.device_id);
device_table
.devices
.insert(device_name.clone(), Device::Pci(x));
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AcpiStruct {}
impl acpi::AcpiHandler for AcpiStruct {
unsafe fn map_physical_region<T>(
&self,
physical_address: usize,
size: usize,
) -> acpi::PhysicalMapping<Self, T> {
info!("PHYS ADDR: {:?}", physical_address);
info!("Size: {:?}", size);
todo!("map_physical_region");
}
*/
/*
for (key, _value) in device_table.devices.iter() {
debug!("{}", key);
}
*/
// interp();
// rhai_shell();
}
/*
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);
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
todo!("unmap_physical_region");
}
}
*/
/*
/// An experimental process message format
pub struct ProcessMessage {
pub to_pid: PID,
pub from_pid: PID,
pub message: [u8; 2048],
pub sender_time: SecondsTime,
}
//
// use libwasm::syscalls::time_calls::SecondsTime;
impl ProcessMessage {
pub fn new(to_pid: PID, from_pid: PID, message: [u8; 2048]) -> Self {
ProcessMessage {
to_pid,
from_pid,
message,
sender_time: SecondsTime {
seconds: 0,
milliseconds: 0,
},
}
}
}
*/
pub fn rhai_shell() {
let mut engine = rhai::Engine::new();
let ret = engine.eval::<i64>("1 + 2");
match ret {
// Ok(x) => println!("{}", x),
// Err(e) => println!("{}", e),
_ => (),
}
loop {}
}
lazy_static::lazy_static!(
pub static ref KEYBUFF: spin::Mutex<Vec<char>> = spin::Mutex::new(
Vec::new())
;
);

View file

@ -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,13 +5,14 @@ use vga::colors::Color16;
use y_compositor_protocol::Version;
use crate::{
kmain::{BOOT_CONF, TICK},
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();
@ -25,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();
}
}

View file

@ -2,7 +2,7 @@
//!
//!
//!
#[inline]
pub fn type_of<T>(_: &T) -> &str {
core::any::type_name::<T>()
}

View file

@ -1,13 +1,6 @@
use shadeable::pixel_format::Rgba64;
use crate::SCREEN_BUFFER;
use {
ab_glyph::{Font, FontRef, Glyph},
vga::{
use vga::{
colors::Color16,
writers::{Graphics640x480x16, GraphicsWriter},
},
};
lazy_static::lazy_static! {
@ -20,7 +13,6 @@ lazy_static::lazy_static! {
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
}
/// Converts a number to ... i forgor 💀
pub fn num_to_vga16(num: u8) -> Color16 {
use Color16::*;

View file

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

View file

@ -1,4 +1,3 @@
use alloc::format;
use wasmi::{
Error, Externals, FuncInstance, FuncRef, ModuleImportResolver, RuntimeArgs, RuntimeValue,
Signature, Trap, ValueType,
@ -7,6 +6,8 @@ use wasmi::{
pub struct HostExternals {}
const ADD_FUNC_INDEX: usize = 0;
const SEND_SIGNAL_INDEX: usize = 1;
const GET_TIME_INDEX: usize = 2;
impl Externals for HostExternals {
fn invoke_index(
@ -22,6 +23,25 @@ impl Externals for HostExternals {
println!("SYSCALL: {} + {} = {}", a, b, result);
Ok(Some(RuntimeValue::I32(result as i32)))
}
SEND_SIGNAL_INDEX => {
let pid: u32 = args.nth_checked(0)?;
let signal: u32 = args.nth_checked(1)?;
println!("SYSCALL: send signal {} to pid {}", signal, pid);
let ret = RuntimeValue::I32(0);
Ok(Some(ret))
}
GET_TIME_INDEX => {
use core::sync::atomic::Ordering::*;
x86_64::instructions::interrupts::disable();
let tick_time = kernel::TICK.load(Relaxed);
x86_64::instructions::interrupts::enable();
let ret = RuntimeValue::I64(tick_time.try_into().unwrap());
Ok(Some(ret))
}
_ => panic!("Unimplemented function at {}", index),
}
}
@ -31,6 +51,8 @@ impl HostExternals {
fn check_signature(&self, index: usize, signature: &Signature) -> bool {
let (params, ret_ty): (&[ValueType], Option<ValueType>) = match index {
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
@ -41,6 +63,7 @@ impl ModuleImportResolver for HostExternals {
fn resolve_func(&self, field_name: &str, signature: &Signature) -> Result<FuncRef, Error> {
let index = match field_name {
"add" => ADD_FUNC_INDEX,
"send_signal" => SEND_SIGNAL_INDEX,
_ => {
return Err(Error::Instantiation(format!(
"Export {} not found",

View file

@ -3,24 +3,26 @@ pub mod host_functions;
extern crate wasmi;
// extern crate wabt;
use alloc::vec::Vec;
use genfs::{Fs, OpenOptions};
use wasmi::{ImportsBuilder, ModuleInstance};
use crate::{filesystem::FILE_SYSTEM, wasm_jumploader::host_functions::HostExternals};
pub fn interp() {
info!("Interpreting...");
trace!("Interpreting...");
let fs = &*FILE_SYSTEM.lock();
info!("Got filesystem");
trace!("Got filesystem");
let file = fs
.open(b"/home/able/bins/test.wasm", OpenOptions::new().read(true))
.open(
b"/home/able/bins/aos_wasm_stress_test.wasm",
OpenOptions::new().read(true),
)
.unwrap();
let mut wasm_binary = Vec::new();
let ret = file.read_to_end(&mut wasm_binary).unwrap();
info!("Binary size {}", ret);
trace!("Binary size {}", ret);
// Load wasm binary and prepare it for instantiation.
let module = wasmi::Module::from_buffer(&wasm_binary).expect("failed to load wasm");

View file

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

22
kernel/Cargo.lock generated Normal file
View file

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

15
kernel/Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
edition = "2021"
name = "kernel"
version = "0.1.2"
[dependencies]
log = "0.4.14"
[dependencies.lazy_static]
version = "1.4.0"
default-features = false
[dependencies.versioning]
git = "https://git.ablecorp.us/able/versioning"

View file

@ -0,0 +1 @@
//!

View file

@ -1,3 +1,6 @@
//!
/// Character device interface.
pub trait CharacterDevice {
/// Returns true if the device can be read from.
fn can_read(&self) -> bool;
@ -7,4 +10,8 @@ pub trait CharacterDevice {
fn read_char(&mut self) -> Option<char>;
/// Writes a single character to the device and returns true if the write was successful
fn write_char(&mut self, c: char) -> bool;
/// Reset the device to its initial state
fn reset(&mut self);
/// initializes the device, returns true if successful
fn initialize(&mut self) -> bool;
}

View file

@ -0,0 +1,4 @@
//! Platform Agnostic Device
pub mod block;
pub mod character;

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

@ -0,0 +1,35 @@
#![deny(missing_docs)]
#![no_std]
#![feature(prelude_import)]
//! The ableOS kernel.
pub mod device_interface;
pub mod messaging;
pub mod panic;
pub mod proccess;
pub mod time;
use core::sync::atomic::{AtomicU64, Ordering::Relaxed};
use versioning::Version;
/// 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);
}
///
pub const KERNEL_VERSION: Version = Version {
major: 0,
minor: 1,
patch: 2,
};

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

@ -0,0 +1,67 @@
//! Interprocess communication.
use crate::{proccess::PID, time::Time};
/// 128 Bytes
pub type Tiny = [u8; 128];
/// 1 KiB
pub type Small = [u8; 1024];
/// 65.536 KiB
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,
/// The message Queue is full
TooManyMessages,
}

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

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

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

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

10
kernel/src/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,
}

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::{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

View file

@ -12,4 +12,4 @@ dependencies = [
[[package]]
name = "libwasm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/able/libwasm.git#502187e8734b54df3c6cae2baf2315539a3ec49b"
source = "git+https://git.ablecorp.us/able/libwasm.git#dedbb769ba01a4b75992437e52ca9a5c2bb9e0f9"

View file

@ -1,4 +1,4 @@
This is a stress test and simple progrram for ableOS.
This is a stress test and simple program for ableOS.
There should be two sub commands echo and input

View file

@ -1,12 +1,36 @@
#![no_std]
#![no_main]
#![deny(improper_ctypes)]
#[no_mangle]
fn start() -> i32 {
let ret = unsafe { add(1, 2) };
unsafe {
send_signal(PID(1), Signals::Quit);
}
ret as i32
}
use libwasm::syscalls::add;
extern "C" {
/// Send a signal to a process
///
/// # Arguments
///
/// * `pid` - The PID of the process to send the signal to
/// * `signal` - The signal to send
pub fn send_signal(pid: PID, signal: Signals) -> bool;
}
use {
libwasm::process::{signals::Signals, PID},
libwasm::syscalls::add,
};
use libwasm::*;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
use core::panic::PanicInfo;

Binary file not shown.

75
userland/wasm_pk_data/Cargo.lock generated Normal file
View file

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "proc-macro2"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "toml"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "wasm_pk_data"
version = "0.1.0"
dependencies = [
"serde",
"toml",
]

View file

@ -0,0 +1,17 @@
[package]
name = "wasm_pk_data"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
toml = "0.5"
[dependencies.serde]
version = "1.0"
features = ["derive"]

View file

@ -0,0 +1,3 @@
name = "bruh"
version = [1233, 123, 123]
authors = ["John Doe", "Jane Doe"]

View file

@ -0,0 +1,20 @@
#![no_std]
extern crate alloc;
use {
alloc::{string::String, vec::Vec},
serde::Deserialize,
};
#[derive(Debug, Deserialize)]
pub struct Version {
pub major: u16,
pub minor: u8,
pub patch: u8,
}
#[derive(Debug, Deserialize)]
pub struct MetaData {
pub name: String,
pub version: Version,
pub authors: Vec<String>,
}