1
1
/**
2
2
* @file
3
- * @author Matt "MateoConLechuga" Waltz
4
- * @brief Contains debugging features for use with a compatible debugger
5
3
*
6
4
* These debug functions are provided to help in the process of debugging
7
- * an application. To enable them, use ' make debug' when compiling a program.
5
+ * an application. To enable them, use ` make debug` when compiling a program.
8
6
*/
9
7
10
8
#include <stdio.h>
@@ -16,16 +14,20 @@ extern "C" {
16
14
#ifndef NDEBUG
17
15
18
16
/** Standard debug output */
19
- #define dbgout ((char *)0xFB0000)
17
+ #define dbgout ((void *)0xFB0000)
20
18
/** Standard error debug output */
21
- #define dbgerr ((char *)0xFC0000)
19
+ #define dbgerr ((void *)0xFC0000)
22
20
23
21
/** Break on read. */
24
22
#define DBG_WATCHPOINT_READ (1 << 0)
25
23
/** Break on write. */
26
24
#define DBG_WATCHPOINT_WRITE (1 << 1)
27
- /** Break on read or write. */
28
- #define DBG_WATCHPOINT_RW ((1 << 0) | (1 << 1))
25
+ /** Break on execute. */
26
+ #define DBG_WATCHPOINT_EXECUTE (1 << 2)
27
+ /** Break on read, write, or execute. */
28
+ #define DBG_WATCHPOINT_ALL (DBG_WATCHPOINT_READ | DBG_WATCHPOINT_WRITE | DBG_WATCHPOINT_EXECUTE)
29
+ /** Remove watchpoint. */
30
+ #define DBG_WATCHPOINT_NONE 0
29
31
30
32
/**
31
33
* Used to print to the emulator console.
@@ -34,110 +36,58 @@ extern "C" {
34
36
* @param[in] ... Uses printf-formated specifier string.
35
37
* @note Does not support floats unless `HAS_PRINTF = YES`.
36
38
*/
37
- #define dbg_printf (...) sprintf(dbgout, ##__VA_ARGS__)
39
+ #define dbg_printf (...) \
40
+ sprintf(dbgout, ##__VA_ARGS__)
38
41
39
42
/**
40
43
* Used to print to the emulator console.
41
44
*
42
45
* See the syntax for 'printf' for format specifiers.
43
- * @param[in] out Can be dbgout (black) or dbgerr (red) .
46
+ * @param[in] out Use \p dbgout for normal output and \p dbgerr for errors .
44
47
* @param[in] ... Uses printf-formated specifier string.
45
48
* @note Does not support floats unless `HAS_PRINTF = YES`.
46
49
*/
47
- #define dbg_sprintf (out , ...) sprintf(out, ##__VA_ARGS__)
50
+ #define dbg_sprintf (out , ...) \
51
+ sprintf(out, ##__VA_ARGS__)
48
52
49
53
/**
50
- * Clears the emulation console
54
+ * Clears the emulation console.
51
55
*/
52
56
#define dbg_ClearConsole () \
53
57
do { \
54
- *(volatile unsigned char*)0xFFFFE0 = 10 ; \
58
+ *(volatile unsigned char*)0xFD0000 = 1 ; \
55
59
} while (0)
56
60
57
61
/**
58
- * Opens the emulator's debugger.
62
+ * Opens the emulator's debugger immediately
59
63
*/
60
- #define dbg_Debugger () \
61
- do { \
62
- *(volatile unsigned char*)0xFFFFE0 = (unsigned char)~0; \
63
- } while (0)
64
-
65
- /**
66
- * Sets an emulated breakpoint.
67
- *
68
- * @param[in] address Breakpoint address to set.
69
- */
70
- #define dbg_SetBreakpoint (address ) \
71
- do { \
72
- *(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
73
- *(volatile unsigned char*)0xFFFFE0 = 1; \
74
- } while (0)
75
-
76
- /**
77
- * Removes an emulated breakpoint.
78
- *
79
- * @param[in] address Breakpoint address to remove.
80
- */
81
- #define dbg_RemoveBreakpoint (address ) \
82
- do { \
83
- *(volatile unsigned int*)0xFFFFE4 = (address); \
84
- *(volatile unsigned char*)0xFFFFE0 = 2; \
85
- } while (0)
86
-
87
- /**
88
- * Sets an emulated watchpoint.
89
- *
90
- * @param[in] address Watchpoint address to set.
91
- * @param[in] length The size of the data at the address.
92
- * @param[in] flags DBG_WATCHPOINT_READ, DBG_WATCHPOINT_WRITE, or
93
- * DBG_WATCHPOINT_RW. (or 0 to disable).
94
- */
95
- #define dbg_SetWatchpoint (address , length , flags ) \
96
- do { \
97
- *(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
98
- *(volatile unsigned int*)0xFFFFE8 = ((unsigned int)(address) + (length) - 1); \
99
- *(volatile unsigned char*)0xFFFFEC = (unsigned char)(flags); \
100
- *(volatile unsigned char*)0xFFFFE0 = 3; \
101
- } while (0)
64
+ void dbg_Debugger (void );
102
65
103
66
/**
104
- * Removes an emulated watchpoint.
105
- *
106
- * @param[in] address Watchpoint address to remove.
67
+ * Sets a watchpoint to open the debugger when an address
68
+ * is read, written, or executed. Use the masks DBG_WATCHPOINT_READ,
69
+ * DBG_WATCHPOINT_WRITE, and DBG_WATCHPOINT_EXECUTE respectively to
70
+ * configure the watchpoint.
71
+ *
72
+ * @param[in] address Watchpoint address.
73
+ * @param[in] size Watchpoint size in bytes. Currently must be 1.
74
+ * @param[in] mask Watchpoint mask, use DBG_WATCHPOINT_NONE to remove
75
+ * the watchpoint.
107
76
*/
108
- #define dbg_RemoveWatchpoint (address ) \
109
- do { \
110
- *(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
111
- *(volatile unsigned char*)0xFFFFE0 = 4; \
112
- } while (0)
77
+ void dbg_WatchpointSet (void * address , size_t size , uint8_t mask );
113
78
114
79
/**
115
- * Removes all emulated breakpoints .
80
+ * Removes all watchpoints .
116
81
*/
117
- #define dbg_RemoveAllBreakpoints () \
118
- do { \
119
- *(volatile unsigned char*)0xFFFFE0 = 5; \
120
- } while (0)
121
-
122
- /**
123
- * Removes all emulated watchpoints.
124
- */
125
- #define dbg_RemoveAllWatchpoints () \
126
- do { \
127
- *(volatile unsigned char*)0xFFFFE0 = 6; \
128
- } while (0)
82
+ void dbg_WatchpointRemoveAll (void );
129
83
130
84
#else
131
85
#define dbg_printf (...) ((void)0)
132
86
#define dbg_sprintf (...) ((void)0)
133
87
#define dbg_ClearConsole (...) ((void)0)
134
88
#define dbg_Debugger (...) ((void)0)
135
- #define dbg_SetBreakpoint (...) ((void)0)
136
- #define dbg_RemoveBreakpoint (...) ((void)0)
137
- #define dbg_SetWatchpoint (...) ((void)0)
138
- #define dbg_RemoveWatchpoint (...) ((void)0)
139
- #define dbg_RemoveAllBreakpoints (...) ((void)0)
140
- #define dbg_RemoveAllWatchpoints (...) ((void)0)
89
+ #define dbg_WatchpointSet (...) ((void)0)
90
+ #define dbg_WatchpointRemoveAll (...) ((void)0)
141
91
#endif
142
92
143
93
#ifdef __cplusplus
0 commit comments