ReactOS 0.4.15-dev-7906-g1b85a5f
i386bug.c
Go to the documentation of this file.
1
2#include <freeldr.h>
3
4#include <debug.h>
5
6typedef struct _FRAME
7{
8 struct _FRAME* Next;
11
13{
14 "Exception 00: DIVIDE BY ZERO",
15 "Exception 01: DEBUG EXCEPTION",
16 "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION",
17 "Exception 03: BREAKPOINT (INT 3)",
18 "Exception 04: OVERFLOW",
19 "Exception 05: BOUND EXCEPTION",
20 "Exception 06: INVALID OPCODE",
21 "Exception 07: FPU NOT AVAILABLE",
22 "Exception 08: DOUBLE FAULT",
23 "Exception 09: COPROCESSOR SEGMENT OVERRUN",
24 "Exception 0A: INVALID TSS",
25 "Exception 0B: SEGMENT NOT PRESENT",
26 "Exception 0C: STACK EXCEPTION",
27 "Exception 0D: GENERAL PROTECTION FAULT",
28 "Exception 0E: PAGE FAULT",
29 "Exception 0F: Reserved",
30 "Exception 10: COPROCESSOR ERROR",
31 "Exception 11: ALIGNMENT CHECK",
32 "Exception 12: MACHINE CHECK"
33};
34
35#define SCREEN_ATTR 0x1F // Bright white on blue background
36
37/* Used to store the current X and Y position on the screen */
40
41static void
43{
45
47
48 for (; *pszText != ANSI_NULL; ++pszText)
49 {
50 if (*pszText == '\n')
51 {
54 continue;
55 }
56
58 if (++i386_ScreenPosX >= Width)
59 {
62 }
63 // FIXME: Implement vertical screen scrolling if we are at the end of the screen.
64 }
65}
66
67static void
69{
70 CHAR Buffer[512];
71
73 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
74
76}
77
78static void
79PrintText(const CHAR *Format, ...)
80{
81 va_list argptr;
82
83 va_start(argptr, Format);
84 PrintTextV(Format, argptr);
85 va_end(argptr);
86}
87
88static void
90{
91 FRAME* Frame;
92
93 PrintText("Frames:\n");
94 for (Frame =
95#ifdef _M_IX86
96 (FRAME*)TrapFrame->Ebp;
97#else
98 (FRAME*)TrapFrame->TrapFrame;
99#endif
100 Frame != NULL && (ULONG_PTR)Frame < STACKADDR;
101 Frame = Frame->Next)
102 {
103 PrintText("%p ", Frame->Address);
104 }
105}
106
107void
108NTAPI
110{
111 PUCHAR InstructionPointer;
112
115 i386_ScreenPosX = 0;
116 i386_ScreenPosY = 0;
117
118 PrintText("An error occured in " VERSION "\n"
119 "Report this error on the ReactOS Bug Tracker: https://jira.reactos.org\n\n"
120 "0x%02lx: %s\n\n", TrapIndex, i386ExceptionDescriptionText[TrapIndex]);
121
122#ifdef _M_IX86
123 PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
124 TrapFrame->Eax, TrapFrame->HardwareEsp, Special->Cr0, TrapFrame->Dr0);
125 PrintText("EBX: %.8lx EBP: %.8lx CR1: ???????? DR1: %.8lx\n",
126 TrapFrame->Ebx, TrapFrame->Ebp, TrapFrame->Dr1);
127 PrintText("ECX: %.8lx ESI: %.8lx CR2: %.8lx DR2: %.8lx\n",
128 TrapFrame->Ecx, TrapFrame->Esi, Special->Cr2, TrapFrame->Dr2);
129 PrintText("EDX: %.8lx EDI: %.8lx CR3: %.8lx DR3: %.8lx\n",
130 TrapFrame->Edx, TrapFrame->Edi, Special->Cr3, TrapFrame->Dr3);
131 PrintText("%*s CR4: %.8lx DR6: %.8lx\n",
132 41, "", Special->Cr4, TrapFrame->Dr6);
133 PrintText("%*s DR7: %.8lx\n",
134 62, "", TrapFrame->Dr7);
135
136 /* NOTE: Segment registers are intrinsically 16 bits. Even if the x86
137 * KTRAP_FRAME structure stores them as ULONG, only their lower 16 bits
138 * are initialized. We thus cast them to USHORT before display. */
139 PrintText(" CS: %.4lx EIP: %.8lx\n",
140 (USHORT)TrapFrame->SegCs, TrapFrame->Eip);
141 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
142 (USHORT)TrapFrame->SegDs, TrapFrame->ErrCode);
143 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
144 (USHORT)TrapFrame->SegEs, TrapFrame->EFlags);
145 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
146 // " FS: %.4lx GDTR: Base %.8lx Limit %.4x\n"
147 (USHORT)TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
148 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
149 // " GS: %.4lx IDTR: Base %.8lx Limit %.4x\n",
150 (USHORT)TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
151 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
152 (USHORT)TrapFrame->HardwareSegSs, Special->Ldtr, Special->Tr);
153#else
154 PrintText("RAX: %.8lx R8: %.8lx R12: %.8lx RSI: %.8lx\n",
155 TrapFrame->Rax, TrapFrame->R8, 0, TrapFrame->Rsi);
156 PrintText("RBX: %.8lx R9: %.8lx R13: %.8lx RDI: %.8lx\n",
157 TrapFrame->Rbx, TrapFrame->R9, 0, TrapFrame->Rdi);
158 PrintText("RCX: %.8lx R10: %.8lx R14: %.8lx RBP: %.8lx\n",
159 TrapFrame->Rcx, TrapFrame->R10, 0, TrapFrame->Rbp);
160 PrintText("RDX: %.8lx R11: %.8lx R15: %.8lx RSP: %.8lx\n",
161 TrapFrame->Rdx, TrapFrame->R11, 0, TrapFrame->Rsp);
162
163 PrintText(" CS: %.4lx RIP: %.8lx\n",
164 TrapFrame->SegCs, TrapFrame->Rip);
165 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
166 TrapFrame->SegDs, TrapFrame->ErrorCode);
167 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
168 TrapFrame->SegEs, TrapFrame->EFlags);
169 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
170 TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
171 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
172 TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
173 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
174 TrapFrame->SegSs, Special->Ldtr, Special->Tr);
175#endif
176
177 /* Display the stack frames */
178 i386PrintFrames(TrapFrame);
179
180#ifdef _M_IX86
181 InstructionPointer = (PUCHAR)TrapFrame->Eip;
182#else
183 InstructionPointer = (PUCHAR)TrapFrame->Rip;
184#endif
185 /* Adjust IP for #BP (INT 03) or #OF to point to the offending instruction */
186 if ((TrapIndex == 3) || (TrapIndex == 4))
187 InstructionPointer--;
188
189 PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
190 InstructionPointer[0], InstructionPointer[1],
191 InstructionPointer[2], InstructionPointer[3],
192 InstructionPointer[4], InstructionPointer[5],
193 InstructionPointer[6], InstructionPointer[7]);
194}
195
196VOID
198 ULONG BugCode,
199 PCHAR File,
200 ULONG Line,
201 PSTR Format,
202 ...)
203{
204 va_list argptr;
205
208 i386_ScreenPosX = 0;
209 i386_ScreenPosY = 0;
210
211 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
212
213 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
214
215 if (File)
216 {
217 PrintText("Location: %s:%ld\n\n", File, Line);
218 }
219
220 va_start(argptr, Format);
221 PrintTextV(Format, argptr);
222 va_end(argptr);
223
224 _disable();
225 __halt();
226 for (;;);
227}
228
229void
230NTAPI
232 ULONG BugCode,
233 PCHAR File,
234 ULONG Line)
235{
238 i386_ScreenPosX = 0;
239 i386_ScreenPosY = 0;
240
241 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
242
243 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
244
245 if (File)
246 {
247 PrintText("Location: %s:%ld\n\n", File, Line);
248 }
249
250 PrintText("Bug Information:\n %p\n %p\n %p\n %p\n %p\n\n",
252
253 _disable();
254 __halt();
255 for (;;);
256}
257
258void
259NTAPI
261{
262 FrLdrBugCheckEx(BugCode, 0, 0);
263}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define VERSION
Definition: rdesktop.h:45
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:531
char * BugCodeStrings[]
Definition: debug.c:520
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoGetDisplaySize(W, H, D)
Definition: machine.h:96
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:104
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:106
Definition: bufpool.h:45
Definition: File.h:16
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define SCREEN_ATTR
Definition: i386bug.c:35
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:68
void NTAPI FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:231
void NTAPI FrLdrBugCheck(ULONG BugCode)
Definition: i386bug.c:260
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: i386bug.c:197
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:89
static ULONG i386_ScreenPosY
Definition: i386bug.c:39
static void i386PrintText(CHAR *pszText)
Definition: i386bug.c:42
static ULONG i386_ScreenPosX
Definition: i386bug.c:38
struct _FRAME FRAME
static const CHAR * i386ExceptionDescriptionText[]
Definition: i386bug.c:12
void NTAPI i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGISTERS Special)
Definition: i386bug.c:109
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:79
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1714
#define Unused(x)
Definition: atlwin.h:28
#define ANSI_NULL
unsigned short USHORT
Definition: pedump.c:61
Definition: ncftp.h:79
ULONG Base
Definition: ketypes.h:450
USHORT Limit
Definition: ketypes.h:449
Definition: i386bug.c:7
PVOID Address
Definition: i386bug.c:9
struct _FRAME * Next
Definition: i386bug.c:8
KDESCRIPTOR Gdtr
Definition: ketypes.h:576
KDESCRIPTOR Idtr
Definition: ketypes.h:577
UINT64 Rsp
Definition: ketypes.h:456
ULONG HardwareSegSs
Definition: ketypes.h:325
UINT64 Dr6
Definition: ketypes.h:416
UINT64 Rdi
Definition: ketypes.h:440
ULONG Edi
Definition: ketypes.h:316
UINT64 Rbp
Definition: ketypes.h:442
UINT64 Rsi
Definition: ketypes.h:441
UINT64 Rdx
Definition: ketypes.h:390
ULONG EFlags
Definition: ketypes.h:454
ULONG Ebp
Definition: ketypes.h:319
ULONG Ebx
Definition: ketypes.h:318
ULONG ErrCode
Definition: ketypes.h:320
UINT64 Dr0
Definition: ketypes.h:412
ULONG HardwareEsp
Definition: ketypes.h:324
ULONG Ecx
Definition: ketypes.h:311
UINT64 Rbx
Definition: ketypes.h:439
UINT64 Dr7
Definition: ketypes.h:417
USHORT SegSs
Definition: ketypes.h:457
UINT64 Dr1
Definition: ketypes.h:413
ULONG Eip
Definition: ketypes.h:321
USHORT SegCs
Definition: ketypes.h:450
UINT64 Rax
Definition: ketypes.h:388
UINT64 Dr3
Definition: ketypes.h:415
UINT64 R10
Definition: ketypes.h:393
UINT64 Rip
Definition: ketypes.h:449
UINT64 TrapFrame
Definition: ketypes.h:438
USHORT SegEs
Definition: ketypes.h:435
USHORT SegFs
Definition: ketypes.h:436
UINT64 ErrorCode
Definition: ketypes.h:445
USHORT SegGs
Definition: ketypes.h:437
UINT64 Dr2
Definition: ketypes.h:414
UINT64 R9
Definition: ketypes.h:392
ULONG Eax
Definition: ketypes.h:312
USHORT SegDs
Definition: ketypes.h:434
UINT64 R8
Definition: ketypes.h:391
UINT64 Rcx
Definition: ketypes.h:389
ULONG Esi
Definition: ketypes.h:317
ULONG Edx
Definition: ketypes.h:310
UINT64 R11
Definition: ketypes.h:394
Definition: match.c:390
else
Definition: tritemp.h:161
char * PSTR
Definition: typedefs.h:51
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
#define STACKADDR
Definition: x86common.h:16
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175