summaryrefslogtreecommitdiff
path: root/sim/testsuite/sim/fr30/testutils.inc
blob: 7523d6f6aa5f6717c2786877dfc9dc5199882141 (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
# r0, r4-r6 are used as tmps, consider them call clobbered by these macros.

	.macro start
	.data
failmsg:
	.ascii "fail\n"
passmsg:
	.ascii "pass\n"
	.text
	.global _start
_start:
	ldi32 0x7fffc,sp	; TODO -- what's a good value for this?
	ldi32 0xffc00,r0
	mov   r0,tbr		; defined in manual
	mov   sp,usp
	mov   sp,ssp
	.endm

; Exit with return code
	.macro exit rc
	ldi32 \rc,r4
	ldi32 #1,r0
	int   #10
	.endm

; Pass the test case
	.macro pass
	ldi32 #5,r6
	ldi32 #passmsg,r5
	ldi32 #1,r4
	ldi32 #5,r0
	int   #10
	exit  #0
	.endm

; Fail the testcase
	.macro fail
	ldi32 #5,r6
	ldi32 #failmsg,r5
	ldi32 #1,r4
	ldi32 #5,r0
	int   #10
	exit  #1
	.endm

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

; Load an immediate value into a dedicated register
	.macro mvi_h_dr val reg
	ldi32 \val,r0
	mov r0,\reg
	.endm

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

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

; Store a register into a word in memory
	.macro mvr_h_mem reg addr
	st \reg,@\addr
	.endm

; Store the current ps on the stack
	.macro save_ps
	st ps,@-r15
	.endm

; Load a word value from memory
	.macro ldmem_h_gr addr reg
	ld @\addr,\reg
	.endm

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

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

; Test the value of an immediate against a general register
	.macro test_h_gr val reg
	.if (\val >= 0) && (\val <= 15)
	cmp \val,\reg
	.else
	.if (\val < 0) && (\val >= -16)
	cmp2 \val,\reg
	.else
	ldi32 \val,r4
	cmp r4,\reg
	.endif
	.endif
	beq test_gr\@
	fail
test_gr\@:
	.endm

; compare two general registers
	.macro testr_h_gr reg1 reg2
	cmp \reg1,\reg2
	beq testr_gr\@
	fail
testr_gr\@:
	.endm

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

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

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

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

; Set the condition codes
	.macro set_cc mask
	andccr	0xf0
	orccr	\mask
	.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,r0
	mvi_h_gr 0x20,r4
	and      r4,r0
	test_h_gr 0x20,r0
	.endm

	.macro test_s_system
	mvr_h_gr ps,r0
	mvi_h_gr 0x20,r4
	and      r4,r0
	test_h_gr 0x0,r0
	.endm

; Set the interrupt bit
	.macro set_i val
	.if (\val == 1)
	orccr	0x10
	.else
	andccr	0x2f
	.endif
	.endm

; Test the stack mode
	.macro test_i val
	mvr_h_gr  ps,r0
	mvi_h_gr  0x10,r4
	and       r4,r0
	.if (\val == 1)
	test_h_gr 0x10,r0
	.else
	test_h_gr 0x0,r0
	.endif
	.endm

; Set the ilm
	.macro set_ilm val
	stilm \val
	.endm

; Test the ilm
	.macro test_ilm val
	mvr_h_gr   ps,r0
	mvi_h_gr   0x1f0000,r4
	and        r4,r0
	mvi_h_gr   \val,r5
	mvi_h_gr   0x1f,r4
	and	   r4,r5
	lsl        15,r5
	lsl        1,r5
	testr_h_gr r0,r5
	.endm

; Test the condition codes
	.macro test_cc N Z V C
	.if (\N == 1)
	bp fail\@
	.else
	bn fail\@
	.endif
	.if (\Z == 1)
	bne fail\@
	.else
	beq fail\@
	.endif
	.if (\V == 1)
	bnv fail\@
	.else
	bv fail\@
	.endif
	.if (\C == 1)
	bnc fail\@
	.else
	bc fail\@
	.endif
	bra test_cc\@
fail\@:
	fail
test_cc\@:
	.endm

; Set the division bits
	.macro set_dbits val
	mvr_h_gr ps,r5
	mvi_h_gr 0xfffff8ff,r4
	and r4,r5
	mvi_h_gr \val,r0
	mvi_h_gr 3,r4
	and r4,r0
	lsl 9,r0
	or r0,r5
	mvr_h_gr r5,ps
	.endm

; Test the division bits
	.macro test_dbits val
	mvr_h_gr ps,r0
	lsr 9,r0
	mvi_h_gr 3,r4
	and r4,r0
	test_h_gr \val,r0
	.endm

; Save the return pointer
	.macro save_rp
	st rp,@-R15
	.ENDM

; restore the return pointer
	.macro restore_rp
	ld @R15+,rp
	.endm

; Ensure branch taken
	.macro take_branch opcode
	\opcode take_br\@
	fail
take_br\@:
	.endm

	.macro take_branch_d opcode val
	\opcode take_brd\@
	ldi:8 \val,r0
	fail
take_brd\@:
	test_h_gr \val,r0
	.endm

; Ensure branch not taken
	.macro no_branch opcode
	\opcode no_brf\@
	bra	no_brs\@
no_brf\@:
	fail
no_brs\@:
	.endm

	.macro no_branch_d opcode val
	\opcode no_brdf\@
	ldi:8   \val,r0
	bra	no_brds\@
no_brdf\@:
	fail
no_brds\@:
	test_h_gr \val,r0
	.endm