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 U32 DebugPrintMask
= DPRINT_WARNING
| DPRINT_MEMORY
| DPRINT_FILESYSTEM
|
37 DPRINT_UI
| DPRINT_DISK
| DPRINT_CACHE
| DPRINT_REACTOS
|
39 #elif defined (DEBUG_INIFILE)
40 U32 DebugPrintMask
= DPRINT_INIFILE
;
41 #elif defined (DEBUG_REACTOS)
42 U32 DebugPrintMask
= DPRINT_REACTOS
| DPRINT_REGISTRY
;
43 #elif defined (DEBUG_CUSTOM)
44 U32 DebugPrintMask
= DPRINT_WARNING
|DPRINT_FILESYSTEM
|DPRINT_MEMORY
|DPRINT_LINUX
;
45 #else //#elif defined (DEBUG_NONE)
46 U32 DebugPrintMask
= 0;
58 #define BOCHS_OUTPUT_PORT 0xe9
60 U32 DebugPort
= RS232
;
61 //U32 DebugPort = SCREEN;
62 //U32 DebugPort = BOCHS;
64 //U32 BaudRate = 19200;
65 U32 BaudRate
= 115200;
67 BOOL 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 else if (DebugPort
== BOCHS
)
94 WRITE_PORT_UCHAR((PUCHAR
)BOCHS_OUTPUT_PORT
, Character
);
98 MachConsPutChar(Character
);
102 VOID
DebugPrintHeader(U32 Mask
)
131 case DPRINT_FILESYSTEM
:
176 case DPRINT_REGISTRY
:
208 case DPRINT_HWDETECT
:
234 static VOID
DebugPrintV(char *format
, int *dataptr
)
236 char c
, *ptr
, str
[16];
240 while ((c
= *(format
++)))
248 if (*format
== 'I' && *(format
+1) == '6' && *(format
+2) == '4')
257 switch (c
= *(format
++))
259 case 'd': case 'u': case 'x':
263 *convert_i64_to_ascii(str
, c
, *((unsigned long long*) dataptr
)) = 0;
268 *convert_to_ascii(str
, c
, *((unsigned long *) dataptr
++)) = 0;
275 DebugPrintChar(*(ptr
++));
281 DebugPrintChar((*(dataptr
++))&0xff);
286 ptr
= (char *)(*(dataptr
++));
288 while ((c
= *(ptr
++)))
297 DebugPrint(DPRINT_WARNING
, "\nDebugPrint() invalid format specifier - %%%c\n", c
);
304 if (DebugPort
== SCREEN
)
311 VOID
DebugPrint(U32 Mask
, char *format
, ...)
313 int *dataptr
= (int *) &format
;
315 // Mask out unwanted debug messages
316 if (!(Mask
& DebugPrintMask
))
321 // Print the header if we have started a new line
322 if (DebugStartOfLine
)
324 DebugPrintHeader(Mask
);
325 DebugStartOfLine
= FALSE
;
328 DebugPrintV(format
, ++dataptr
);
331 VOID
DebugPrint1(char *format
, ...)
333 int *dataptr
= (int *) &format
;
335 DebugPrintV(format
, ++dataptr
);
338 VOID
DebugDumpBuffer(U32 Mask
, PVOID Buffer
, U32 Length
)
340 PUCHAR BufPtr
= (PUCHAR
)Buffer
;
344 // Mask out unwanted debug messages
345 if (!(Mask
& DebugPrintMask
))
350 DebugStartOfLine
= FALSE
; // We don't want line headers
351 DebugPrint(Mask
, "Dumping buffer at 0x%x with length of %d bytes:\n", Buffer
, Length
);
353 for (Idx
=0; Idx
<Length
; )
355 DebugStartOfLine
= FALSE
; // We don't want line headers
359 DebugPrint(Mask
, "000%x:\t", Idx
);
361 else if (Idx
< 0x0100)
363 DebugPrint(Mask
, "00%x:\t", Idx
);
365 else if (Idx
< 0x1000)
367 DebugPrint(Mask
, "0%x:\t", Idx
);
371 DebugPrint(Mask
, "%x:\t", Idx
);
374 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
376 if (BufPtr
[Idx
] < 0x10)
378 DebugPrint(Mask
, "0");
380 DebugPrint(Mask
, "%x", BufPtr
[Idx
]);
384 DebugPrint(Mask
, "-");
388 DebugPrint(Mask
, " ");
393 DebugPrint(Mask
, " ");
395 for (Idx2
=0; Idx2
<16; Idx2
++,Idx
++)
397 if ((BufPtr
[Idx
] > 20) && (BufPtr
[Idx
] < 0x80))
399 DebugPrint(Mask
, "%c", BufPtr
[Idx
]);
403 DebugPrint(Mask
, ".");
407 DebugPrint(Mask
, "\n");
411 #endif // defined DEBUG