aboutsummaryrefslogtreecommitdiff
path: root/kernel/main.dats
blob: c57f53d89d35713aff47ced867e1afa70f60b6c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "./prelude/kernel_prelude.hats"

#define ATS_DYNLOADFLAG 0

staload "kernel/interrupts/idt.sats"
staload "kernel/bootinfo/multiboot.sats"
staload "lib/SATS/writer.sats"

staload UN = "prelude/SATS/unsafe.sats"

%{^
  void breakpoint(){ 
    __asm__("int3");
  }
%}

//NOTE: how to make sure ats checks 2 contstraints in one if statement?
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


extern fun breakpoint() :void  = "mac#"

extern fun main(p : Ptr1) : void = "ext#"
implement  main(p) = let
  val () = clear_screen()

  // Initialize boot info struct
  val bootptr = boot_info_init(p) 
  val (kernel_start,kernel_end) = get_kernel_ranges(bootptr)
in

  print_memory_mappings(bootptr);

  print_elf_headers(bootptr);
  println!("Kernel Size: ", kernel_size(kernel_start,kernel_end));

  // Initialize interrupt table
  idt_init();

  // Throws breakpoint exception
  breakpoint();


  println!("End");

  let
    prval () = bootptr.1(bootptr.0)
  in end


end