1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Test the powerpc alignment handler on POWER8/POWER9 4 * 5 * Copyright (C) 2017 IBM Corporation (Michael Neuling, Andrew Donnellan) 6 */ 7 8 /* 9 * This selftest exercises the powerpc alignment fault handler. 10 * 11 * We create two sets of source and destination buffers, one in regular memory, 12 * the other cache-inhibited (by default we use /dev/fb0 for this, but an 13 * alterative path for cache-inhibited memory may be provided). 14 * 15 * One way to get cache-inhibited memory is to use the "mem" kernel parameter 16 * to limit the kernel to less memory than actually exists. Addresses above 17 * the limit may still be accessed but will be treated as cache-inhibited. For 18 * example, if there is actually 4GB of memory and the parameter "mem=3GB" is 19 * used, memory from address 0xC0000000 onwards is treated as cache-inhibited. 20 * To access this region /dev/mem is used. The kernel should be configured 21 * without CONFIG_STRICT_DEVMEM. In this case use: 22 * ./alignment_handler /dev/mem 0xc0000000 23 * 24 * We initialise the source buffers, then use whichever set of load/store 25 * instructions is under test to copy bytes from the source buffers to the 26 * destination buffers. For the regular buffers, these instructions will 27 * execute normally. For the cache-inhibited buffers, these instructions 28 * will trap and cause an alignment fault, and the alignment fault handler 29 * will emulate the particular instruction under test. We then compare the 30 * destination buffers to ensure that the native and emulated cases give the 31 * same result. 32 * 33 * TODO: 34 * - Any FIXMEs below 35 * - Test VSX regs < 32 and > 32 36 * - Test all loads and stores 37 * - Check update forms do update register 38 * - Test alignment faults over page boundary 39 * 40 * Some old binutils may not support all the instructions. 41 */ 42 43 44 #include <sys/mman.h> 45 #include <sys/types.h> 46 #include <sys/stat.h> 47 #include <fcntl.h> 48 #include <unistd.h> 49 #include <stdbool.h> 50 #include <stdio.h> 51 #include <stdlib.h> 52 #include <string.h> 53 #include <assert.h> 54 #include <getopt.h> 55 #include <setjmp.h> 56 #include <signal.h> 57 58 #include "utils.h" 59 #include "instructions.h" 60 61 int bufsize; 62 int debug; 63 int testing; 64 volatile int gotsig; 65 bool prefixes_enabled; 66 char *cipath = "/dev/fb0"; 67 long cioffset; 68 69 void sighandler(int sig, siginfo_t *info, void *ctx) 70 { 71 ucontext_t *ucp = ctx; 72 73 if (!testing) { 74 signal(sig, SIG_DFL); 75 kill(0, sig); 76 } 77 gotsig = sig; 78 #ifdef __powerpc64__ 79 if (prefixes_enabled) { 80 u32 inst = *(u32 *)ucp->uc_mcontext.gp_regs[PT_NIP]; 81 ucp->uc_mcontext.gp_regs[PT_NIP] += ((inst >> 26 == 1) ? 8 : 4); 82 } else { 83 ucp->uc_mcontext.gp_regs[PT_NIP] += 4; 84 } 85 #else 86 ucp->uc_mcontext.uc_regs->gregs[PT_NIP] += 4; 87 #endif 88 } 89 90 #define XFORM(reg, n) " " #reg " ,%"#n",%2 ;" 91 #define DFORM(reg, n) " " #reg " ,0(%"#n") ;" 92 93 #define TEST(name, ld_op, st_op, form, ld_reg, st_reg) \ 94 void test_##name(char *s, char *d) \ 95 { \ 96 asm volatile( \ 97 #ld_op form(ld_reg, 0) \ 98 #st_op form(st_reg, 1) \ 99 :: "r"(s), "r"(d), "r"(0) \ 100 : "memory", "vs0", "vs32", "r31"); \ 101 } \ 102 rc |= do_test(#name, test_##name) 103 104 #define TESTP(name, ld_op, st_op, ld_reg, st_reg) \ 105 void test_##name(char *s, char *d) \ 106 { \ 107 asm volatile( \ 108 ld_op(ld_reg, %0, 0, 0) \ 109 st_op(st_reg, %1, 0, 0) \ 110 :: "r"(s), "r"(d), "r"(0) \ 111 : "memory", "vs0", "vs32", "r31"); \ 112 } \ 113 rc |= do_test(#name, test_##name) 114 115 #define LOAD_VSX_XFORM_TEST(op) TEST(op, op, stxvd2x, XFORM, 32, 32) 116 #define STORE_VSX_XFORM_TEST(op) TEST(op, lxvd2x, op, XFORM, 32, 32) 117 #define LOAD_VSX_DFORM_TEST(op) TEST(op, op, stxv, DFORM, 32, 32) 118 #define STORE_VSX_DFORM_TEST(op) TEST(op, lxv, op, DFORM, 32, 32) 119 #define LOAD_VMX_XFORM_TEST(op) TEST(op, op, stxvd2x, XFORM, 0, 32) 120 #define STORE_VMX_XFORM_TEST(op) TEST(op, lxvd2x, op, XFORM, 32, 0) 121 #define LOAD_VMX_DFORM_TEST(op) TEST(op, op, stxv, DFORM, 0, 32) 122 #define STORE_VMX_DFORM_TEST(op) TEST(op, lxv, op, DFORM, 32, 0) 123 124 #define LOAD_XFORM_TEST(op) TEST(op, op, stdx, XFORM, 31, 31) 125 #define STORE_XFORM_TEST(op) TEST(op, ldx, op, XFORM, 31, 31) 126 #define LOAD_DFORM_TEST(op) TEST(op, op, std, DFORM, 31, 31) 127 #define STORE_DFORM_TEST(op) TEST(op, ld, op, DFORM, 31, 31) 128 129 #define LOAD_FLOAT_DFORM_TEST(op) TEST(op, op, stfd, DFORM, 0, 0) 130 #define STORE_FLOAT_DFORM_TEST(op) TEST(op, lfd, op, DFORM, 0, 0) 131 #define LOAD_FLOAT_XFORM_TEST(op) TEST(op, op, stfdx, XFORM, 0, 0) 132 #define STORE_FLOAT_XFORM_TEST(op) TEST(op, lfdx, op, XFORM, 0, 0) 133 134 #define LOAD_MLS_PREFIX_TEST(op) TESTP(op, op, PSTD, 31, 31) 135 #define STORE_MLS_PREFIX_TEST(op) TESTP(op, PLD, op, 31, 31) 136 137 #define LOAD_8LS_PREFIX_TEST(op) TESTP(op, op, PSTD, 31, 31) 138 #define STORE_8LS_PREFIX_TEST(op) TESTP(op, PLD, op, 31, 31) 139 140 #define LOAD_FLOAT_MLS_PREFIX_TEST(op) TESTP(op, op, PSTFD, 0, 0) 141 #define STORE_FLOAT_MLS_PREFIX_TEST(op) TESTP(op, PLFD, op, 0, 0) 142 143 #define LOAD_VSX_8LS_PREFIX_TEST(op, tail) TESTP(op, op, PSTXV ## tail, 0, 32) 144 #define STORE_VSX_8LS_PREFIX_TEST(op, tail) TESTP(op, PLXV ## tail, op, 32, 0) 145 146 /* FIXME: Unimplemented tests: */ 147 // STORE_DFORM_TEST(stq) /* FIXME: need two registers for quad */ 148 // STORE_DFORM_TEST(stswi) /* FIXME: string instruction */ 149 150 // STORE_XFORM_TEST(stwat) /* AMO can't emulate or run on CI */ 151 // STORE_XFORM_TEST(stdat) /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ 152 153 154 /* preload byte by byte */ 155 void preload_data(void *dst, int offset, int width) 156 { 157 char *c = dst; 158 int i; 159 160 c += offset; 161 162 for (i = 0 ; i < width ; i++) 163 c[i] = i; 164 } 165 166 int test_memcpy(void *dst, void *src, int size, int offset, 167 void (*test_func)(char *, char *)) 168 { 169 char *s, *d; 170 171 s = src; 172 s += offset; 173 d = dst; 174 d += offset; 175 176 assert(size == 16); 177 gotsig = 0; 178 testing = 1; 179 180 test_func(s, d); /* run the actual test */ 181 182 testing = 0; 183 if (gotsig) { 184 if (debug) 185 printf(" Got signal %i\n", gotsig); 186 return 1; 187 } 188 return 0; 189 } 190 191 void dumpdata(char *s1, char *s2, int n, char *test_name) 192 { 193 int i; 194 195 printf(" %s: unexpected result:\n", test_name); 196 printf(" mem:"); 197 for (i = 0; i < n; i++) 198 printf(" %02x", s1[i]); 199 printf("\n"); 200 printf(" ci: "); 201 for (i = 0; i < n; i++) 202 printf(" %02x", s2[i]); 203 printf("\n"); 204 } 205 206 int test_memcmp(void *s1, void *s2, int n, int offset, char *test_name) 207 { 208 char *s1c, *s2c; 209 210 s1c = s1; 211 s1c += offset; 212 s2c = s2; 213 s2c += offset; 214 215 if (memcmp(s1c, s2c, n)) { 216 if (debug) { 217 printf("\n Compare failed. Offset:%i length:%i\n", 218 offset, n); 219 dumpdata(s1c, s2c, n, test_name); 220 } 221 return 1; 222 } 223 return 0; 224 } 225 226 /* 227 * Do two memcpy tests using the same instructions. One cachable 228 * memory and the other doesn't. 229 */ 230 int do_test(char *test_name, void (*test_func)(char *, char *)) 231 { 232 int offset, width, fd, rc, r; 233 void *mem0, *mem1, *ci0, *ci1; 234 235 printf("\tDoing %s:\t", test_name); 236 237 fd = open(cipath, O_RDWR); 238 if (fd < 0) { 239 printf("\n"); 240 perror("Can't open ci file now?"); 241 return 1; 242 } 243 244 ci0 = mmap(NULL, bufsize, PROT_WRITE | PROT_READ, MAP_SHARED, 245 fd, cioffset); 246 ci1 = mmap(NULL, bufsize, PROT_WRITE | PROT_READ, MAP_SHARED, 247 fd, cioffset + bufsize); 248 249 if ((ci0 == MAP_FAILED) || (ci1 == MAP_FAILED)) { 250 printf("\n"); 251 perror("mmap failed"); 252 SKIP_IF(1); 253 } 254 255 rc = posix_memalign(&mem0, bufsize, bufsize); 256 if (rc) { 257 printf("\n"); 258 return rc; 259 } 260 261 rc = posix_memalign(&mem1, bufsize, bufsize); 262 if (rc) { 263 printf("\n"); 264 free(mem0); 265 return rc; 266 } 267 268 rc = 0; 269 /* 270 * offset = 0 is aligned but tests the workaround for the P9N 271 * DD2.1 vector CI load issue (see 5080332c2c89 "powerpc/64s: 272 * Add workaround for P9 vector CI load issue") 273 */ 274 for (offset = 0; offset < 16; offset++) { 275 width = 16; /* vsx == 16 bytes */ 276 r = 0; 277 278 /* load pattern into memory byte by byte */ 279 preload_data(ci0, offset, width); 280 preload_data(mem0, offset, width); // FIXME: remove?? 281 memcpy(ci0, mem0, bufsize); 282 memcpy(ci1, mem1, bufsize); /* initialise output to the same */ 283 284 /* sanity check */ 285 test_memcmp(mem0, ci0, width, offset, test_name); 286 287 r |= test_memcpy(ci1, ci0, width, offset, test_func); 288 r |= test_memcpy(mem1, mem0, width, offset, test_func); 289 if (r && !debug) { 290 printf("FAILED: Got signal"); 291 rc = 1; 292 break; 293 } 294 295 r |= test_memcmp(mem1, ci1, width, offset, test_name); 296 if (r && !debug) { 297 printf("FAILED: Wrong Data"); 298 rc = 1; 299 break; 300 } 301 } 302 303 if (rc == 0) 304 printf("PASSED"); 305 306 printf("\n"); 307 308 munmap(ci0, bufsize); 309 munmap(ci1, bufsize); 310 free(mem0); 311 free(mem1); 312 close(fd); 313 314 return rc; 315 } 316 317 static bool can_open_cifile(void) 318 { 319 int fd; 320 321 fd = open(cipath, O_RDWR); 322 if (fd < 0) 323 return false; 324 325 close(fd); 326 return true; 327 } 328 329 int test_alignment_handler_vsx_206(void) 330 { 331 int rc = 0; 332 333 SKIP_IF(!can_open_cifile()); 334 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 335 336 printf("VSX: 2.06B\n"); 337 LOAD_VSX_XFORM_TEST(lxvd2x); 338 LOAD_VSX_XFORM_TEST(lxvw4x); 339 LOAD_VSX_XFORM_TEST(lxsdx); 340 LOAD_VSX_XFORM_TEST(lxvdsx); 341 STORE_VSX_XFORM_TEST(stxvd2x); 342 STORE_VSX_XFORM_TEST(stxvw4x); 343 STORE_VSX_XFORM_TEST(stxsdx); 344 return rc; 345 } 346 347 int test_alignment_handler_vsx_207(void) 348 { 349 int rc = 0; 350 351 SKIP_IF(!can_open_cifile()); 352 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_2_07)); 353 354 printf("VSX: 2.07B\n"); 355 LOAD_VSX_XFORM_TEST(lxsspx); 356 LOAD_VSX_XFORM_TEST(lxsiwax); 357 LOAD_VSX_XFORM_TEST(lxsiwzx); 358 STORE_VSX_XFORM_TEST(stxsspx); 359 STORE_VSX_XFORM_TEST(stxsiwx); 360 return rc; 361 } 362 363 int test_alignment_handler_vsx_300(void) 364 { 365 int rc = 0; 366 367 SKIP_IF(!can_open_cifile()); 368 369 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00)); 370 printf("VSX: 3.00B\n"); 371 LOAD_VMX_DFORM_TEST(lxsd); 372 LOAD_VSX_XFORM_TEST(lxsibzx); 373 LOAD_VSX_XFORM_TEST(lxsihzx); 374 LOAD_VMX_DFORM_TEST(lxssp); 375 LOAD_VSX_DFORM_TEST(lxv); 376 LOAD_VSX_XFORM_TEST(lxvb16x); 377 LOAD_VSX_XFORM_TEST(lxvh8x); 378 LOAD_VSX_XFORM_TEST(lxvx); 379 LOAD_VSX_XFORM_TEST(lxvwsx); 380 LOAD_VSX_XFORM_TEST(lxvl); 381 LOAD_VSX_XFORM_TEST(lxvll); 382 STORE_VMX_DFORM_TEST(stxsd); 383 STORE_VSX_XFORM_TEST(stxsibx); 384 STORE_VSX_XFORM_TEST(stxsihx); 385 STORE_VMX_DFORM_TEST(stxssp); 386 STORE_VSX_DFORM_TEST(stxv); 387 STORE_VSX_XFORM_TEST(stxvb16x); 388 STORE_VSX_XFORM_TEST(stxvh8x); 389 STORE_VSX_XFORM_TEST(stxvx); 390 STORE_VSX_XFORM_TEST(stxvl); 391 STORE_VSX_XFORM_TEST(stxvll); 392 return rc; 393 } 394 395 int test_alignment_handler_vsx_prefix(void) 396 { 397 int rc = 0; 398 399 SKIP_IF(!can_open_cifile()); 400 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 401 402 printf("VSX: PREFIX\n"); 403 LOAD_VSX_8LS_PREFIX_TEST(PLXSD, 0); 404 LOAD_VSX_8LS_PREFIX_TEST(PLXSSP, 0); 405 LOAD_VSX_8LS_PREFIX_TEST(PLXV0, 0); 406 LOAD_VSX_8LS_PREFIX_TEST(PLXV1, 1); 407 STORE_VSX_8LS_PREFIX_TEST(PSTXSD, 0); 408 STORE_VSX_8LS_PREFIX_TEST(PSTXSSP, 0); 409 STORE_VSX_8LS_PREFIX_TEST(PSTXV0, 0); 410 STORE_VSX_8LS_PREFIX_TEST(PSTXV1, 1); 411 return rc; 412 } 413 414 int test_alignment_handler_integer(void) 415 { 416 int rc = 0; 417 418 SKIP_IF(!can_open_cifile()); 419 420 printf("Integer\n"); 421 LOAD_DFORM_TEST(lbz); 422 LOAD_DFORM_TEST(lbzu); 423 LOAD_XFORM_TEST(lbzx); 424 LOAD_XFORM_TEST(lbzux); 425 LOAD_DFORM_TEST(lhz); 426 LOAD_DFORM_TEST(lhzu); 427 LOAD_XFORM_TEST(lhzx); 428 LOAD_XFORM_TEST(lhzux); 429 LOAD_DFORM_TEST(lha); 430 LOAD_DFORM_TEST(lhau); 431 LOAD_XFORM_TEST(lhax); 432 LOAD_XFORM_TEST(lhaux); 433 LOAD_XFORM_TEST(lhbrx); 434 LOAD_DFORM_TEST(lwz); 435 LOAD_DFORM_TEST(lwzu); 436 LOAD_XFORM_TEST(lwzx); 437 LOAD_XFORM_TEST(lwzux); 438 LOAD_DFORM_TEST(lwa); 439 LOAD_XFORM_TEST(lwax); 440 LOAD_XFORM_TEST(lwaux); 441 LOAD_XFORM_TEST(lwbrx); 442 LOAD_DFORM_TEST(ld); 443 LOAD_DFORM_TEST(ldu); 444 LOAD_XFORM_TEST(ldx); 445 LOAD_XFORM_TEST(ldux); 446 LOAD_DFORM_TEST(lmw); 447 STORE_DFORM_TEST(stb); 448 STORE_XFORM_TEST(stbx); 449 STORE_DFORM_TEST(stbu); 450 STORE_XFORM_TEST(stbux); 451 STORE_DFORM_TEST(sth); 452 STORE_XFORM_TEST(sthx); 453 STORE_DFORM_TEST(sthu); 454 STORE_XFORM_TEST(sthux); 455 STORE_XFORM_TEST(sthbrx); 456 STORE_DFORM_TEST(stw); 457 STORE_XFORM_TEST(stwx); 458 STORE_DFORM_TEST(stwu); 459 STORE_XFORM_TEST(stwux); 460 STORE_XFORM_TEST(stwbrx); 461 STORE_DFORM_TEST(std); 462 STORE_XFORM_TEST(stdx); 463 STORE_DFORM_TEST(stdu); 464 STORE_XFORM_TEST(stdux); 465 STORE_DFORM_TEST(stmw); 466 467 return rc; 468 } 469 470 int test_alignment_handler_integer_206(void) 471 { 472 int rc = 0; 473 474 SKIP_IF(!can_open_cifile()); 475 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 476 477 printf("Integer: 2.06\n"); 478 479 LOAD_XFORM_TEST(ldbrx); 480 STORE_XFORM_TEST(stdbrx); 481 482 return rc; 483 } 484 485 int test_alignment_handler_integer_prefix(void) 486 { 487 int rc = 0; 488 489 SKIP_IF(!can_open_cifile()); 490 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 491 492 printf("Integer: PREFIX\n"); 493 LOAD_MLS_PREFIX_TEST(PLBZ); 494 LOAD_MLS_PREFIX_TEST(PLHZ); 495 LOAD_MLS_PREFIX_TEST(PLHA); 496 LOAD_MLS_PREFIX_TEST(PLWZ); 497 LOAD_8LS_PREFIX_TEST(PLWA); 498 LOAD_8LS_PREFIX_TEST(PLD); 499 STORE_MLS_PREFIX_TEST(PSTB); 500 STORE_MLS_PREFIX_TEST(PSTH); 501 STORE_MLS_PREFIX_TEST(PSTW); 502 STORE_8LS_PREFIX_TEST(PSTD); 503 return rc; 504 } 505 506 int test_alignment_handler_vmx(void) 507 { 508 int rc = 0; 509 510 SKIP_IF(!can_open_cifile()); 511 SKIP_IF(!have_hwcap(PPC_FEATURE_HAS_ALTIVEC)); 512 513 printf("VMX\n"); 514 LOAD_VMX_XFORM_TEST(lvx); 515 516 /* 517 * FIXME: These loads only load part of the register, so our 518 * testing method doesn't work. Also they don't take alignment 519 * faults, so it's kinda pointless anyway 520 * 521 LOAD_VMX_XFORM_TEST(lvebx) 522 LOAD_VMX_XFORM_TEST(lvehx) 523 LOAD_VMX_XFORM_TEST(lvewx) 524 LOAD_VMX_XFORM_TEST(lvxl) 525 */ 526 STORE_VMX_XFORM_TEST(stvx); 527 STORE_VMX_XFORM_TEST(stvebx); 528 STORE_VMX_XFORM_TEST(stvehx); 529 STORE_VMX_XFORM_TEST(stvewx); 530 STORE_VMX_XFORM_TEST(stvxl); 531 return rc; 532 } 533 534 int test_alignment_handler_fp(void) 535 { 536 int rc = 0; 537 538 SKIP_IF(!can_open_cifile()); 539 540 printf("Floating point\n"); 541 LOAD_FLOAT_DFORM_TEST(lfd); 542 LOAD_FLOAT_XFORM_TEST(lfdx); 543 LOAD_FLOAT_DFORM_TEST(lfdu); 544 LOAD_FLOAT_XFORM_TEST(lfdux); 545 LOAD_FLOAT_DFORM_TEST(lfs); 546 LOAD_FLOAT_XFORM_TEST(lfsx); 547 LOAD_FLOAT_DFORM_TEST(lfsu); 548 LOAD_FLOAT_XFORM_TEST(lfsux); 549 STORE_FLOAT_DFORM_TEST(stfd); 550 STORE_FLOAT_XFORM_TEST(stfdx); 551 STORE_FLOAT_DFORM_TEST(stfdu); 552 STORE_FLOAT_XFORM_TEST(stfdux); 553 STORE_FLOAT_DFORM_TEST(stfs); 554 STORE_FLOAT_XFORM_TEST(stfsx); 555 STORE_FLOAT_DFORM_TEST(stfsu); 556 STORE_FLOAT_XFORM_TEST(stfsux); 557 STORE_FLOAT_XFORM_TEST(stfiwx); 558 559 return rc; 560 } 561 562 int test_alignment_handler_fp_205(void) 563 { 564 int rc = 0; 565 566 SKIP_IF(!can_open_cifile()); 567 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_05)); 568 569 printf("Floating point: 2.05\n"); 570 571 LOAD_FLOAT_DFORM_TEST(lfdp); 572 LOAD_FLOAT_XFORM_TEST(lfdpx); 573 LOAD_FLOAT_XFORM_TEST(lfiwax); 574 STORE_FLOAT_DFORM_TEST(stfdp); 575 STORE_FLOAT_XFORM_TEST(stfdpx); 576 577 return rc; 578 } 579 580 int test_alignment_handler_fp_206(void) 581 { 582 int rc = 0; 583 584 SKIP_IF(!can_open_cifile()); 585 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06)); 586 587 printf("Floating point: 2.06\n"); 588 589 LOAD_FLOAT_XFORM_TEST(lfiwzx); 590 591 return rc; 592 } 593 594 595 int test_alignment_handler_fp_prefix(void) 596 { 597 int rc = 0; 598 599 SKIP_IF(!can_open_cifile()); 600 SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_1)); 601 602 printf("Floating point: PREFIX\n"); 603 LOAD_FLOAT_DFORM_TEST(lfs); 604 LOAD_FLOAT_MLS_PREFIX_TEST(PLFS); 605 LOAD_FLOAT_MLS_PREFIX_TEST(PLFD); 606 STORE_FLOAT_MLS_PREFIX_TEST(PSTFS); 607 STORE_FLOAT_MLS_PREFIX_TEST(PSTFD); 608 return rc; 609 } 610 611 void usage(char *prog) 612 { 613 printf("Usage: %s [options] [path [offset]]\n", prog); 614 printf(" -d Enable debug error output\n"); 615 printf("\n"); 616 printf("This test requires a POWER8, POWER9 or POWER10 CPU "); 617 printf("and either a usable framebuffer at /dev/fb0 or "); 618 printf("the path to usable cache inhibited memory and optional "); 619 printf("offset to be provided\n"); 620 } 621 622 int main(int argc, char *argv[]) 623 { 624 625 struct sigaction sa; 626 int rc = 0; 627 int option = 0; 628 629 while ((option = getopt(argc, argv, "d")) != -1) { 630 switch (option) { 631 case 'd': 632 debug++; 633 break; 634 default: 635 usage(argv[0]); 636 exit(1); 637 } 638 } 639 argc -= optind; 640 argv += optind; 641 642 if (argc > 0) 643 cipath = argv[0]; 644 if (argc > 1) 645 cioffset = strtol(argv[1], 0, 0x10); 646 647 bufsize = getpagesize(); 648 649 sa.sa_sigaction = sighandler; 650 sigemptyset(&sa.sa_mask); 651 sa.sa_flags = SA_SIGINFO; 652 if (sigaction(SIGSEGV, &sa, NULL) == -1 653 || sigaction(SIGBUS, &sa, NULL) == -1 654 || sigaction(SIGILL, &sa, NULL) == -1) { 655 perror("sigaction"); 656 exit(1); 657 } 658 659 prefixes_enabled = have_hwcap2(PPC_FEATURE2_ARCH_3_1); 660 661 rc |= test_harness(test_alignment_handler_vsx_206, 662 "test_alignment_handler_vsx_206"); 663 rc |= test_harness(test_alignment_handler_vsx_207, 664 "test_alignment_handler_vsx_207"); 665 rc |= test_harness(test_alignment_handler_vsx_300, 666 "test_alignment_handler_vsx_300"); 667 rc |= test_harness(test_alignment_handler_vsx_prefix, 668 "test_alignment_handler_vsx_prefix"); 669 rc |= test_harness(test_alignment_handler_integer, 670 "test_alignment_handler_integer"); 671 rc |= test_harness(test_alignment_handler_integer_206, 672 "test_alignment_handler_integer_206"); 673 rc |= test_harness(test_alignment_handler_integer_prefix, 674 "test_alignment_handler_integer_prefix"); 675 rc |= test_harness(test_alignment_handler_vmx, 676 "test_alignment_handler_vmx"); 677 rc |= test_harness(test_alignment_handler_fp, 678 "test_alignment_handler_fp"); 679 rc |= test_harness(test_alignment_handler_fp_205, 680 "test_alignment_handler_fp_205"); 681 rc |= test_harness(test_alignment_handler_fp_206, 682 "test_alignment_handler_fp_206"); 683 rc |= test_harness(test_alignment_handler_fp_prefix, 684 "test_alignment_handler_fp_prefix"); 685 return rc; 686 } 687