aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug/Debugger/debug_macros.h
blob: d852f380f06d80eb1051ecb9236f11fa04ae5158 (plain)
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
/** @file debug_macros.h
 *  @brief internal macros used by debug_stub routines
 *
 */

/* Copyright (C) 2007-2010 the NxOS developers
 *
 * Module Developed by: TC Wan <tcwan@cs.usm.my>
 *
 * See AUTHORS for a full list of the developers.
 *
 * See COPYING for redistribution license
 *
 */

#ifndef __DEBUG_MACROS_H__
#define __DEBUG_MACROS_H__




/*@{*/

/** _dbg_jumpTableHandler
 *      Call Jump Table Routine based on Index
 *	On entry:
 *	  @param jumptableaddr is the address (constant) of the Jump Table
 *	  @param jumpreg is the register used to perform the indirect jump
 *	  @param indexreg contains jump table index value
 */
	.macro  _dbg_jumpTableHandler   jumptableaddr, jumpreg, indexreg

	ldr	 \jumpreg, =\jumptableaddr
	ldr	 \jumpreg, [\jumpreg, \indexreg, lsl #2]
	mov	 lr, pc
	bx	  \jumpreg	/* Call Command Handler Routine */
	.endm


/** _dbg_thumbDecodeEntry
 *      Load Thumb Instruction Decoder Entry
 *      On entry:
 *        @param instrreg is the register to load the instruction into
 *        @param instrmask is the register to load the instruction mask into
 *        @param codehandler is the register to load the code handling routine into
 *        @param indexreg contains decode table index value
 *      NOTE: instrreg, instrmask, codehandler must be in increasing register number order
 */
        .macro  _dbg_thumbDecodeEntry   instrreg, instrmask, codehandler, indexreg

        ldr      \instrmask, =debug_thumbDecodeTable                    /* Temporary register */
        add      \instrmask, \instrmask, \indexreg, lsl #3
        ldm      \instrmask, {\instrreg, \codehandler}                  /* LSHW: IID, MSHW: IBM */
        mov      \instrmask, \instrreg, lsr #16
        mov      \instrreg, \instrreg, lsl #16
        mov      \instrreg, \instrreg, lsr #16                          /* Keep HLFWORD0 containing instruction */
        .endm

/** _dbg_armDecodeEntry
 *      Load ARM Instruction Decoder Entry
 *      On entry:
 *        @param instrreg is the register to load the instruction into
 *        @param instrmask is the register to load the instruction mask into
 *        @param codehandler is the register to load the code handling routine into
 *        @param indexreg contains decode table index value
 *      NOTE: instrreg, instrmask, codehandler must be in increasing register number order
 */
        .macro  _dbg_armDecodeEntry   instrreg, instrmask, codehandler, indexreg

        ldr      \instrmask, =debug_armDecodeTable                    /* Temporary register */
        add      \instrmask, \instrmask, \indexreg, lsl #3
        add      \instrmask, \instrmask, \indexreg, lsl #2              /* 12  byte entries */
        ldm      \instrmask, {\instrreg, \instrmask, \codehandler}
        .endm

/** _asciiz
 *	Terminate string given string buffer pointer in \strptr
 *	scratchreg is used as a scratch register (destroyed)
 *
 */
	.macro	_asciiz	strptr, scratchreg
	mov	\scratchreg, #0				/* ASCIIZ character */
	strb	\scratchreg, [\strptr]			/* Terminate ASCII string */
 	.endm


/** _dbg_stpcpy
 *	_dbg_stpcpy macro
 *	On entry:
 *	  deststrptr: Destination string
 *	  sourcestrptr: Source string
 *	  scratchreg: scratch register for copying
 *	On exit:
 *	  deststrptr: Pointer to ASCIIZ character in destination string
 *	  sourcestrptr: Pointer to next character slot in source string (after ASCIIZ)
 *	  scratchreg: destroyed
 */
	.macro  _dbg_stpcpy	 deststrptr, sourcestrptr, scratchreg
1:	ldrb	\scratchreg, [\sourcestrptr], #1
	strb	\scratchreg, [\deststrptr], #1
	teq	 \scratchreg, #0
	bne	 1b
	sub	 \deststrptr, \deststrptr, #1	/* Adjust Destination string pointer to point at ASCIIZ character */
	.endm

/** _dbg_memcpy
 *      _dbg_stpcpy macro
 *      On entry:
 *        deststrptr: Destination string
 *        sourcestrptr: Source string
 *        sizereg: Number of bytes to copy
 *        scratchreg: scratch register for copying
 *      On exit:
 *        deststrptr: Pointer to next character slot in destination string
 *        sourcestrptr: Pointer to next character slot in source string
 *        sizereg, scratchreg: destroyed
 */
        .macro  _dbg_memcpy      deststrptr, sourcestrptr, sizereg, scratchreg
1:      ldrb    \scratchreg, [\sourcestrptr], #1
        strb    \scratchreg, [\deststrptr], #1
        subs    \sizereg, \sizereg, #1
        bne      1b
        .endm

/** _dbg_CopyMsg2OutputBuf
 *      Copies source message to output buffer
 *      On entry:
 *        R2: source message buffer (ASCIIZ terminated)
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_CopyMsg2OutputBuf
        ldr      r0, =debug_OutMsgBuf
        _dbg_stpcpy     r0, r2, r3
        .endm

/** _dbg_CopyMsg2OutputBuf_withParam
 *  Internal Routine called to output message with parameters
 *      Return Message with byte-sized parameter
 *      On entry:
 *        R1: byte-sized param
 *        R2: source message buffer (ASCIIZ terminated)
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R1-R3: destroyed
 */
        .macro  _dbg_CopyMsg2OutputBuf_withParam
        _dbg_CopyMsg2OutputBuf    /* R1 unchanged */
        bl      byte2ascii        /* R0 points to buffer position after byte value */
        _asciiz r0, r1
        .endm

/** _dbg_outputAckOnlyFlag
 *      Return Flag ('+') for Continue or Step
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_outputAckOnlyFlag
        ldr      r2, =debug_AckOnlyFlag                  /* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
        .endm


/** _dbg_outputRetransmitFlag
 *      Return Flag ('-') for Checksum Error (retransmission needed)
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_outputRetransmitFlag
        ldr      r2, =debug_RetransmitFlag                  /* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
        .endm

/** _dbg_outputMsgValidResponse
 *	Return Message with valid response ('+$')
 *	On exit:
 *	  R0: Pointer to Output Buffer next character slot location
 *        R2-R3: destroyed
 */
	.macro  _dbg_outputMsgValidResponse
	ldr	 r2, =debug_ValidResponsePrefix
        _dbg_CopyMsg2OutputBuf
	.endm

/** _dbg_outputMsgStatusOk
 *	Return Message with Ok ('+$OK') status
 *	On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *	  R2-R3: destroyed
 */
	.macro  _dbg_outputMsgStatusOk
	ldr	 r2, =debug_OkResponse			/* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
	.endm

/** _dbg_outputMsgCurrTID
 *      Return Message with Default Thread ID ('+$QC0')
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_outputMsgCurrTID
        ldr      r2, =debug_ThreadIDResponse              /* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
        .endm

/** _dbg_outputMsgFirstThreadInfo
 *      Return Message with Default Current Thread ID ('+$m0')
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_outputMsgFirstThreadInfo
        ldr      r2, =debug_FirstThreadInfoResponse        /* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
        .endm

/** _dbg_outputMsgSubsequentThreadInfo
 *      Return Message with Default Current Thread ID ('+$m0')
 *      On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R2-R3: destroyed
 */
        .macro  _dbg_outputMsgSubsequentThreadInfo
        ldr      r2, =debug_SubsequentThreadInfoResponse   /* ASCIIZ terminated */
        _dbg_CopyMsg2OutputBuf
        .endm

/** _dbg_outputMsgStatusErr
 *	Return Message with Error ('+$ENN') status
 *	On entry:
 *	  R1: error code
 *	On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R1-R3: destroyed
 */
	.macro  _dbg_outputMsgStatusErr
        ldr     r2, =debug_ErrorResponsePrefix
	_dbg_CopyMsg2OutputBuf_withParam
	.endm

/** _dbg_outputMsgStatusErrCode
 *	Return Message with Error ('+$ENN') status
 *	On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R1-R3: destroyed
 */
	.macro  _dbg_outputMsgStatusErrCode errcode
	mov	r1, #\errcode
	_dbg_outputMsgStatusErr
	.endm

/** _dbg_outputMsgStatusSig
 *	Return Message with Signal ('+$SNN') status
 *	On entry:
 *	  R1: signal code
 *	On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R1-R3: destroyed
 */
	.macro  _dbg_outputMsgStatusSig
        ldr     r2, =debug_SignalResponsePrefix
        _dbg_CopyMsg2OutputBuf_withParam
	.endm

/** _dbg_outputMsgStatusSigCode
 *	Return Message with Signal ('+$SNN') status
 *	On exit:
 *        R0: Pointer to Output Buffer ASCIIZ location
 *        R1-R3: destroyed
 */
	.macro  _dbg_outputMsgStatusSigCode statuscode
	mov	r1, #\statuscode
	_dbg_outputMsgStatusSig
	.endm


/** _regenum2index
 *      Convert register enum to debugger stack index
 *
 *      On entry:
 *        @param indexenum: enum representing Register to access
 *        @param indexreg: register to be used to store the debugger stack index value (0-max index)
 *      On exit:
 *        @param indexreg contains debugger stack index value (0-max index)
 */
	.macro	_regenum2index indexenum, indexreg
    add     \indexreg, \indexenum, #DBGSTACK_USERREG_INDEX /* Convert register index to Debug Stack index */
    .endm

/** _getdbgregisterfromindex
 *      Retrieve register contents from debugger stack given index
 *
 *      On entry:
 *        @param indexreg contains debugger stack index value (0-max index)
 *      On exit:
 *        @param indexreg: Breakpoint index (preserved)
 *        @param contentsreg: Register Contents for given index
 */
        .macro  _getdbgregisterfromindex  indexreg, contentsreg
        ldr      \contentsreg, =__debugger_stack_bottom__
        ldr      \contentsreg, [\contentsreg, \indexreg, lsl #2]
        .endm

/** _setdbgregisterfromindex
 *      Store register contents to debugger stack given index
 *
 *      On entry:
 *        @param indexreg contains debugger stack index value (0-max index)
 *        @param contentsreg: Register Contents for given index
 *        @param addressreg: Scratch register for address pointer
 *      On exit:
 *        @param indexreg: Breakpoint index (preserved)
 *        @param contentsreg: Register Contents for given index
 */
        .macro  _setdbgregisterfromindex  indexreg, contentsreg, addressreg
        ldr      \addressreg, =__debugger_stack_bottom__
        str      \contentsreg, [\addressreg, \indexreg, lsl #2]
        .endm

/** _getdbgregister
 *      Retrieve register contents from debugger stack given immediate index value
 *
 *      On entry:
 *        @param indexval contains debugger stack index value (0-max index)
 *      On exit:
 *        @param contentsreg: Register Contents for given index
 */
        .macro  _getdbgregister  indexval, contentsreg
        ldr      \contentsreg, =__debugger_stack_bottom__
        ldr      \contentsreg, [\contentsreg, #(\indexval << 2)]
        .endm

/** _setdbgregister
 *      Store register contents to debugger stack given immediate index value
 *
 *      On entry:
 *        @param indexval contains debugger stack index value (0-max index)
 *        @param contentsreg: Register Contents for given index
 *        @param addressreg: Scratch register for address pointer
 *      On exit:
 *        @param contentsreg: Register Contents for given index
 *        @param addressreg: Destroyed
 */
        .macro  _setdbgregister  indexval, contentsreg, addressreg
        ldr      \addressreg, =__debugger_stack_bottom__
        str      \contentsreg, [\addressreg, #(\indexval << 2)]
        .endm

/** _index2bkptindex_addr
 *	Convert Breakpoint index to breakpoing entry address
 *
 *	On entry:
 *	  @param indexreg contains breakpoint index value
 *	On exit:
 *	  @param indexreg: Breakpoint index (preserved)
 *	  @param addrreg: Breakpoint Entry Address
 */
	.macro _index2bkptindex_addr indexreg, addrreg
	ldr	 \addrreg, =__breakpoints_start__
	add	 \addrreg, \addrreg, \indexreg, lsl #3	   /* Calculate Breakpoint Entry Address */
	.endm

/** _dbg_getstate
 *	Get Debugger State
 *	On exit:
 *	  @param reg: Debugger State enum
 */
	.macro _dbg_getstate	reg
	ldr	 \reg, =debug_state
	ldrb     \reg, [\reg]
	.endm

/** _dbg_setstate
 *	Set Debugger State to given value
 *	On exit:
 *	  r0, r1: destroyed
 */
	.macro _dbg_setstate	state
	mov	 r0, #\state
	ldr	 r1, =debug_state
	strb     r0, [r1]
	.endm

/** _dbg_getmode
 *	Get Debugger Mode
 *	On exit:
 *	  @param reg: Debugger Mode (Boolean)
 */
	.macro _dbg_getmode	reg
	ldr	 \reg, =debug_mode
	ldrb     \reg, [\reg]
	.endm

/** _dbg_setmode
 *	Set Debugger Mode to given value
 *	On exit:
 *	  r0, r1: destroyed
 */
	.macro _dbg_setmode	mode
	mov	 r0, #\mode
	ldr	 r1, =debug_mode
	strb     r0, [r1]
	.endm

/** _dbg_get_bkpt_type
 *      Get Breakpoint Type
 *      On exit:
 *        @param reg: Breakpoint Type
 */
        .macro _dbg_get_bkpt_type     reg
        ldr      \reg, =debug_bkpt_type
        ldrb     \reg, [\reg]
        .endm

/** _dbg_set_bkpt_type
 *      Set Breakpoint Type using value in reg
 *      On exit:
 *        @param reg: destroyed
 *        r1: destroyed
 */
		.macro _dbg_set_bkpt_type     reg
		ldr      r1, =debug_bkpt_type
		strb     \reg, [r1]
		.endm

/** _dbg_set_bkpt_type_val
 *      Set Breakpoint Type to given value
 *      On exit:
 *        r0, r1: destroyed
 */
        .macro _dbg_set_bkpt_type_val   bkpt_type
        mov      r0, #\bkpt_type
        ldr      r1, =debug_bkpt_type
        strb     r0, [r1]
        .endm

/** _dbg_getcurrbkpt_index
 *	Get current breakpoint index
 *	On exit:
 *	  @param reg: Breakpoint index
 */
	.macro _dbg_getcurrbkpt_index   reg
	ldr	 \reg, =debug_curr_breakpoint
	ldrb \reg, [\reg]
	.endm

/** _dbg_setcurrbkpt_index
 *	Set current breakpoint index
 *	On exit:
 *	  r1: destroyed
 */
	.macro _dbg_setcurrbkpt_index  reg
	ldr	 r1, =debug_curr_breakpoint
	strb \reg, [r1]
	.endm

 /*@}*/

#endif /* __DEBUG_MACROS_H__ */