ReactOS 0.4.16-dev-329-g9223134
i386bug.c
Go to the documentation of this file.
1
2#include <freeldr.h>
3
4#include <reactos/buildno.h>
5#include <debug.h>
6
7typedef struct _FRAME
8{
9 struct _FRAME* Next;
12
14{
15 "Exception 00: DIVIDE BY ZERO",
16 "Exception 01: DEBUG EXCEPTION",
17 "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION",
18 "Exception 03: BREAKPOINT (INT 3)",
19 "Exception 04: OVERFLOW",
20 "Exception 05: BOUND EXCEPTION",
21 "Exception 06: INVALID OPCODE",
22 "Exception 07: FPU NOT AVAILABLE",
23 "Exception 08: DOUBLE FAULT",
24 "Exception 09: COPROCESSOR SEGMENT OVERRUN",
25 "Exception 0A: INVALID TSS",
26 "Exception 0B: SEGMENT NOT PRESENT",
27 "Exception 0C: STACK EXCEPTION",
28 "Exception 0D: GENERAL PROTECTION FAULT",
29 "Exception 0E: PAGE FAULT",
30 "Exception 0F: Reserved",
31 "Exception 10: COPROCESSOR ERROR",
32 "Exception 11: ALIGNMENT CHECK",
33 "Exception 12: MACHINE CHECK"
34};
35
36#define SCREEN_ATTR 0x1F // Bright white on blue background
37
38/* Used to store the current X and Y position on the screen */
41
42static void
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}
67
68static void
70{
71 CHAR Buffer[512];
72
74 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
75
77}
78
79static void
80PrintText(const CHAR *Format, ...)
81{
82 va_list argptr;
83
84 va_start(argptr, Format);
85 PrintTextV(Format, argptr);
86 va_end(argptr);
87}
88
89static void
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}
107
108void
109NTAPI
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}
196
197VOID
199 ULONG BugCode,
200 PCHAR File,
201 ULONG Line,
202 PSTR Format,
203 ...)
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}
229
230void
231NTAPI
233 ULONG BugCode,
234 PCHAR File,
235 ULONG Line)
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}
258
259void
260NTAPI
262{
263 FrLdrBugCheckEx(BugCode, 0, 0);
264}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:527
char * BugCodeStrings[]
Definition: debug.c:516
#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:36
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:69
void NTAPI FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:232
void NTAPI FrLdrBugCheck(ULONG BugCode)
Definition: i386bug.c:261
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: i386bug.c:198
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:90
static ULONG i386_ScreenPosY
Definition: i386bug.c:40
static void i386PrintText(CHAR *pszText)
Definition: i386bug.c:43
static ULONG i386_ScreenPosX
Definition: i386bug.c:39
struct _FRAME FRAME
static const CHAR * i386ExceptionDescriptionText[]
Definition: i386bug.c:13
void NTAPI i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGISTERS Special)
Definition: i386bug.c:110
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: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:8
PVOID Address
Definition: i386bug.c:10
struct _FRAME * Next
Definition: i386bug.c:9
KDESCRIPTOR Gdtr
Definition: ketypes.h:580
KDESCRIPTOR Idtr
Definition: ketypes.h:581
UINT64 Dr0
Definition: ketypes.h:416
UINT64 Rsp
Definition: ketypes.h:460
ULONG HardwareSegSs
Definition: ketypes.h:325
UINT64 Rdi
Definition: ketypes.h:444
ULONG Edi
Definition: ketypes.h:316
UINT64 Rbp
Definition: ketypes.h:446
UINT64 Rsi
Definition: ketypes.h:445
UINT64 Rdx
Definition: ketypes.h:394
ULONG EFlags
Definition: ketypes.h:458
ULONG Ebp
Definition: ketypes.h:319
UINT64 Dr6
Definition: ketypes.h:420
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:443
USHORT SegSs
Definition: ketypes.h:461
UINT64 Dr3
Definition: ketypes.h:419
ULONG Eip
Definition: ketypes.h:321
UINT64 Dr7
Definition: ketypes.h:421
USHORT SegCs
Definition: ketypes.h:454
UINT64 Rax
Definition: ketypes.h:392
UINT64 Dr1
Definition: ketypes.h:417
UINT64 R10
Definition: ketypes.h:397
UINT64 Rip
Definition: ketypes.h:453
UINT64 TrapFrame
Definition: ketypes.h:442
UINT64 Dr2
Definition: ketypes.h:418
USHORT SegEs
Definition: ketypes.h:439
USHORT SegFs
Definition: ketypes.h:440
UINT64 ErrorCode
Definition: ketypes.h:449
USHORT SegGs
Definition: ketypes.h:441
UINT64 R9
Definition: ketypes.h:396
ULONG Eax
Definition: ketypes.h:312
USHORT SegDs
Definition: ketypes.h:438
UINT64 R8
Definition: ketypes.h:395
UINT64 Rcx
Definition: ketypes.h:393
ULONG Esi
Definition: ketypes.h:317
ULONG Edx
Definition: ketypes.h:310
UINT64 R11
Definition: ketypes.h:398
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