From 9aa84a0f40b0b1651f61f79b4a790fc7638356eb Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 24 Nov 2024 23:51:37 -0600 Subject: [PATCH] :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"