ReactOS  0.4.13-dev-73-gcfe54aa
i386bug.c
Go to the documentation of this file.
1 
2 #include <freeldr.h>
3 
4 #include <debug.h>
5 
6 typedef struct _FRAME
7 {
8  struct _FRAME *Next;
9  void *Address;
10 } FRAME;
11 
12 static const char *i386ExceptionDescriptionText[] =
13 {
14  "Exception 00: DIVIDE BY ZERO\n\n",
15  "Exception 01: DEBUG EXCEPTION\n\n",
16  "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION\n\n",
17  "Exception 03: BREAKPOINT (INT 3)\n\n",
18  "Exception 04: OVERFLOW\n\n",
19  "Exception 05: BOUND EXCEPTION\n\n",
20  "Exception 06: INVALID OPCODE\n\n",
21  "Exception 07: FPU NOT AVAILABLE\n\n",
22  "Exception 08: DOUBLE FAULT\n\n",
23  "Exception 09: COPROCESSOR SEGMENT OVERRUN\n\n",
24  "Exception 0A: INVALID TSS\n\n",
25  "Exception 0B: SEGMENT NOT PRESENT\n\n",
26  "Exception 0C: STACK EXCEPTION\n\n",
27  "Exception 0D: GENERAL PROTECTION FAULT\n\n",
28  "Exception 0E: PAGE FAULT\n\n",
29  "Exception 0F: Reserved\n\n",
30  "Exception 10: COPROCESSOR ERROR\n\n",
31  "Exception 11: ALIGNMENT CHECK\n\n",
32  "Exception 12: MACHINE CHECK\n\n"
33 };
34 
35 #define SCREEN_ATTR 0x1F // Bright white on blue background
36 
37 #if 0
38 static void
39 i386PrintChar(char chr, ULONG x, ULONG y)
40 {
42 }
43 #endif
44 
45 /* Used to store the current X and Y position on the screen */
48 
49 static void
50 i386PrintText(char *pszText)
51 {
52  char chr;
53  while (1)
54  {
55  chr = *pszText++;
56 
57  if (chr == 0) break;
58  if (chr == '\n')
59  {
61  i386_ScreenPosX = 0;
62  continue;
63  }
64 
67  }
68 }
69 
70 static void
71 PrintText(const char *format, ...)
72 {
73  va_list argptr;
74  char buffer[256];
75 
76  va_start(argptr, format);
77  _vsnprintf(buffer, sizeof(buffer), format, argptr);
78  buffer[sizeof(buffer) - 1] = 0;
79  va_end(argptr);
81 }
82 
83 static void
85 {
86  FRAME *Frame;
87 
88  PrintText("Frames:\n");
89 #ifdef _M_IX86
90  for (Frame = (FRAME*)TrapFrame->Ebp;
91  Frame != 0 && (ULONG_PTR)Frame < STACKADDR;
92  Frame = Frame->Next)
93 #else
94  for (Frame = (FRAME*)TrapFrame->TrapFrame;
95  Frame != 0 && (ULONG_PTR)Frame < STACKADDR;
96  Frame = Frame->Next)
97 #endif
98  {
99  PrintText("%p ", Frame->Address);
100  }
101 }
102 
103 void
104 NTAPI
106 {
107  PUCHAR InstructionPointer;
108 
111  i386_ScreenPosX = 0;
112  i386_ScreenPosY = 0;
113 
114  PrintText("An error occured in " VERSION "\n"
115  "Report this error to the ReactOS Development mailing list <ros-dev@reactos.org>\n\n"
116  "0x%02lx: %s\n", TrapIndex, i386ExceptionDescriptionText[TrapIndex]);
117 #ifdef _M_IX86
118  PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
119  TrapFrame->Eax, TrapFrame->HardwareEsp, Special->Cr0, TrapFrame->Dr0);
120  PrintText("EBX: %.8lx EBP: %.8lx CR1: ???????? DR1: %.8lx\n",
121  TrapFrame->Ebx, TrapFrame->Ebp, TrapFrame->Dr1);
122  PrintText("ECX: %.8lx ESI: %.8lx CR2: %.8lx DR2: %.8lx\n",
123  TrapFrame->Ecx, TrapFrame->Esi, Special->Cr2, TrapFrame->Dr2);
124  PrintText("EDX: %.8lx EDI: %.8lx CR3: %.8lx DR3: %.8lx\n",
125  TrapFrame->Edx, TrapFrame->Edi, Special->Cr3, TrapFrame->Dr3);
126  PrintText(" DR6: %.8lx\n",
127  TrapFrame->Dr6);
128  PrintText(" DR7: %.8lx\n\n",
129  TrapFrame->Dr7);
130  PrintText("CS: %.4lx EIP: %.8lx\n",
131  TrapFrame->SegCs, TrapFrame->Eip);
132  PrintText("DS: %.4lx ERROR CODE: %.8lx\n",
133  TrapFrame->SegDs, TrapFrame->ErrCode);
134  PrintText("ES: %.4lx EFLAGS: %.8lx\n",
135  TrapFrame->SegEs, TrapFrame->EFlags);
136  PrintText("FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
137  TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
138  PrintText("GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
139  TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
140  PrintText("SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
141  TrapFrame->HardwareSegSs, Special->Ldtr, Special->Idtr.Limit);
142 
143  i386PrintFrames(TrapFrame); // Display frames
144  InstructionPointer = (PUCHAR)TrapFrame->Eip;
145 #else
146  PrintText("RAX: %.8lx R8: %.8lx R12: %.8lx RSI: %.8lx\n",
147  TrapFrame->Rax, TrapFrame->R8, 0, TrapFrame->Rsi);
148  PrintText("RBX: %.8lx R9: %.8lx R13: %.8lx RDI: %.8lx\n",
149  TrapFrame->Rbx, TrapFrame->R9, 0, TrapFrame->Rdi);
150  PrintText("RCX: %.8lx R10: %.8lx R14: %.8lx RBP: %.8lx\n",
151  TrapFrame->Rcx, TrapFrame->R10, 0, TrapFrame->Rbp);
152  PrintText("RDX: %.8lx R11: %.8lx R15: %.8lx RSP: %.8lx\n",
153  TrapFrame->Rdx, TrapFrame->R11, 0, TrapFrame->Rsp);
154 
155  PrintText("CS: %.4lx RIP: %.8lx\n",
156  TrapFrame->SegCs, TrapFrame->Rip);
157  PrintText("DS: %.4lx ERROR CODE: %.8lx\n",
158  TrapFrame->SegDs, TrapFrame->ErrorCode);
159  PrintText("ES: %.4lx EFLAGS: %.8lx\n",
160  TrapFrame->SegEs, TrapFrame->EFlags);
161  PrintText("FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
162  TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
163  PrintText("GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
164  TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
165  PrintText("SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
166  TrapFrame->SegSs, Special->Ldtr, Special->Idtr.Limit);
167  InstructionPointer = (PUCHAR)TrapFrame->Rip;
168 #endif
169  PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x \n",
170  InstructionPointer[0], InstructionPointer[1],
171  InstructionPointer[2], InstructionPointer[3],
172  InstructionPointer[4], InstructionPointer[5],
173  InstructionPointer[6], InstructionPointer[7]);
174 }
175 
176 VOID
178  ULONG BugCode,
179  PCHAR File,
180  ULONG Line,
181  PSTR Format,
182  ...)
183 {
184  CHAR Buffer[1024];
185  va_list argptr;
186 
189  i386_ScreenPosX = 0;
190  i386_ScreenPosY = 0;
191 
192  PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
193 
194  PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
195 
196  if (File)
197  {
198  PrintText("Location: %s:%ld\n\n", File, Line);
199  }
200 
201  va_start(argptr, Format);
202  _vsnprintf(Buffer, sizeof(Buffer), Format, argptr);
203  va_end(argptr);
204  Buffer[sizeof(Buffer) - 1] = 0;
205 
207 
208  _disable();
209  __halt();
210  for (;;);
211 }
212 
213 void
214 NTAPI
216  ULONG BugCode,
217  PCHAR File,
218  ULONG Line)
219 {
222  i386_ScreenPosX = 0;
223  i386_ScreenPosY = 0;
224 
225  PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
226 
227  PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
228 
229  if (File)
230  {
231  PrintText("Location: %s:%ld\n\n", File, Line);
232  }
233 
234  PrintText("Bug Information:\n %p\n %p\n %p\n %p\n %p\n\n",
236 
237  _disable();
238  __halt();
239  for (;;);
240 }
241 
242 void
243 NTAPI
245 {
246  FrLdrBugCheckEx(BugCode, 0, 0);
247 }
UINT64 R8
Definition: ketypes.h:321
char * BugCodeStrings[]
Definition: debug.c:508
signed char * PCHAR
Definition: retypes.h:7
VOID FrLdrBugCheckWithMessage(ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
Definition: i386bug.c:177
UINT64 Rbp
Definition: ketypes.h:372
UINT64 R10
Definition: ketypes.h:323
void NTAPI i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGISTERS Special)
Definition: i386bug.c:105
UINT64 Rbx
Definition: ketypes.h:369
UINT64 R9
Definition: ketypes.h:322
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1595
USHORT SegFs
Definition: ketypes.h:366
GLuint buffer
Definition: glext.h:5915
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
ULONG HardwareSegSs
Definition: ketypes.h:269
ULONG Esi
Definition: ketypes.h:261
PVOID Base
Definition: ketypes.h:486
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
ULONG Edi
Definition: ketypes.h:260
USHORT Limit
Definition: ketypes.h:485
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define STACKADDR
Definition: x86common.h:16
UINT64 Dr2
Definition: ketypes.h:344
ULONG Eax
Definition: ketypes.h:256
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define va_end(ap)
Definition: acmsvcex.h:90
UINT64 Rsi
Definition: ketypes.h:371
USHORT SegGs
Definition: ketypes.h:367
UINT64 Rax
Definition: ketypes.h:318
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:102
USHORT SegEs
Definition: ketypes.h:365
struct _FRAME * Next
Definition: i386bug.c:8
USHORT SegCs
Definition: ketypes.h:380
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
KDESCRIPTOR Gdtr
Definition: ketypes.h:506
static const char * i386ExceptionDescriptionText[]
Definition: i386bug.c:12
void NTAPI FrLdrBugCheck(ULONG BugCode)
Definition: i386bug.c:244
ULONG HardwareEsp
Definition: ketypes.h:268
void NTAPI FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:215
UINT64 Dr6
Definition: ketypes.h:346
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:84
UINT64 Dr3
Definition: ketypes.h:345
struct _FRAME FRAME
Definition: ncftp.h:79
#define MachVideoClearScreen(Attr)
Definition: machine.h:90
UINT64 Rdx
Definition: ketypes.h:320
UINT64 Dr1
Definition: ketypes.h:343
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:100
USHORT SegDs
Definition: ketypes.h:364
ULONG Ecx
Definition: ketypes.h:255
ULONG Eip
Definition: ketypes.h:265
int chr(char *serport)
Definition: gdblib.c:152
UINT64 Dr0
Definition: ketypes.h:342
UINT64 R11
Definition: ketypes.h:324
USHORT SegSs
Definition: ketypes.h:387
ULONG Ebx
Definition: ketypes.h:262
signed char * PSTR
Definition: retypes.h:7
UINT64 Rsp
Definition: ketypes.h:386
#define SCREEN_ATTR
Definition: i386bug.c:35
#define va_start(ap, A)
Definition: acmsvcex.h:91
static void i386PrintText(char *pszText)
Definition: i386bug.c:50
UINT64 Rdi
Definition: ketypes.h:370
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define _vsnprintf
Definition: xmlstorage.h:202
UINT64 ErrorCode
Definition: ketypes.h:375
UINT64 Rip
Definition: ketypes.h:379
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:516
Definition: File.h:15
UINT64 Dr7
Definition: ketypes.h:347
static void PrintText(const char *format,...)
Definition: i386bug.c:71
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
UINT64 Rcx
Definition: ketypes.h:319
ULONG i386_ScreenPosY
Definition: i386bug.c:47
void * Address
Definition: i386bug.c:9
ULONG i386_ScreenPosX
Definition: i386bug.c:46
ULONG ErrCode
Definition: ketypes.h:264
ULONG EFlags
Definition: ketypes.h:384
#define VERSION
Definition: rdesktop.h:45
UINT64 TrapFrame
Definition: ketypes.h:368
ULONG Edx
Definition: ketypes.h:254
ULONG Ebp
Definition: ketypes.h:263
Definition: i386bug.c:6
KDESCRIPTOR Idtr
Definition: ketypes.h:507