aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/interrupts/idt.dats16
-rw-r--r--kernel/interrupts/idt.sats15
2 files changed, 17 insertions, 14 deletions
diff --git a/kernel/interrupts/idt.dats b/kernel/interrupts/idt.dats
index fa141f6..c939875 100644
--- a/kernel/interrupts/idt.dats
+++ b/kernel/interrupts/idt.dats
@@ -24,21 +24,21 @@ in
println!("DEFAULT EXCEPTION HANDLER - ERROR CODE")
end
-var idt : @[idt_entry_t][256] // The table
+var idt : @[idt_entry_t][IDT_MAX_DESCRIPTORS] // The table
var idtr : idtr_t // interrupt descriptor table register instance
-fun idt_set_descriptor {l:addr} {n : nat | n < 256} (vector: int n, isr: (&int_frame) -> void, flags: uint8) : void = let
- extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (@[idt_entry_t][256]@l)
+fun idt_set_descriptor {n : nat | n < IDT_MAX_DESCRIPTORS} (vector: int n, isr: uint64, flags: uint8) : void = let
+ extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (@[idt_entry_t][IDT_MAX_DESCRIPTORS]@l)
prval (pf, fpf) = __assert (addr@(idt))
val x = $UN.cast{uint64}(0xFFFF)
val y = $UN.cast{uint64}(0xFFFFFFF)
val entry = @{
- isr_low = $UN.cast($UN.cast{uint64}(isr) land x),
+ isr_low = $UN.cast(isr land x),
kernel_cs = $UN.cast(0x08),
ist = $UN.cast(0),
attributes = flags,
- isr_mid = $UN.cast(($UN.cast{uint64}(isr) >> 16) land x),
- isr_high = $UN.cast(($UN.cast{uint64}(isr) >> 32) land y),
+ isr_mid = $UN.cast((isr >> 16) land x),
+ isr_high = $UN.cast((isr >> 32) land y),
reserved = $UN.cast(0)
}
in
@@ -58,10 +58,10 @@ extern fun setup(idtr : idtr_t) : void = "ext#"
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,default_exception_handler,$UN.cast(TRAP_GATE_FLAGS)); loop(i + 1))
+ 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{uint16}(8 * 256);
+ idtr.limit := $UN.cast(8 * IDT_MAX_DESCRIPTORS);
loop(0);
setup(idtr);
let prval () = fpf(pf) in end
diff --git a/kernel/interrupts/idt.sats b/kernel/interrupts/idt.sats
index ce40cd8..b8ee06d 100644
--- a/kernel/interrupts/idt.sats
+++ b/kernel/interrupts/idt.sats
@@ -2,6 +2,9 @@
TRAP_GATE_FLAGS 0x8F // p=1, dpl=0b00, type=0b1111
#define
INT_GATE_FLAGS 0x8E // p=1, dpl=0b00, type=0b1110
+#define
+IDT_MAX_DESCRIPTORS 256
+
typedef idt_entry_t = @{
isr_low = uint16, // The lower 16 bits of the ISR's address
@@ -14,17 +17,17 @@ typedef idt_entry_t = @{
}
typedef idtr_t = @{
- limit = uint16,
+ limit = uint16 (8 * IDT_MAX_DESCRIPTORS),
base = [l : addr] ptr l
}
// Interrupt frame to pass to ISR
-typedef int_frame = @{
- ip = uint64, // instruction pointer
- cs = uint64, // code segment
+typedef int_frame = @{
+ ip = [l : agz] ptr l, // instruction pointer
+ cs = [l : agz] ptr l, // code segment
rflags = uint64,
- sp = uint64, // stack pointer
- ss = uint64 // stack segment
+ sp = [l : agz] ptr l, // stack pointer
+ ss = [l : agz] ptr l // stack segment
}
fun idt_init() : void