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: ");
177 DbgPrint("UNKNOWN: ");
185 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
191 // Mask out unwanted debug messages
192 if (!(Mask
& DebugPrintMask
))
197 // Print the header if we have started a new line
198 if (DebugStartOfLine
)
200 DbgPrint("(%s:%d) ", g_file
, g_line
);
201 DebugPrintHeader(Mask
);
202 DebugStartOfLine
= FALSE
;
205 va_start(ap
, format
);
206 vsprintf(Buffer
, format
, ap
);
211 DebugPrintChar(*ptr
++);
215 VOID
DebugDumpBuffer(ULONG Mask
, PVOID Buffer
, ULONG Length
)
217 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
221 // Mask out unwanted debug messages
222 if (!(Mask
& DebugPrintMask
))
227 DebugStartOfLine
= FALSE
; // We don't want line headers
228 DbgPrintMask(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
230 for (Idx
=0; Idx
<Length
; )
232 DebugStartOfLine
= FALSE
; // We don't want line headers
236 DbgPrintMask(Mask
, "000%x:\t", Idx
);
238 else if (Idx
< 0x0100)
240 DbgPrintMask(Mask
, "00%x:\t", Idx
);
242 else if (Idx
< 0x1000)
244 DbgPrintMask(Mask
, "0%x:\t", Idx
);
248 DbgPrintMask(Mask
, "%x:\t", Idx
);
251 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
253 if (BufPtr
[Idx
] < 0x10)
255 DbgPrintMask(Mask
, "0");
257 DbgPrintMask(Mask
, "%x", BufPtr
[Idx
]);
261 DbgPrintMask(Mask
, "-");
265 DbgPrintMask(Mask
, " ");
270 DbgPrintMask(Mask
, " ");
272 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
274 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
276 DbgPrintMask(Mask
, "%c", BufPtr
[Idx
]);
280 DbgPrintMask(Mask
, ".");
284 DbgPrintMask(Mask
, "\n");
290 VOID
DbgPrintMask(ULONG Mask
, char *format
, ...)
294 ULONG
DbgPrint(PCCH Format
, ...)
302 MsgBoxPrint(const char *Format
, ...)
308 va_start(ap
, Format
);
310 /* Construct a string */
311 Length
= _vsnprintf(Buffer
, 512, Format
, ap
);
313 /* Check if we went past the buffer */
314 if (Length
== MAXULONG
)
316 /* Terminate it if we went over-board */
317 Buffer
[sizeof(Buffer
) - 1] = '\n';
320 Length
= sizeof(Buffer
);
323 /* Show it as a message box */
324 UiMessageBox(Buffer
);
326 /* Cleanup and exit */