aboutsummaryrefslogtreecommitdiff
path: root/kernel/memory
diff options
context:
space:
mode:
authorXander <xander@biltopia.org>2023-07-21 22:38:43 +0200
committerXander <xander@biltopia.org>2023-07-21 22:38:43 +0200
commit58096a11ea200d4caf656bac712cde24daa8a697 (patch)
tree41df97b7d352217888804d8b13ae0802beaa5ffd /kernel/memory
parent1d25d9783127c181f79732eb5c20c680444af414 (diff)
downloadats-os-58096a11ea200d4caf656bac712cde24daa8a697.tar.xz
ats-os-58096a11ea200d4caf656bac712cde24daa8a697.zip
Working frame allocator but VERY ugly code
Diffstat (limited to 'kernel/memory')
-rw-r--r--kernel/memory/frame.dats23
-rw-r--r--kernel/memory/frame.sats2
2 files changed, 12 insertions, 13 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)
diff --git a/kernel/memory/frame.sats b/kernel/memory/frame.sats
index 0d29298..d965567 100644
--- a/kernel/memory/frame.sats
+++ b/kernel/memory/frame.sats
@@ -20,4 +20,4 @@ vtypedef allocptr = [l : agz] (frame_allocator_t@l , frame_allocator_t@l -<lin,
fn containing_address {l : addr} (address : ptr l) : frame_t
fn allocate_frame {l : agz}{k : agz} (pf : !frame_allocator_t @ l >> frame_allocator_t @ l, bf : !boot_info_t @ k | p : ptr l, b : ptr k) : frame_t
fn deallocate_frame (p : !allocptr) : void
-fn frame_allocator_init() : allocptr
+fn frame_allocator_init(kernel_start: Ptr, kernel_end: Ptr, multiboot_start:Ptr, multiboot_end: Ptr, b : !bootptr) : allocptr