forked from AbleOS/ableos
Merge branch 'master' into master
This commit is contained in:
commit
473598d5df
|
@ -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`
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -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();
|
||||
|
|
186
kernel/src/capabilities.rs
Normal file
186
kernel/src/capabilities.rs
Normal file
|
@ -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<Argument>,
|
||||
ret: String,
|
||||
}
|
||||
|
||||
struct Capability {
|
||||
name: String,
|
||||
functions: Vec<Function>,
|
||||
sub_capabilities: Vec<Capability>,
|
||||
}
|
||||
|
||||
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<Capability>,
|
||||
}
|
||||
|
||||
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<String>".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);
|
||||
}
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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![];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue