diff options
author | Xander <xander@biltopia.org> | 2023-07-21 22:38:43 +0200 |
---|---|---|
committer | Xander <xander@biltopia.org> | 2023-07-21 22:38:43 +0200 |
commit | 58096a11ea200d4caf656bac712cde24daa8a697 (patch) | |
tree | 41df97b7d352217888804d8b13ae0802beaa5ffd /kernel/memory/frame.dats | |
parent | 1d25d9783127c181f79732eb5c20c680444af414 (diff) | |
download | ats-os-58096a11ea200d4caf656bac712cde24daa8a697.tar.xz ats-os-58096a11ea200d4caf656bac712cde24daa8a697.zip |
Working frame allocator but VERY ugly code
Diffstat (limited to 'kernel/memory/frame.dats')
-rw-r--r-- | kernel/memory/frame.dats | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/kernel/memory/frame.dats b/kernel/memory/frame.dats index 8578e8f..b1d86af 100644 --- a/kernel/memory/frame.dats +++ b/kernel/memory/frame.dats @@ -2,18 +2,12 @@ #define ATS_DYNLOADFLAG 0 -macdef invalid_area = @{ - base_addr = the_null_ptr, - length = 1, - type = 0u, - reserved = 0 -} - staload "./frame.sats" staload "kernel/bootinfo/multiboot.sats" staload UN = "prelude/SATS/unsafe.sats" + implement containing_address(address) : frame_t = @{ counter = $UN.cast{size_t}(address) / i2sz(PAGE_SIZE) @@ -55,15 +49,20 @@ var frame_allocator : frame_allocator_t in - implement frame_allocator_init() : allocptr = let + implement frame_allocator_init(kernel_start, kernel_end, multiboot_start, multiboot_end, b) : allocptr = let extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (frame_allocator_t@l) // takeout proof UNSAFE: prval (pf, fpf) = __assert (addr@frame_allocator) val allocator = @{ next_free_frame = containing_address(the_null_ptr), - current_area = invalid_area + current_area = invalid_area, + kernel_start = containing_address(kernel_start), + kernel_end = containing_address(kernel_end), + multiboot_start = containing_address(multiboot_start), + multiboot_end = containing_address(multiboot_end) } in - + frame_allocator := allocator; + choose_next_area(pf,b.0 | addr@frame_allocator, b.2); (pf, fpf | addr@frame_allocator) end @@ -81,11 +80,11 @@ implement allocate_frame(pf , bf | p,b) : frame_t = // all frames of current area are used, switch to next area choose_next_area(pf, bf | p,b); allocate_frame(pf,bf | p,b) - ) else if (frame.num > p->kernel_start.num && frame.num <= p->kernel_end.num) then ( + ) else if (frame.num >= p->kernel_start.num && frame.num <= p->kernel_end.num) then ( // frame is used by kernel p->next_free_frame := @{num = p->kernel_end.num + 1}; allocate_frame(pf,bf | p,b) - ) else if (frame.num > p->multiboot_start.num && frame.num <= p->multiboot_end.num) then ( + ) else if (frame.num >= p->multiboot_start.num && frame.num <= p->multiboot_end.num) then ( // frame is used by multiboot info structure p->next_free_frame := @{num = p->multiboot_end.num + 1}; allocate_frame(pf,bf | p,b) |