From 5c4056bc5cd5e6dc95104d708c2bbb2cd669d266 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 10:00:24 -0600 Subject: [PATCH] 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 baaf1a6..45ec401 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 5a80bf4..8d63c2d 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 0000000..e32bd1a --- /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 0000000..34aba7a --- /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 0000000..5b2e74c --- /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 0000000..a05698f --- /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 0000000..138d53c --- /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 961037c..538e778 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 77cb04c..ab66cfa 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 530c98a..a7b849e 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"