From 5c4056bc5cd5e6dc95104d708c2bbb2cd669d266 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 10:00:24 -0600 Subject: [PATCH 01/22] commit checkpoint --- Cargo.lock | 6 +- repbuild/src/main.rs | 2 +- .../libraries/stn/src/alloc/alloc_return.hb | 4 + .../libraries/stn/src/alloc/block_alloc.hb | 73 +++++++++++++++++++ sysdata/libraries/stn/src/alloc/fake_alloc.hb | 22 ++++++ sysdata/libraries/stn/src/alloc/lib.hb | 2 + sysdata/libraries/stn/src/alloc/main.hb | 25 +++++++ sysdata/libraries/stn/src/lib.hb | 2 + sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 20 ++--- 10 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 sysdata/libraries/stn/src/alloc/alloc_return.hb create mode 100644 sysdata/libraries/stn/src/alloc/block_alloc.hb create mode 100644 sysdata/libraries/stn/src/alloc/fake_alloc.hb create mode 100644 sysdata/libraries/stn/src/alloc/lib.hb create mode 100644 sysdata/libraries/stn/src/alloc/main.hb diff --git a/Cargo.lock b/Cargo.lock index baaf1a605..45ec40178 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#86ca959ea3eae1cb32298e135a444820583d24a0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" dependencies = [ "hbbytecode", ] diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 5a80bf499..8d63c2dd8 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -485,7 +485,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { #[rustfmt::skip] com.args([ "-M", "virt", - "-cpu", "neoverse-n2", + "-cpu", "max", "-device", "ramfb", "-device", "qemu-xhci", "-device", "usb-kbd", diff --git a/sysdata/libraries/stn/src/alloc/alloc_return.hb b/sysdata/libraries/stn/src/alloc/alloc_return.hb new file mode 100644 index 000000000..e32bd1aac --- /dev/null +++ b/sysdata/libraries/stn/src/alloc/alloc_return.hb @@ -0,0 +1,4 @@ +AllocReturn := struct { + byte_count: uint, + ptr: ?^u8, +} diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb new file mode 100644 index 000000000..34aba7a02 --- /dev/null +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -0,0 +1,73 @@ +alloc_return := @use("alloc_return.hb") + +/* the block size is 64 bytes, 64 blocks of 64 bytes. + this will very quickly lead to exhaustion of free blocks. +*/ +BlockAlloc := struct { + state := uint, + ptr := ^u8, + + $init := fn(): Self{ + // request a kernel page + // ptr := memory.alloc(1) + return .(0, null) + } + + + // $alloc := fn(self: Self, alloc_type: Type, count: uint): alloc_return.AllocReturn { + // offset := 0 + // a := 0 + // loop { + // a = self.state << offset; + // // check if the `offset` bit is 1, if it is move to the next offset + // if a == 1 { + // offset += 1 + // } else { + // // self it to 1 and return the ptr to the allocation + // self.state |= a + // return (ptr + (offset * 64)) + // } + // // there are only 64 blocks + // if offset >= 64 { + // break; + // } + // } + // return null + // } + + // $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint): void { + // size := size_of(alloc_type)*count + // // get the size alligned to the nearest block + // rounded_size := nearest_block_size_rounded_up(size) + + + // state_bit_start := { + // // Do math here to figure out what starting ptr corresponds to what bit + // 3 + // } + + // offset := 0 + + // loop { + // if rounded_size > 0 { + // // set state_bit_start+offset to 0 + + + // // at the end move to the next one + // offset += 1 + // } else { + // break; + // } + + // rounded_size -= 64 + // } + + // return void + // } + + // $deinit := fn(&self): void { + // self.state := 0 + + + // } +} diff --git a/sysdata/libraries/stn/src/alloc/fake_alloc.hb b/sysdata/libraries/stn/src/alloc/fake_alloc.hb new file mode 100644 index 000000000..5b2e74c65 --- /dev/null +++ b/sysdata/libraries/stn/src/alloc/fake_alloc.hb @@ -0,0 +1,22 @@ +alloc_return := @use("alloc_return.hb") + + +FakeAlloc := struct { + $init := fn():Self{ + return .() + } + + $alloc := fn(&self, alloc_type: Type, count: uint): alloc_return.AllocReturn { + return .(0, null) + } + + $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint) : void{ + return void + } + // Nothing to clean up here + $deinit := fn(&self): void { + return void + } +} + + diff --git a/sysdata/libraries/stn/src/alloc/lib.hb b/sysdata/libraries/stn/src/alloc/lib.hb new file mode 100644 index 000000000..a05698f10 --- /dev/null +++ b/sysdata/libraries/stn/src/alloc/lib.hb @@ -0,0 +1,2 @@ +// .{FakeAlloc} := @use("fake_alloc.hb") +.{BlockAlloc} := @use("block_alloc.hb") diff --git a/sysdata/libraries/stn/src/alloc/main.hb b/sysdata/libraries/stn/src/alloc/main.hb new file mode 100644 index 000000000..138d53c43 --- /dev/null +++ b/sysdata/libraries/stn/src/alloc/main.hb @@ -0,0 +1,25 @@ +allocators := @use("alloc/alloc.hb") + +AStruct := struct { + a_field: u8, +} + +main := fn():void{ + alloc := allocators.FakeAlloc.init() + astruct := alloc.alloc(AStruct, 2) + if astruct.ptr != null{ + panic("FakeAlloc actually allocated.") + } + alloc.dealloc(astruct_ptr, AStruct, 2) + alloc.deinit() + + balloc := allocators.BlockAlloc.init() + bstruct_ptr := balloc.alloc(AStruct, 2) + if bstruct_ptr == null { + panic("BlockAlloc actually didn't allocate.") + } + balloc.dealloc(bstruct_ptr, AStruct, 2) + balloc.deinit() + + +} diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 961037cb9..538e77862 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -1,4 +1,5 @@ acs := @use("acs.hb") +alloc := @use("alloc/lib.hb") string := @use("string.hb") log := @use("log.hb") memory := @use("memory.hb") @@ -9,6 +10,7 @@ file := @use("file_io.hb") dt := @use("dt.hb") process := @use("process.hb") + panic := fn(message: ?^u8): never { log.error("Error: Panic Called, Message:\0") if message == null { diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 77cb04c04..ab66cfa82 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1 +1 @@ -.{example: main} := @use("./examples/text.hb") \ No newline at end of file +.{example: main} := @use("./examples/orbit.hb") \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 530c98a7b..a7b849e0d 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,26 +22,26 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] -# [boot.limine.ableos.modules.render_example] -# path = "boot:///render_example.hbf" +[boot.limine.ableos.modules.render_example] +path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] +# path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.sunset_client] -path = "boot:///sunset_client.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" -[boot.limine.ableos.modules.sunset_client_2] -path = "boot:///sunset_client_2.hbf" +# [boot.limine.ableos.modules.sunset_client_2] +# path = "boot:///sunset_client_2.hbf" -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" # [boot.limine.ableos.modules.processes] # path = "boot:///processes.hbf" From 241139f5af5594d62932f6e052f852036fa583ff Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 10:18:09 -0600 Subject: [PATCH 02/22] changes --- .../libraries/stn/src/alloc/alloc_return.hb | 6 +- .../libraries/stn/src/alloc/block_alloc.hb | 132 +++++++++--------- sysdata/libraries/stn/src/alloc/fake_alloc.hb | 6 +- sysdata/libraries/stn/src/alloc/lib.hb | 4 +- sysdata/libraries/stn/src/lib.hb | 3 +- sysdata/programs/alloc_test/README.md | 1 + sysdata/programs/alloc_test/meta.toml | 11 ++ sysdata/programs/alloc_test/src/main.hb | 25 ++++ sysdata/system_config.toml | 7 +- 9 files changed, 118 insertions(+), 77 deletions(-) create mode 100644 sysdata/programs/alloc_test/README.md create mode 100644 sysdata/programs/alloc_test/meta.toml create mode 100644 sysdata/programs/alloc_test/src/main.hb diff --git a/sysdata/libraries/stn/src/alloc/alloc_return.hb b/sysdata/libraries/stn/src/alloc/alloc_return.hb index e32bd1aac..bdc61f518 100644 --- a/sysdata/libraries/stn/src/alloc/alloc_return.hb +++ b/sysdata/libraries/stn/src/alloc/alloc_return.hb @@ -1,4 +1,4 @@ AllocReturn := struct { - byte_count: uint, - ptr: ?^u8, -} + byte_count: uint, + ptr: ?^u8, +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb index 34aba7a02..7cd29c6b6 100644 --- a/sysdata/libraries/stn/src/alloc/block_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -4,70 +4,72 @@ alloc_return := @use("alloc_return.hb") this will very quickly lead to exhaustion of free blocks. */ BlockAlloc := struct { - state := uint, - ptr := ^u8, + state: uint, + ptr: ?^u8, - $init := fn(): Self{ - // request a kernel page - // ptr := memory.alloc(1) - return .(0, null) - } - - - // $alloc := fn(self: Self, alloc_type: Type, count: uint): alloc_return.AllocReturn { - // offset := 0 - // a := 0 - // loop { - // a = self.state << offset; - // // check if the `offset` bit is 1, if it is move to the next offset - // if a == 1 { - // offset += 1 - // } else { - // // self it to 1 and return the ptr to the allocation - // self.state |= a - // return (ptr + (offset * 64)) - // } - // // there are only 64 blocks - // if offset >= 64 { - // break; - // } - // } - // return null - // } - - // $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint): void { - // size := size_of(alloc_type)*count - // // get the size alligned to the nearest block - // rounded_size := nearest_block_size_rounded_up(size) - - - // state_bit_start := { - // // Do math here to figure out what starting ptr corresponds to what bit - // 3 - // } - - // offset := 0 - - // loop { - // if rounded_size > 0 { - // // set state_bit_start+offset to 0 - - - // // at the end move to the next one - // offset += 1 - // } else { - // break; - // } - - // rounded_size -= 64 - // } - - // return void - // } - - // $deinit := fn(&self): void { - // self.state := 0 - - - // } + $init := fn(): Self { + return .(0, null) + } } + +// $alloc := fn(self: Self, alloc_type: Type, count: uint): alloc_return.AllocReturn { +// offset := 0 +// a := 0 +// loop { +// a = self.state << offset; +// // check if the `offset` bit is 1, if it is move to the next offset +// if a == 1 { +// offset += 1 +// } else { +// // self it to 1 and return the ptr to the allocation +// self.state |= a +// return (ptr + (offset * 64)) +// } +// // there are only 64 blocks +// if offset >= 64 { +// break; +// } +// } +// return null +// } + + + +// request a kernel page +// ptr := memory.alloc(1) + + + +// $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint): void { +// size := size_of(alloc_type)*count +// // get the size alligned to the nearest block +// rounded_size := nearest_block_size_rounded_up(size) + +// state_bit_start := { +// // Do math here to figure out what starting ptr corresponds to what bit +// 3 +// } + +// offset := 0 + +// loop { +// if rounded_size > 0 { +// // set state_bit_start+offset to 0 + +// // at the end move to the next one +// offset += 1 +// } else { +// break; +// } + +// rounded_size -= 64 +// } + +// return void +// } + +// $deinit := fn(&self): void { +// self.state := 0 + +// } +// } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/alloc/fake_alloc.hb b/sysdata/libraries/stn/src/alloc/fake_alloc.hb index 5b2e74c65..a7ccd76fc 100644 --- a/sysdata/libraries/stn/src/alloc/fake_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/fake_alloc.hb @@ -6,15 +6,15 @@ FakeAlloc := struct { return .() } - $alloc := fn(&self, alloc_type: Type, count: uint): alloc_return.AllocReturn { + $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { return .(0, null) } - $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint) : void{ + $dealloc := fn(self: Self, ptr: ^u8, alloc_type: Type, count: uint) : void{ return void } // Nothing to clean up here - $deinit := fn(&self): void { + $deinit := fn(self: Self): void { return void } } diff --git a/sysdata/libraries/stn/src/alloc/lib.hb b/sysdata/libraries/stn/src/alloc/lib.hb index a05698f10..f80a36190 100644 --- a/sysdata/libraries/stn/src/alloc/lib.hb +++ b/sysdata/libraries/stn/src/alloc/lib.hb @@ -1,2 +1,2 @@ -// .{FakeAlloc} := @use("fake_alloc.hb") -.{BlockAlloc} := @use("block_alloc.hb") +.{BlockAlloc} := @use("block_alloc.hb"); +.{FakeAlloc} := @use("fake_alloc.hb") \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 538e77862..d90217b66 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -1,5 +1,5 @@ acs := @use("acs.hb") -alloc := @use("alloc/lib.hb") +allocators := @use("alloc/lib.hb") string := @use("string.hb") log := @use("log.hb") memory := @use("memory.hb") @@ -10,7 +10,6 @@ file := @use("file_io.hb") dt := @use("dt.hb") process := @use("process.hb") - panic := fn(message: ?^u8): never { log.error("Error: Panic Called, Message:\0") if message == null { diff --git a/sysdata/programs/alloc_test/README.md b/sysdata/programs/alloc_test/README.md new file mode 100644 index 000000000..560819442 --- /dev/null +++ b/sysdata/programs/alloc_test/README.md @@ -0,0 +1 @@ +# alloc_test \ No newline at end of file diff --git a/sysdata/programs/alloc_test/meta.toml b/sysdata/programs/alloc_test/meta.toml new file mode 100644 index 000000000..aa77119fd --- /dev/null +++ b/sysdata/programs/alloc_test/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "alloc_test" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/alloc_test/src/main.hb b/sysdata/programs/alloc_test/src/main.hb new file mode 100644 index 000000000..7b4a7dcd2 --- /dev/null +++ b/sysdata/programs/alloc_test/src/main.hb @@ -0,0 +1,25 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{allocators, panic} := stn + +AStruct := struct { + a_field: u8, +} + +main := fn(): void { + alloc := allocators.FakeAlloc.init() + astruct := alloc.alloc(AStruct, 2) + // if astruct.ptr != null{ + // panic.panic("FakeAlloc actually allocated.") + // } + // alloc.dealloc(&astruct.ptr, AStruct, 2) + alloc.deinit() + + // balloc := allocators.BlockAlloc.init() + // bstruct_ptr := balloc.alloc(AStruct, 2) + // if bstruct_ptr == null { + // panic("BlockAlloc actually didn't allocate.") + // } + // balloc.dealloc(bstruct_ptr, AStruct, 2) + // balloc.deinit() + return +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index a7b849e0d..182c3dedc 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,8 +22,8 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] -[boot.limine.ableos.modules.render_example] -path = "boot:///render_example.hbf" +# [boot.limine.ableos.modules.render_example] +# path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" @@ -45,3 +45,6 @@ path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.processes] # path = "boot:///processes.hbf" + +# [boot.limine.ableos.modules.alloc_test] +# path = "boot:///alloc_test.hbf" \ No newline at end of file From 5ea3ee9fe1c0c51fa21ede66ad48b63d4d489373 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sun, 24 Nov 2024 16:39:24 +0000 Subject: [PATCH 03/22] able sanity check --- kernel/src/kmain.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 625b9cd7e..fdd670094 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -22,12 +22,13 @@ use { pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { debug!("Entered kmain"); - #[cfg(feature = "ktest")] { + #[cfg(feature = "ktest")] + { use crate::ktest; debug!("TESTING"); ktest::test_main(); - loop {}; + loop {} } // let kcmd = build_cmd("Kernel Command Line", cmdline); @@ -131,7 +132,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { executor.run(); }; - + log::info!("Started AbleOS"); crate::arch::spin_loop() } From 6f82c92c309a0f21374cce323119e26f86678735 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 11:03:06 -0600 Subject: [PATCH 04/22] sorta alloc support. Compiler error checkpoint --- .../libraries/stn/src/alloc/block_alloc.hb | 119 +++++++++--------- sysdata/libraries/stn/src/alloc/fake_alloc.hb | 31 +++-- sysdata/programs/alloc_test/src/main.hb | 27 ++-- sysdata/system_config.toml | 4 +- 4 files changed, 90 insertions(+), 91 deletions(-) diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb index 7cd29c6b6..0477b0f51 100644 --- a/sysdata/libraries/stn/src/alloc/block_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -1,75 +1,74 @@ +.{log} := @use("../lib.hb") alloc_return := @use("alloc_return.hb") /* the block size is 64 bytes, 64 blocks of 64 bytes. this will very quickly lead to exhaustion of free blocks. */ BlockAlloc := struct { + // hi state: uint, ptr: ?^u8, $init := fn(): Self { return .(0, null) } + + $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { + offset := 1 + a := 1 + loop { + // a = self.state >> offset; + // check if the `offset` bit is 1, if it is move to the next offset + if a == 1 { + offset += 1 + log.info("Already Allocated\0") + } else { + // self it to 1 and return the ptr to the allocation + self.state |= a + // return ptr + offset * 64 + return .(64, self.ptr + offset * 64) + } + // there are only 64 blocks + if offset >= 64 { + return .(0, null) + } + } + } + + $dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void { + // size := size_of(alloc_type)*count + size := 64 + // get the size alligned to the nearest block + // rounded_size := nearest_block_size_rounded_up(size) + rounded_size := 64 + + state_bit_start := { + // Do math here to figure out what starting ptr corresponds to what bit + 3 + } + + offset := 0 + + loop { + if rounded_size > 0 { + // set state_bit_start+offset to 0 + + // at the end move to the next one + offset += 1 + } else { + break + } + + rounded_size -= 64 + } + return void + } + + $deinit := fn(self: Self): void { + self.state = 0 + self.ptr = null + } } -// $alloc := fn(self: Self, alloc_type: Type, count: uint): alloc_return.AllocReturn { -// offset := 0 -// a := 0 -// loop { -// a = self.state << offset; -// // check if the `offset` bit is 1, if it is move to the next offset -// if a == 1 { -// offset += 1 -// } else { -// // self it to 1 and return the ptr to the allocation -// self.state |= a -// return (ptr + (offset * 64)) -// } -// // there are only 64 blocks -// if offset >= 64 { -// break; -// } -// } -// return null -// } - - - // request a kernel page -// ptr := memory.alloc(1) - - - -// $dealloc := fn(&self, ptr: ^u8, alloc_type: Type, count: uint): void { -// size := size_of(alloc_type)*count -// // get the size alligned to the nearest block -// rounded_size := nearest_block_size_rounded_up(size) - -// state_bit_start := { -// // Do math here to figure out what starting ptr corresponds to what bit -// 3 -// } - -// offset := 0 - -// loop { -// if rounded_size > 0 { -// // set state_bit_start+offset to 0 - -// // at the end move to the next one -// offset += 1 -// } else { -// break; -// } - -// rounded_size -= 64 -// } - -// return void -// } - -// $deinit := fn(&self): void { -// self.state := 0 - -// } -// } \ No newline at end of file +// ptr := memory.alloc(1) \ No newline at end of file diff --git a/sysdata/libraries/stn/src/alloc/fake_alloc.hb b/sysdata/libraries/stn/src/alloc/fake_alloc.hb index a7ccd76fc..82c422acc 100644 --- a/sysdata/libraries/stn/src/alloc/fake_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/fake_alloc.hb @@ -1,22 +1,19 @@ alloc_return := @use("alloc_return.hb") - FakeAlloc := struct { - $init := fn():Self{ - return .() - } - - $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { - return .(0, null) - } - - $dealloc := fn(self: Self, ptr: ^u8, alloc_type: Type, count: uint) : void{ - return void - } - // Nothing to clean up here - $deinit := fn(self: Self): void { - return void - } -} + $init := fn(): Self { + return .() + } + $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { + return .(0, null) + } + $dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void { + return void + } + // Nothing to clean up here + $deinit := fn(self: Self): void { + return void + } +} \ No newline at end of file diff --git a/sysdata/programs/alloc_test/src/main.hb b/sysdata/programs/alloc_test/src/main.hb index 7b4a7dcd2..67ed88451 100644 --- a/sysdata/programs/alloc_test/src/main.hb +++ b/sysdata/programs/alloc_test/src/main.hb @@ -1,25 +1,28 @@ stn := @use("../../../libraries/stn/src/lib.hb"); -.{allocators, panic} := stn +.{allocators, panic, log} := stn AStruct := struct { - a_field: u8, + a_field: u8, } main := fn(): void { - alloc := allocators.FakeAlloc.init() - astruct := alloc.alloc(AStruct, 2) + // alloc := allocators.FakeAlloc.init() + // astruct := alloc.alloc(AStruct, 2) // if astruct.ptr != null{ - // panic.panic("FakeAlloc actually allocated.") + // panic.panic("FakeAlloc actually allocated.") // } // alloc.dealloc(&astruct.ptr, AStruct, 2) - alloc.deinit() + // alloc.deinit() - // balloc := allocators.BlockAlloc.init() - // bstruct_ptr := balloc.alloc(AStruct, 2) - // if bstruct_ptr == null { - // panic("BlockAlloc actually didn't allocate.") - // } + balloc := allocators.BlockAlloc.init() + bstruct := balloc.alloc(AStruct, 2) + if bstruct.ptr == null { + log.info("Hi\0") + // panic.panic("BlockAlloc actually didn't allocate.") + } else { + log.info("Allocator functioned.\0") + } // balloc.dealloc(bstruct_ptr, AStruct, 2) // balloc.deinit() - return + return } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 182c3dedc..61344f6f0 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -46,5 +46,5 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.processes] # path = "boot:///processes.hbf" -# [boot.limine.ableos.modules.alloc_test] -# path = "boot:///alloc_test.hbf" \ No newline at end of file +[boot.limine.ableos.modules.alloc_test] +path = "boot:///alloc_test.hbf" \ No newline at end of file From 2261f3610165b874faf17a499c2273c88ab669a4 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 11:04:12 -0600 Subject: [PATCH 05/22] simply just dont inline --- sysdata/libraries/stn/src/alloc/block_alloc.hb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb index 0477b0f51..b0917bd58 100644 --- a/sysdata/libraries/stn/src/alloc/block_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -13,7 +13,7 @@ BlockAlloc := struct { return .(0, null) } - $alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { + alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { offset := 1 a := 1 loop { @@ -35,7 +35,7 @@ BlockAlloc := struct { } } - $dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void { + dealloc := fn(self: Self, ptr: ^u8, alloc_type: type, count: uint): void { // size := size_of(alloc_type)*count size := 64 // get the size alligned to the nearest block From 0ee8b7a4e4a26addb7db06830732528e7fdefe37 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 11:08:22 -0600 Subject: [PATCH 06/22] janky error handling --- sysdata/libraries/stn/src/alloc/block_alloc.hb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb index b0917bd58..6f27fa428 100644 --- a/sysdata/libraries/stn/src/alloc/block_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -1,4 +1,4 @@ -.{log} := @use("../lib.hb") +.{log, panic} := @use("../lib.hb") alloc_return := @use("alloc_return.hb") /* the block size is 64 bytes, 64 blocks of 64 bytes. @@ -17,7 +17,7 @@ BlockAlloc := struct { offset := 1 a := 1 loop { - // a = self.state >> offset; + // a = self.state >> offset // check if the `offset` bit is 1, if it is move to the next offset if a == 1 { offset += 1 @@ -26,7 +26,12 @@ BlockAlloc := struct { // self it to 1 and return the ptr to the allocation self.state |= a // return ptr + offset * 64 - return .(64, self.ptr + offset * 64) + if self.ptr != null { + return .(64, self.ptr + offset * 64) + } else { + // panic.panic("Allocator is not inited.\0") + // return .(0, null) + } } // there are only 64 blocks if offset >= 64 { From d7e0d573e244601bc364cfbd5667d471fc5d18cd Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 11:57:06 -0600 Subject: [PATCH 07/22] Style guide commit. Feel free to bikeshed about it. What should be added etcetc --- STYLE_GUIDE.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 STYLE_GUIDE.md diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md new file mode 100644 index 000000000..63707b328 --- /dev/null +++ b/STYLE_GUIDE.md @@ -0,0 +1,47 @@ +# Style Guide +This style guide has two modes that a guideline may be. + +`strict` means that prs will be rejected if they do not follow the guideline. + +`loose` means that a pr would be accepted but should later be fixed. + + +## Magic Numbers | loose +The policy on magic numbers is make them const and have a comment above them. Typically linking to a source of information about the magic number. + +This helps cut down on magic numbers while making acceptable names and atleast half assed documentation. + +```rust +// The standard vga port is mapped at 0xB8000 +$VGA_PTR := 0xB8000 +``` + +## Tabs Vs Spaces | loose +I prefer for hblang code to use hard tabs. + +The rational behind this is that a tab is `1 Indent` which some developers might want to be various different sizes when displayed + +Soft tabs do not allow this user/editor specific as soft tabs always become spaces. + +Bottom line is this is an accessibility feature. + +There are some samples below. +``` +\t means hard tab +\n means new line +\0x20 means space +``` + +### Allowed +```rust +if x == y {\n +\tlog(z)\n +}\n +``` + +### Not Allowed +```rust +if x == y {\n +\0x20\0x20\0x20\0x20log(z)\n +}\n +``` \ No newline at end of file From 8b2b50e43333f99427ce177fe1b77d6bf43604dc Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 12:22:06 -0600 Subject: [PATCH 08/22] Style guide update, vscode config to make tab indent follow the style guide --- .vscode/settings.json | 2 ++ STYLE_GUIDE.md | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e0c3d059c..893772838 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { + "editor.insertSpaces": false, + "editor.detectIndentation": false, "rust-analyzer.checkOnSave.allTargets": false, "rust-analyzer.showUnlinkedFileNotification": false, "C_Cpp.errorSquiggles": "disabled" diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 63707b328..5f2e22242 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -5,6 +5,23 @@ This style guide has two modes that a guideline may be. `loose` means that a pr would be accepted but should later be fixed. +## Empty Functions | loose +Empty functions are typically a sign of an unfinished program or driver. + +In cases where there is a clear reason to have an empty function it will be allowed. +For example FakeAlloc is only empty functions because it is a example of an the allocator api. + +### Allowed +```rust +/// in example.hb +a := fn(): void {} +``` +### Not Allowed +```rust +/// in fat32.hb +a := fn(): void {} +``` + ## Magic Numbers | loose The policy on magic numbers is make them const and have a comment above them. Typically linking to a source of information about the magic number. @@ -16,7 +33,7 @@ This helps cut down on magic numbers while making acceptable names and atleast h $VGA_PTR := 0xB8000 ``` -## Tabs Vs Spaces | loose +## Tabs Vs Spaces | strict I prefer for hblang code to use hard tabs. The rational behind this is that a tab is `1 Indent` which some developers might want to be various different sizes when displayed From 8c88c0b5aec90c24ab24d4a06fbd9011f94064e2 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 12:43:15 -0600 Subject: [PATCH 09/22] defer in alloc --- STYLE_GUIDE.md | 4 +++- sysdata/programs/alloc_test/src/main.hb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 5f2e22242..17ed727fd 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -26,7 +26,9 @@ a := fn(): void {} ## Magic Numbers | loose The policy on magic numbers is make them const and have a comment above them. Typically linking to a source of information about the magic number. -This helps cut down on magic numbers while making acceptable names and atleast half assed documentation. +This helps cut down on magic numbers while making acceptable names and atleast half assed documentation. + +Constants are inlined anyways, so its the same thing in the binary. ```rust // The standard vga port is mapped at 0xB8000 diff --git a/sysdata/programs/alloc_test/src/main.hb b/sysdata/programs/alloc_test/src/main.hb index 67ed88451..479d1b412 100644 --- a/sysdata/programs/alloc_test/src/main.hb +++ b/sysdata/programs/alloc_test/src/main.hb @@ -15,6 +15,7 @@ main := fn(): void { // alloc.deinit() balloc := allocators.BlockAlloc.init() + defer balloc.deinit() bstruct := balloc.alloc(AStruct, 2) if bstruct.ptr == null { log.info("Hi\0") @@ -23,6 +24,5 @@ main := fn(): void { log.info("Allocator functioned.\0") } // balloc.dealloc(bstruct_ptr, AStruct, 2) - // balloc.deinit() return } \ No newline at end of file From 0b57c2e9bb4c534d60799ea787de6a2a0842276e Mon Sep 17 00:00:00 2001 From: koniifer Date: Sun, 24 Nov 2024 20:58:14 +0000 Subject: [PATCH 10/22] simple foldhash implementation --- Cargo.lock | 6 +- kernel/src/kmain.rs | 2 +- sysdata/libraries/stn/src/hash/foldhash.hb | 189 +++++++++++++++++++++ sysdata/libraries/stn/src/hash/lib.hb | 2 + sysdata/libraries/stn/src/lib.hb | 1 + sysdata/programs/hash_test/meta.toml | 11 ++ sysdata/programs/hash_test/src/main.hb | 31 ++++ sysdata/system_config.toml | 5 +- 8 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 sysdata/libraries/stn/src/hash/foldhash.hb create mode 100644 sysdata/libraries/stn/src/hash/lib.hb create mode 100644 sysdata/programs/hash_test/meta.toml create mode 100644 sysdata/programs/hash_test/src/main.hb diff --git a/Cargo.lock b/Cargo.lock index 45ec40178..02fc4ee13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#784d552c1dee2a3cfde4b83e01523d91988bb554" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" dependencies = [ "hbbytecode", ] diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index fdd670094..a9f7bc61f 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -76,6 +76,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { "Graphics front ptr {:?}", fb1.address.as_ptr().unwrap() as *const u8 ); + log::info!("Started AbleOS"); unsafe { let executor = LazyCell::::force_mut(&mut EXECUTOR); @@ -132,7 +133,6 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { executor.run(); }; - log::info!("Started AbleOS"); crate::arch::spin_loop() } diff --git a/sysdata/libraries/stn/src/hash/foldhash.hb b/sysdata/libraries/stn/src/hash/foldhash.hb new file mode 100644 index 000000000..2aa9e1b42 --- /dev/null +++ b/sysdata/libraries/stn/src/hash/foldhash.hb @@ -0,0 +1,189 @@ +/* +* This code is an implementation of the FoldHash algorithm from https://github.com/orlp/foldhash, +* originally written by Orson Peters under the zlib license. +* +* Changes to the original code were made to meet the simplicity requirements of this implementation. +* Behaviour aims to be equivalent but not identical to the original code. +* +* Copyright (c) 2024 Orson Peters +* +* This software is provided 'as-is', without any express or implied warranty. In +* no event will the authors be held liable for any damages arising from the use of +* this software. +* +* Permission is granted to anyone to use this software for any purpose, including +* commercial applications, and to alter it and redistribute it freely, subject to +* the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not claim +* that you wrote the original software. If you use this software in a product, +* an acknowledgment in the product documentation would be appreciated but is +* not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +*/; + +.{math, random} := @use("../lib.hb") + +$ARBITRARY0 := 0x243F6A8885A308D3 +$ARBITRARY1 := 0x13198A2E03707344 +$ARBITRARY2 := 0xA4093822299F31D0 +$ARBITRARY3 := 0x82EFA98EC4E6C89 +$ARBITRARY4 := 0x452821E638D01377 +$ARBITRARY5 := 0xBE5466CF34E90C6C +$ARBITRARY6 := 0xC0AC29B7C97C50DD +$ARBITRARY7 := 0x3F84D5B5B5470917 +$ARBITRARY8 := 0x9216D5D98979FB1B +$ARBITRARY9 := 0xD1310BA698DFB5AC +$FIXED_GLOBAL_SEED := [uint].(ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7) + +global_seed := 0 + +u128 := packed struct {a: uint, b: uint} + +$folded_multiply := fn(x: uint, y: uint): uint { + lx := @as(u32, @intcast(x)) + ly := @as(u32, @intcast(y)) + hx := x >> 32 + hy := y >> 32 + afull := lx * hy + bfull := hx * ly + return afull ^ (bfull << 32 | bfull >> 32) +} + +hash_bytes_medium := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, fold_seed: uint): uint { + lo := bytes + end := bytes + len + hi := end - 16 + + loop if lo >= hi break else { + a := *@as(^uint, @bitcast(lo)) + b := *@as(^uint, @bitcast(lo + 8)) + c := *@as(^uint, @bitcast(hi)) + d := *@as(^uint, @bitcast(hi + 8)) + s0 = folded_multiply(a ^ s0, c ^ fold_seed) + s1 = folded_multiply(b ^ s1, d ^ fold_seed) + hi -= 16 + lo += 16 + } + return s0 ^ s1 +} + +hash_bytes_long := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, s2: uint, s3: uint, fold_seed: uint): uint { + $chunk_size := 64 + chunks := len / chunk_size + remainder := len % chunk_size + + ptr := bytes + i := 0 + loop if i >= chunks break else { + a := *@as(^uint, @bitcast(ptr)) + b := *@as(^uint, @bitcast(ptr + 8)) + c := *@as(^uint, @bitcast(ptr + 16)) + d := *@as(^uint, @bitcast(ptr + 24)) + e := *@as(^uint, @bitcast(ptr + 32)) + f := *@as(^uint, @bitcast(ptr + 40)) + g := *@as(^uint, @bitcast(ptr + 48)) + h := *@as(^uint, @bitcast(ptr + 56)) + + s0 = folded_multiply(a ^ s0, e ^ fold_seed) + s1 = folded_multiply(b ^ s1, f ^ fold_seed) + s2 = folded_multiply(c ^ s2, g ^ fold_seed) + s3 = folded_multiply(d ^ s3, h ^ fold_seed) + + ptr += chunk_size + i += 1 + } + + s0 ^= s2 + s1 ^= s3 + + if remainder > 0 { + remainder_start := bytes + len - math.max(uint, remainder, 16) + return hash_bytes_medium(remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed) + } + + return s0 ^ s1 +} + +FoldHasher := struct { + accumulator: uint, + original_seed: uint, + sponge: u128, + sponge_len: u8, + fold_seed: uint, + expand_seed: uint, + expand_seed2: uint, + expand_seed3: uint, + + $new := fn(seed: uint): Self { + return .( + seed, + seed, + .(0, 0), + 0, + FIXED_GLOBAL_SEED[0], + FIXED_GLOBAL_SEED[1], + FIXED_GLOBAL_SEED[2], + FIXED_GLOBAL_SEED[3], + ) + } + + default := fn(): Self { + if global_seed == 0 { + // ! consider this "secure enough" for now + global_seed = random.any(uint) + } + return Self.new(global_seed) + } + + write := fn(self: ^Self, bytes: ^u8, len: uint): void { + s0 := self.accumulator + s1 := self.expand_seed + if len <= 16 { + if len >= 8 { + s0 ^= *@bitcast(bytes) + s1 ^= *@bitcast(bytes + len - 8) + } else if len >= 4 { + s0 ^= *@as(^u32, @bitcast(bytes)) + s1 ^= *@as(^u32, @bitcast(bytes + len - 4)) + } else if len > 0 { + lo := *bytes + mid := *(bytes + len / 2) + hi := *(bytes + len - 1) + s0 ^= lo + s1 ^= @as(uint, hi) << 8 | mid + } + self.accumulator = folded_multiply(s0, s1) + } else if len < 256 { + self.accumulator = hash_bytes_medium(bytes, len, s0, s1, self.fold_seed) + } else { + self.accumulator = hash_bytes_long( + bytes, + len, + s0, + s1, + self.expand_seed2, + self.expand_seed3, + self.fold_seed, + ) + } + } + + finish := fn(self: ^Self): uint { + if self.sponge_len > 0 { + return folded_multiply(self.sponge.b ^ self.accumulator, self.sponge.a ^ self.fold_seed) + } else { + return self.accumulator + } + } + + reset := fn(self: ^Self): void { + self.accumulator = self.original_seed + self.sponge = .(0, 0) + self.sponge_len = 0 + } +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/hash/lib.hb b/sysdata/libraries/stn/src/hash/lib.hb new file mode 100644 index 000000000..da97bfd7c --- /dev/null +++ b/sysdata/libraries/stn/src/hash/lib.hb @@ -0,0 +1,2 @@ +//! NON CRYPTOGRAPHIC HASHER +foldhash := @use("foldhash.hb") \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index d90217b66..dc6494ece 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -1,5 +1,6 @@ acs := @use("acs.hb") allocators := @use("alloc/lib.hb") +hashers := @use("hash/lib.hb") string := @use("string.hb") log := @use("log.hb") memory := @use("memory.hb") diff --git a/sysdata/programs/hash_test/meta.toml b/sysdata/programs/hash_test/meta.toml new file mode 100644 index 000000000..fc157f124 --- /dev/null +++ b/sysdata/programs/hash_test/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "hash_test" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/hash_test/src/main.hb b/sysdata/programs/hash_test/src/main.hb new file mode 100644 index 000000000..08405413d --- /dev/null +++ b/sysdata/programs/hash_test/src/main.hb @@ -0,0 +1,31 @@ +.{hashers, log, memory, string} := @use("../../../libraries/stn/src/lib.hb") + +main := fn(): void { + buffer := memory.request_page(1) + target := "abcdefghijklmnop\0" + strings := [^u8].("abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0") + len := @sizeof(@TypeOf(strings)) / @sizeof(^u8) + strlen := string.length(target) + + // hasher := hashers.foldhash.FoldHasher.new(1) + hasher := hashers.foldhash.FoldHasher.default() + hasher.write(target, strlen) + correct := hasher.finish() + + log.warn("target:\0") + log.warn(target) + + i := 0 + loop if i == len break else { + defer i += 1 + hasher.reset() + hasher.write(strings[i], strlen) + d := hasher.finish() + if d == correct { + log.warn("match found\0") + } + log.info(strings[i]) + log.debug(string.display_int(@bitcast(d), buffer, 16)) + string.clear(buffer) + } +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 61344f6f0..34b0649f3 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -46,5 +46,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.processes] # path = "boot:///processes.hbf" +# [boot.limine.ableos.modules.alloc_test] +# path = "boot:///alloc_test.hbf" + [boot.limine.ableos.modules.alloc_test] -path = "boot:///alloc_test.hbf" \ No newline at end of file +path = "boot:///hash_test.hbf" From bdb762c9862b8cc7a4a0fcbe31425f734231fba9 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 23:50:46 -0600 Subject: [PATCH 11/22] Magic function style guide --- STYLE_GUIDE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 17ed727fd..6298d0e6a 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -21,6 +21,17 @@ a := fn(): void {} /// in fat32.hb a := fn(): void {} ``` +## Magic Functions | loose +'Magic functions' are what I am calling small helper functions that do one or two things. +### Example +```rust +a := null +magic_a := fn(){ + a = 10 +} +``` +The exact policy I want to have here is a bit fuzzy. I think that functions like this are nice in certain situations and not in others. +Regardless of if you use them or not, put a comment above the function explaining rational. ## Magic Numbers | loose From 9aa84a0f40b0b1651f61f79b4a790fc7638356eb Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 23:51:37 -0600 Subject: [PATCH 12/22] :thumbsup: checkpoint --- .../libraries/stn/src/alloc/block_alloc.hb | 47 ++++++++++++------- sysdata/programs/alloc_test/src/main.hb | 16 ++++--- sysdata/programs/sunset_server/src/main.hb | 3 ++ sysdata/system_config.toml | 2 +- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/sysdata/libraries/stn/src/alloc/block_alloc.hb b/sysdata/libraries/stn/src/alloc/block_alloc.hb index 6f27fa428..7cca60624 100644 --- a/sysdata/libraries/stn/src/alloc/block_alloc.hb +++ b/sysdata/libraries/stn/src/alloc/block_alloc.hb @@ -1,4 +1,4 @@ -.{log, panic} := @use("../lib.hb") +.{log, panic, memory} := @use("../lib.hb") alloc_return := @use("alloc_return.hb") /* the block size is 64 bytes, 64 blocks of 64 bytes. @@ -10,29 +10,40 @@ BlockAlloc := struct { ptr: ?^u8, $init := fn(): Self { - return .(0, null) + alloc_page_ptr := memory.request_page(1) + state := 0xFFFFFFFFFFFFFFFF + return .(state, alloc_page_ptr) } alloc := fn(self: Self, alloc_type: type, count: uint): alloc_return.AllocReturn { - offset := 1 - a := 1 + offset := 0 + state_2 := 0 loop { - // a = self.state >> offset - // check if the `offset` bit is 1, if it is move to the next offset - if a == 1 { - offset += 1 - log.info("Already Allocated\0") + xyz := self.state & 1 + abc := if xyz == 1 { + true } else { - // self it to 1 and return the ptr to the allocation - self.state |= a - // return ptr + offset * 64 - if self.ptr != null { - return .(64, self.ptr + offset * 64) - } else { - // panic.panic("Allocator is not inited.\0") - // return .(0, null) - } + false } + // check if the `offset` bit is 1, if it is move to the next offset + if abc { + offset += 1 + return .(0, null) + } else { + log.info("Already Allocated\0") + } + + // else { + // // self it to 1 and return the ptr to the allocation + // self.state |= a + // // return ptr + offset * 64 + // if self.ptr != null { + // return .(64, self.ptr + offset * 64) + // } else { + // // panic.panic("Allocator is not inited.\0") + // // return .(0, null) + // } + // } // there are only 64 blocks if offset >= 64 { return .(0, null) diff --git a/sysdata/programs/alloc_test/src/main.hb b/sysdata/programs/alloc_test/src/main.hb index 479d1b412..250ecea60 100644 --- a/sysdata/programs/alloc_test/src/main.hb +++ b/sysdata/programs/alloc_test/src/main.hb @@ -15,14 +15,16 @@ main := fn(): void { // alloc.deinit() balloc := allocators.BlockAlloc.init() - defer balloc.deinit() + // defer { + // balloc.deinit() + // } bstruct := balloc.alloc(AStruct, 2) - if bstruct.ptr == null { - log.info("Hi\0") - // panic.panic("BlockAlloc actually didn't allocate.") - } else { - log.info("Allocator functioned.\0") - } + // if bstruct.ptr == null { + // log.info("Hi\0") + // // panic.panic("BlockAlloc actually didn't allocate.") + // } else { + // log.info("Allocator functioned.\0") + // } // balloc.dealloc(bstruct_ptr, AStruct, 2) return } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 43295868e..1376ee514 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -13,6 +13,9 @@ img := @embed("../../../assets/wallpaper.qoi") main := fn(): int { sunset.server.start() + defer { + stn.log.info("Sunset Server Exit\0") + } screen := render.init(true) render.clear(screen, render.black) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 34b0649f3..f6b8e0399 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -50,4 +50,4 @@ resolution = "1024x768x24" # path = "boot:///alloc_test.hbf" [boot.limine.ableos.modules.alloc_test] -path = "boot:///hash_test.hbf" +path = "boot:///alloc_test.hbf" From 1b3dc153e8ccf8df961f32e9370e94f61029f77b Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 26 Nov 2024 07:39:16 -0600 Subject: [PATCH 13/22] SDoom + pcspkr: Both prerelease --- repbuild/src/main.rs | 4 ++ sysdata/libraries/horizon_api/src/lib.hb | 6 --- .../horizon_api/src/widgets/label.hb | 38 ++++++------- sysdata/programs/pcspkr/README.md | 1 + sysdata/programs/pcspkr/meta.toml | 11 ++++ sysdata/programs/pcspkr/src/main.hb | 45 ++++++++++++++++ sysdata/programs/sdoom/README.md | 4 ++ sysdata/programs/sdoom/meta.toml | 11 ++++ sysdata/programs/sdoom/src/main.hb | 53 +++++++++++++++++++ sysdata/programs/sdoom/src/player.hb | 0 sysdata/programs/sunset_client_2/src/main.hb | 2 +- sysdata/programs/sunset_server/src/main.hb | 12 ++--- sysdata/system_config.toml | 27 +++++----- 13 files changed, 170 insertions(+), 44 deletions(-) create mode 100644 sysdata/programs/pcspkr/README.md create mode 100644 sysdata/programs/pcspkr/meta.toml create mode 100644 sysdata/programs/pcspkr/src/main.hb create mode 100644 sysdata/programs/sdoom/README.md create mode 100644 sysdata/programs/sdoom/meta.toml create mode 100644 sysdata/programs/sdoom/src/main.hb create mode 100644 sysdata/programs/sdoom/src/player.hb diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 8d63c2dd8..d361cbc1a 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -460,6 +460,10 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { // "-serial", "stdio", "-m", "2G", "-smp", "1", + "-audiodev", + "pa,id=speaker", + "-machine", + "pcspk-audiodev=speaker", "-parallel", "none", "-monitor", "none", "-machine", accel, diff --git a/sysdata/libraries/horizon_api/src/lib.hb b/sysdata/libraries/horizon_api/src/lib.hb index 112bbac3a..bae1ba613 100644 --- a/sysdata/libraries/horizon_api/src/lib.hb +++ b/sysdata/libraries/horizon_api/src/lib.hb @@ -26,12 +26,6 @@ create_window := fn(channel: int): ^render.Surface { if windowing_system_buffer == 0 { return @as(^render.Surface, idk) } else { - // ! bad able, stop using string messages :ragey: - // msg := "\{01}\0" - // msg_length := 2 - - // @as(void, @eca(3, windowing_system_buffer, msg, msg_length)) - x := 0 loop if x > 1000 break else x += 1 diff --git a/sysdata/libraries/horizon_api/src/widgets/label.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb index 5d1fb1951..ce7e030a7 100644 --- a/sysdata/libraries/horizon_api/src/widgets/label.hb +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -14,14 +14,27 @@ Label := struct { text_length: uint, bg: Color, fg: Color, -} -set_label_text := fn(label: Label, text: ^u8): void { - text_length := string.length(text) + new_label := fn(text: ^u8): Self { + text_surface := render.new_surface(1024, 20) + text_length := string.length(text) + label := Self.(3, true, text_surface, text, text_length, render.black, render.white) + return label + } - label.is_dirty = true - label.text = text - label.text_length = text_length + set_label_text := fn(self: Self, text: ^u8): void { + text_length := string.length(text) + + self.is_dirty = true + self.text = text + self.text_length = text_length + } + + $set_color := fn(self: Self, bg: Color, fg: Color): void { + self.bg = bg + self.fg = fg + self.is_dirty = true + } } render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { @@ -30,17 +43,4 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V render.put_text(label.surface, font, .(0, 0), label.fg, label.text) } render.put_surface(surface, label.surface, pos, false) -} - -new_label := fn(text: ^u8): Label { - text_surface := render.new_surface(1024, 20) - text_length := string.length(text) - label := Label.(3, true, text_surface, text, text_length, render.black, render.white) - return label -} - -$set_color := fn(label: Label, bg: Color, fg: Color): void { - label.bg = bg - label.fg = fg - label.is_dirty = true } \ No newline at end of file diff --git a/sysdata/programs/pcspkr/README.md b/sysdata/programs/pcspkr/README.md new file mode 100644 index 000000000..5a5f4b956 --- /dev/null +++ b/sysdata/programs/pcspkr/README.md @@ -0,0 +1 @@ +# pcspkr \ No newline at end of file diff --git a/sysdata/programs/pcspkr/meta.toml b/sysdata/programs/pcspkr/meta.toml new file mode 100644 index 000000000..d71a5f20c --- /dev/null +++ b/sysdata/programs/pcspkr/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "pcspkr" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/pcspkr/src/main.hb b/sysdata/programs/pcspkr/src/main.hb new file mode 100644 index 000000000..5c5055cbf --- /dev/null +++ b/sysdata/programs/pcspkr/src/main.hb @@ -0,0 +1,45 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{memory, buffer, log, string, math} := stn; +.{inb, outb} := memory + +$PIT_CLOCK := 1193180 + +play_sound := fn(frequency: u32): void { + div := 0 + + div = PIT_CLOCK / frequency + memory.outb(0x43, 0xB6) + memory.outb(0x42, @intcast(div)) + memory.outb(0x42, @intcast(div >> 8)) + + tmp := inb(0x61) + if tmp != (tmp | 3) { + outb(0x61, tmp | 3) + } +} + +no_sound := fn(): void { + tmp := memory.inb(0x61) & 0xFC + + memory.outb(0x61, tmp) +} + +beep := fn(): void { + play_sound(1000) + idx := 0 + loop { + if idx >= 1000000 { + idx += 1 + } else { + break + } + } + + no_sound() +} + +main := fn(): int { + no_sound() + beep() + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/sdoom/README.md b/sysdata/programs/sdoom/README.md new file mode 100644 index 000000000..e752f1fa9 --- /dev/null +++ b/sysdata/programs/sdoom/README.md @@ -0,0 +1,4 @@ +# sdoom +SDoom stands for simple doom. + +This is not a full implementation of doom and is instead a doom style renderer. \ No newline at end of file diff --git a/sysdata/programs/sdoom/meta.toml b/sysdata/programs/sdoom/meta.toml new file mode 100644 index 000000000..b6e9cbde0 --- /dev/null +++ b/sysdata/programs/sdoom/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "sdoom" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/sdoom/src/main.hb b/sysdata/programs/sdoom/src/main.hb new file mode 100644 index 000000000..22aebc7ba --- /dev/null +++ b/sysdata/programs/sdoom/src/main.hb @@ -0,0 +1,53 @@ +sunset := @use("../../../libraries/sunset_proto/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb") + +stn := @use("../../../libraries/stn/src/lib.hb"); +.{log} := stn; +.{Vec2} := stn.math + +Player := struct { + x: i8, + y: i8, + + $new := fn(x: i8, y: i8): Self { + return Self.(x, y) + } +} + +GameState := struct { + player: Player, + + $new := fn(): Self { + p := Player.new(0, 0) + return Self.(p) + } +} + +main := fn(): void { + sunset.client.find_server() + + window := sunset.client.new(.(.(600, 400), .(200, 200), "SDoom\0")) + + if window == null { + log.error("got no window\0") + return + } + + game_state := GameState.new() + + loop { + render.clear(window.surface, render.black) + width := 100 + idx := 1 + + loop { + if idx >= width { + break + } + render.put_vline(window.surface, idx, 10, 100, render.white) + idx += 1 + } + + _ = sunset.client.send_frame(window) + } +} \ No newline at end of file diff --git a/sysdata/programs/sdoom/src/player.hb b/sysdata/programs/sdoom/src/player.hb new file mode 100644 index 000000000..e69de29bb diff --git a/sysdata/programs/sunset_client_2/src/main.hb b/sysdata/programs/sunset_client_2/src/main.hb index 3fcf1c1ad..2e5475966 100644 --- a/sysdata/programs/sunset_client_2/src/main.hb +++ b/sysdata/programs/sunset_client_2/src/main.hb @@ -13,7 +13,7 @@ main := fn(): void { return } - window := sunset.client.new(.(.(400, 300), .(400, 240), "Sunset!\0")) + window := sunset.client.new(.(.(400, 100), .(400, 240), "Sunset!\0")) if window == null { log.error("got no window\0") diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 1376ee514..fa109c6b7 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb") horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); -.{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label +.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label stn := @use("../../../libraries/stn/src/lib.hb"); .{Vec2} := stn.math @@ -31,8 +31,8 @@ main := fn(): int { mouse_x := 100 mouse_y := 100 - text_label := new_label("Hi\0") - set_color(text_label, sunset.server.DECO_COLOUR, render.black) + text_label := Label.new_label("Hi\0") + text_label.set_color(sunset.server.DECO_COLOUR, render.black) loop { mouse_event := intouch.recieve_mouse_event() @@ -62,13 +62,13 @@ main := fn(): int { } if mouse_event.left { - set_label_text(text_label, "LEFT CLICK\0") + text_label.set_label_text("LEFT CLICK\0") } if mouse_event.middle { - set_label_text(text_label, "MIDDLE CLICK\0") + text_label.set_label_text("MIDDLE CLICK\0") } if mouse_event.right { - set_label_text(text_label, "RIGHT CLICK\0") + text_label.set_label_text("RIGHT CLICK\0") } } { diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index f6b8e0399..a63f1704c 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,26 +28,29 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -# [boot.limine.ableos.modules.ps2_mouse_driver] -# path = "boot:///ps2_mouse_driver.hbf" +[boot.limine.ableos.modules.ps2_mouse_driver] +path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -# [boot.limine.ableos.modules.sunset_client] -# path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.sunset_client] +path = "boot:///sunset_client.hbf" -# [boot.limine.ableos.modules.sunset_client_2] -# path = "boot:///sunset_client_2.hbf" +[boot.limine.ableos.modules.sunset_client_2] +path = "boot:///sunset_client_2.hbf" -# [boot.limine.ableos.modules.sunset_server] -# path = "boot:///sunset_server.hbf" +[boot.limine.ableos.modules.sdoom] +path = "boot:///sdoom.hbf" -# [boot.limine.ableos.modules.processes] -# path = "boot:///processes.hbf" +[boot.limine.ableos.modules.sunset_server] +path = "boot:///sunset_server.hbf" + +# [boot.limine.ableos.modules.pcspkr] +# path = "boot:///pcspkr.hbf" # [boot.limine.ableos.modules.alloc_test] # path = "boot:///alloc_test.hbf" -[boot.limine.ableos.modules.alloc_test] -path = "boot:///alloc_test.hbf" +# [boot.limine.ableos.modules.hash_test] +# path = "boot:///hash_test.hbf" From 685c6f0b20723379fede80547b11963236bf90e2 Mon Sep 17 00:00:00 2001 From: koniifer Date: Tue, 26 Nov 2024 19:32:19 +0000 Subject: [PATCH 14/22] task scheduler weirdness --- kernel/src/holeybytes/ecah.rs | 3 +- kernel/src/holeybytes/mod.rs | 7 +- kernel/src/kmain.rs | 2 +- kernel/src/lib.rs | 7 +- kernel/src/task.rs | 154 ++++++++++++++++------------------ 5 files changed, 85 insertions(+), 88 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 67576f478..a34f683a8 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -33,7 +33,7 @@ unsafe fn x86_in(address: u16) -> T { } #[inline(always)] -pub fn handler(vm: &mut Vm) { +pub fn handler(vm: &mut Vm, pid: &usize) { let ecall_number = vm.registers[2].cast::(); match ecall_number { @@ -209,7 +209,6 @@ pub fn handler(vm: &mut Vm) { let buffer_id = vm.registers[3].cast::(); let map_ptr = vm.registers[4].cast::(); let max_length = vm.registers[5].cast::(); - let mut buffs = IPC_BUFFERS.lock(); let buff: &mut IpcBuffer = match buffs.get_mut(&buffer_id) { Some(buff) => buff, diff --git a/kernel/src/holeybytes/mod.rs b/kernel/src/holeybytes/mod.rs index 2c4dbab4f..ab68d04f8 100644 --- a/kernel/src/holeybytes/mod.rs +++ b/kernel/src/holeybytes/mod.rs @@ -65,7 +65,12 @@ impl<'p> Future for ExecThread { return Poll::Ready(Err(err)); } Ok(VmRunOk::End) => return Poll::Ready(Ok(())), - Ok(VmRunOk::Ecall) => ecah::handler(&mut self.vm), + Ok(VmRunOk::Ecall) => ecah::handler( + &mut self.vm, + cx.ext() + .downcast_ref() + .expect("PID did not exist in Context"), + ), Ok(VmRunOk::Timer) => (), Ok(VmRunOk::Breakpoint) => { log::error!( diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index a9f7bc61f..928dbe57f 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -122,7 +122,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { if cmd_len > 0 { thr.set_arguments(cmd.as_ptr() as u64, cmd_len); } - executor.spawn(Box::pin(async move { + executor.spawn(Box::pin(async { if let Err(e) = thr.await { log::error!("{e:?}"); } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 52956ecd1..cf68a83d3 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -10,9 +10,11 @@ abi_x86_interrupt, lazy_get, alloc_error_handler, + local_waker, + context_ext, ptr_sub_ptr, naked_functions, - pointer_is_aligned_to, + pointer_is_aligned_to )] #![allow(dead_code, internal_features, static_mut_refs)] extern crate alloc; @@ -35,8 +37,7 @@ mod utils; // #[cfg(feature = "tests")] mod ktest; -use alloc::string::ToString; -use versioning::Version; +use {alloc::string::ToString, versioning::Version}; /// Kernel's version pub const VERSION: Version = Version { diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 3326871b3..01c6688c0 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -3,7 +3,8 @@ use { core::{ future::Future, pin::Pin, - task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, + sync::atomic::{AtomicBool, Ordering}, + task::{Context, ContextBuilder, Poll, RawWaker, RawWakerVTable, Waker}, }, crossbeam_queue::SegQueue, slab::Slab, @@ -14,7 +15,6 @@ pub fn yield_now() -> impl Future { impl Future for YieldNow { type Output = (); - #[inline(always)] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { if self.0 { Poll::Ready(()) @@ -29,53 +29,70 @@ pub fn yield_now() -> impl Future { YieldNow(false) } +pub trait Process: Future + Send {} +impl + Send> Process for T {} + pub struct Executor { tasks: Slab, - task_queue: Arc, + task_queue: Arc>, } impl Executor { pub fn new() -> Self { Self { tasks: Slab::new(), - task_queue: Arc::new(TaskQueue::new()), + task_queue: Arc::new(SegQueue::new()), } } - #[inline] - pub fn spawn(&mut self, future: Pin + Send>>) -> usize { + pub fn spawn(&mut self, future: Pin>) -> usize { let id = self.tasks.insert(Task::new(future)); - self.task_queue.queue.push(id); + self.task_queue.push(id); + id } + pub fn pause(&mut self, id: usize) { + if let Some(task) = self.tasks.get(id) { + task.set_paused(true); + } + } + + pub fn unpause(&mut self, id: usize) { + if let Some(task) = self.tasks.get(id) { + task.set_paused(false); + self.task_queue.push(id); + } + } + pub fn run(&mut self) { let mut task_batch = [0; 32]; - let mut batch_len = 0; - loop { - self.task_queue.batch_pop(&mut task_batch, &mut batch_len); + let mut batch_len = 0; - if batch_len == 0 { - if self.task_queue.is_empty() { + while let Some(id) = self.task_queue.pop() { + task_batch[batch_len] = id; + batch_len += 1; + if batch_len == task_batch.len() { break; - } else { - continue; } } - for &id in &task_batch[..batch_len] { - if let Some(task) = self.tasks.get_mut(id) { - let waker = task - .waker - .get_or_insert_with(|| TaskWaker::new(id, Arc::clone(&self.task_queue))); + if batch_len == 0 { + break; + } - let waker = unsafe { Waker::from_raw(TaskWaker::into_raw_waker(waker)) }; - let mut cx = Context::from_waker(&waker); + for &(mut id) in &task_batch[..batch_len] { + if let Some(task) = self.tasks.get_mut(id) { + if task.is_paused() { + continue; + } + + let waker = create_waker(id, Arc::clone(&self.task_queue)); + let mut cx = ContextBuilder::from_waker(&waker).ext(&mut id).build(); if let Poll::Ready(()) = task.poll(&mut cx) { self.tasks.remove(id); - self.task_queue.free_tasks.push(id); } } } @@ -84,95 +101,70 @@ impl Executor { } struct Task { - future: Pin + Send>>, - waker: Option, + future: Pin>, + paused: AtomicBool, } impl Task { - #[inline(always)] - pub fn new(future: Pin + Send>>) -> Self { + fn new(future: Pin>) -> Self { Self { future, - waker: None, + paused: AtomicBool::new(false), } } - #[inline(always)] fn poll(&mut self, cx: &mut Context) -> Poll<()> { self.future.as_mut().poll(cx) } + + fn is_paused(&self) -> bool { + self.paused.load(Ordering::Acquire) + } + + fn set_paused(&self, paused: bool) { + self.paused.store(paused, Ordering::Release) + } } +fn create_waker(task_id: usize, task_queue: Arc>) -> Waker { + let data = Box::new(TaskWaker { + task_id, + task_queue, + }); + let raw_waker = RawWaker::new(Box::into_raw(data) as *const (), &VTABLE); + unsafe { Waker::from_raw(raw_waker) } +} + +#[derive(Clone)] struct TaskWaker { - id: usize, - task_queue: Arc, + task_id: usize, + task_queue: Arc>, } impl TaskWaker { - #[inline(always)] - fn new(id: usize, task_queue: Arc) -> Self { - Self { id, task_queue } - } - - #[inline(always)] fn wake(&self) { - self.task_queue.queue.push(self.id); - } - - fn into_raw_waker(waker: &TaskWaker) -> RawWaker { - let ptr = waker as *const TaskWaker; - RawWaker::new(ptr.cast(), &VTABLE) + self.task_queue.push(self.task_id); } } const VTABLE: RawWakerVTable = RawWakerVTable::new(clone_raw, wake_raw, wake_by_ref_raw, drop_raw); unsafe fn clone_raw(ptr: *const ()) -> RawWaker { - let waker = &*(ptr as *const TaskWaker); - TaskWaker::into_raw_waker(waker) + let task_waker = Box::from_raw(ptr as *mut TaskWaker); + let raw_waker = RawWaker::new(Box::into_raw(task_waker.clone()) as *const (), &VTABLE); + raw_waker } unsafe fn wake_raw(ptr: *const ()) { - let waker = &*(ptr as *const TaskWaker); - waker.wake(); + let task_waker = Box::from_raw(ptr as *mut TaskWaker); + task_waker.wake(); } unsafe fn wake_by_ref_raw(ptr: *const ()) { - let waker = &*(ptr as *const TaskWaker); - waker.wake(); + let task_waker = &*(ptr as *const TaskWaker); + task_waker.wake(); } -unsafe fn drop_raw(_: *const ()) {} - -struct TaskQueue { - queue: SegQueue, - next_task: usize, - free_tasks: SegQueue, -} - -impl TaskQueue { - fn new() -> Self { - Self { - queue: SegQueue::new(), - next_task: 0, - free_tasks: SegQueue::new(), - } - } - - #[inline(always)] - fn batch_pop(&self, output: &mut [usize], len: &mut usize) { - *len = 0; - while let Some(id) = self.queue.pop() { - output[*len] = id; - *len += 1; - if *len == output.len() { - break; - } - } - } - - #[inline(always)] - fn is_empty(&self) -> bool { - self.queue.is_empty() - } +unsafe fn drop_raw(ptr: *const ()) { + drop(Box::from_raw(ptr as *mut TaskWaker)); } From 5d152811b213d2f0436489971c024228bee6fcc4 Mon Sep 17 00:00:00 2001 From: kodin Date: Tue, 26 Nov 2024 15:53:50 -0600 Subject: [PATCH 15/22] Interrupt Forwarding (#22) Co-authored-by: Talha Qamar Reviewed-on: https://git.ablecorp.us/AbleOS/ableos/pulls/22 Co-authored-by: kodin Co-committed-by: kodin --- kernel/src/arch/x86_64/interrupts.rs | 7 ++++++- kernel/src/holeybytes/ecah.rs | 11 ++++++++++ kernel/src/task.rs | 28 ++++++++++++++++++++++--- sysdata/libraries/stn/src/sleep.hb | 1 + sysdata/programs/timer_test/meta.toml | 11 ++++++++++ sysdata/programs/timer_test/src/main.hb | 8 +++++++ sysdata/system_config.toml | 27 +++++++++++++----------- 7 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 sysdata/programs/timer_test/meta.toml create mode 100644 sysdata/programs/timer_test/src/main.hb diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 4bd3c8a96..28b432c99 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -62,7 +62,7 @@ extern "x86-interrupt" fn page_fault( } extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { - // interrupt(Interrupt::Timer); + interrupt(Interrupt::Timer); unsafe { LAPIC.end_of_interrupt(); @@ -85,6 +85,7 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { fn interrupt(interrupt_type: Interrupt) { use crate::arch::INTERRUPT_LIST; + use crate::kmain::EXECUTOR; let il = INTERRUPT_LIST.lock(); let val = il.list.get(&interrupt_type).unwrap(); @@ -107,4 +108,8 @@ fn interrupt(interrupt_type: Interrupt) { // log::info!("{}", buffer); } + + unsafe{ + EXECUTOR.send_interrupt(interrupt_type as u8); + } } diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index a34f683a8..b1561f96e 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -1,5 +1,7 @@ //! Environment call handling routines +use log::log; + use {alloc::boxed::Box, core::cell::LazyCell, hbvm::mem::Address}; use crate::{ @@ -242,6 +244,15 @@ pub fn handler(vm: &mut Vm, pid: &usize) { vm.registers[3] = x } } + 6 => { // Wait till interrupt + use crate::kmain::EXECUTOR; + let interrupt_type = vm.registers[3].cast::(); + info!("Interrupt subscribled: {}", interrupt_type); + unsafe{ + EXECUTOR.pause(pid.clone()); + LazyCell::::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type); + } + } _ => { log::error!("Syscall unknown {:?}{:?}", ecall_number, vm.registers); } diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 01c6688c0..c79140f78 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -35,6 +35,7 @@ impl + Send> Process for T {} pub struct Executor { tasks: Slab, task_queue: Arc>, + interrupt_lookup: [Option; u8::MAX as usize], } impl Executor { @@ -42,6 +43,7 @@ impl Executor { Self { tasks: Slab::new(), task_queue: Arc::new(SegQueue::new()), + interrupt_lookup: [None; u8::MAX as usize], } } @@ -52,19 +54,23 @@ impl Executor { id } - pub fn pause(&mut self, id: usize) { + pub fn pause(&self, id: usize) { if let Some(task) = self.tasks.get(id) { task.set_paused(true); } } - pub fn unpause(&mut self, id: usize) { + pub fn unpause(&self, id: usize) { if let Some(task) = self.tasks.get(id) { task.set_paused(false); self.task_queue.push(id); } } + pub fn interrupt_subscribe(&mut self, pid : usize, interrupt_type: u8){ + self.interrupt_lookup[interrupt_type as usize] = Some(pid); + } + pub fn run(&mut self) { let mut task_batch = [0; 32]; loop { @@ -79,7 +85,8 @@ impl Executor { } if batch_len == 0 { - break; + //break; + continue; } for &(mut id) in &task_batch[..batch_len] { @@ -93,11 +100,26 @@ impl Executor { if let Poll::Ready(()) = task.poll(&mut cx) { self.tasks.remove(id); + self.interrupt_lookup.map(|pid|{ + if let Some(pid) = pid{ + if pid == id { + return None; + } + } + return pid; + }); } } } } } + + pub fn send_interrupt(&self, interrupt : u8){ + let id = self.interrupt_lookup[interrupt as usize]; + if let Some(id) = id{ + self.unpause(id); + } + } } struct Task { diff --git a/sysdata/libraries/stn/src/sleep.hb b/sysdata/libraries/stn/src/sleep.hb index d3232675f..5aeaf148e 100644 --- a/sysdata/libraries/stn/src/sleep.hb +++ b/sysdata/libraries/stn/src/sleep.hb @@ -3,4 +3,5 @@ subscribe_to_interrupt := fn(interrupt_number: u8): bool { } // Pauses execution until the interrupt occures sleep_until_interrupt := fn(interrupt_number: u8): void { + @eca(6, interrupt_number) } \ No newline at end of file diff --git a/sysdata/programs/timer_test/meta.toml b/sysdata/programs/timer_test/meta.toml new file mode 100644 index 000000000..c05908d05 --- /dev/null +++ b/sysdata/programs/timer_test/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "timer_test" +authors = ["Talha Qamar"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/timer_test/src/main.hb b/sysdata/programs/timer_test/src/main.hb new file mode 100644 index 000000000..b2142eac5 --- /dev/null +++ b/sysdata/programs/timer_test/src/main.hb @@ -0,0 +1,8 @@ +sleep := @use("../../../libraries/stn/src/sleep.hb") +log := @use("../../../libraries/stn/src/log.hb") + +main := fn(): int { + log.info("BEFORE\0") + sleep.sleep_until_interrupt(32) + log.info("AFTER\0") +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index a63f1704c..34ab7905c 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,23 +28,26 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.sunset_client] -path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.timer_test] +path = "boot:///timer_test.hbf" -[boot.limine.ableos.modules.sunset_client_2] -path = "boot:///sunset_client_2.hbf" - -[boot.limine.ableos.modules.sdoom] -path = "boot:///sdoom.hbf" - -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" +# +# [boot.limine.ableos.modules.sunset_client_2] +# path = "boot:///sunset_client_2.hbf" +# +# [boot.limine.ableos.modules.sdoom] +# path = "boot:///sdoom.hbf" +# +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" # [boot.limine.ableos.modules.pcspkr] # path = "boot:///pcspkr.hbf" From f6a8a78b6c5dbda0d1c86e61547abffb1be30622 Mon Sep 17 00:00:00 2001 From: koniifer Date: Tue, 26 Nov 2024 22:02:54 +0000 Subject: [PATCH 16/22] mini size fixes --- kernel/src/holeybytes/ecah.rs | 11 ++++++----- kernel/src/ktest.rs | 6 +++--- kernel/src/lib.rs | 4 +++- sysdata/programs/timer_test/src/main.hb | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index b1561f96e..2a4d2e1a4 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -1,7 +1,5 @@ //! Environment call handling routines -use log::log; - use {alloc::boxed::Box, core::cell::LazyCell, hbvm::mem::Address}; use crate::{ @@ -244,13 +242,16 @@ pub fn handler(vm: &mut Vm, pid: &usize) { vm.registers[3] = x } } - 6 => { // Wait till interrupt + 6 => { + // Wait till interrupt use crate::kmain::EXECUTOR; let interrupt_type = vm.registers[3].cast::(); info!("Interrupt subscribled: {}", interrupt_type); - unsafe{ + unsafe { EXECUTOR.pause(pid.clone()); - LazyCell::::get_mut(&mut EXECUTOR).unwrap().interrupt_subscribe(pid.clone(), interrupt_type); + LazyCell::::get_mut(&mut EXECUTOR) + .unwrap() + .interrupt_subscribe(pid.clone(), interrupt_type); } } _ => { diff --git a/kernel/src/ktest.rs b/kernel/src/ktest.rs index 43a2a11a3..bd5ec7f39 100644 --- a/kernel/src/ktest.rs +++ b/kernel/src/ktest.rs @@ -16,13 +16,13 @@ pub fn test_main() { unsafe { let mut current_test = &__ktest_start as *const fn(); let mut current = 1; - let test_end = &__ktest_end as *const fn(); + let test_end = &__ktest_end as *const fn(); while current_test < test_end { let test_fn = *current_test; debug!("Running test {}", current); - + test_fn(); debug!("Test {} passed", current); @@ -35,4 +35,4 @@ pub fn test_main() { #[ktest] pub fn trivial_assertion() { assert_eq!(1, 1); -} \ No newline at end of file +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index cf68a83d3..3f2be1166 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -35,9 +35,10 @@ mod task; mod utils; // #[cfg(feature = "tests")] +#[allow(improper_ctypes, non_upper_case_globals)] mod ktest; -use {alloc::string::ToString, versioning::Version}; +use versioning::Version; /// Kernel's version pub const VERSION: Version = Version { @@ -49,6 +50,7 @@ pub const VERSION: Version = Version { #[panic_handler] #[cfg(target_os = "none")] fn panic(info: &core::panic::PanicInfo) -> ! { + use alloc::string::ToString; arch::register_dump(); if let Some(loc) = info.location() { diff --git a/sysdata/programs/timer_test/src/main.hb b/sysdata/programs/timer_test/src/main.hb index b2142eac5..a491de4da 100644 --- a/sysdata/programs/timer_test/src/main.hb +++ b/sysdata/programs/timer_test/src/main.hb @@ -1,7 +1,7 @@ sleep := @use("../../../libraries/stn/src/sleep.hb") log := @use("../../../libraries/stn/src/log.hb") -main := fn(): int { +main := fn(): void { log.info("BEFORE\0") sleep.sleep_until_interrupt(32) log.info("AFTER\0") From 95cf948d594eca4c5f68013d3e0f6e09705c99a8 Mon Sep 17 00:00:00 2001 From: funky Date: Wed, 27 Nov 2024 19:09:15 +1100 Subject: [PATCH 17/22] Ktest major improvements --- kernel/ktest_macro/src/lib.rs | 71 +++++++++++++++++++++++++++++++---- kernel/lds/aarch64-qemu.ld | 5 +++ kernel/src/kmain.rs | 7 +++- kernel/src/ktest.rs | 49 +++++++++++++++--------- kernel/src/lib.rs | 1 - 5 files changed, 105 insertions(+), 28 deletions(-) diff --git a/kernel/ktest_macro/src/lib.rs b/kernel/ktest_macro/src/lib.rs index c1c3a8a35..ebff0402c 100644 --- a/kernel/ktest_macro/src/lib.rs +++ b/kernel/ktest_macro/src/lib.rs @@ -1,28 +1,85 @@ extern crate proc_macro; extern crate quote; extern crate syn; + use { proc_macro::TokenStream, quote::quote, - syn::{parse_macro_input, ItemFn} + syn::{parse::Parse, parse_macro_input, Expr, ItemFn, Token} }; +struct KtestInput { + lhs: Expr, + _comma: Token![,], + rhs: Expr, +} + +impl Parse for KtestInput { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + Ok(Self { + lhs: input.parse()?, + _comma: input.parse()?, + rhs: input.parse()?, + }) + } +} + +#[proc_macro] +pub fn ktest_eq(item: TokenStream) -> TokenStream { + let input = parse_macro_input!(item as KtestInput); + + let lhs = input.lhs; + let rhs = input.rhs; + + let out = quote! { + if #lhs != #rhs { + return Err(name); + } + }; + TokenStream::from(out) +} + +#[proc_macro] +pub fn ktest_neq(item: TokenStream) -> TokenStream { + let input = parse_macro_input!(item as KtestInput); + + let lhs = input.lhs; + let rhs = input.rhs; + + let out = quote! { + if #lhs == #rhs { + return Err(name); + } + }; + TokenStream::from(out) +} + #[proc_macro_attribute] pub fn ktest(_attr: TokenStream, item: TokenStream) -> TokenStream { let input = parse_macro_input!(item as ItemFn); let test_name = &input.sig.ident; + let test_string = test_name.to_string(); let static_var_name = syn::Ident::new( - &format!("__ktest_{}", test_name), + &format!("__ktest_{}", test_name).to_uppercase(), test_name.span(), ); - let out = quote! { - // #[cfg(feature = "ktest")] - #input - // #[cfg(feature = "ktest")] + let block = &input.block; + let out = quote! { + #[cfg(feature = "ktest")] + fn #test_name() -> Result { + use crate::alloc::string::ToString; + let name = #test_string.to_string(); + + #block + + return Ok(name); + } + + #[cfg(feature = "ktest")] #[unsafe(link_section = ".note.ktest")] #[used] - pub static #static_var_name: fn() = #test_name; + pub static #static_var_name: fn() -> Result = #test_name; }; TokenStream::from(out) diff --git a/kernel/lds/aarch64-qemu.ld b/kernel/lds/aarch64-qemu.ld index dbcbacf92..adf13fbce 100644 --- a/kernel/lds/aarch64-qemu.ld +++ b/kernel/lds/aarch64-qemu.ld @@ -6,6 +6,11 @@ SECTIONS .text.boot : { *(.text.boot) } .text : { *(.text) } .data : { *(.data) } + .note.ktest : { + __ktest_start = .; + *(.note.ktest) + __ktest_end = .; + } .rodata : { *(.rodata) } .bss : { *(COMMON) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 928dbe57f..8d9d3989f 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -24,8 +24,11 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { #[cfg(feature = "ktest")] { - use crate::ktest; - debug!("TESTING"); + use { + crate::ktest, + log::info, + }; + info!("Running tests"); ktest::test_main(); loop {} diff --git a/kernel/src/ktest.rs b/kernel/src/ktest.rs index bd5ec7f39..c19444521 100644 --- a/kernel/src/ktest.rs +++ b/kernel/src/ktest.rs @@ -1,38 +1,51 @@ -pub use ktest_macro::ktest; -use log::debug; +pub use ktest_macro::*; + +use { + alloc::string::String, + log::{error, info}, +}; extern "C" { - static __ktest_start: fn(); - static __ktest_end: fn(); + static __ktest_start: fn() -> Result; + static __ktest_end: fn() -> Result; } -// TODO: Get test_fn linker name (may require no_mangle in macro) -// More info on tests (run the rest even if panic) -// Implement ktest for arm and riscv (Later problems, see below) +// TODO: Implement ktest for arm and riscv (Later problems, see below) // Allow for arch specific tests (Leave for now) -// Allow for ktest test name attr -// Usefull message at the end of testing +// Should panic tests +// Test specific panic handler pub fn test_main() { unsafe { - let mut current_test = &__ktest_start as *const fn(); - let mut current = 1; - let test_end = &__ktest_end as *const fn(); + let mut current_test = &__ktest_start as *const fn() -> Result; + let test_end = &__ktest_end as *const fn() -> Result; + + let mut pass = 0; + let mut fail = 0; while current_test < test_end { let test_fn = *current_test; - debug!("Running test {}", current); - - test_fn(); - debug!("Test {} passed", current); + let test_name = test_fn(); + match test_name { + Ok(name) => { + info!("Test: {} passed", name); + pass += 1; + }, + Err(name) => { + error!("Test: {} failed", name); + fail += 1; + } + } current_test = current_test.add(1); - current += 1; } + + info!("{}/{} tests passed", pass, pass + fail); } } #[ktest] pub fn trivial_assertion() { - assert_eq!(1, 1); + ktest_eq!(1, 1); + ktest_neq!(0, 1); } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 3f2be1166..b0005d814 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -34,7 +34,6 @@ mod memory; mod task; mod utils; -// #[cfg(feature = "tests")] #[allow(improper_ctypes, non_upper_case_globals)] mod ktest; From 9d1c59b65da02aa6f66b628f26ebe885807f9dff Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 27 Nov 2024 12:41:51 +0000 Subject: [PATCH 18/22] consolidate simple tests, bug revealed --- sysdata/libraries/stn/src/lib.hb | 1 + sysdata/programs/alloc_test/README.md | 1 - sysdata/programs/alloc_test/meta.toml | 11 ---------- sysdata/programs/dt_buffer_test/README.md | 1 - sysdata/programs/dt_buffer_test/src/main.hb | 13 ------------ sysdata/programs/hash_test/meta.toml | 11 ---------- sysdata/programs/processes/meta.toml | 11 ---------- sysdata/programs/serial_driver_test/meta.toml | 11 ---------- .../programs/serial_driver_test/src/main.hb | 20 ------------------ .../{dt_buffer_test => test}/meta.toml | 4 ++-- sysdata/programs/test/src/main.hb | 7 ++++++ .../programs/test/src/tests/serial_driver.hb | 18 ++++++++++++++++ .../src/tests/stn/allocators.hb} | 6 +++--- .../tests/stn/assets}/hello_world_and_spin.hb | 0 .../stn/assets}/hello_world_and_spin.hbf | Bin sysdata/programs/test/src/tests/stn/dt.hb | 18 ++++++++++++++++ .../main.hb => test/src/tests/stn/hashers.hb} | 5 +++-- sysdata/programs/test/src/tests/stn/lib.hb | 5 +++++ .../main.hb => test/src/tests/stn/process.hb} | 7 +++--- sysdata/programs/test/src/tests/stn/sleep.hb | 8 +++++++ sysdata/programs/timer_test/meta.toml | 11 ---------- sysdata/programs/timer_test/src/main.hb | 8 ------- sysdata/system_config.toml | 10 ++------- 23 files changed, 71 insertions(+), 116 deletions(-) delete mode 100644 sysdata/programs/alloc_test/README.md delete mode 100644 sysdata/programs/alloc_test/meta.toml delete mode 100644 sysdata/programs/dt_buffer_test/README.md delete mode 100644 sysdata/programs/dt_buffer_test/src/main.hb delete mode 100644 sysdata/programs/hash_test/meta.toml delete mode 100644 sysdata/programs/processes/meta.toml delete mode 100644 sysdata/programs/serial_driver_test/meta.toml delete mode 100644 sysdata/programs/serial_driver_test/src/main.hb rename sysdata/programs/{dt_buffer_test => test}/meta.toml (73%) create mode 100644 sysdata/programs/test/src/main.hb create mode 100644 sysdata/programs/test/src/tests/serial_driver.hb rename sysdata/programs/{alloc_test/src/main.hb => test/src/tests/stn/allocators.hb} (87%) rename sysdata/programs/{processes/src => test/src/tests/stn/assets}/hello_world_and_spin.hb (100%) rename sysdata/programs/{processes/src => test/src/tests/stn/assets}/hello_world_and_spin.hbf (100%) create mode 100644 sysdata/programs/test/src/tests/stn/dt.hb rename sysdata/programs/{hash_test/src/main.hb => test/src/tests/stn/hashers.hb} (87%) create mode 100644 sysdata/programs/test/src/tests/stn/lib.hb rename sysdata/programs/{processes/src/main.hb => test/src/tests/stn/process.hb} (61%) create mode 100644 sysdata/programs/test/src/tests/stn/sleep.hb delete mode 100644 sysdata/programs/timer_test/meta.toml delete mode 100644 sysdata/programs/timer_test/src/main.hb diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index dc6494ece..93919178c 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -10,6 +10,7 @@ random := @use("random.hb") file := @use("file_io.hb") dt := @use("dt.hb") process := @use("process.hb") +sleep := @use("sleep.hb") panic := fn(message: ?^u8): never { log.error("Error: Panic Called, Message:\0") diff --git a/sysdata/programs/alloc_test/README.md b/sysdata/programs/alloc_test/README.md deleted file mode 100644 index 560819442..000000000 --- a/sysdata/programs/alloc_test/README.md +++ /dev/null @@ -1 +0,0 @@ -# alloc_test \ No newline at end of file diff --git a/sysdata/programs/alloc_test/meta.toml b/sysdata/programs/alloc_test/meta.toml deleted file mode 100644 index aa77119fd..000000000 --- a/sysdata/programs/alloc_test/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "alloc_test" -authors = [""] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/dt_buffer_test/README.md b/sysdata/programs/dt_buffer_test/README.md deleted file mode 100644 index c01a7c5e1..000000000 --- a/sysdata/programs/dt_buffer_test/README.md +++ /dev/null @@ -1 +0,0 @@ -# dt_buffer_test \ No newline at end of file diff --git a/sysdata/programs/dt_buffer_test/src/main.hb b/sysdata/programs/dt_buffer_test/src/main.hb deleted file mode 100644 index 7d37f6ad1..000000000 --- a/sysdata/programs/dt_buffer_test/src/main.hb +++ /dev/null @@ -1,13 +0,0 @@ -.{dt} := @use("../../../libraries/stn/src/lib.hb") - -main := fn(): void { - dt.get(void, "framebuffer/fb0/width\0") - dt.get(void, "cpu/cpu0/architecture\0") - - // Checking if the first detected serial port is memory mapped or port mapped - // 0 -> memory mapped - // 1 -> port mapped - dt.get(void, "serial_ports/sp0/mapping\0") - - return -} \ No newline at end of file diff --git a/sysdata/programs/hash_test/meta.toml b/sysdata/programs/hash_test/meta.toml deleted file mode 100644 index fc157f124..000000000 --- a/sysdata/programs/hash_test/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "hash_test" -authors = [""] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/processes/meta.toml b/sysdata/programs/processes/meta.toml deleted file mode 100644 index 86a48694f..000000000 --- a/sysdata/programs/processes/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "processes" -authors = ["koniifer"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/serial_driver_test/meta.toml b/sysdata/programs/serial_driver_test/meta.toml deleted file mode 100644 index f8f995c92..000000000 --- a/sysdata/programs/serial_driver_test/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "serial_driver_test" -authors = ["able"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/serial_driver_test/src/main.hb b/sysdata/programs/serial_driver_test/src/main.hb deleted file mode 100644 index 19ad6c153..000000000 --- a/sysdata/programs/serial_driver_test/src/main.hb +++ /dev/null @@ -1,20 +0,0 @@ -.{string, buffer} := @use("../../../libraries/stn/src/lib.hb") - -log_info := fn(): void { - a := buffer.search("XNumber\0") - if a == 0 { - } else { - msg := "XABC\0" - // inline is broked - // msg_length := @inline(string.length, msg) - msg_length := 5 - @as(void, @eca(3, a, msg, msg_length)) - } - - return -} - -main := fn(): int { - log_info() - return 0 -} \ No newline at end of file diff --git a/sysdata/programs/dt_buffer_test/meta.toml b/sysdata/programs/test/meta.toml similarity index 73% rename from sysdata/programs/dt_buffer_test/meta.toml rename to sysdata/programs/test/meta.toml index f25002e98..93c3dd77e 100644 --- a/sysdata/programs/dt_buffer_test/meta.toml +++ b/sysdata/programs/test/meta.toml @@ -1,6 +1,6 @@ [package] -name = "dt_buffer_test" -authors = ["able"] +name = "test" +authors = ["koniifer", "able"] [dependants.libraries] diff --git a/sysdata/programs/test/src/main.hb b/sysdata/programs/test/src/main.hb new file mode 100644 index 000000000..3b3bc21c9 --- /dev/null +++ b/sysdata/programs/test/src/main.hb @@ -0,0 +1,7 @@ +stn := @use("./tests/stn/lib.hb") +serial_driver := @use("./tests/serial_driver.hb") + +main := fn(): uint { + // return serial_driver.test() + return stn.process.test() +} \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/serial_driver.hb b/sysdata/programs/test/src/tests/serial_driver.hb new file mode 100644 index 000000000..8e27b11d0 --- /dev/null +++ b/sysdata/programs/test/src/tests/serial_driver.hb @@ -0,0 +1,18 @@ +.{string, buffer} := @use("../../../../libraries/stn/src/lib.hb") + +log_info := fn(): void { + a := buffer.search("XNumber\0") + if a == 0 { + } else { + msg := "XABC\0" + msg_length := string.length(msg) + @eca(3, a, msg, msg_length) + } + + return +} + +test := fn(): uint { + log_info() + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/alloc_test/src/main.hb b/sysdata/programs/test/src/tests/stn/allocators.hb similarity index 87% rename from sysdata/programs/alloc_test/src/main.hb rename to sysdata/programs/test/src/tests/stn/allocators.hb index 250ecea60..8b194b7ff 100644 --- a/sysdata/programs/alloc_test/src/main.hb +++ b/sysdata/programs/test/src/tests/stn/allocators.hb @@ -1,11 +1,11 @@ -stn := @use("../../../libraries/stn/src/lib.hb"); +stn := @use("../../../../../libraries/stn/src/lib.hb"); .{allocators, panic, log} := stn AStruct := struct { a_field: u8, } -main := fn(): void { +test := fn(): uint { // alloc := allocators.FakeAlloc.init() // astruct := alloc.alloc(AStruct, 2) // if astruct.ptr != null{ @@ -26,5 +26,5 @@ main := fn(): void { // log.info("Allocator functioned.\0") // } // balloc.dealloc(bstruct_ptr, AStruct, 2) - return + return 0 } \ No newline at end of file diff --git a/sysdata/programs/processes/src/hello_world_and_spin.hb b/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb similarity index 100% rename from sysdata/programs/processes/src/hello_world_and_spin.hb rename to sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hb diff --git a/sysdata/programs/processes/src/hello_world_and_spin.hbf b/sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hbf similarity index 100% rename from sysdata/programs/processes/src/hello_world_and_spin.hbf rename to sysdata/programs/test/src/tests/stn/assets/hello_world_and_spin.hbf diff --git a/sysdata/programs/test/src/tests/stn/dt.hb b/sysdata/programs/test/src/tests/stn/dt.hb new file mode 100644 index 000000000..e331f33b2 --- /dev/null +++ b/sysdata/programs/test/src/tests/stn/dt.hb @@ -0,0 +1,18 @@ +.{dt, memory, string, log} := @use("../../../../../libraries/stn/src/lib.hb") + +test := fn(): uint { + buffer := memory.request_page(1) + + log.info(string.display_int(dt.get(int, "framebuffer/fb0/width\0"), buffer, 10)) + string.clear(buffer) + + log.info(string.display_int(dt.get(int, "cpu/cpu0/architecture\0"), buffer, 10)) + string.clear(buffer) + + // 0 -> memory mapped + // 1 -> port mapped + + log.info(string.display_int(dt.get(int, "serial_ports/sp0/mapping\0"), buffer, 10)) + + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/hash_test/src/main.hb b/sysdata/programs/test/src/tests/stn/hashers.hb similarity index 87% rename from sysdata/programs/hash_test/src/main.hb rename to sysdata/programs/test/src/tests/stn/hashers.hb index 08405413d..a1052d6e9 100644 --- a/sysdata/programs/hash_test/src/main.hb +++ b/sysdata/programs/test/src/tests/stn/hashers.hb @@ -1,6 +1,6 @@ -.{hashers, log, memory, string} := @use("../../../libraries/stn/src/lib.hb") +.{hashers, log, memory, string} := @use("../../../../../libraries/stn/src/lib.hb") -main := fn(): void { +test := fn(): uint { buffer := memory.request_page(1) target := "abcdefghijklmnop\0" strings := [^u8].("abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0") @@ -28,4 +28,5 @@ main := fn(): void { log.debug(string.display_int(@bitcast(d), buffer, 16)) string.clear(buffer) } + return 0 } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/lib.hb b/sysdata/programs/test/src/tests/stn/lib.hb new file mode 100644 index 000000000..da08b7795 --- /dev/null +++ b/sysdata/programs/test/src/tests/stn/lib.hb @@ -0,0 +1,5 @@ +hashers := @use("./hashers.hb") +allocators := @use("./allocators.hb") +sleep := @use("./sleep.hb") +dt := @use("./dt.hb") +process := @use("./process.hb") \ No newline at end of file diff --git a/sysdata/programs/processes/src/main.hb b/sysdata/programs/test/src/tests/stn/process.hb similarity index 61% rename from sysdata/programs/processes/src/main.hb rename to sysdata/programs/test/src/tests/stn/process.hb index 06b4ade8f..493e36a71 100644 --- a/sysdata/programs/processes/src/main.hb +++ b/sysdata/programs/test/src/tests/stn/process.hb @@ -1,8 +1,8 @@ -.{process, log, string, memory} := @use("../../../libraries/stn/src/lib.hb") +.{process, log, string, memory} := @use("../../../../../libraries/stn/src/lib.hb") -exe := @embed("./hello_world_and_spin.hbf") +exe := @embed("./assets/hello_world_and_spin.hbf") -main := fn(): void { +test := fn(): uint { buf := "\0\0\0\0\0\0\0" loop { log.info( @@ -16,4 +16,5 @@ main := fn(): void { i := 0 loop if i == 1000000 break else i += 1 } + return 0 } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/sleep.hb b/sysdata/programs/test/src/tests/stn/sleep.hb new file mode 100644 index 000000000..9eaeb31df --- /dev/null +++ b/sysdata/programs/test/src/tests/stn/sleep.hb @@ -0,0 +1,8 @@ +.{sleep, log} := @use("../../../../../libraries/stn/src/lib.hb") + +test := fn(): uint { + log.info("BEFORE\0") + sleep.sleep_until_interrupt(32) + log.info("AFTER\0") + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/timer_test/meta.toml b/sysdata/programs/timer_test/meta.toml deleted file mode 100644 index c05908d05..000000000 --- a/sysdata/programs/timer_test/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "timer_test" -authors = ["Talha Qamar"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/timer_test/src/main.hb b/sysdata/programs/timer_test/src/main.hb deleted file mode 100644 index a491de4da..000000000 --- a/sysdata/programs/timer_test/src/main.hb +++ /dev/null @@ -1,8 +0,0 @@ -sleep := @use("../../../libraries/stn/src/sleep.hb") -log := @use("../../../libraries/stn/src/log.hb") - -main := fn(): void { - log.info("BEFORE\0") - sleep.sleep_until_interrupt(32) - log.info("AFTER\0") -} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 34ab7905c..72445ba97 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -34,9 +34,6 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.timer_test] -path = "boot:///timer_test.hbf" - # [boot.limine.ableos.modules.sunset_client] # path = "boot:///sunset_client.hbf" # @@ -52,8 +49,5 @@ path = "boot:///timer_test.hbf" # [boot.limine.ableos.modules.pcspkr] # path = "boot:///pcspkr.hbf" -# [boot.limine.ableos.modules.alloc_test] -# path = "boot:///alloc_test.hbf" - -# [boot.limine.ableos.modules.hash_test] -# path = "boot:///hash_test.hbf" +[boot.limine.ableos.modules.test] +path = "boot:///test.hbf" From fd26ec734bed77d6aae9b2ff78e36899b6920196 Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 27 Nov 2024 12:52:48 +0000 Subject: [PATCH 19/22] temp interrupt fix, problem with sds_search_service --- kernel/src/arch/x86_64/interrupts.rs | 46 +++++++++++++--------------- kernel/src/task.rs | 16 +++++----- sysdata/system_config.toml | 22 ++++++------- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 28b432c99..336f0c892 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -83,33 +83,31 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { } } +#[allow(unused_imports)] fn interrupt(interrupt_type: Interrupt) { - use crate::arch::INTERRUPT_LIST; - use crate::kmain::EXECUTOR; - let il = INTERRUPT_LIST.lock(); - let val = il.list.get(&interrupt_type).unwrap(); + use crate::{arch::INTERRUPT_LIST, kmain::EXECUTOR}; + // let il = INTERRUPT_LIST.lock(); + // let val = il.list.get(&interrupt_type).unwrap(); - use crate::holeybytes::kernel_services::service_definition_service::sds_search_service; - let buffer = sds_search_service(val); - if buffer != 0 { - use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec}; - let mut buffs = IPC_BUFFERS.lock(); - match buffs.get_mut(&buffer) { - Some(buff) => { - let mut msg_vec = Vec::new(); - msg_vec.push(0xFF); - buff.push(msg_vec.to_vec()); - log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer); - } - None => { - log::error!("Access of non-existent buffer {}", buffer) - } - } + // use crate::holeybytes::kernel_services::service_definition_service::sds_search_service; + // let buffer = sds_search_service(val); + // if buffer != 0 { + // use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec}; + // let mut buffs = IPC_BUFFERS.lock(); + // match buffs.get_mut(&buffer) { + // Some(buff) => { + // let mut msg_vec = Vec::new(); + // msg_vec.push(0xFF); + // buff.push(msg_vec.to_vec()); + // log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer); + // } + // None => { + // log::error!("Access of non-existent buffer {}", buffer) + // } + // } + // } - // log::info!("{}", buffer); - } - - unsafe{ + unsafe { EXECUTOR.send_interrupt(interrupt_type as u8); } } diff --git a/kernel/src/task.rs b/kernel/src/task.rs index c79140f78..1040fb9b6 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -33,7 +33,7 @@ pub trait Process: Future + Send {} impl + Send> Process for T {} pub struct Executor { - tasks: Slab, + tasks: Slab, task_queue: Arc>, interrupt_lookup: [Option; u8::MAX as usize], } @@ -41,7 +41,7 @@ pub struct Executor { impl Executor { pub fn new() -> Self { Self { - tasks: Slab::new(), + tasks: Slab::new(), task_queue: Arc::new(SegQueue::new()), interrupt_lookup: [None; u8::MAX as usize], } @@ -67,7 +67,7 @@ impl Executor { } } - pub fn interrupt_subscribe(&mut self, pid : usize, interrupt_type: u8){ + pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) { self.interrupt_lookup[interrupt_type as usize] = Some(pid); } @@ -85,7 +85,7 @@ impl Executor { } if batch_len == 0 { - //break; + // break; continue; } @@ -100,8 +100,8 @@ impl Executor { if let Poll::Ready(()) = task.poll(&mut cx) { self.tasks.remove(id); - self.interrupt_lookup.map(|pid|{ - if let Some(pid) = pid{ + self.interrupt_lookup.map(|pid| { + if let Some(pid) = pid { if pid == id { return None; } @@ -114,9 +114,9 @@ impl Executor { } } - pub fn send_interrupt(&self, interrupt : u8){ + pub fn send_interrupt(&self, interrupt: u8) { let id = self.interrupt_lookup[interrupt as usize]; - if let Some(id) = id{ + if let Some(id) = id { self.unpause(id); } } diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 72445ba97..72ef8b42e 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,26 +28,26 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -# path = "boot:///ps2_mouse_driver.hbf" -# [boot.limine.ableos.modules.ps2_mouse_driver] +[boot.limine.ableos.modules.ps2_mouse_driver] +path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" # [boot.limine.ableos.modules.sunset_client] # path = "boot:///sunset_client.hbf" -# + # [boot.limine.ableos.modules.sunset_client_2] # path = "boot:///sunset_client_2.hbf" -# -# [boot.limine.ableos.modules.sdoom] -# path = "boot:///sdoom.hbf" -# -# [boot.limine.ableos.modules.sunset_server] -# path = "boot:///sunset_server.hbf" + +[boot.limine.ableos.modules.sdoom] +path = "boot:///sdoom.hbf" + +[boot.limine.ableos.modules.sunset_server] +path = "boot:///sunset_server.hbf" # [boot.limine.ableos.modules.pcspkr] # path = "boot:///pcspkr.hbf" -[boot.limine.ableos.modules.test] -path = "boot:///test.hbf" +# [boot.limine.ableos.modules.test] +# path = "boot:///test.hbf" From a551b2672fad9916eaddcec0d67eab1bf4ee3cae Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 27 Nov 2024 16:53:17 +0000 Subject: [PATCH 20/22] buffer awaiting -> free performance and free bugs --- kernel/src/holeybytes/ecah.rs | 20 ++++++++++++++--- kernel/src/task.rs | 26 +++++++++++++++++++++- sysdata/libraries/stn/src/buffer.hb | 4 ++++ sysdata/libraries/sunset_proto/src/lib.hb | 6 ++++- sysdata/programs/sunset_server/src/main.hb | 4 ++-- sysdata/programs/test/src/main.hb | 2 +- sysdata/system_config.toml | 12 +++++----- 7 files changed, 60 insertions(+), 14 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 2a4d2e1a4..ab540d6bb 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -80,6 +80,10 @@ pub fn handler(vm: &mut Vm, pid: &usize) { let length = vm.registers[5].cast::() as usize; trace!("IPC address: {:?}", mem_addr); + unsafe { LazyCell::::get_mut(&mut EXECUTOR) } + .unwrap() + .send_buffer(buffer_id as usize); + match buffer_id { 0 => match sds_msg_handler(vm, mem_addr, length) { Ok(()) => {} @@ -246,12 +250,22 @@ pub fn handler(vm: &mut Vm, pid: &usize) { // Wait till interrupt use crate::kmain::EXECUTOR; let interrupt_type = vm.registers[3].cast::(); - info!("Interrupt subscribled: {}", interrupt_type); + debug!("Interrupt subscribed: {}", interrupt_type); unsafe { - EXECUTOR.pause(pid.clone()); LazyCell::::get_mut(&mut EXECUTOR) .unwrap() - .interrupt_subscribe(pid.clone(), interrupt_type); + .interrupt_subscribe(*pid, interrupt_type); + } + } + 7 => { + // Wait till buffer + use crate::kmain::EXECUTOR; + let buffer_id = vm.registers[3].cast::() as usize; + debug!("Buffer subscribed: {}", buffer_id); + unsafe { + LazyCell::::get_mut(&mut EXECUTOR) + .unwrap() + .buffer_subscribe(*pid, buffer_id); } } _ => { diff --git a/kernel/src/task.rs b/kernel/src/task.rs index 1040fb9b6..8807505a9 100644 --- a/kernel/src/task.rs +++ b/kernel/src/task.rs @@ -1,5 +1,9 @@ use { - alloc::{boxed::Box, sync::Arc}, + alloc::{ + boxed::Box, + collections::{BTreeMap, BTreeSet}, + sync::Arc, + }, core::{ future::Future, pin::Pin, @@ -36,6 +40,7 @@ pub struct Executor { tasks: Slab, task_queue: Arc>, interrupt_lookup: [Option; u8::MAX as usize], + buffer_lookup: BTreeMap>, } impl Executor { @@ -44,6 +49,7 @@ impl Executor { tasks: Slab::new(), task_queue: Arc::new(SegQueue::new()), interrupt_lookup: [None; u8::MAX as usize], + buffer_lookup: BTreeMap::new(), } } @@ -68,9 +74,19 @@ impl Executor { } pub fn interrupt_subscribe(&mut self, pid: usize, interrupt_type: u8) { + self.pause(pid); self.interrupt_lookup[interrupt_type as usize] = Some(pid); } + pub fn buffer_subscribe(&mut self, pid: usize, buffer_id: usize) { + self.pause(pid); + if let Some(buf) = self.buffer_lookup.get_mut(&buffer_id) { + buf.insert(pid); + } else { + self.buffer_lookup.insert(buffer_id, BTreeSet::from([pid])); + } + } + pub fn run(&mut self) { let mut task_batch = [0; 32]; loop { @@ -108,6 +124,9 @@ impl Executor { } return pid; }); + self.buffer_lookup.iter_mut().for_each(|(_, pid_set)| { + pid_set.remove(&id); + }); } } } @@ -120,6 +139,11 @@ impl Executor { self.unpause(id); } } + pub fn send_buffer(&self, id: usize) { + if let Some(buf) = self.buffer_lookup.get(&id) { + buf.iter().for_each(|pid| self.unpause(*pid)); + } + } } struct Task { diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 17f5a3f30..495f53a27 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,5 +1,9 @@ string := @use("string.hb") +$await := fn(buffer_id: uint): void { + return @eca(7, buffer_id) +} + $recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index f75dfb286..6191960bd 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -48,6 +48,8 @@ await_channel := fn(): Channel { await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { response := @as(?Message(Expr), null) loop { + // awaiting here causes flickering... idk why + buffer.await(buffer_id) buffer.recv(?Message(Expr), buffer_id, &response) if response != null { return @as(Message(Expr), response) @@ -58,9 +60,11 @@ await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { await_header := fn(buffer_id: uint): MessageHeader { response := @as(?MessageHeader, null) loop { + // awaiting here causes flickering... idk why + buffer.await(buffer_id) buffer.recv(?MessageHeader, buffer_id, &response) if response != null { - return @as(?MessageHeader, response) + return @as(MessageHeader, response) } } } diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index fa109c6b7..9f438d741 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -91,8 +91,8 @@ main := fn(): int { // Mouse cursor { - render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER) - render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR) + render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER) + render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR) } render.sync(screen) diff --git a/sysdata/programs/test/src/main.hb b/sysdata/programs/test/src/main.hb index 3b3bc21c9..debec4e02 100644 --- a/sysdata/programs/test/src/main.hb +++ b/sysdata/programs/test/src/main.hb @@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb") main := fn(): uint { // return serial_driver.test() - return stn.process.test() + return stn.sleep.test() } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 72ef8b42e..297b1b3d0 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -34,14 +34,14 @@ path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -# [boot.limine.ableos.modules.sunset_client] -# path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.sunset_client] +path = "boot:///sunset_client.hbf" -# [boot.limine.ableos.modules.sunset_client_2] -# path = "boot:///sunset_client_2.hbf" +[boot.limine.ableos.modules.sunset_client_2] +path = "boot:///sunset_client_2.hbf" -[boot.limine.ableos.modules.sdoom] -path = "boot:///sdoom.hbf" +# [boot.limine.ableos.modules.sdoom] +# path = "boot:///sdoom.hbf" [boot.limine.ableos.modules.sunset_server] path = "boot:///sunset_server.hbf" From 38d3a10659dbddc999a0fea9b5f4ba04fbd28a3a Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 30 Nov 2024 11:46:33 +0000 Subject: [PATCH 21/22] updates and updates --- Cargo.lock | 57 ++++++++++++++++++++++++--------------------- rust-toolchain.toml | 4 +++- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02fc4ee13..a4eea1abe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,9 +73,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" dependencies = [ "shlex", ] @@ -201,9 +201,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "allocator-api2", "equivalent", @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a3355a59c0727e58519a94a8f65013beb9c2331b" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" dependencies = [ "hbbytecode", ] @@ -401,7 +401,7 @@ dependencies = [ "uart_16550", "versioning", "x2apic", - "x86_64 0.15.1", + "x86_64 0.15.2", "xml", ] @@ -421,9 +421,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.164" +version = "0.2.167" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" +checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" [[package]] name = "limine" @@ -433,9 +433,9 @@ checksum = "02034f8f6b3e7bf050f310fbaf6db0018b8e54b75598d0a4c97172054752fede" [[package]] name = "litemap" -version = "0.7.4" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" [[package]] name = "lock_api" @@ -593,9 +593,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.18" +version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" +checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" dependencies = [ "log", "once_cell", @@ -726,9 +726,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.89" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -827,17 +827,20 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "2.10.1" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +checksum = "b30e6f97efe1fa43535ee241ee76967d3ff6ff3953ebb430d8d55c5393029e7b" dependencies = [ "base64", + "litemap", "log", "once_cell", "rustls", "rustls-pki-types", "url", "webpki-roots", + "yoke", + "zerofrom", ] [[package]] @@ -996,7 +999,7 @@ dependencies = [ "bitflags 1.3.2", "paste", "raw-cpuid 10.7.0", - "x86_64 0.14.12", + "x86_64 0.14.13", ] [[package]] @@ -1012,9 +1015,9 @@ dependencies = [ [[package]] name = "x86_64" -version = "0.14.12" +version = "0.14.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cb6fd45bfeab6a5055c5bffdb08768bd0c069f1d946debe585bbb380a7c062" +checksum = "c101112411baafbb4bf8d33e4c4a80ab5b02d74d2612331c61e8192fc9710491" dependencies = [ "bit_field", "bitflags 2.6.0", @@ -1024,9 +1027,9 @@ dependencies = [ [[package]] name = "x86_64" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc79523af8abf92fb1a970c3e086c5a343f6bcc1a0eb890f575cbb3b45743df" +checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae" dependencies = [ "bit_field", "bitflags 2.6.0", @@ -1044,9 +1047,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" dependencies = [ "serde", "stable_deref_trait", @@ -1068,9 +1071,9 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" dependencies = [ "zerofrom-derive", ] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a0db7f55d..b37e5aafb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,7 @@ [toolchain] # old toolchain # channel = "nightly-2024-07-27" -channel = "nightly-2024-11-20" +# last stable +# channel = "nightly-2024-11-20" +channel = "nightly" components = ["rust-src", "llvm-tools"] From db01da58e1e20438a59ca168619d51ab336f4cd1 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 30 Nov 2024 21:52:18 +0000 Subject: [PATCH 22/22] new path resolver and stuff --- Cargo.lock | 6 +++--- repbuild/src/dev.rs | 8 +++++--- sysdata/libraries/sunset_proto/src/lib.hb | 2 +- sysdata/libraries/sunset_proto/src/server.hb | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4eea1abe..85df3e115 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#cf672beb79378fa2af529e12fd955204da443ac8" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#cf672beb79378fa2af529e12fd955204da443ac8" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a2ca8d98df7f58366252b71f58450a0ab5c11bca" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#cf672beb79378fa2af529e12fd955204da443ac8" dependencies = [ "hbbytecode", ] diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index 48f90e070..2f0a95aa7 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -83,7 +83,8 @@ impl Package { &path, Options { fmt: true, - in_house_regalloc: true, + resolver: Some(hblang::ABLEOS_PATH_RESOLVER), + ..Default::default() }, out, @@ -99,7 +100,7 @@ impl Package { hblang::run_compiler( &path, Options { - in_house_regalloc: true, + resolver: Some(hblang::ABLEOS_PATH_RESOLVER), ..Default::default() }, out, @@ -111,8 +112,9 @@ impl Package { hblang::run_compiler( &path, Options { + resolver: Some(hblang::ABLEOS_PATH_RESOLVER), dump_asm: true, - in_house_regalloc: true, + ..Default::default() }, out, diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index 6191960bd..9be50d85f 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -1,4 +1,4 @@ -.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb"); +.{math: .{Vec2}, buffer, memory} := @use("stn"); .{Surface} := @use("../../render/src/lib.hb") $BUFFER_SERVER := "sunset_server\0" diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 4850ce697..4dd16d9c4 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,6 +1,6 @@ -.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); -.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text, clear, white, black} := @use("../../render/src/lib.hb"); -.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb") +.{math, log, string, random, buffer, memory} := @use("stn"); +.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text, clear, white, black} := @use("lib:render"); +.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("lib:sunset_proto") WindowServer := struct { window_count: uint,