ReactOS  0.4.15-dev-4570-g4f8bbd1
i386bug.c File Reference
#include <freeldr.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 35 of file i386bug.c.

Typedef Documentation

◆ FRAME

typedef struct _FRAME FRAME

Function Documentation

◆ FrLdrBugCheck()

void NTAPI FrLdrBugCheck ( ULONG  BugCode)

Definition at line 260 of file i386bug.c.

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

◆ FrLdrBugCheckEx()

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

Definition at line 231 of file i386bug.c.

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 }
char * BugCodeStrings[]
Definition: debug.c:515
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1715
#define FALSE
Definition: types.h:117
Definition: ncftp.h:79
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:104
#define SCREEN_ATTR
Definition: i386bug.c:35
void __cdecl _disable(void)
Definition: intrin_arm.h:365
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:523
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:79
Definition: File.h:15
static ULONG i386_ScreenPosY
Definition: i386bug.c:39
static ULONG i386_ScreenPosX
Definition: i386bug.c:38

Referenced by FrLdrBugCheck().

◆ FrLdrBugCheckWithMessage()

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

Definition at line 197 of file i386bug.c.

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 }
char * BugCodeStrings[]
Definition: debug.c:515
__INTRIN_INLINE void __halt(void)
Definition: intrin_x86.h:1715
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:68
char * va_list
Definition: acmsvcex.h:78
va_start(ap, x)
Definition: ncftp.h:79
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:104
#define SCREEN_ATTR
Definition: i386bug.c:35
void __cdecl _disable(void)
Definition: intrin_arm.h:365
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:79
Definition: File.h:15
static ULONG i386_ScreenPosY
Definition: i386bug.c:39
static ULONG i386_ScreenPosX
Definition: i386bug.c:38

◆ i386PrintExceptionText()

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

Definition at line 109 of file i386bug.c.

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 }
UINT64 R8
Definition: ketypes.h:326
UINT64 Rbp
Definition: ketypes.h:377
UINT64 R10
Definition: ketypes.h:328
UINT64 Rbx
Definition: ketypes.h:374
UINT64 R9
Definition: ketypes.h:327
unsigned char * PUCHAR
Definition: retypes.h:3
USHORT SegFs
Definition: ketypes.h:371
ULONG HardwareSegSs
Definition: ketypes.h:272
ULONG Esi
Definition: ketypes.h:264
PVOID Base
Definition: ketypes.h:491
ULONG Edi
Definition: ketypes.h:263
USHORT Limit
Definition: ketypes.h:490
UINT64 Dr2
Definition: ketypes.h:349
ULONG Eax
Definition: ketypes.h:259
UINT64 Rsi
Definition: ketypes.h:376
USHORT SegGs
Definition: ketypes.h:372
#define FALSE
Definition: types.h:117
UINT64 Rax
Definition: ketypes.h:323
USHORT SegEs
Definition: ketypes.h:370
USHORT SegCs
Definition: ketypes.h:385
KDESCRIPTOR Gdtr
Definition: ketypes.h:511
ULONG HardwareEsp
Definition: ketypes.h:271
UINT64 Dr6
Definition: ketypes.h:351
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:89
UINT64 Dr3
Definition: ketypes.h:350
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
UINT64 Rdx
Definition: ketypes.h:325
UINT64 Dr1
Definition: ketypes.h:348
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:104
USHORT SegDs
Definition: ketypes.h:369
ULONG Ecx
Definition: ketypes.h:258
ULONG Eip
Definition: ketypes.h:268
UINT64 Dr0
Definition: ketypes.h:347
UINT64 R11
Definition: ketypes.h:329
USHORT SegSs
Definition: ketypes.h:392
ULONG Ebx
Definition: ketypes.h:265
unsigned short USHORT
Definition: pedump.c:61
UINT64 Rsp
Definition: ketypes.h:391
#define SCREEN_ATTR
Definition: i386bug.c:35
UINT64 Rdi
Definition: ketypes.h:375
UINT64 ErrorCode
Definition: ketypes.h:380
UINT64 Rip
Definition: ketypes.h:384
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:79
UINT64 Dr7
Definition: ketypes.h:352
static const CHAR * i386ExceptionDescriptionText[]
Definition: i386bug.c:12
UINT64 Rcx
Definition: ketypes.h:324
static ULONG i386_ScreenPosY
Definition: i386bug.c:39
static ULONG i386_ScreenPosX
Definition: i386bug.c:38
ULONG ErrCode
Definition: ketypes.h:267
ULONG EFlags
Definition: ketypes.h:389
#define VERSION
Definition: rdesktop.h:45
ULONG Edx
Definition: ketypes.h:257
ULONG Ebp
Definition: ketypes.h:266
KDESCRIPTOR Idtr
Definition: ketypes.h:512

◆ i386PrintFrames()

static void i386PrintFrames ( PKTRAP_FRAME  TrapFrame)
static

Definition at line 89 of file i386bug.c.

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 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
else
Definition: tritemp.h:161
#define STACKADDR
Definition: x86common.h:16
struct _FRAME * Next
Definition: i386bug.c:8
PVOID Address
Definition: i386bug.c:9
#define NULL
Definition: types.h:112
static void PrintText(const CHAR *Format,...)
Definition: i386bug.c:79
UINT64 TrapFrame
Definition: ketypes.h:373
ULONG Ebp
Definition: ketypes.h:266
Definition: i386bug.c:6

Referenced by i386PrintExceptionText().

◆ i386PrintText()

static void i386PrintText ( CHAR pszText)
static

Definition at line 42 of file i386bug.c.

43 {
45 
47 
48  for (; *pszText != ANSI_NULL; ++pszText)
49  {
50  if (*pszText == '\n')
51  {
52  i386_ScreenPosX = 0;
54  continue;
55  }
56 
58  if (++i386_ScreenPosX >= Width)
59  {
60  i386_ScreenPosX = 0;
62  }
63  // FIXME: Implement vertical screen scrolling if we are at the end of the screen.
64  }
65 }
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1166
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:124
#define MachVideoGetDisplaySize(W, H, D)
Definition: machine.h:96
#define ANSI_NULL
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:106
#define SCREEN_ATTR
Definition: i386bug.c:35
unsigned int ULONG
Definition: retypes.h:1
static ULONG i386_ScreenPosY
Definition: i386bug.c:39
static ULONG i386_ScreenPosX
Definition: i386bug.c:38

Referenced by PrintTextV().

◆ PrintText()

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

Definition at line 79 of file i386bug.c.

80 {
81  va_list argptr;
82 
83  va_start(argptr, Format);
84  PrintTextV(Format, argptr);
85  va_end(argptr);
86 }
#define va_end(ap)
Definition: acmsvcex.h:90
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:68
char * va_list
Definition: acmsvcex.h:78
va_start(ap, x)

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

◆ PrintTextV()

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

Definition at line 68 of file i386bug.c.

69 {
70  CHAR Buffer[512];
71 
72  _vsnprintf(Buffer, sizeof(Buffer), Format, args);
73  Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
74 
76 }
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
char CHAR
Definition: xmlstorage.h:175
Definition: match.c:390
#define ANSI_NULL
Definition: bufpool.h:45
#define _vsnprintf
Definition: xmlstorage.h:202
static void i386PrintText(CHAR *pszText)
Definition: i386bug.c:42

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 12 of file i386bug.c.

Referenced by i386PrintExceptionText().