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