From ae321a99235d8a9a4dbd317f4178c294b1128998 Mon Sep 17 00:00:00 2001 From: able Date: Mon, 10 Jul 2023 22:54:05 -0500 Subject: [PATCH 1/6] CAPS: Adding in capabilities --- kernel/src/capabilities.rs | 177 +++++++++++++++++++++++++++++++++++++ kernel/src/handle.rs | 1 + kernel/src/lib.rs | 1 + 3 files changed, 179 insertions(+) create mode 100644 kernel/src/capabilities.rs diff --git a/kernel/src/capabilities.rs b/kernel/src/capabilities.rs new file mode 100644 index 0000000..ed95595 --- /dev/null +++ b/kernel/src/capabilities.rs @@ -0,0 +1,177 @@ +//! AbleOS capability tree implementation + +use { + alloc::{ + format, + string::{String, ToString}, + vec, + }, + core::fmt, +}; + +// Seperate +use alloc::vec::Vec; + +struct Argument { + name: String, + type_: String, +} + +struct Function { + name: String, + args: Vec, + ret: Option, +} + +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: {}\n", self.name)?; + for function in &self.functions { + write!(f, " Function: {}\n", function.name)?; + for arg in &function.args { + write!(f, " Argument: {} (Type: {})\n", arg.name, arg.type_)?; + } + if let Some(ret_type) = &function.ret { + write!(f, " Return Type: {}\n", ret_type)?; + } else { + write!(f, " Return Type: None\n")?; + } + } + for sub_capability in &self.sub_capabilities { + write!(f, "{}", sub_capability.to_string_with_indentation(2))?; + } + Ok(()) + } +} + +impl Capability { + fn to_string_with_indentation(&self, level: usize) -> String { + let indent = " ".repeat(level); + let mut result = format!("{}Capability: {}\n", indent, self.name); + for function in &self.functions { + result.push_str(&format!("{} Function: {}\n", indent, function.name)); + for arg in &function.args { + result.push_str(&format!( + "{} Argument: {} (Type: {})\n", + indent, arg.name, arg.type_ + )); + } + if let Some(ret_type) = &function.ret { + result.push_str(&format!("{} Return Type: {}\n", indent, ret_type)); + } else { + result.push_str(&format!("{} Return Type: None\n", indent)); + } + } + 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(), + } + } +} + +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: Some("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: Some("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, + }); + + 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: Some("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: Some("Vec".to_string()), + }); + + capability_tree + .sub_capabilities + .push(file_management_capability); + capability_tree + .sub_capabilities + .push(directory_management_capability); + + log::debug!("{}", capability_tree); +} diff --git a/kernel/src/handle.rs b/kernel/src/handle.rs index 9cb34c8..cc76284 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/lib.rs b/kernel/src/lib.rs index 4aeb67c..570bb5b 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; From b7da4f17c24a9bb7dc7542aca024b124123d2f41 Mon Sep 17 00:00:00 2001 From: able Date: Wed, 12 Jul 2023 06:03:06 -0500 Subject: [PATCH 2/6] REPBUILD: default devices changed --- repbuild/src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 1424038..3bd4af8 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -173,20 +173,21 @@ 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"]); } } From 340d76fd13eee61879f7a44fc71593bf40bfdcf0 Mon Sep 17 00:00:00 2001 From: able Date: Wed, 12 Jul 2023 06:03:29 -0500 Subject: [PATCH 3/6] CAPS: Changing the printing of caps --- kernel/src/capabilities.rs | 93 +++++++++++++++++++++----------------- kernel/src/kmain.rs | 4 ++ 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/kernel/src/capabilities.rs b/kernel/src/capabilities.rs index ed95595..2c8e7fd 100644 --- a/kernel/src/capabilities.rs +++ b/kernel/src/capabilities.rs @@ -1,8 +1,8 @@ //! AbleOS capability tree implementation use { + crate::{tab, utils::TAB}, alloc::{ - format, string::{String, ToString}, vec, }, @@ -20,7 +20,7 @@ struct Argument { struct Function { name: String, args: Vec, - ret: Option, + ret: String, } struct Capability { @@ -41,49 +41,57 @@ impl Capability { impl fmt::Display for Capability { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "Capability: {}\n", self.name)?; + write!(f, "Capability: {}\r\n", self.name)?; for function in &self.functions { - write!(f, " Function: {}\n", function.name)?; + write!(f, "{}Function: {}\r\n", tab!(1), function.name)?; for arg in &function.args { - write!(f, " Argument: {} (Type: {})\n", arg.name, arg.type_)?; - } - if let Some(ret_type) = &function.ret { - write!(f, " Return Type: {}\n", ret_type)?; - } else { - write!(f, " Return Type: None\n")?; + 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, "{}", sub_capability.to_string_with_indentation(2))?; + write!(f, "{}{}\r\n", tab!(1), sub_capability)?; } Ok(()) } } -impl Capability { - fn to_string_with_indentation(&self, level: usize) -> String { - let indent = " ".repeat(level); - let mut result = format!("{}Capability: {}\n", indent, self.name); - for function in &self.functions { - result.push_str(&format!("{} Function: {}\n", indent, function.name)); - for arg in &function.args { - result.push_str(&format!( - "{} Argument: {} (Type: {})\n", - indent, arg.name, arg.type_ - )); - } - if let Some(ret_type) = &function.ret { - result.push_str(&format!("{} Return Type: {}\n", indent, ret_type)); - } else { - result.push_str(&format!("{} Return Type: None\n", indent)); - } - } - for sub_capability in &self.sub_capabilities { - result.push_str(&sub_capability.to_string_with_indentation(level + 1)); - } - result - } -} +// 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, @@ -97,7 +105,8 @@ impl CapabilityTree { } } -fn example() { +/// 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()); @@ -113,7 +122,7 @@ fn example() { type_: "String".to_string(), }, ], - ret: Some("FileHandle".to_string()), + ret: "FileHandle".to_string(), }); file_management_capability.functions.push(Function { name: "ReadFile".to_string(), @@ -131,7 +140,7 @@ fn example() { type_: "usize".to_string(), }, ], - ret: Some("usize".to_string()), + ret: "usize".to_string(), }); file_management_capability.functions.push(Function { name: "WriteFile".to_string(), @@ -145,7 +154,7 @@ fn example() { type_: "&[u8]".to_string(), }, ], - ret: None, + ret: "None".to_string(), }); let mut directory_management_capability = Capability::new("Directory Management".to_string()); @@ -155,7 +164,7 @@ fn example() { name: "path".to_string(), type_: "String".to_string(), }], - ret: Some("bool".to_string()), + ret: "bool".to_string(), }); directory_management_capability.functions.push(Function { name: "ListDirectory".to_string(), @@ -163,7 +172,7 @@ fn example() { name: "path".to_string(), type_: "String".to_string(), }], - ret: Some("Vec".to_string()), + ret: "Vec".to_string(), }); capability_tree @@ -173,5 +182,5 @@ fn example() { .sub_capabilities .push(directory_management_capability); - log::debug!("{}", capability_tree); + log::debug!("CapTree\r\n{}", capability_tree); } diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 5a3fd52..0cd2b4e 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::{ @@ -37,6 +39,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![]; From c264865d49c199427a53d76ff3c141b7320dccea Mon Sep 17 00:00:00 2001 From: able Date: Wed, 12 Jul 2023 09:01:58 -0500 Subject: [PATCH 4/6] X86: cpuid changes --- kernel/src/arch/x86_64/cpuid.rs | 27 +++++++++++++++++++++++++-- kernel/src/arch/x86_64/mod.rs | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/x86_64/cpuid.rs b/kernel/src/arch/x86_64/cpuid.rs index f94d77f..e0ed015 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 0151c7d..a7d141f 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(); From de8661be62f7fb1b52487c9cd919c7fa9be20cc5 Mon Sep 17 00:00:00 2001 From: able Date: Wed, 12 Jul 2023 10:04:20 -0500 Subject: [PATCH 5/6] COMMUNITY: Discord link update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf6a74a..3cabc8e 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` From a18ca4335fdb9bcf2f082c609d3bf069aef245bd Mon Sep 17 00:00:00 2001 From: able Date: Wed, 12 Jul 2023 11:27:42 -0500 Subject: [PATCH 6/6] REPBUILD: Space --- repbuild/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 3bd4af8..ad6c771 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -188,7 +188,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { #[cfg(target_os = "linux")] { - // com.args(["-enable-kvm", "-cpu", "host"]); + //com.args(["-enable-kvm", "-cpu", "host"]); } }