diff --git a/sysdata/libraries/stn/src/alloc/alloc_return.hb b/sysdata/libraries/stn/src/alloc/alloc_return.hb index e32bd1aa..bdc61f51 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 34aba7a0..7cd29c6b 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 5b2e74c6..a7ccd76f 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 a05698f1..f80a3619 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 538e7786..d90217b6 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 00000000..56081944 --- /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 00000000..aa77119f --- /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 00000000..7b4a7dcd --- /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 a7b849e0..182c3ded 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