diff options
author | Xander <xander@biltopia.org> | 2023-07-11 17:30:25 +0200 |
---|---|---|
committer | Xander <xander@biltopia.org> | 2023-07-11 17:30:25 +0200 |
commit | f44cb1fd2e58f0233dccdf8a1fac84e310857e7e (patch) | |
tree | b4847c063d2a8d5c85d62dafeb4fe9c110ab8b4c | |
parent | d7239440b314c3cfedc6fa840646698d4b30ee88 (diff) | |
download | ats-os-f44cb1fd2e58f0233dccdf8a1fac84e310857e7e.tar.xz ats-os-f44cb1fd2e58f0233dccdf8a1fac84e310857e7e.zip |
Implemented default interrupts
-rw-r--r-- | kernel/interrupts/idt.dats | 81 | ||||
-rw-r--r-- | kernel/interrupts/idt.sats | 10 |
2 files changed, 81 insertions, 10 deletions
diff --git a/kernel/interrupts/idt.dats b/kernel/interrupts/idt.dats index c939875..ba6bb20 100644 --- a/kernel/interrupts/idt.dats +++ b/kernel/interrupts/idt.dats @@ -6,24 +6,60 @@ staload "./idt.sats" staload UN = "prelude/SATS/unsafe.sats" +extern typedef "int_frame" = int_frame + +//----------------------------------No __attribute__ support in ats--------- + %{ __attribute__ ((interrupt)) + void default_exception_handler(int_frame *frame){ + default_exception_handler2(frame); + } + + __attribute__ ((interrupt)) + void default_exception_handler_e(int_frame *frame, uint64_t error_code){ + default_exception_handler_e2(frame, error_code); + } + + __attribute__ ((interrupt)) + void default_interrupt_handler(int_frame *frame, uint64_t error_code){ + default_interrupt_handler_e2(frame, error_code); + } + + __attribute__ ((interrupt)) + void default_interrupt_handler_e(int_frame *frame, uint64_t error_code){ + default_interrupt_handler_e2(frame, error_code); + } %} -// Default exception handler -fun default_exception_handler(frame: &int_frame) : void = let + +// DEFAULT HANDLERS, -------------------------------------------------- + +extern fun default_exception_handler2(frame: &int_frame) : void = "mac#" +implement default_exception_handler2(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 +extern fun default_exception_handler_e2(frame: &int_frame, error_code : uint64) : void = "mac#" +implement default_exception_handler_e2(frame,error_code) = let +in + println!("DEFAULT EXCEPTION HANDLER - WIDTH ERROR CODE"); +end + +extern fun default_interrupt_handler2(frame: &int_frame) : void = "mac#" +implement default_interrupt_handler2(frame) = let +in + println!("DEFAULT INTERRUPT HANDLER - NO ERROR CODE"); +end + +extern fun default_interrupt_handler_e2(frame: &int_frame, error_code : uint64) : void = "mac#" +implement default_interrupt_handler_e2(frame,error_code) = let in - println!("DEFAULT EXCEPTION HANDLER - ERROR CODE") + println!("DEFAULT INTERRUPT HANDLER - WIDTH ERROR CODE"); end +//------------------------------------------------------- + var idt : @[idt_entry_t][IDT_MAX_DESCRIPTORS] // The table var idtr : idtr_t // interrupt descriptor table register instance @@ -55,14 +91,39 @@ extern typedef "idtr_t" = idtr_t extern fun setup(idtr : idtr_t) : void = "ext#" +// Setup exception handlers (vector 0-31) +fun setup_exceptions() = let + fun loop {n : nat | n <= 32} (i : int n) : void = if (i < 32) then ( + idt_set_descriptor(i,$UN.cast( + case+ i of + | _ when i = 8 || i = 10 || i = 11 || i = 12 + || i = 13 || i = 14 || i = 17 || i = 22 => default_exception_handler_e + | _ => default_exception_handler + ),$UN.cast(TRAP_GATE_FLAGS)); + loop(i + 1) + ) +in +loop(0) +end + +// Setup trap interrupts (vector 32-255) +fun setup_interrupts() = let + fun loop {n : nat | n <= IDT_MAX_DESCRIPTORS && n >= 32} (i : int n) : void = if (i < IDT_MAX_DESCRIPTORS - 1) then ( + idt_set_descriptor(i,$UN.cast(default_interrupt_handler),$UN.cast(INT_GATE_FLAGS)); + loop(i + 1) + ) +in +loop(32) +end + implement idt_init() : void = let extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (idtr_t@l) prval (pf, fpf) = __assert (addr@(idtr)) - fun loop {n : nat | n <= 32} (i : int n) : void = if (i < 32) then (idt_set_descriptor(i,$UN.cast(default_exception_handler),$UN.cast(TRAP_GATE_FLAGS)); loop(i + 1)) in idtr.base := addr@(idt); idtr.limit := $UN.cast(8 * IDT_MAX_DESCRIPTORS); - loop(0); + setup_exceptions(); + setup_interrupts(); setup(idtr); let prval () = fpf(pf) in end end diff --git a/kernel/interrupts/idt.sats b/kernel/interrupts/idt.sats index b8ee06d..46f56d9 100644 --- a/kernel/interrupts/idt.sats +++ b/kernel/interrupts/idt.sats @@ -30,4 +30,14 @@ typedef int_frame = @{ ss = [l : agz] ptr l // stack segment } +// ------- Default handlers (exceptions and interrupts) + +fun default_exception_handler(frame: &int_frame) : void = "mac#" +fun default_exception_handler_e(frame: &int_frame, error_code : uint64) : void = "mac#" + +fun default_interrupt_handler(frame: &int_frame) : void = "mac#" +fun default_interrupt_handler_e(frame: &int_frame, error_code : uint64) : void = "mac#" + +// ------- + fun idt_init() : void |