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

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

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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 /*
  2  * Ptrace test for GPR/FPR registers in 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 "ptrace-gpr.h"
 13 #include "tm.h"
 14 
 15 /* Tracer and Tracee Shared Data */
 16 int shm_id;
 17 int *cptr, *pptr;
 18 
 19 float a = FPR_1;
 20 float b = FPR_2;
 21 float c = FPR_3;
 22 float d = FPR_4;
 23 
 24 __attribute__((used)) void wait_parent(void)
 25 {
 26         cptr[2] = 1;
 27         while (!cptr[1])
 28                 asm volatile("" : : : "memory");
 29 }
 30 
 31 void tm_spd_gpr(void)
 32 {
 33         unsigned long gpr_buf[18];
 34         unsigned long result, texasr;
 35         float fpr_buf[32];
 36 
 37         cptr = (int *)shmat(shm_id, NULL, 0);
 38 
 39 trans:
 40         cptr[2] = 0;
 41         asm __volatile__(
 42                 ASM_LOAD_GPR_IMMED(gpr_1)
 43                 ASM_LOAD_FPR_SINGLE_PRECISION(flt_1)
 44 
 45                 "1: ;"
 46                 "tbegin.;"
 47                 "beq 2f;"
 48 
 49                 ASM_LOAD_GPR_IMMED(gpr_2)
 50                 "tsuspend.;"
 51                 ASM_LOAD_GPR_IMMED(gpr_4)
 52                 ASM_LOAD_FPR_SINGLE_PRECISION(flt_4)
 53 
 54                 "bl wait_parent;"
 55                 "tresume.;"
 56                 "tend.;"
 57                 "li 0, 0;"
 58                 "ori %[res], 0, 0;"
 59                 "b 3f;"
 60 
 61                 /* Transaction abort handler */
 62                 "2: ;"
 63                 "li 0, 1;"
 64                 "ori %[res], 0, 0;"
 65                 "mfspr %[texasr], %[sprn_texasr];"
 66 
 67                 "3: ;"
 68                 : [res] "=r" (result), [texasr] "=r" (texasr)
 69                 : [gpr_1]"i"(GPR_1), [gpr_2]"i"(GPR_2), [gpr_4]"i"(GPR_4),
 70                 [sprn_texasr] "i" (SPRN_TEXASR), [flt_1] "r" (&a),
 71                 [flt_2] "r" (&b), [flt_4] "r" (&d)
 72                 : "memory", "r5", "r6", "r7",
 73                 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
 74                 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
 75                 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
 76                 );
 77 
 78         if (result) {
 79                 if (!cptr[0])
 80                         goto trans;
 81 
 82                 shmdt((void *)cptr);
 83                 store_gpr(gpr_buf);
 84                 store_fpr_single_precision(fpr_buf);
 85 
 86                 if (validate_gpr(gpr_buf, GPR_3))
 87                         exit(1);
 88 
 89                 if (validate_fpr_float(fpr_buf, c))
 90                         exit(1);
 91                 exit(0);
 92         }
 93         shmdt((void *)cptr);
 94         exit(1);
 95 }
 96 
 97 int trace_tm_spd_gpr(pid_t child)
 98 {
 99         unsigned long gpr[18];
100         unsigned long fpr[32];
101 
102         FAIL_IF(start_trace(child));
103         FAIL_IF(show_gpr(child, gpr));
104         FAIL_IF(validate_gpr(gpr, GPR_4));
105         FAIL_IF(show_fpr(child, fpr));
106         FAIL_IF(validate_fpr(fpr, FPR_4_REP));
107         FAIL_IF(show_ckpt_fpr(child, fpr));
108         FAIL_IF(validate_fpr(fpr, FPR_1_REP));
109         FAIL_IF(show_ckpt_gpr(child, gpr));
110         FAIL_IF(validate_gpr(gpr, GPR_1));
111         FAIL_IF(write_ckpt_gpr(child, GPR_3));
112         FAIL_IF(write_ckpt_fpr(child, FPR_3_REP));
113 
114         pptr[0] = 1;
115         pptr[1] = 1;
116         FAIL_IF(stop_trace(child));
117         return TEST_PASS;
118 }
119 
120 int ptrace_tm_spd_gpr(void)
121 {
122         pid_t pid;
123         int ret, status;
124 
125         SKIP_IF(!have_htm());
126         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 3, 0777|IPC_CREAT);
127         pid = fork();
128         if (pid < 0) {
129                 perror("fork() failed");
130                 return TEST_FAIL;
131         }
132 
133         if (pid == 0)
134                 tm_spd_gpr();
135 
136         if (pid) {
137                 pptr = (int *)shmat(shm_id, NULL, 0);
138                 pptr[0] = 0;
139                 pptr[1] = 0;
140 
141                 while (!pptr[2])
142                         asm volatile("" : : : "memory");
143                 ret = trace_tm_spd_gpr(pid);
144                 if (ret) {
145                         kill(pid, SIGTERM);
146                         shmdt((void *)pptr);
147                         shmctl(shm_id, IPC_RMID, NULL);
148                         return TEST_FAIL;
149                 }
150 
151                 shmdt((void *)pptr);
152 
153                 ret = wait(&status);
154                 shmctl(shm_id, IPC_RMID, NULL);
155                 if (ret != pid) {
156                         printf("Child's exit status not captured\n");
157                         return TEST_FAIL;
158                 }
159 
160                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
161                         TEST_PASS;
162         }
163         return TEST_PASS;
164 }
165 
166 int main(int argc, char *argv[])
167 {
168         return test_harness(ptrace_tm_spd_gpr, "ptrace_tm_spd_gpr");
169 }
170 

~ [ 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