1 /* Low level interface to valgrind, for the remote server for GDB integrated
4 Free Software Foundation, Inc.
6 This file is part of VALGRIND.
7 It has been inspired from a file from gdbserver in gdb 6.6.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
29 #include "pub_core_machine.h"
30 #include "pub_core_threadstate.h"
31 #include "pub_core_transtab.h"
32 #include "pub_core_gdbserver.h"
34 #include "valgrind_low.h"
36 #include "libvex_guest_s390x.h"
38 static struct reg regs
[] = {
67 { "acr10", 1472, 32 },
68 { "acr11", 1504, 32 },
69 { "acr12", 1536, 32 },
70 { "acr13", 1568, 32 },
71 { "acr14", 1600, 32 },
72 { "acr15", 1632, 32 },
90 { "orig_r2", 2720, 64 },
101 { "v10l", 3424, 64 },
102 { "v11l", 3488, 64 },
103 { "v12l", 3552, 64 },
104 { "v13l", 3616, 64 },
105 { "v14l", 3680, 64 },
106 { "v15l", 3744, 64 },
107 { "v16", 3808, 128 },
108 { "v17", 3936, 128 },
109 { "v18", 4064, 128 },
110 { "v19", 4192, 128 },
111 { "v20", 4320, 128 },
112 { "v21", 4448, 128 },
113 { "v22", 4576, 128 },
114 { "v23", 4704, 128 },
115 { "v24", 4832, 128 },
116 { "v25", 4960, 128 },
117 { "v26", 5088, 128 },
118 { "v27", 5216, 128 },
119 { "v28", 5344, 128 },
120 { "v29", 5472, 128 },
121 { "v30", 5600, 128 },
122 { "v31", 5728, 128 },
124 static const char *expedite_regs
[] = { "r14", "r15", "pswa", 0 };
125 #define num_regs_all (sizeof (regs) / sizeof (regs[0]))
129 CORE_ADDR
get_pc (void)
133 collect_register_by_name ("pswa", &pc
);
135 dlog(1, "stop pc is %p\n", (void *) pc
);
140 void set_pc (CORE_ADDR newpc
)
142 supply_register_by_name ("pswa", &newpc
);
145 /* store registers in the guest state (gdbserver_to_valgrind)
146 or fetch register from the guest state (valgrind_to_gdbserver). */
148 void transfer_register (ThreadId tid
, int abs_regno
, void * buf
,
149 transfer_direction dir
, int size
, Bool
*mod
)
151 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
152 int set
= abs_regno
/ num_regs
;
153 int regno
= abs_regno
% num_regs
;
156 VexGuestS390XState
* s390x
= (VexGuestS390XState
*) get_arch (set
, tst
);
159 // numbers here have to match the order of regs above
160 // Attention: gdb order does not match valgrind order.
161 case 0: *mod
= False
; break; //GDBTD??? { "pswm", 0, 64 },
162 case 1: VG_(transfer
) (&s390x
->guest_IA
, buf
, dir
, size
, mod
); break;
163 case 2: VG_(transfer
) (&s390x
->guest_r0
, buf
, dir
, size
, mod
); break;
164 case 3: VG_(transfer
) (&s390x
->guest_r1
, buf
, dir
, size
, mod
); break;
165 case 4: VG_(transfer
) (&s390x
->guest_r2
, buf
, dir
, size
, mod
); break;
166 case 5: VG_(transfer
) (&s390x
->guest_r3
, buf
, dir
, size
, mod
); break;
167 case 6: VG_(transfer
) (&s390x
->guest_r4
, buf
, dir
, size
, mod
); break;
168 case 7: VG_(transfer
) (&s390x
->guest_r5
, buf
, dir
, size
, mod
); break;
169 case 8: VG_(transfer
) (&s390x
->guest_r6
, buf
, dir
, size
, mod
); break;
170 case 9: VG_(transfer
) (&s390x
->guest_r7
, buf
, dir
, size
, mod
); break;
171 case 10: VG_(transfer
) (&s390x
->guest_r8
, buf
, dir
, size
, mod
); break;
172 case 11: VG_(transfer
) (&s390x
->guest_r9
, buf
, dir
, size
, mod
); break;
173 case 12: VG_(transfer
) (&s390x
->guest_r10
, buf
, dir
, size
, mod
); break;
174 case 13: VG_(transfer
) (&s390x
->guest_r11
, buf
, dir
, size
, mod
); break;
175 case 14: VG_(transfer
) (&s390x
->guest_r12
, buf
, dir
, size
, mod
); break;
176 case 15: VG_(transfer
) (&s390x
->guest_r13
, buf
, dir
, size
, mod
); break;
177 case 16: VG_(transfer
) (&s390x
->guest_r14
, buf
, dir
, size
, mod
); break;
178 case 17: VG_(transfer
) (&s390x
->guest_r15
, buf
, dir
, size
, mod
); break;
179 case 18: VG_(transfer
) (&s390x
->guest_a0
, buf
, dir
, size
, mod
); break;
180 case 19: VG_(transfer
) (&s390x
->guest_a1
, buf
, dir
, size
, mod
); break;
181 case 20: VG_(transfer
) (&s390x
->guest_a2
, buf
, dir
, size
, mod
); break;
182 case 21: VG_(transfer
) (&s390x
->guest_a3
, buf
, dir
, size
, mod
); break;
183 case 22: VG_(transfer
) (&s390x
->guest_a4
, buf
, dir
, size
, mod
); break;
184 case 23: VG_(transfer
) (&s390x
->guest_a5
, buf
, dir
, size
, mod
); break;
185 case 24: VG_(transfer
) (&s390x
->guest_a6
, buf
, dir
, size
, mod
); break;
186 case 25: VG_(transfer
) (&s390x
->guest_a7
, buf
, dir
, size
, mod
); break;
187 case 26: VG_(transfer
) (&s390x
->guest_a8
, buf
, dir
, size
, mod
); break;
188 case 27: VG_(transfer
) (&s390x
->guest_a9
, buf
, dir
, size
, mod
); break;
189 case 28: VG_(transfer
) (&s390x
->guest_a10
, buf
, dir
, size
, mod
); break;
190 case 29: VG_(transfer
) (&s390x
->guest_a11
, buf
, dir
, size
, mod
); break;
191 case 30: VG_(transfer
) (&s390x
->guest_a12
, buf
, dir
, size
, mod
); break;
192 case 31: VG_(transfer
) (&s390x
->guest_a13
, buf
, dir
, size
, mod
); break;
193 case 32: VG_(transfer
) (&s390x
->guest_a14
, buf
, dir
, size
, mod
); break;
194 case 33: VG_(transfer
) (&s390x
->guest_a15
, buf
, dir
, size
, mod
); break;
195 case 34: VG_(transfer
) (&s390x
->guest_fpc
, buf
, dir
, size
, mod
); break;
196 case 35: VG_(transfer
) (&s390x
->guest_v0
.w64
[0], buf
, dir
, size
, mod
); break;
197 case 36: VG_(transfer
) (&s390x
->guest_v1
.w64
[0], buf
, dir
, size
, mod
); break;
198 case 37: VG_(transfer
) (&s390x
->guest_v2
.w64
[0], buf
, dir
, size
, mod
); break;
199 case 38: VG_(transfer
) (&s390x
->guest_v3
.w64
[0], buf
, dir
, size
, mod
); break;
200 case 39: VG_(transfer
) (&s390x
->guest_v4
.w64
[0], buf
, dir
, size
, mod
); break;
201 case 40: VG_(transfer
) (&s390x
->guest_v5
.w64
[0], buf
, dir
, size
, mod
); break;
202 case 41: VG_(transfer
) (&s390x
->guest_v6
.w64
[0], buf
, dir
, size
, mod
); break;
203 case 42: VG_(transfer
) (&s390x
->guest_v7
.w64
[0], buf
, dir
, size
, mod
); break;
204 case 43: VG_(transfer
) (&s390x
->guest_v8
.w64
[0], buf
, dir
, size
, mod
); break;
205 case 44: VG_(transfer
) (&s390x
->guest_v9
.w64
[0], buf
, dir
, size
, mod
); break;
206 case 45: VG_(transfer
) (&s390x
->guest_v10
.w64
[0], buf
, dir
, size
, mod
); break;
207 case 46: VG_(transfer
) (&s390x
->guest_v11
.w64
[0], buf
, dir
, size
, mod
); break;
208 case 47: VG_(transfer
) (&s390x
->guest_v12
.w64
[0], buf
, dir
, size
, mod
); break;
209 case 48: VG_(transfer
) (&s390x
->guest_v13
.w64
[0], buf
, dir
, size
, mod
); break;
210 case 49: VG_(transfer
) (&s390x
->guest_v14
.w64
[0], buf
, dir
, size
, mod
); break;
211 case 50: VG_(transfer
) (&s390x
->guest_v15
.w64
[0], buf
, dir
, size
, mod
); break;
212 case 51: *mod
= False
; break; //GDBTD??? { "orig_r2", 0, 64 },
213 case 52: VG_(transfer
) (&s390x
->guest_v0
.w64
[1], buf
, dir
, size
, mod
); break;
214 case 53: VG_(transfer
) (&s390x
->guest_v1
.w64
[1], buf
, dir
, size
, mod
); break;
215 case 54: VG_(transfer
) (&s390x
->guest_v2
.w64
[1], buf
, dir
, size
, mod
); break;
216 case 55: VG_(transfer
) (&s390x
->guest_v3
.w64
[1], buf
, dir
, size
, mod
); break;
217 case 56: VG_(transfer
) (&s390x
->guest_v4
.w64
[1], buf
, dir
, size
, mod
); break;
218 case 57: VG_(transfer
) (&s390x
->guest_v5
.w64
[1], buf
, dir
, size
, mod
); break;
219 case 58: VG_(transfer
) (&s390x
->guest_v6
.w64
[1], buf
, dir
, size
, mod
); break;
220 case 59: VG_(transfer
) (&s390x
->guest_v7
.w64
[1], buf
, dir
, size
, mod
); break;
221 case 60: VG_(transfer
) (&s390x
->guest_v8
.w64
[1], buf
, dir
, size
, mod
); break;
222 case 61: VG_(transfer
) (&s390x
->guest_v9
.w64
[1], buf
, dir
, size
, mod
); break;
223 case 62: VG_(transfer
) (&s390x
->guest_v10
.w64
[1], buf
, dir
, size
, mod
); break;
224 case 63: VG_(transfer
) (&s390x
->guest_v11
.w64
[1], buf
, dir
, size
, mod
); break;
225 case 64: VG_(transfer
) (&s390x
->guest_v12
.w64
[1], buf
, dir
, size
, mod
); break;
226 case 65: VG_(transfer
) (&s390x
->guest_v13
.w64
[1], buf
, dir
, size
, mod
); break;
227 case 66: VG_(transfer
) (&s390x
->guest_v14
.w64
[1], buf
, dir
, size
, mod
); break;
228 case 67: VG_(transfer
) (&s390x
->guest_v15
.w64
[1], buf
, dir
, size
, mod
); break;
229 case 68: VG_(transfer
) (&s390x
->guest_v16
, buf
, dir
, size
, mod
); break;
230 case 69: VG_(transfer
) (&s390x
->guest_v17
, buf
, dir
, size
, mod
); break;
231 case 70: VG_(transfer
) (&s390x
->guest_v18
, buf
, dir
, size
, mod
); break;
232 case 71: VG_(transfer
) (&s390x
->guest_v19
, buf
, dir
, size
, mod
); break;
233 case 72: VG_(transfer
) (&s390x
->guest_v20
, buf
, dir
, size
, mod
); break;
234 case 73: VG_(transfer
) (&s390x
->guest_v21
, buf
, dir
, size
, mod
); break;
235 case 74: VG_(transfer
) (&s390x
->guest_v22
, buf
, dir
, size
, mod
); break;
236 case 75: VG_(transfer
) (&s390x
->guest_v23
, buf
, dir
, size
, mod
); break;
237 case 76: VG_(transfer
) (&s390x
->guest_v24
, buf
, dir
, size
, mod
); break;
238 case 77: VG_(transfer
) (&s390x
->guest_v25
, buf
, dir
, size
, mod
); break;
239 case 78: VG_(transfer
) (&s390x
->guest_v26
, buf
, dir
, size
, mod
); break;
240 case 79: VG_(transfer
) (&s390x
->guest_v27
, buf
, dir
, size
, mod
); break;
241 case 80: VG_(transfer
) (&s390x
->guest_v28
, buf
, dir
, size
, mod
); break;
242 case 81: VG_(transfer
) (&s390x
->guest_v29
, buf
, dir
, size
, mod
); break;
243 case 82: VG_(transfer
) (&s390x
->guest_v30
, buf
, dir
, size
, mod
); break;
244 case 83: VG_(transfer
) (&s390x
->guest_v31
, buf
, dir
, size
, mod
); break;
245 default: vg_assert(0);
254 VG_(machine_get_VexArchInfo
) (&va
, &vai
);
255 return (vai
.hwcaps
& VEX_HWCAPS_S390X_VX
) != 0;
259 const char* target_xml (Bool shadow_mode
)
263 return "s390x-vx-linux-valgrind.xml";
265 return "s390x-generic-valgrind.xml";
268 return "s390x-vx-linux.xml";
270 return "s390x-generic.xml";
274 static CORE_ADDR
** target_get_dtv (ThreadState
*tst
)
276 VexGuestS390XState
* s390x
= (VexGuestS390XState
*)&tst
->arch
.vex
;
277 // Thread pointer is in a0 (high 32 bits) and a1. Dtv is the second word.
278 return (CORE_ADDR
**)((Addr
)((Addr64
)s390x
->guest_a0
<< 32
279 | (Addr64
)s390x
->guest_a1
)
280 + sizeof(CORE_ADDR
));
283 static struct valgrind_target_ops low_target
= {
284 -1, // Override at init time.
285 17, //sp = r15, which is register offset 17 in regs
295 void s390x_init_architecture (struct valgrind_target_ops
*target
)
297 *target
= low_target
;
299 num_regs
= num_regs_all
;
301 num_regs
= num_regs_all
- 32; // Remove all VX registers.
302 target
->num_regs
= num_regs
;
303 set_register_cache (regs
, num_regs
);
304 gdbserver_expedite_regs
= expedite_regs
;