From 680bdcf253f52d511c2319d245552826ac03a042 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 10 Sep 2011 23:05:10 +0000 Subject: [PATCH] [NTOSKRNL] The handlers for unexpected interrupts that we generate from asm macros use a push instruction with an 8 bit operand to push the interrupt number on the stack. Now the 8 bit push has the unfortunate behaviour of sign extending to 32 bit. But since the assembler is smart (or at least thinks so) it will not generate such a push instruction for values larger than 0x7f. This resulted in 7 bytes long stubs in the range of 0x30 .. 0x7f and 10 bytes long stubs after that. To fix this 128 is substracted from the value and later readded in the common code path. A second issue arose, because the assembler would start to use 8 bit relative short jumps as soon as the target was less than 127 bytes away, which happened for some of the higher interrupts, which then had a smaller stub then the others. Fix this by moving the stubs up in the code further away from the target label, so that always 32bit relative jumps will be used. These problems didn't show up so far, since we used the PIC and interrupts in the range of 0x30 .. 0x40 and the code that relied on the stubs all having the same length was working well. This changes with an APIC based hal, where interrupts of much higher number are likely to be used. svn path=/trunk/; revision=53679 --- reactos/ntoskrnl/ke/i386/trap.s | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/ke/i386/trap.s b/reactos/ntoskrnl/ke/i386/trap.s index 8d7a809c6c5..84de56686dd 100644 --- a/reactos/ntoskrnl/ke/i386/trap.s +++ b/reactos/ntoskrnl/ke/i386/trap.s @@ -13,14 +13,16 @@ #include #include -MACRO(GENERATE_IDT_STUB, Number) -idt _KiUnexpectedInterrupt&Number, INT_32_DPL0 +MACRO(GENERATE_IDT_STUB, Vector) +idt _KiUnexpectedInterrupt&Vector, INT_32_DPL0 ENDM -MACRO(GENERATE_INT_HANDLER, Number) +MACRO(GENERATE_INT_HANDLER, Vector) //.func KiUnexpectedInterrupt&Number -_KiUnexpectedInterrupt&Number: - push PRIMARY_VECTOR_BASE + Number +_KiUnexpectedInterrupt&Vector: + /* This is a push instruction with 8bit operand. Since the instruction + sign extends the value to 32 bits, we need to offset it */ + push (Vector - 128) jmp _KiEndUnexpectedRange@0 //.endfunc ENDM @@ -66,7 +68,7 @@ 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 _KiTrap0F, INT_32_DPL0 /* INT 2F: RESERVED */ -i = 0 +i = HEX(30) REPEAT 208 GENERATE_IDT_STUB %i i = i + 1 @@ -80,11 +82,19 @@ _KiIdtDescriptor: PUBLIC _KiUnexpectedEntrySize _KiUnexpectedEntrySize: - .long _KiUnexpectedInterrupt1 - _KiUnexpectedInterrupt0 + .long _KiUnexpectedInterrupt49 - _KiUnexpectedInterrupt48 /******************************************************************************/ .code +PUBLIC _KiStartUnexpectedRange@0 +_KiStartUnexpectedRange@0: +i = HEX(30) +REPEAT 208 + GENERATE_INT_HANDLER %i + i = i + 1 +ENDR + TRAP_ENTRY KiTrap00, KI_PUSH_FAKE_ERROR_CODE TRAP_ENTRY KiTrap01, KI_PUSH_FAKE_ERROR_CODE TRAP_ENTRY KiTrap03, KI_PUSH_FAKE_ERROR_CODE @@ -140,15 +150,10 @@ PUBLIC _KiFastCallEntry KiCallHandler @KiFastCallEntryHandler@8 .ENDP KiFastCallEntry -PUBLIC _KiStartUnexpectedRange@0 -_KiStartUnexpectedRange@0: -i = 0 -REPEAT 208 - GENERATE_INT_HANDLER %i - i = i + 1 -ENDR + PUBLIC _KiEndUnexpectedRange@0 _KiEndUnexpectedRange@0: + add dword ptr[esp], 128 jmp _KiUnexpectedInterruptTail