diff --git a/README.md b/README.md index bf6a74ac..3cabc8e1 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ TODO - A ton more # Community -[Discord](https://discord.gg/5TnJ8sa7) +[Discord](https://discord.gg/JrKVukDtgs) # Compiling 1. `git submodule update --init` diff --git a/kernel/src/arch/x86_64/cpuid.rs b/kernel/src/arch/x86_64/cpuid.rs index f94d77f2..e0ed015f 100644 --- a/kernel/src/arch/x86_64/cpuid.rs +++ b/kernel/src/arch/x86_64/cpuid.rs @@ -1,5 +1,7 @@ -use core::{arch::asm, fmt, ops::Deref, slice, str}; - +use { + alloc::vec::Vec, + core::{arch::asm, fmt, ops::Deref, slice, str}, +}; #[repr(u32)] pub enum RequestType { BasicInformation = 0x0000_0000, @@ -767,6 +769,27 @@ impl Master { physical_address_size: pas, } } + // TODO: Macroify this and also include all of the cpu features from self + pub fn features(&self) -> Vec<(&str, bool)> { + let mut fv = Vec::new(); + let apic = self.apic(); + let avx = self.avx(); + let avx2 = self.avx2(); + let x2 = self.x2apic(); + + let gb_pages = self.gigabyte_pages(); + let rdseed = self.rdseed(); + let rdrand = self.rdrand(); + + fv.push(("apic", apic)); + fv.push(("avx", avx)); + fv.push(("avx2", avx2)); + fv.push(("gigabyte pages", gb_pages)); + fv.push(("rdrand", rdrand)); + fv.push(("rdseed", rdseed)); + fv.push(("x2apic", x2)); + fv + } master_attr_reader!(version_information, VersionInformation); master_attr_reader!( diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 0151c7d9..a7d141f2 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -102,6 +102,7 @@ unsafe extern "C" fn _kernel_start() -> ! { let mut cpu_features = xml::XMLElement::new("CPU Features"); { + cpuinfo.version_information().unwrap(); let apic = cpuinfo.apic(); let avx = cpuinfo.avx(); let avx2 = cpuinfo.avx2(); diff --git a/kernel/src/capabilities.rs b/kernel/src/capabilities.rs new file mode 100644 index 00000000..2c8e7fd6 --- /dev/null +++ b/kernel/src/capabilities.rs @@ -0,0 +1,186 @@ +//! AbleOS capability tree implementation + +use { + crate::{tab, utils::TAB}, + alloc::{ + string::{String, ToString}, + vec, + }, + core::fmt, +}; + +// Seperate +use alloc::vec::Vec; + +struct Argument { + name: String, + type_: String, +} + +struct Function { + name: String, + args: Vec, + ret: String, +} + +struct Capability { + name: String, + functions: Vec, + sub_capabilities: Vec, +} + +impl Capability { + fn new(name: String) -> Capability { + Capability { + name, + functions: Vec::new(), + sub_capabilities: Vec::new(), + } + } +} + +impl fmt::Display for Capability { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Capability: {}\r\n", self.name)?; + for function in &self.functions { + write!(f, "{}Function: {}\r\n", tab!(1), function.name)?; + for arg in &function.args { + write!( + f, + "{}Argument: {} (Type: {})\r\n", + tab!(2), + arg.name, + arg.type_ + )?; + } + write!(f, "{}Return Type: {}\r\n", tab!(2), &function.ret)?; + } + for sub_capability in &self.sub_capabilities { + write!(f, "{}{}\r\n", tab!(1), sub_capability)?; + } + Ok(()) + } +} + +// impl Capability { +// fn to_string_with_indentation(&self, level: usize) -> String { +// let indent = tab!(level); +// let mut result = format!("{}Capability: {}\n", indent, self.name); +// for function in &self.functions { +// result.push_str(&format!( +// "{}Function: {}\n", +// tab!(indent + 1), +// function.name +// )); +// for arg in &function.args { +// result.push_str(&format!( +// "{}Argument: {} (Type: {})\n", +// tab!(indent + 2), +// arg.name, +// arg.type_ +// )); +// } +// result.push_str(&format!( +// "{}Return Type: {}\n", +// tab!(indent + 2), +// &function.ret +// )); +// } +// for sub_capability in &self.sub_capabilities { +// result.push_str(&sub_capability.to_string_with_indentation(level + 1)); +// } +// result +// } +// } + +struct CapabilityTree { + capabilities: Vec, +} + +impl CapabilityTree { + fn new() -> CapabilityTree { + CapabilityTree { + capabilities: Vec::new(), + } + } +} + +/// A super simple capabilities example +pub fn example() { + let mut capability_tree = Capability::new("VFS".to_string()); + + let mut file_management_capability = Capability::new("File Management".to_string()); + file_management_capability.functions.push(Function { + name: "OpenFile".to_string(), + args: vec![ + Argument { + name: "path".to_string(), + type_: "String".to_string(), + }, + Argument { + name: "mode".to_string(), + type_: "String".to_string(), + }, + ], + ret: "FileHandle".to_string(), + }); + file_management_capability.functions.push(Function { + name: "ReadFile".to_string(), + args: vec![ + Argument { + name: "file".to_string(), + type_: "FileHandle".to_string(), + }, + Argument { + name: "buffer".to_string(), + type_: "&mut [u8]".to_string(), + }, + Argument { + name: "length".to_string(), + type_: "usize".to_string(), + }, + ], + ret: "usize".to_string(), + }); + file_management_capability.functions.push(Function { + name: "WriteFile".to_string(), + args: vec![ + Argument { + name: "file".to_string(), + type_: "FileHandle".to_string(), + }, + Argument { + name: "buffer".to_string(), + type_: "&[u8]".to_string(), + }, + ], + ret: "None".to_string(), + }); + + let mut directory_management_capability = Capability::new("Directory Management".to_string()); + directory_management_capability.functions.push(Function { + name: "CreateDirectory".to_string(), + args: vec![Argument { + name: "path".to_string(), + type_: "String".to_string(), + }], + ret: "bool".to_string(), + }); + directory_management_capability.functions.push(Function { + name: "ListDirectory".to_string(), + args: vec![Argument { + name: "path".to_string(), + type_: "String".to_string(), + }], + ret: "Vec".to_string(), + }); + + capability_tree + .sub_capabilities + .push(file_management_capability); + capability_tree + .sub_capabilities + .push(directory_management_capability); + + log::debug!("CapTree\r\n{}", capability_tree); +} diff --git a/kernel/src/handle.rs b/kernel/src/handle.rs index 9cb34c87..cc76284d 100644 --- a/kernel/src/handle.rs +++ b/kernel/src/handle.rs @@ -26,6 +26,7 @@ impl OSHandle { #[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)] pub struct Handle { id: OSHandle, + // TODO: Update this to be indexes into the caps perms: Permissions, } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index e6bd82e6..a4481629 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -1,5 +1,7 @@ //! AbleOS Kernel Entrypoint +use crate::capabilities; + // use crate::arch::sloop; use { crate::{ @@ -39,6 +41,8 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { // TODO: schedule the filesystem driver from the initramfs // TODO: schedule the init system from the initramfs + capabilities::example(); + // TODO: change this to a driver { let mut prog = alloc::vec![]; diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 4aeb67c9..570bb5bd 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -22,6 +22,7 @@ extern crate alloc; mod allocator; mod arch; mod bootmodules; +pub mod capabilities; pub mod device_tree; pub mod handle; pub mod host; diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 1424038d..ad6c7716 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -173,21 +173,22 @@ fn run(release: bool, target: Target) -> Result<(), Error> { "-m", "4G", // "-serial", "stdio", "-smp", "cores=4", - "-vga", "cirrus", + // "-vga", "cirrus", // "-device", "ati-vga", - "-device", "virtio-gpu-pci", + // "-device", "virtio-gpu-pci", - "-device", "virtio-serial,id=virtio-serial0", - "-chardev", "stdio,id=char0,mux=on", - "-device", "virtconsole,chardev=char0", - "-device", "virtio-mouse-pci", + // "-device", "virtio-serial,id=virtio-serial0", + // "-chardev", "stdio,id=char0,mux=on", + // "-device", "virtconsole,chardev=char0", + // "-device", "virtio-mouse-pci", // "-device", "ati-vga", "model=rage128p" ]); #[cfg(target_os = "linux")] { - // com.args(["-enable-kvm", "-cpu", "host"]); + + //com.args(["-enable-kvm", "-cpu", "host"]); } }