From 4cd8d01832be3100b89f9f12a7f828b787e2f901 Mon Sep 17 00:00:00 2001 From: Luca Dariz Date: Sat, 5 Feb 2022 18:51:29 +0100 Subject: fix Task State Segment layout for 64 bit Signed-off-by: Luca Dariz Message-Id: <20220205175129.309469-7-luca@orpolo.org> --- i386/i386/i386asm.sym | 4 ++++ i386/i386/ktss.c | 7 ++++++- i386/i386/pcb.c | 4 ++++ i386/i386/tss.h | 24 ++++++++++++++++++++++-- 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 #include #include /* - * 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. */ -- cgit v1.2.3