From 6295a7118e9232754c941fe0c0919763e6712730 Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 30 Aug 2024 07:38:04 -0500 Subject: [PATCH 1/3] Added beef to ableOS --- Cargo.lock | 54 +++++++++++++++++++++++++++++++ dev/Cargo.toml | 1 + dev/src/idl/mod.rs | 20 ++++++++++++ dev/src/main.rs | 51 ++++++++++++++++++----------- sysdata/idl/abc/README.md | 1 + sysdata/idl/abc/src/protocol.aidl | 2 ++ 6 files changed, 111 insertions(+), 18 deletions(-) create mode 100644 dev/src/idl/mod.rs create mode 100644 sysdata/idl/abc/README.md create mode 100644 sysdata/idl/abc/src/protocol.aidl diff --git a/Cargo.lock b/Cargo.lock index b75962c28..77c8bf640 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,12 @@ version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bit" version = "0.1.1" @@ -248,6 +254,9 @@ dependencies = [ [[package]] name = "dev" version = "0.1.0" +dependencies = [ + "logos", +] [[package]] name = "embedded-graphics" @@ -638,6 +647,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0fc32485e41ae5e9dedd1442f36dec998431adc9f321224c2c5d645f38fdcb" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.149" @@ -665,6 +680,39 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "logos" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1ceb190eb9bdeecdd8f1ad6a71d6d632a50905948771718741b5461fb01e13" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90be66cb7bd40cb5cc2e9cfaf2d1133b04a3d93b72344267715010a466e0915a" +dependencies = [ + "beef", + "fnv", + "lazy_static", + "proc-macro2", + "quote", + "regex-syntax", + "syn 2.0.38", +] + +[[package]] +name = "logos-derive" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45154231e8e96586b39494029e58f12f8ffcb5ecf80333a603a13aa205ea8cbd" +dependencies = [ + "logos-codegen", +] + [[package]] name = "memchr" version = "2.6.4" @@ -803,6 +851,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "repbuild" version = "0.2.0" diff --git a/dev/Cargo.toml b/dev/Cargo.toml index 0cf2f73ca..9895777e5 100644 --- a/dev/Cargo.toml +++ b/dev/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +logos = "0.14.1" diff --git a/dev/src/idl/mod.rs b/dev/src/idl/mod.rs new file mode 100644 index 000000000..69b65238e --- /dev/null +++ b/dev/src/idl/mod.rs @@ -0,0 +1,20 @@ +use logos::Logos; + +#[derive(Logos, Debug, PartialEq)] +#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens +enum Token { + // Tokens can be literal strings, of any length. + #[token("protocol")] + Protocol, + + #[token(".")] + Period, + + // Or regular expressions. + #[regex("[a-zA-Z]+")] + Text, +} + +pub fn main() { + let mut lex = Token::lexer("Create ridiculously fast Lexers."); +} diff --git a/dev/src/main.rs b/dev/src/main.rs index 107e2c621..8e27d7224 100644 --- a/dev/src/main.rs +++ b/dev/src/main.rs @@ -1,4 +1,5 @@ -use std::{fmt::format, io::Write}; +use std::io::Write; +pub mod idl; pub enum Options { Build, @@ -6,6 +7,12 @@ pub enum Options { New, Run, } +#[derive(PartialEq)] +pub enum DevelopmentType { + Program, + Library, + IDL, +} fn main() { let mut args: Vec = std::env::args().collect(); @@ -24,29 +31,31 @@ fn main() { let binding = args.pop().unwrap(); let dev_type = binding.as_str(); let name = args.pop().unwrap(); + use DevelopmentType::*; match dev_type { - "lib" | "library" => new(true, name), - "prog" | "program" => new(false, name), + "lib" | "library" => new(Library, name), + "prog" | "program" => new(Program, name), + "idl" => { + new(IDL, name); + // idl::main(); + panic!("IDL is not finalized yet.") + } _ => {} }; } "run" => run(), - - "help" => { - // println!("This is the help message."); - // println!("A prototype build tool meant to help with ableOS software development."); - help() - } + "help" => help(), _ => { println!("Error"); } } } -pub fn new(library: bool, name: String) { - let (folder_hierarchy, entry_name) = match library { - true => ("libraries", "lib.hb"), - false => ("programs", "main.hb"), +pub fn new(development_type: DevelopmentType, name: String) { + let (folder_hierarchy, entry_name) = match development_type { + DevelopmentType::Program => ("programs", "main.hb"), + DevelopmentType::Library => ("libraries", "lib.hb"), + DevelopmentType::IDL => ("idl", "protocol.aidl"), }; let project_folder_path_string = format!("sysdata/{folder_hierarchy}/{name}"); @@ -66,18 +75,24 @@ pub fn new(library: bool, name: String) { let full_path_string = format!("{src_folder_path_string}/{entry_name}"); let mut file = std::fs::File::create(full_path_string.clone()).unwrap(); - let file_contents = if library { - "" - } else { - "main := fn(): int { + let file_contents = match development_type { + DevelopmentType::Program => "main := fn(): int { return 0 }" + .to_string(), + DevelopmentType::Library => "".to_string(), + DevelopmentType::IDL => format!( + "protocol {} {{ +}}", + name + ) + .to_owned(), } .to_string(); file.write_all(file_contents.as_bytes()).unwrap(); println!("New project created."); - if !library { + if development_type == DevelopmentType::Program { println!("You should add your project into the ableOS system configuration in sysdata/system_config.toml") } } diff --git a/sysdata/idl/abc/README.md b/sysdata/idl/abc/README.md new file mode 100644 index 000000000..bb36f3744 --- /dev/null +++ b/sysdata/idl/abc/README.md @@ -0,0 +1 @@ +# abc \ No newline at end of file diff --git a/sysdata/idl/abc/src/protocol.aidl b/sysdata/idl/abc/src/protocol.aidl new file mode 100644 index 000000000..b08bdcf1b --- /dev/null +++ b/sysdata/idl/abc/src/protocol.aidl @@ -0,0 +1,2 @@ +protocol abc { + } \ No newline at end of file From 0d3641e199bad25892761145ccf719ab980fe27e Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Fri, 26 Jul 2024 18:29:12 +0500 Subject: [PATCH 2/3] just getting started --- sysdata/programs/ps2_driver/README.md | 3 +++ sysdata/programs/ps2_driver/src/controller.hb | 0 sysdata/programs/ps2_driver/src/keyboard.hb | 0 sysdata/programs/ps2_driver/src/main.hb | 2 ++ 4 files changed, 5 insertions(+) create mode 100644 sysdata/programs/ps2_driver/README.md create mode 100644 sysdata/programs/ps2_driver/src/controller.hb create mode 100644 sysdata/programs/ps2_driver/src/keyboard.hb create mode 100644 sysdata/programs/ps2_driver/src/main.hb diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md new file mode 100644 index 000000000..96840d1e0 --- /dev/null +++ b/sysdata/programs/ps2_driver/README.md @@ -0,0 +1,3 @@ +# PS/2 Driver +This program is a simple driver to read keypresses from a PS/2 Keyboard +Also will contain an abstraction for the PS/2 controller in general so the Mouse code will probably also live here...maybe diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb new file mode 100644 index 000000000..e69de29bb diff --git a/sysdata/programs/ps2_driver/src/keyboard.hb b/sysdata/programs/ps2_driver/src/keyboard.hb new file mode 100644 index 000000000..e69de29bb diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb new file mode 100644 index 000000000..b5b3a7e88 --- /dev/null +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -0,0 +1,2 @@ +main:= fn(): int { +} From 161529753698f2020ead4fd6f87e36b40e71e415 Mon Sep 17 00:00:00 2001 From: Talha Qamar Date: Fri, 30 Aug 2024 18:03:12 +0500 Subject: [PATCH 3/3] Detecting keypresses --- sysdata/libraries/stn/src/buffer.hb | 4 +--- sysdata/programs/ps2_driver/meta.toml | 11 +++++++++ sysdata/programs/ps2_driver/src/main.hb | 31 ++++++++++++++++++++++++- sysdata/system_config.toml | 2 ++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 sysdata/programs/ps2_driver/meta.toml diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 1f5bb1734..f6e677980 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -4,9 +4,7 @@ receive_message := fn(buffer_id: int, memory_map_location: ^u8, length: int): ^u return @eca(^u8, 4, buffer_id, memory_map_location, length) } -send_message := fn(buffer_id: int): void { - message := "Hello there\0" - message_length := string.length(message) +send_message := fn(buffer_id: int, message: ^u8, message_length: int): void { @eca(i32, 3, buffer_id, message, message_length) return } diff --git a/sysdata/programs/ps2_driver/meta.toml b/sysdata/programs/ps2_driver/meta.toml new file mode 100644 index 000000000..0a2d770c9 --- /dev/null +++ b/sysdata/programs/ps2_driver/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "ps2_driver" +authors = ["Talha Qamar"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index b5b3a7e88..3f09a8e48 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,2 +1,31 @@ -main:= fn(): int { +.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb") + +send_byte := fn(byte: u8): u8 { + memory.outb(0, 96, byte) + input := memory.inb(0, 96) + return input } + +main := fn(): int { + log.info("PS/2 Driver Loaded\0") + if send_byte(238) == 238 { + log.info("PS/2 Keyboard Echoed\0") + } + if send_byte(244) == 250 { + log.info("Enabled scanning\0") + } + buf := buffer.create() + ptr := memory.request_page(1) + prev_input := 250 + loop { + input := memory.inb(0, 96) + if input == prev_input { + continue + } + prev_input = input + keycode_str := string.display_int(input, ptr) + log.info(string.display_int(buf)) + buffer.send_message(buf, keycode_str, string.length(keycode_str)) + } + return 0 +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index f0539ef83..b9668e464 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,6 +22,8 @@ resolution = "1024x768x24" [boot.limine.ableos.modules.a_serial_driver] path = "boot:///a_serial_driver.hbf" +[boot.limine.ableos.modules.ps2_driver] + path = "boot:///ps2_driver.hbf" [boot.limine.ableos.modules.diskio_driver] path = "boot:///diskio_driver.hbf"