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
;
71 if (DebugPort
& RS232
)
73 Rs232PortInitialize(ComPort
, BaudRate
);
77 VOID
DebugPrintChar(UCHAR Character
)
79 if (Character
== '\n')
81 DebugStartOfLine
= TRUE
;
84 if (DebugPort
& RS232
)
86 if (Character
== '\n')
88 Rs232PortPutByte('\r');
90 Rs232PortPutByte(Character
);
92 if (DebugPort
& BOCHS
)
94 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
96 if (DebugPort
& SCREEN
)
98 MachConsPutChar(Character
);
103 DbgPrint(const char *Format
, ...)
110 va_start(ap
, Format
);
111 Length
= _vsnprintf(Buffer
, sizeof(Buffer
), Format
, ap
);
114 /* Check if we went past the buffer */
117 /* Terminate it if we went over-board */
118 Buffer
[sizeof(Buffer
) - 1] = '\n';
121 Length
= sizeof(Buffer
);
124 for (i
= 0; i
< Length
; i
++)
126 DebugPrintChar(Buffer
[i
]);
132 VOID
DebugPrintHeader(ULONG Mask
)
141 DbgPrint("WARNING: ");
144 DbgPrint("MEMORY: ");
146 case DPRINT_FILESYSTEM
:
147 DbgPrint("FILESYS: ");
150 DbgPrint("INIFILE: ");
161 case DPRINT_REGISTRY
:
162 DbgPrint("REGISTRY: ");
165 DbgPrint("REACTOS: ");
171 DbgPrint("WINLDR: ");
173 case DPRINT_HWDETECT
:
174 DbgPrint("HWDETECT: ");
176 case DPRINT_PELOADER
:
177 DbgPrint("PELOADER: ");
179 case DPRINT_SCSIPORT
:
180 DbgPrint("SCSIPORT: ");
183 DbgPrint("UNKNOWN: ");
191 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
197 // Mask out unwanted debug messages
198 if (!(Mask
& DebugPrintMask
))
203 // Disable file/line for scsiport messages
204 if (Mask
& DPRINT_SCSIPORT
)
206 DebugStartOfLine
= FALSE
;
209 // Print the header if we have started a new line
210 if (DebugStartOfLine
)
212 DbgPrint("(%s:%d) ", g_file
, g_line
);
213 DebugPrintHeader(Mask
);
214 DebugStartOfLine
= FALSE
;
217 va_start(ap
, format
);
218 vsprintf(Buffer
, format
, ap
);
223 DebugPrintChar(*ptr
++);
227 VOID
DebugDumpBuffer(ULONG Mask
, PVOID Buffer
, ULONG Length
)
229 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
233 // Mask out unwanted debug messages
234 if (!(Mask
& DebugPrintMask
))
239 DebugStartOfLine
= FALSE
; // We don't want line headers
240 DbgPrintMask(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
242 for (Idx
=0; Idx
<Length
; )
244 DebugStartOfLine
= FALSE
; // We don't want line headers
248 DbgPrintMask(Mask
, "000%x:\t", Idx
);
250 else if (Idx
< 0x0100)
252 DbgPrintMask(Mask
, "00%x:\t", Idx
);
254 else if (Idx
< 0x1000)
256 DbgPrintMask(Mask
, "0%x:\t", Idx
);
260 DbgPrintMask(Mask
, "%x:\t", Idx
);
263 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
265 if (BufPtr
[Idx
] < 0x10)
267 DbgPrintMask(Mask
, "0");
269 DbgPrintMask(Mask
, "%x", BufPtr
[Idx
]);
273 DbgPrintMask(Mask
, "-");
277 DbgPrintMask(Mask
, " ");
282 DbgPrintMask(Mask
, " ");
284 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
286 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
288 DbgPrintMask(Mask
, "%c", BufPtr
[Idx
]);
292 DbgPrintMask(Mask
, ".");
296 DbgPrintMask(Mask
, "\n");
302 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
306 ULONG
DbgPrint(PCCH Format
, ...)
314 MsgBoxPrint(const char *Format
, ...)
320 va_start(ap
, Format
);
322 /* Construct a string */
323 Length
= _vsnprintf(Buffer
, 512, Format
, ap
);
325 /* Check if we went past the buffer */
326 if (Length
== MAXULONG
)
328 /* Terminate it if we went over-board */
329 Buffer
[sizeof(Buffer
) - 1] = '\n';
332 Length
= sizeof(Buffer
);
335 /* Show it as a message box */
336 UiMessageBox(Buffer
);
338 /* Cleanup and exit */
347 IN ULONG BugCheckCode
,
348 IN ULONG_PTR BugCheckParameter1
,
349 IN ULONG_PTR BugCheckParameter2
,
350 IN ULONG_PTR BugCheckParameter3
,
351 IN ULONG_PTR BugCheckParameter4
)
354 sprintf(Buffer
, "*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)",
355 BugCheckCode
, BugCheckParameter1
, BugCheckParameter2
,
356 BugCheckParameter3
, BugCheckParameter4
);
357 UiMessageBoxCritical(Buffer
);