aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/xtensa/test_windowed.S
blob: 5ead90a790ed365a951e8f973183f3dc90b0f243 (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
#include "macros.inc"

test_suite windowed

#if XCHAL_HAVE_WINDOWED

.altmacro

.macro reset_window start
    movi    a2, 0xffff
    wsr     a2, windowstart
    rsync
    movi    a2, 0
    wsr     a2, windowbase
    rsync
    movi    a2, \start
    wsr     a2, windowstart
    rsync
.endm

.macro overflow_test shift, window, probe_ok, probe_ex
    set_vector window_overflow_4, 0
    set_vector window_overflow_8, 0
    set_vector window_overflow_12, 0

    movi    a2, 1 | (((1 << ((\window) / 4)) | 1) << ((\shift) / 4))
    wsr     a2, windowstart
    reset_ps

    mov     a2, a\probe_ok
    set_vector window_overflow_\window, 10f
1:
    mov     a2, a\probe_ex
    test_fail
10:
    rsr     a2, epc1
    movi    a3, 1b
    assert  eq, a2, a3
    movi    a2, 2f
    wsr     a2, epc1

    rsr     a2, windowbase
    movi    a3, (\shift) / 4
    assert  eq, a2, a3
    rsr     a2, ps
    movi    a3, 0x4001f
    assert  eq, a2, a3
    rfwo
    test_fail
2:
    rsr     a2, windowbase
    assert  eqi, a2, 0
    rsr     a2, windowstart
    movi    a3, 1 | ((1 << ((\window) / 4)) << ((\shift) / 4))
    assert  eq, a2, a3
    rsr     a2, ps
    movi    a3, 0x4000f
    assert  eq, a2, a3
.endm

.macro overflow_tests shift, window, probe
    .if \probe < 15
    overflow_test \shift, \window, %((\shift) - 1), \probe
    overflow_tests \shift, \window, %((\probe) + 1)
    .endif
.endm

.macro all_overflow_tests
    .irp shift, 4, 8, 12
    .irp window, 4, 8, 12
    overflow_tests \shift, \window, \shift
    .endr
    .endr
.endm

test overflow
    all_overflow_tests
test_end


.macro underflow_test window
    set_vector window_underflow_4, 0
    set_vector window_underflow_8, 0
    set_vector window_underflow_12, 0

    set_vector window_underflow_\window, 10f

    reset_window 1
    reset_ps

    ssai    2
    movi    a2, 2f
    slli    a2, a2, 2
    movi    a3, (\window) / 4
    src     a0, a3, a2
1:
    retw
    test_fail
10:
    rsr     a2, epc1
    movi    a3, 1b
    assert  eq, a2, a3
    movi    a2, 2f
    wsr     a2, epc1

    rsr     a2, ps
    movi    a3, 0x4001f
    assert  eq, a2, a3
    rsr     a2, windowbase
    movi    a3, (XCHAL_NUM_AREGS - (\window)) / 4
    assert  eq, a2, a3
    rsr     a2, windowstart
    assert  eqi, a2, 1
    rfwu
2:
    rsr     a2, ps
    movi    a3, 0x4000f
    assert  eq, a2, a3
    rsr     a2, windowbase
    assert  eqi, a2, 0
    rsr     a2, windowstart
    assert  bsi.l, a2, 0
    assert  bsi.l, a2, (XCHAL_NUM_AREGS - (\window)) / 4
.endm

test underflow
    set_vector window_overflow_4, 0
    set_vector window_overflow_8, 0
    set_vector window_overflow_12, 0

    underflow_test 4
    underflow_test 8
    underflow_test 12
test_end


.macro retw_test window
    reset_window %(1 | (1 << ((XCHAL_NUM_AREGS - \window) / 4)))
    reset_ps

    ssai    2
    movi    a2, 1f
    slli    a2, a2, 2
    movi    a3, (\window) / 4
    src     a0, a3, a2
    retw
    test_fail
1:
    rsr     a2, ps
    movi    a3, 0x4000f
    assert  eq, a2, a3
    rsr     a2, windowbase
    movi    a3, (XCHAL_NUM_AREGS - (\window)) / 4
    assert  eq, a2, a3
    rsr     a2, windowstart
    assert  bci.l, a2, 0
    assert  bsi.l, a2, (XCHAL_NUM_AREGS - (\window)) / 4
.endm

test retw
    set_vector window_underflow_4, 0
    set_vector window_underflow_8, 0
    set_vector window_underflow_12, 0

    retw_test 4
    retw_test 8
    retw_test 12
test_end

test movsp
    set_vector kernel, 2f

    reset_window 1
    reset_ps
1:
    movsp   a2, a3
    test_fail
2:
    rsr     a2, exccause
    assert  eqi, a2, 5
    rsr     a2, epc1
    movi    a3, 1b
    assert  eq, a2, a3

    set_vector kernel, 0

    reset_window %(0x1 | (1 << ((XCHAL_NUM_AREGS / 4) - 1)))
    reset_ps

    movsp   a2, a3
test_end

test rotw
    reset_window 0x4b
    reset_ps

    movi    a3, 0x10

    rotw    1
    rsr     a2, windowbase
    assert  eqi, a2, 1
    movi    a3, 0x11
    movi    a7, 0x12

    rotw    2
    rsr     a2, windowbase
    assert  eqi, a2, 3
    movi    a3, 0x13
    movi    a7, 0x14
    movi    a11, 0x15

    rotw    3
    rsr     a2, windowbase
    assert  eqi, a2, 6
    movi    a3, 0x16
    movi    a7, 0x17

#if XCHAL_NUM_AREGS == 32
    movi    a2, 0x44
    wsr     a2, windowstart
#elif XCHAL_NUM_AREGS == 64
    movi    a2, 0x4004
    wsr     a2, windowstart
    rotw    -8
#else
#error XCHAL_NUM_AREGS unsupported
#endif
    rsync

    movi    a2, 0x10
    assert  eq, a2, a11
    movi    a11, 0x18
    movi    a2, 0x11
    assert  eq, a2, a15
    movi    a15, 0x19

    rotw    4
    movi    a2, 0x12
    assert  eq, a2, a3
    movi    a2, 0x13
    assert  eq, a2, a7
    movi    a2, 0x14
    assert  eq, a2, a11
    movi    a2, 0x15
    assert  eq, a2, a15

    movi    a2, 0x5
    wsr     a2, windowstart
    rsync

    rotw    -2
    movi    a2, 0x18
    assert  eq, a2, a3
    movi    a2, 0x19
    assert  eq, a2, a7
test_end

.macro callw_test window
    call\window 2f
1:
    test_fail
    .align  4
2:
    rsr     a2, windowbase
    assert  eqi, a2, 0
    rsr     a2, ps
    movi    a3, 0x4000f | ((\window) << 14)
    assert  eq, a2, a3
    movi    a2, 1b
    slli    a2, a2, 2
    ssai    2
    movi    a3, (\window) / 4
    src     a2, a3, a2
    assert  eq, a2, a\window
.endm

test callw
    reset_window 0x1
    reset_ps

    callw_test 4
    callw_test 8
    callw_test 12
test_end


.macro entry_test window
    reset_window 0x1
    reset_ps
    movi    a2, 0x4000f | ((\window) << 14)
    wsr     a2, ps
    isync
    movi    a3, 0x12345678
    j       1f
    .align  4
1:
    entry   a3, 0x5678
    movi    a2, 0x12340000
    assert  eq, a2, a3
    rsr     a2, windowbase
    assert  eqi, a2, (\window) / 4
    rsr     a2, windowstart
    movi    a3, 1 | (1 << ((\window) / 4))
    assert  eq, a2, a3
    rotw    -(\window) / 4
.endm

test entry
    entry_test 4
    entry_test 8
    entry_test 12
test_end

.macro entry_overflow_test window, free, next_window
    set_vector window_overflow_4, 0
    set_vector window_overflow_8, 0
    set_vector window_overflow_12, 0
    set_vector window_overflow_\next_window, 10f

    movi    a2, \window
    movi    a2, \free
    movi    a2, \next_window
    reset_window %(1 | ((1 | (1 << ((\next_window) / 4))) << ((\free) / 4)))
    reset_ps
    movi    a2, 0x4000f | ((\window) << 14)
    wsr     a2, ps
    isync
    movi    a3, 0x12345678
    j       1f
    .align  4
1:
    entry   a3, 0x5678
    test_fail
    .align  4
10:
    rsr     a2, epc1
    movi    a3, 1b
    assert  eq, a2, a3
    movi    a2, 2f
    wsr     a2, epc1

    rsr     a2, windowbase
    movi    a3, (\free) / 4
    assert  eq, a2, a3
    rfwo
2:
.endm

.macro all_entry_overflow_tests
    .irp window, 4, 8, 12
    .irp next_window, 4, 8, 12
    .irp free, 4, 8, 12
    .if \free <= \window
    entry_overflow_test \window, \free, \next_window
    .endif
    .endr
    .endr
    .endr
.endm

test entry_overflow
    all_entry_overflow_tests
test_end

#endif

test_suite_end