1 // SPDX-License-Identifier: GPL-2.0-only 2 3 #include "../../kselftest.h" 4 #define MAX_VSIZE (8192 * 32) 5 6 void dump(char *ptr, int size) 7 { 8 int i = 0; 9 10 for (i = 0; i < size; i++) { 11 if (i != 0) { 12 if (i % 16 == 0) 13 printf("\n"); 14 else if (i % 8 == 0) 15 printf(" "); 16 } 17 printf("%02x ", ptr[i]); 18 } 19 printf("\n"); 20 } 21 22 int main(void) 23 { 24 int i; 25 unsigned long vl; 26 char *datap, *tmp; 27 28 ksft_set_plan(1); 29 30 datap = malloc(MAX_VSIZE); 31 if (!datap) { 32 ksft_test_result_fail("fail to allocate memory for size = %d\n", MAX_VSIZE); 33 exit(-1); 34 } 35 36 tmp = datap; 37 asm volatile ( 38 ".option push\n\t" 39 ".option arch, +v\n\t" 40 "vsetvli %0, x0, e8, m8, ta, ma\n\t" 41 "vse8.v v0, (%2)\n\t" 42 "add %1, %2, %0\n\t" 43 "vse8.v v8, (%1)\n\t" 44 "add %1, %1, %0\n\t" 45 "vse8.v v16, (%1)\n\t" 46 "add %1, %1, %0\n\t" 47 "vse8.v v24, (%1)\n\t" 48 ".option pop\n\t" 49 : "=&r" (vl), "=r" (tmp) : "r" (datap) : "memory"); 50 51 ksft_print_msg("vl = %lu\n", vl); 52 53 if (datap[0] != 0x00 && datap[0] != 0xff) { 54 ksft_test_result_fail("v-regesters are not properly initialized\n"); 55 dump(datap, vl * 4); 56 exit(-1); 57 } 58 59 for (i = 1; i < vl * 4; i++) { 60 if (datap[i] != datap[0]) { 61 ksft_test_result_fail("detect stale values on v-regesters\n"); 62 dump(datap, vl * 4); 63 exit(-2); 64 } 65 } 66 67 free(datap); 68 69 ksft_test_result_pass("tests for v_initval_nolibc pass\n"); 70 ksft_exit_pass(); 71 return 0; 72 } 73