pci interface skeleton
update hblang improve libraries/render hide some annoying warnings minor changes to page allocator and buffers implement page dealloc fiddle with sysdata
This commit is contained in:
parent
1031ca6314
commit
3ca7e13f3e
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -73,9 +73,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.86"
|
version = "1.0.87"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
|
@ -160,9 +160,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.1.16"
|
version = "1.1.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b"
|
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
@ -444,17 +444,17 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbytecode"
|
name = "hbbytecode"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d9aab2191b57d4c9fa5a57e70c38039e605ad741"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8a5027cab7ce008dbb0964fe0522c8fef585979"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbytecode"
|
name = "hbbytecode"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/ableos/holey-bytes#894f73ca35199f524dff6160c57c0916169fbaf6"
|
source = "git+https://git.ablecorp.us/ableos/holey-bytes#e8a5027cab7ce008dbb0964fe0522c8fef585979"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hblang"
|
name = "hblang"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d9aab2191b57d4c9fa5a57e70c38039e605ad741"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8a5027cab7ce008dbb0964fe0522c8fef585979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
|
"hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
|
||||||
]
|
]
|
||||||
|
@ -462,7 +462,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d9aab2191b57d4c9fa5a57e70c38039e605ad741"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8a5027cab7ce008dbb0964fe0522c8fef585979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
|
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
|
||||||
]
|
]
|
||||||
|
@ -470,7 +470,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/ableos/holey-bytes#894f73ca35199f524dff6160c57c0916169fbaf6"
|
source = "git+https://git.ablecorp.us/ableos/holey-bytes#e8a5027cab7ce008dbb0964fe0522c8fef585979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)",
|
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)",
|
||||||
]
|
]
|
||||||
|
@ -598,9 +598,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.9.0"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
|
@ -1008,18 +1008,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.209"
|
version = "1.0.210"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
|
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.209"
|
version = "1.0.210"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
|
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1028,9 +1028,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.127"
|
version = "1.0.128"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
|
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
@ -1170,9 +1170,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.11"
|
version = "0.7.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
|
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
|
|
@ -109,7 +109,6 @@ pub fn handler(vm: &mut Vm) {
|
||||||
|
|
||||||
let mut msg_vec = block_read(mem_addr, length);
|
let mut msg_vec = block_read(mem_addr, length);
|
||||||
let msg_type = msg_vec[0];
|
let msg_type = msg_vec[0];
|
||||||
msg_vec.remove(0);
|
|
||||||
match msg_type {
|
match msg_type {
|
||||||
0 => 'wow: {
|
0 => 'wow: {
|
||||||
let size = match msg_vec[0] {
|
let size = match msg_vec[0] {
|
||||||
|
@ -121,10 +120,7 @@ pub fn handler(vm: &mut Vm) {
|
||||||
break 'wow;
|
break 'wow;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
msg_vec.remove(0);
|
let addr = u16::from_le_bytes(msg_vec[1..3].try_into());
|
||||||
let addr = u16::from_le_bytes(msg_vec[0..2].try_into().unwrap());
|
|
||||||
msg_vec.remove(0);
|
|
||||||
msg_vec.remove(0);
|
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
match size {
|
match size {
|
||||||
1 => x86_in(addr) as u64,
|
1 => x86_in(addr) as u64,
|
||||||
|
@ -133,12 +129,11 @@ pub fn handler(vm: &mut Vm) {
|
||||||
_ => panic!("how?"),
|
_ => panic!("how?"),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
msg_vec.clear();
|
|
||||||
trace!("Read the value {} from address {}", value, addr);
|
trace!("Read the value {} from address {}", value, addr);
|
||||||
vm.registers[1] = hbvm::value::Value(value);
|
vm.registers[1] = hbvm::value::Value(value);
|
||||||
}
|
}
|
||||||
1 => 'wow: {
|
1 => 'wow: {
|
||||||
let size = match msg_vec[0] {
|
let size = match msg_vec[1] {
|
||||||
0 => 1,
|
0 => 1,
|
||||||
1 => 2,
|
1 => 2,
|
||||||
2 => 4,
|
2 => 4,
|
||||||
|
@ -147,26 +142,28 @@ pub fn handler(vm: &mut Vm) {
|
||||||
break 'wow;
|
break 'wow;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
msg_vec.remove(0);
|
let addr = unsafe {
|
||||||
let addr = u16::from_le_bytes(msg_vec[0..2].try_into().unwrap());
|
u16::from_le_bytes(msg_vec[1..3].try_into().unwrap_unchecked())
|
||||||
msg_vec.remove(0);
|
};
|
||||||
msg_vec.remove(0);
|
|
||||||
trace!("Setting address {}", addr);
|
trace!("Setting address {}", addr);
|
||||||
unsafe {
|
unsafe {
|
||||||
match size {
|
match size {
|
||||||
1 => x86_out(addr, msg_vec[0]),
|
1 => x86_out(addr, msg_vec[3]),
|
||||||
2 => x86_out_16(
|
2 => x86_out_16(
|
||||||
addr,
|
addr,
|
||||||
u16::from_le_bytes(msg_vec[0..2].try_into().unwrap()),
|
u16::from_le_bytes(
|
||||||
|
msg_vec[3..5].try_into().unwrap_unchecked(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
4 => x86_out_32(
|
4 => x86_out_32(
|
||||||
addr,
|
addr,
|
||||||
u32::from_le_bytes(msg_vec[0..4].try_into().unwrap()),
|
u32::from_le_bytes(
|
||||||
|
msg_vec[3..7].try_into().unwrap_unchecked(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
_ => panic!("How?"),
|
_ => panic!("How?"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg_vec.clear();
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -179,18 +176,18 @@ pub fn handler(vm: &mut Vm) {
|
||||||
let mut buffs = IPC_BUFFERS.lock();
|
let mut buffs = IPC_BUFFERS.lock();
|
||||||
match buffs.get_mut(&buffer_id) {
|
match buffs.get_mut(&buffer_id) {
|
||||||
Some(buff) => {
|
Some(buff) => {
|
||||||
let mut msg_vec = vec![];
|
let mut msg_vec = Vec::with_capacity(length);
|
||||||
|
|
||||||
for x in 0..(length as isize) {
|
for x in 0..(length as isize) {
|
||||||
let xyz = mem_addr as *const u8;
|
let xyz = mem_addr as *const u8;
|
||||||
let value = unsafe { xyz.offset(x).read() };
|
let value = unsafe { xyz.offset(x).read() };
|
||||||
msg_vec.push(value);
|
msg_vec.push(value);
|
||||||
}
|
}
|
||||||
buff.push(msg_vec.clone());
|
|
||||||
debug!(
|
debug!(
|
||||||
"Message {:?} has been sent to Buffer({})",
|
"Message {:?} has been sent to Buffer({})",
|
||||||
msg_vec, buffer_id
|
msg_vec, buffer_id
|
||||||
);
|
);
|
||||||
|
buff.push(msg_vec);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
log::error!("Access of non-existent buffer {}", buffer_id)
|
log::error!("Access of non-existent buffer {}", buffer_id)
|
||||||
|
|
|
@ -4,10 +4,16 @@ use {
|
||||||
kernel_services::{block_read, mem_serve},
|
kernel_services::{block_read, mem_serve},
|
||||||
Vm,
|
Vm,
|
||||||
},
|
},
|
||||||
alloc::alloc::alloc_zeroed,
|
alloc::{
|
||||||
|
alloc::{alloc_zeroed, dealloc},
|
||||||
|
vec::Vec,
|
||||||
|
},
|
||||||
|
core::alloc::Layout,
|
||||||
log::{debug, info},
|
log::{debug, info},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use alloc::vec;
|
||||||
|
|
||||||
pub enum MemoryServiceError {
|
pub enum MemoryServiceError {
|
||||||
InvalidMemoryFormat,
|
InvalidMemoryFormat,
|
||||||
}
|
}
|
||||||
|
@ -20,12 +26,9 @@ pub enum MemoryQuotaType {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_page(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), MemoryServiceError> {
|
fn alloc_page(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), MemoryServiceError> {
|
||||||
let mut val = alloc::vec::Vec::new();
|
let ptr = unsafe { alloc_zeroed(Layout::new::<[u8; 4096]>()) };
|
||||||
for _ in 0..4096 {
|
info!("Block address: {:?}", ptr);
|
||||||
val.push(0);
|
vm.registers[1] = hbvm::value::Value(ptr as u64);
|
||||||
}
|
|
||||||
info!("Block address: {:?}", val.as_ptr());
|
|
||||||
vm.registers[1] = hbvm::value::Value(val.as_ptr() as u64);
|
|
||||||
vm.registers[2] = hbvm::value::Value(4096);
|
vm.registers[2] = hbvm::value::Value(4096);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -37,32 +40,37 @@ pub fn memory_msg_handler(
|
||||||
) -> Result<(), MemoryServiceError> {
|
) -> Result<(), MemoryServiceError> {
|
||||||
let mut msg_vec = block_read(mem_addr, length);
|
let mut msg_vec = block_read(mem_addr, length);
|
||||||
let msg_type = msg_vec[0];
|
let msg_type = msg_vec[0];
|
||||||
|
|
||||||
msg_vec.remove(0);
|
|
||||||
match msg_type {
|
match msg_type {
|
||||||
0 => {
|
0 => {
|
||||||
let page_count = msg_vec[0];
|
let page_count = msg_vec[1];
|
||||||
msg_vec.remove(0);
|
let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap();
|
||||||
|
|
||||||
let mptr_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
|
|
||||||
let mptr: u64 = u64::from_le_bytes(mptr_raw);
|
let mptr: u64 = u64::from_le_bytes(mptr_raw);
|
||||||
|
|
||||||
log::debug!("Allocating {} pages @ {:x}", page_count, mptr);
|
log::debug!("Allocating {} pages @ {:x}", page_count, mptr);
|
||||||
|
|
||||||
let mut val = alloc::vec::Vec::new();
|
let ptr = unsafe {
|
||||||
for _ in 0..(page_count as isize * 4096) {
|
alloc_zeroed(Layout::from_size_align_unchecked(
|
||||||
val.push(0);
|
page_count as usize * 4096,
|
||||||
}
|
1,
|
||||||
vm.registers[1] = hbvm::value::Value(val.as_ptr() as u64);
|
))
|
||||||
log::debug!("Kernel ptr: {:x}", val.as_ptr() as u64);
|
};
|
||||||
}
|
|
||||||
1 => {
|
|
||||||
let page_count = msg_vec[0];
|
|
||||||
msg_vec.remove(0);
|
|
||||||
|
|
||||||
let mptr_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
|
vm.registers[1] = hbvm::value::Value(ptr as u64);
|
||||||
|
log::debug!("Kernel ptr: {:x}", ptr as u64);
|
||||||
|
}
|
||||||
|
|
||||||
|
1 => {
|
||||||
|
let page_count = msg_vec[1];
|
||||||
|
|
||||||
|
let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap();
|
||||||
let mptr: u64 = u64::from_le_bytes(mptr_raw);
|
let mptr: u64 = u64::from_le_bytes(mptr_raw);
|
||||||
log::debug!("Deallocating {} pages @ {:x}", page_count, mptr);
|
log::debug!("Deallocating {} pages @ {:x}", page_count, mptr);
|
||||||
|
unsafe {
|
||||||
|
dealloc(
|
||||||
|
mptr as *mut u8,
|
||||||
|
Layout::from_size_align_unchecked(page_count as usize * 4096, 1),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
use MemoryQuotaType::*;
|
use MemoryQuotaType::*;
|
||||||
|
@ -73,19 +81,10 @@ pub fn memory_msg_handler(
|
||||||
3 => KillQuota,
|
3 => KillQuota,
|
||||||
_ => NoQuota,
|
_ => NoQuota,
|
||||||
};
|
};
|
||||||
msg_vec.remove(0);
|
let hid_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap();
|
||||||
let hid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
|
|
||||||
let hid: u64 = u64::from_le_bytes(hid_raw);
|
let hid: u64 = u64::from_le_bytes(hid_raw);
|
||||||
for _ in 0..8 {
|
let pid_raw: [u8; 8] = msg_vec[10..18].try_into().unwrap();
|
||||||
msg_vec.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
let pid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap();
|
|
||||||
let pid: u64 = u64::from_le_bytes(hid_raw);
|
let pid: u64 = u64::from_le_bytes(hid_raw);
|
||||||
for _ in 0..8 {
|
|
||||||
msg_vec.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Setting HID-{:x}:PID-{:x}'s quota type to {:?}",
|
"Setting HID-{:x}:PID-{:x}'s quota type to {:?}",
|
||||||
hid, pid, quota_type
|
hid, pid, quota_type
|
||||||
|
@ -94,7 +93,6 @@ pub fn memory_msg_handler(
|
||||||
3 => {
|
3 => {
|
||||||
let page_count = msg_vec[0];
|
let page_count = msg_vec[0];
|
||||||
log::debug!(" {} pages", page_count);
|
log::debug!(" {} pages", page_count);
|
||||||
msg_vec.remove(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -4,10 +4,10 @@ pub mod mem_serve;
|
||||||
pub mod service_definition_service;
|
pub mod service_definition_service;
|
||||||
|
|
||||||
pub fn block_read(mem_addr: u64, length: usize) -> Vec<u8> {
|
pub fn block_read(mem_addr: u64, length: usize) -> Vec<u8> {
|
||||||
let mut msg_vec = vec![];
|
let mut msg_vec = Vec::with_capacity(length);
|
||||||
|
let xyz = mem_addr as *const u8;
|
||||||
|
|
||||||
for x in 0..(length as isize) {
|
for x in 0..(length as isize) {
|
||||||
let xyz = mem_addr as *const u8;
|
|
||||||
let value = unsafe { xyz.offset(x).read() };
|
let value = unsafe { xyz.offset(x).read() };
|
||||||
msg_vec.push(value);
|
msg_vec.push(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,9 @@ impl IpcBuffer {
|
||||||
}
|
}
|
||||||
pub fn push(&mut self, msg: Message) {
|
pub fn push(&mut self, msg: Message) {
|
||||||
match &self.buffer {
|
match &self.buffer {
|
||||||
BufferTypes::Unbound(buff) => buff.push(msg.clone()),
|
BufferTypes::Unbound(buff) => buff.push(msg),
|
||||||
BufferTypes::Bound(buff) => {
|
BufferTypes::Bound(buff) => {
|
||||||
let _ = buff.push(msg.clone());
|
let _ = buff.push(msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
//! The ableOS kernel.
|
//! The ableOS kernel.
|
||||||
//! Named akern.
|
//! Named akern.
|
||||||
//! Akern is woefully undersupported at the moment but we are looking to add support improve hardware discovery and make our lives as kernel and operating system developers easier and better
|
//! Akern is woefully undersupported at the moment but we are looking to add support improve hardware discovery and make our lives as kernel and operating system developers easier and better
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![feature(
|
#![feature(
|
||||||
abi_x86_interrupt,
|
abi_x86_interrupt,
|
||||||
alloc_error_handler,
|
alloc_error_handler,
|
||||||
inline_const,
|
|
||||||
panic_info_message,
|
panic_info_message,
|
||||||
pointer_is_aligned,
|
|
||||||
ptr_sub_ptr,
|
ptr_sub_ptr,
|
||||||
custom_test_frameworks,
|
custom_test_frameworks,
|
||||||
naked_functions,
|
naked_functions,
|
||||||
pointer_is_aligned_to
|
pointer_is_aligned_to
|
||||||
)]
|
)]
|
||||||
#![allow(dead_code)]
|
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
|
#![cfg_attr(not(debug_assertions), allow(unused, deprecated))]
|
||||||
|
#![allow(dead_code)]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
mod allocator;
|
mod allocator;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(unused)]
|
||||||
use std::{
|
use std::{
|
||||||
fmt::format,
|
fmt::format,
|
||||||
fs::{read_to_string, File},
|
fs::{read_to_string, File},
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(unused)]
|
||||||
mod dev;
|
mod dev;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
|
|
|
@ -32,10 +32,12 @@ put_line := default.put_line
|
||||||
clear := default.clear
|
clear := default.clear
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
screen_width := default.screen_width
|
width := default.width
|
||||||
screen_height := default.screen_height
|
height := default.height
|
||||||
set_screen_height := default.set_screen_height
|
dimensions := default.dimensions
|
||||||
set_screen_width := default.set_screen_width
|
set_height := default.set_height
|
||||||
|
set_width := default.set_width
|
||||||
|
set_dimensions := default.set_dimensions
|
||||||
sync := default.sync
|
sync := default.sync
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.{log, math, memory, buffer} := @use("../../stn/src/lib.hb");
|
.{math, memory} := @use("../../stn/src/lib.hb");
|
||||||
.{IVec2} := @use("rel:lib.hb")
|
.{IVec2} := @use("rel:lib.hb")
|
||||||
|
|
||||||
Color := struct {b: u8, g: u8, r: u8, a: u8}
|
Color := struct {b: u8, g: u8, r: u8, a: u8}
|
||||||
|
@ -31,22 +31,23 @@ front_buffer := @as(^Color, @bitcast(0xFFFF8000C0000000))
|
||||||
// jank back buffer time, im sure nothing will go wrong
|
// jank back buffer time, im sure nothing will go wrong
|
||||||
// will be removed as soon as i can figure out a fast way of doing runtime global scope
|
// will be removed as soon as i can figure out a fast way of doing runtime global scope
|
||||||
back_buffer := @as(^Color, @bitcast(0xFFFF8000C0000000 + fb_bytes))
|
back_buffer := @as(^Color, @bitcast(0xFFFF8000C0000000 + fb_bytes))
|
||||||
// create_back_buffer := fn(): ^Color {
|
|
||||||
// if total_pages <= 0xFF {
|
create_back_buffer := fn(): ^Color {
|
||||||
// return @bitcast(@inline(memory.request_page, total_pages))
|
if total_pages <= 0xFF {
|
||||||
// }
|
return @bitcast(@inline(memory.request_page, total_pages))
|
||||||
// ptr := @inline(memory.request_page, 255)
|
}
|
||||||
// remaining := total_pages - 0xFF
|
ptr := @inline(memory.request_page, 255)
|
||||||
// loop if remaining <= 0 break else {
|
remaining := total_pages - 0xFF
|
||||||
// if remaining < 0xFF {
|
loop if remaining <= 0 break else {
|
||||||
// memory.request_page(remaining)
|
if remaining < 0xFF {
|
||||||
// } else {
|
memory.request_page(remaining)
|
||||||
// memory.request_page(0xFF)
|
} else {
|
||||||
// }
|
memory.request_page(0xFF)
|
||||||
// remaining -= 0xFF
|
}
|
||||||
// }
|
remaining -= 0xFF
|
||||||
// return @bitcast(ptr)
|
}
|
||||||
// }
|
return @bitcast(ptr)
|
||||||
|
}
|
||||||
|
|
||||||
clear := fn(color: Color): void {
|
clear := fn(color: Color): void {
|
||||||
n := 0
|
n := 0
|
||||||
|
@ -71,11 +72,11 @@ sync := fn(): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_width := fn(): int {
|
width := fn(): int {
|
||||||
return fb_width
|
return fb_width
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_height := fn(): int {
|
height := fn(): int {
|
||||||
return fb_height
|
return fb_height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,14 +187,23 @@ put_line := fn(p0: IVec2, p1: IVec2, color: Color): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_screen_height := fn(new: int): void {
|
set_height := fn(new: int): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_screen_width := fn(new: int): void {
|
set_width := fn(new: int): void {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dimensions := fn(): IVec2 {
|
||||||
|
return .(fb_width, fb_height)
|
||||||
|
}
|
||||||
|
|
||||||
|
set_dimensions := fn(new: IVec2): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
init := fn(): void {
|
init := fn(): void {
|
||||||
|
back_buffer = create_back_buffer()
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
.{log, math} := @use("../../stn/src/lib.hb");
|
.{pci, memory, string, log} := @use("../../stn/src/lib.hb");
|
||||||
.{IVec2} := @use("rel:lib.hb")
|
.{IVec2} := @use("rel:lib.hb")
|
||||||
|
|
||||||
Color := struct {b: u8, g: u8, r: u8, a: u8}
|
Color := struct {b: u8, g: u8, r: u8, a: u8}
|
||||||
|
@ -23,14 +23,18 @@ clear := fn(color: Color): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_width := fn(): int {
|
width := fn(): int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
screen_height := fn(): int {
|
height := fn(): int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dimensions := fn(): IVec2 {
|
||||||
|
return .(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
put_pixel := fn(position: IVec2, color: Color): void {
|
put_pixel := fn(position: IVec2, color: Color): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -55,14 +59,33 @@ put_line := fn(p0: IVec2, p1: IVec2, color: Color): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_screen_height := fn(new: int): void {
|
set_height := fn(new: int): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set_screen_width := fn(new: int): void {
|
set_width := fn(new: int): void {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
set_dimensions := fn(new: IVec2): void {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sync := fn(): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
init := fn(): void {
|
init := fn(): void {
|
||||||
|
b := memory.request_page(1)
|
||||||
|
bus := 0
|
||||||
|
device := 0
|
||||||
|
loop if bus == 256 break else {
|
||||||
|
loop if device == 32 break else {
|
||||||
|
a := pci.config_read(0, 0, 0, 0)
|
||||||
|
log.info(string.display_int(a, b))
|
||||||
|
device += 1
|
||||||
|
}
|
||||||
|
bus += 1
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -4,3 +4,4 @@ memory := @use("rel:memory.hb")
|
||||||
buffer := @use("rel:buffer.hb")
|
buffer := @use("rel:buffer.hb")
|
||||||
math := @use("rel:math.hb")
|
math := @use("rel:math.hb")
|
||||||
random := @use("rel:random.hb")
|
random := @use("rel:random.hb")
|
||||||
|
pci := @use("rel:pci.hb")
|
|
@ -19,26 +19,26 @@ release_page := fn(ptr: ^u8, page_count: u8): void {
|
||||||
|
|
||||||
outb := fn(addr: u16, value: u8): void {
|
outb := fn(addr: u16, value: u8): void {
|
||||||
msg := "\0\0\0\0\0";
|
msg := "\0\0\0\0\0";
|
||||||
*msg = 1;
|
*@as(^u8, msg) = @as(u8, 1);
|
||||||
*(msg + 1) = 0;
|
*@as(^u8, msg + 1) = @as(u8, 0);
|
||||||
*@as(^u16, @bitcast(msg + 2)) = addr;
|
*@as(^u16, @bitcast(msg + 2)) = addr;
|
||||||
*(msg + 4) = value
|
*@as(^u8, msg + 4) = value
|
||||||
@eca(void, 3, 3, msg, 5)
|
@eca(void, 3, 3, msg, 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inb := fn(addr: u16): u8 {
|
inb := fn(addr: u16): u8 {
|
||||||
msg := "\0\0\0\0";
|
msg := "\0\0\0\0";
|
||||||
*msg = 0;
|
*@as(^u8, msg) = @as(u8, 0);
|
||||||
*(msg + 1) = 0;
|
*@as(^u8, msg + 1) = @as(u8, 0);
|
||||||
*@as(^u16, @bitcast(msg + 2)) = addr
|
*@as(^u16, @bitcast(msg + 2)) = addr
|
||||||
return @eca(u8, 3, 3, msg, 4)
|
return @eca(u8, 3, 3, msg, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
outl := fn(addr: u16, value: u32): void {
|
outl := fn(addr: u16, value: u32): void {
|
||||||
msg := "\0\0\0\0\0\0\0\0";
|
msg := "\0\0\0\0\0\0\0\0";
|
||||||
*msg = 1;
|
*@as(^u8, msg) = @as(u8, 1);
|
||||||
*(msg + 1) = 2;
|
*@as(^u8, msg + 1) = @as(u8, 2);
|
||||||
*@as(^u16, @bitcast(msg + 2)) = addr;
|
*@as(^u16, @bitcast(msg + 2)) = addr;
|
||||||
*@as(^u32, @bitcast(msg + 4)) = value
|
*@as(^u32, @bitcast(msg + 4)) = value
|
||||||
@eca(void, 3, 3, msg, 8)
|
@eca(void, 3, 3, msg, 8)
|
||||||
|
@ -47,8 +47,8 @@ outl := fn(addr: u16, value: u32): void {
|
||||||
|
|
||||||
inl := fn(addr: u16): u32 {
|
inl := fn(addr: u16): u32 {
|
||||||
msg := "\0\0\0\0";
|
msg := "\0\0\0\0";
|
||||||
*msg = 0;
|
*@as(^u8, msg) = @as(u8, 0);
|
||||||
*(msg + 1) = 2;
|
*@as(^u8, msg + 1) = @as(u8, 2);
|
||||||
*@as(^u16, @bitcast(msg + 2)) = addr
|
*@as(^u16, @bitcast(msg + 2)) = addr
|
||||||
return @eca(u32, 3, 3, msg, 4)
|
return @eca(u32, 3, 3, msg, 4)
|
||||||
}
|
}
|
50
sysdata/libraries/stn/src/pci.hb
Normal file
50
sysdata/libraries/stn/src/pci.hb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
.{inl, outl} := @use("rel:memory.hb")
|
||||||
|
|
||||||
|
config_read := fn(bus: u8, device: u8, func: u8, offset: u8): u32 {
|
||||||
|
lbus := @as(u32, bus)
|
||||||
|
ldevice := @as(u32, device)
|
||||||
|
lfunc := @as(u32, func)
|
||||||
|
loffset := @as(u32, offset)
|
||||||
|
|
||||||
|
address := lbus << 16 | ldevice << 11 | lfunc << 8 | loffset & 0xFC | @as(u32, 0x80000000)
|
||||||
|
|
||||||
|
outl(0xCF8, address)
|
||||||
|
return inl(0xCFC)
|
||||||
|
}
|
||||||
|
|
||||||
|
config_write := fn(bus: u8, device: u8, func: u8, offset: u8, value: u32): void {
|
||||||
|
lbus := @as(u32, bus)
|
||||||
|
ldevice := @as(u32, device)
|
||||||
|
lfunc := @as(u32, func)
|
||||||
|
loffset := @as(u32, offset)
|
||||||
|
|
||||||
|
address := lbus << 16 | ldevice << 11 | lfunc << 8 | loffset & 0xFC | @as(u32, 0x80000000)
|
||||||
|
|
||||||
|
outl(0xCF8, address)
|
||||||
|
outl(0xCFC, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
get_header_type := fn(bus: u8, device: u8, func: u8): u8 {
|
||||||
|
return @as(u8, config_read(bus, device, func, 0xC) >> 16 & 0xFF)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ids := struct {vendor: u16, device: u16}
|
||||||
|
|
||||||
|
get_ids := fn(bus: u8, device: u8, func: u8): Ids {
|
||||||
|
res := config_read(bus, device, func, 0)
|
||||||
|
return .(@as(u16, res >> 16 & 0xFFFF), @as(u16, res & 0xFFFF))
|
||||||
|
}
|
||||||
|
|
||||||
|
PciDeviceInfo := struct {header_type: u8, device: u8, bus: u8, device_id: Ids, full_class: u16, rev_id: u8}
|
||||||
|
|
||||||
|
check_device := fn(bus: u8, device: u8): PciDeviceInfo {
|
||||||
|
ids := get_ids(bus, device, 0)
|
||||||
|
if ids.vendor == 0xFFFF {
|
||||||
|
return .(0, 0, 0, .(0, 0), 0, 0)
|
||||||
|
}
|
||||||
|
reg2 := config_read(bus, device, 0, 0x8)
|
||||||
|
class := @as(u16, reg2 >> 16 & 0xFFFF)
|
||||||
|
header_type := get_header_type(bus, device, 0)
|
||||||
|
|
||||||
|
return .(header_type, device, bus, ids, class, @as(u8, reg2 & 0xFF))
|
||||||
|
}
|
|
@ -6,12 +6,13 @@ render := @use("../../../../libraries/render/src/lib.hb")
|
||||||
|
|
||||||
example := fn(): void {
|
example := fn(): void {
|
||||||
render.clear(.(100, 50, 0, 255))
|
render.clear(.(100, 50, 0, 255))
|
||||||
width := render.screen_width()
|
width := render.width()
|
||||||
height := render.screen_height()
|
height := render.height()
|
||||||
p0 := render.IVec2.(0, 0 - 1)
|
p0 := render.IVec2.(0, 0)
|
||||||
p1 := render.IVec2.(0, height - 1)
|
p1 := render.IVec2.(0, height)
|
||||||
loop if p0.y >= height break else {
|
loop if p0.y >= height break else {
|
||||||
render.put_line(p0, p1, .(255, 180, 100, 255))
|
render.put_line(p0, p1, .(255, 180, 100, 255))
|
||||||
|
render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255))
|
||||||
p0.y += height >> 6
|
p0.y += height >> 6
|
||||||
p1.x += width >> 6
|
p1.x += width >> 6
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ render := @use("../../../../libraries/render/src/lib.hb")
|
||||||
example := fn(): void {
|
example := fn(): void {
|
||||||
vel := render.IVec2.(1, 1)
|
vel := render.IVec2.(1, 1)
|
||||||
pos := render.IVec2.(100, 100)
|
pos := render.IVec2.(100, 100)
|
||||||
width := render.screen_width()
|
width := render.width()
|
||||||
height := render.screen_height()
|
height := render.height()
|
||||||
loop {
|
loop {
|
||||||
render.put_rect(pos, .(100, 100), render.white)
|
render.put_rect(pos, .(100, 100), render.white)
|
||||||
render.sync()
|
render.sync()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.{example} := @use("./examples/lines.hb")
|
.{example} := @use("./examples/square.hb")
|
||||||
|
|
||||||
main := fn(): void {
|
main := fn(): void {
|
||||||
@inline(example)
|
@inline(example)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "a_serial_driver"
|
name = "serial_driver"
|
||||||
authors = ["Able"]
|
authors = ["Able"]
|
||||||
|
|
||||||
[dependants.libraries]
|
[dependants.libraries]
|
|
@ -1,5 +1,4 @@
|
||||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
.{memory, buffer} := @use("../../../libraries/stn/src/lib.hb")
|
||||||
.{log, string, memory, buffer} := stn
|
|
||||||
|
|
||||||
serial_print := fn(ptr: ^u8): void {
|
serial_print := fn(ptr: ^u8): void {
|
||||||
letter := 0
|
letter := 0
|
|
@ -1,4 +1,4 @@
|
||||||
.{string, memory, buffer} := @use("../../../libraries/stn/src/lib.hb")
|
.{string, buffer} := @use("../../../libraries/stn/src/lib.hb")
|
||||||
|
|
||||||
log_info := fn(): void {
|
log_info := fn(): void {
|
||||||
a := buffer.search("XNumber\0")
|
a := buffer.search("XNumber\0")
|
||||||
|
|
|
@ -20,11 +20,11 @@ resolution = "1024x768x24"
|
||||||
# [boot.limine.ableos.modules.tests]
|
# [boot.limine.ableos.modules.tests]
|
||||||
# path = "boot:///tests.hbf"
|
# path = "boot:///tests.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.0render_driver]
|
[boot.limine.ableos.modules.1render_driver]
|
||||||
path = "boot:///render_driver.hbf"
|
path = "boot:///render_driver.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.a_serial_driver]
|
[boot.limine.ableos.modules.0serial_driver]
|
||||||
path = "boot:///a_serial_driver.hbf"
|
path = "boot:///serial_driver.hbf"
|
||||||
|
|
||||||
[boot.limine.ableos.modules.diskio_driver]
|
[boot.limine.ableos.modules.diskio_driver]
|
||||||
path = "boot:///diskio_driver.hbf"
|
path = "boot:///diskio_driver.hbf"
|
||||||
|
|
Loading…
Reference in a new issue