From 9523507f1b38086d0c70fed0313e4afb22068f87 Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 30 Mar 2023 01:31:55 -0500 Subject: [PATCH] work on driver layout and STD lib --- Cargo.lock | 8 ++++ Cargo.toml | 3 ++ .../audio/pc_beeper_driver/.cargo/config.toml | 2 + drivers/audio/pc_beeper_driver/Cargo.toml | 8 ++++ drivers/audio/pc_beeper_driver/src/main.rs | 7 ++++ libraries/able_graphics_library/src/lib.rs | 1 + .../src/raw_pixel/lib.rs | 1 - .../src/raw_pixel/mod.rs | 18 +++++++++ libraries/audio_interface/Cargo.toml | 8 ++++ libraries/audio_interface/src/lib.rs | 38 +++++++++++++++++++ libraries/std/src/entry.rs | 12 +++--- libraries/std/src/env.rs | 9 +++++ libraries/std/src/io.rs | 12 ++++++ libraries/std/src/lib.rs | 18 +++++++++ libraries/std/src/panic.rs | 15 +++++++- libraries/std/src/prelude/rust_2021/mod.rs | 1 + programs/std_test/run.sh | 2 +- programs/std_test/src/main.rs | 10 +++++ 18 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 drivers/audio/pc_beeper_driver/.cargo/config.toml create mode 100644 drivers/audio/pc_beeper_driver/Cargo.toml create mode 100644 drivers/audio/pc_beeper_driver/src/main.rs delete mode 100644 libraries/able_graphics_library/src/raw_pixel/lib.rs create mode 100644 libraries/able_graphics_library/src/raw_pixel/mod.rs create mode 100644 libraries/audio_interface/Cargo.toml create mode 100644 libraries/audio_interface/src/lib.rs create mode 100644 libraries/std/src/env.rs create mode 100644 libraries/std/src/io.rs diff --git a/Cargo.lock b/Cargo.lock index 72d16c4..5ac3906 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,10 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +[[package]] +name = "audio_interface" +version = "0.1.0" + [[package]] name = "base64" version = "0.13.1" @@ -224,6 +228,10 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "pc_beeper_driver" +version = "0.1.0" + [[package]] name = "proc-macro2" version = "1.0.47" diff --git a/Cargo.toml b/Cargo.toml index df72a9f..2aef1a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ members = [ "drivers/basic_driver", "drivers/randomness_handler", + "drivers/audio/pc_beeper_driver", + "drivers/graphics/derelict_microarchitecture", "drivers/graphics/ground", "drivers/graphics/novideo", @@ -13,6 +15,7 @@ members = [ "drivers/mice/ps2_mouse", "libraries/able_graphics_library", + "libraries/audio_interface", "libraries/clparse", "libraries/cryptography", "libraries/locale-maxima", diff --git a/drivers/audio/pc_beeper_driver/.cargo/config.toml b/drivers/audio/pc_beeper_driver/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/drivers/audio/pc_beeper_driver/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/drivers/audio/pc_beeper_driver/Cargo.toml b/drivers/audio/pc_beeper_driver/Cargo.toml new file mode 100644 index 0000000..a95cdf1 --- /dev/null +++ b/drivers/audio/pc_beeper_driver/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pc_beeper_driver" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/drivers/audio/pc_beeper_driver/src/main.rs b/drivers/audio/pc_beeper_driver/src/main.rs new file mode 100644 index 0000000..cc04b80 --- /dev/null +++ b/drivers/audio/pc_beeper_driver/src/main.rs @@ -0,0 +1,7 @@ +#![no_std] +#![no_main] + +#[no_mangle] +fn start() { + // Simple driver +} diff --git a/libraries/able_graphics_library/src/lib.rs b/libraries/able_graphics_library/src/lib.rs index a61cfdc..5bfb6a0 100644 --- a/libraries/able_graphics_library/src/lib.rs +++ b/libraries/able_graphics_library/src/lib.rs @@ -9,6 +9,7 @@ pub mod color; pub mod cursor; pub mod engine3d; pub mod ptmode; +pub mod raw_pixel; pub const VERSION: versioning::Version = versioning::Version { major: 0, diff --git a/libraries/able_graphics_library/src/raw_pixel/lib.rs b/libraries/able_graphics_library/src/raw_pixel/lib.rs deleted file mode 100644 index 0519ecb..0000000 --- a/libraries/able_graphics_library/src/raw_pixel/lib.rs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/libraries/able_graphics_library/src/raw_pixel/mod.rs b/libraries/able_graphics_library/src/raw_pixel/mod.rs new file mode 100644 index 0000000..f8c5e66 --- /dev/null +++ b/libraries/able_graphics_library/src/raw_pixel/mod.rs @@ -0,0 +1,18 @@ +use alloc::vec::Vec; + +pub struct Color { + r: u8, + g: u8, + b: u8, + a: u8, +} + +pub struct PixelBuffer { + width: usize, + height: usize, + data: Vec, +} +impl PixelBuffer { + pub fn xy_calc(x: usize, y: isize) {} + pub fn blit(&mut self, x: isize, y: isize, buff: PixelBuffer) {} +} diff --git a/libraries/audio_interface/Cargo.toml b/libraries/audio_interface/Cargo.toml new file mode 100644 index 0000000..50cb4fc --- /dev/null +++ b/libraries/audio_interface/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "audio_interface" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/libraries/audio_interface/src/lib.rs b/libraries/audio_interface/src/lib.rs new file mode 100644 index 0000000..36bb60b --- /dev/null +++ b/libraries/audio_interface/src/lib.rs @@ -0,0 +1,38 @@ +pub struct AudioObject { + // Play one bit per this interval + playback_speed: u64, + playback_ring: [u8; 2048], + paused: bool, +} +impl AudioInterface for AudioObject { + fn pause(&mut self) -> Result<(), AudioErrors> { + self.paused = true; + Ok(()) + } + + fn play() -> Result<(), AudioErrors> { + todo!() + } + + fn stop() -> Result<(), AudioErrors> { + todo!() + } + + fn fill_playback_buffer(&mut self, playback_slice: [u8; 128]) -> Result<(), AudioErrors> { + todo!() + } +} + +pub enum AudioErrors { + EmptyPlaybackBuffer, +} + +pub trait AudioInterface { + fn pause(&mut self) -> Result<(), AudioErrors>; + fn play() -> Result<(), AudioErrors>; + + // Stop will clear the buffer and stop playback + fn stop() -> Result<(), AudioErrors>; + + fn fill_playback_buffer(&mut self, playback_slice: [u8; 128]) -> Result<(), AudioErrors>; +} diff --git a/libraries/std/src/entry.rs b/libraries/std/src/entry.rs index 7a485ab..3431b5f 100644 --- a/libraries/std/src/entry.rs +++ b/libraries/std/src/entry.rs @@ -10,12 +10,12 @@ unsafe extern "C" fn _start() -> ! { main(0, core::ptr::null()); - asm!( - "syscall", - in("rax") 60, - in("rdi") 0, - options(noreturn) - ); + // asm!( + // "syscall", + // in("rax") 60, + // in("rdi") 0, + // options(noreturn) + // ); } #[lang = "start"] diff --git a/libraries/std/src/env.rs b/libraries/std/src/env.rs new file mode 100644 index 0000000..b87c16a --- /dev/null +++ b/libraries/std/src/env.rs @@ -0,0 +1,9 @@ +pub struct Args { + pub inner: [u8; 10], +} + +pub fn args() -> Args { + Args { + inner: [65, 66, 65, 66, 65, 65, 66, 65, 66, 65], + } +} diff --git a/libraries/std/src/io.rs b/libraries/std/src/io.rs new file mode 100644 index 0000000..78fee16 --- /dev/null +++ b/libraries/std/src/io.rs @@ -0,0 +1,12 @@ +pub enum IOErrors { + UnknownError, +} + +pub struct Port { + inner: T, +} +impl Port { + pub fn read(&self) -> Result { + Ok(self.inner) + } +} diff --git a/libraries/std/src/lib.rs b/libraries/std/src/lib.rs index cc3229a..9f3fb9b 100644 --- a/libraries/std/src/lib.rs +++ b/libraries/std/src/lib.rs @@ -3,6 +3,8 @@ #![no_std] mod entry; +pub mod env; +pub mod io; pub mod panic; use core::arch::asm; @@ -31,3 +33,19 @@ pub fn print(s: &str) { ); } } + +pub fn print_char(c: char) { + let array = [c]; + + unsafe { + asm!( + "syscall", + in("rax") 1, + in("rdi") 1, + in("rsi") array.as_ptr(), + in("rdx") 1, + out("rcx") _, + out("r11") _, + ); + } +} diff --git a/libraries/std/src/panic.rs b/libraries/std/src/panic.rs index ebbb3d8..ad2c3f2 100644 --- a/libraries/std/src/panic.rs +++ b/libraries/std/src/panic.rs @@ -1,5 +1,18 @@ +use core::arch::asm; + #[panic_handler] fn panic_handler(pinfo: &core::panic::PanicInfo) -> ! { - print("PANIC!"); + print("PANIC!\n"); + + // #[cfg(unix)] + unsafe { + asm!( + "syscall", + in("rax") 231, + in("rdi") 1, + options(noreturn) + ); + } + loop {} } diff --git a/libraries/std/src/prelude/rust_2021/mod.rs b/libraries/std/src/prelude/rust_2021/mod.rs index 5d1ac95..32d3435 100644 --- a/libraries/std/src/prelude/rust_2021/mod.rs +++ b/libraries/std/src/prelude/rust_2021/mod.rs @@ -1,6 +1,7 @@ pub use core::prelude::v1::*; pub use crate::print; +pub use crate::print_char; pub use core::panic; diff --git a/programs/std_test/run.sh b/programs/std_test/run.sh index da6ea62..ae07ffb 100755 --- a/programs/std_test/run.sh +++ b/programs/std_test/run.sh @@ -1,2 +1,2 @@ -cargo +nightly xbuild -p std_test --target std_test/bare-x86_64.json; +cargo +nightly xbuild -p std_test --target std_test/bare-x86_64.json && \ ../target/bare-x86_64/debug/std_test \ No newline at end of file diff --git a/programs/std_test/src/main.rs b/programs/std_test/src/main.rs index 6167b04..4464ace 100644 --- a/programs/std_test/src/main.rs +++ b/programs/std_test/src/main.rs @@ -1,4 +1,14 @@ +use std::{ + env::{self, args}, + print_char, +}; + fn main() { + for x in args().inner { + print_char(x as char); + } + print_char(b'\n' as char); + print("Hello, world!\n"); panic!("Broken");