]> git.proxmox.com Git - mirror_qemu.git/blob - tests/tcg/xtensa/test_mmu.S
099031fd14f419032de6cfc0dac4265ead0d91d9
[mirror_qemu.git] / tests / tcg / xtensa / test_mmu.S
1 #include "macros.inc"
2
3 test_suite mmu
4
5 .purgem test_init
6
7 .macro test_init
8 movi a2, 0x00000004
9 idtlb a2
10 movi a2, 0x00100004
11 idtlb a2
12 movi a2, 0x00200004
13 idtlb a2
14 movi a2, 0x00300004
15 idtlb a2
16 movi a2, 0x00000007
17 idtlb a2
18 .endm
19
20 test tlb_group
21 movi a2, 0x04000002 /* PPN */
22 movi a3, 0x01200004 /* VPN */
23 wdtlb a2, a3
24 witlb a2, a3
25 movi a3, 0x00200004
26 rdtlb0 a1, a3
27 ritlb0 a2, a3
28 movi a3, 0x01000001
29 assert eq, a1, a3
30 assert eq, a2, a3
31 movi a3, 0x00200004
32 rdtlb1 a1, a3
33 ritlb1 a2, a3
34 movi a3, 0x04000002
35 assert eq, a1, a3
36 assert eq, a2, a3
37 movi a3, 0x01234567
38 pdtlb a1, a3
39 pitlb a2, a3
40 movi a3, 0x01234014
41 assert eq, a1, a3
42 movi a3, 0x0123400c
43 assert eq, a2, a3
44 movi a3, 0x00200004
45 idtlb a3
46 iitlb a3
47 movi a3, 0x01234567
48 pdtlb a1, a3
49 pitlb a2, a3
50 movi a3, 0x00000010
51 and a1, a1, a3
52 assert eqi, a1, 0
53 movi a3, 0x00000008
54 and a2, a2, a3
55 assert eqi, a2, 0
56 test_end
57
58 test itlb_miss
59 set_vector kernel, 1f
60
61 movi a3, 0x00100000
62 jx a3
63 test_fail
64 1:
65 rsr a2, excvaddr
66 assert eq, a2, a3
67 rsr a2, exccause
68 movi a3, 16
69 assert eq, a2, a3
70 test_end
71
72 test dtlb_miss
73 set_vector kernel, 1f
74
75 movi a3, 0x00100000
76 l8ui a2, a3, 0
77 test_fail
78 1:
79 rsr a2, excvaddr
80 assert eq, a2, a3
81 rsr a2, exccause
82 movi a3, 24
83 assert eq, a2, a3
84 test_end
85
86 test itlb_multi_hit
87 set_vector kernel, 1f
88
89 movi a2, 0x04000002 /* PPN */
90 movi a3, 0xf0000004 /* VPN */
91 witlb a2, a3
92 movi a3, 0xf0000000
93 pitlb a2, a3
94 test_fail
95 1:
96 rsr a2, exccause
97 movi a3, 17
98 assert eq, a2, a3
99 test_end
100
101 test dtlb_multi_hit
102 set_vector kernel, 1f
103
104 movi a2, 0x04000002 /* PPN */
105 movi a3, 0x01200004 /* VPN */
106 wdtlb a2, a3
107 movi a3, 0x01200007 /* VPN */
108 wdtlb a2, a3
109 movi a3, 0x01200000
110 pdtlb a2, a3
111 test_fail
112 1:
113 rsr a2, exccause
114 movi a3, 25
115 assert eq, a2, a3
116 test_end
117
118 test inst_fetch_privilege
119 set_vector kernel, 3f
120
121 movi a2, 0x4004f
122 wsr a2, ps
123 1:
124 isync
125 nop
126 2:
127 test_fail
128 3:
129 movi a1, 1b
130 rsr a2, excvaddr
131 rsr a3, epc1
132 assert ge, a2, a1
133 assert ge, a3, a1
134 movi a1, 2b
135 assert lt, a2, a1
136 assert lt, a3, a1
137 rsr a2, exccause
138 movi a3, 18
139 assert eq, a2, a3
140 rsr a2, ps
141 movi a3, 0x4005f
142 assert eq, a2, a3
143 test_end
144
145 test load_store_privilege
146 set_vector kernel, 2f
147
148 movi a3, 10f
149 pitlb a3, a3
150 ritlb1 a2, a3
151 movi a1, 0x10
152 or a2, a2, a1
153 movi a1, 0x000ff000
154 and a3, a3, a1
155 movi a1, 4
156 or a3, a3, a1
157 witlb a2, a3
158 movi a3, 10f
159 movi a1, 0x000fffff
160 and a1, a3, a1
161
162 movi a2, 0x04000003 /* PPN */
163 movi a3, 0x01200004 /* VPN */
164 wdtlb a2, a3
165 movi a3, 0x01200001
166 movi a2, 0x4004f
167 jx a1
168 10:
169 wsr a2, ps
170 isync
171 1:
172 l8ui a2, a3, 0
173 test_fail
174 2:
175 rsr a2, excvaddr
176 assert eq, a2, a3
177 rsr a2, epc1
178 movi a3, 1b
179 movi a1, 0x000fffff
180 and a3, a3, a1
181 assert eq, a2, a3
182 rsr a2, exccause
183 movi a3, 26
184 assert eq, a2, a3
185 rsr a2, ps
186 movi a3, 0x4005f
187 assert eq, a2, a3
188 test_end
189
190 test cring_load_store_privilege
191 set_vector kernel, 0
192 set_vector double, 2f
193
194 movi a2, 0x04000003 /* PPN */
195 movi a3, 0x01200004 /* VPN */
196 wdtlb a2, a3
197 movi a3, 0x01200004
198 movi a2, 0x4005f /* ring 1 + excm => cring == 0 */
199 wsr a2, ps
200 isync
201 l8ui a2, a3, 0 /* cring used */
202 1:
203 l32e a2, a3, -4 /* ring used */
204 test_fail
205 2:
206 rsr a2, excvaddr
207 addi a2, a2, 4
208 assert eq, a2, a3
209 rsr a2, depc
210 movi a3, 1b
211 assert eq, a2, a3
212 rsr a2, exccause
213 movi a3, 26
214 assert eq, a2, a3
215 rsr a2, ps
216 movi a3, 0x4005f
217 assert eq, a2, a3
218 test_end
219
220 test inst_fetch_prohibited
221 set_vector kernel, 2f
222
223 movi a3, 10f
224 pitlb a3, a3
225 ritlb1 a2, a3
226 movi a1, 0xfffff000
227 and a2, a2, a1
228 movi a1, 0x4
229 or a2, a2, a1
230 movi a1, 0x000ff000
231 and a3, a3, a1
232 movi a1, 4
233 or a3, a3, a1
234 witlb a2, a3
235 movi a3, 10f
236 movi a1, 0x000fffff
237 and a1, a3, a1
238 jx a1
239 .align 4
240 10:
241 nop
242 test_fail
243 2:
244 rsr a2, excvaddr
245 assert eq, a2, a1
246 rsr a2, epc1
247 assert eq, a2, a1
248 rsr a2, exccause
249 movi a3, 20
250 assert eq, a2, a3
251 test_end
252
253 test load_prohibited
254 set_vector kernel, 2f
255
256 movi a2, 0x0400000c /* PPN */
257 movi a3, 0x01200004 /* VPN */
258 wdtlb a2, a3
259 movi a3, 0x01200002
260 1:
261 l8ui a2, a3, 0
262 test_fail
263 2:
264 rsr a2, excvaddr
265 assert eq, a2, a3
266 rsr a2, epc1
267 movi a3, 1b
268 assert eq, a2, a3
269 rsr a2, exccause
270 movi a3, 28
271 assert eq, a2, a3
272 test_end
273
274 test store_prohibited
275 set_vector kernel, 2f
276
277 movi a2, 0x04000001 /* PPN */
278 movi a3, 0x01200004 /* VPN */
279 wdtlb a2, a3
280 movi a3, 0x01200003
281 l8ui a2, a3, 0
282 1:
283 s8i a2, a3, 0
284 test_fail
285 2:
286 rsr a2, excvaddr
287 assert eq, a2, a3
288 rsr a2, epc1
289 movi a3, 1b
290 assert eq, a2, a3
291 rsr a2, exccause
292 movi a3, 29
293 assert eq, a2, a3
294 test_end
295
296 /* Set up page table entry vaddr->paddr, ring=pte_ring, attr=pte_attr
297 * and DTLB way 7 to cover this PTE, ring=pt_ring, attr=pt_attr
298 */
299 .macro pt_setup pt_ring, pt_attr, pte_ring, vaddr, paddr, pte_attr
300 movi a2, 0x80000000
301 wsr a2, ptevaddr
302
303 movi a3, 0x80000007 | (((\vaddr) >> 10) & 0xfffff000) /* way 7 */
304 movi a4, 0x04000003 | ((\pt_ring) << 4) /* PADDR 64M */
305 wdtlb a4, a3
306 isync
307
308 movi a3, ((\paddr) & 0xfffff000) | ((\pte_ring) << 4) | (\pte_attr)
309 movi a1, ((\vaddr) >> 12) << 2
310 add a2, a1, a2
311 s32i a3, a2, 0
312
313 movi a3, 0x80000007 | (((\vaddr) >> 10) & 0xfffff000) /* way 7 */
314 movi a4, 0x04000000 | ((\pt_ring) << 4) | (\pt_attr) /* PADDR 64M */
315 wdtlb a4, a3
316 isync
317
318 movi a3, (\vaddr)
319 .endm
320
321 /* out: PS.RING=ring, PS.EXCM=excm, a3=vaddr */
322 .macro go_ring ring, excm, vaddr
323 movi a3, 10f
324 pitlb a3, a3
325 ritlb1 a2, a3
326 movi a1, 0x10
327 or a2, a2, a1
328 movi a1, 0x000ff000
329 and a3, a3, a1
330 movi a1, 4
331 or a3, a3, a1
332 witlb a2, a3
333 movi a3, 10f
334 movi a1, 0x000fffff
335 and a1, a3, a1
336
337 movi a2, 0
338 wsr a2, excvaddr
339
340 movi a3, \vaddr
341 movi a2, 0x4000f | ((\ring) << 6) | ((\excm) << 4)
342 jx a1
343 10:
344 wsr a2, ps
345 isync
346 .endm
347
348 /* in: a3 -- virtual address to test */
349 .macro assert_auto_tlb
350 movi a2, 0x4000f
351 wsr a2, ps
352 isync
353 pdtlb a2, a3
354 movi a1, 0xfffff01f
355 and a2, a2, a1
356 movi a1, 0xfffff000
357 and a1, a1, a3
358 xor a1, a1, a2
359 assert gei, a1, 0x10
360 movi a2, 0x14
361 assert lt, a1, a2
362 .endm
363
364 /* in: a3 -- virtual address to test */
365 .macro assert_no_auto_tlb
366 movi a2, 0x4000f
367 wsr a2, ps
368 isync
369 pdtlb a2, a3
370 movi a1, 0x10
371 and a1, a1, a2
372 assert eqi, a1, 0
373 .endm
374
375 .macro assert_sr sr, v
376 rsr a2, \sr
377 movi a1, (\v)
378 assert eq, a1, a2
379 .endm
380
381 .macro assert_epc1_1m vaddr
382 movi a2, (\vaddr)
383 movi a1, 0xfffff
384 and a1, a1, a2
385 rsr a2, epc1
386 assert eq, a1, a2
387 .endm
388
389 test dtlb_autoload
390 set_vector kernel, 0
391
392 pt_setup 0, 3, 1, 0x1000, 0x1000, 3
393 assert_no_auto_tlb
394
395 l8ui a1, a3, 0
396
397 rsr a2, excvaddr
398 assert eq, a2, a3
399
400 assert_auto_tlb
401 test_end
402
403 test autoload_load_store_privilege
404 set_vector kernel, 0
405 set_vector double, 2f
406
407 pt_setup 0, 3, 0, 0x2000, 0x2000, 3
408 movi a3, 0x2004
409 assert_no_auto_tlb
410
411 movi a2, 0x4005f /* ring 1 + excm => cring == 0 */
412 wsr a2, ps
413 isync
414 1:
415 l32e a2, a3, -4 /* ring used */
416 test_fail
417 2:
418 rsr a2, excvaddr
419 addi a1, a3, -4
420 assert eq, a1, a2
421
422 assert_auto_tlb
423 assert_sr depc, 1b
424 assert_sr exccause, 26
425 test_end
426
427 test autoload_pte_load_prohibited
428 set_vector kernel, 2f
429
430 pt_setup 0, 3, 0, 0x3000, 0, 0xc
431 assert_no_auto_tlb
432 1:
433 l32i a2, a3, 0
434 test_fail
435 2:
436 rsr a2, excvaddr
437 assert eq, a2, a3
438
439 assert_auto_tlb
440 assert_sr epc1, 1b
441 assert_sr exccause, 28
442 test_end
443
444 test autoload_pt_load_prohibited
445 set_vector kernel, 2f
446
447 pt_setup 0, 0xc, 0, 0x4000, 0x4000, 3
448 assert_no_auto_tlb
449 1:
450 l32i a2, a3, 0
451 test_fail
452 2:
453 rsr a2, excvaddr
454 assert eq, a2, a3
455
456 assert_no_auto_tlb
457 assert_sr epc1, 1b
458 assert_sr exccause, 24
459 test_end
460
461 test autoload_pt_privilege
462 set_vector kernel, 2f
463 pt_setup 0, 3, 1, 0x5000, 0, 3
464 go_ring 1, 0, 0x5001
465
466 l8ui a2, a3, 0
467 1:
468 syscall
469 2:
470 rsr a2, excvaddr
471 assert eq, a2, a3
472
473 assert_auto_tlb
474 assert_epc1_1m 1b
475 assert_sr exccause, 1
476 test_end
477
478 test autoload_pte_privilege
479 set_vector kernel, 2f
480 pt_setup 0, 3, 0, 0x6000, 0, 3
481 go_ring 1, 0, 0x6001
482 1:
483 l8ui a2, a3, 0
484 syscall
485 2:
486 rsr a2, excvaddr
487 assert eq, a2, a3
488
489 assert_auto_tlb
490 assert_epc1_1m 1b
491 assert_sr exccause, 26
492 test_end
493
494 test autoload_3_level_pt
495 set_vector kernel, 2f
496 pt_setup 1, 3, 1, 0x00400000, 0, 3
497 pt_setup 1, 3, 1, 0x80001000, 0x2000000, 3
498 go_ring 1, 0, 0x00400001
499 1:
500 l8ui a2, a3, 0
501 syscall
502 2:
503 rsr a2, excvaddr
504 assert eq, a2, a3
505
506 assert_no_auto_tlb
507 assert_epc1_1m 1b
508 assert_sr exccause, 24
509 test_end
510
511 test_suite_end