mirror of
https://github.com/reactos/reactos.git
synced 2025-06-05 09:20:30 +00:00
[NTOS:KE][SDK:ASM] Code formatting/styling only.
- Un-hardcode the RPL_MASK value. - s/KiUnexpectedInterrupt&Number/KiUnexpectedInterrupt&Vector/ - Use C-style comments in traphdlr.c as everywhere else in the file. - Update the URLs for the MSDN "FPO" macro documentation.
This commit is contained in:
parent
1dc4ba9da7
commit
d15e36a1f1
4 changed files with 86 additions and 101 deletions
|
@ -66,16 +66,15 @@ MACRO(idt, Handler, Bits)
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
|
|
||||||
KI_PUSH_FAKE_ERROR_CODE = HEX(0001)
|
#define KI_PUSH_FAKE_ERROR_CODE HEX(0001)
|
||||||
KI_UNUSED = HEX(0002)
|
#define KI_UNUSED HEX(0002)
|
||||||
KI_NONVOLATILES_ONLY = HEX(0004)
|
#define KI_NONVOLATILES_ONLY HEX(0004)
|
||||||
KI_FAST_SYSTEM_CALL = HEX(0008)
|
#define KI_FAST_SYSTEM_CALL HEX(0008)
|
||||||
KI_SOFTWARE_TRAP = HEX(0010)
|
#define KI_SOFTWARE_TRAP HEX(0010)
|
||||||
KI_HARDWARE_INT = HEX(0020)
|
#define KI_HARDWARE_INT HEX(0020)
|
||||||
KI_DONT_SAVE_SEGS = HEX(0100)
|
#define KI_DONT_SAVE_SEGS HEX(0100)
|
||||||
|
|
||||||
MACRO(KiEnterTrap, Flags)
|
MACRO(KiEnterTrap, Flags)
|
||||||
LOCAL kernel_trap
|
|
||||||
LOCAL not_v86_trap
|
LOCAL not_v86_trap
|
||||||
LOCAL set_sane_segs
|
LOCAL set_sane_segs
|
||||||
|
|
||||||
|
@ -145,7 +144,7 @@ MACRO(KiEnterTrap, Flags)
|
||||||
if (Flags AND KI_DONT_SAVE_SEGS)
|
if (Flags AND KI_DONT_SAVE_SEGS)
|
||||||
|
|
||||||
/* Initialize TrapFrame segment registers with sane values */
|
/* Initialize TrapFrame segment registers with sane values */
|
||||||
mov eax, KGDT_R3_DATA OR 3
|
mov eax, KGDT_R3_DATA OR RPL_MASK
|
||||||
mov ecx, fs
|
mov ecx, fs
|
||||||
mov [esp + KTRAP_FRAME_DS], eax
|
mov [esp + KTRAP_FRAME_DS], eax
|
||||||
mov [esp + KTRAP_FRAME_ES], eax
|
mov [esp + KTRAP_FRAME_ES], eax
|
||||||
|
@ -250,17 +249,17 @@ MACRO(TRAP_ENTRY, Trap, Flags)
|
||||||
.ENDP
|
.ENDP
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
#define KI_RESTORE_EAX HEX(001)
|
#define KI_RESTORE_EAX HEX(0001)
|
||||||
#define KI_RESTORE_ECX_EDX HEX(002)
|
#define KI_RESTORE_ECX_EDX HEX(0002)
|
||||||
#define KI_RESTORE_FS HEX(004)
|
#define KI_RESTORE_FS HEX(0004)
|
||||||
#define KI_RESTORE_SEGMENTS HEX(008)
|
#define KI_RESTORE_SEGMENTS HEX(0008)
|
||||||
#define KI_RESTORE_EFLAGS HEX(010)
|
#define KI_RESTORE_EFLAGS HEX(0010)
|
||||||
#define KI_EXIT_SYSCALL HEX(020)
|
#define KI_EXIT_SYSCALL HEX(0020)
|
||||||
#define KI_EXIT_JMP HEX(040)
|
#define KI_EXIT_JMP HEX(0040)
|
||||||
#define KI_EXIT_RET HEX(080)
|
#define KI_EXIT_RET HEX(0080)
|
||||||
#define KI_EXIT_IRET HEX(100)
|
#define KI_EXIT_IRET HEX(0100)
|
||||||
#define KI_EDITED_FRAME HEX(200)
|
#define KI_EDITED_FRAME HEX(0200)
|
||||||
#define KI_EXIT_RET8 HEX(400)
|
#define KI_EXIT_RET8 HEX(0400)
|
||||||
#define KI_RESTORE_VOLATILES (KI_RESTORE_EAX OR KI_RESTORE_ECX_EDX)
|
#define KI_RESTORE_VOLATILES (KI_RESTORE_EAX OR KI_RESTORE_ECX_EDX)
|
||||||
|
|
||||||
MACRO(KiTrapExitStub, Name, Flags)
|
MACRO(KiTrapExitStub, Name, Flags)
|
||||||
|
|
|
@ -18,7 +18,7 @@ idt _KiUnexpectedInterrupt&Vector, INT_32_DPL0
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
MACRO(GENERATE_INT_HANDLER, Vector)
|
MACRO(GENERATE_INT_HANDLER, Vector)
|
||||||
//.func KiUnexpectedInterrupt&Number
|
//.func KiUnexpectedInterrupt&Vector
|
||||||
_KiUnexpectedInterrupt&Vector:
|
_KiUnexpectedInterrupt&Vector:
|
||||||
/* This is a push instruction with 8bit operand. Since the instruction
|
/* This is a push instruction with 8bit operand. Since the instruction
|
||||||
sign extends the value to 32 bits, we need to offset it */
|
sign extends the value to 32 bits, we need to offset it */
|
||||||
|
|
|
@ -222,7 +222,7 @@ KiDebugHandler(IN PKTRAP_FRAME TrapFrame,
|
||||||
IN ULONG Parameter3)
|
IN ULONG Parameter3)
|
||||||
{
|
{
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Enable interrupts if the trap came from user-mode */
|
/* Enable interrupts if the trap came from user-mode */
|
||||||
if (KiUserTrap(TrapFrame)) _enable();
|
if (KiUserTrap(TrapFrame)) _enable();
|
||||||
|
@ -248,7 +248,7 @@ KiNpxHandler(IN PKTRAP_FRAME TrapFrame,
|
||||||
ULONG Cr0, Mask, Error, ErrorOffset, DataOffset;
|
ULONG Cr0, Mask, Error, ErrorOffset, DataOffset;
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Check for kernel trap */
|
/* Check for kernel trap */
|
||||||
if (!KiUserTrap(TrapFrame))
|
if (!KiUserTrap(TrapFrame))
|
||||||
|
@ -410,7 +410,7 @@ KiTrap00Handler(IN PKTRAP_FRAME TrapFrame)
|
||||||
KiEnterTrap(TrapFrame);
|
KiEnterTrap(TrapFrame);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Enable interrupts */
|
/* Enable interrupts */
|
||||||
_enable();
|
_enable();
|
||||||
|
@ -430,7 +430,7 @@ KiTrap01Handler(IN PKTRAP_FRAME TrapFrame)
|
||||||
KiEnterTrap(TrapFrame);
|
KiEnterTrap(TrapFrame);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Check if this was a single step after sysenter */
|
/* Check if this was a single step after sysenter */
|
||||||
if (TrapFrame->Eip == (ULONG)KiFastCallEntry)
|
if (TrapFrame->Eip == (ULONG)KiFastCallEntry)
|
||||||
|
@ -467,58 +467,52 @@ KiTrap02(VOID)
|
||||||
KTRAP_FRAME TrapFrame;
|
KTRAP_FRAME TrapFrame;
|
||||||
KIRQL OldIrql;
|
KIRQL OldIrql;
|
||||||
|
|
||||||
//
|
/*
|
||||||
// In some sort of strange recursion case, we might end up here with the IF
|
* In some sort of strange recursion case, we might end up here with the IF
|
||||||
// flag incorrectly on the interrupt frame -- during a normal NMI this would
|
* flag incorrectly on the interrupt frame -- during a normal NMI this would
|
||||||
// normally already be set.
|
* normally already be set.
|
||||||
//
|
*
|
||||||
// For sanity's sake, make sure interrupts are disabled for sure.
|
* For sanity's sake, make sure interrupts are disabled for sure.
|
||||||
// NMIs will already be since the CPU does it for us.
|
* NMIs will already be since the CPU does it for us.
|
||||||
//
|
*/
|
||||||
_disable();
|
_disable();
|
||||||
|
|
||||||
//
|
/* Get the current TSS, thread, and process */
|
||||||
// Get the current TSS, thread, and process
|
|
||||||
//
|
|
||||||
Tss = PCR->TSS;
|
Tss = PCR->TSS;
|
||||||
Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
|
Thread = ((PKIPCR)PCR)->PrcbData.CurrentThread;
|
||||||
Process = Thread->ApcState.Process;
|
Process = Thread->ApcState.Process;
|
||||||
|
|
||||||
//
|
/* Save data usually not present in the TSS */
|
||||||
// Save data usually not in the TSS
|
|
||||||
//
|
|
||||||
Tss->CR3 = Process->DirectoryTableBase[0];
|
Tss->CR3 = Process->DirectoryTableBase[0];
|
||||||
Tss->IoMapBase = Process->IopmOffset;
|
Tss->IoMapBase = Process->IopmOffset;
|
||||||
Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0;
|
Tss->LDT = Process->LdtDescriptor.LimitLow ? KGDT_LDT : 0;
|
||||||
|
|
||||||
//
|
/* Now get the base address of the NMI TSS */
|
||||||
// Now get the base address of the NMI TSS
|
|
||||||
//
|
|
||||||
TssGdt = &((PKIPCR)KeGetPcr())->GDT[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
|
TssGdt = &((PKIPCR)KeGetPcr())->GDT[KGDT_NMI_TSS / sizeof(KGDTENTRY)];
|
||||||
NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow |
|
NmiTss = (PKTSS)(ULONG_PTR)(TssGdt->BaseLow |
|
||||||
TssGdt->HighWord.Bytes.BaseMid << 16 |
|
TssGdt->HighWord.Bytes.BaseMid << 16 |
|
||||||
TssGdt->HighWord.Bytes.BaseHi << 24);
|
TssGdt->HighWord.Bytes.BaseHi << 24);
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Switch to it and activate it, masking off the nested flag
|
* Switch to it and activate it, masking off the nested flag.
|
||||||
//
|
*
|
||||||
// Note that in reality, we are already on the NMI tss -- we just need to
|
* Note that in reality, we are already on the NMI TSS -- we just
|
||||||
// update the PCR to reflect this
|
* need to update the PCR to reflect this.
|
||||||
//
|
*/
|
||||||
PCR->TSS = NmiTss;
|
PCR->TSS = NmiTss;
|
||||||
__writeeflags(__readeflags() &~ EFLAGS_NESTED_TASK);
|
__writeeflags(__readeflags() &~ EFLAGS_NESTED_TASK);
|
||||||
TssGdt->HighWord.Bits.Dpl = 0;
|
TssGdt->HighWord.Bits.Dpl = 0;
|
||||||
TssGdt->HighWord.Bits.Pres = 1;
|
TssGdt->HighWord.Bits.Pres = 1;
|
||||||
TssGdt->HighWord.Bits.Type = I386_TSS;
|
TssGdt->HighWord.Bits.Type = I386_TSS;
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Now build the trap frame based on the original TSS
|
* Now build the trap frame based on the original TSS.
|
||||||
//
|
*
|
||||||
// The CPU does a hardware "Context switch" / task switch of sorts and so it
|
* The CPU does a hardware "Context switch" / task switch of sorts
|
||||||
// takes care of saving our context in the normal TSS.
|
* and so it takes care of saving our context in the normal TSS.
|
||||||
//
|
*
|
||||||
// We just have to go get the values...
|
* We just have to go get the values...
|
||||||
//
|
*/
|
||||||
RtlZeroMemory(&TrapFrame, sizeof(KTRAP_FRAME));
|
RtlZeroMemory(&TrapFrame, sizeof(KTRAP_FRAME));
|
||||||
TrapFrame.HardwareSegSs = Tss->Ss0;
|
TrapFrame.HardwareSegSs = Tss->Ss0;
|
||||||
TrapFrame.HardwareEsp = Tss->Esp0;
|
TrapFrame.HardwareEsp = Tss->Esp0;
|
||||||
|
@ -541,64 +535,50 @@ KiTrap02(VOID)
|
||||||
TrapFrame.DbgEip = Tss->Eip;
|
TrapFrame.DbgEip = Tss->Eip;
|
||||||
TrapFrame.DbgEbp = Tss->Ebp;
|
TrapFrame.DbgEbp = Tss->Ebp;
|
||||||
|
|
||||||
//
|
/* Store the trap frame in the KPRCB */
|
||||||
// Store the trap frame in the KPRCB
|
|
||||||
//
|
|
||||||
KiSaveProcessorState(&TrapFrame, NULL);
|
KiSaveProcessorState(&TrapFrame, NULL);
|
||||||
|
|
||||||
//
|
/* Call any registered NMI handlers and see if they handled it or not */
|
||||||
// Call any registered NMI handlers and see if they handled it or not
|
|
||||||
//
|
|
||||||
if (!KiHandleNmi())
|
if (!KiHandleNmi())
|
||||||
{
|
{
|
||||||
//
|
/*
|
||||||
// They did not, so call the platform HAL routine to bugcheck the system
|
* They did not, so call the platform HAL routine to bugcheck the system
|
||||||
//
|
*
|
||||||
// Make sure the HAL believes it's running at HIGH IRQL... we can't use
|
* Make sure the HAL believes it's running at HIGH IRQL... we can't use
|
||||||
// the normal APIs here as playing with the IRQL could change the system
|
* the normal APIs here as playing with the IRQL could change the system
|
||||||
// state
|
* state.
|
||||||
//
|
*/
|
||||||
OldIrql = PCR->Irql;
|
OldIrql = PCR->Irql;
|
||||||
PCR->Irql = HIGH_LEVEL;
|
PCR->Irql = HIGH_LEVEL;
|
||||||
HalHandleNMI(NULL);
|
HalHandleNMI(NULL);
|
||||||
PCR->Irql = OldIrql;
|
PCR->Irql = OldIrql;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/*
|
||||||
// Although the CPU disabled NMIs, we just did a BIOS Call, which could've
|
* Although the CPU disabled NMIs, we just did a BIOS call, which could've
|
||||||
// totally changed things.
|
* totally changed things.
|
||||||
//
|
*
|
||||||
// We have to make sure we're still in our original NMI -- a nested NMI
|
* We have to make sure we're still in our original NMI -- a nested NMI
|
||||||
// will point back to the NMI TSS, and in that case we're hosed.
|
* will point back to the NMI TSS, and in that case we're hosed.
|
||||||
//
|
*/
|
||||||
if (PCR->TSS->Backlink != KGDT_NMI_TSS)
|
if (PCR->TSS->Backlink != KGDT_NMI_TSS)
|
||||||
{
|
{
|
||||||
//
|
/* Restore original TSS */
|
||||||
// Restore original TSS
|
|
||||||
//
|
|
||||||
PCR->TSS = Tss;
|
PCR->TSS = Tss;
|
||||||
|
|
||||||
//
|
/* Set it back to busy */
|
||||||
// Set it back to busy
|
|
||||||
//
|
|
||||||
TssGdt->HighWord.Bits.Dpl = 0;
|
TssGdt->HighWord.Bits.Dpl = 0;
|
||||||
TssGdt->HighWord.Bits.Pres = 1;
|
TssGdt->HighWord.Bits.Pres = 1;
|
||||||
TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS;
|
TssGdt->HighWord.Bits.Type = I386_ACTIVE_TSS;
|
||||||
|
|
||||||
//
|
/* Restore nested flag */
|
||||||
// Restore nested flag
|
|
||||||
//
|
|
||||||
__writeeflags(__readeflags() | EFLAGS_NESTED_TASK);
|
__writeeflags(__readeflags() | EFLAGS_NESTED_TASK);
|
||||||
|
|
||||||
//
|
/* Handled, return from interrupt */
|
||||||
// Handled, return from interrupt
|
|
||||||
//
|
|
||||||
KiIret();
|
KiIret();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/* Unhandled: crash the system */
|
||||||
// Unhandled: crash the system
|
|
||||||
//
|
|
||||||
KiSystemFatalException(EXCEPTION_NMI, NULL);
|
KiSystemFatalException(EXCEPTION_NMI, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +603,7 @@ KiTrap04Handler(IN PKTRAP_FRAME TrapFrame)
|
||||||
KiEnterTrap(TrapFrame);
|
KiEnterTrap(TrapFrame);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Enable interrupts */
|
/* Enable interrupts */
|
||||||
_enable();
|
_enable();
|
||||||
|
@ -643,7 +623,7 @@ KiTrap05Handler(IN PKTRAP_FRAME TrapFrame)
|
||||||
KiEnterTrap(TrapFrame);
|
KiEnterTrap(TrapFrame);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Check for kernel-mode fault */
|
/* Check for kernel-mode fault */
|
||||||
if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame);
|
if (!KiUserTrap(TrapFrame)) KiSystemFatalException(EXCEPTION_BOUND_CHECK, TrapFrame);
|
||||||
|
@ -878,7 +858,7 @@ KiTrap0AHandler(IN PKTRAP_FRAME TrapFrame)
|
||||||
KiEnterTrap(TrapFrame);
|
KiEnterTrap(TrapFrame);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Kill the system */
|
/* Kill the system */
|
||||||
KiSystemFatalException(EXCEPTION_INVALID_TSS, TrapFrame);
|
KiSystemFatalException(EXCEPTION_INVALID_TSS, TrapFrame);
|
||||||
|
@ -1485,7 +1465,7 @@ KiTrap13Handler(IN PKTRAP_FRAME TrapFrame)
|
||||||
SaveArea = KiGetThreadNpxArea(Thread);
|
SaveArea = KiGetThreadNpxArea(Thread);
|
||||||
|
|
||||||
/* Check for VDM trap */
|
/* Check for VDM trap */
|
||||||
ASSERT((KiVdmTrap(TrapFrame)) == FALSE);
|
ASSERT(KiVdmTrap(TrapFrame) == FALSE);
|
||||||
|
|
||||||
/* Check for user trap */
|
/* Check for user trap */
|
||||||
if (!KiUserTrap(TrapFrame))
|
if (!KiUserTrap(TrapFrame))
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
#ifndef __ASM_INC__
|
#ifndef __ASM_INC__
|
||||||
#define __ASM_INC__
|
#define __ASM_INC__
|
||||||
|
|
||||||
/* Common definitions for FPO macro
|
/*
|
||||||
see http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
|
* Common definitions for the FPO macro.
|
||||||
|
* See https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
|
||||||
|
*/
|
||||||
#define FRAME_FPO 0
|
#define FRAME_FPO 0
|
||||||
#define FRAME_TRAP 1
|
#define FRAME_TRAP 1
|
||||||
#define FRAME_TSS 2
|
#define FRAME_TSS 2
|
||||||
|
@ -65,8 +67,10 @@ GLOBAL_LABEL MACRO label
|
||||||
%label::
|
%label::
|
||||||
ENDM
|
ENDM
|
||||||
|
|
||||||
/* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
|
/*
|
||||||
and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
|
* See https://docs.microsoft.com/en-us/cpp/assembler/masm/dot-fpo
|
||||||
|
* and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
|
||||||
|
*/
|
||||||
FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
|
FPO MACRO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
|
||||||
.FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
|
.FPO (cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame)
|
||||||
ENDM
|
ENDM
|
||||||
|
@ -317,8 +321,10 @@ ENDM
|
||||||
.section .rdata
|
.section .rdata
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/* check http://msdn.microsoft.com/en-us/library/9c9k076y%28VS.80%29.aspx
|
/*
|
||||||
and http://msdn.microsoft.com/en-us/library/ms679352%28VS.85%29.aspx */
|
* See https://docs.microsoft.com/en-us/cpp/assembler/masm/dot-fpo
|
||||||
|
* and https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_fpo_data
|
||||||
|
*/
|
||||||
.macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
|
.macro FPO cdwLocals, cdwParams, cbProlog, cbRegs, fUseBP, cbFrame
|
||||||
.if (cbFrame == FRAME_TRAP)
|
.if (cbFrame == FRAME_TRAP)
|
||||||
.cfi_signal_frame
|
.cfi_signal_frame
|
||||||
|
|
Loading…
Reference in a new issue