aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/tss.dats20
-rw-r--r--kernel/tss.sats48
2 files changed, 68 insertions, 0 deletions
diff --git a/kernel/tss.dats b/kernel/tss.dats
new file mode 100644
index 0000000..e4569d6
--- /dev/null
+++ b/kernel/tss.dats
@@ -0,0 +1,20 @@
+#include "kernel/prelude/kernel_prelude.hats"
+
+#define ATS_DYNLOADFLAG 0
+
+staload "./tss.sats"
+
+staload UN = "prelude/SATS/unsafe.sats"
+
+var tss : tss_t // Task State Segment
+var stack1 : stack // Double fault stack
+
+implement tss_init() : void = let
+ extern praxi __assert{l:addr} (ptr: ptr (l)): vtakeout0 (tss_t@l)
+ prval (pf, fpf) = __assert (addr@(tss)) // takeout proof UNSAFE:
+ val sp1 = @{a = ptr_add<uint8>(addr@(stack1),STACK_SIZE)}
+in
+ tss.ist.IS1 := sp1;
+ let prval () = fpf(pf) in end
+end
+
diff --git a/kernel/tss.sats b/kernel/tss.sats
new file mode 100644
index 0000000..e5016a8
--- /dev/null
+++ b/kernel/tss.sats
@@ -0,0 +1,48 @@
+#define
+STACK_SIZE 4096
+
+// Stack pointer
+typedef sp_t = @{
+ (* low = uint32, // The higher 32 bits of stack pointer *)
+ (* high = uint32 /// The lower 32 bits of stack pointer *)
+ a = [l : addr] ptr l
+}
+
+// Interrupt Stack table
+typedef ist_t = @{
+ IS1 = sp_t, // Interrupt stack pointer 1
+ IS2 = sp_t, // Interrupt stack pointer 2
+ IS3 = sp_t, // Interrupt stack pointer 3
+ IS4 = sp_t, // Interrupt stack pointer 4
+ IS5 = sp_t, // Interrupt stack pointer 5
+ IS6 = sp_t, // Interrupt stack pointer 6
+ IS7 = sp_t // Interrupt stack pointer 7
+}
+
+// Privilege change stack table
+typedef rst_t = @{
+ RSP0 = sp_t, // Points to stack with privilege level 0
+ RSP1 = sp_t, // Points to stack with privilege level 1
+ RSP2 = sp_t // Points to stack with privilege level 2
+}
+
+// I/O Permission Bitmap
+typedef iopb_t = uint16
+
+//Task state segment
+typedef tss_t = @{
+ r1 = uint32 0, // Reserved space
+ rst = rst_t,
+ r2 = uint32 0, // Reserved space
+ r3 = uint32 0, // Reserved space
+ ist = ist_t,
+ r4 = uint32 0, // Reserved space
+ r5 = uint32 0, // Reserved space
+ r6 = uint16 0, // Reserved space
+ iopb = iopb_t
+}
+
+typedef stack = @[uint8][STACK_SIZE]
+
+fun tss_init() : void
+