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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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
| DPRINT_MEMORY
|
42 DPRINT_REACTOS
| DPRINT_WINDOWS
| DPRINT_HWDETECT
;
43 #else //#elif defined (DEBUG_NONE)
44 ULONG DebugPrintMask
= 0;
56 #define BOCHS_OUTPUT_PORT 0xe9
58 ULONG DebugPort
= RS232
;
59 //ULONG DebugPort = SCREEN;
60 //ULONG DebugPort = BOCHS;
61 //ULONG DebugPort = SCREEN|BOCHS;
63 //ULONG BaudRate = 19200;
64 ULONG BaudRate
= 115200;
66 BOOLEAN DebugStartOfLine
= TRUE
;
70 if (DebugPort
& RS232
)
72 Rs232PortInitialize(ComPort
, BaudRate
);
76 VOID
DebugPrintChar(UCHAR Character
)
78 if (Character
== '\n')
80 DebugStartOfLine
= TRUE
;
83 if (DebugPort
& RS232
)
85 if (Character
== '\n')
87 Rs232PortPutByte('\r');
89 Rs232PortPutByte(Character
);
91 if (DebugPort
& BOCHS
)
93 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
95 if (DebugPort
& SCREEN
)
97 MachConsPutChar(Character
);
101 VOID
DebugPrintHeader(ULONG Mask
)
130 case DPRINT_FILESYSTEM
:
175 case DPRINT_REGISTRY
:
217 case DPRINT_HWDETECT
:
243 VOID
DebugPrint(ULONG Mask
, char *format
, ...)
249 // Mask out unwanted debug messages
250 if (!(Mask
& DebugPrintMask
))
255 // Print the header if we have started a new line
256 if (DebugStartOfLine
)
258 DebugPrintHeader(Mask
);
259 DebugStartOfLine
= FALSE
;
262 va_start(ap
, format
);
263 vsprintf(Buffer
, format
, ap
);
267 DebugPrintChar(*ptr
++);
271 VOID
DebugPrint1(char *format
, ...)
277 va_start(ap
, format
);
278 vsprintf(Buffer
, format
, ap
);
282 DebugPrintChar(*ptr
++);
286 VOID
DebugDumpBuffer(ULONG Mask
, PVOID Buffer
, ULONG Length
)
288 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
292 // Mask out unwanted debug messages
293 if (!(Mask
& DebugPrintMask
))
298 DebugStartOfLine
= FALSE
; // We don't want line headers
299 DebugPrint(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
301 for (Idx
=0; Idx
<Length
; )
303 DebugStartOfLine
= FALSE
; // We don't want line headers
307 DebugPrint(Mask
, "000%x:\t", Idx
);
309 else if (Idx
< 0x0100)
311 DebugPrint(Mask
, "00%x:\t", Idx
);
313 else if (Idx
< 0x1000)
315 DebugPrint(Mask
, "0%x:\t", Idx
);
319 DebugPrint(Mask
, "%x:\t", Idx
);
322 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
324 if (BufPtr
[Idx
] < 0x10)
326 DebugPrint(Mask
, "0");
328 DebugPrint(Mask
, "%x", BufPtr
[Idx
]);
332 DebugPrint(Mask
, "-");
336 DebugPrint(Mask
, " ");
341 DebugPrint(Mask
, " ");
343 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
345 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
347 DebugPrint(Mask
, "%c", BufPtr
[Idx
]);
351 DebugPrint(Mask
, ".");
355 DebugPrint(Mask
, "\n");
361 VOID
DebugPrint(ULONG Mask
, char *format
, ...)
365 #endif // defined DBG