3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #if DBG && !defined(_M_ARM)
27 //#define DEBUG_INIFILE
28 //#define DEBUG_REACTOS
29 //#define DEBUG_CUSTOM
32 #if defined (DEBUG_ALL)
33 ULONG DebugPrintMask
= DPRINT_WARNING
| DPRINT_MEMORY
| DPRINT_FILESYSTEM
|
34 DPRINT_UI
| DPRINT_DISK
| DPRINT_CACHE
| DPRINT_REACTOS
|
35 DPRINT_LINUX
| DPRINT_HWDETECT
;
36 #elif defined (DEBUG_INIFILE)
37 ULONG DebugPrintMask
= DPRINT_INIFILE
;
38 #elif defined (DEBUG_REACTOS)
39 ULONG DebugPrintMask
= DPRINT_REACTOS
| DPRINT_REGISTRY
;
40 #elif defined (DEBUG_CUSTOM)
41 ULONG DebugPrintMask
= DPRINT_WARNING
|
42 DPRINT_UI
| DPRINT_CACHE
| DPRINT_REACTOS
|
44 #else //#elif defined (DEBUG_NONE)
45 ULONG DebugPrintMask
= 0;
57 #define BOCHS_OUTPUT_PORT 0xe9
59 ULONG DebugPort
= RS232
;
60 //ULONG DebugPort = SCREEN;
61 //ULONG DebugPort = BOCHS;
62 //ULONG DebugPort = SCREEN|BOCHS;
64 //ULONG BaudRate = 19200;
65 ULONG BaudRate
= 115200;
67 BOOLEAN DebugStartOfLine
= TRUE
;
69 // We need to emulate these, because the original ones don't work in freeldr
70 int __cdecl
wctomb(char *mbchar
, wchar_t wchar
)
76 int __cdecl
mbtowc (wchar_t *wchar
, const char *mbchar
, size_t count
)
84 if (DebugPort
& RS232
)
86 Rs232PortInitialize(ComPort
, BaudRate
);
90 VOID
DebugPrintChar(UCHAR Character
)
92 if (Character
== '\n')
94 DebugStartOfLine
= TRUE
;
97 if (DebugPort
& RS232
)
99 if (Character
== '\n')
101 Rs232PortPutByte('\r');
103 Rs232PortPutByte(Character
);
105 if (DebugPort
& BOCHS
)
107 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
109 if (DebugPort
& SCREEN
)
111 MachConsPutChar(Character
);
116 DbgPrint(const char *Format
, ...)
123 va_start(ap
, Format
);
124 Length
= _vsnprintf(Buffer
, sizeof(Buffer
), Format
, ap
);
127 /* Check if we went past the buffer */
130 /* Terminate it if we went over-board */
131 Buffer
[sizeof(Buffer
) - 1] = '\n';
134 Length
= sizeof(Buffer
);
137 for (i
= 0; i
< Length
; i
++)
139 DebugPrintChar(Buffer
[i
]);
145 VOID
DebugPrintHeader(ULONG Mask
)
154 DbgPrint("WARNING: ");
157 DbgPrint("MEMORY: ");
159 case DPRINT_FILESYSTEM
:
160 DbgPrint("FILESYS: ");
163 DbgPrint("INIFILE: ");
174 case DPRINT_REGISTRY
:
175 DbgPrint("REGISTRY: ");
178 DbgPrint("REACTOS: ");
184 DbgPrint("WINLDR: ");
186 case DPRINT_HWDETECT
:
187 DbgPrint("HWDETECT: ");
189 case DPRINT_PELOADER
:
190 DbgPrint("PELOADER: ");
192 case DPRINT_SCSIPORT
:
193 DbgPrint("SCSIPORT: ");
196 DbgPrint("UNKNOWN: ");
204 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
210 // Mask out unwanted debug messages
211 if (!(Mask
& DebugPrintMask
))
216 // Disable file/line for scsiport messages
217 if (Mask
& DPRINT_SCSIPORT
)
219 DebugStartOfLine
= FALSE
;
222 // Print the header if we have started a new line
223 if (DebugStartOfLine
)
225 DbgPrint("(%s:%d) ", g_file
, g_line
);
226 DebugPrintHeader(Mask
);
227 DebugStartOfLine
= FALSE
;
230 va_start(ap
, format
);
231 vsprintf(Buffer
, format
, ap
);
236 DebugPrintChar(*ptr
++);
240 VOID
DebugDumpBuffer(ULONG Mask
, PVOID Buffer
, ULONG Length
)
242 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
246 // Mask out unwanted debug messages
247 if (!(Mask
& DebugPrintMask
))
252 DebugStartOfLine
= FALSE
; // We don't want line headers
253 DbgPrintMask(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
255 for (Idx
=0; Idx
<Length
; )
257 DebugStartOfLine
= FALSE
; // We don't want line headers
261 DbgPrintMask(Mask
, "000%x:\t", Idx
);
263 else if (Idx
< 0x0100)
265 DbgPrintMask(Mask
, "00%x:\t", Idx
);
267 else if (Idx
< 0x1000)
269 DbgPrintMask(Mask
, "0%x:\t", Idx
);
273 DbgPrintMask(Mask
, "%x:\t", Idx
);
276 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
278 if (BufPtr
[Idx
] < 0x10)
280 DbgPrintMask(Mask
, "0");
282 DbgPrintMask(Mask
, "%x", BufPtr
[Idx
]);
286 DbgPrintMask(Mask
, "-");
290 DbgPrintMask(Mask
, " ");
295 DbgPrintMask(Mask
, " ");
297 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
299 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
301 DbgPrintMask(Mask
, "%c", BufPtr
[Idx
]);
305 DbgPrintMask(Mask
, ".");
309 DbgPrintMask(Mask
, "\n");
315 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
319 ULONG
DbgPrint(PCCH Format
, ...)
327 MsgBoxPrint(const char *Format
, ...)
333 va_start(ap
, Format
);
335 /* Construct a string */
336 Length
= _vsnprintf(Buffer
, 512, Format
, ap
);
338 /* Check if we went past the buffer */
339 if (Length
== MAXULONG
)
341 /* Terminate it if we went over-board */
342 Buffer
[sizeof(Buffer
) - 1] = '\n';
345 Length
= sizeof(Buffer
);
348 /* Show it as a message box */
349 UiMessageBox(Buffer
);
351 /* Cleanup and exit */
361 IN ULONG BugCheckCode
,
362 IN ULONG_PTR BugCheckParameter1
,
363 IN ULONG_PTR BugCheckParameter2
,
364 IN ULONG_PTR BugCheckParameter3
,
365 IN ULONG_PTR BugCheckParameter4
)
368 sprintf(Buffer
, "*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)",
369 BugCheckCode
, BugCheckParameter1
, BugCheckParameter2
,
370 BugCheckParameter3
, BugCheckParameter4
);
371 UiMessageBoxCritical(Buffer
);