[FREELDR] Fix release builds for PC-98 and Xbox platforms
[reactos.git] / boot / freeldr / freeldr / include / debug.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #ifndef __DEBUG_H
21 #define __DEBUG_H
22
23 #define DPRINT_NONE 0 // No debug print
24 #define DPRINT_WARNING 1 // debugger messages and other misc stuff
25 #define DPRINT_MEMORY 2 // memory management messages
26 #define DPRINT_FILESYSTEM 3 // file system messages
27 #define DPRINT_INIFILE 4 // .ini file messages
28 #define DPRINT_UI 5 // user interface messages
29 #define DPRINT_DISK 6 // disk messages
30 #define DPRINT_CACHE 7 // cache messages
31 #define DPRINT_REGISTRY 8 // registry messages
32 #define DPRINT_REACTOS 9 // ReactOS messages
33 #define DPRINT_LINUX 10 // Linux messages
34 #define DPRINT_HWDETECT 11 // hardware detection messages
35 #define DPRINT_WINDOWS 12 // messages from Windows loader
36 #define DPRINT_PELOADER 13 // messages from PE images loader
37 #define DPRINT_SCSIPORT 14 // messages from SCSI miniport
38 #define DPRINT_HEAP 15 // messages in a bottle
39 #define DBG_CHANNELS_COUNT 16
40
41 #if DBG && !defined(_M_ARM)
42
43 VOID DebugInit(IN ULONG_PTR FrLdrSectionId);
44 ULONG DbgPrint(const char *Format, ...);
45 VOID DbgPrint2(ULONG Mask, ULONG Level, const char *File, ULONG Line, char *Format, ...);
46 VOID DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length);
47 VOID DebugDisableScreenPort();
48 VOID DbgParseDebugChannels(PCHAR Value);
49
50 #define ERR_LEVEL 0x1
51 #define FIXME_LEVEL 0x2
52 #define WARN_LEVEL 0x4
53 #define TRACE_LEVEL 0x8
54
55 #define MAX_LEVEL ERR_LEVEL | FIXME_LEVEL | WARN_LEVEL | TRACE_LEVEL
56
57 #define DBG_DEFAULT_CHANNEL(ch) static int DbgDefaultChannel = DPRINT_##ch
58
59 #define ERR_CH(ch, fmt, ...) DbgPrint2(DPRINT_##ch, ERR_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
60 #define FIXME_CH(ch, fmt, ...) DbgPrint2(DPRINT_##ch, FIXME_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
61 #define WARN_CH(ch, fmt, ...) DbgPrint2(DPRINT_##ch, WARN_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
62 #define TRACE_CH(ch, fmt, ...) DbgPrint2(DPRINT_##ch, TRACE_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
63
64 #define ERR(fmt, ...) DbgPrint2(DbgDefaultChannel, ERR_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
65 #define FIXME(fmt, ...) DbgPrint2(DbgDefaultChannel, FIXME_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
66 #define WARN(fmt, ...) DbgPrint2(DbgDefaultChannel, WARN_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
67 #define TRACE(fmt, ...) DbgPrint2(DbgDefaultChannel, TRACE_LEVEL, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
68
69 #define UNIMPLEMENTED DbgPrint("(%s:%d) WARNING: %s is UNIMPLEMENTED!\n", __FILE__, __LINE__, __FUNCTION__);
70
71 #define BugCheck(fmt, ...) do { DbgPrint("(%s:%d) Fatal Error in %s: " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); for (;;); } while (0)
72 #define DbgDumpBuffer(mask, buf, len) DebugDumpBuffer(mask, buf, len)
73
74 #ifdef __i386__
75
76 // Debugging support functions:
77 //
78 // BREAKPOINT() - Inserts an "int 3" instruction
79 // INSTRUCTION_BREAKPOINTX(x) - Enters exception handler right before instruction at address "x" is executed
80 // MEMORY_READWRITE_BREAKPOINTX(x) - Enters exception handler when a read or write occurs at address "x"
81 // MEMORY_WRITE_BREAKPOINTX(x) - Enters exception handler when a write occurs at address "x"
82 //
83 // You may have as many BREAKPOINT()'s as you like but you may only
84 // have up to four of any of the others.
85 #define BREAKPOINT() __asm__ ("int $3");
86 void INSTRUCTION_BREAKPOINT1(unsigned long addr);
87 void MEMORY_READWRITE_BREAKPOINT1(unsigned long addr);
88 void MEMORY_WRITE_BREAKPOINT1(unsigned long addr);
89 void INSTRUCTION_BREAKPOINT2(unsigned long addr);
90 void MEMORY_READWRITE_BREAKPOINT2(unsigned long addr);
91 void MEMORY_WRITE_BREAKPOINT2(unsigned long addr);
92 void INSTRUCTION_BREAKPOINT3(unsigned long addr);
93 void MEMORY_READWRITE_BREAKPOINT3(unsigned long addr);
94 void MEMORY_WRITE_BREAKPOINT3(unsigned long addr);
95 void INSTRUCTION_BREAKPOINT4(unsigned long addr);
96 void MEMORY_READWRITE_BREAKPOINT4(unsigned long addr);
97 void MEMORY_WRITE_BREAKPOINT4(unsigned long addr);
98
99 #endif // defined __i386__
100
101 #else
102
103 #define DBG_DEFAULT_CHANNEL(ch)
104
105 #define ERR_CH(ch, fmt, ...)
106 #define FIXME_CH(ch, fmt, ...)
107 #define WARN_CH(ch, fmt, ...)
108 #define TRACE_CH(ch, fmt, ...)
109
110 #define ERR(fmt, ...)
111 #define FIXME(fmt, ...)
112 #define WARN(fmt, ...)
113 #define TRACE(fmt, ...)
114
115 #define UNIMPLEMENTED
116
117 #define DebugInit(FrLdrSectionId)
118 #define BugCheck(fmt, ...)
119 #define DbgDumpBuffer(mask, buf, len)
120 #define DebugDisableScreenPort()
121 #define DbgParseDebugChannels(val)
122
123 #endif // DBG
124
125 void
126 NTAPI
127 FrLdrBugCheck(ULONG BugCode);
128
129 VOID
130 FrLdrBugCheckWithMessage(
131 ULONG BugCode,
132 PCHAR File,
133 ULONG Line,
134 PSTR Format,
135 ...);
136
137 /* Bugcheck codes */
138 enum _FRLDR_BUGCHECK_CODES
139 {
140 TEST_BUGCHECK,
141 MISSING_HARDWARE_REQUIREMENTS,
142 FREELDR_IMAGE_CORRUPTION,
143 MEMORY_INIT_FAILURE,
144 };
145
146 extern char *BugCodeStrings[];
147 extern ULONG_PTR BugCheckInfo[5];
148
149 #endif // defined __DEBUG_H