ReactOS 0.4.16-dev-847-g386fccd
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 "DIVIDE BY ZERO",
16 "DEBUG EXCEPTION",
17 "NON-MASKABLE INTERRUPT EXCEPTION",
18 "BREAKPOINT (INT 3)",
19 "OVERFLOW",
20 "BOUND EXCEPTION",
21 "INVALID OPCODE",
22 "FPU NOT AVAILABLE",
23 "DOUBLE FAULT",
24 "COPROCESSOR SEGMENT OVERRUN",
25 "INVALID TSS",
26 "SEGMENT NOT PRESENT",
27 "STACK EXCEPTION",
28 "GENERAL PROTECTION FAULT",
29 "PAGE FAULT",
30 "Reserved",
31 "COPROCESSOR ERROR",
32 "ALIGNMENT CHECK",
33 "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: Exception %02X: %s\n\n",
122 TrapIndex,
123 TrapIndex,
125
126#ifdef _M_IX86
127 PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
128 TrapFrame->Eax, TrapFrame->HardwareEsp, Special->Cr0, TrapFrame->Dr0);
129 PrintText("EBX: %.8lx EBP: %.8lx CR1: ???????? DR1: %.8lx\n",
130 TrapFrame->Ebx, TrapFrame->Ebp, TrapFrame->Dr1);
131 PrintText("ECX: %.8lx ESI: %.8lx CR2: %.8lx DR2: %.8lx\n",
132 TrapFrame->Ecx, TrapFrame->Esi, Special->Cr2, TrapFrame->Dr2);
133 PrintText("EDX: %.8lx EDI: %.8lx CR3: %.8lx DR3: %.8lx\n",
134 TrapFrame->Edx, TrapFrame->Edi, Special->Cr3, TrapFrame->Dr3);
135 PrintText("%*s CR4: %.8lx DR6: %.8lx\n",
136 41, "", Special->Cr4, TrapFrame->Dr6);
137 PrintText("%*s DR7: %.8lx\n",
138 62, "", TrapFrame->Dr7);
139
140 /* NOTE: Segment registers are intrinsically 16 bits. Even if the x86
141 * KTRAP_FRAME structure stores them as ULONG, only their lower 16 bits
142 * are initialized. We thus cast them to USHORT before display. */
143 PrintText(" CS: %.4lx EIP: %.8lx\n",
144 (USHORT)TrapFrame->SegCs, TrapFrame->Eip);
145 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
146 (USHORT)TrapFrame->SegDs, TrapFrame->ErrCode);
147 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
148 (USHORT)TrapFrame->SegEs, TrapFrame->EFlags);
149 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
150 // " FS: %.4lx GDTR: Base %.8lx Limit %.4x\n"
151 (USHORT)TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
152 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
153 // " GS: %.4lx IDTR: Base %.8lx Limit %.4x\n",
154 (USHORT)TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
155 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
156 (USHORT)TrapFrame->HardwareSegSs, Special->Ldtr, Special->Tr);
157#else
158 PrintText("RAX: %.8lx R8: %.8lx R12: %.8lx RSI: %.8lx\n",
159 TrapFrame->Rax, TrapFrame->R8, 0, TrapFrame->Rsi);
160 PrintText("RBX: %.8lx R9: %.8lx R13: %.8lx RDI: %.8lx\n",
161 TrapFrame->Rbx, TrapFrame->R9, 0, TrapFrame->Rdi);
162 PrintText("RCX: %.8lx R10: %.8lx R14: %.8lx RBP: %.8lx\n",
163 TrapFrame->Rcx, TrapFrame->R10, 0, TrapFrame->Rbp);
164 PrintText("RDX: %.8lx R11: %.8lx R15: %.8lx RSP: %.8lx\n",
165 TrapFrame->Rdx, TrapFrame->R11, 0, TrapFrame->Rsp);
166
167 PrintText(" CS: %.4lx RIP: %.8lx\n",
168 TrapFrame->SegCs, TrapFrame->Rip);
169 PrintText(" DS: %.4lx ERROR CODE: %.8lx\n",
170 TrapFrame->SegDs, TrapFrame->ErrorCode);
171 PrintText(" ES: %.4lx EFLAGS: %.8lx\n",
172 TrapFrame->SegEs, TrapFrame->EFlags);
173 PrintText(" FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
174 TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
175 PrintText(" GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
176 TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
177 PrintText(" SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
178 TrapFrame->SegSs, Special->Ldtr, Special->Tr);
179#endif
180
181 /* Display the stack frames */
182 i386PrintFrames(TrapFrame);
183
184#ifdef _M_IX86
185 InstructionPointer = (PUCHAR)TrapFrame->Eip;
186#else
187 InstructionPointer = (PUCHAR)TrapFrame->Rip;
188#endif
189 /* Adjust IP for #BP (INT 03) or #OF to point to the offending instruction */
190 if ((TrapIndex == 3) || (TrapIndex == 4))
191 InstructionPointer--;
192
193 PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
194 InstructionPointer[0], InstructionPointer[1],
195 InstructionPointer[2], InstructionPointer[3],
196 InstructionPointer[4], InstructionPointer[5],
197 InstructionPointer[6], InstructionPointer[7]);
198}
199
201VOID
203 ULONG BugCode,
204 PCHAR File,
205 ULONG Line,
206 PSTR Format,
207 ...)
208{
209 va_list argptr;
210
213 i386_ScreenPosX = 0;
214 i386_ScreenPosY = 0;
215
216 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
217
218 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
219
220 if (File)
221 {
222 PrintText("Location: %s:%ld\n\n", File, Line);
223 }
224
225 va_start(argptr, Format);
226 PrintTextV(Format, argptr);
227 va_end(argptr);
228
229 _disable();
230 __halt();
231 for (;;);
232}
233
234static
236void
238 ULONG BugCode,
239 PCHAR File,
240 ULONG Line)
241{
244 i386_ScreenPosX = 0;
245 i386_ScreenPosY = 0;
246
247 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
248
249 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
250
251 if (File)
252 {
253 PrintText("Location: %s:%ld\n\n", File, Line);
254 }
255
256 PrintText("Bug Information:\n %p\n %p\n %p\n %p\n %p\n\n",
258
259 _disable();
260 __halt();
261 for (;;);
262}
263
265void
266NTAPI
268{
269 FrLdrBugCheckEx(BugCode, 0, 0);
270}
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:561
char * BugCodeStrings[]
Definition: debug.c:550
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoGetDisplaySize(W, H, D)
Definition: machine.h:96
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:102
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:104
Definition: bufpool.h:45
Definition: File.h:16
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
static DECLSPEC_NORETURN void FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:237
#define SCREEN_ATTR
Definition: i386bug.c:36
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:69
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
DECLSPEC_NORETURN VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: i386bug.c:202
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
DECLSPEC_NORETURN void NTAPI FrLdrBugCheck(ULONG BugCode)
Definition: i386bug.c:267
void __cdecl _disable(void)
Definition: intrin_arm.h:365
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1728
#define Unused(x)
Definition: atlwin.h:28
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
#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: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 TrapFrame
Definition: ketypes.h:462
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
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