- Use static IDT entries generated through a macro, instead of dynamically allocating them each boot. Note that we do not store them in an i386 compatible format, but much like NT, swap the bits so that our macro can more clearly define each entry.

svn path=/trunk/; revision=20938
This commit is contained in:
Alex Ionescu 2006-01-17 17:28:41 +00:00
parent bc2e6ca915
commit d8582ed67b
8 changed files with 104 additions and 144 deletions

View file

@ -440,11 +440,10 @@ typedef struct _KIPCR
ULONG IrrActive; /* 2C */ ULONG IrrActive; /* 2C */
ULONG IDR; /* 30 */ ULONG IDR; /* 30 */
PVOID KdVersionBlock; /* 34 */ PVOID KdVersionBlock; /* 34 */
PKIDTENTRY IDT; /* 38 */
#ifdef _REACTOS_ #ifdef _REACTOS_
PUSHORT IDT; /* 38 */
PUSHORT GDT; /* 3C */ PUSHORT GDT; /* 3C */
#else #else
PKIDTENTRY IDT; /* 38 */
PKGDTENTRY GDT; /* 3C */ PKGDTENTRY GDT; /* 3C */
#endif #endif
struct _KTSS *TSS; /* 40 */ struct _KTSS *TSS; /* 40 */

View file

@ -22,6 +22,10 @@
#define DoNotRestoreSegments 0 #define DoNotRestoreSegments 0
#define DoNotRestoreVolatiles 0 #define DoNotRestoreVolatiles 0
// Arguments for idt
#define INT_32_DPL0 0x8E00
#define INT_32_DPL3 0xEE00
.intel_syntax noprefix .intel_syntax noprefix
// //
@ -59,6 +63,22 @@
#define RELEASE_SPINLOCK(x) #define RELEASE_SPINLOCK(x)
#endif #endif
//
// @name SET_TF_DEBUG_HEADER
//
// This macro sets up the debug header in the trap frame.
//
// @param None.
//
// @remark ebp = PKTRAP_FRAME.
// edi/ebx = Have been saved and can be used.
//
.macro idt Handler, Bits
.long \Handler
.short \Bits
.short KGDT_R0_CODE
.endm
// //
// @name SET_TF_DEBUG_HEADER // @name SET_TF_DEBUG_HEADER
// //

View file

@ -46,8 +46,6 @@ typedef struct __DESCRIPTOR
} IDT_DESCRIPTOR, GDT_DESCRIPTOR; } IDT_DESCRIPTOR, GDT_DESCRIPTOR;
#include <poppack.h> #include <poppack.h>
extern IDT_DESCRIPTOR KiIdt[256];
//extern GDT_DESCRIPTOR KiGdt[256]; //extern GDT_DESCRIPTOR KiGdt[256];
/* /*

View file

@ -9,6 +9,14 @@
* Skywing (skywing@valhallalegends.com) * Skywing (skywing@valhallalegends.com)
*/ */
/*
* FIXMES:
* - Clean up file (remove all stack functions and use RtlWalkFrameChain/RtlCaptureStackBacktrace)
* - Sanitize some context fields.
* - Add PSEH handler when an exception occurs in an exception (KiCopyExceptionRecord).
* - Forward exceptions to user-mode debugger.
*/
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ntoskrnl.h> #include <ntoskrnl.h>
@ -20,19 +28,13 @@
#pragma alloc_text(INIT, KeInitExceptions) #pragma alloc_text(INIT, KeInitExceptions)
#endif #endif
/*
* FIXMES:
* - Clean up file.
* - Sanitize some context fields.
* - Add PSEH handler when an exception occurs in an exception (KiCopyExceptionRecord).
* - Implement official stack trace functions (exported) and remove stuff here.
* - Forward exceptions to user-mode debugger.
*/
VOID VOID
NTAPI NTAPI
Ki386AdjustEsp0(IN PKTRAP_FRAME TrapFrame); Ki386AdjustEsp0(
IN PKTRAP_FRAME TrapFrame
);
extern KIDTENTRY KiIdt[];
/* GLOBALS *****************************************************************/ /* GLOBALS *****************************************************************/
@ -45,31 +47,6 @@ Ki386AdjustEsp0(IN PKTRAP_FRAME TrapFrame);
# define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0])) # define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
#endif #endif
extern void KiSystemService(void);
extern void KiDebugService(void);
extern VOID KiTrap0(VOID);
extern VOID KiTrap1(VOID);
extern VOID KiTrap2(VOID);
extern VOID KiTrap3(VOID);
extern VOID KiTrap4(VOID);
extern VOID KiTrap5(VOID);
extern VOID KiTrap6(VOID);
extern VOID KiTrap7(VOID);
extern VOID KiTrap8(VOID);
extern VOID KiTrap9(VOID);
extern VOID KiTrap10(VOID);
extern VOID KiTrap11(VOID);
extern VOID KiTrap12(VOID);
extern VOID KiTrap13(VOID);
extern VOID KiTrap14(VOID);
extern VOID KiTrap15(VOID);
extern VOID KiTrap16(VOID);
extern VOID KiTrap17(VOID);
extern VOID KiTrap18(VOID);
extern VOID KiTrap19(VOID);
extern VOID KiTrapUnknown(VOID);
extern ULONG init_stack; extern ULONG init_stack;
extern ULONG init_stack_top; extern ULONG init_stack_top;
@ -389,7 +366,7 @@ KiDoubleFaultHandler(VOID)
if (StackRepeatLength[i] == 0) if (StackRepeatLength[i] == 0)
{ {
for(;;); for(;;);
} }
for (j = 0; j < StackRepeatLength[i]; j++) for (j = 0; j < StackRepeatLength[i]; j++)
{ {
KeRosPrintAddress(StackTrace[i + j]); KeRosPrintAddress(StackTrace[i + j]);
@ -1168,83 +1145,24 @@ KeRosGetStackFrames ( PULONG Frames, ULONG FrameCount )
return Count; return Count;
} }
static void
set_system_call_gate(unsigned int sel, unsigned int func)
{
DPRINT("sel %x %d\n",sel,sel);
KiIdt[sel].a = (((int)func)&0xffff) +
(KGDT_R0_CODE << 16);
KiIdt[sel].b = 0xef00 + (((int)func)&0xffff0000);
DPRINT("idt[sel].b %x\n",KiIdt[sel].b);
}
static void set_interrupt_gate(unsigned int sel, unsigned int func)
{
DPRINT("set_interrupt_gate(sel %d, func %x)\n",sel,func);
KiIdt[sel].a = (((int)func)&0xffff) +
(KGDT_R0_CODE << 16);
KiIdt[sel].b = 0x8e00 + (((int)func)&0xffff0000);
}
static void set_trap_gate(unsigned int sel, unsigned int func, unsigned int dpl)
{
DPRINT("set_trap_gate(sel %d, func %x, dpl %d)\n",sel, func, dpl);
ASSERT(dpl <= 3);
KiIdt[sel].a = (((int)func)&0xffff) +
(KGDT_R0_CODE << 16);
KiIdt[sel].b = 0x8f00 + (dpl << 13) + (((int)func)&0xffff0000);
}
static void
set_task_gate(unsigned int sel, unsigned task_sel)
{
KiIdt[sel].a = task_sel << 16;
KiIdt[sel].b = 0x8500;
}
VOID VOID
INIT_FUNCTION INIT_FUNCTION
NTAPI NTAPI
KeInitExceptions(VOID) KeInitExceptions(VOID)
/*
* FUNCTION: Initalize CPU exception handling
*/
{ {
int i; ULONG i;
USHORT FlippedSelector;
DPRINT("KeInitExceptions()\n"); /* Loop the IDT */
for (i = 0; i <= MAXIMUM_IDTVECTOR; i ++)
/*
* Set up the other gates
*/
set_trap_gate(0, (ULONG)KiTrap0, 0);
set_trap_gate(1, (ULONG)KiTrap1, 0);
set_trap_gate(2, (ULONG)KiTrap2, 0);
set_trap_gate(3, (ULONG)KiTrap3, 3);
set_trap_gate(4, (ULONG)KiTrap4, 0);
set_trap_gate(5, (ULONG)KiTrap5, 0);
set_trap_gate(6, (ULONG)KiTrap6, 0);
set_trap_gate(7, (ULONG)KiTrap7, 0);
set_task_gate(8, KGDT_DF_TSS);
set_trap_gate(9, (ULONG)KiTrap9, 0);
set_trap_gate(10, (ULONG)KiTrap10, 0);
set_trap_gate(11, (ULONG)KiTrap11, 0);
set_trap_gate(12, (ULONG)KiTrap12, 0);
set_trap_gate(13, (ULONG)KiTrap13, 0);
set_interrupt_gate(14, (ULONG)KiTrap14);
set_trap_gate(15, (ULONG)KiTrap15, 0);
set_trap_gate(16, (ULONG)KiTrap16, 0);
set_trap_gate(17, (ULONG)KiTrap17, 0);
set_trap_gate(18, (ULONG)KiTrap18, 0);
set_trap_gate(19, (ULONG)KiTrap19, 0);
for (i = 20; i < 256; i++)
{ {
set_trap_gate(i,(int)KiTrapUnknown, 0); /* Save the current Selector */
} FlippedSelector = KiIdt[i].Selector;
set_system_call_gate(0x2d,(int)KiDebugService); /* Flip Selector and Extended Offset */
set_system_call_gate(0x2e,(int)KiSystemService); KiIdt[i].Selector = KiIdt[i].ExtendedOffset;
KiIdt[i].ExtendedOffset = FlippedSelector;
}
} }
VOID VOID

View file

@ -131,6 +131,7 @@ static ISR_TABLE IsrTable[NR_IRQS][1];
#endif #endif
#define TAG_ISR_LOCK TAG('I', 'S', 'R', 'L') #define TAG_ISR_LOCK TAG('I', 'S', 'R', 'L')
extern IDT_DESCRIPTOR KiIdt[256];
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/

View file

@ -31,7 +31,7 @@ ULONG KeI386XMMIPresent = 0;
ULONG KeI386FxsrPresent = 0; ULONG KeI386FxsrPresent = 0;
extern PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS]; extern PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS];
extern ULONG IdleProcessorMask; extern ULONG IdleProcessorMask;
extern KIDTENTRY KiIdt[256];
static VOID INIT_FUNCTION Ki386GetCpuId(VOID); static VOID INIT_FUNCTION Ki386GetCpuId(VOID);
#if defined (ALLOC_PRAGMA) #if defined (ALLOC_PRAGMA)
@ -309,7 +309,7 @@ KeInit1(PCHAR CommandLine, PULONG LastKernelAddress)
KPCR->Irql = SYNCH_LEVEL; KPCR->Irql = SYNCH_LEVEL;
KPCR->NtTib.Self = &KPCR->NtTib; KPCR->NtTib.Self = &KPCR->NtTib;
KPCR->GDT = KiBootGdt; KPCR->GDT = KiBootGdt;
KPCR->IDT = (PUSHORT)KiIdt; KPCR->IDT = KiIdt;
KPCR->TSS = &KiBootTss; KPCR->TSS = &KiBootTss;
KPCR->Number = 0; KPCR->Number = 0;
KPCR->SetMember = 1 << 0; KPCR->SetMember = 1 << 0;

View file

@ -20,44 +20,52 @@
* - Handle failure after PsConvertToGuiThread. * - Handle failure after PsConvertToGuiThread.
* - Figure out what the DEBUGEIP hack is for and how it can be moved away. * - Figure out what the DEBUGEIP hack is for and how it can be moved away.
* - Add DR macro/save and VM macro/save. * - Add DR macro/save and VM macro/save.
* - Add .func .endfunc to everything that doesn't have it yet.
* - Implement KiCallbackReturn, KiGetTickCount, KiRaiseAssertion. * - Implement KiCallbackReturn, KiGetTickCount, KiRaiseAssertion.
*/ */
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
.globl _KiIdt
_KiIdt:
/* This is the Software Interrupt Table that we handle in this file: */ /* This is the Software Interrupt Table that we handle in this file: */
.globl _KiTrap0 /* INT 0: Divide Error (#DE) */ idt _KiTrap0, INT_32_DPL0 /* INT 00: Divide Error (#DE) */
.globl _KiTrap1 /* INT 1: Debug Exception (#DB) */ idt _KiTrap1, INT_32_DPL0 /* INT 01: Debug Exception (#DB) */
.globl _KiTrap2 /* INT 2: NMI Interrupt */ idt _KiTrap2, INT_32_DPL0 /* INT 02: NMI Interrupt */
.globl _KiTrap3 /* INT 3: Breakpoint Exception (#BP) */ idt _KiTrap3, INT_32_DPL3 /* INT 03: Breakpoint Exception (#BP) */
.globl _KiTrap4 /* INT 4: Overflow Exception (#OF) */ idt _KiTrap4, INT_32_DPL3 /* INT 04: Overflow Exception (#OF) */
.globl _KiTrap5 /* INT 5: BOUND Range Exceeded (#BR) */ idt _KiTrap5, INT_32_DPL0 /* INT 05: BOUND Range Exceeded (#BR) */
.globl _KiTrap6 /* INT 6: Invalid Opcode Code (#UD) */ idt _KiTrap6, INT_32_DPL0 /* INT 06: Invalid Opcode Code (#UD) */
.globl _KiTrap7 /* INT 7: Device Not Available (#NM) */ idt _KiTrap7, INT_32_DPL0 /* INT 07: Device Not Available (#NM) */
.globl _KiTrap8 /* INT 8: Double Fault Exception (#DF) */ idt _KiTrap8, INT_32_DPL0 /* INT 08: Double Fault Exception (#DF) */
.globl _KiTrap9 /* INT 9: RESERVED */ idt _KiTrap9, INT_32_DPL0 /* INT 09: RESERVED */
.globl _KiTrap10 /* INT 10: Invalid TSS Exception (#TS) */ idt _KiTrap10, INT_32_DPL0 /* INT 0A: Invalid TSS Exception (#TS) */
.globl _KiTrap11 /* INT 11: Segment Not Present (#NP) */ idt _KiTrap11, INT_32_DPL0 /* INT 0B: Segment Not Present (#NP) */
.globl _KiTrap12 /* INT 12: Stack Fault Exception (#SS) */ idt _KiTrap12, INT_32_DPL0 /* INT 0C: Stack Fault Exception (#SS) */
.globl _KiTrap13 /* INT 13: General Protection (#GP) */ idt _KiTrap13, INT_32_DPL0 /* INT 0D: General Protection (#GP) */
.globl _KiTrap14 /* INT 14: Page-Fault Exception (#PF) */ idt _KiTrap14, INT_32_DPL0 /* INT 0E: Page-Fault Exception (#PF) */
.globl _KiTrap15 /* INT 15: RESERVED */ idt _KiTrap15, INT_32_DPL0 /* INT 0F: RESERVED */
.globl _KiTrap16 /* INT 16: x87 FPU Error (#MF) */ idt _KiTrap16, INT_32_DPL0 /* INT 10: x87 FPU Error (#MF) */
.globl _KiTrap17 /* INT 17: Align Check Exception (#AC) */ idt _KiTrap17, INT_32_DPL0 /* INT 11: Align Check Exception (#AC) */
.globl _KiTrap18 /* INT 18: Machine Check Exception (#MC)*/ idt _KiTrap18, INT_32_DPL0 /* INT 12: Machine Check Exception (#MC)*/
.globl _KiTrap19 /* INT 19: SIMD FPU Exception (#XF) */ idt _KiTrap19, INT_32_DPL0 /* INT 13: SIMD FPU Exception (#XF) */
.globl _KiTrapUnknown /* INT 20-30: UNDEFINED INTERRUPTS */ .rept 22
.globl _KiDebugService /* INT 31: Get Tick Count Handler */ idt _KiTrapUnknown, INT_32_DPL0 /* INT 14-29: UNDEFINED INTERRUPTS */
.globl _KiCallbackReturn /* INT 32: User-Mode Callback Return */ .endr
.globl _KiRaiseAssertion /* INT 33: Debug Assertion Handler */ idt _KiGetTickCount, INT_32_DPL3 /* INT 2A: Get Tick Count Handler */
.globl _KiDebugService /* INT 34: Debug Service Handler */ idt _KiCallbackReturn, INT_32_DPL3 /* INT 2B: User-Mode Callback Return */
.globl _KiSystemService /* INT 35: System Call Service Handler */ idt _KiRaiseAssertion, INT_32_DPL3 /* INT 2C: Debug Assertion Handler */
idt _KiDebugService, INT_32_DPL3 /* INT 2D: Debug Service Handler */
idt _KiSystemService, INT_32_DPL3 /* INT 2E: System Call Service Handler */
idt _KiTrapUnknown, INT_32_DPL0 /* INT 2F: RESERVED */
.rept 220
idt _KiTrapUnknown, INT_32_DPL0 /* INT 30-FF: UNDEFINED INTERRUPTS */
.endr
/* We also handle LSTAR Entry */ /* System call entrypoints: */
.globl _KiFastCallEntry .globl _KiFastCallEntry
.globl _KiSystemService
/* And special system-defined software traps */ /* And special system-defined software traps: */
.globl _NtRaiseException@12 .globl _NtRaiseException@12
.globl _NtContinue@8 .globl _NtContinue@8
@ -66,8 +74,18 @@
.globl _KiServiceExit2 /* Exit from syscall with complete frame*/ .globl _KiServiceExit2 /* Exit from syscall with complete frame*/
.globl _Kei386EoiHelper@0 /* Exit from interrupt or H/W trap */ .globl _Kei386EoiHelper@0 /* Exit from interrupt or H/W trap */
.globl _KiIdtDescriptor
_KiIdtDescriptor:
.short 0x800
.long _KiIdt
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
_KiGetTickCount:
_KiCallbackReturn:
_KiRaiseAssertion:
int 3
.func KiSystemService .func KiSystemService
_KiSystemService: _KiSystemService:
@ -473,6 +491,7 @@ AbiosExit:
/* Not yet supported */ /* Not yet supported */
int 3 int 3
.func KiDebugService
_KiDebugService: _KiDebugService:
/* Push error code */ /* Push error code */
@ -526,7 +545,9 @@ NotUserMode:
/* Exit through common routine */ /* Exit through common routine */
jmp _Kei386EoiHelper@0 jmp _Kei386EoiHelper@0
.endfunc
.func NtRaiseException@12
_NtRaiseException@12: _NtRaiseException@12:
/* NOTE: We -must- be called by Zw* to have the right frame! */ /* NOTE: We -must- be called by Zw* to have the right frame! */
@ -571,7 +592,9 @@ _NtRaiseException@12:
/* Restore debug registers too */ /* Restore debug registers too */
jmp _KiServiceExit jmp _KiServiceExit
.endfunc
.func NtContinue@8
_NtContinue@8: _NtContinue@8:
/* NOTE: We -must- be called by Zw* to have the right frame! */ /* NOTE: We -must- be called by Zw* to have the right frame! */
@ -619,6 +642,7 @@ Error:
pop ebp pop ebp
mov esp, ebp mov esp, ebp
jmp _KiServiceExit jmp _KiServiceExit
.endfunc
_KiTrap0: _KiTrap0:
/* Push error code */ /* Push error code */
@ -780,6 +804,7 @@ _KiTrap7:
jne _Kei386EoiHelper@0 jne _Kei386EoiHelper@0
jmp _KiV86Complete jmp _KiV86Complete
.globl _KiTrap8
_KiTrap8: _KiTrap8:
call _KiDoubleFaultHandler call _KiDoubleFaultHandler
iret iret

View file

@ -30,7 +30,6 @@
<file>exp.c</file> <file>exp.c</file>
<file>fpu.c</file> <file>fpu.c</file>
<file>gdt.c</file> <file>gdt.c</file>
<file>idt.c</file>
<file>irq.c</file> <file>irq.c</file>
<file>irqhand.s</file> <file>irqhand.s</file>
<file>kernel.c</file> <file>kernel.c</file>