From f33cc0bf7039f8530d690abfdbb758ff9ea71bf0 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 7 Jul 2024 08:35:07 -0500 Subject: [PATCH] did some stuff /shrug --- Cargo.lock | 6 +-- kernel/src/holeybytes/ecah.rs | 16 ++++++- repbuild/src/dev.rs | 12 +++++- sysdata/libraries/stn/src/buffer.hb | 20 +++++++++ sysdata/libraries/stn/src/lib.hb | 35 ++------------- sysdata/libraries/stn/src/log.hb | 15 +++++++ sysdata/libraries/stn/src/memory.hb | 18 ++++++++ sysdata/libraries/stn/src/string.hb | 8 ++++ sysdata/programs/fb_driver/src/main.hb | 27 ++++++------ sysdata/programs/tests/src/main.hb | 59 +++++++------------------- 10 files changed, 121 insertions(+), 95 deletions(-) create mode 100644 sysdata/libraries/stn/src/buffer.hb create mode 100644 sysdata/libraries/stn/src/log.hb create mode 100644 sysdata/libraries/stn/src/memory.hb create mode 100644 sysdata/libraries/stn/src/string.hb diff --git a/Cargo.lock b/Cargo.lock index da30e1309..46efea333 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,7 +429,7 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#59705c062dbd0eeeaf2feb4a76230a393672c646" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#efa7271a5917c9b78ed06563df2bea13f895f8ca" [[package]] name = "hbbytecode" @@ -439,7 +439,7 @@ source = "git+https://git.ablecorp.us/ableos/holey-bytes#e494785f93dad2722ebd9e5 [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#59705c062dbd0eeeaf2feb4a76230a393672c646" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#efa7271a5917c9b78ed06563df2bea13f895f8ca" dependencies = [ "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -447,7 +447,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#59705c062dbd0eeeaf2feb4a76230a393672c646" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#efa7271a5917c9b78ed06563df2bea13f895f8ca" dependencies = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 827c42b1b..c42423dfc 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -116,11 +116,25 @@ pub fn handler(vm: &mut Vm) { } 4 => { let buffer_id = vm.registers[3].cast::(); + let mut map_ptr = vm.registers[4].cast::(); + let max_length = vm.registers[5].cast::(); let mut buffs = IPC_BUFFERS.lock(); let mut buff = buffs.get_mut(&buffer_id).unwrap(); let msg = buff.pop(); - info!("Recieve {:?} from Buffer({})", msg, buffer_id); + if msg.len() > max_length.try_into().unwrap() { + info!("{}", max_length); + error!("Message is too long to map in."); + } else { + unsafe { + let ptr: *mut u64 = &mut map_ptr; + for (index, byte) in msg.iter().enumerate() { + ptr.offset(index.try_into().unwrap()).write_bytes(*byte, 1); + } + } + + info!("Recieve {:?} from Buffer({})", msg, buffer_id); + } } 5 => { #[cfg(target_arch = "x86_64")] diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index 2978cd467..967e84c05 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -5,7 +5,7 @@ use std::{ process::exit, }; -use error_stack::Report; +use {error_stack::Report, hblang::Options}; use crate::Error; pub struct Package { @@ -69,8 +69,16 @@ impl Package { let path = format!("sysdata/programs/{}/{}", self.name, file); let mut bytes = Vec::new(); // compile here - let _ = hblang::run_compiler(&path, Default::default(), &mut bytes); + // let _ = hblang::run_compiler( + // &path, + // Options { + // fmt: true, + // ..Default::default() + // }, + // &mut bytes, + // ); + let _ = hblang::run_compiler(&path, Default::default(), &mut bytes); match std::fs::create_dir("target/programs") { Ok(_) => (), Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => (), diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb new file mode 100644 index 000000000..81cb995be --- /dev/null +++ b/sysdata/libraries/stn/src/buffer.hb @@ -0,0 +1,20 @@ +string := @use("rel:string.hb"); + +receive_message := fn(buffer_id: int, memory_map_location: ^u8, length: int): ^u8 { + return @eca(void, 4, buffer_id, memory_map_location, length); +} + +send_message := fn(buffer_id: int): void { + message := "Hello there\0"; + message_length := string.length(message); + + @eca(i32, 3, buffer_id, message, message_length); + return; +} + +create := fn(): int { + msg := "\{01}Number\0"; + msg_length := string.length(msg); + *msg = 0; + return @eca(int, 1, 0, msg, msg_length); +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 16e861865..fe530ec1b 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -1,31 +1,4 @@ -char := struct {} - - -log := fn(log_level: int, message: ^char, message_length: int): int { - @eca(i32,1, 1, 1) - return 0; -} - -error := fn(message: ^char, message_length: int): int { - log(0, message, message_length) -} - -warn := fn(message: ^char, message_length: int): int { - log(1, message, message_length) -} - -info := fn(message: ^char, message_length: int): int { - log(2, message, message_length) -} - -debug := fn(message: ^char, message_length: int): int { - log(3, message, message_length) -} - -trace := fn(message: ^char, message_length: int): int { - log(4, message, message_length) -} - -test := fn(): int { - @eca(i32, 1, 1, 1); -} +string := @use("rel:string.hb"); +log := @use("rel:log.hb"); +memory := @use("rel:memory.hb"); +buffer := @use("rel:buffer.hb"); \ No newline at end of file diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb new file mode 100644 index 000000000..7028346f7 --- /dev/null +++ b/sysdata/libraries/stn/src/log.hb @@ -0,0 +1,15 @@ +string := @use("rel:string.hb"); + +log := fn(message: ^u8, level: u8): void { + message_length := string.length(message); + *(message + message_length) = level; + + @eca(i32, 3, 1, message, message_length + 1); + return; +} + +error:= fn(message: ^u8):void return log(message, 0); +warn:= fn(message: ^u8):void return log(message, 1); +info:= fn(message: ^u8):void return log(message, 2); +debug:= fn(message: ^u8):void return log(message, 3); +trace:= fn(message: ^u8):void return log(message, 4); \ No newline at end of file diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb new file mode 100644 index 000000000..1357cf833 --- /dev/null +++ b/sysdata/libraries/stn/src/memory.hb @@ -0,0 +1,18 @@ +request_page := fn(page_count: u8): ^u8 { + msg := "\{00}\{01}xxxxxxxx\0"; + msg_page_count := msg + 1; + *msg_page_count = page_count; + return @eca(^u8, 3, 2, msg, 12); +} + +release_page := fn(ptr: ^u8, page_count: u8): void { + msg := "\{01}\{00}xxxxxxxx\0"; + + msg_page_count := msg + 1; + *msg_page_count = page_count; + + msg_ptr := @as(^^u8, @bitcast(msg+2)); + *msg_ptr = ptr; + + return @eca(void, 3, 2, msg, 12); +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb new file mode 100644 index 000000000..3ee31a618 --- /dev/null +++ b/sysdata/libraries/stn/src/string.hb @@ -0,0 +1,8 @@ +length := fn(ptr: ^u8): int { + len := 0; + loop if *ptr == 0 break else { + len += 1; + ptr += 1; + } + return len; +} \ No newline at end of file diff --git a/sysdata/programs/fb_driver/src/main.hb b/sysdata/programs/fb_driver/src/main.hb index 1b1d3cf8e..4233b2c3e 100644 --- a/sysdata/programs/fb_driver/src/main.hb +++ b/sysdata/programs/fb_driver/src/main.hb @@ -1,16 +1,15 @@ - main := fn(): int { - frame_buffer := @as(^u32, @bitcast(18446603339442421760)); - color := 0; - loop { - len := 786432*4; - loop if len == 0 break else { - fb := frame_buffer + @as(^u32, @bitcast(len)); - *fb = color; - len -= 1; - color += 100; - } - } - return 0; + frame_buffer := @as(^u8, @bitcast(18446603339442421760)); + color := 17; + + loop { + len := (786432 * 4)+1; + loop if len == 0 break else { + fb := frame_buffer + len; + *fb = color; + len = len - 1; + color += len; + } + } + return 0; } - diff --git a/sysdata/programs/tests/src/main.hb b/sysdata/programs/tests/src/main.hb index 4b97588d3..277e4b846 100644 --- a/sysdata/programs/tests/src/main.hb +++ b/sysdata/programs/tests/src/main.hb @@ -1,49 +1,20 @@ -log := fn(message: ^u8, level: u8): void { - message_2 := message; - len := 0; - loop if *message_2 == 0 { - *message_2 = level; - break - } else { - len += 1; - message_2 += 1; - } - len += 1; - - @eca(i32, 3, 1, message, len); - return; -} - -error:= fn(message: ^u8):void return log(message, 0); -warn:= fn(message: ^u8):void return log(message, 1); -info:= fn(message: ^u8):void return log(message, 2); -debug:= fn(message: ^u8):void return log(message, 3); -trace:= fn(message: ^u8):void return log(message, 4); - - -request_mem_page := fn(page_count: u8): ^u8 { - msg := "\{00}\{01}xxxxxxxx\0"; - msg_mem_page_count := msg + 1; - *msg_mem_page_count = page_count; - return @eca(^u8, 3, 2, msg, 12); -} - -release_mem_page := fn(ptr: ^u8, page_count: u8): void { - msg := "\{01}\{00}xxxxxxxx\0"; - - msg_mem_page_count := msg + 1; - *msg_mem_page_count = page_count; - - msg_mem_ptr := @as(^^u8, @bitcast(msg+2)); - *msg_mem_ptr = ptr; - - a := @eca(void, 3, 2, msg, 12); - return; -} +stn := @use("../../../libraries/stn/src/lib.hb"); +log := stn.log; +string := stn.string; +memory := stn.memory; +buffer := stn.buffer; main := fn(): int { - buffer := request_mem_page(3); - release_mem_page(buffer, 3); + // Create a buffer + buffer_id := buffer.create(); + buffer.send_message(buffer_id); + + memory_pages := memory.request_page(3); + buffer.receive_message(buffer_id, memory_pages, 4096*3); + + log.info("abc\0"); + + memory.release_page(memory_pages, 3); return 0; } \ No newline at end of file