-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiag.h
75 lines (66 loc) · 2.75 KB
/
diag.h
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
// Include this in every MMU-connected device to enable diagnostics.
//
// Add HANDLE_DIAGNOSTICS near the top of the device source file to
// insert support code for diagnostics. It will create a function
// which implements a callback to control the verbosity level. This
// function must be included in the struct passed to mmu_register.
//
// The syntax for diagnostic output is this:
// LEVEL(FORMAT [, ARGS])
// where LEVEL is one of the six levels below,
// FORMAT is a printf-style format string, and
// ARGS are arguments to the format string.
#include "mmu.h"
extern void diag_set_module_levels(char *);
extern void print_diagnostic(int, struct mmu *, const char *, ...);
#define LEVEL_FATAL 1
#define LEVEL_ERROR 2
#define LEVEL_WARN 3
#define LEVEL_INFO 4
#define LEVEL_DEBUG 5
#define LEVEL_TRACE 6
#define LEVEL_CLOCK 7
#define PRINT_DIAG(LEVEL, FORMAT, ...) \
print_diagnostic(LEVEL_##LEVEL, mmu_device, FORMAT, ##__VA_ARGS__)
// Panic, we're about to die!
#define FATAL(FORMAT, ...) PRINT_DIAG(FATAL, FORMAT, ##__VA_ARGS__)
// Serous error, but we can proceed.
#define ERROR(FORMAT, ...) PRINT_DIAG(ERROR, FORMAT, ##__VA_ARGS__)
// Problem, alert the user.
#define WARN(FORMAT, ...) PRINT_DIAG(WARN, FORMAT, ##__VA_ARGS__)
// No problem, but user may want to know.
#define INFO(FORMAT, ...) PRINT_DIAG(INFO, FORMAT, ##__VA_ARGS__)
// Step-by-step description of internal mechanisms.
#define DEBUG(FORMAT, ...) PRINT_DIAG(DEBUG, FORMAT, ##__VA_ARGS__)
#ifdef DBG
// Feel free to call this just about CPU instruction.
#define TRACE(FORMAT, ...) PRINT_DIAG(TRACE, FORMAT, ##__VA_ARGS__)
// Feel free to call this just about every clock cycle.
#define CLOCK(FORMAT, ...) PRINT_DIAG(CLOCK, FORMAT, ##__VA_ARGS__)
#define ASSERT(CONDITION) \
do { \
if(!(CONDITION)) \
FATAL("Assertion failed: %s", #CONDITION); \
} while(0)
#else
#define ASSERT(CONDITION)
#define TRACE(FORMAT, ...)
#define CLOCK(FORMAT, ...)
#endif
#define HANDLE_DIAGNOSTICS(device) \
static struct mmu *mmu_device = NULL; \
static void device ## _diagnostics(struct mmu *device, int n) \
{ \
mmu_device = device; \
device->verbosity = n; \
}
#define HANDLE_DIAGNOSTICS_NON_MMU_DEVICE(device, device_id) \
do { \
extern void diagnostics_level(struct mmu *, int); \
extern int verbosity; \
struct mmu *dummy_device; \
dummy_device = (struct mmu *)malloc(sizeof(struct mmu)); \
dummy_device->diagnostics = device ## _diagnostics; \
memcpy(dummy_device->id, device_id, 4); \
diagnostics_level(dummy_device, verbosity); \
} while(0)