1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/**
** @file debug.h
**
** @author Numerous CSCI-452 classes
**
** Debugging macros and constants.
**
*/
#ifndef DEBUG_H_
#define DEBUG_H_
// Standard system headers
#include <cio.h>
#include <support.h>
// Kernel library
#include <lib.h>
#ifndef ASM_SRC
/*
** Start of C-only definitions
*/
/*
** General function entry/exit announcements
*/
#ifdef ANNOUNCE_ENTRY
// Announce that we have entered a kernel function
// usage: ENTERING( "name" ), EXITING( "name" )
// currently, these do not use the macro parameter, but could be
// modified to do so; instead, we use the __func__ CPP pseudo-macro
// to get the function name
#define ENTERING(n) do { cio_puts( " enter " __func__ ); } while(0)
#define EXITING(n) do { cio_puts( " exit " __func__ ); } while(0)
#else
#define ENTERING(m) // do nothing
#define EXITING(m) // do nothing
#endif
/*
** Console messages when error conditions are noted.
*/
// Warning messages to the console
// m: message (condition, etc.)
#define WARNING(m) do { \
cio_printf( "\n** %s (%s @ %d): ", __func__, __FILE__, __LINE__ ); \
cio_puts( m ); \
cio_putchar( '\n' ); \
} while(0)
// Panic messages to the console
// n: severity level
// m: message (condition, etc.)
#define PANIC(n,m) do { \
sprint( b512, "%s (%s @ %d), %d: %s\n", \
__func__, __FILE__, __LINE__, n, # m ); \
kpanic( b512 ); \
} while(0)
/*
** Assertions are categorized by the "sanity level" being used in this
** compilation; each only triggers a fault if the sanity level is at or
** above a specific value. This allows selective enabling/disabling of
** debugging checks.
**
** The sanity level is set during compilation with the CPP macro
** "SANITY". A sanity level of 0 disables conditional assertions,
** but not the basic assert() version.
*/
#ifndef SANITY
// default sanity check level: check everything!
#define SANITY 9999
#endif
// Always-active assertions
#define assert(x) if( !(x) ) { PANIC(0,x); }
// only provide these macros if the sanity check level is positive
#if SANITY > 0
#define assert1(x) if( SANITY >= 1 && !(x) ) { PANIC(1,x); }
#define assert2(x) if( SANITY >= 2 && !(x) ) { PANIC(2,x); }
#define assert3(x) if( SANITY >= 3 && !(x) ) { PANIC(3,x); }
#define assert4(x) if( SANITY >= 4 && !(x) ) { PANIC(4,x); }
// arbitrary sanity level
#define assertN(n,x) if( SANITY >= (n) && !(x) ) { PANIC(n,x); }
#else
#define assert1(x) // do nothing
#define assert2(x) // do nothing
#define assert3(x) // do nothing
#define assert4(x) // do nothing
#define assertN(n,x) // do nothing
#endif /* SANITY > 0 */
/*
** Tracing options are enabled by defining one or more of the T_
** macros described in the Makefile.
**
** To add a tracing option:
**
** 1) Pick a short name for it (e.g., "PCB", "VM", ...)
** 2) At the end of this list, add code like this, with "name"
** replaced by your short name, and "nnnnnnnn" replaced by a
** unique bit that will designate this tracing option:
**
** #ifdef T_name
** #define TRname 0xnnnnnnnn
** #else
** #define TRname 0
** #endif
**
** Use the next bit position following the one in last list entry.
** 3) Add this to the end of the "TRACE" macro definition:
**
** | TRname
**
** 4) In the list of "TRACING_*" macros, add one for your option
** (using a name that might be more descriptive) in the 'then' clause:
**
** #define TRACING_bettername ((TRACE & TRname) != 0)
**
** 5) Also add a "null" version in the 'else' clause:
**
** #define TRACING_bettername 0
**
** 6) Maybe add your T_name choice to the Makefile with an explanation
** on the off chance you want anyone else to be able to understand
** what it's used for. :-)
**
** We're making CPP work for its pay with this file.
*/
// 2^0 bit
#ifdef T_PCB
#define TRPCB 0x00000001
#else
#define TRPCB 0
#endif
#ifdef T_VM
#define TRVM 0x00000002
#else
#define TRVM 0
#endif
#ifdef T_QUE
#define TRQUEUE 0x00000004
#else
#define TRQUEUE 0
#endif
#ifdef T_SCH
#define TRSCHED 0x00000008
#else
#define TRSCHED 0
#endif
// 2^4 bit
#ifdef T_DSP
#define TRDISP 0x00000010
#else
#define TRDISP 0
#endif
#ifdef T_SCALL
#define TRSYSCALLS 0x00000020
#else
#define TRSYSCALLS 0
#endif
#ifdef T_SRET
#define TRSYSRETS 0x00000040
#else
#define TRSYSRETS 0
#endif
#ifdef T_EXIT
#define TREXIT 0x00000080
#else
#define TREXIT 0
#endif
// 2^8 bit
#ifdef T_INIT
#define TRINIT 0x00000100
#else
#define TRINIT 0
#endif
#ifdef T_KM
#define TRKMEM 0x00000200
#else
#define TRKMEM 0
#endif
#ifdef T_KMFR
#define TRKMEM_F 0x00000400
#else
#define TRKMEM_F 0
#endif
#ifdef T_KMIN
#define TRKMEM_I 0x00000800
#else
#define TRKMEM_I 0
#endif
// 2^12 bit
#ifdef T_FORK
#define TRFORK 0x00001000
#else
#define TRFORK 0
#endif
#ifdef T_EXEC
#define TREXEC 0x00002000
#else
#define TREXEC 0
#endif
#ifdef T_SIO
#define TRSIO_STAT 0x00004000
#else
#define TRSIO_STAT 0
#endif
#ifdef T_SIOR
#define TRSIO_RD 0x00008000
#else
#define TRSIO_RD 0
#endif
// 2^16 bit
#ifdef T_SIOW
#define TRSIO_WR 0x00010000
#else
#define TRSIO_WR 0
#endif
#ifdef T_USER
#define TRUSER 0x00020000
#else
#define TRUSER 0
#endif
#ifdef T_ELF
#define TRELF 0x00040000
#else
#define TRELF 0
#endif
// 13 bits remaining for tracing options
// next available bit: 0x00080000
#define TRACE (TRDISP | TREXIT | TRINIT | TRKMEM | TRKMEM_F | TRKMEM_I | TRPCB | TRQUEUE | TRSCHED | TREXEC | TRSIO_RD | TRSIO_STAT | TRSIO_WR | TRFORK | TRVM | TRSYSCALLS | TRSYSRETS | TRUSER | TRELF)
#if TRACE > 0
// compile-time expressions for testing trace options
// usage: #if TRACING_thing
#define TRACING_PCB ((TRACE & TRPCB) != 0)
#define TRACING_VM ((TRACE & TRVM) != 0)
#define TRACING_QUEUE ((TRACE & TRQUEUE) != 0)
#define TRACING_SCHED ((TRACE & TRSCHED) != 0)
#define TRACING_DISPATCH ((TRACE & TRDISPATCH) != 0)
#define TRACING_SYSCALLS ((TRACE & TRSYSCALLS) != 0)
#define TRACING_SYSRETS ((TRACE & TRSYSRETS) != 0)
#define TRACING_EXIT ((TRACE & TREXIT) != 0)
#define TRACING_INIT ((TRACE & TRINIT) != 0)
#define TRACING_KMEM ((TRACE & TRKMEM) != 0)
#define TRACING_KMEM_FREELIST ((TRACE & TRKMEM_F) != 0)
#define TRACING_KMEM_INIT ((TRACE & TRKMEM_I) != 0)
#define TRACING_FORK ((TRACE & TRFORK) != 0)
#define TRACING_EXEC ((TRACE & TREXEC) != 0)
#define TRACING_SIO_STAT ((TRACE & TRSIO_STAT) != 0)
#define TRACING_SIO_ISR ((TRACE & TRSIO_ISR) != 0)
#define TRACING_SIO_RD ((TRACE & TRSIO_RD) != 0)
#define TRACING_SIO_WR ((TRACE & TRSIO_WR) != 0)
#define TRACING_USER ((TRACE & TRUSER) != 0)
#define TRACING_ELF ((TRACE & TRELF) != 0)
// more generic tests
#define TRACING_SOMETHING (TRACE != 0)
#else
// TRACE == 0, so just define these all as "false"
#define TRACING_PCB 0
#define TRACING_STACK 0
#define TRACING_QUEUE 0
#define TRACING_SCHED 0
#define TRACING_DISPATCH 0
#define TRACING_SYSCALLS 0
#define TRACING_SYSRET 0
#define TRACING_EXIT 0
#define TRACING_INIT 0
#define TRACING_KMEM 0
#define TRACING_KMEM_FREELIST 0
#define TRACING_KMEM_INIT 0
#define TRACING_FORK 0
#define TRACING_EXEC 0
#define TRACING_SI_STAT 0
#define TRACING_SIO_ISR 0
#define TRACING_SIO_RD 0
#define TRACING_SIO_WR 0
#define TRACING_USER 0
#define TRACING_ELF 0
#define TRACING_SOMETHING 0
#endif /* TRACE */
#endif /* !ASM_SRC */
#endif
|