- Fix bugs in ASM version of KfLowerIrql (not yet used)

- Fix bugs in INT_PROLOG.
- Fix an important bug in TRAP_EPILOG which was causing register restoration to happen at all times (such as in Kei386EoiHelper/KiServiceExit2 when it shouldn't happen).
- Add DRx restoration from trap frame, if DR7 is set.
- Added and fixed some debugging assertions in TRAP_EPILOG.

svn path=/trunk/; revision=23661
This commit is contained in:
Alex Ionescu 2006-08-23 06:33:52 +00:00
parent c30a8d1cd4
commit de56d52a1b
3 changed files with 95 additions and 33 deletions

View file

@ -180,7 +180,6 @@ _@HalRequestSoftwareInterrupt@4:
jbe AfterCall jbe AfterCall
/* Call the pending interrupt */ /* Call the pending interrupt */
jmp $
call _SoftIntHandlerTable[edx*4] call _SoftIntHandlerTable[edx*4]
AfterCall: AfterCall:
@ -403,8 +402,9 @@ DoCall:
add esp, 8 add esp, 8
jmp SoftIntHandlerTable2[eax*4] jmp SoftIntHandlerTable2[eax*4]
.endfunc .endfunc
#endif
#if 0
.globl @KfLowerIrql@4 .globl @KfLowerIrql@4
.func @KfLowerIrql@4 .func @KfLowerIrql@4
_@KfLowerIrql@4: _@KfLowerIrql@4:
@ -430,21 +430,15 @@ SkipMask:
/* Set the new IRQL and check if there's a pending software interrupt */ /* Set the new IRQL and check if there's a pending software interrupt */
mov [fs:KPCR_IRQL], cl mov [fs:KPCR_IRQL], cl
mov eax, [fs:KPCR_IDR] mov eax, [fs:KPCR_IRR]
mov al, _SoftIntByteTable[eax] mov al, _SoftIntByteTable[eax]
cmp al, cl cmp al, cl
ja DoCall3 jbe DoCall3
/* Restore interrupts and return */
popf
ret
.align 4
DoCall3:
/* There is, call it */ /* There is, call it */
call _SoftIntHandlerTable[eax*4] call _SoftIntHandlerTable[eax*4]
jmp $
DoCall3:
/* Restore interrupts and return */ /* Restore interrupts and return */
popf popf

View file

@ -371,6 +371,11 @@ Author:
#define CR4_XMMEXCPT 0x400 #define CR4_XMMEXCPT 0x400
#endif #endif
//
// DR7 Values
//
#define DR7_RESERVED_MASK 0xDC00
// //
// Usermode callout frame definitions // Usermode callout frame definitions
// //

View file

@ -352,7 +352,7 @@ _KiUnexpectedInterrupt&Number:
mov [esp+KTRAP_FRAME_EAX], eax mov [esp+KTRAP_FRAME_EAX], eax
mov [esp+KTRAP_FRAME_ECX], ecx mov [esp+KTRAP_FRAME_ECX], ecx
mov [esp+KTRAP_FRAME_EDX], edx mov [esp+KTRAP_FRAME_EDX], edx
mov dword ptr [esp+KTRAP_FRAME_EXCEPTION_LIST], -1 mov dword ptr [esp+KTRAP_FRAME_PREVIOUS_MODE], -1
/* Check if this was from V86 Mode */ /* Check if this was from V86 Mode */
/* test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK */ /* test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK */
@ -366,23 +366,28 @@ _KiUnexpectedInterrupt&Number:
mov word ptr [esp+KTRAP_FRAME_FS], fs mov word ptr [esp+KTRAP_FRAME_FS], fs
mov word ptr [esp+KTRAP_FRAME_DS], ds mov word ptr [esp+KTRAP_FRAME_DS], ds
mov word ptr [esp+KTRAP_FRAME_ES], es mov word ptr [esp+KTRAP_FRAME_ES], es
mov word ptr [esp+KTRAP_FRAME_GS], gs mov [esp+KTRAP_FRAME_GS], gs
/* Load the segment registers */ /* Load the segment registers (use OVERRIDE (0x66)) */
mov ebx, KGDT_R0_PCR mov ebx, KGDT_R0_PCR
mov eax, KGDT_R3_DATA | RPL_MASK mov eax, KGDT_R3_DATA | RPL_MASK
.byte 0x66
mov fs, bx mov fs, bx
.byte 0x66
mov ds, ax mov ds, ax
.byte 0x66
mov es, ax mov es, ax
1: 1:
/* Save the previous exception list */ /* Get the previous exception list */
mov ebx, [fs:KPCR_EXCEPTION_LIST] mov ebx, [fs:KPCR_EXCEPTION_LIST]
mov [esp+KTRAP_FRAME_EXCEPTION_LIST], ebx
/* Set the exception handler chain terminator */ /* Set the exception handler chain terminator */
mov dword ptr [fs:KPCR_EXCEPTION_LIST], -1 mov dword ptr [fs:KPCR_EXCEPTION_LIST], -1
/* Save the previous exception list */
mov [esp+KTRAP_FRAME_EXCEPTION_LIST], ebx
/* Check if this is the ABIOS stack */ /* Check if this is the ABIOS stack */
/* cmp esp, 0x10000*/ /* cmp esp, 0x10000*/
/* jb Abios_Label*/ /* jb Abios_Label*/
@ -534,16 +539,16 @@ _KiUnexpectedInterrupt&Number:
pushfd pushfd
pop edx pop edx
test edx, EFLAGS_INTERRUPT_MASK test edx, EFLAGS_INTERRUPT_MASK
jnz 1f jnz 6f
/* Assert the stack */ /* Assert the stack */
cmp esp, ebp cmp esp, ebp
jnz 1f jnz 6f
/* Assert the trap frame */ /* Assert the trap frame */
0: 5:
//sub dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00 sub dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
//jnz 2f //jnz 0f // FIXME: ROS IS BROKEN
/* Assert FS */ /* Assert FS */
mov bx, fs mov bx, fs
@ -552,24 +557,23 @@ _KiUnexpectedInterrupt&Number:
/* Assert exception list */ /* Assert exception list */
cmp dword ptr fs:[KPCR_EXCEPTION_LIST], 0 cmp dword ptr fs:[KPCR_EXCEPTION_LIST], 0
jnz 4f jnz 2f
2:
add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
1: 1:
int 3 push -1
jmp 0b call _KeBugCheck@4
4:
#endif #endif
2:
/* Get exception list */ /* Get exception list */
mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST] mov edx, [esp+KTRAP_FRAME_EXCEPTION_LIST]
#ifdef DBG #ifdef DBG
/* Assert the saved exception list */ /* Assert the saved exception list */
or edx, edx or edx, edx
jnz 5f jnz 1f
int 3 int 3
5: 1:
#endif #endif
/* Restore it */ /* Restore it */
@ -582,17 +586,32 @@ _KiUnexpectedInterrupt&Number:
#ifdef DBG #ifdef DBG
/* Assert the saved previous mode */ /* Assert the saved previous mode */
cmp ecx, -1 cmp ecx, -1
jnz 6f jnz 1f
int 3 int 3
6: 1:
#endif #endif
/* Restore the previous mode */ /* Restore the previous mode */
mov esi, [fs:KPCR_CURRENT_THREAD] mov esi, [fs:KPCR_CURRENT_THREAD]
mov byte ptr [esi+KTHREAD_PREVIOUS_MODE], cl mov byte ptr [esi+KTHREAD_PREVIOUS_MODE], cl
.else
#ifdef DBG
/* Assert the saved previous mode */
mov ecx, [esp+KTRAP_FRAME_PREVIOUS_MODE]
cmp ecx, -1
jz 1f
int 3
1:
#endif
.endif .endif
/* Check for debug registers */
test dword ptr [esp+KTRAP_FRAME_DR7], ~DR7_RESERVED_MASK
jnz 2f
/* Check for V86 */ /* Check for V86 */
4:
test dword ptr [esp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK test dword ptr [esp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz V86_Exit jnz V86_Exit
@ -600,7 +619,7 @@ _KiUnexpectedInterrupt&Number:
test word ptr [esp+KTRAP_FRAME_CS], FRAME_EDITED test word ptr [esp+KTRAP_FRAME_CS], FRAME_EDITED
jz 7f jz 7f
.ifeq \RestoreAllRegs .if \RestoreAllRegs
/* Check the old mode */ /* Check the old mode */
cmp word ptr [esp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK cmp word ptr [esp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK
bt word ptr [esp+KTRAP_FRAME_CS], 0 bt word ptr [esp+KTRAP_FRAME_CS], 0
@ -692,6 +711,7 @@ FastExit:
sysexit sysexit
.endif .endif
.if \RestoreAllRegs
8: 8:
/* Restore EAX */ /* Restore EAX */
mov eax, [esp+KTRAP_FRAME_EAX] mov eax, [esp+KTRAP_FRAME_EAX]
@ -708,6 +728,49 @@ FastExit:
/* Jump back to mainline code */ /* Jump back to mainline code */
jmp 3b jmp 3b
.endif
0:
/* Fix up the mask */
add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
6:
int 3
jmp 5b
2:
/* Check if this was V86 mode */
test dword ptr [esp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz 1f
/* Check if it was user mode */
test word ptr [esp+KTRAP_FRAME_CS], MODE_MASK
jz 4b
1:
/* Clear DR7 */
xor ebx, ebx
mov dr7, ebx
/* Get DR0, 1, 2 */
mov esi, [ebp+KTRAP_FRAME_DR0]
mov edi, [ebp+KTRAP_FRAME_DR1]
mov ebx, [ebp+KTRAP_FRAME_DR2]
/* Set them */
mov dr0, esi
mov dr1, edi
mov dr2, ebx
/* Get DR3, 6, 7 */
mov esi, [ebp+KTRAP_FRAME_DR3]
mov edi, [ebp+KTRAP_FRAME_DR6]
mov ebx, [ebp+KTRAP_FRAME_DR7]
/* Set them */
mov dr3, esi
mov dr6, edi
mov dr7, ebx
jz 4b
7: 7:
/* Restore real CS value */ /* Restore real CS value */