From cef3f6bdddfe768e7a1a84edcec76c11c1634941 Mon Sep 17 00:00:00 2001 From: Xander Date: Sun, 6 Aug 2023 17:44:45 +0200 Subject: Implemented panic --- kernel/bootinfo/multiboot.dats | 24 +++++++++++++----------- kernel/bootinfo/multiboot.sats | 14 +++++++------- kernel/main.dats | 4 ++-- lib/DATS/init.dats | 23 ++++++++++++++++------- lib/DATS/panic.dats | 24 ++++++++++++++++++++++++ lib/SATS/init.sats | 4 ++-- lib/SATS/panic.sats | 5 +++++ 7 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 lib/DATS/panic.dats create mode 100644 lib/SATS/panic.sats diff --git a/kernel/bootinfo/multiboot.dats b/kernel/bootinfo/multiboot.dats index 9fe9103..cf72ba7 100644 --- a/kernel/bootinfo/multiboot.dats +++ b/kernel/bootinfo/multiboot.dats @@ -28,9 +28,9 @@ in implement init (p : Ptr1) = let val total_size = g1ofg0($UN.ptr0_get(p)) - fun loop {n,i : nat | i < n} .. (boot_info : &boot_info_t? >> boot_info_t, p : ptr, i: uint i, n: uint n): void = let + fun loop (boot_info : &boot_info_t? >> boot_info_t, p : ptr): void = let extern castfn unsafe_init(x : &boot_info_t? >> boot_info_t) :<> void - val type = $UN.ptr0_get(p) + val type= $UN.ptr0_get(p) val size = $UN.ptr0_get(ptr_succ(p)) val next = (if (size % 8u != 0) then size + 8u - (size % 8u) else size) : uint in @@ -45,8 +45,8 @@ in ) | _ => (); - if (i < n - 1u) then - loop(boot_info,ptr_add(p, next),succ(i),n) + if (type != 0u) then + loop(boot_info,ptr_add(p, next)) else unsafe_init(boot_info) end @@ -54,23 +54,25 @@ in implement initialize$fwork(v) = ( if (total_size > 0u) then ( v.total_size := total_size; - loop(v, ptr_add(p,2),0u,total_size); + $effmask_ntm(loop(v, ptr_add(p,2))); let prval () = opt_some v in true end) else let prval () = opt_none v in false end ) - in end + in + initialize(bootinfo_ref) + end implement get_memory_mappings_n() = let - implement exec$fwork(v,_) = _get_memory_mappings_n(v) + implement exec$fwork(v) = _get_memory_mappings_n(v) in - exec(bootinfo_ref,i2sz(0)) + exec(bootinfo_ref) end implement get_memory_mapping(n) = let - implement exec$fwork(v,_) = _get_memory_mapping(v,n) + implement exec$fwork(v) = _get_memory_mapping(v,n) in - exec(bootinfo_ref,invalid_area) + exec(bootinfo_ref) end implement print_memory_mappings() = let @@ -123,7 +125,7 @@ end //---------------------------------------------- (* //---------------------ELF---------------------- *) -(**) + (* implement get_elf_headers_n(p) = ui2sz p.2->elf_tag.num *) (**) (* implement get_elf_header (p,n) = ( *) diff --git a/kernel/bootinfo/multiboot.sats b/kernel/bootinfo/multiboot.sats index 6be1e73..9a41f29 100644 --- a/kernel/bootinfo/multiboot.sats +++ b/kernel/bootinfo/multiboot.sats @@ -54,14 +54,14 @@ macdef invalid_area = @{ fun init(p : Ptr1) :void -fn get_memory_mappings_n () : [n:nat] size_t n +fn get_memory_mappings_n () : size_t fn get_memory_mapping (n : size_t) : memory_area_t fn print_memory_mappings () : void // Print all available memory area's -(* fn get_elf_headers_n () : [n:nat] size_t n *) -(* fn get_elf_header (n : size_t) : elf64_shdr_t *) -(* fn print_elf_headers () : void *) -(**) -(* fn get_kernel_ranges () : (Ptr,Ptr) // (kernel start, kernel end) *) -(* fn get_multiboot_ranges () : (Ptr0,Ptr0) // (bootinfo start, bootinfo end) *) +fn get_elf_headers_n () : [n:nat] size_t n +fn get_elf_header (n : size_t) : elf64_shdr_t +fn print_elf_headers () : void + +fn get_kernel_ranges () : (Ptr,Ptr) // (kernel start, kernel end) +fn get_multiboot_ranges () : (Ptr0,Ptr0) // (bootinfo start, bootinfo end) diff --git a/kernel/main.dats b/kernel/main.dats index 4c7d49a..7b7c162 100644 --- a/kernel/main.dats +++ b/kernel/main.dats @@ -38,13 +38,13 @@ extern fun breakpoint() :void = "mac#" extern fun entry(p : Ptr1) : void = "ext#" implement entry(p) = let - // Initialize boot info struct - val () = $BOOT.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 + // Initialize boot info struct + $BOOT.init(p); clear_screen(); $BOOT.print_memory_mappings(); diff --git a/lib/DATS/init.dats b/lib/DATS/init.dats index cfdc12e..c2ae39d 100644 --- a/lib/DATS/init.dats +++ b/lib/DATS/init.dats @@ -1,5 +1,7 @@ #include "share/atspre_staload.hats" staload "lib/SATS/init.sats" +staload "lib/SATS/panic.sats" +staload UN = "prelude/SATS/unsafe.sats" #define ATS_DYNLOADFLAG 0 @@ -20,26 +22,33 @@ in prval () = opt_some p->obj in end + else + panic("Not initialized") end -implement{vt} exec_void$fwork (v) = () +implement{vt} exec_void$fwork (v) = panic("Not overloaded") -implement{vt} {a} exec (r,default) = let +implement{vt} {a} exec (r) = let val (vbox pf | p) = ref_get_viewptr{initializable vt}(r) in if p->initialized then let prval () = opt_unsome p->obj - val a = exec$fwork (p->obj,default) + val out = exec$fwork (p->obj) prval () = opt_some p->obj in - a + out end - else - default + else ( + panic("Not inialized"); + $UN.ptr0_get(the_null_ptr) + ) end -implement{vt} {a} exec$fwork (v,default) = default +implement{vt} {a} exec$fwork (v) = ( + (panic("Not overloaded")); + $UN.ptr0_get(the_null_ptr) +) implement{vt} initialize (r) = let val (vbox pf | p) = ref_get_viewptr{initializable vt}(r) diff --git a/lib/DATS/panic.dats b/lib/DATS/panic.dats new file mode 100644 index 0000000..356eda5 --- /dev/null +++ b/lib/DATS/panic.dats @@ -0,0 +1,24 @@ +staload "lib/SATS/panic.sats" +staload "lib/SATS/writer.sats" + +staload UN = "prelude/SATS/unsafe.sats" + +#define ATS_DYNLOADFLAG 0 + +%{$ + inline void halt() { + while (1){ + __asm__ volatile ("cli ; hlt"); + } + } +%} + +extern fun halt(): void = "mac#" + +implement panic_loc(loc,msg) = ( + put_string "KERNEL PANIC:\n "; + put_string loc; + put_string "\n\n "; + put_string msg; + halt(); +) diff --git a/lib/SATS/init.sats b/lib/SATS/init.sats index 9261ca9..69c6c9a 100644 --- a/lib/SATS/init.sats +++ b/lib/SATS/init.sats @@ -6,8 +6,8 @@ fun {vt:viewt@ype} uninitialized (v : opt(vt,false)): initializable vt fun {vt:viewt@ype} exec_void (r: ref(initializable vt)): void fun {vt:viewt@ype} exec_void$fwork (v : &vt): void -fun {vt:viewt@ype} {a: t@ype} exec (r: ref(initializable vt), default: a): a -fun {vt:viewt@ype} {a: t@ype} exec$fwork (v : &vt, default: a): a +fun {vt:viewt@ype} {a: t@ype} exec (r: ref(initializable vt)): a +fun {vt:viewt@ype} {a: t@ype} exec$fwork (v : &vt): a fun {vt:viewt@ype} initialize (r: ref(initializable vt)): void fun {vt:viewt@ype} initialize$fwork (v: &vt? >> opt(vt,success)): #[success : bool] bool success diff --git a/lib/SATS/panic.sats b/lib/SATS/panic.sats new file mode 100644 index 0000000..123b8da --- /dev/null +++ b/lib/SATS/panic.sats @@ -0,0 +1,5 @@ +staload UN = "prelude/SATS/unsafe.sats" + +fun panic_loc (loc: string, msg: string) :<> void + +macdef panic(msg) = panic_loc($mylocation, ,(msg)) -- cgit v1.2.3