aboutsummaryrefslogtreecommitdiff
path: root/kernel/interrupts/idt.dats
blob: 380260a884f2ec90c111516389b160193ff7a4c0 (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
#include "kernel/kernel_prelude.hats"

#define ATS_DYNLOADFLAG 0

staload "./idt.sats"

extern castfn i2u8 {n: nat} (i: int n): uint8 n
extern castfn i2u16 {n: nat} (i: int n): uint16 n
extern castfn i2u32 {n: nat} (i: int n): uint32 n
extern castfn i2u64 {n: nat} (i: int n): uint64 n
extern castfn i2u {n: int} (i: uint8 n): int n

%{
  __attribute__ ((interrupt))
%}
// Default exception handler
fun default_exception_handler(frame: &int_frame) : void = let 
in
  println!("DEFAULT EXCEPTION HANDLER - NO ERROR CODE")
end


%{
  __attribute__ ((interrupt))
%}
// Default exception handler (with error code)
fun default_exception_handler_e(frame: &int_frame, error_code : uint64) : void = let 
in
  println!("DEFAULT EXCEPTION HANDLER - ERROR CODE")
end

var idt : @[idt_entry_t][256] // The table
var idtr : idtr_t // interrupt descriptor table register instance

fun idt_set_descriptor {l : agz} {n : nat | n < 256} (vector: uint8 n, isr: ptr l, flags: uint8) : void = let
  extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (@[idt_entry_t][256]@l)
  prval (pf, fpf) = __assert (addr@(idt))
  val t = @{
    isr_low = i2u16(0), 
    kernel_cs = i2u16(0) , 
    ist = i2u8(0), 
    attributes = i2u8(0) , 
    isr_mid = i2u16(0), 
    isr_high = i2u32(0), 
    reserved = i2u32(0)
  }
in
  idt[i2u(vector)] := t;
  let prval () = fpf(pf) in end
end

implement idt_init() : void = let in end