xref: /openbmc/qemu/tests/tcg/xtensa/test_windowed.S (revision 4a09d0bb)
1#include "macros.inc"
2
3test_suite windowed
4
5.altmacro
6
7.macro reset_window start
8    movi    a2, 0xff
9    wsr     a2, windowstart
10    rsync
11    movi    a2, 0
12    wsr     a2, windowbase
13    rsync
14    movi    a2, \start
15    wsr     a2, windowstart
16    rsync
17.endm
18
19.macro overflow_test shift, window, probe_ok, probe_ex
20    set_vector window_overflow_4, 0
21    set_vector window_overflow_8, 0
22    set_vector window_overflow_12, 0
23
24    movi    a2, 1 | (((1 << ((\window) / 4)) | 1) << ((\shift) / 4))
25    wsr     a2, windowstart
26    reset_ps
27
28    mov     a2, a\probe_ok
29    set_vector window_overflow_\window, 10f
301:
31    mov     a2, a\probe_ex
32    test_fail
3310:
34    rsr     a2, epc1
35    movi    a3, 1b
36    assert  eq, a2, a3
37    movi    a2, 2f
38    wsr     a2, epc1
39
40    rsr     a2, windowbase
41    movi    a3, (\shift) / 4
42    assert  eq, a2, a3
43    rsr     a2, ps
44    movi    a3, 0x4001f
45    assert  eq, a2, a3
46    rfwo
47    test_fail
482:
49    rsr     a2, windowbase
50    assert  eqi, a2, 0
51    rsr     a2, windowstart
52    movi    a3, 1 | ((1 << ((\window) / 4)) << ((\shift) / 4))
53    assert  eq, a2, a3
54    rsr     a2, ps
55    movi    a3, 0x4000f
56    assert  eq, a2, a3
57.endm
58
59.macro overflow_tests shift, window, probe
60    .if \probe < 15
61    overflow_test \shift, \window, %((\shift) - 1), \probe
62    overflow_tests \shift, \window, %((\probe) + 1)
63    .endif
64.endm
65
66.macro all_overflow_tests
67    .irp shift, 4, 8, 12
68    .irp window, 4, 8, 12
69    overflow_tests \shift, \window, \shift
70    .endr
71    .endr
72.endm
73
74test overflow
75    all_overflow_tests
76test_end
77
78
79.macro underflow_test window
80    set_vector window_underflow_4, 0
81    set_vector window_underflow_8, 0
82    set_vector window_underflow_12, 0
83
84    set_vector window_underflow_\window, 10f
85
86    reset_window 1
87    reset_ps
88
89    ssai    2
90    movi    a2, 2f
91    slli    a2, a2, 2
92    movi    a3, (\window) / 4
93    src     a0, a3, a2
941:
95    retw
96    test_fail
9710:
98    rsr     a2, epc1
99    movi    a3, 1b
100    assert  eq, a2, a3
101    movi    a2, 2f
102    wsr     a2, epc1
103
104    rsr     a2, ps
105    movi    a3, 0x4001f
106    assert  eq, a2, a3
107    rsr     a2, windowbase
108    assert  eqi, a2, 8 - ((\window) / 4)
109    rsr     a2, windowstart
110    assert  eqi, a2, 1
111    rfwu
1122:
113    rsr     a2, ps
114    movi    a3, 0x4000f
115    assert  eq, a2, a3
116    rsr     a2, windowbase
117    assert  eqi, a2, 0
118    rsr     a2, windowstart
119    assert  bsi, a2, 0
120    assert  bsi, a2, 8 - ((\window) / 4)
121.endm
122
123test underflow
124    set_vector window_overflow_4, 0
125    set_vector window_overflow_8, 0
126    set_vector window_overflow_12, 0
127
128    underflow_test 4
129    underflow_test 8
130    underflow_test 12
131test_end
132
133
134.macro retw_test window
135    reset_window %(1 | (1 << (8 - (\window) / 4)))
136    reset_ps
137
138    ssai    2
139    movi    a2, 1f
140    slli    a2, a2, 2
141    movi    a3, (\window) / 4
142    src     a0, a3, a2
143    retw
144    test_fail
1451:
146    rsr     a2, ps
147    movi    a3, 0x4000f
148    assert  eq, a2, a3
149    rsr     a2, windowbase
150    assert  eqi, a2, 8 - ((\window) / 4)
151    rsr     a2, windowstart
152    assert  bci, a2, 0
153    assert  bsi, a2, 8 - ((\window) / 4)
154.endm
155
156test retw
157    set_vector window_underflow_4, 0
158    set_vector window_underflow_8, 0
159    set_vector window_underflow_12, 0
160
161    retw_test 4
162    retw_test 8
163    retw_test 12
164test_end
165
166test movsp
167    set_vector kernel, 2f
168
169    reset_window 1
170    reset_ps
1711:
172    movsp   a2, a3
173    test_fail
1742:
175    rsr     a2, exccause
176    assert  eqi, a2, 5
177    rsr     a2, epc1
178    movi    a3, 1b
179    assert  eq, a2, a3
180
181    set_vector kernel, 0
182
183    reset_window 0x81
184    reset_ps
185
186    movsp   a2, a3
187test_end
188
189test rotw
190    reset_window 0x4b
191    reset_ps
192
193    movi    a3, 0x10
194
195    rotw    1
196    rsr     a2, windowbase
197    assert  eqi, a2, 1
198    movi    a3, 0x11
199    movi    a7, 0x12
200
201    rotw    2
202    rsr     a2, windowbase
203    assert  eqi, a2, 3
204    movi    a3, 0x13
205    movi    a7, 0x14
206    movi    a11, 0x15
207
208    rotw    3
209    rsr     a2, windowbase
210    assert  eqi, a2, 6
211    movi    a3, 0x16
212    movi    a7, 0x17
213
214    movi    a2, 0x44
215    wsr     a2, windowstart
216    rsync
217
218    movi    a2, 0x10
219    assert  eq, a2, a11
220    movi    a11, 0x18
221    movi    a2, 0x11
222    assert  eq, a2, a15
223    movi    a15, 0x19
224
225    rotw    4
226    movi    a2, 0x12
227    assert  eq, a2, a3
228    movi    a2, 0x13
229    assert  eq, a2, a7
230    movi    a2, 0x14
231    assert  eq, a2, a11
232    movi    a2, 0x15
233    assert  eq, a2, a15
234
235    movi    a2, 0x5
236    wsr     a2, windowstart
237    rsync
238
239    rotw    -2
240    movi    a2, 0x18
241    assert  eq, a2, a3
242    movi    a2, 0x19
243    assert  eq, a2, a7
244test_end
245
246.macro callw_test window
247    call\window 2f
2481:
249    test_fail
250    .align  4
2512:
252    rsr     a2, windowbase
253    assert  eqi, a2, 0
254    rsr     a2, ps
255    movi    a3, 0x4000f | ((\window) << 14)
256    assert  eq, a2, a3
257    movi    a2, 1b
258    slli    a2, a2, 2
259    ssai    2
260    movi    a3, (\window) / 4
261    src     a2, a3, a2
262    assert  eq, a2, a\window
263.endm
264
265test callw
266    reset_window 0x1
267    reset_ps
268
269    callw_test 4
270    callw_test 8
271    callw_test 12
272test_end
273
274
275.macro entry_test window
276    reset_window 0x1
277    reset_ps
278    movi    a2, 0x4000f | ((\window) << 14)
279    wsr     a2, ps
280    isync
281    movi    a3, 0x12345678
282    j       1f
283    .align  4
2841:
285    entry   a3, 0x5678
286    movi    a2, 0x12340000
287    assert  eq, a2, a3
288    rsr     a2, windowbase
289    assert  eqi, a2, (\window) / 4
290    rsr     a2, windowstart
291    movi    a3, 1 | (1 << ((\window) / 4))
292    assert  eq, a2, a3
293    rotw    -(\window) / 4
294.endm
295
296test entry
297    entry_test 4
298    entry_test 8
299    entry_test 12
300test_end
301
302.macro entry_overflow_test window, free, next_window
303    set_vector window_overflow_4, 0
304    set_vector window_overflow_8, 0
305    set_vector window_overflow_12, 0
306    set_vector window_overflow_\next_window, 10f
307
308    movi    a2, \window
309    movi    a2, \free
310    movi    a2, \next_window
311    reset_window %(1 | ((1 | (1 << ((\next_window) / 4))) << ((\free) / 4)))
312    reset_ps
313    movi    a2, 0x4000f | ((\window) << 14)
314    wsr     a2, ps
315    isync
316    movi    a3, 0x12345678
317    j       1f
318    .align  4
3191:
320    entry   a3, 0x5678
321    test_fail
322    .align  4
32310:
324    rsr     a2, epc1
325    movi    a3, 1b
326    assert  eq, a2, a3
327    movi    a2, 2f
328    wsr     a2, epc1
329
330    rsr     a2, windowbase
331    movi    a3, (\free) / 4
332    assert  eq, a2, a3
333    rfwo
3342:
335.endm
336
337.macro all_entry_overflow_tests
338    .irp window, 4, 8, 12
339    .irp next_window, 4, 8, 12
340    .irp free, 4, 8, 12
341    .if \free <= \window
342    entry_overflow_test \window, \free, \next_window
343    .endif
344    .endr
345    .endr
346    .endr
347.endm
348
349test entry_overflow
350    all_entry_overflow_tests
351test_end
352
353test_suite_end
354