From 3ca7e13f3ec9df67664e02808405e800381016ef Mon Sep 17 00:00:00 2001 From: koniifer Date: Sun, 8 Sep 2024 19:25:13 +0100 Subject: [PATCH] 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 --- Cargo.lock | 38 +++++----- kernel/src/holeybytes/ecah.rs | 31 ++++---- .../holeybytes/kernel_services/mem_serve.rs | 70 +++++++++---------- kernel/src/holeybytes/kernel_services/mod.rs | 4 +- kernel/src/ipc/buffer.rs | 4 +- kernel/src/lib.rs | 6 +- repbuild/src/dev.rs | 1 + repbuild/src/main.rs | 1 + sysdata/libraries/render/src/lib.hb | 10 +-- sysdata/libraries/render/src/software.hb | 52 ++++++++------ sysdata/libraries/render/src/svga.hb | 33 +++++++-- sysdata/libraries/stn/src/lib.hb | 3 +- sysdata/libraries/stn/src/memory.hb | 18 ++--- sysdata/libraries/stn/src/pci.hb | 50 +++++++++++++ sysdata/programs/diskio_driver/src/main.hb | 2 +- .../render_example/src/examples/lines.hb | 9 +-- .../render_example/src/examples/square.hb | 4 +- sysdata/programs/render_example/src/main.hb | 2 +- .../README.md | 0 .../meta.toml | 2 +- .../src/main.hb | 3 +- .../programs/serial_driver_test/src/main.hb | 2 +- sysdata/system_config.toml | 6 +- 23 files changed, 216 insertions(+), 135 deletions(-) create mode 100644 sysdata/libraries/stn/src/pci.hb rename sysdata/programs/{a_serial_driver => serial_driver}/README.md (100%) rename sysdata/programs/{a_serial_driver => serial_driver}/meta.toml (84%) rename sysdata/programs/{a_serial_driver => serial_driver}/src/main.hb (90%) diff --git a/Cargo.lock b/Cargo.lock index 0fadff6..a124b3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" [[package]] name = "autocfg" @@ -160,9 +160,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.1.16" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ "shlex", ] @@ -444,17 +444,17 @@ dependencies = [ [[package]] name = "hbbytecode" 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]] name = "hbbytecode" 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]] name = "hblang" 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 = [ "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -462,7 +462,7 @@ dependencies = [ [[package]] name = "hbvm" 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 = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -470,7 +470,7 @@ dependencies = [ [[package]] name = "hbvm" 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 = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)", ] @@ -598,9 +598,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] name = "itoa" @@ -1008,18 +1008,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -1028,9 +1028,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -1170,9 +1170,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index f4f162c..9bca359 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -109,7 +109,6 @@ pub fn handler(vm: &mut Vm) { let mut msg_vec = block_read(mem_addr, length); let msg_type = msg_vec[0]; - msg_vec.remove(0); match msg_type { 0 => 'wow: { let size = match msg_vec[0] { @@ -121,10 +120,7 @@ pub fn handler(vm: &mut Vm) { break 'wow; } }; - msg_vec.remove(0); - let addr = u16::from_le_bytes(msg_vec[0..2].try_into().unwrap()); - msg_vec.remove(0); - msg_vec.remove(0); + let addr = u16::from_le_bytes(msg_vec[1..3].try_into()); let value = unsafe { match size { 1 => x86_in(addr) as u64, @@ -133,12 +129,11 @@ pub fn handler(vm: &mut Vm) { _ => panic!("how?"), } }; - msg_vec.clear(); trace!("Read the value {} from address {}", value, addr); vm.registers[1] = hbvm::value::Value(value); } 1 => 'wow: { - let size = match msg_vec[0] { + let size = match msg_vec[1] { 0 => 1, 1 => 2, 2 => 4, @@ -147,26 +142,28 @@ pub fn handler(vm: &mut Vm) { break 'wow; } }; - msg_vec.remove(0); - let addr = u16::from_le_bytes(msg_vec[0..2].try_into().unwrap()); - msg_vec.remove(0); - msg_vec.remove(0); + let addr = unsafe { + u16::from_le_bytes(msg_vec[1..3].try_into().unwrap_unchecked()) + }; trace!("Setting address {}", addr); unsafe { match size { - 1 => x86_out(addr, msg_vec[0]), + 1 => x86_out(addr, msg_vec[3]), 2 => x86_out_16( 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( 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?"), } } - msg_vec.clear(); } _ => {} } @@ -179,18 +176,18 @@ pub fn handler(vm: &mut Vm) { let mut buffs = IPC_BUFFERS.lock(); match buffs.get_mut(&buffer_id) { Some(buff) => { - let mut msg_vec = vec![]; + let mut msg_vec = Vec::with_capacity(length); for x in 0..(length as isize) { let xyz = mem_addr as *const u8; let value = unsafe { xyz.offset(x).read() }; msg_vec.push(value); } - buff.push(msg_vec.clone()); debug!( "Message {:?} has been sent to Buffer({})", msg_vec, buffer_id ); + buff.push(msg_vec); } None => { log::error!("Access of non-existent buffer {}", buffer_id) diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 16ecbe8..8965dbb 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -4,10 +4,16 @@ use { kernel_services::{block_read, mem_serve}, Vm, }, - alloc::alloc::alloc_zeroed, + alloc::{ + alloc::{alloc_zeroed, dealloc}, + vec::Vec, + }, + core::alloc::Layout, log::{debug, info}, }; +use alloc::vec; + pub enum MemoryServiceError { InvalidMemoryFormat, } @@ -20,12 +26,9 @@ pub enum MemoryQuotaType { } fn alloc_page(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), MemoryServiceError> { - let mut val = alloc::vec::Vec::new(); - for _ in 0..4096 { - val.push(0); - } - info!("Block address: {:?}", val.as_ptr()); - vm.registers[1] = hbvm::value::Value(val.as_ptr() as u64); + let ptr = unsafe { alloc_zeroed(Layout::new::<[u8; 4096]>()) }; + info!("Block address: {:?}", ptr); + vm.registers[1] = hbvm::value::Value(ptr as u64); vm.registers[2] = hbvm::value::Value(4096); Ok(()) } @@ -37,32 +40,37 @@ pub fn memory_msg_handler( ) -> Result<(), MemoryServiceError> { let mut msg_vec = block_read(mem_addr, length); let msg_type = msg_vec[0]; - - msg_vec.remove(0); match msg_type { 0 => { - let page_count = msg_vec[0]; - msg_vec.remove(0); - - let mptr_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap(); + 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); log::debug!("Allocating {} pages @ {:x}", page_count, mptr); - let mut val = alloc::vec::Vec::new(); - for _ in 0..(page_count as isize * 4096) { - val.push(0); - } - 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 ptr = unsafe { + alloc_zeroed(Layout::from_size_align_unchecked( + page_count as usize * 4096, + 1, + )) + }; - 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); 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 => { use MemoryQuotaType::*; @@ -73,19 +81,10 @@ pub fn memory_msg_handler( 3 => KillQuota, _ => NoQuota, }; - msg_vec.remove(0); - let hid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap(); + let hid_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap(); let hid: u64 = u64::from_le_bytes(hid_raw); - for _ in 0..8 { - msg_vec.remove(0); - } - - let pid_raw: [u8; 8] = msg_vec[0..8].try_into().unwrap(); + let pid_raw: [u8; 8] = msg_vec[10..18].try_into().unwrap(); let pid: u64 = u64::from_le_bytes(hid_raw); - for _ in 0..8 { - msg_vec.remove(0); - } - debug!( "Setting HID-{:x}:PID-{:x}'s quota type to {:?}", hid, pid, quota_type @@ -94,7 +93,6 @@ pub fn memory_msg_handler( 3 => { let page_count = msg_vec[0]; log::debug!(" {} pages", page_count); - msg_vec.remove(0); } _ => { diff --git a/kernel/src/holeybytes/kernel_services/mod.rs b/kernel/src/holeybytes/kernel_services/mod.rs index 23908ef..367a63d 100644 --- a/kernel/src/holeybytes/kernel_services/mod.rs +++ b/kernel/src/holeybytes/kernel_services/mod.rs @@ -4,10 +4,10 @@ pub mod mem_serve; pub mod service_definition_service; pub fn block_read(mem_addr: u64, length: usize) -> Vec { - 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) { - let xyz = mem_addr as *const u8; let value = unsafe { xyz.offset(x).read() }; msg_vec.push(value); } diff --git a/kernel/src/ipc/buffer.rs b/kernel/src/ipc/buffer.rs index 71756bb..85c98f9 100644 --- a/kernel/src/ipc/buffer.rs +++ b/kernel/src/ipc/buffer.rs @@ -48,9 +48,9 @@ impl IpcBuffer { } pub fn push(&mut self, msg: Message) { match &self.buffer { - BufferTypes::Unbound(buff) => buff.push(msg.clone()), + BufferTypes::Unbound(buff) => buff.push(msg), BufferTypes::Bound(buff) => { - let _ = buff.push(msg.clone()); + let _ = buff.push(msg); } }; } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 26c3270..8587369 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,21 +1,19 @@ //! The ableOS kernel. //! 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 - #![no_std] #![feature( abi_x86_interrupt, alloc_error_handler, - inline_const, panic_info_message, - pointer_is_aligned, ptr_sub_ptr, custom_test_frameworks, naked_functions, pointer_is_aligned_to )] -#![allow(dead_code)] #![test_runner(crate::test_runner)] +#![cfg_attr(not(debug_assertions), allow(unused, deprecated))] +#![allow(dead_code)] extern crate alloc; mod allocator; diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index 67768e8..2e81228 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -1,3 +1,4 @@ +#![allow(unused)] use std::{ fmt::format, fs::{read_to_string, File}, diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 8eb4835..3c7095f 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -1,3 +1,4 @@ +#![allow(unused)] mod dev; use { diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 3cb0274..47a3b7e 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -32,10 +32,12 @@ put_line := default.put_line clear := default.clear // Display -screen_width := default.screen_width -screen_height := default.screen_height -set_screen_height := default.set_screen_height -set_screen_width := default.set_screen_width +width := default.width +height := default.height +dimensions := default.dimensions +set_height := default.set_height +set_width := default.set_width +set_dimensions := default.set_dimensions sync := default.sync // Math diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index 0da615a..da15e5c 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -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") 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 // 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)) -// create_back_buffer := fn(): ^Color { -// if total_pages <= 0xFF { -// return @bitcast(@inline(memory.request_page, total_pages)) -// } -// ptr := @inline(memory.request_page, 255) -// remaining := total_pages - 0xFF -// loop if remaining <= 0 break else { -// if remaining < 0xFF { -// memory.request_page(remaining) -// } else { -// memory.request_page(0xFF) -// } -// remaining -= 0xFF -// } -// return @bitcast(ptr) -// } + +create_back_buffer := fn(): ^Color { + if total_pages <= 0xFF { + return @bitcast(@inline(memory.request_page, total_pages)) + } + ptr := @inline(memory.request_page, 255) + remaining := total_pages - 0xFF + loop if remaining <= 0 break else { + if remaining < 0xFF { + memory.request_page(remaining) + } else { + memory.request_page(0xFF) + } + remaining -= 0xFF + } + return @bitcast(ptr) +} clear := fn(color: Color): void { n := 0 @@ -71,11 +72,11 @@ sync := fn(): void { return } -screen_width := fn(): int { +width := fn(): int { return fb_width } -screen_height := fn(): int { +height := fn(): int { return fb_height } @@ -186,14 +187,23 @@ put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { return } -set_screen_height := fn(new: int): void { +set_height := fn(new: int): void { 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 } init := fn(): void { + back_buffer = create_back_buffer() return } \ No newline at end of file diff --git a/sysdata/libraries/render/src/svga.hb b/sysdata/libraries/render/src/svga.hb index b1e9bf8..8d878c3 100644 --- a/sysdata/libraries/render/src/svga.hb +++ b/sysdata/libraries/render/src/svga.hb @@ -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") Color := struct {b: u8, g: u8, r: u8, a: u8} @@ -23,14 +23,18 @@ clear := fn(color: Color): void { return } -screen_width := fn(): int { +width := fn(): int { return 0 } -screen_height := fn(): int { +height := fn(): int { return 0 } +dimensions := fn(): IVec2 { + return .(0, 0) +} + put_pixel := fn(position: IVec2, color: Color): void { return } @@ -55,14 +59,33 @@ put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { return } -set_screen_height := fn(new: int): void { +set_height := fn(new: int): void { 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 } 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 } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index fa4414b..be4dac2 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -3,4 +3,5 @@ log := @use("rel:log.hb") memory := @use("rel:memory.hb") buffer := @use("rel:buffer.hb") math := @use("rel:math.hb") -random := @use("rel:random.hb") \ No newline at end of file +random := @use("rel:random.hb") +pci := @use("rel:pci.hb") \ No newline at end of file diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 0d25d87..7d4e71f 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -19,26 +19,26 @@ release_page := fn(ptr: ^u8, page_count: u8): void { outb := fn(addr: u16, value: u8): void { msg := "\0\0\0\0\0"; - *msg = 1; - *(msg + 1) = 0; + *@as(^u8, msg) = @as(u8, 1); + *@as(^u8, msg + 1) = @as(u8, 0); *@as(^u16, @bitcast(msg + 2)) = addr; - *(msg + 4) = value + *@as(^u8, msg + 4) = value @eca(void, 3, 3, msg, 5) return } inb := fn(addr: u16): u8 { msg := "\0\0\0\0"; - *msg = 0; - *(msg + 1) = 0; + *@as(^u8, msg) = @as(u8, 0); + *@as(^u8, msg + 1) = @as(u8, 0); *@as(^u16, @bitcast(msg + 2)) = addr return @eca(u8, 3, 3, msg, 4) } outl := fn(addr: u16, value: u32): void { msg := "\0\0\0\0\0\0\0\0"; - *msg = 1; - *(msg + 1) = 2; + *@as(^u8, msg) = @as(u8, 1); + *@as(^u8, msg + 1) = @as(u8, 2); *@as(^u16, @bitcast(msg + 2)) = addr; *@as(^u32, @bitcast(msg + 4)) = value @eca(void, 3, 3, msg, 8) @@ -47,8 +47,8 @@ outl := fn(addr: u16, value: u32): void { inl := fn(addr: u16): u32 { msg := "\0\0\0\0"; - *msg = 0; - *(msg + 1) = 2; + *@as(^u8, msg) = @as(u8, 0); + *@as(^u8, msg + 1) = @as(u8, 2); *@as(^u16, @bitcast(msg + 2)) = addr return @eca(u32, 3, 3, msg, 4) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/pci.hb b/sysdata/libraries/stn/src/pci.hb new file mode 100644 index 0000000..c07b518 --- /dev/null +++ b/sysdata/libraries/stn/src/pci.hb @@ -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)) +} \ No newline at end of file diff --git a/sysdata/programs/diskio_driver/src/main.hb b/sysdata/programs/diskio_driver/src/main.hb index 1800402..e5edf84 100644 --- a/sysdata/programs/diskio_driver/src/main.hb +++ b/sysdata/programs/diskio_driver/src/main.hb @@ -2,7 +2,7 @@ main := fn(): int { // shuts down ableOS - //memory.outb(0xF400, 0) + // memory.outb(0xF400, 0) a := memory.inb(0x4600) b := memory.inb(0x4700) diff --git a/sysdata/programs/render_example/src/examples/lines.hb b/sysdata/programs/render_example/src/examples/lines.hb index bd345f5..ff2953c 100644 --- a/sysdata/programs/render_example/src/examples/lines.hb +++ b/sysdata/programs/render_example/src/examples/lines.hb @@ -6,12 +6,13 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { render.clear(.(100, 50, 0, 255)) - width := render.screen_width() - height := render.screen_height() - p0 := render.IVec2.(0, 0 - 1) - p1 := render.IVec2.(0, height - 1) + width := render.width() + height := render.height() + p0 := render.IVec2.(0, 0) + p1 := render.IVec2.(0, height) loop if p0.y >= height break else { 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 p1.x += width >> 6 } diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 975387b..54b4416 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -6,8 +6,8 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { vel := render.IVec2.(1, 1) pos := render.IVec2.(100, 100) - width := render.screen_width() - height := render.screen_height() + width := render.width() + height := render.height() loop { render.put_rect(pos, .(100, 100), render.white) render.sync() diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 63d6390..052e1cf 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,4 +1,4 @@ -.{example} := @use("./examples/lines.hb") +.{example} := @use("./examples/square.hb") main := fn(): void { @inline(example) diff --git a/sysdata/programs/a_serial_driver/README.md b/sysdata/programs/serial_driver/README.md similarity index 100% rename from sysdata/programs/a_serial_driver/README.md rename to sysdata/programs/serial_driver/README.md diff --git a/sysdata/programs/a_serial_driver/meta.toml b/sysdata/programs/serial_driver/meta.toml similarity index 84% rename from sysdata/programs/a_serial_driver/meta.toml rename to sysdata/programs/serial_driver/meta.toml index 812e297..33de705 100644 --- a/sysdata/programs/a_serial_driver/meta.toml +++ b/sysdata/programs/serial_driver/meta.toml @@ -1,5 +1,5 @@ [package] -name = "a_serial_driver" +name = "serial_driver" authors = ["Able"] [dependants.libraries] diff --git a/sysdata/programs/a_serial_driver/src/main.hb b/sysdata/programs/serial_driver/src/main.hb similarity index 90% rename from sysdata/programs/a_serial_driver/src/main.hb rename to sysdata/programs/serial_driver/src/main.hb index c98054f..4cb3f11 100644 --- a/sysdata/programs/a_serial_driver/src/main.hb +++ b/sysdata/programs/serial_driver/src/main.hb @@ -1,5 +1,4 @@ -stn := @use("../../../libraries/stn/src/lib.hb"); -.{log, string, memory, buffer} := stn +.{memory, buffer} := @use("../../../libraries/stn/src/lib.hb") serial_print := fn(ptr: ^u8): void { letter := 0 diff --git a/sysdata/programs/serial_driver_test/src/main.hb b/sysdata/programs/serial_driver_test/src/main.hb index a9af0fa..6893bc2 100644 --- a/sysdata/programs/serial_driver_test/src/main.hb +++ b/sysdata/programs/serial_driver_test/src/main.hb @@ -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 { a := buffer.search("XNumber\0") diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 52fb187..380f791 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -20,11 +20,11 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.tests] # path = "boot:///tests.hbf" -[boot.limine.ableos.modules.0render_driver] +[boot.limine.ableos.modules.1render_driver] path = "boot:///render_driver.hbf" -[boot.limine.ableos.modules.a_serial_driver] -path = "boot:///a_serial_driver.hbf" +[boot.limine.ableos.modules.0serial_driver] +path = "boot:///serial_driver.hbf" [boot.limine.ableos.modules.diskio_driver] path = "boot:///diskio_driver.hbf"