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.
30 //#define DEBUG_INIFILE
31 //#define DEBUG_REACTOS
32 //#define DEBUG_CUSTOM
35 #if defined (DEBUG_ALL)
36 ULONG DebugPrintMask
= DPRINT_WARNING
| DPRINT_MEMORY
| DPRINT_FILESYSTEM
|
37 DPRINT_UI
| DPRINT_DISK
| DPRINT_CACHE
| DPRINT_REACTOS
|
38 DPRINT_LINUX
| DPRINT_HWDETECT
;
39 #elif defined (DEBUG_INIFILE)
40 ULONG DebugPrintMask
= DPRINT_INIFILE
;
41 #elif defined (DEBUG_REACTOS)
42 ULONG DebugPrintMask
= DPRINT_REACTOS
| DPRINT_REGISTRY
;
43 #elif defined (DEBUG_CUSTOM)
44 ULONG DebugPrintMask
= DPRINT_WARNING
|DPRINT_FILESYSTEM
|DPRINT_MEMORY
|DPRINT_LINUX
;
45 #else //#elif defined (DEBUG_NONE)
46 ULONG DebugPrintMask
= 0;
58 #define BOCHS_OUTPUT_PORT 0xe9
60 ULONG DebugPort
= RS232
;
61 //ULONG DebugPort = SCREEN;
62 //ULONG DebugPort = BOCHS;
63 //ULONG DebugPort = SCREEN|BOCHS;
65 //ULONG BaudRate = 19200;
66 ULONG BaudRate
= 115200;
68 BOOL DebugStartOfLine
= TRUE
;
72 if (DebugPort
== RS232
)
74 Rs232PortInitialize(ComPort
, BaudRate
);
78 VOID
DebugPrintChar(UCHAR Character
)
80 if (Character
== '\n')
82 DebugStartOfLine
= TRUE
;
85 if (DebugPort
& RS232
)
87 if (Character
== '\n')
89 Rs232PortPutByte('\r');
91 Rs232PortPutByte(Character
);
93 if (DebugPort
& BOCHS
)
95 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
97 if (DebugPort
& SCREEN
)
99 MachConsPutChar(Character
);
103 VOID
DebugPrintHeader(ULONG Mask
)
132 case DPRINT_FILESYSTEM
:
177 case DPRINT_REGISTRY
:
209 case DPRINT_HWDETECT
:
235 static VOID
DebugPrintV(char *format
, int *dataptr
)
237 char c
, *ptr
, str
[16];
241 while ((c
= *(format
++)))
249 if (*format
== 'I' && *(format
+1) == '6' && *(format
+2) == '4')
258 switch (c
= *(format
++))
260 case 'd': case 'u': case 'x':
264 *convert_i64_to_ascii(str
, c
, *((unsigned long long*) dataptr
)) = 0;
269 *convert_to_ascii(str
, c
, *((unsigned long *) dataptr
++)) = 0;
276 DebugPrintChar(*(ptr
++));
282 DebugPrintChar((*(dataptr
++))&0xff);
287 ptr
= (char *)(*(dataptr
++));
289 while ((c
= *(ptr
++)))
298 DebugPrint(DPRINT_WARNING
, "\nDebugPrint() invalid format specifier - %%%c\n", c
);
305 if (DebugPort
== SCREEN
)
312 VOID
DebugPrint(ULONG Mask
, char *format
, ...)
314 int *dataptr
= (int *) &format
;
316 // Mask out unwanted debug messages
317 if (!(Mask
& DebugPrintMask
))
322 // Print the header if we have started a new line
323 if (DebugStartOfLine
)
325 DebugPrintHeader(Mask
);
326 DebugStartOfLine
= FALSE
;
329 DebugPrintV(format
, ++dataptr
);
332 VOID
DebugPrint1(char *format
, ...)
334 int *dataptr
= (int *) &format
;
336 DebugPrintV(format
, ++dataptr
);
339 VOID
DebugDumpBuffer(ULONG Mask
, PVOID Buffer
, ULONG Length
)
341 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
345 // Mask out unwanted debug messages
346 if (!(Mask
& DebugPrintMask
))
351 DebugStartOfLine
= FALSE
; // We don't want line headers
352 DebugPrint(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
354 for (Idx
=0; Idx
<Length
; )
356 DebugStartOfLine
= FALSE
; // We don't want line headers
360 DebugPrint(Mask
, "000%x:\t", Idx
);
362 else if (Idx
< 0x0100)
364 DebugPrint(Mask
, "00%x:\t", Idx
);
366 else if (Idx
< 0x1000)
368 DebugPrint(Mask
, "0%x:\t", Idx
);
372 DebugPrint(Mask
, "%x:\t", Idx
);
375 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
377 if (BufPtr
[Idx
] < 0x10)
379 DebugPrint(Mask
, "0");
381 DebugPrint(Mask
, "%x", BufPtr
[Idx
]);
385 DebugPrint(Mask
, "-");
389 DebugPrint(Mask
, " ");
394 DebugPrint(Mask
, " ");
396 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
398 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
400 DebugPrint(Mask
, "%c", BufPtr
[Idx
]);
404 DebugPrint(Mask
, ".");
408 DebugPrint(Mask
, "\n");
412 #endif // defined DEBUG