Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / powerpc / lib / test_emulate_step.c
blob783d1b85ecfe3fd7055d3d2323004e3d99dcbb59
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Simple sanity tests for instruction emulation infrastructure.
5 * Copyright IBM Corp. 2016
6 */
8 #define pr_fmt(fmt) "emulate_step_test: " fmt
10 #include <linux/ptrace.h>
11 #include <asm/cpu_has_feature.h>
12 #include <asm/sstep.h>
13 #include <asm/ppc-opcode.h>
14 #include <asm/code-patching.h>
15 #include <asm/inst.h>
17 #define MAX_SUBTESTS 16
19 #define IGNORE_GPR(n) (0x1UL << (n))
20 #define IGNORE_XER (0x1UL << 32)
21 #define IGNORE_CCR (0x1UL << 33)
22 #define NEGATIVE_TEST (0x1UL << 63)
24 #define TEST_PLD(r, base, i, pr) \
25 ppc_inst_prefix(PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_H(i), \
26 PPC_INST_PLD | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
28 #define TEST_PLWZ(r, base, i, pr) \
29 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
30 PPC_RAW_LWZ(r, base, i))
32 #define TEST_PSTD(r, base, i, pr) \
33 ppc_inst_prefix(PPC_PREFIX_8LS | __PPC_PRFX_R(pr) | IMM_H(i), \
34 PPC_INST_PSTD | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
36 #define TEST_PLFS(r, base, i, pr) \
37 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
38 PPC_INST_LFS | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
40 #define TEST_PSTFS(r, base, i, pr) \
41 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
42 PPC_INST_STFS | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
44 #define TEST_PLFD(r, base, i, pr) \
45 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
46 PPC_INST_LFD | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
48 #define TEST_PSTFD(r, base, i, pr) \
49 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
50 PPC_INST_STFD | ___PPC_RT(r) | ___PPC_RA(base) | IMM_L(i))
52 #define TEST_PADDI(t, a, i, pr) \
53 ppc_inst_prefix(PPC_PREFIX_MLS | __PPC_PRFX_R(pr) | IMM_H(i), \
54 PPC_RAW_ADDI(t, a, i))
57 static void __init init_pt_regs(struct pt_regs *regs)
59 static unsigned long msr;
60 static bool msr_cached;
62 memset(regs, 0, sizeof(struct pt_regs));
64 if (likely(msr_cached)) {
65 regs->msr = msr;
66 return;
69 asm volatile("mfmsr %0" : "=r"(regs->msr));
71 regs->msr |= MSR_FP;
72 regs->msr |= MSR_VEC;
73 regs->msr |= MSR_VSX;
75 msr = regs->msr;
76 msr_cached = true;
79 static void __init show_result(char *mnemonic, char *result)
81 pr_info("%-14s : %s\n", mnemonic, result);
84 static void __init show_result_with_descr(char *mnemonic, char *descr,
85 char *result)
87 pr_info("%-14s : %-50s %s\n", mnemonic, descr, result);
90 static void __init test_ld(void)
92 struct pt_regs regs;
93 unsigned long a = 0x23;
94 int stepped = -1;
96 init_pt_regs(&regs);
97 regs.gpr[3] = (unsigned long) &a;
99 /* ld r5, 0(r3) */
100 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LD(5, 3, 0)));
102 if (stepped == 1 && regs.gpr[5] == a)
103 show_result("ld", "PASS");
104 else
105 show_result("ld", "FAIL");
108 static void __init test_pld(void)
110 struct pt_regs regs;
111 unsigned long a = 0x23;
112 int stepped = -1;
114 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
115 show_result("pld", "SKIP (!CPU_FTR_ARCH_31)");
116 return;
119 init_pt_regs(&regs);
120 regs.gpr[3] = (unsigned long)&a;
122 /* pld r5, 0(r3), 0 */
123 stepped = emulate_step(&regs, TEST_PLD(5, 3, 0, 0));
125 if (stepped == 1 && regs.gpr[5] == a)
126 show_result("pld", "PASS");
127 else
128 show_result("pld", "FAIL");
131 static void __init test_lwz(void)
133 struct pt_regs regs;
134 unsigned int a = 0x4545;
135 int stepped = -1;
137 init_pt_regs(&regs);
138 regs.gpr[3] = (unsigned long) &a;
140 /* lwz r5, 0(r3) */
141 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LWZ(5, 3, 0)));
143 if (stepped == 1 && regs.gpr[5] == a)
144 show_result("lwz", "PASS");
145 else
146 show_result("lwz", "FAIL");
149 static void __init test_plwz(void)
151 struct pt_regs regs;
152 unsigned int a = 0x4545;
153 int stepped = -1;
155 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
156 show_result("plwz", "SKIP (!CPU_FTR_ARCH_31)");
157 return;
160 init_pt_regs(&regs);
161 regs.gpr[3] = (unsigned long)&a;
163 /* plwz r5, 0(r3), 0 */
165 stepped = emulate_step(&regs, TEST_PLWZ(5, 3, 0, 0));
167 if (stepped == 1 && regs.gpr[5] == a)
168 show_result("plwz", "PASS");
169 else
170 show_result("plwz", "FAIL");
173 static void __init test_lwzx(void)
175 struct pt_regs regs;
176 unsigned int a[3] = {0x0, 0x0, 0x1234};
177 int stepped = -1;
179 init_pt_regs(&regs);
180 regs.gpr[3] = (unsigned long) a;
181 regs.gpr[4] = 8;
182 regs.gpr[5] = 0x8765;
184 /* lwzx r5, r3, r4 */
185 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LWZX(5, 3, 4)));
186 if (stepped == 1 && regs.gpr[5] == a[2])
187 show_result("lwzx", "PASS");
188 else
189 show_result("lwzx", "FAIL");
192 static void __init test_std(void)
194 struct pt_regs regs;
195 unsigned long a = 0x1234;
196 int stepped = -1;
198 init_pt_regs(&regs);
199 regs.gpr[3] = (unsigned long) &a;
200 regs.gpr[5] = 0x5678;
202 /* std r5, 0(r3) */
203 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STD(5, 3, 0)));
204 if (stepped == 1 && regs.gpr[5] == a)
205 show_result("std", "PASS");
206 else
207 show_result("std", "FAIL");
210 static void __init test_pstd(void)
212 struct pt_regs regs;
213 unsigned long a = 0x1234;
214 int stepped = -1;
216 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
217 show_result("pstd", "SKIP (!CPU_FTR_ARCH_31)");
218 return;
221 init_pt_regs(&regs);
222 regs.gpr[3] = (unsigned long)&a;
223 regs.gpr[5] = 0x5678;
225 /* pstd r5, 0(r3), 0 */
226 stepped = emulate_step(&regs, TEST_PSTD(5, 3, 0, 0));
227 if (stepped == 1 || regs.gpr[5] == a)
228 show_result("pstd", "PASS");
229 else
230 show_result("pstd", "FAIL");
233 static void __init test_ldarx_stdcx(void)
235 struct pt_regs regs;
236 unsigned long a = 0x1234;
237 int stepped = -1;
238 unsigned long cr0_eq = 0x1 << 29; /* eq bit of CR0 */
240 init_pt_regs(&regs);
241 asm volatile("mfcr %0" : "=r"(regs.ccr));
244 /*** ldarx ***/
246 regs.gpr[3] = (unsigned long) &a;
247 regs.gpr[4] = 0;
248 regs.gpr[5] = 0x5678;
250 /* ldarx r5, r3, r4, 0 */
251 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LDARX(5, 3, 4, 0)));
254 * Don't touch 'a' here. Touching 'a' can do Load/store
255 * of 'a' which result in failure of subsequent stdcx.
256 * Instead, use hardcoded value for comparison.
258 if (stepped <= 0 || regs.gpr[5] != 0x1234) {
259 show_result("ldarx / stdcx.", "FAIL (ldarx)");
260 return;
264 /*** stdcx. ***/
266 regs.gpr[5] = 0x9ABC;
268 /* stdcx. r5, r3, r4 */
269 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STDCX(5, 3, 4)));
272 * Two possible scenarios that indicates successful emulation
273 * of stdcx. :
274 * 1. Reservation is active and store is performed. In this
275 * case cr0.eq bit will be set to 1.
276 * 2. Reservation is not active and store is not performed.
277 * In this case cr0.eq bit will be set to 0.
279 if (stepped == 1 && ((regs.gpr[5] == a && (regs.ccr & cr0_eq))
280 || (regs.gpr[5] != a && !(regs.ccr & cr0_eq))))
281 show_result("ldarx / stdcx.", "PASS");
282 else
283 show_result("ldarx / stdcx.", "FAIL (stdcx.)");
286 #ifdef CONFIG_PPC_FPU
287 static void __init test_lfsx_stfsx(void)
289 struct pt_regs regs;
290 union {
291 float a;
292 int b;
293 } c;
294 int cached_b;
295 int stepped = -1;
297 init_pt_regs(&regs);
300 /*** lfsx ***/
302 c.a = 123.45;
303 cached_b = c.b;
305 regs.gpr[3] = (unsigned long) &c.a;
306 regs.gpr[4] = 0;
308 /* lfsx frt10, r3, r4 */
309 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LFSX(10, 3, 4)));
311 if (stepped == 1)
312 show_result("lfsx", "PASS");
313 else
314 show_result("lfsx", "FAIL");
317 /*** stfsx ***/
319 c.a = 678.91;
321 /* stfsx frs10, r3, r4 */
322 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STFSX(10, 3, 4)));
324 if (stepped == 1 && c.b == cached_b)
325 show_result("stfsx", "PASS");
326 else
327 show_result("stfsx", "FAIL");
330 static void __init test_plfs_pstfs(void)
332 struct pt_regs regs;
333 union {
334 float a;
335 int b;
336 } c;
337 int cached_b;
338 int stepped = -1;
340 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
341 show_result("pld", "SKIP (!CPU_FTR_ARCH_31)");
342 return;
345 init_pt_regs(&regs);
348 /*** plfs ***/
350 c.a = 123.45;
351 cached_b = c.b;
353 regs.gpr[3] = (unsigned long)&c.a;
355 /* plfs frt10, 0(r3), 0 */
356 stepped = emulate_step(&regs, TEST_PLFS(10, 3, 0, 0));
358 if (stepped == 1)
359 show_result("plfs", "PASS");
360 else
361 show_result("plfs", "FAIL");
364 /*** pstfs ***/
366 c.a = 678.91;
368 /* pstfs frs10, 0(r3), 0 */
369 stepped = emulate_step(&regs, TEST_PSTFS(10, 3, 0, 0));
371 if (stepped == 1 && c.b == cached_b)
372 show_result("pstfs", "PASS");
373 else
374 show_result("pstfs", "FAIL");
377 static void __init test_lfdx_stfdx(void)
379 struct pt_regs regs;
380 union {
381 double a;
382 long b;
383 } c;
384 long cached_b;
385 int stepped = -1;
387 init_pt_regs(&regs);
390 /*** lfdx ***/
392 c.a = 123456.78;
393 cached_b = c.b;
395 regs.gpr[3] = (unsigned long) &c.a;
396 regs.gpr[4] = 0;
398 /* lfdx frt10, r3, r4 */
399 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LFDX(10, 3, 4)));
401 if (stepped == 1)
402 show_result("lfdx", "PASS");
403 else
404 show_result("lfdx", "FAIL");
407 /*** stfdx ***/
409 c.a = 987654.32;
411 /* stfdx frs10, r3, r4 */
412 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STFDX(10, 3, 4)));
414 if (stepped == 1 && c.b == cached_b)
415 show_result("stfdx", "PASS");
416 else
417 show_result("stfdx", "FAIL");
420 static void __init test_plfd_pstfd(void)
422 struct pt_regs regs;
423 union {
424 double a;
425 long b;
426 } c;
427 long cached_b;
428 int stepped = -1;
430 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
431 show_result("pld", "SKIP (!CPU_FTR_ARCH_31)");
432 return;
435 init_pt_regs(&regs);
438 /*** plfd ***/
440 c.a = 123456.78;
441 cached_b = c.b;
443 regs.gpr[3] = (unsigned long)&c.a;
445 /* plfd frt10, 0(r3), 0 */
446 stepped = emulate_step(&regs, TEST_PLFD(10, 3, 0, 0));
448 if (stepped == 1)
449 show_result("plfd", "PASS");
450 else
451 show_result("plfd", "FAIL");
454 /*** pstfd ***/
456 c.a = 987654.32;
458 /* pstfd frs10, 0(r3), 0 */
459 stepped = emulate_step(&regs, TEST_PSTFD(10, 3, 0, 0));
461 if (stepped == 1 && c.b == cached_b)
462 show_result("pstfd", "PASS");
463 else
464 show_result("pstfd", "FAIL");
466 #else
467 static void __init test_lfsx_stfsx(void)
469 show_result("lfsx", "SKIP (CONFIG_PPC_FPU is not set)");
470 show_result("stfsx", "SKIP (CONFIG_PPC_FPU is not set)");
473 static void __init test_plfs_pstfs(void)
475 show_result("plfs", "SKIP (CONFIG_PPC_FPU is not set)");
476 show_result("pstfs", "SKIP (CONFIG_PPC_FPU is not set)");
479 static void __init test_lfdx_stfdx(void)
481 show_result("lfdx", "SKIP (CONFIG_PPC_FPU is not set)");
482 show_result("stfdx", "SKIP (CONFIG_PPC_FPU is not set)");
485 static void __init test_plfd_pstfd(void)
487 show_result("plfd", "SKIP (CONFIG_PPC_FPU is not set)");
488 show_result("pstfd", "SKIP (CONFIG_PPC_FPU is not set)");
490 #endif /* CONFIG_PPC_FPU */
492 #ifdef CONFIG_ALTIVEC
493 static void __init test_lvx_stvx(void)
495 struct pt_regs regs;
496 union {
497 vector128 a;
498 u32 b[4];
499 } c;
500 u32 cached_b[4];
501 int stepped = -1;
503 init_pt_regs(&regs);
506 /*** lvx ***/
508 cached_b[0] = c.b[0] = 923745;
509 cached_b[1] = c.b[1] = 2139478;
510 cached_b[2] = c.b[2] = 9012;
511 cached_b[3] = c.b[3] = 982134;
513 regs.gpr[3] = (unsigned long) &c.a;
514 regs.gpr[4] = 0;
516 /* lvx vrt10, r3, r4 */
517 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LVX(10, 3, 4)));
519 if (stepped == 1)
520 show_result("lvx", "PASS");
521 else
522 show_result("lvx", "FAIL");
525 /*** stvx ***/
527 c.b[0] = 4987513;
528 c.b[1] = 84313948;
529 c.b[2] = 71;
530 c.b[3] = 498532;
532 /* stvx vrs10, r3, r4 */
533 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STVX(10, 3, 4)));
535 if (stepped == 1 && cached_b[0] == c.b[0] && cached_b[1] == c.b[1] &&
536 cached_b[2] == c.b[2] && cached_b[3] == c.b[3])
537 show_result("stvx", "PASS");
538 else
539 show_result("stvx", "FAIL");
541 #else
542 static void __init test_lvx_stvx(void)
544 show_result("lvx", "SKIP (CONFIG_ALTIVEC is not set)");
545 show_result("stvx", "SKIP (CONFIG_ALTIVEC is not set)");
547 #endif /* CONFIG_ALTIVEC */
549 #ifdef CONFIG_VSX
550 static void __init test_lxvd2x_stxvd2x(void)
552 struct pt_regs regs;
553 union {
554 vector128 a;
555 u32 b[4];
556 } c;
557 u32 cached_b[4];
558 int stepped = -1;
560 init_pt_regs(&regs);
563 /*** lxvd2x ***/
565 cached_b[0] = c.b[0] = 18233;
566 cached_b[1] = c.b[1] = 34863571;
567 cached_b[2] = c.b[2] = 834;
568 cached_b[3] = c.b[3] = 6138911;
570 regs.gpr[3] = (unsigned long) &c.a;
571 regs.gpr[4] = 0;
573 /* lxvd2x vsr39, r3, r4 */
574 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LXVD2X(39, R3, R4)));
576 if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) {
577 show_result("lxvd2x", "PASS");
578 } else {
579 if (!cpu_has_feature(CPU_FTR_VSX))
580 show_result("lxvd2x", "PASS (!CPU_FTR_VSX)");
581 else
582 show_result("lxvd2x", "FAIL");
586 /*** stxvd2x ***/
588 c.b[0] = 21379463;
589 c.b[1] = 87;
590 c.b[2] = 374234;
591 c.b[3] = 4;
593 /* stxvd2x vsr39, r3, r4 */
594 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STXVD2X(39, R3, R4)));
596 if (stepped == 1 && cached_b[0] == c.b[0] && cached_b[1] == c.b[1] &&
597 cached_b[2] == c.b[2] && cached_b[3] == c.b[3] &&
598 cpu_has_feature(CPU_FTR_VSX)) {
599 show_result("stxvd2x", "PASS");
600 } else {
601 if (!cpu_has_feature(CPU_FTR_VSX))
602 show_result("stxvd2x", "PASS (!CPU_FTR_VSX)");
603 else
604 show_result("stxvd2x", "FAIL");
607 #else
608 static void __init test_lxvd2x_stxvd2x(void)
610 show_result("lxvd2x", "SKIP (CONFIG_VSX is not set)");
611 show_result("stxvd2x", "SKIP (CONFIG_VSX is not set)");
613 #endif /* CONFIG_VSX */
615 #ifdef CONFIG_VSX
616 static void __init test_lxvp_stxvp(void)
618 struct pt_regs regs;
619 union {
620 vector128 a;
621 u32 b[4];
622 } c[2];
623 u32 cached_b[8];
624 int stepped = -1;
626 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
627 show_result("lxvp", "SKIP (!CPU_FTR_ARCH_31)");
628 show_result("stxvp", "SKIP (!CPU_FTR_ARCH_31)");
629 return;
632 init_pt_regs(&regs);
634 /*** lxvp ***/
636 cached_b[0] = c[0].b[0] = 18233;
637 cached_b[1] = c[0].b[1] = 34863571;
638 cached_b[2] = c[0].b[2] = 834;
639 cached_b[3] = c[0].b[3] = 6138911;
640 cached_b[4] = c[1].b[0] = 1234;
641 cached_b[5] = c[1].b[1] = 5678;
642 cached_b[6] = c[1].b[2] = 91011;
643 cached_b[7] = c[1].b[3] = 121314;
645 regs.gpr[4] = (unsigned long)&c[0].a;
648 * lxvp XTp,DQ(RA)
649 * XTp = 32xTX + 2xTp
650 * let TX=1 Tp=1 RA=4 DQ=0
652 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LXVP(34, 4, 0)));
654 if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) {
655 show_result("lxvp", "PASS");
656 } else {
657 if (!cpu_has_feature(CPU_FTR_VSX))
658 show_result("lxvp", "PASS (!CPU_FTR_VSX)");
659 else
660 show_result("lxvp", "FAIL");
663 /*** stxvp ***/
665 c[0].b[0] = 21379463;
666 c[0].b[1] = 87;
667 c[0].b[2] = 374234;
668 c[0].b[3] = 4;
669 c[1].b[0] = 90;
670 c[1].b[1] = 122;
671 c[1].b[2] = 555;
672 c[1].b[3] = 32144;
675 * stxvp XSp,DQ(RA)
676 * XSp = 32xSX + 2xSp
677 * let SX=1 Sp=1 RA=4 DQ=0
679 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STXVP(34, 4, 0)));
681 if (stepped == 1 && cached_b[0] == c[0].b[0] && cached_b[1] == c[0].b[1] &&
682 cached_b[2] == c[0].b[2] && cached_b[3] == c[0].b[3] &&
683 cached_b[4] == c[1].b[0] && cached_b[5] == c[1].b[1] &&
684 cached_b[6] == c[1].b[2] && cached_b[7] == c[1].b[3] &&
685 cpu_has_feature(CPU_FTR_VSX)) {
686 show_result("stxvp", "PASS");
687 } else {
688 if (!cpu_has_feature(CPU_FTR_VSX))
689 show_result("stxvp", "PASS (!CPU_FTR_VSX)");
690 else
691 show_result("stxvp", "FAIL");
694 #else
695 static void __init test_lxvp_stxvp(void)
697 show_result("lxvp", "SKIP (CONFIG_VSX is not set)");
698 show_result("stxvp", "SKIP (CONFIG_VSX is not set)");
700 #endif /* CONFIG_VSX */
702 #ifdef CONFIG_VSX
703 static void __init test_lxvpx_stxvpx(void)
705 struct pt_regs regs;
706 union {
707 vector128 a;
708 u32 b[4];
709 } c[2];
710 u32 cached_b[8];
711 int stepped = -1;
713 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
714 show_result("lxvpx", "SKIP (!CPU_FTR_ARCH_31)");
715 show_result("stxvpx", "SKIP (!CPU_FTR_ARCH_31)");
716 return;
719 init_pt_regs(&regs);
721 /*** lxvpx ***/
723 cached_b[0] = c[0].b[0] = 18233;
724 cached_b[1] = c[0].b[1] = 34863571;
725 cached_b[2] = c[0].b[2] = 834;
726 cached_b[3] = c[0].b[3] = 6138911;
727 cached_b[4] = c[1].b[0] = 1234;
728 cached_b[5] = c[1].b[1] = 5678;
729 cached_b[6] = c[1].b[2] = 91011;
730 cached_b[7] = c[1].b[3] = 121314;
732 regs.gpr[3] = (unsigned long)&c[0].a;
733 regs.gpr[4] = 0;
736 * lxvpx XTp,RA,RB
737 * XTp = 32xTX + 2xTp
738 * let TX=1 Tp=1 RA=3 RB=4
740 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_LXVPX(34, 3, 4)));
742 if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) {
743 show_result("lxvpx", "PASS");
744 } else {
745 if (!cpu_has_feature(CPU_FTR_VSX))
746 show_result("lxvpx", "PASS (!CPU_FTR_VSX)");
747 else
748 show_result("lxvpx", "FAIL");
751 /*** stxvpx ***/
753 c[0].b[0] = 21379463;
754 c[0].b[1] = 87;
755 c[0].b[2] = 374234;
756 c[0].b[3] = 4;
757 c[1].b[0] = 90;
758 c[1].b[1] = 122;
759 c[1].b[2] = 555;
760 c[1].b[3] = 32144;
763 * stxvpx XSp,RA,RB
764 * XSp = 32xSX + 2xSp
765 * let SX=1 Sp=1 RA=3 RB=4
767 stepped = emulate_step(&regs, ppc_inst(PPC_RAW_STXVPX(34, 3, 4)));
769 if (stepped == 1 && cached_b[0] == c[0].b[0] && cached_b[1] == c[0].b[1] &&
770 cached_b[2] == c[0].b[2] && cached_b[3] == c[0].b[3] &&
771 cached_b[4] == c[1].b[0] && cached_b[5] == c[1].b[1] &&
772 cached_b[6] == c[1].b[2] && cached_b[7] == c[1].b[3] &&
773 cpu_has_feature(CPU_FTR_VSX)) {
774 show_result("stxvpx", "PASS");
775 } else {
776 if (!cpu_has_feature(CPU_FTR_VSX))
777 show_result("stxvpx", "PASS (!CPU_FTR_VSX)");
778 else
779 show_result("stxvpx", "FAIL");
782 #else
783 static void __init test_lxvpx_stxvpx(void)
785 show_result("lxvpx", "SKIP (CONFIG_VSX is not set)");
786 show_result("stxvpx", "SKIP (CONFIG_VSX is not set)");
788 #endif /* CONFIG_VSX */
790 #ifdef CONFIG_VSX
791 static void __init test_plxvp_pstxvp(void)
793 struct ppc_inst instr;
794 struct pt_regs regs;
795 union {
796 vector128 a;
797 u32 b[4];
798 } c[2];
799 u32 cached_b[8];
800 int stepped = -1;
802 if (!cpu_has_feature(CPU_FTR_ARCH_31)) {
803 show_result("plxvp", "SKIP (!CPU_FTR_ARCH_31)");
804 show_result("pstxvp", "SKIP (!CPU_FTR_ARCH_31)");
805 return;
808 /*** plxvp ***/
810 cached_b[0] = c[0].b[0] = 18233;
811 cached_b[1] = c[0].b[1] = 34863571;
812 cached_b[2] = c[0].b[2] = 834;
813 cached_b[3] = c[0].b[3] = 6138911;
814 cached_b[4] = c[1].b[0] = 1234;
815 cached_b[5] = c[1].b[1] = 5678;
816 cached_b[6] = c[1].b[2] = 91011;
817 cached_b[7] = c[1].b[3] = 121314;
819 init_pt_regs(&regs);
820 regs.gpr[3] = (unsigned long)&c[0].a;
823 * plxvp XTp,D(RA),R
824 * XTp = 32xTX + 2xTp
825 * let RA=3 R=0 D=d0||d1=0 R=0 Tp=1 TX=1
827 instr = ppc_inst_prefix(PPC_RAW_PLXVP(34, 0, 3, 0) >> 32,
828 PPC_RAW_PLXVP(34, 0, 3, 0) & 0xffffffff);
830 stepped = emulate_step(&regs, instr);
831 if (stepped == 1 && cpu_has_feature(CPU_FTR_VSX)) {
832 show_result("plxvp", "PASS");
833 } else {
834 if (!cpu_has_feature(CPU_FTR_VSX))
835 show_result("plxvp", "PASS (!CPU_FTR_VSX)");
836 else
837 show_result("plxvp", "FAIL");
840 /*** pstxvp ***/
842 c[0].b[0] = 21379463;
843 c[0].b[1] = 87;
844 c[0].b[2] = 374234;
845 c[0].b[3] = 4;
846 c[1].b[0] = 90;
847 c[1].b[1] = 122;
848 c[1].b[2] = 555;
849 c[1].b[3] = 32144;
852 * pstxvp XSp,D(RA),R
853 * XSp = 32xSX + 2xSp
854 * let RA=3 D=d0||d1=0 R=0 Sp=1 SX=1
856 instr = ppc_inst_prefix(PPC_RAW_PSTXVP(34, 0, 3, 0) >> 32,
857 PPC_RAW_PSTXVP(34, 0, 3, 0) & 0xffffffff);
859 stepped = emulate_step(&regs, instr);
861 if (stepped == 1 && cached_b[0] == c[0].b[0] && cached_b[1] == c[0].b[1] &&
862 cached_b[2] == c[0].b[2] && cached_b[3] == c[0].b[3] &&
863 cached_b[4] == c[1].b[0] && cached_b[5] == c[1].b[1] &&
864 cached_b[6] == c[1].b[2] && cached_b[7] == c[1].b[3] &&
865 cpu_has_feature(CPU_FTR_VSX)) {
866 show_result("pstxvp", "PASS");
867 } else {
868 if (!cpu_has_feature(CPU_FTR_VSX))
869 show_result("pstxvp", "PASS (!CPU_FTR_VSX)");
870 else
871 show_result("pstxvp", "FAIL");
874 #else
875 static void __init test_plxvp_pstxvp(void)
877 show_result("plxvp", "SKIP (CONFIG_VSX is not set)");
878 show_result("pstxvp", "SKIP (CONFIG_VSX is not set)");
880 #endif /* CONFIG_VSX */
882 static void __init run_tests_load_store(void)
884 test_ld();
885 test_pld();
886 test_lwz();
887 test_plwz();
888 test_lwzx();
889 test_std();
890 test_pstd();
891 test_ldarx_stdcx();
892 test_lfsx_stfsx();
893 test_plfs_pstfs();
894 test_lfdx_stfdx();
895 test_plfd_pstfd();
896 test_lvx_stvx();
897 test_lxvd2x_stxvd2x();
898 test_lxvp_stxvp();
899 test_lxvpx_stxvpx();
900 test_plxvp_pstxvp();
903 struct compute_test {
904 char *mnemonic;
905 unsigned long cpu_feature;
906 struct {
907 char *descr;
908 unsigned long flags;
909 struct ppc_inst instr;
910 struct pt_regs regs;
911 } subtests[MAX_SUBTESTS + 1];
914 /* Extreme values for si0||si1 (the MLS:D-form 34 bit immediate field) */
915 #define SI_MIN BIT(33)
916 #define SI_MAX (BIT(33) - 1)
917 #define SI_UMAX (BIT(34) - 1)
919 static struct compute_test compute_tests[] = {
921 .mnemonic = "nop",
922 .subtests = {
924 .descr = "R0 = LONG_MAX",
925 .instr = ppc_inst(PPC_INST_NOP),
926 .regs = {
927 .gpr[0] = LONG_MAX,
933 .mnemonic = "add",
934 .subtests = {
936 .descr = "RA = LONG_MIN, RB = LONG_MIN",
937 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
938 .regs = {
939 .gpr[21] = LONG_MIN,
940 .gpr[22] = LONG_MIN,
944 .descr = "RA = LONG_MIN, RB = LONG_MAX",
945 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
946 .regs = {
947 .gpr[21] = LONG_MIN,
948 .gpr[22] = LONG_MAX,
952 .descr = "RA = LONG_MAX, RB = LONG_MAX",
953 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
954 .regs = {
955 .gpr[21] = LONG_MAX,
956 .gpr[22] = LONG_MAX,
960 .descr = "RA = ULONG_MAX, RB = ULONG_MAX",
961 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
962 .regs = {
963 .gpr[21] = ULONG_MAX,
964 .gpr[22] = ULONG_MAX,
968 .descr = "RA = ULONG_MAX, RB = 0x1",
969 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
970 .regs = {
971 .gpr[21] = ULONG_MAX,
972 .gpr[22] = 0x1,
976 .descr = "RA = INT_MIN, RB = INT_MIN",
977 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
978 .regs = {
979 .gpr[21] = INT_MIN,
980 .gpr[22] = INT_MIN,
984 .descr = "RA = INT_MIN, RB = INT_MAX",
985 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
986 .regs = {
987 .gpr[21] = INT_MIN,
988 .gpr[22] = INT_MAX,
992 .descr = "RA = INT_MAX, RB = INT_MAX",
993 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
994 .regs = {
995 .gpr[21] = INT_MAX,
996 .gpr[22] = INT_MAX,
1000 .descr = "RA = UINT_MAX, RB = UINT_MAX",
1001 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
1002 .regs = {
1003 .gpr[21] = UINT_MAX,
1004 .gpr[22] = UINT_MAX,
1008 .descr = "RA = UINT_MAX, RB = 0x1",
1009 .instr = ppc_inst(PPC_RAW_ADD(20, 21, 22)),
1010 .regs = {
1011 .gpr[21] = UINT_MAX,
1012 .gpr[22] = 0x1,
1018 .mnemonic = "add.",
1019 .subtests = {
1021 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1022 .flags = IGNORE_CCR,
1023 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1024 .regs = {
1025 .gpr[21] = LONG_MIN,
1026 .gpr[22] = LONG_MIN,
1030 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1031 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1032 .regs = {
1033 .gpr[21] = LONG_MIN,
1034 .gpr[22] = LONG_MAX,
1038 .descr = "RA = LONG_MAX, RB = LONG_MAX",
1039 .flags = IGNORE_CCR,
1040 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1041 .regs = {
1042 .gpr[21] = LONG_MAX,
1043 .gpr[22] = LONG_MAX,
1047 .descr = "RA = ULONG_MAX, RB = ULONG_MAX",
1048 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1049 .regs = {
1050 .gpr[21] = ULONG_MAX,
1051 .gpr[22] = ULONG_MAX,
1055 .descr = "RA = ULONG_MAX, RB = 0x1",
1056 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1057 .regs = {
1058 .gpr[21] = ULONG_MAX,
1059 .gpr[22] = 0x1,
1063 .descr = "RA = INT_MIN, RB = INT_MIN",
1064 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1065 .regs = {
1066 .gpr[21] = INT_MIN,
1067 .gpr[22] = INT_MIN,
1071 .descr = "RA = INT_MIN, RB = INT_MAX",
1072 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1073 .regs = {
1074 .gpr[21] = INT_MIN,
1075 .gpr[22] = INT_MAX,
1079 .descr = "RA = INT_MAX, RB = INT_MAX",
1080 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1081 .regs = {
1082 .gpr[21] = INT_MAX,
1083 .gpr[22] = INT_MAX,
1087 .descr = "RA = UINT_MAX, RB = UINT_MAX",
1088 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1089 .regs = {
1090 .gpr[21] = UINT_MAX,
1091 .gpr[22] = UINT_MAX,
1095 .descr = "RA = UINT_MAX, RB = 0x1",
1096 .instr = ppc_inst(PPC_RAW_ADD_DOT(20, 21, 22)),
1097 .regs = {
1098 .gpr[21] = UINT_MAX,
1099 .gpr[22] = 0x1,
1105 .mnemonic = "addc",
1106 .subtests = {
1108 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1109 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1110 .regs = {
1111 .gpr[21] = LONG_MIN,
1112 .gpr[22] = LONG_MIN,
1116 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1117 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1118 .regs = {
1119 .gpr[21] = LONG_MIN,
1120 .gpr[22] = LONG_MAX,
1124 .descr = "RA = LONG_MAX, RB = LONG_MAX",
1125 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1126 .regs = {
1127 .gpr[21] = LONG_MAX,
1128 .gpr[22] = LONG_MAX,
1132 .descr = "RA = ULONG_MAX, RB = ULONG_MAX",
1133 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1134 .regs = {
1135 .gpr[21] = ULONG_MAX,
1136 .gpr[22] = ULONG_MAX,
1140 .descr = "RA = ULONG_MAX, RB = 0x1",
1141 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1142 .regs = {
1143 .gpr[21] = ULONG_MAX,
1144 .gpr[22] = 0x1,
1148 .descr = "RA = INT_MIN, RB = INT_MIN",
1149 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1150 .regs = {
1151 .gpr[21] = INT_MIN,
1152 .gpr[22] = INT_MIN,
1156 .descr = "RA = INT_MIN, RB = INT_MAX",
1157 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1158 .regs = {
1159 .gpr[21] = INT_MIN,
1160 .gpr[22] = INT_MAX,
1164 .descr = "RA = INT_MAX, RB = INT_MAX",
1165 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1166 .regs = {
1167 .gpr[21] = INT_MAX,
1168 .gpr[22] = INT_MAX,
1172 .descr = "RA = UINT_MAX, RB = UINT_MAX",
1173 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1174 .regs = {
1175 .gpr[21] = UINT_MAX,
1176 .gpr[22] = UINT_MAX,
1180 .descr = "RA = UINT_MAX, RB = 0x1",
1181 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1182 .regs = {
1183 .gpr[21] = UINT_MAX,
1184 .gpr[22] = 0x1,
1188 .descr = "RA = LONG_MIN | INT_MIN, RB = LONG_MIN | INT_MIN",
1189 .instr = ppc_inst(PPC_RAW_ADDC(20, 21, 22)),
1190 .regs = {
1191 .gpr[21] = LONG_MIN | (uint)INT_MIN,
1192 .gpr[22] = LONG_MIN | (uint)INT_MIN,
1198 .mnemonic = "addc.",
1199 .subtests = {
1201 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1202 .flags = IGNORE_CCR,
1203 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1204 .regs = {
1205 .gpr[21] = LONG_MIN,
1206 .gpr[22] = LONG_MIN,
1210 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1211 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1212 .regs = {
1213 .gpr[21] = LONG_MIN,
1214 .gpr[22] = LONG_MAX,
1218 .descr = "RA = LONG_MAX, RB = LONG_MAX",
1219 .flags = IGNORE_CCR,
1220 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1221 .regs = {
1222 .gpr[21] = LONG_MAX,
1223 .gpr[22] = LONG_MAX,
1227 .descr = "RA = ULONG_MAX, RB = ULONG_MAX",
1228 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1229 .regs = {
1230 .gpr[21] = ULONG_MAX,
1231 .gpr[22] = ULONG_MAX,
1235 .descr = "RA = ULONG_MAX, RB = 0x1",
1236 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1237 .regs = {
1238 .gpr[21] = ULONG_MAX,
1239 .gpr[22] = 0x1,
1243 .descr = "RA = INT_MIN, RB = INT_MIN",
1244 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1245 .regs = {
1246 .gpr[21] = INT_MIN,
1247 .gpr[22] = INT_MIN,
1251 .descr = "RA = INT_MIN, RB = INT_MAX",
1252 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1253 .regs = {
1254 .gpr[21] = INT_MIN,
1255 .gpr[22] = INT_MAX,
1259 .descr = "RA = INT_MAX, RB = INT_MAX",
1260 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1261 .regs = {
1262 .gpr[21] = INT_MAX,
1263 .gpr[22] = INT_MAX,
1267 .descr = "RA = UINT_MAX, RB = UINT_MAX",
1268 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1269 .regs = {
1270 .gpr[21] = UINT_MAX,
1271 .gpr[22] = UINT_MAX,
1275 .descr = "RA = UINT_MAX, RB = 0x1",
1276 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1277 .regs = {
1278 .gpr[21] = UINT_MAX,
1279 .gpr[22] = 0x1,
1283 .descr = "RA = LONG_MIN | INT_MIN, RB = LONG_MIN | INT_MIN",
1284 .instr = ppc_inst(PPC_RAW_ADDC_DOT(20, 21, 22)),
1285 .regs = {
1286 .gpr[21] = LONG_MIN | (uint)INT_MIN,
1287 .gpr[22] = LONG_MIN | (uint)INT_MIN,
1293 .mnemonic = "divde",
1294 .subtests = {
1296 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1297 .instr = ppc_inst(PPC_RAW_DIVDE(20, 21, 22)),
1298 .regs = {
1299 .gpr[21] = LONG_MIN,
1300 .gpr[22] = LONG_MIN,
1304 .descr = "RA = 1L, RB = 0",
1305 .instr = ppc_inst(PPC_RAW_DIVDE(20, 21, 22)),
1306 .flags = IGNORE_GPR(20),
1307 .regs = {
1308 .gpr[21] = 1L,
1309 .gpr[22] = 0,
1313 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1314 .instr = ppc_inst(PPC_RAW_DIVDE(20, 21, 22)),
1315 .regs = {
1316 .gpr[21] = LONG_MIN,
1317 .gpr[22] = LONG_MAX,
1323 .mnemonic = "divde.",
1324 .subtests = {
1326 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1327 .instr = ppc_inst(PPC_RAW_DIVDE_DOT(20, 21, 22)),
1328 .regs = {
1329 .gpr[21] = LONG_MIN,
1330 .gpr[22] = LONG_MIN,
1334 .descr = "RA = 1L, RB = 0",
1335 .instr = ppc_inst(PPC_RAW_DIVDE_DOT(20, 21, 22)),
1336 .flags = IGNORE_GPR(20),
1337 .regs = {
1338 .gpr[21] = 1L,
1339 .gpr[22] = 0,
1343 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1344 .instr = ppc_inst(PPC_RAW_DIVDE_DOT(20, 21, 22)),
1345 .regs = {
1346 .gpr[21] = LONG_MIN,
1347 .gpr[22] = LONG_MAX,
1353 .mnemonic = "divdeu",
1354 .subtests = {
1356 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1357 .instr = ppc_inst(PPC_RAW_DIVDEU(20, 21, 22)),
1358 .flags = IGNORE_GPR(20),
1359 .regs = {
1360 .gpr[21] = LONG_MIN,
1361 .gpr[22] = LONG_MIN,
1365 .descr = "RA = 1L, RB = 0",
1366 .instr = ppc_inst(PPC_RAW_DIVDEU(20, 21, 22)),
1367 .flags = IGNORE_GPR(20),
1368 .regs = {
1369 .gpr[21] = 1L,
1370 .gpr[22] = 0,
1374 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1375 .instr = ppc_inst(PPC_RAW_DIVDEU(20, 21, 22)),
1376 .regs = {
1377 .gpr[21] = LONG_MIN,
1378 .gpr[22] = LONG_MAX,
1382 .descr = "RA = LONG_MAX - 1, RB = LONG_MAX",
1383 .instr = ppc_inst(PPC_RAW_DIVDEU(20, 21, 22)),
1384 .regs = {
1385 .gpr[21] = LONG_MAX - 1,
1386 .gpr[22] = LONG_MAX,
1390 .descr = "RA = LONG_MIN + 1, RB = LONG_MIN",
1391 .instr = ppc_inst(PPC_RAW_DIVDEU(20, 21, 22)),
1392 .flags = IGNORE_GPR(20),
1393 .regs = {
1394 .gpr[21] = LONG_MIN + 1,
1395 .gpr[22] = LONG_MIN,
1401 .mnemonic = "divdeu.",
1402 .subtests = {
1404 .descr = "RA = LONG_MIN, RB = LONG_MIN",
1405 .instr = ppc_inst(PPC_RAW_DIVDEU_DOT(20, 21, 22)),
1406 .flags = IGNORE_GPR(20),
1407 .regs = {
1408 .gpr[21] = LONG_MIN,
1409 .gpr[22] = LONG_MIN,
1413 .descr = "RA = 1L, RB = 0",
1414 .instr = ppc_inst(PPC_RAW_DIVDEU_DOT(20, 21, 22)),
1415 .flags = IGNORE_GPR(20),
1416 .regs = {
1417 .gpr[21] = 1L,
1418 .gpr[22] = 0,
1422 .descr = "RA = LONG_MIN, RB = LONG_MAX",
1423 .instr = ppc_inst(PPC_RAW_DIVDEU_DOT(20, 21, 22)),
1424 .regs = {
1425 .gpr[21] = LONG_MIN,
1426 .gpr[22] = LONG_MAX,
1430 .descr = "RA = LONG_MAX - 1, RB = LONG_MAX",
1431 .instr = ppc_inst(PPC_RAW_DIVDEU_DOT(20, 21, 22)),
1432 .regs = {
1433 .gpr[21] = LONG_MAX - 1,
1434 .gpr[22] = LONG_MAX,
1438 .descr = "RA = LONG_MIN + 1, RB = LONG_MIN",
1439 .instr = ppc_inst(PPC_RAW_DIVDEU_DOT(20, 21, 22)),
1440 .flags = IGNORE_GPR(20),
1441 .regs = {
1442 .gpr[21] = LONG_MIN + 1,
1443 .gpr[22] = LONG_MIN,
1449 .mnemonic = "paddi",
1450 .cpu_feature = CPU_FTR_ARCH_31,
1451 .subtests = {
1453 .descr = "RA = LONG_MIN, SI = SI_MIN, R = 0",
1454 .instr = TEST_PADDI(21, 22, SI_MIN, 0),
1455 .regs = {
1456 .gpr[21] = 0,
1457 .gpr[22] = LONG_MIN,
1461 .descr = "RA = LONG_MIN, SI = SI_MAX, R = 0",
1462 .instr = TEST_PADDI(21, 22, SI_MAX, 0),
1463 .regs = {
1464 .gpr[21] = 0,
1465 .gpr[22] = LONG_MIN,
1469 .descr = "RA = LONG_MAX, SI = SI_MAX, R = 0",
1470 .instr = TEST_PADDI(21, 22, SI_MAX, 0),
1471 .regs = {
1472 .gpr[21] = 0,
1473 .gpr[22] = LONG_MAX,
1477 .descr = "RA = ULONG_MAX, SI = SI_UMAX, R = 0",
1478 .instr = TEST_PADDI(21, 22, SI_UMAX, 0),
1479 .regs = {
1480 .gpr[21] = 0,
1481 .gpr[22] = ULONG_MAX,
1485 .descr = "RA = ULONG_MAX, SI = 0x1, R = 0",
1486 .instr = TEST_PADDI(21, 22, 0x1, 0),
1487 .regs = {
1488 .gpr[21] = 0,
1489 .gpr[22] = ULONG_MAX,
1493 .descr = "RA = INT_MIN, SI = SI_MIN, R = 0",
1494 .instr = TEST_PADDI(21, 22, SI_MIN, 0),
1495 .regs = {
1496 .gpr[21] = 0,
1497 .gpr[22] = INT_MIN,
1501 .descr = "RA = INT_MIN, SI = SI_MAX, R = 0",
1502 .instr = TEST_PADDI(21, 22, SI_MAX, 0),
1503 .regs = {
1504 .gpr[21] = 0,
1505 .gpr[22] = INT_MIN,
1509 .descr = "RA = INT_MAX, SI = SI_MAX, R = 0",
1510 .instr = TEST_PADDI(21, 22, SI_MAX, 0),
1511 .regs = {
1512 .gpr[21] = 0,
1513 .gpr[22] = INT_MAX,
1517 .descr = "RA = UINT_MAX, SI = 0x1, R = 0",
1518 .instr = TEST_PADDI(21, 22, 0x1, 0),
1519 .regs = {
1520 .gpr[21] = 0,
1521 .gpr[22] = UINT_MAX,
1525 .descr = "RA = UINT_MAX, SI = SI_MAX, R = 0",
1526 .instr = TEST_PADDI(21, 22, SI_MAX, 0),
1527 .regs = {
1528 .gpr[21] = 0,
1529 .gpr[22] = UINT_MAX,
1533 .descr = "RA is r0, SI = SI_MIN, R = 0",
1534 .instr = TEST_PADDI(21, 0, SI_MIN, 0),
1535 .regs = {
1536 .gpr[21] = 0x0,
1540 .descr = "RA = 0, SI = SI_MIN, R = 0",
1541 .instr = TEST_PADDI(21, 22, SI_MIN, 0),
1542 .regs = {
1543 .gpr[21] = 0x0,
1544 .gpr[22] = 0x0,
1548 .descr = "RA is r0, SI = 0, R = 1",
1549 .instr = TEST_PADDI(21, 0, 0, 1),
1550 .regs = {
1551 .gpr[21] = 0,
1555 .descr = "RA is r0, SI = SI_MIN, R = 1",
1556 .instr = TEST_PADDI(21, 0, SI_MIN, 1),
1557 .regs = {
1558 .gpr[21] = 0,
1561 /* Invalid instruction form with R = 1 and RA != 0 */
1563 .descr = "RA = R22(0), SI = 0, R = 1",
1564 .instr = TEST_PADDI(21, 22, 0, 1),
1565 .flags = NEGATIVE_TEST,
1566 .regs = {
1567 .gpr[21] = 0,
1568 .gpr[22] = 0,
1575 static int __init emulate_compute_instr(struct pt_regs *regs,
1576 struct ppc_inst instr,
1577 bool negative)
1579 int analysed;
1580 struct instruction_op op;
1582 if (!regs || !ppc_inst_val(instr))
1583 return -EINVAL;
1585 regs->nip = patch_site_addr(&patch__exec_instr);
1587 analysed = analyse_instr(&op, regs, instr);
1588 if (analysed != 1 || GETTYPE(op.type) != COMPUTE) {
1589 if (negative)
1590 return -EFAULT;
1591 pr_info("emulation failed, instruction = %s\n", ppc_inst_as_str(instr));
1592 return -EFAULT;
1594 if (analysed == 1 && negative)
1595 pr_info("negative test failed, instruction = %s\n", ppc_inst_as_str(instr));
1596 if (!negative)
1597 emulate_update_regs(regs, &op);
1598 return 0;
1601 static int __init execute_compute_instr(struct pt_regs *regs,
1602 struct ppc_inst instr)
1604 extern int exec_instr(struct pt_regs *regs);
1606 if (!regs || !ppc_inst_val(instr))
1607 return -EINVAL;
1609 /* Patch the NOP with the actual instruction */
1610 patch_instruction_site(&patch__exec_instr, instr);
1611 if (exec_instr(regs)) {
1612 pr_info("execution failed, instruction = %s\n", ppc_inst_as_str(instr));
1613 return -EFAULT;
1616 return 0;
1619 #define gpr_mismatch(gprn, exp, got) \
1620 pr_info("GPR%u mismatch, exp = 0x%016lx, got = 0x%016lx\n", \
1621 gprn, exp, got)
1623 #define reg_mismatch(name, exp, got) \
1624 pr_info("%s mismatch, exp = 0x%016lx, got = 0x%016lx\n", \
1625 name, exp, got)
1627 static void __init run_tests_compute(void)
1629 unsigned long flags;
1630 struct compute_test *test;
1631 struct pt_regs *regs, exp, got;
1632 unsigned int i, j, k;
1633 struct ppc_inst instr;
1634 bool ignore_gpr, ignore_xer, ignore_ccr, passed, rc, negative;
1636 for (i = 0; i < ARRAY_SIZE(compute_tests); i++) {
1637 test = &compute_tests[i];
1639 if (test->cpu_feature && !early_cpu_has_feature(test->cpu_feature)) {
1640 show_result(test->mnemonic, "SKIP (!CPU_FTR)");
1641 continue;
1644 for (j = 0; j < MAX_SUBTESTS && test->subtests[j].descr; j++) {
1645 instr = test->subtests[j].instr;
1646 flags = test->subtests[j].flags;
1647 regs = &test->subtests[j].regs;
1648 negative = flags & NEGATIVE_TEST;
1649 ignore_xer = flags & IGNORE_XER;
1650 ignore_ccr = flags & IGNORE_CCR;
1651 passed = true;
1653 memcpy(&exp, regs, sizeof(struct pt_regs));
1654 memcpy(&got, regs, sizeof(struct pt_regs));
1657 * Set a compatible MSR value explicitly to ensure
1658 * that XER and CR bits are updated appropriately
1660 exp.msr = MSR_KERNEL;
1661 got.msr = MSR_KERNEL;
1663 rc = emulate_compute_instr(&got, instr, negative) != 0;
1664 if (negative) {
1665 /* skip executing instruction */
1666 passed = rc;
1667 goto print;
1668 } else if (rc || execute_compute_instr(&exp, instr)) {
1669 passed = false;
1670 goto print;
1673 /* Verify GPR values */
1674 for (k = 0; k < 32; k++) {
1675 ignore_gpr = flags & IGNORE_GPR(k);
1676 if (!ignore_gpr && exp.gpr[k] != got.gpr[k]) {
1677 passed = false;
1678 gpr_mismatch(k, exp.gpr[k], got.gpr[k]);
1682 /* Verify LR value */
1683 if (exp.link != got.link) {
1684 passed = false;
1685 reg_mismatch("LR", exp.link, got.link);
1688 /* Verify XER value */
1689 if (!ignore_xer && exp.xer != got.xer) {
1690 passed = false;
1691 reg_mismatch("XER", exp.xer, got.xer);
1694 /* Verify CR value */
1695 if (!ignore_ccr && exp.ccr != got.ccr) {
1696 passed = false;
1697 reg_mismatch("CR", exp.ccr, got.ccr);
1700 print:
1701 show_result_with_descr(test->mnemonic,
1702 test->subtests[j].descr,
1703 passed ? "PASS" : "FAIL");
1708 static int __init test_emulate_step(void)
1710 printk(KERN_INFO "Running instruction emulation self-tests ...\n");
1711 run_tests_load_store();
1712 run_tests_compute();
1714 return 0;
1716 late_initcall(test_emulate_step);