File: testutils.inc

package info (click to toggle)
gdb-doc 16.3-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 244,264 kB
  • sloc: ansic: 2,134,731; asm: 375,582; exp: 206,875; cpp: 73,639; makefile: 70,232; sh: 26,038; python: 13,697; yacc: 11,341; ada: 7,358; xml: 6,098; perl: 5,077; pascal: 3,389; tcl: 2,986; f90: 2,764; lisp: 1,984; cs: 879; lex: 738; sed: 228; awk: 181; objc: 137; fortran: 57
file content (361 lines) | stat: -rw-r--r-- 5,472 bytes parent folder | download | duplicates (35)
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
; Copied from fr30 and modified.
; r9, r11-r13 are used as tmps, consider them call clobbered by these macros.
;
; Do not use the macro counter \@ in macros, there's a bug in
; gas 2.9.1 when it is also a line-separator.
;

	; Don't require the $-prefix on registers.
	.syntax no_register_prefix

	.macro startnostack
	.data
	.space 64,0 ; Simple stack
stackhi:
failmsg:
	.ascii "fail\n"
passmsg:
	.ascii "pass\n"
	.text
	break 11
	.global _start
_start:
	.endm

	.macro start
	startnostack
	move.d stackhi,sp
	.endm

; Exit with return code
	.macro exit rc
	move.d \rc,r10
	moveq 1,r9	; == __NR_exit
	break 13
	break 15
	.endm

; Pass the test case
	.macro pass
	moveq 5,r12
	move.d passmsg,r11
	move.d 1,r10
	moveq 4,r9	; == __NR_write
	break 13
	exit 0
	.endm

; Fail the testcase
	.macro fail
;	moveq 5,r12
;	move.d failmsg,r11
;	move.d 1,r10
;	moveq 4,r1
;	break 13
;	exit 1
	break 15
	.endm

	.macro quit
	break 15
	.endm

	.macro dumpr3
	break 14
	.endm

; Load an immediate value into a general register
; TODO: use minimal sized insn
	.macro mvi_h_gr val reg
	move.d \val,\reg
	.endm

; Load an immediate value into a dedicated register
	.macro mvi_h_dr val reg
	move.d \val,r9
	move.d r9,\reg
	.endm

; Load a general register into another general register
	.macro mvr_h_gr src targ
	move.d \src,\targ
	.endm

; Store an immediate into a word in memory
	.macro mvi_h_mem val addr
	mvi_h_gr  \val r11
	mvr_h_mem r11,\addr
	.endm

; Store a register into a word in memory
	.macro mvr_h_mem reg addr
	move.d \addr,$r13
	move.d \reg,[$r13]
	.endm

; Store the current ps on the stack
	.macro save_ps
	.if ..asm.arch.cris.v32
	move ccs,acr ; Push will do a "subq" first.
	push acr
	.else
	push dccr
	.endif
	.endm

; Load a word value from memory
	.macro ldmem_h_gr addr reg
	move.d \addr,$r13
	move.d [$r13],\reg
	.endm

; Add 2 general registers
	.macro add_h_gr reg1 reg2
	add.d \reg1,\reg2
	.endm

; Increment a register by and immediate
	.macro inci_h_gr inc reg
	mvi_h_gr \inc,r11
	add.d r11,\reg
	.endm

; Test the value of an immediate against a general register
	.macro test_h_gr val reg
	cmp.d \val,\reg
	beq 9f
	nop
	fail
9:
	.endm

; compare two general registers
	.macro testr_h_gr reg1 reg2
	cmp.d \reg1,\reg2
	beq 9f
	fail
9:
	.endm

; Test the value of an immediate against a dedicated register
	.macro test_h_dr val reg
	move \reg,$r12
	test_h_gr \val $r12
	.endm

; Test the value of an general register against a dedicated register
	.macro testr_h_dr gr dr
	move \dr,$r12
	testr_h_gr \gr $r12
	.endm

; Compare an immediate with word in memory
	.macro test_h_mem val addr
	ldmem_h_gr \addr $r12
	test_h_gr \val $r12
	.endm

; Compare a general register with word in memory
	.macro testr_h_mem reg addr
	ldmem_h_gr \addr r12
	testr_h_gr \reg r12
	.endm

; Set the condition codes
; The lower bits of the mask *are* nzvc, so we don't
; have to do anything strange.
	.macro set_cc mask
	move.w \mask,r13
	.if ..asm.arch.cris.v32
	move r13,ccs
	.else
	move r13,ccr
	.endif
	.endm

; Set the stack mode
;	 .macro set_s_user
;	 orccr	0x20
;	 .endm
;
;	 .macro set_s_system
;	 andccr	0x1f
;	 .endm
;
;; Test the stack mode
;	 .macro test_s_user
;	 mvr_h_gr ps,r9
;	 mvi_h_gr 0x20,r11
;	 and	  r11,r9
;	 test_h_gr 0x20,r9
;	 .endm
;
;	 .macro test_s_system
;	 mvr_h_gr ps,r9
;	 mvi_h_gr 0x20,r11
;	 and	  r11,r9
;	 test_h_gr 0x0,r9
;	 .endm

; Set the interrupt bit
; ??? Do they mean "enable interrupts" or "disable interrupts"?
; Assuming enable here.
	.macro set_i val
	.if (\val == 1)
	ei
	.else
	di
	.endif
	.endm

; Test the stack mode
;	 .macro test_i val
;	 mvr_h_gr  ps,r9
;	 mvi_h_gr  0x10,r11
;	 and	   r11,r9
;	 .if (\val == 1)
;	 test_h_gr 0x10,r9
;	 .else
;	 test_h_gr 0x0,r9
;	 .endif
;	 .endm
;
;; Set the ilm
;	 .macro set_ilm val
;	 stilm \val
;	 .endm
;
;; Test the ilm
;	 .macro test_ilm val
;	 mvr_h_gr   ps,r9
;	 mvi_h_gr   0x1f0000,r11
;	 and	    r11,r9
;	 mvi_h_gr   \val,r12
;	 mvi_h_gr   0x1f,r11
;	 and	   r11,r12
;	 lsl	    15,r12
;	 lsl	    1,r12
;	 testr_h_gr r9,r12
;	 .endm
;
; Test the condition codes
	.macro test_cc N Z V C
	.if \N
	bpl 9f
	nop
	.else
	bmi 9f
	nop
	.endif
	.if \Z
	bne 9f
	nop
	.else
	beq 9f
	nop
	.endif
	.if \V
	bvc 9f
	nop
	.else
	bvs 9f
	nop
	.endif
	.if \C
	bcc 9f
	nop
	.else
	bcs 9f
	nop
	.endif
	ba 8f
	nop
9:
	fail
8:
	.endm

	.macro test_move_cc N Z V C
	.if ..asm.arch.cris.v32
	; V and C aren't affected on v32, so to re-use the test-cases,
	; we fake them cleared.  There's a separate test, nonvcv32.ms
	; covering this omission.
	clearf vc
	test_cc \N \Z 0 0
	.else
	test_cc \N \Z \V \C
	.endif
	.endm

; Set the division bits
;	 .macro set_dbits val
;	 mvr_h_gr ps,r12
;	 mvi_h_gr 0xfffff8ff,r11
;	 and r11,r12
;	 mvi_h_gr \val,r9
;	 mvi_h_gr 3,r11
;	 and r11,r9
;	 lsl 9,r9
;	 or r9,r12
;	 mvr_h_gr r12,ps
;	 .endm
;
;; Test the division bits
;	 .macro test_dbits val
;	 mvr_h_gr ps,r9
;	 lsr 9,r9
;	 mvi_h_gr 3,r11
;	 and r11,r9
;	 test_h_gr \val,r9
;	 .endm
;
; Save the return pointer
	.macro save_rp
	push srp
	.ENDM

; restore the return pointer
	.macro restore_rp
	pop srp
	.endm

; Ensure branch taken
	.macro take_branch opcode
	\opcode 9f
	nop
	fail
9:
	.endm

	.macro take_branch_d opcode val
	\opcode 9f
	nop
	move.d \val,r9
	fail
9:
	test_h_gr \val,r9
	.endm

; Ensure branch not taken
	.macro no_branch opcode
	\opcode 9f
	nop
	ba	8f
	nop
9:
	fail
8:
	.endm

	.macro no_branch_d opcode val
	\opcode 9f
	move.d	 \val,r9
	nop
	ba	8f
	nop
9:
	fail
8:
	test_h_gr \val,r9
	.endm