ptrace-tm-spd-vsx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Ptrace test for VMX/VSX registers in the TM Suspend context
  3. *
  4. * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include "ptrace.h"
  12. #include "tm.h"
  13. #include "ptrace-vsx.h"
  14. int shm_id;
  15. int *cptr, *pptr;
  16. unsigned long fp_load[VEC_MAX];
  17. unsigned long fp_load_new[VEC_MAX];
  18. unsigned long fp_store[VEC_MAX];
  19. unsigned long fp_load_ckpt[VEC_MAX];
  20. unsigned long fp_load_ckpt_new[VEC_MAX];
  21. __attribute__((used)) void load_vsx(void)
  22. {
  23. loadvsx(fp_load, 0);
  24. }
  25. __attribute__((used)) void load_vsx_new(void)
  26. {
  27. loadvsx(fp_load_new, 0);
  28. }
  29. __attribute__((used)) void load_vsx_ckpt(void)
  30. {
  31. loadvsx(fp_load_ckpt, 0);
  32. }
  33. __attribute__((used)) void wait_parent(void)
  34. {
  35. cptr[2] = 1;
  36. while (!cptr[1])
  37. asm volatile("" : : : "memory");
  38. }
  39. void tm_spd_vsx(void)
  40. {
  41. unsigned long result, texasr;
  42. int ret;
  43. cptr = (int *)shmat(shm_id, NULL, 0);
  44. trans:
  45. cptr[2] = 0;
  46. asm __volatile__(
  47. "bl load_vsx_ckpt;"
  48. "1: ;"
  49. "tbegin.;"
  50. "beq 2f;"
  51. "bl load_vsx_new;"
  52. "tsuspend.;"
  53. "bl load_vsx;"
  54. "bl wait_parent;"
  55. "tresume.;"
  56. "tend.;"
  57. "li 0, 0;"
  58. "ori %[res], 0, 0;"
  59. "b 3f;"
  60. "2: ;"
  61. "li 0, 1;"
  62. "ori %[res], 0, 0;"
  63. "mfspr %[texasr], %[sprn_texasr];"
  64. "3: ;"
  65. : [res] "=r" (result), [texasr] "=r" (texasr)
  66. : [fp_load] "r" (fp_load), [fp_load_ckpt] "r" (fp_load_ckpt),
  67. [sprn_texasr] "i" (SPRN_TEXASR)
  68. : "memory", "r0", "r1", "r2", "r3", "r4",
  69. "r8", "r9", "r10", "r11"
  70. );
  71. if (result) {
  72. if (!cptr[0])
  73. goto trans;
  74. shmdt((void *)cptr);
  75. storevsx(fp_store, 0);
  76. ret = compare_vsx_vmx(fp_store, fp_load_ckpt_new);
  77. if (ret)
  78. exit(1);
  79. exit(0);
  80. }
  81. shmdt((void *)cptr);
  82. exit(1);
  83. }
  84. int trace_tm_spd_vsx(pid_t child)
  85. {
  86. unsigned long vsx[VSX_MAX];
  87. unsigned long vmx[VMX_MAX + 2][2];
  88. FAIL_IF(start_trace(child));
  89. FAIL_IF(show_vsx(child, vsx));
  90. FAIL_IF(validate_vsx(vsx, fp_load));
  91. FAIL_IF(show_vmx(child, vmx));
  92. FAIL_IF(validate_vmx(vmx, fp_load));
  93. FAIL_IF(show_vsx_ckpt(child, vsx));
  94. FAIL_IF(validate_vsx(vsx, fp_load_ckpt));
  95. FAIL_IF(show_vmx_ckpt(child, vmx));
  96. FAIL_IF(validate_vmx(vmx, fp_load_ckpt));
  97. memset(vsx, 0, sizeof(vsx));
  98. memset(vmx, 0, sizeof(vmx));
  99. load_vsx_vmx(fp_load_ckpt_new, vsx, vmx);
  100. FAIL_IF(write_vsx_ckpt(child, vsx));
  101. FAIL_IF(write_vmx_ckpt(child, vmx));
  102. pptr[0] = 1;
  103. pptr[1] = 1;
  104. FAIL_IF(stop_trace(child));
  105. return TEST_PASS;
  106. }
  107. int ptrace_tm_spd_vsx(void)
  108. {
  109. pid_t pid;
  110. int ret, status, i;
  111. SKIP_IF(!have_htm());
  112. shm_id = shmget(IPC_PRIVATE, sizeof(int) * 3, 0777|IPC_CREAT);
  113. for (i = 0; i < 128; i++) {
  114. fp_load[i] = 1 + rand();
  115. fp_load_new[i] = 1 + 2 * rand();
  116. fp_load_ckpt[i] = 1 + 3 * rand();
  117. fp_load_ckpt_new[i] = 1 + 4 * rand();
  118. }
  119. pid = fork();
  120. if (pid < 0) {
  121. perror("fork() failed");
  122. return TEST_FAIL;
  123. }
  124. if (pid == 0)
  125. tm_spd_vsx();
  126. if (pid) {
  127. pptr = (int *)shmat(shm_id, NULL, 0);
  128. while (!pptr[2])
  129. asm volatile("" : : : "memory");
  130. ret = trace_tm_spd_vsx(pid);
  131. if (ret) {
  132. kill(pid, SIGKILL);
  133. shmdt((void *)pptr);
  134. shmctl(shm_id, IPC_RMID, NULL);
  135. return TEST_FAIL;
  136. }
  137. shmdt((void *)pptr);
  138. ret = wait(&status);
  139. shmctl(shm_id, IPC_RMID, NULL);
  140. if (ret != pid) {
  141. printf("Child's exit status not captured\n");
  142. return TEST_FAIL;
  143. }
  144. return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
  145. TEST_PASS;
  146. }
  147. return TEST_PASS;
  148. }
  149. int main(int argc, char *argv[])
  150. {
  151. return test_harness(ptrace_tm_spd_vsx, "ptrace_tm_spd_vsx");
  152. }