forked from AbleOS/ableos
👍 checkpoint
This commit is contained in:
parent
bdb762c986
commit
9aa84a0f40
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue