ReactOS 0.4.16-dev-1019-g2c2cdfd
i386bug.c File Reference
#include <freeldr.h>
#include <reactos/buildno.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)
 
DECLSPEC_NORETURN VOID FrLdrBugCheckWithMessage (ULONG BugCode, PCHAR File, ULONG Line, PSTR Format,...)
 
static DECLSPEC_NORETURN void FrLdrBugCheckEx (ULONG BugCode, PCHAR File, ULONG Line)
 
DECLSPEC_NORETURN 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 36 of file i386bug.c.

Typedef Documentation

◆ FRAME

typedef struct _FRAME FRAME

Function Documentation

◆ FrLdrBugCheck()

DECLSPEC_NORETURN void NTAPI FrLdrBugCheck ( ULONG  BugCode)

Definition at line 267 of file i386bug.c.

268{
269 FrLdrBugCheckEx(BugCode, 0, 0);
270}
static DECLSPEC_NORETURN void FrLdrBugCheckEx(ULONG BugCode, PCHAR File, ULONG Line)
Definition: i386bug.c:237

◆ FrLdrBugCheckEx()

static DECLSPEC_NORETURN void FrLdrBugCheckEx ( ULONG  BugCode,
PCHAR  File,
ULONG  Line 
)
static

Definition at line 237 of file i386bug.c.

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}
ULONG_PTR BugCheckInfo[5]
Definition: debug.c:561
char * BugCodeStrings[]
Definition: debug.c:550
#define MachVideoClearScreen(Attr)
Definition: machine.h:92
#define MachVideoHideShowTextCursor(Show)
Definition: machine.h:102
Definition: File.h:16
#define FALSE
Definition: types.h:117
#define SCREEN_ATTR
Definition: i386bug.c:36
static ULONG i386_ScreenPosY
Definition: i386bug.c:40
static ULONG i386_ScreenPosX
Definition: i386bug.c:39
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:1728
Definition: ncftp.h:79

Referenced by FrLdrBugCheck().

◆ FrLdrBugCheckWithMessage()

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

Definition at line 202 of file i386bug.c.

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}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static void PrintTextV(const CHAR *Format, va_list args)
Definition: i386bug.c:69

◆ i386PrintExceptionText()

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

Definition at line 110 of file i386bug.c.

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}
static void i386PrintFrames(PKTRAP_FRAME TrapFrame)
Definition: i386bug.c:90
static const CHAR * i386ExceptionDescriptionText[]
Definition: i386bug.c:13
unsigned short USHORT
Definition: pedump.c:61
ULONG Base
Definition: ketypes.h:450
USHORT Limit
Definition: ketypes.h:449
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 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
unsigned char * PUCHAR
Definition: typedefs.h:53

◆ i386PrintFrames()

static void i386PrintFrames ( PKTRAP_FRAME  TrapFrame)
static

Definition at line 90 of file i386bug.c.

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}
#define NULL
Definition: types.h:112
Definition: i386bug.c:8
PVOID Address
Definition: i386bug.c:10
struct _FRAME * Next
Definition: i386bug.c:9
UINT64 TrapFrame
Definition: ketypes.h:462
else
Definition: tritemp.h:161
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STACKADDR
Definition: x86common.h:16

Referenced by i386PrintExceptionText().

◆ i386PrintText()

static void i386PrintText ( CHAR pszText)
static

Definition at line 43 of file i386bug.c.

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}
#define MachVideoGetDisplaySize(W, H, D)
Definition: machine.h:96
#define MachVideoPutChar(Ch, Attr, X, Y)
Definition: machine.h:104
#define Unused(x)
Definition: atlwin.h:28
#define ANSI_NULL
uint32_t ULONG
Definition: typedefs.h:59
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89

Referenced by PrintTextV().

◆ PrintText()

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

Definition at line 80 of file i386bug.c.

81{
82 va_list argptr;
83
84 va_start(argptr, Format);
85 PrintTextV(Format, argptr);
86 va_end(argptr);
87}

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

◆ PrintTextV()

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

Definition at line 69 of file i386bug.c.

70{
71 CHAR Buffer[512];
72
74 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
75
77}
Definition: bufpool.h:45
static void i386PrintText(CHAR *pszText)
Definition: i386bug.c:43
Definition: match.c:390
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175

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:
=
{
"DIVIDE BY ZERO",
"DEBUG EXCEPTION",
"NON-MASKABLE INTERRUPT EXCEPTION",
"BREAKPOINT (INT 3)",
"OVERFLOW",
"BOUND EXCEPTION",
"INVALID OPCODE",
"FPU NOT AVAILABLE",
"DOUBLE FAULT",
"COPROCESSOR SEGMENT OVERRUN",
"INVALID TSS",
"SEGMENT NOT PRESENT",
"STACK EXCEPTION",
"GENERAL PROTECTION FAULT",
"PAGE FAULT",
"Reserved",
"COPROCESSOR ERROR",
"ALIGNMENT CHECK",
"MACHINE CHECK"
}

Definition at line 13 of file i386bug.c.

Referenced by i386PrintExceptionText().