~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Ptrace test for GPR/FPR registers in TM context
  4  *
  5  * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
  6  */
  7 #include "ptrace.h"
  8 #include "ptrace-gpr.h"
  9 #include "tm.h"
 10 
 11 /* Tracer and Tracee Shared Data */
 12 int shm_id;
 13 unsigned long *cptr, *pptr;
 14 
 15 float a = FPR_1;
 16 float b = FPR_2;
 17 float c = FPR_3;
 18 
 19 void tm_gpr(void)
 20 {
 21         unsigned long gpr_buf[18];
 22         unsigned long result, texasr;
 23         float fpr_buf[32];
 24 
 25         printf("Starting the child\n");
 26         cptr = (unsigned long *)shmat(shm_id, NULL, 0);
 27 
 28 trans:
 29         cptr[1] = 0;
 30         asm __volatile__(
 31                 ASM_LOAD_GPR_IMMED(gpr_1)
 32                 ASM_LOAD_FPR_SINGLE_PRECISION(flt_1)
 33                 "1: ;"
 34                 "tbegin.;"
 35                 "beq 2f;"
 36                 ASM_LOAD_GPR_IMMED(gpr_2)
 37                 ASM_LOAD_FPR_SINGLE_PRECISION(flt_2)
 38                 "tsuspend.;"
 39                 "li 7, 1;"
 40                 "stw 7, 0(%[cptr1]);"
 41                 "tresume.;"
 42                 "b .;"
 43 
 44                 "tend.;"
 45                 "li 0, 0;"
 46                 "ori %[res], 0, 0;"
 47                 "b 3f;"
 48 
 49                 /* Transaction abort handler */
 50                 "2: ;"
 51                 "li 0, 1;"
 52                 "ori %[res], 0, 0;"
 53                 "mfspr %[texasr], %[sprn_texasr];"
 54 
 55                 "3: ;"
 56                 : [res] "=r" (result), [texasr] "=r" (texasr)
 57                 : [gpr_1]"i"(GPR_1), [gpr_2]"i"(GPR_2),
 58                 [sprn_texasr] "i" (SPRN_TEXASR), [flt_1] "b" (&a),
 59                 [flt_2] "b" (&b), [cptr1] "b" (&cptr[1])
 60                 : "memory", "r7", "r8", "r9", "r10",
 61                 "r11", "r12", "r13", "r14", "r15", "r16",
 62                 "r17", "r18", "r19", "r20", "r21", "r22",
 63                 "r23", "r24", "r25", "r26", "r27", "r28",
 64                 "r29", "r30", "r31"
 65                 );
 66 
 67         if (result) {
 68                 if (!cptr[0])
 69                         goto trans;
 70 
 71                 shmdt((void *)cptr);
 72                 store_gpr(gpr_buf);
 73                 store_fpr_single_precision(fpr_buf);
 74 
 75                 if (validate_gpr(gpr_buf, GPR_3))
 76                         exit(1);
 77 
 78                 if (validate_fpr_float(fpr_buf, c))
 79                         exit(1);
 80 
 81                 exit(0);
 82         }
 83         shmdt((void *)cptr);
 84         exit(1);
 85 }
 86 
 87 int trace_tm_gpr(pid_t child)
 88 {
 89         unsigned long gpr[18];
 90         unsigned long fpr[32];
 91 
 92         FAIL_IF(start_trace(child));
 93         FAIL_IF(show_gpr(child, gpr));
 94         FAIL_IF(validate_gpr(gpr, GPR_2));
 95         FAIL_IF(show_fpr(child, fpr));
 96         FAIL_IF(validate_fpr(fpr, FPR_2_REP));
 97         FAIL_IF(show_ckpt_fpr(child, fpr));
 98         FAIL_IF(validate_fpr(fpr, FPR_1_REP));
 99         FAIL_IF(show_ckpt_gpr(child, gpr));
100         FAIL_IF(validate_gpr(gpr, GPR_1));
101         FAIL_IF(write_ckpt_gpr(child, GPR_3));
102         FAIL_IF(write_ckpt_fpr(child, FPR_3_REP));
103 
104         pptr[0] = 1;
105         FAIL_IF(stop_trace(child));
106 
107         return TEST_PASS;
108 }
109 
110 int ptrace_tm_gpr(void)
111 {
112         pid_t pid;
113         int ret, status;
114 
115         SKIP_IF(!have_htm());
116         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
117         pid = fork();
118         if (pid < 0) {
119                 perror("fork() failed");
120                 return TEST_FAIL;
121         }
122         if (pid == 0)
123                 tm_gpr();
124 
125         if (pid) {
126                 pptr = (unsigned long *)shmat(shm_id, NULL, 0);
127 
128                 while (!pptr[1])
129                         asm volatile("" : : : "memory");
130                 ret = trace_tm_gpr(pid);
131                 if (ret) {
132                         kill(pid, SIGTERM);
133                         return TEST_FAIL;
134                 }
135 
136                 shmdt((void *)pptr);
137 
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 
145                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
146                         TEST_PASS;
147         }
148         return TEST_PASS;
149 }
150 
151 int main(int argc, char *argv[])
152 {
153         return test_harness(ptrace_tm_gpr, "ptrace_tm_gpr");
154 }
155 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp