cleanup and docs

This commit is contained in:
able 2023-06-13 06:00:11 -05:00
parent b9b798efff
commit 16ccd51e4a
9 changed files with 54 additions and 25 deletions

View file

@ -67,7 +67,7 @@ pub fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
}
let reg2 = unsafe { pci_config_read(bus, device, 0, 0x8) };
let class = ((reg2 >> 16) & 0x0000FFFF) as u16;
let class = ((reg2 >> 16) & 0x0000_FFFF) as u16;
let pci_class = PciFullClass::from_u16(class);
let header_type = get_header_type(bus, device, 0);
@ -80,7 +80,7 @@ pub fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
id: device_id,
},
full_class: pci_class,
rev_id: (reg2 & 0x000000FF) as u8,
rev_id: (reg2 & 0x0000_00FF) as u8,
})
}
@ -271,7 +271,7 @@ use core::fmt::Display;
use crate::kmain::DEVICE_TREE;
use {x86_64::instructions::port::Port};
use x86_64::instructions::port::Port;
#[allow(non_camel_case_types, dead_code)]
#[derive(Debug, Clone, Copy, PartialEq)]
@ -460,7 +460,7 @@ unsafe fn pci_config_read(bus: u8, device: u8, func: u8, offset: u8) -> u32 {
let offset = offset as u32;
// construct address param
let address =
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x80000000) as u32;
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000) as u32;
// write address
Port::new(0xCF8).write(address);
@ -476,7 +476,7 @@ unsafe fn pci_config_write(bus: u8, device: u8, func: u8, offset: u8, value: u32
let offset = offset as u32;
// construct address param
let address =
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x80000000) as u32;
((bus << 16) | (device << 11) | (func << 8) | (offset & 0xFC) | 0x8000_0000) as u32;
// write address
Port::new(0xCF8).write(address);

View file

@ -1,14 +1,24 @@
use alloc::{string::String, vec::Vec};
//! A tree of hardware devices
use {crate::alloc::string::ToString, core::fmt, hashbrown::HashMap};
use {
crate::alloc::string::ToString,
alloc::{string::String, vec::Vec},
core::fmt,
hashbrown::HashMap,
};
/// A device object.
/// TODO define device
pub type Device = xml::XMLElement;
/// A tree of devices
// TODO: alphabatize this list
#[derive(Debug)]
pub struct DeviceTree {
/// The device tree
pub devices: HashMap<String, Vec<Device>>,
}
impl DeviceTree {
/// Build the device tree. Does not populate the device tree
pub fn new() -> Self {
let mut dt = Self {
devices: HashMap::new(),

View file

@ -1,23 +1,28 @@
//! A handle module
use {
crate::arch::hardware_random_u64,
core::fmt::{self, Formatter},
};
/// An operating system handle without permissions attached
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct OSHandle {
pub id: u64,
id: u64,
}
impl OSHandle {
/// turn a u64 into an OSHandle
pub fn new_from_u64(id: u64) -> Self {
Self { id }
}
/// Generate a new OSHandle using the HAL random function
pub fn random_new() -> Self {
Self {
id: hardware_random_u64(),
}
}
}
/// A handle for resources
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
pub struct Handle {
id: OSHandle,
@ -25,13 +30,14 @@ pub struct Handle {
}
impl Handle {
/// make a new handle
pub fn new() -> Handle {
Handle {
id: OSHandle::random_new(),
perms: Permissions::new(),
}
}
/// represent the os handle as a u64
pub fn as_u64(&self) -> u64 {
self.id.id
}
@ -45,13 +51,12 @@ impl fmt::Display for Handle {
}
#[derive(PartialEq, Hash, Eq, Debug, Clone, Copy)]
pub struct Permissions {
struct Permissions {
edit_children: bool,
edit_attributes: bool,
}
impl Permissions {
pub fn new() -> Self {
fn new() -> Self {
Self {
edit_children: true,
edit_attributes: true,

View file

@ -1,15 +1,20 @@
use hbvm::engine::Engine;
//! the system interface
use {
crate::ipc::message::Message,
crossbeam_queue::{ArrayQueue, SegQueue},
hbvm::engine::Engine,
log::trace,
};
/// Host errors
pub enum HostError {
/// A host memory error
MemoryError,
}
/// Check f0 register for the handle
/// check f1 for the message ptr
/// check f2 for the message length
pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
let _handle = engine.registers.f0;
let message_start = engine.registers.f1;
@ -28,7 +33,7 @@ pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
Ok(())
}
pub fn ipc_recv(_engine: &mut Engine) {}
// pub fn ipc_recv(_engine: &mut Engine) {}
/// Check f0 for the buffer type
/// 0 means an unbound buffer
@ -52,6 +57,6 @@ pub fn ipc_mkbuf(engine: &mut Engine) {
}
}
pub fn rpc_discover(_engine: &mut Engine) {}
pub fn rpc_register(_engine: &mut Engine) {}
pub fn rpc_call(_engine: &mut Engine) {}
// pub fn rpc_discover(_engine: &mut Engine) {}
// pub fn rpc_register(_engine: &mut Engine) {}
// pub fn rpc_call(_engine: &mut Engine) {}

View file

@ -1,24 +1,29 @@
use crossbeam_queue::{ArrayQueue, SegQueue};
//!
use super::message::Message;
use {
super::message::Message,
crossbeam_queue::{ArrayQueue, SegQueue},
};
enum BufferTypes {
Unbound(SegQueue<Message>),
Bound(ArrayQueue<Message>),
}
/// Interproccess buffer
pub struct IpcBuffer {
protocol: Protocol,
buffer: BufferTypes,
}
impl IpcBuffer {
/// Validate a message to match the `IPC.protocol`
pub fn validate_messages(&mut self) -> Result<(), IpcError> {
Ok(())
}
}
/// Interprocess Communication Errors
pub enum IpcError {
/// An invalid message error returned to the sender
InvalidMessage,
}

View file

@ -1,2 +1,3 @@
//! Interprocess communication
pub mod buffer;
pub mod message;

View file

@ -62,11 +62,13 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
let byte = sc.receive();
if byte == b'\r' {
sc.send(b'\n');
}
sc.send(b'\r');
} else {
sc.send(byte);
}
}
}
}
pub static DEVICE_TREE: Lazy<Mutex<DeviceTree>> = Lazy::new(|| {
let dt = DeviceTree::new();

View file

@ -16,7 +16,7 @@
#![deny(clippy::pedantic, warnings)]
#![allow(dead_code)]
#![test_runner(crate::test_runner)]
// #![deny(missing_docs)]
#![deny(missing_docs)]
extern crate alloc;

View file

@ -9,6 +9,7 @@ fn main() -> Result<(), Error> {
let mut args = std::env::args();
args.next();
// TODO: work on adding in system.toml support
// TODO: check the disk.img time and system.toml time and if system.toml is higher then rebuild the disk
match args.next().as_deref() {
Some("build" | "b") => {