summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Dariz <luca.dariz@gmail.com>2022-02-05 18:51:29 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-27 21:09:32 +0200
commit4cd8d01832be3100b89f9f12a7f828b787e2f901 (patch)
tree11d96dcee890778b741456592df958fa95fbfe2c
parenta42ceb867327dfd39147377fbd244df88f5d4d53 (diff)
fix Task State Segment layout for 64 bit
Signed-off-by: Luca Dariz <luca@orpolo.org> Message-Id: <20220205175129.309469-7-luca@orpolo.org>
-rw-r--r--i386/i386/i386asm.sym4
-rw-r--r--i386/i386/ktss.c7
-rw-r--r--i386/i386/pcb.c4
-rw-r--r--i386/i386/tss.h24
4 files changed, 36 insertions, 3 deletions
diff --git a/i386/i386/i386asm.sym b/i386/i386/i386asm.sym
index 9e1d13d7..417c040d 100644
--- a/i386/i386/i386asm.sym
+++ b/i386/i386/i386asm.sym
@@ -95,8 +95,12 @@ offset i386_interrupt_state i eip
offset i386_interrupt_state i cs
offset i386_interrupt_state i efl
+#ifdef __x86_64__
+offset i386_tss tss rsp0
+#else
offset i386_tss tss esp0
offset i386_tss tss ss0
+#endif
offset machine_slot sub_type cpu_type
diff --git a/i386/i386/ktss.c b/i386/i386/ktss.c
index 917e6305..0d21d3eb 100644
--- a/i386/i386/ktss.c
+++ b/i386/i386/ktss.c
@@ -57,9 +57,14 @@ ktss_init(void)
ACC_PL_K|ACC_TSS, 0);
/* Initialize the master TSS. */
+#ifdef __x86_64__
+ ktss.tss.rsp0 = (unsigned long)(exception_stack+1024);
+#else /* ! __x86_64__ */
ktss.tss.ss0 = KERNEL_DS;
ktss.tss.esp0 = (unsigned long)(exception_stack+1024);
- ktss.tss.io_bit_map_offset = IOPB_INVAL;
+#endif /* __x86_64__ */
+
+ ktss.tss.io_bit_map_offset = IOPB_INVAL;
/* Set the last byte in the I/O bitmap to all 1's. */
ktss.barrier = 0xff;
diff --git a/i386/i386/pcb.c b/i386/i386/pcb.c
index 03245848..a261ae1f 100644
--- a/i386/i386/pcb.c
+++ b/i386/i386/pcb.c
@@ -153,7 +153,11 @@ void switch_ktss(pcb_t pcb)
if (hyp_stack_switch(KERNEL_DS, pcb_stack_top))
panic("stack_switch");
#else /* MACH_RING1 */
+#ifdef __x86_64__
+ curr_ktss(mycpu)->tss.rsp0 = pcb_stack_top;
+#else /* __x86_64__ */
curr_ktss(mycpu)->tss.esp0 = pcb_stack_top;
+#endif /* __x86_64__ */
#endif /* MACH_RING1 */
}
diff --git a/i386/i386/tss.h b/i386/i386/tss.h
index ff25f217..31e1f5cb 100644
--- a/i386/i386/tss.h
+++ b/i386/i386/tss.h
@@ -27,13 +27,33 @@
#ifndef _I386_TSS_H_
#define _I386_TSS_H_
+#include <sys/types.h>
#include <mach/inline.h>
#include <machine/io_perm.h>
/*
- * i386 Task State Segment
+ * x86 Task State Segment
*/
+#ifdef __x86_64__
+struct i386_tss {
+ uint32_t _reserved0;
+ uint64_t rsp0;
+ uint64_t rsp1;
+ uint64_t rsp2;
+ uint64_t _reserved1;
+ uint64_t ist1;
+ uint64_t ist2;
+ uint64_t ist3;
+ uint64_t ist4;
+ uint64_t ist5;
+ uint64_t ist6;
+ uint64_t ist7;
+ uint64_t _reserved2;
+ uint16_t _reserved3;
+ uint16_t io_bit_map_offset;
+} __attribute__((__packed__));
+#else /* ! __x86_64__ */
struct i386_tss {
int back_link; /* segment number of previous task,
if nested */
@@ -67,7 +87,7 @@ struct i386_tss {
/* offset to start of IO permission
bit map */
};
-
+#endif /* __x86_64__ */
/* The structure extends the above TSS structure by an I/O permission bitmap
and the barrier. */