This source file includes following definitions.
- signal_usr1
- tm_signal_context_chk
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <signal.h>
24 #include <unistd.h>
25
26 #include <altivec.h>
27
28 #include "utils.h"
29 #include "tm.h"
30
31 #define MAX_ATTEMPT 500000
32
33 #define NV_VSX_REGS 12
34 #define VSX20 20
35 #define FPR20 20
36
37 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
38
39 static sig_atomic_t fail, broken;
40
41
42 vector int vsxs[] = {
43
44
45 { 1, 2, 3, 4},{ 5, 6, 7, 8},{ 9,10,11,12},
46 {13,14,15,16},{17,18,19,20},{21,22,23,24},
47 {25,26,27,28},{29,30,31,32},{33,34,35,36},
48 {37,38,39,40},{41,42,43,44},{45,46,47,48},
49
50
51 {-1, -2, -3, -4 },{-5, -6, -7, -8 },{-9, -10,-11,-12},
52 {-13,-14,-15,-16},{-17,-18,-19,-20},{-21,-22,-23,-24},
53 {-25,-26,-27,-28},{-29,-30,-31,-32},{-33,-34,-35,-36},
54 {-37,-38,-39,-40},{-41,-42,-43,-44},{-45,-46,-47,-48}
55 };
56
57 static void signal_usr1(int signum, siginfo_t *info, void *uc)
58 {
59 int i, j;
60 uint8_t vsx[sizeof(vector int)];
61 uint8_t vsx_tm[sizeof(vector int)];
62 ucontext_t *ucp = uc;
63 ucontext_t *tm_ucp = ucp->uc_link;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 long *vsx_ptr = (long *)(ucp->uc_mcontext.v_regs + 1);
97 long *tm_vsx_ptr = (long *)(tm_ucp->uc_mcontext.v_regs + 1);
98
99
100 for (i = 0; i < NV_VSX_REGS; i++) {
101
102
103
104
105
106 memcpy(vsx, &ucp->uc_mcontext.fp_regs[FPR20 + i], 8);
107 memcpy(vsx + 8, &vsx_ptr[VSX20 + i], 8);
108
109 fail = memcmp(vsx, &vsxs[i], sizeof(vector int));
110
111 if (fail) {
112 broken = 1;
113 printf("VSX%d (1st context) == 0x", VSX20 + i);
114 for (j = 0; j < 16; j++)
115 printf("%02x", vsx[j]);
116 printf(" instead of 0x");
117 for (j = 0; j < 4; j++)
118 printf("%08x", vsxs[i][j]);
119 printf(" (expected)\n");
120 }
121 }
122
123
124 for (i = 0; i < NV_VSX_REGS; i++) {
125
126
127
128
129
130 memcpy(vsx_tm, &tm_ucp->uc_mcontext.fp_regs[FPR20 + i], 8);
131 memcpy(vsx_tm + 8, &tm_vsx_ptr[VSX20 + i], 8);
132
133 fail = memcmp(vsx_tm, &vsxs[NV_VSX_REGS + i], sizeof(vector int));
134
135 if (fail) {
136 broken = 1;
137 printf("VSX%d (2nd context) == 0x", VSX20 + i);
138 for (j = 0; j < 16; j++)
139 printf("%02x", vsx_tm[j]);
140 printf(" instead of 0x");
141 for (j = 0; j < 4; j++)
142 printf("%08x", vsxs[NV_VSX_REGS + i][j]);
143 printf("(expected)\n");
144 }
145 }
146 }
147
148 static int tm_signal_context_chk()
149 {
150 struct sigaction act;
151 int i;
152 long rc;
153 pid_t pid = getpid();
154
155 SKIP_IF(!have_htm());
156
157 act.sa_sigaction = signal_usr1;
158 sigemptyset(&act.sa_mask);
159 act.sa_flags = SA_SIGINFO;
160 if (sigaction(SIGUSR1, &act, NULL) < 0) {
161 perror("sigaction sigusr1");
162 exit(1);
163 }
164
165 i = 0;
166 while (i < MAX_ATTEMPT && !broken) {
167
168
169
170
171
172
173 rc = tm_signal_self_context_load(pid, NULL, NULL, NULL, vsxs);
174 FAIL_IF(rc != pid);
175 i++;
176 }
177
178 return (broken);
179 }
180
181 int main(void)
182 {
183 return test_harness(tm_signal_context_chk, "tm_signal_context_chk_vsx");
184 }