#include "./prelude/kernel_prelude.hats" staload "kernel/interrupts/idt.sats" staload BOOT = "kernel/bootinfo/multiboot.sats" staload FRAME = "kernel/memory/frame.sats" staload ENTRY = "kernel/memory/paging/entry.sats" staload PAGE = "kernel/memory/paging/page.sats" staload "lib/SATS/valid.sats" staload "lib/DATS/valid.dats" staload "lib/SATS/writer.sats" #define ATS_DYNLOADFLAG 0 %{^ void breakpoint(){ __asm__("int3"); } %} //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 if (kernel_end > the_null_ptr) then if (kernel_start > the_null_ptr) then Ptr12size(kernel_end) - Ptr12size(kernel_start) else i2sz(0) else i2sz(0) end fn test() : void = let val a = sz_to_Ptr0(i2sz(42 * 512 * 512 * 4096)); // 42th P3 entry val page = $PAGE.containing_address(a) val () = println!("page num: ", page.num) val frame = $FRAME.allocate_frame() var flags = @[$ENTRY.entry_flag]($ENTRY.WRITABLE) val () = $PAGE.map_to(page,frame,flags,i2sz(1)) val aframe = $PAGE.translate(a) val frame2 = $FRAME.allocate_frame() (* val () = println!("Map to ", frame.num) *) in if (is_valid(aframe)) then let val vframe = unwrap_valid(aframe) in println!("Got ",vframe) end else ( destroy_unvalid(aframe); println!("Unvalid aframe") ); println!("frame2: ", frame2.num) end extern fun breakpoint() :void = "mac#" extern fun main(p : Ptr1) : void = "ext#" implement main(p) = let val () = $BOOT.init(p); val (kernel_start,kernel_end) = $BOOT.get_kernel_ranges() val (multiboot_start,multiboot_end) = $BOOT.get_multiboot_ranges() val () = $FRAME.init(kernel_start,kernel_end,multiboot_start,multiboot_end); in (* $BOOT.print_memory_mappings(); *) (* $BOOT.print_elf_headers(); *) println!("Kernel Size: ", kernel_size(kernel_start,kernel_end)); test(); // Initialize interrupt table idt_init(); // Throws breakpoint exception breakpoint(); println!("End"); end