[POWERCFG] Add hints on missing property pages and remove an obsolete declaration
[reactos.git] / boot / freeldr / freeldr / arch / i386 / i386bug.c
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 /* Used to store the current X and Y position on the screen */
38 static ULONG i386_ScreenPosX = 0;
39 static ULONG i386_ScreenPosY = 0;
40
41 #if 0
42 static void
43 i386PrintChar(CHAR chr, ULONG x, ULONG y)
44 {
45 MachVideoPutChar(chr, SCREEN_ATTR, x, y);
46 }
47 #endif
48
49 static void
50 i386PrintText(CHAR *pszText)
51 {
52 ULONG Width, Unused;
53
54 MachVideoGetDisplaySize(&Width, &Unused, &Unused);
55
56 for (; *pszText != ANSI_NULL; ++pszText)
57 {
58 if (*pszText == '\n')
59 {
60 i386_ScreenPosX = 0;
61 ++i386_ScreenPosY;
62 continue;
63 }
64
65 MachVideoPutChar(*pszText, SCREEN_ATTR, i386_ScreenPosX, i386_ScreenPosY);
66 if (++i386_ScreenPosX >= Width)
67 {
68 i386_ScreenPosX = 0;
69 ++i386_ScreenPosY;
70 }
71 // FIXME: Implement vertical screen scrolling if we are at the end of the screen.
72 }
73 }
74
75 static void
76 PrintTextV(const CHAR *Format, va_list args)
77 {
78 CHAR Buffer[512];
79
80 _vsnprintf(Buffer, sizeof(Buffer), Format, args);
81 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
82
83 i386PrintText(Buffer);
84 }
85
86 static void
87 PrintText(const CHAR *Format, ...)
88 {
89 va_list argptr;
90
91 va_start(argptr, Format);
92 PrintTextV(Format, argptr);
93 va_end(argptr);
94 }
95
96 static void
97 i386PrintFrames(PKTRAP_FRAME TrapFrame)
98 {
99 FRAME *Frame;
100
101 PrintText("Frames:\n");
102 #ifdef _M_IX86
103 for (Frame = (FRAME*)TrapFrame->Ebp;
104 Frame != 0 && (ULONG_PTR)Frame < STACKADDR;
105 Frame = Frame->Next)
106 #else
107 for (Frame = (FRAME*)TrapFrame->TrapFrame;
108 Frame != 0 && (ULONG_PTR)Frame < STACKADDR;
109 Frame = Frame->Next)
110 #endif
111 {
112 PrintText("%p ", Frame->Address);
113 }
114 }
115
116 void
117 NTAPI
118 i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGISTERS Special)
119 {
120 PUCHAR InstructionPointer;
121
122 MachVideoHideShowTextCursor(FALSE);
123 MachVideoClearScreen(SCREEN_ATTR);
124 i386_ScreenPosX = 0;
125 i386_ScreenPosY = 0;
126
127 PrintText("An error occured in " VERSION "\n"
128 "Report this error on the ReactOS Bug Tracker: https://jira.reactos.org\n\n"
129 "0x%02lx: %s\n", TrapIndex, i386ExceptionDescriptionText[TrapIndex]);
130 #ifdef _M_IX86
131 PrintText("EAX: %.8lx ESP: %.8lx CR0: %.8lx DR0: %.8lx\n",
132 TrapFrame->Eax, TrapFrame->HardwareEsp, Special->Cr0, TrapFrame->Dr0);
133 PrintText("EBX: %.8lx EBP: %.8lx CR1: ???????? DR1: %.8lx\n",
134 TrapFrame->Ebx, TrapFrame->Ebp, TrapFrame->Dr1);
135 PrintText("ECX: %.8lx ESI: %.8lx CR2: %.8lx DR2: %.8lx\n",
136 TrapFrame->Ecx, TrapFrame->Esi, Special->Cr2, TrapFrame->Dr2);
137 PrintText("EDX: %.8lx EDI: %.8lx CR3: %.8lx DR3: %.8lx\n",
138 TrapFrame->Edx, TrapFrame->Edi, Special->Cr3, TrapFrame->Dr3);
139 PrintText(" DR6: %.8lx\n",
140 TrapFrame->Dr6);
141 PrintText(" DR7: %.8lx\n\n",
142 TrapFrame->Dr7);
143 PrintText("CS: %.4lx EIP: %.8lx\n",
144 TrapFrame->SegCs, TrapFrame->Eip);
145 PrintText("DS: %.4lx ERROR CODE: %.8lx\n",
146 TrapFrame->SegDs, TrapFrame->ErrCode);
147 PrintText("ES: %.4lx EFLAGS: %.8lx\n",
148 TrapFrame->SegEs, TrapFrame->EFlags);
149 PrintText("FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
150 TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
151 PrintText("GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
152 TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
153 PrintText("SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
154 TrapFrame->HardwareSegSs, Special->Ldtr, Special->Idtr.Limit);
155
156 i386PrintFrames(TrapFrame); // Display frames
157 InstructionPointer = (PUCHAR)TrapFrame->Eip;
158 #else
159 PrintText("RAX: %.8lx R8: %.8lx R12: %.8lx RSI: %.8lx\n",
160 TrapFrame->Rax, TrapFrame->R8, 0, TrapFrame->Rsi);
161 PrintText("RBX: %.8lx R9: %.8lx R13: %.8lx RDI: %.8lx\n",
162 TrapFrame->Rbx, TrapFrame->R9, 0, TrapFrame->Rdi);
163 PrintText("RCX: %.8lx R10: %.8lx R14: %.8lx RBP: %.8lx\n",
164 TrapFrame->Rcx, TrapFrame->R10, 0, TrapFrame->Rbp);
165 PrintText("RDX: %.8lx R11: %.8lx R15: %.8lx RSP: %.8lx\n",
166 TrapFrame->Rdx, TrapFrame->R11, 0, TrapFrame->Rsp);
167
168 PrintText("CS: %.4lx RIP: %.8lx\n",
169 TrapFrame->SegCs, TrapFrame->Rip);
170 PrintText("DS: %.4lx ERROR CODE: %.8lx\n",
171 TrapFrame->SegDs, TrapFrame->ErrorCode);
172 PrintText("ES: %.4lx EFLAGS: %.8lx\n",
173 TrapFrame->SegEs, TrapFrame->EFlags);
174 PrintText("FS: %.4lx GDTR Base: %.8lx Limit: %.4x\n",
175 TrapFrame->SegFs, Special->Gdtr.Base, Special->Gdtr.Limit);
176 PrintText("GS: %.4lx IDTR Base: %.8lx Limit: %.4x\n",
177 TrapFrame->SegGs, Special->Idtr.Base, Special->Idtr.Limit);
178 PrintText("SS: %.4lx LDTR: %.4lx TR: %.4lx\n\n",
179 TrapFrame->SegSs, Special->Ldtr, Special->Idtr.Limit);
180 InstructionPointer = (PUCHAR)TrapFrame->Rip;
181 #endif
182 PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x \n",
183 InstructionPointer[0], InstructionPointer[1],
184 InstructionPointer[2], InstructionPointer[3],
185 InstructionPointer[4], InstructionPointer[5],
186 InstructionPointer[6], InstructionPointer[7]);
187 }
188
189 VOID
190 FrLdrBugCheckWithMessage(
191 ULONG BugCode,
192 PCHAR File,
193 ULONG Line,
194 PSTR Format,
195 ...)
196 {
197 va_list argptr;
198
199 MachVideoHideShowTextCursor(FALSE);
200 MachVideoClearScreen(SCREEN_ATTR);
201 i386_ScreenPosX = 0;
202 i386_ScreenPosY = 0;
203
204 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
205
206 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
207
208 if (File)
209 {
210 PrintText("Location: %s:%ld\n\n", File, Line);
211 }
212
213 va_start(argptr, Format);
214 PrintTextV(Format, argptr);
215 va_end(argptr);
216
217 _disable();
218 __halt();
219 for (;;);
220 }
221
222 void
223 NTAPI
224 FrLdrBugCheckEx(
225 ULONG BugCode,
226 PCHAR File,
227 ULONG Line)
228 {
229 MachVideoHideShowTextCursor(FALSE);
230 MachVideoClearScreen(SCREEN_ATTR);
231 i386_ScreenPosX = 0;
232 i386_ScreenPosY = 0;
233
234 PrintText("A problem has been detected and FreeLoader boot has been aborted.\n\n");
235
236 PrintText("%ld: %s\n\n", BugCode, BugCodeStrings[BugCode]);
237
238 if (File)
239 {
240 PrintText("Location: %s:%ld\n\n", File, Line);
241 }
242
243 PrintText("Bug Information:\n %p\n %p\n %p\n %p\n %p\n\n",
244 BugCheckInfo[0], BugCheckInfo[1], BugCheckInfo[2], BugCheckInfo[3], BugCheckInfo[4]);
245
246 _disable();
247 __halt();
248 for (;;);
249 }
250
251 void
252 NTAPI
253 FrLdrBugCheck(ULONG BugCode)
254 {
255 FrLdrBugCheckEx(BugCode, 0, 0);
256 }