aboutsummaryrefslogtreecommitdiff
path: root/kernel/main.dats
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/main.dats
parent1d25d9783127c181f79732eb5c20c680444af414 (diff)
downloadats-os-58096a11ea200d4caf656bac712cde24daa8a697.tar.xz
ats-os-58096a11ea200d4caf656bac712cde24daa8a697.zip
Working frame allocator but VERY ugly code
Diffstat (limited to 'kernel/main.dats')
-rw-r--r--kernel/main.dats19
1 files changed, 17 insertions, 2 deletions
diff --git a/kernel/main.dats b/kernel/main.dats
index c57f53d..ecbbb40 100644
--- a/kernel/main.dats
+++ b/kernel/main.dats
@@ -4,10 +4,9 @@
staload "kernel/interrupts/idt.sats"
staload "kernel/bootinfo/multiboot.sats"
+staload "kernel/memory/frame.sats"
staload "lib/SATS/writer.sats"
-staload UN = "prelude/SATS/unsafe.sats"
-
%{^
void breakpoint(){
__asm__("int3");
@@ -15,6 +14,7 @@ staload UN = "prelude/SATS/unsafe.sats"
%}
//NOTE: how to make sure ats checks 2 contstraints in one if statement?
+//TODO: put in seperate utils module (just generic size function)
fn kernel_size(kernel_start : Ptr, kernel_end : Ptr) : size_t = let
extern castfn Ptr12size (a : Ptr1): size_t
in
@@ -27,6 +27,12 @@ in
i2sz(0)
end
+fn test(allocptr : !allocptr, bootptr : !bootptr) : void = let
+ fun loop(i : int) : void = if (i < 160) then( let val _ = allocate_frame(allocptr.0, bootptr.0 | allocptr.2, bootptr.2) in end; loop(succ(i)))
+in
+ loop(0)
+end
+
extern fun breakpoint() :void = "mac#"
@@ -37,12 +43,20 @@ implement main(p) = let
// Initialize boot info struct
val bootptr = boot_info_init(p)
val (kernel_start,kernel_end) = get_kernel_ranges(bootptr)
+ val (multiboot_start,multiboot_end) = get_multiboot_ranges(bootptr)
+ val allocptr = frame_allocator_init(kernel_start,kernel_end,multiboot_start,multiboot_end,bootptr)
in
print_memory_mappings(bootptr);
print_elf_headers(bootptr);
println!("Kernel Size: ", kernel_size(kernel_start,kernel_end));
+ test(allocptr,bootptr);
+ let
+ val frame = allocate_frame(allocptr.0, bootptr.0 | allocptr.2, bootptr.2)
+ in
+ println!(frame.num)
+ end;
// Initialize interrupt table
idt_init();
@@ -55,6 +69,7 @@ in
let
prval () = bootptr.1(bootptr.0)
+ prval () = allocptr.1(allocptr.0)
in end