ReactOS 0.4.16-dev-570-g1868985
i386bug.c File Reference
#include <freeldr.h>
#include <reactos/buildno.h>
#include <debug.h>
Include dependency graph for i386bug.c:

Go to the source code of this file.

Classes

struct  _FRAME
 

Macros

#define SCREEN_ATTR   0x1F
 

Typedefs

typedef struct _FRAME FRAME
 

Functions

static void i386PrintText (CHAR *pszText)
 
static void PrintTextV (const CHAR *Format, va_list args)
 
static void PrintText (const CHAR *Format,...)
 
static void i386PrintFrames (PKTRAP_FRAME TrapFrame)
 
void NTAPI i386PrintExceptionText (ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGISTERS Special)
 
VOID FrLdrBugCheckWithMessage (ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
 
void NTAPI FrLdrBugCheckEx (ULONG BugCode, PCHAR File, ULONG Line)
 
void NTAPI FrLdrBugCheck (ULONG BugCode)
 

Variables

static const CHARi386ExceptionDescriptionText []
 
static ULONG i386_ScreenPosX = 0
 
static ULONG i386_ScreenPosY = 0
 

Macro Definition Documentation

◆ SCREEN_ATTR

#define SCREEN_ATTR   0x1F

Definition at line 36 of file i386bug.c.

Typedef Documentation

◆ FRAME

typedef struct _FRAME FRAME

Function Documentation

◆ FrLdrBugCheck()

void NTAPI FrLdrBugCheck ( ULONG  BugCode)

Definition at line 261 of file i386bug.c.

262{
263 FrLdrBugCheckEx(BugCode, 0, 0);
264}
void NTAPI FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:232

◆ FrLdrBugCheckEx()

void NTAPI FrLdrBugCheckEx ( ULONG  BugCode,
PCHAR  File,
ULONG  Line 
)

Definition at line 232 of file i386bug.c.

236{
239 i386_ScreenPosX = 0;
240 i386_ScreenPosY = 0;
241
242 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
243
244 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
245
246 if (File)
247 {
248 PrintText("Location: %s:%ld\n\n", File, Line);
249 }
250
251 PrintText("Bug Information:\n %p\n %p\n %p\n %p\n %p\n\n",
253
254 _disable();
255 __halt();
256 for (;;);
257}
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:527
char * BugCodeStrings[]
Definition: debug.c:516
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:104
Definition: File.h:16
#define FALSE
Definition: types.h:117
#define SCREEN_ATTR
Definition: i386bug.c:36
static ULONG i386_ScreenPosY
Definition: i386bug.c:40
static ULONG i386_ScreenPosX
Definition: i386bug.c:39
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:80
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1728
Definition: ncftp.h:79

Referenced by FrLdrBugCheck().

◆ FrLdrBugCheckWithMessage()

VOID FrLdrBugCheckWithMessage ( ULONG  BugCode,
PCHAR  File,
ULONG  Line,
PSTR  Format,
  ... 
)

Definition at line 198 of file i386bug.c.

204{
205 va_list argptr;
206
209 i386_ScreenPosX = 0;
210 i386_ScreenPosY = 0;
211
212 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
213
214 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
215
216 if (File)
217 {
218 PrintText("Location: %s:%ld\n\n", File, Line);
219 }
220
221 va_start(argptr, Format);
222 PrintTextV(Format, argptr);
223 va_end(argptr);
224
225 _disable();
226 __halt();
227 for (;;);
228}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:69

◆ i386PrintExceptionText()

void NTAPI i386PrintExceptionText ( ULONG  TrapIndex,
PKTRAP_FRAME  TrapFrame,
PKSPECIAL_REGISTERS  Special 
)

Definition at line 110 of file i386bug.c.

111{
112 PUCHAR InstructionPointer;
113
116 i386_ScreenPosX = 0;
117 i386_ScreenPosY = 0;
118
119 PrintText("FreeLdr " KERNEL_VERSION_STR " " KERNEL_VERSION_BUILD_STR "\n"
120 "Report this error on the ReactOS Bug Tracker: https://jira.reactos.org\n\n"
121 "0x%02lx: %s\n\n", TrapIndex, i386ExceptionDescriptionText[TrapIndex]);
122
123#ifdef _M_IX86
124 PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
125 TrapFrame->Eax, TrapFrame->HardwareEsp, Special->Cr0, TrapFrame->Dr0);
126 PrintText("EBX: %.8lx EBP: %.8lx CR1: ???????? DR1: %.8lx\n",
127 TrapFrame->Ebx, TrapFrame->Ebp, TrapFrame->Dr1);
128 PrintText("ECX: %.8lx ESI: %.8lx CR2: %.8lx DR2: %.8lx\n",
129 TrapFrame->Ecx, TrapFrame->Esi, Special->Cr2, TrapFrame->Dr2);
130 PrintText("EDX: %.8lx EDI: %.8lx CR3: %.8lx DR3: %.8lx\n",
131 TrapFrame->Edx, TrapFrame->Edi, Special->Cr3, TrapFrame->Dr3);
132 PrintText("%*s CR4: %.8lx DR6: %.8lx\n",
133 41, "", Special->Cr4, TrapFrame->Dr6);
134 PrintText("%*s DR7: %.8lx\n",
135 62, "", TrapFrame->Dr7);
136
137 /* NOTE: Segment registers are intrinsically 16 bits. Even if the x86
138 * KTRAP_FRAME structure stores them as ULONG, only their lower 16 bits
139 * are initialized. We thus cast them to USHORT before display. */
140 PrintText(" CS: %.4lx EIP: %.8lx\n",
141 (USHORT)TrapFrame->SegCs, TrapFrame->Eip);
142 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
143 (USHORT)TrapFrame->SegDs, TrapFrame->ErrCode);
144 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
145 (USHORT)TrapFrame->SegEs, TrapFrame->EFlags);
146 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
147 // " FS: %.4lx GDTR: Base %.8lx Limit %.4x\n"
148 (USHORT)TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
149 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
150 // " GS: %.4lx IDTR: Base %.8lx Limit %.4x\n",
151 (USHORT)TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
152 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
153 (USHORT)TrapFrame->HardwareSegSs, Special->Ldtr, Special->Tr);
154#else
155 PrintText("RAX: %.8lx R8: %.8lx R12: %.8lx RSI: %.8lx\n",
156 TrapFrame->Rax, TrapFrame->R8, 0, TrapFrame->Rsi);
157 PrintText("RBX: %.8lx R9: %.8lx R13: %.8lx RDI: %.8lx\n",
158 TrapFrame->Rbx, TrapFrame->R9, 0, TrapFrame->Rdi);
159 PrintText("RCX: %.8lx R10: %.8lx R14: %.8lx RBP: %.8lx\n",
160 TrapFrame->Rcx, TrapFrame->R10, 0, TrapFrame->Rbp);
161 PrintText("RDX: %.8lx R11: %.8lx R15: %.8lx RSP: %.8lx\n",
162 TrapFrame->Rdx, TrapFrame->R11, 0, TrapFrame->Rsp);
163
164 PrintText(" CS: %.4lx RIP: %.8lx\n",
165 TrapFrame->SegCs, TrapFrame->Rip);
166 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
167 TrapFrame->SegDs, TrapFrame->ErrorCode);
168 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
169 TrapFrame->SegEs, TrapFrame->EFlags);
170 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
171 TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
172 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
173 TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
174 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
175 TrapFrame->SegSs, Special->Ldtr, Special->Tr);
176#endif
177
178 /* Display the stack frames */
179 i386PrintFrames(TrapFrame);
180
181#ifdef _M_IX86
182 InstructionPointer = (PUCHAR)TrapFrame->Eip;
183#else
184 InstructionPointer = (PUCHAR)TrapFrame->Rip;
185#endif
186 /* Adjust IP for #BP (INT 03) or #OF to point to the offending instruction */
187 if ((TrapIndex == 3) || (TrapIndex == 4))
188 InstructionPointer--;
189
190 PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
191 InstructionPointer[0], InstructionPointer[1],
192 InstructionPointer[2], InstructionPointer[3],
193 InstructionPointer[4], InstructionPointer[5],
194 InstructionPointer[6], InstructionPointer[7]);
195}
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:90
static const CHAR * i386ExceptionDescriptionText[]
Definition: i386bug.c:13
unsigned short USHORT
Definition: pedump.c:61
ULONG Base
Definition: ketypes.h:450
USHORT Limit
Definition: ketypes.h:449
KDESCRIPTOR Gdtr
Definition: ketypes.h:600
KDESCRIPTOR Idtr
Definition: ketypes.h:601
UINT64 Dr0
Definition: ketypes.h:436
UINT64 Rsp
Definition: ketypes.h:480
ULONG HardwareSegSs
Definition: ketypes.h:325
UINT64 Rdi
Definition: ketypes.h:464
ULONG Edi
Definition: ketypes.h:316
UINT64 Rbp
Definition: ketypes.h:466
UINT64 Rsi
Definition: ketypes.h:465
UINT64 Rdx
Definition: ketypes.h:414
ULONG EFlags
Definition: ketypes.h:478
ULONG Ebp
Definition: ketypes.h:319
UINT64 Dr6
Definition: ketypes.h:440
ULONG Ebx
Definition: ketypes.h:318
ULONG ErrCode
Definition: ketypes.h:320
ULONG HardwareEsp
Definition: ketypes.h:324
ULONG Ecx
Definition: ketypes.h:311
UINT64 Rbx
Definition: ketypes.h:463
USHORT SegSs
Definition: ketypes.h:481
UINT64 Dr3
Definition: ketypes.h:439
ULONG Eip
Definition: ketypes.h:321
UINT64 Dr7
Definition: ketypes.h:441
USHORT SegCs
Definition: ketypes.h:474
UINT64 Rax
Definition: ketypes.h:412
UINT64 Dr1
Definition: ketypes.h:437
UINT64 R10
Definition: ketypes.h:417
UINT64 Rip
Definition: ketypes.h:473
UINT64 Dr2
Definition: ketypes.h:438
USHORT SegEs
Definition: ketypes.h:459
USHORT SegFs
Definition: ketypes.h:460
UINT64 ErrorCode
Definition: ketypes.h:469
USHORT SegGs
Definition: ketypes.h:461
UINT64 R9
Definition: ketypes.h:416
ULONG Eax
Definition: ketypes.h:312
USHORT SegDs
Definition: ketypes.h:458
UINT64 R8
Definition: ketypes.h:415
UINT64 Rcx
Definition: ketypes.h:413
ULONG Esi
Definition: ketypes.h:317
ULONG Edx
Definition: ketypes.h:310
UINT64 R11
Definition: ketypes.h:418
unsigned char * PUCHAR
Definition: typedefs.h:53

◆ i386PrintFrames()

static void i386PrintFrames ( PKTRAP_FRAME  TrapFrame)
static

Definition at line 90 of file i386bug.c.

91{
92 FRAME* Frame;
93
94 PrintText("Frames:\n");
95 for (Frame =
96#ifdef _M_IX86
97 (FRAME*)TrapFrame->Ebp;
98#else
99 (FRAME*)TrapFrame->TrapFrame;
100#endif
101 Frame != NULL && (ULONG_PTR)Frame < STACKADDR;
102 Frame = Frame->Next)
103 {
104 PrintText("%p ", Frame->Address);
105 }
106}
#define NULL
Definition: types.h:112
Definition: i386bug.c:8
PVOID Address
Definition: i386bug.c:10
struct _FRAME * Next
Definition: i386bug.c:9
UINT64 TrapFrame
Definition: ketypes.h:462
else
Definition: tritemp.h:161
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STACKADDR
Definition: x86common.h:16

Referenced by i386PrintExceptionText().

◆ i386PrintText()

static void i386PrintText ( CHAR pszText)
static

Definition at line 43 of file i386bug.c.

44{
46
48
49 for (; *pszText != ANSI_NULL; ++pszText)
50 {
51 if (*pszText == '\n')
52 {
55 continue;
56 }
57
59 if (++i386_ScreenPosX >= Width)
60 {
63 }
64 // FIXME: Implement vertical screen scrolling if we are at the end of the screen.
65 }
66}
#define MachVideoGetDisplaySize(W, H, D)
Definition: machine.h:96
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:106
#define Unused(x)
Definition: atlwin.h:28
#define ANSI_NULL
uint32_t ULONG
Definition: typedefs.h:59
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89

Referenced by PrintTextV().

◆ PrintText()

static void PrintText ( const CHAR Format,
  ... 
)
static

Definition at line 80 of file i386bug.c.

81{
82 va_list argptr;
83
84 va_start(argptr, Format);
85 PrintTextV(Format, argptr);
86 va_end(argptr);
87}

Referenced by FrLdrBugCheckEx(), FrLdrBugCheckWithMessage(), i386PrintExceptionText(), and i386PrintFrames().

◆ PrintTextV()

static void PrintTextV ( const CHAR Format,
va_list  args 
)
static

Definition at line 69 of file i386bug.c.

70{
71 CHAR Buffer[512];
72
74 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
75
77}
Definition: bufpool.h:45
static void i386PrintText(CHAR *pszText)
Definition: i386bug.c:43
Definition: match.c:390
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175

Referenced by FrLdrBugCheckWithMessage(), and PrintText().

Variable Documentation

◆ i386_ScreenPosX

ULONG i386_ScreenPosX = 0
static

◆ i386_ScreenPosY

ULONG i386_ScreenPosY = 0
static

◆ i386ExceptionDescriptionText

const CHAR* i386ExceptionDescriptionText[]
static
Initial value:
=
{
"Exception 00: DIVIDE BY ZERO",
"Exception 01: DEBUG EXCEPTION",
"Exception 02: NON-MASKABLE INTERRUPT EXCEPTION",
"Exception 03: BREAKPOINT (INT 3)",
"Exception 04: OVERFLOW",
"Exception 05: BOUND EXCEPTION",
"Exception 06: INVALID OPCODE",
"Exception 07: FPU NOT AVAILABLE",
"Exception 08: DOUBLE FAULT",
"Exception 09: COPROCESSOR SEGMENT OVERRUN",
"Exception 0A: INVALID TSS",
"Exception 0B: SEGMENT NOT PRESENT",
"Exception 0C: STACK EXCEPTION",
"Exception 0D: GENERAL PROTECTION FAULT",
"Exception 0E: PAGE FAULT",
"Exception 0F: Reserved",
"Exception 10: COPROCESSOR ERROR",
"Exception 11: ALIGNMENT CHECK",
"Exception 12: MACHINE CHECK"
}

Definition at line 13 of file i386bug.c.

Referenced by i386PrintExceptionText().