- Replaced some common sequences of inline assembly with macros. Avoid

having compiler checks scattered all over the place.
- Added some disabled code to KiDumpTrapFrame that dumps every address
on the stack that could be a return address. This is quite handy for
debugging crashes in modules compiled with fpo.

svn path=/trunk/; revision=8615
This commit is contained in:
David Welch 2004-03-09 21:49:54 +00:00
parent e04ce16d15
commit 1fbda72a7a
10 changed files with 79 additions and 172 deletions

View file

@ -53,13 +53,7 @@ NtShutdownSystem(IN SHUTDOWN_ACTION Action)
#else #else
PopSetSystemPowerState(PowerSystemShutdown); PopSetSystemPowerState(PowerSystemShutdown);
#if defined(__GNUC__) Ke386DisableInterrupts();
__asm__("cli\n");
#elif defined(_MSC_VER)
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
while (TRUE) while (TRUE)
{ {

View file

@ -135,6 +135,30 @@ VOID KeFreeGdtSelector(ULONG Entry);
VOID VOID
NtEarlyInitVdm(VOID); NtEarlyInitVdm(VOID);
#if defined(__GNUC__)
#define Ke386DisableInterrupts() __asm__("cli\n\t");
#define Ke386EnableInterrupts() __asm__("sti\n\t");
#define Ke386HaltProcessor() __asm__("hlt\n\t");
#define Ke386GetPageTableDirectory(X) \
__asm__("movl %%cr3,%0\n\t" : "=d" (X));
#define Ke386SetPageTableDirectory(X) \
__asm__("movl %0,%%cr3\n\t" \
: /* no outputs */ \
: "r" (X));
#elif defined(_MSC_VER)
#define Ke386DisableInterrupts() __asm cli
#define Ke386EnableInterrupts() __asm sti
#define Ke386HaltProcessor() __asm hlt
#define Ke386GetPageTableDirectory(X) \
__asm mov eax, cr3; \
__asm mov X, eax;
#define Ke386GetPageTableDirectory(X) \
__asm mov eax, X; \
__asm mov cr3, eax;
#else
#error Unknown compiler for inline assembler
#endif
#endif /* __ASM__ */ #endif /* __ASM__ */
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */ #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: bug.c,v 1.42 2004/03/06 22:24:13 dwelch Exp $ /* $Id: bug.c,v 1.43 2004/03/09 21:49:53 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/bug.c * FILE: ntoskrnl/ke/bug.c
@ -103,13 +103,7 @@ KeBugCheckWithTf(ULONG BugCheckCode,
KdDebugState |= KD_DEBUG_SCREEN; KdDebugState |= KD_DEBUG_SCREEN;
} }
#if defined(__GNUC__) Ke386DisableInterrupts();
__asm__("cli\n\t");
#elif defined(_MSC_VER)
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
if (KeGetCurrentIrql() < DISPATCH_LEVEL) if (KeGetCurrentIrql() < DISPATCH_LEVEL)
{ {
@ -142,16 +136,7 @@ KeBugCheckWithTf(ULONG BugCheckCode,
if (InBugCheck == 1) if (InBugCheck == 1)
{ {
DbgPrint("Recursive bug check halting now\n"); DbgPrint("Recursive bug check halting now\n");
for (;;) Ke386HaltProcessor();
{
#if defined(__GNUC__)
__asm__("hlt\n\t");
#elif defined(_MSC_VER)
__asm hlt
#else
#error Unknown compiler for inline assembler
#endif
}
} }
InBugCheck = 1; InBugCheck = 1;
KiDumpTrapFrame(Tf, BugCheckParameter1, BugCheckParameter2); KiDumpTrapFrame(Tf, BugCheckParameter1, BugCheckParameter2);
@ -161,28 +146,14 @@ KeBugCheckWithTf(ULONG BugCheckCode,
if (KdDebuggerEnabled) if (KdDebuggerEnabled)
{ {
#if defined(__GNUC__) Ke386EnableInterrupts();
__asm__("sti\n\t");
DbgBreakPointNoBugCheck(); DbgBreakPointNoBugCheck();
__asm__("cli\n\t"); Ke386DisableInterrupts();
#elif defined(_MSC_VER)
__asm sti
DbgBreakPointNoBugCheck();
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
} }
for (;;) for (;;)
{ {
#if defined(__GNUC__) Ke386HaltProcessor();
__asm__("hlt\n\t");
#elif defined(_MSC_VER)
__asm hlt
#else
#error Unknown compiler for inline assembler
#endif
} }
} }
@ -215,13 +186,8 @@ KeBugCheckEx(ULONG BugCheckCode,
KdDebugState |= KD_DEBUG_SCREEN; KdDebugState |= KD_DEBUG_SCREEN;
} }
#if defined(__GNUC__) Ke386DisableInterrupts();
__asm__("cli\n\t");
#elif defined(_MSC_VER)
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
if (KeGetCurrentIrql() < DISPATCH_LEVEL) if (KeGetCurrentIrql() < DISPATCH_LEVEL)
{ {
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
@ -253,16 +219,7 @@ KeBugCheckEx(ULONG BugCheckCode,
if (InBugCheck == 1) if (InBugCheck == 1)
{ {
DbgPrint("Recursive bug check halting now\n"); DbgPrint("Recursive bug check halting now\n");
for (;;) Ke386HaltProcessor();
{
#if defined(__GNUC__)
__asm__("hlt\n\t");
#elif defined(_MSC_VER)
__asm hlt
#else
#error Unknown compiler for inline assembler
#endif
}
} }
InBugCheck = 1; InBugCheck = 1;
if (PsGetCurrentProcess() != NULL) if (PsGetCurrentProcess() != NULL)
@ -291,28 +248,14 @@ KeBugCheckEx(ULONG BugCheckCode,
if (KdDebuggerEnabled) if (KdDebuggerEnabled)
{ {
#if defined(__GNUC__) Ke386EnableInterrupts();
__asm__("sti\n\t");
DbgBreakPointNoBugCheck(); DbgBreakPointNoBugCheck();
__asm__("cli\n\t"); Ke386DisableInterrupts();
#elif defined(_MSC_VER)
__asm sti
DbgBreakPointNoBugCheck();
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
} }
for (;;) for (;;)
{ {
#if defined(__GNUC__) Ke386HaltProcessor();
__asm__("hlt\n\t");
#elif defined(_MSC_VER)
__asm hlt
#else
#error Unknown compiler for inline assembler
#endif
} }
} }

View file

@ -318,6 +318,7 @@ KiDoubleFaultHandler(VOID)
StackBase = (ULONG)&init_stack; StackBase = (ULONG)&init_stack;
} }
/* Change to an #if 0 if no frames are printed because of fpo. */
#if 1 #if 1
DbgPrint("Frames: "); DbgPrint("Frames: ");
Frame = (PULONG)OldTss->Ebp; Frame = (PULONG)OldTss->Ebp;
@ -442,14 +443,7 @@ KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG Parameter1, ULONG Parameter2)
Tf->Cs&0xffff, Tf->Eip); Tf->Cs&0xffff, Tf->Eip);
print_address((PVOID)Tf->Eip); print_address((PVOID)Tf->Eip);
DbgPrint("\n"); DbgPrint("\n");
#if defined(__GNUC__) Ke386GetPageTableDirectory(cr3_);
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3_));
#elif defined(_MSC_VER)
__asm mov eax, cr3;
__asm mov cr3_, eax;
#else
#error Unknown compiler for inline assembler
#endif
DbgPrint("cr2 %x cr3 %x ", cr2, cr3_); DbgPrint("cr2 %x cr3 %x ", cr2, cr3_);
DbgPrint("Proc: %x ",PsGetCurrentProcess()); DbgPrint("Proc: %x ",PsGetCurrentProcess());
if (PsGetCurrentProcess() != NULL) if (PsGetCurrentProcess() != NULL)
@ -494,6 +488,7 @@ KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG Parameter1, ULONG Parameter2)
* Dump the stack frames * Dump the stack frames
*/ */
DbgPrint("Frames: "); DbgPrint("Frames: ");
#if 0
i = 1; i = 1;
Frame = (PULONG)Tf->Ebp; Frame = (PULONG)Tf->Ebp;
while (Frame != NULL) while (Frame != NULL)
@ -506,7 +501,11 @@ KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG Parameter1, ULONG Parameter2)
DbgPrint("<INVALID>"); DbgPrint("<INVALID>");
break; break;
} }
print_address(Eip); if (!print_address(Eip))
{
DbgPrint("<%X>", Eip);
break;
}
Status = MmSafeCopyFromUser(&Frame, Frame, sizeof(Frame)); Status = MmSafeCopyFromUser(&Frame, Frame, sizeof(Frame));
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -515,6 +514,19 @@ KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG Parameter1, ULONG Parameter2)
i++; i++;
DbgPrint(" "); DbgPrint(" ");
} }
#else
i = 1;
Frame = (PULONG)((ULONG_PTR)Esp0 + KTRAP_FRAME_EFLAGS);
while (Frame < (PULONG)PsGetCurrentThread()->Tcb.StackBase && i < 50)
{
ULONG Address = *Frame;
if (print_address((PVOID)Address))
{
i++;
}
Frame++;
}
#endif
} }
ULONG ULONG
@ -573,13 +585,7 @@ KiTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr)
{ {
if (Tf->Eflags & FLAG_IF) if (Tf->Eflags & FLAG_IF)
{ {
#if defined(__GNUC__) Ke386EnableInterrupts();
__asm__("sti\n\t");
#elif defined(_MSC_VER)
__asm sti
#else
#error Unknown compiler for inline assembler
#endif
} }
Status = MmPageFault(Tf->Cs&0xffff, Status = MmPageFault(Tf->Cs&0xffff,
&Tf->Eip, &Tf->Eip,
@ -626,10 +632,13 @@ KeDumpStackFrames(PULONG Frame)
i = 1; i = 1;
while (Frame != NULL) while (Frame != NULL)
{ {
print_address((PVOID)Frame[1]); if (!print_address((PVOID)Frame[1]))
{
DbgPrint("<%X>", (PVOID)Frame[1]);
}
Frame = (PULONG)Frame[0]; Frame = (PULONG)Frame[0];
i++; i++;
DbgPrint("\n"); DbgPrint(" ");
} }
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: irq.c,v 1.40 2004/01/18 22:58:10 gdalsnes Exp $ /* $Id: irq.c,v 1.41 2004/03/09 21:49:53 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/i386/irq.c * FILE: ntoskrnl/ke/i386/irq.c
@ -391,7 +391,7 @@ KiInterruptDispatch (ULONG Vector, PKIRQ_TRAPFRAME Trapframe)
* Enable interrupts * Enable interrupts
* NOTE: Only higher priority interrupts will get through * NOTE: Only higher priority interrupts will get through
*/ */
__asm__("sti\n\t"); Ke386EnableInterrupts();
/* /*
* Actually call the ISR. * Actually call the ISR.
@ -401,7 +401,7 @@ KiInterruptDispatch (ULONG Vector, PKIRQ_TRAPFRAME Trapframe)
/* /*
* Disable interrupts * Disable interrupts
*/ */
__asm__("cli\n\t"); Ke386DisableInterrupts();
/* /*
* Unmask the related irq * Unmask the related irq
@ -491,13 +491,7 @@ KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
* Enable interrupts * Enable interrupts
* NOTE: Only higher priority interrupts will get through * NOTE: Only higher priority interrupts will get through
*/ */
#if defined(__GNUC__) Ke386EnableInterrupts();
__asm__("sti\n\t");
#elif defined(_MSC_VER)
__asm sti
#else
#error Unknown compiler for inline assembler
#endif
/* /*
* Actually call the ISR. * Actually call the ISR.
@ -523,13 +517,7 @@ KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
/* /*
* End the system interrupt. * End the system interrupt.
*/ */
#if defined(__GNUC__) Ke386DisableInterrupts();
__asm__("cli\n\t");
#elif defined(_MSC_VER)
__asm cli
#else
#error Unknown compiler for inline assembler
#endif
HalEndSystemInterrupt (old_level, 0); HalEndSystemInterrupt (old_level, 0);

View file

@ -93,13 +93,8 @@ KeApplicationProcessorInit(VOID)
*/ */
Ki386InitializeLdt(); Ki386InitializeLdt();
#if defined(__GNUC__) /* Now we can enable interrupts. */
__asm__ __volatile__ ("sti\n\t"); Ke386EnableInterrupts();
#elif defined(_MSC_VER)
__asm sti
#else
#error Unknown compiler for inline assembler
#endif
} }
VOID INIT_FUNCTION VOID INIT_FUNCTION

View file

@ -126,14 +126,7 @@ Ki386ApplicationProcessorInitializeTSS(VOID)
Id = KeGetCurrentProcessorNumber(); Id = KeGetCurrentProcessorNumber();
Gdt = KeGetCurrentKPCR()->GDT; Gdt = KeGetCurrentKPCR()->GDT;
#if defined(__GNUC__) Ke386GetPageTableDirectory(cr3_);
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3_));
#elif defined(_MSC_VER)
__asm mov eax, cr3;
__asm mov cr3_, eax;
#else
#error Unknown compiler for inline assembler
#endif
Tss = ExAllocatePool(NonPagedPool, sizeof(KTSS)); Tss = ExAllocatePool(NonPagedPool, sizeof(KTSS));
TrapTss = ExAllocatePool(NonPagedPool, sizeof(KTSSNOIOPM)); TrapTss = ExAllocatePool(NonPagedPool, sizeof(KTSSNOIOPM));
@ -214,14 +207,7 @@ Ki386BootInitializeTSS(VOID)
extern unsigned int trap_stack, trap_stack_top; extern unsigned int trap_stack, trap_stack_top;
unsigned int base, length; unsigned int base, length;
#if defined(__GNUC__) Ke386GetPageTableDirectory(cr3_);
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3_));
#elif defined(_MSC_VER)
__asm mov eax, cr3;
__asm mov cr3_, eax;
#else
#error Unknown compiler for inline assembler
#endif
Ki386TssArray[0] = &KiBootTss; Ki386TssArray[0] = &KiBootTss;
Ki386TrapTssArray[0] = &KiBootTrapTss; Ki386TrapTssArray[0] = &KiBootTrapTss;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: process.c,v 1.18 2003/12/30 18:52:04 fireball Exp $ /* $Id: process.c,v 1.19 2004/03/09 21:49:53 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/process.c * FILE: ntoskrnl/ke/process.c
@ -81,16 +81,7 @@ KeAttachProcess (PEPROCESS Process)
CurrentThread->ThreadsProcess = Process; CurrentThread->ThreadsProcess = Process;
PageDir = Process->Pcb.DirectoryTableBase.u.LowPart; PageDir = Process->Pcb.DirectoryTableBase.u.LowPart;
DPRINT("Switching process context to %x\n",PageDir); DPRINT("Switching process context to %x\n",PageDir);
#if defined(__GNUC__) Ke386SetPageTableDirectory(PageDir);
__asm__("movl %0,%%cr3\n\t"
: /* no outputs */
: "r" (PageDir));
#elif defined(_MSC_VER)
__asm mov eax, PageDir;
__asm mov cr3, eax;
#else
#error Unknown compiler for inline assembler
#endif
KeLowerIrql(oldlvl); KeLowerIrql(oldlvl);
} }
@ -121,16 +112,7 @@ KeDetachProcess (VOID)
CurrentThread->ThreadsProcess = CurrentThread->OldProcess; CurrentThread->ThreadsProcess = CurrentThread->OldProcess;
CurrentThread->OldProcess = NULL; CurrentThread->OldProcess = NULL;
PageDir = CurrentThread->ThreadsProcess->Pcb.DirectoryTableBase.u.LowPart; PageDir = CurrentThread->ThreadsProcess->Pcb.DirectoryTableBase.u.LowPart;
#if defined(__GNUC__) Ke386SetPageTableDirectory(PageDir);
__asm__("movl %0,%%cr3\n\t"
: /* no inputs */
: "r" (PageDir));
#elif defined(_MSC_VER)
__asm mov eax, PageDir;
__asm mov cr3, eax;
#else
#error Unknown compiler for inline assembler
#endif
KeLowerIrql(oldlvl); KeLowerIrql(oldlvl);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: page.c,v 1.62 2004/01/05 14:28:21 weiden Exp $ /* $Id: page.c,v 1.63 2004/03/09 21:49:53 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/i386/page.c * FILE: ntoskrnl/mm/i386/page.c
@ -78,15 +78,7 @@ PULONG
MmGetPageDirectory(VOID) MmGetPageDirectory(VOID)
{ {
unsigned int page_dir=0; unsigned int page_dir=0;
#if defined(__GNUC__) Ke386GetPageTableDirectory(page_dir);
__asm__("movl %%cr3,%0\n\t"
: "=r" (page_dir));
#elif defined(_MSC_VER)
__asm mov eax, cr3;
__asm mov page_dir, eax;
#else
#error Unknown compiler for inline assembler
#endif
return((PULONG)page_dir); return((PULONG)page_dir);
} }

View file

@ -40,13 +40,7 @@ PsIdleThreadMain(PVOID Context)
} }
NtYieldExecution(); NtYieldExecution();
#if defined(__GNUC__) Ke386HaltProcessor();
__asm__( "hlt" );
#elif defined(_MSC_VER)
__asm hlt
#else
#error Unknown compiler for inline assembler
#endif
} }
} }