forked from AbleOS/ableos
cleanup and docs
This commit is contained in:
parent
b9b798efff
commit
16ccd51e4a
|
@ -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 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 pci_class = PciFullClass::from_u16(class);
|
||||||
let header_type = get_header_type(bus, device, 0);
|
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,
|
id: device_id,
|
||||||
},
|
},
|
||||||
full_class: pci_class,
|
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 crate::kmain::DEVICE_TREE;
|
||||||
|
|
||||||
use {x86_64::instructions::port::Port};
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
#[allow(non_camel_case_types, dead_code)]
|
#[allow(non_camel_case_types, dead_code)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[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;
|
let offset = offset as u32;
|
||||||
// construct address param
|
// construct address param
|
||||||
let address =
|
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
|
// write address
|
||||||
Port::new(0xCF8).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;
|
let offset = offset as u32;
|
||||||
// construct address param
|
// construct address param
|
||||||
let address =
|
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
|
// write address
|
||||||
Port::new(0xCF8).write(address);
|
Port::new(0xCF8).write(address);
|
||||||
|
|
|
@ -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;
|
pub type Device = xml::XMLElement;
|
||||||
|
|
||||||
|
/// A tree of devices
|
||||||
// TODO: alphabatize this list
|
// TODO: alphabatize this list
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DeviceTree {
|
pub struct DeviceTree {
|
||||||
|
/// The device tree
|
||||||
pub devices: HashMap<String, Vec<Device>>,
|
pub devices: HashMap<String, Vec<Device>>,
|
||||||
}
|
}
|
||||||
impl DeviceTree {
|
impl DeviceTree {
|
||||||
|
/// Build the device tree. Does not populate the device tree
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut dt = Self {
|
let mut dt = Self {
|
||||||
devices: HashMap::new(),
|
devices: HashMap::new(),
|
||||||
|
|
|
@ -1,23 +1,28 @@
|
||||||
|
//! A handle module
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::arch::hardware_random_u64,
|
crate::arch::hardware_random_u64,
|
||||||
core::fmt::{self, Formatter},
|
core::fmt::{self, Formatter},
|
||||||
};
|
};
|
||||||
|
/// An operating system handle without permissions attached
|
||||||
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
||||||
pub struct OSHandle {
|
pub struct OSHandle {
|
||||||
pub id: u64,
|
id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OSHandle {
|
impl OSHandle {
|
||||||
|
/// turn a u64 into an OSHandle
|
||||||
pub fn new_from_u64(id: u64) -> Self {
|
pub fn new_from_u64(id: u64) -> Self {
|
||||||
Self { id }
|
Self { id }
|
||||||
}
|
}
|
||||||
|
/// Generate a new OSHandle using the HAL random function
|
||||||
pub fn random_new() -> Self {
|
pub fn random_new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: hardware_random_u64(),
|
id: hardware_random_u64(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// A handle for resources
|
||||||
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Copy)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
id: OSHandle,
|
id: OSHandle,
|
||||||
|
@ -25,13 +30,14 @@ pub struct Handle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
|
/// make a new handle
|
||||||
pub fn new() -> Handle {
|
pub fn new() -> Handle {
|
||||||
Handle {
|
Handle {
|
||||||
id: OSHandle::random_new(),
|
id: OSHandle::random_new(),
|
||||||
perms: Permissions::new(),
|
perms: Permissions::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// represent the os handle as a u64
|
||||||
pub fn as_u64(&self) -> u64 {
|
pub fn as_u64(&self) -> u64 {
|
||||||
self.id.id
|
self.id.id
|
||||||
}
|
}
|
||||||
|
@ -45,13 +51,12 @@ impl fmt::Display for Handle {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Hash, Eq, Debug, Clone, Copy)]
|
#[derive(PartialEq, Hash, Eq, Debug, Clone, Copy)]
|
||||||
|
struct Permissions {
|
||||||
pub struct Permissions {
|
|
||||||
edit_children: bool,
|
edit_children: bool,
|
||||||
edit_attributes: bool,
|
edit_attributes: bool,
|
||||||
}
|
}
|
||||||
impl Permissions {
|
impl Permissions {
|
||||||
pub fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
edit_children: true,
|
edit_children: true,
|
||||||
edit_attributes: true,
|
edit_attributes: true,
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
use hbvm::engine::Engine;
|
//! the system interface
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::ipc::message::Message,
|
crate::ipc::message::Message,
|
||||||
crossbeam_queue::{ArrayQueue, SegQueue},
|
crossbeam_queue::{ArrayQueue, SegQueue},
|
||||||
|
hbvm::engine::Engine,
|
||||||
log::trace,
|
log::trace,
|
||||||
};
|
};
|
||||||
|
/// Host errors
|
||||||
pub enum HostError {
|
pub enum HostError {
|
||||||
|
/// A host memory error
|
||||||
MemoryError,
|
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> {
|
pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
|
||||||
let _handle = engine.registers.f0;
|
let _handle = engine.registers.f0;
|
||||||
let message_start = engine.registers.f1;
|
let message_start = engine.registers.f1;
|
||||||
|
@ -28,7 +33,7 @@ pub fn ipc_send(engine: &mut Engine) -> Result<(), HostError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ipc_recv(_engine: &mut Engine) {}
|
// pub fn ipc_recv(_engine: &mut Engine) {}
|
||||||
|
|
||||||
/// Check f0 for the buffer type
|
/// Check f0 for the buffer type
|
||||||
/// 0 means an unbound buffer
|
/// 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_discover(_engine: &mut Engine) {}
|
||||||
pub fn rpc_register(_engine: &mut Engine) {}
|
// pub fn rpc_register(_engine: &mut Engine) {}
|
||||||
pub fn rpc_call(_engine: &mut Engine) {}
|
// pub fn rpc_call(_engine: &mut Engine) {}
|
||||||
|
|
|
@ -1,24 +1,29 @@
|
||||||
use crossbeam_queue::{ArrayQueue, SegQueue};
|
//!
|
||||||
|
|
||||||
use super::message::Message;
|
use {
|
||||||
|
super::message::Message,
|
||||||
|
crossbeam_queue::{ArrayQueue, SegQueue},
|
||||||
|
};
|
||||||
|
|
||||||
enum BufferTypes {
|
enum BufferTypes {
|
||||||
Unbound(SegQueue<Message>),
|
Unbound(SegQueue<Message>),
|
||||||
Bound(ArrayQueue<Message>),
|
Bound(ArrayQueue<Message>),
|
||||||
}
|
}
|
||||||
|
/// Interproccess buffer
|
||||||
pub struct IpcBuffer {
|
pub struct IpcBuffer {
|
||||||
protocol: Protocol,
|
protocol: Protocol,
|
||||||
buffer: BufferTypes,
|
buffer: BufferTypes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IpcBuffer {
|
impl IpcBuffer {
|
||||||
|
/// Validate a message to match the `IPC.protocol`
|
||||||
pub fn validate_messages(&mut self) -> Result<(), IpcError> {
|
pub fn validate_messages(&mut self) -> Result<(), IpcError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Interprocess Communication Errors
|
||||||
pub enum IpcError {
|
pub enum IpcError {
|
||||||
|
/// An invalid message error returned to the sender
|
||||||
InvalidMessage,
|
InvalidMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
//! Interprocess communication
|
||||||
pub mod buffer;
|
pub mod buffer;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
|
|
|
@ -62,8 +62,10 @@ pub fn kmain(cmdline: &str, bootstrap: Option<&'static [u8]>) -> ! {
|
||||||
let byte = sc.receive();
|
let byte = sc.receive();
|
||||||
if byte == b'\r' {
|
if byte == b'\r' {
|
||||||
sc.send(b'\n');
|
sc.send(b'\n');
|
||||||
|
sc.send(b'\r');
|
||||||
|
} else {
|
||||||
|
sc.send(byte);
|
||||||
}
|
}
|
||||||
sc.send(byte);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#![deny(clippy::pedantic, warnings)]
|
#![deny(clippy::pedantic, warnings)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
// #![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ fn main() -> Result<(), Error> {
|
||||||
let mut args = std::env::args();
|
let mut args = std::env::args();
|
||||||
args.next();
|
args.next();
|
||||||
// TODO: work on adding in system.toml support
|
// 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() {
|
match args.next().as_deref() {
|
||||||
Some("build" | "b") => {
|
Some("build" | "b") => {
|
||||||
|
|
Loading…
Reference in a new issue