Commit | Line | Data |
---|---|---|
265f716b DJ |
1 | /* GNU/Linux S/390 specific low level interface, for the remote server |
2 | for GDB. | |
28e7fd62 | 3 | Copyright (C) 2001-2013 Free Software Foundation, Inc. |
265f716b DJ |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
265f716b DJ |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
265f716b DJ |
19 | |
20 | /* This file is used for both 31-bit and 64-bit S/390 systems. */ | |
21 | ||
22 | #include "server.h" | |
23 | #include "linux-low.h" | |
c642a434 | 24 | #include "elf/common.h" |
265f716b DJ |
25 | |
26 | #include <asm/ptrace.h> | |
c642a434 UW |
27 | #include <sys/ptrace.h> |
28 | #include <sys/uio.h> | |
7803799a | 29 | #include <elf.h> |
265f716b | 30 | |
7803799a UW |
31 | #ifndef HWCAP_S390_HIGH_GPRS |
32 | #define HWCAP_S390_HIGH_GPRS 512 | |
33 | #endif | |
d05b4ac3 | 34 | |
c642a434 UW |
35 | #ifndef PTRACE_GETREGSET |
36 | #define PTRACE_GETREGSET 0x4204 | |
37 | #endif | |
38 | ||
39 | #ifndef PTRACE_SETREGSET | |
40 | #define PTRACE_SETREGSET 0x4205 | |
41 | #endif | |
42 | ||
7803799a UW |
43 | /* Defined in auto-generated file s390-linux32.c. */ |
44 | void init_registers_s390_linux32 (void); | |
3aee8918 PA |
45 | extern const struct target_desc *tdesc_s390_linux32; |
46 | ||
c642a434 UW |
47 | /* Defined in auto-generated file s390-linux32v1.c. */ |
48 | void init_registers_s390_linux32v1 (void); | |
3aee8918 PA |
49 | extern const struct target_desc *tdesc_s390_linux32v1; |
50 | ||
c642a434 UW |
51 | /* Defined in auto-generated file s390-linux32v2.c. */ |
52 | void init_registers_s390_linux32v2 (void); | |
3aee8918 PA |
53 | extern const struct target_desc *tdesc_s390_linux32v2; |
54 | ||
7803799a UW |
55 | /* Defined in auto-generated file s390-linux64.c. */ |
56 | void init_registers_s390_linux64 (void); | |
3aee8918 PA |
57 | extern const struct target_desc *tdesc_s390_linux64; |
58 | ||
c642a434 UW |
59 | /* Defined in auto-generated file s390-linux64v1.c. */ |
60 | void init_registers_s390_linux64v1 (void); | |
3aee8918 PA |
61 | extern const struct target_desc *tdesc_s390_linux64v1; |
62 | ||
c642a434 UW |
63 | /* Defined in auto-generated file s390-linux64v2.c. */ |
64 | void init_registers_s390_linux64v2 (void); | |
3aee8918 PA |
65 | extern const struct target_desc *tdesc_s390_linux64v2; |
66 | ||
4ac33720 UW |
67 | /* Defined in auto-generated file s390-te-linux64.c. */ |
68 | void init_registers_s390_te_linux64 (void); | |
69 | extern const struct target_desc *tdesc_s390_te_linux64; | |
70 | ||
7803799a UW |
71 | /* Defined in auto-generated file s390x-linux64.c. */ |
72 | void init_registers_s390x_linux64 (void); | |
3aee8918 PA |
73 | extern const struct target_desc *tdesc_s390x_linux64; |
74 | ||
c642a434 UW |
75 | /* Defined in auto-generated file s390x-linux64v1.c. */ |
76 | void init_registers_s390x_linux64v1 (void); | |
3aee8918 PA |
77 | extern const struct target_desc *tdesc_s390x_linux64v1; |
78 | ||
c642a434 UW |
79 | /* Defined in auto-generated file s390x-linux64v2.c. */ |
80 | void init_registers_s390x_linux64v2 (void); | |
3aee8918 | 81 | extern const struct target_desc *tdesc_s390x_linux64v2; |
d05b4ac3 | 82 | |
4ac33720 UW |
83 | /* Defined in auto-generated file s390x-te-linux64.c. */ |
84 | void init_registers_s390x_te_linux64 (void); | |
85 | extern const struct target_desc *tdesc_s390x_te_linux64; | |
86 | ||
c642a434 | 87 | #define s390_num_regs 52 |
265f716b | 88 | |
2ec06d2e | 89 | static int s390_regmap[] = { |
265f716b DJ |
90 | PT_PSWMASK, PT_PSWADDR, |
91 | ||
92 | PT_GPR0, PT_GPR1, PT_GPR2, PT_GPR3, | |
93 | PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7, | |
94 | PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11, | |
95 | PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15, | |
96 | ||
97 | PT_ACR0, PT_ACR1, PT_ACR2, PT_ACR3, | |
98 | PT_ACR4, PT_ACR5, PT_ACR6, PT_ACR7, | |
99 | PT_ACR8, PT_ACR9, PT_ACR10, PT_ACR11, | |
100 | PT_ACR12, PT_ACR13, PT_ACR14, PT_ACR15, | |
101 | ||
265f716b DJ |
102 | PT_FPC, |
103 | ||
d0f54f9d | 104 | #ifndef __s390x__ |
265f716b DJ |
105 | PT_FPR0_HI, PT_FPR1_HI, PT_FPR2_HI, PT_FPR3_HI, |
106 | PT_FPR4_HI, PT_FPR5_HI, PT_FPR6_HI, PT_FPR7_HI, | |
107 | PT_FPR8_HI, PT_FPR9_HI, PT_FPR10_HI, PT_FPR11_HI, | |
108 | PT_FPR12_HI, PT_FPR13_HI, PT_FPR14_HI, PT_FPR15_HI, | |
109 | #else | |
110 | PT_FPR0, PT_FPR1, PT_FPR2, PT_FPR3, | |
111 | PT_FPR4, PT_FPR5, PT_FPR6, PT_FPR7, | |
112 | PT_FPR8, PT_FPR9, PT_FPR10, PT_FPR11, | |
113 | PT_FPR12, PT_FPR13, PT_FPR14, PT_FPR15, | |
114 | #endif | |
c642a434 UW |
115 | |
116 | PT_ORIGGPR2, | |
265f716b DJ |
117 | }; |
118 | ||
7803799a | 119 | #ifdef __s390x__ |
c642a434 | 120 | #define s390_num_regs_3264 68 |
7803799a UW |
121 | |
122 | static int s390_regmap_3264[] = { | |
123 | PT_PSWMASK, PT_PSWADDR, | |
124 | ||
493e2a69 MS |
125 | PT_GPR0, PT_GPR0, PT_GPR1, PT_GPR1, |
126 | PT_GPR2, PT_GPR2, PT_GPR3, PT_GPR3, | |
127 | PT_GPR4, PT_GPR4, PT_GPR5, PT_GPR5, | |
128 | PT_GPR6, PT_GPR6, PT_GPR7, PT_GPR7, | |
129 | PT_GPR8, PT_GPR8, PT_GPR9, PT_GPR9, | |
130 | PT_GPR10, PT_GPR10, PT_GPR11, PT_GPR11, | |
131 | PT_GPR12, PT_GPR12, PT_GPR13, PT_GPR13, | |
132 | PT_GPR14, PT_GPR14, PT_GPR15, PT_GPR15, | |
7803799a UW |
133 | |
134 | PT_ACR0, PT_ACR1, PT_ACR2, PT_ACR3, | |
135 | PT_ACR4, PT_ACR5, PT_ACR6, PT_ACR7, | |
136 | PT_ACR8, PT_ACR9, PT_ACR10, PT_ACR11, | |
137 | PT_ACR12, PT_ACR13, PT_ACR14, PT_ACR15, | |
138 | ||
139 | PT_FPC, | |
140 | ||
141 | PT_FPR0, PT_FPR1, PT_FPR2, PT_FPR3, | |
142 | PT_FPR4, PT_FPR5, PT_FPR6, PT_FPR7, | |
143 | PT_FPR8, PT_FPR9, PT_FPR10, PT_FPR11, | |
144 | PT_FPR12, PT_FPR13, PT_FPR14, PT_FPR15, | |
c642a434 UW |
145 | |
146 | PT_ORIGGPR2, | |
7803799a UW |
147 | }; |
148 | #endif | |
149 | ||
150 | ||
2ec06d2e DJ |
151 | static int |
152 | s390_cannot_fetch_register (int regno) | |
265f716b | 153 | { |
265f716b DJ |
154 | return 0; |
155 | } | |
156 | ||
2ec06d2e DJ |
157 | static int |
158 | s390_cannot_store_register (int regno) | |
265f716b | 159 | { |
265f716b DJ |
160 | return 0; |
161 | } | |
2ec06d2e | 162 | |
ee1a7ae4 | 163 | static void |
442ea881 | 164 | s390_collect_ptrace_register (struct regcache *regcache, int regno, char *buf) |
ee1a7ae4 | 165 | { |
3aee8918 | 166 | int size = register_size (regcache->tdesc, regno); |
ee1a7ae4 UW |
167 | if (size < sizeof (long)) |
168 | { | |
3aee8918 PA |
169 | const struct regs_info *regs_info = (*the_low_target.regs_info) (); |
170 | struct usrregs_info *usr = regs_info->usrregs; | |
171 | int regaddr = usr->regmap[regno]; | |
7803799a | 172 | |
ee1a7ae4 UW |
173 | memset (buf, 0, sizeof (long)); |
174 | ||
3aee8918 PA |
175 | if ((regno ^ 1) < usr->num_regs |
176 | && usr->regmap[regno ^ 1] == regaddr) | |
7803799a | 177 | { |
18f5de3b JK |
178 | collect_register (regcache, regno & ~1, buf); |
179 | collect_register (regcache, (regno & ~1) + 1, | |
180 | buf + sizeof (long) - size); | |
7803799a | 181 | } |
d6db1fab UW |
182 | else if (regaddr == PT_PSWMASK) |
183 | { | |
184 | /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying | |
185 | the basic addressing mode bit from the PSW address. */ | |
3aee8918 | 186 | char *addr = alloca (register_size (regcache->tdesc, regno ^ 1)); |
d6db1fab UW |
187 | collect_register (regcache, regno, buf); |
188 | collect_register (regcache, regno ^ 1, addr); | |
189 | buf[1] &= ~0x8; | |
190 | buf[size] |= (addr[0] & 0x80); | |
191 | } | |
192 | else if (regaddr == PT_PSWADDR) | |
193 | { | |
194 | /* Convert 4-byte PSW address to 8 bytes by clearing the addressing | |
195 | mode bit (which gets copied to the PSW mask instead). */ | |
196 | collect_register (regcache, regno, buf + sizeof (long) - size); | |
197 | buf[sizeof (long) - size] &= ~0x80; | |
198 | } | |
c642a434 UW |
199 | else if ((regaddr >= PT_GPR0 && regaddr <= PT_GPR15) |
200 | || regaddr == PT_ORIGGPR2) | |
442ea881 | 201 | collect_register (regcache, regno, buf + sizeof (long) - size); |
ee1a7ae4 | 202 | else |
442ea881 | 203 | collect_register (regcache, regno, buf); |
ee1a7ae4 UW |
204 | } |
205 | else | |
18f5de3b | 206 | collect_register (regcache, regno, buf); |
ee1a7ae4 UW |
207 | } |
208 | ||
209 | static void | |
493e2a69 MS |
210 | s390_supply_ptrace_register (struct regcache *regcache, |
211 | int regno, const char *buf) | |
ee1a7ae4 | 212 | { |
3aee8918 | 213 | int size = register_size (regcache->tdesc, regno); |
ee1a7ae4 UW |
214 | if (size < sizeof (long)) |
215 | { | |
3aee8918 PA |
216 | const struct regs_info *regs_info = (*the_low_target.regs_info) (); |
217 | struct usrregs_info *usr = regs_info->usrregs; | |
218 | int regaddr = usr->regmap[regno]; | |
7803799a | 219 | |
3aee8918 PA |
220 | if ((regno ^ 1) < usr->num_regs |
221 | && usr->regmap[regno ^ 1] == regaddr) | |
7803799a | 222 | { |
18f5de3b JK |
223 | supply_register (regcache, regno & ~1, buf); |
224 | supply_register (regcache, (regno & ~1) + 1, | |
225 | buf + sizeof (long) - size); | |
7803799a | 226 | } |
d6db1fab UW |
227 | else if (regaddr == PT_PSWMASK) |
228 | { | |
229 | /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying | |
230 | the basic addressing mode into the PSW address. */ | |
231 | char *mask = alloca (size); | |
3aee8918 | 232 | char *addr = alloca (register_size (regcache->tdesc, regno ^ 1)); |
d6db1fab UW |
233 | memcpy (mask, buf, size); |
234 | mask[1] |= 0x8; | |
235 | supply_register (regcache, regno, mask); | |
236 | ||
237 | collect_register (regcache, regno ^ 1, addr); | |
238 | addr[0] &= ~0x80; | |
239 | addr[0] |= (buf[size] & 0x80); | |
240 | supply_register (regcache, regno ^ 1, addr); | |
241 | } | |
242 | else if (regaddr == PT_PSWADDR) | |
243 | { | |
244 | /* Convert 8-byte PSW address to 4 bytes by truncating, but | |
245 | keeping the addressing mode bit (which was set from the mask). */ | |
246 | char *addr = alloca (size); | |
247 | char amode; | |
248 | collect_register (regcache, regno, addr); | |
249 | amode = addr[0] & 0x80; | |
250 | memcpy (addr, buf + sizeof (long) - size, size); | |
251 | addr[0] &= ~0x80; | |
252 | addr[0] |= amode; | |
253 | supply_register (regcache, regno, addr); | |
254 | } | |
c642a434 UW |
255 | else if ((regaddr >= PT_GPR0 && regaddr <= PT_GPR15) |
256 | || regaddr == PT_ORIGGPR2) | |
442ea881 | 257 | supply_register (regcache, regno, buf + sizeof (long) - size); |
ee1a7ae4 | 258 | else |
442ea881 | 259 | supply_register (regcache, regno, buf); |
ee1a7ae4 UW |
260 | } |
261 | else | |
442ea881 | 262 | supply_register (regcache, regno, buf); |
ee1a7ae4 UW |
263 | } |
264 | ||
b7149293 UW |
265 | /* Provide only a fill function for the general register set. ps_lgetregs |
266 | will use this for NPTL support. */ | |
267 | ||
3aee8918 PA |
268 | static void |
269 | s390_fill_gregset (struct regcache *regcache, void *buf) | |
b7149293 UW |
270 | { |
271 | int i; | |
3aee8918 PA |
272 | const struct regs_info *regs_info = (*the_low_target.regs_info) (); |
273 | struct usrregs_info *usr = regs_info->usrregs; | |
b7149293 | 274 | |
3aee8918 | 275 | for (i = 0; i < usr->num_regs; i++) |
7803799a | 276 | { |
3aee8918 PA |
277 | if (usr->regmap[i] < PT_PSWMASK |
278 | || usr->regmap[i] > PT_ACR15) | |
7803799a UW |
279 | continue; |
280 | ||
3aee8918 PA |
281 | s390_collect_ptrace_register (regcache, i, |
282 | (char *) buf + usr->regmap[i]); | |
7803799a | 283 | } |
b7149293 UW |
284 | } |
285 | ||
c642a434 UW |
286 | /* Fill and store functions for extended register sets. */ |
287 | ||
288 | static void | |
289 | s390_fill_last_break (struct regcache *regcache, void *buf) | |
290 | { | |
291 | /* Last break address is read-only. */ | |
292 | } | |
293 | ||
294 | static void | |
295 | s390_store_last_break (struct regcache *regcache, const void *buf) | |
296 | { | |
3aee8918 PA |
297 | const char *p; |
298 | ||
299 | p = (const char *) buf + 8 - register_size (regcache->tdesc, 0); | |
300 | supply_register_by_name (regcache, "last_break", p); | |
c642a434 UW |
301 | } |
302 | ||
303 | static void | |
304 | s390_fill_system_call (struct regcache *regcache, void *buf) | |
305 | { | |
306 | collect_register_by_name (regcache, "system_call", buf); | |
307 | } | |
308 | ||
309 | static void | |
310 | s390_store_system_call (struct regcache *regcache, const void *buf) | |
311 | { | |
312 | supply_register_by_name (regcache, "system_call", buf); | |
313 | } | |
314 | ||
3aee8918 | 315 | static struct regset_info s390_regsets[] = { |
1570b33e | 316 | { 0, 0, 0, 0, GENERAL_REGS, s390_fill_gregset, NULL }, |
c642a434 UW |
317 | /* Last break address is read-only; do not attempt PTRACE_SETREGSET. */ |
318 | { PTRACE_GETREGSET, PTRACE_GETREGSET, NT_S390_LAST_BREAK, 0, | |
319 | EXTENDED_REGS, s390_fill_last_break, s390_store_last_break }, | |
320 | { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_SYSTEM_CALL, 0, | |
321 | EXTENDED_REGS, s390_fill_system_call, s390_store_system_call }, | |
1570b33e | 322 | { 0, 0, 0, -1, -1, NULL, NULL } |
b7149293 UW |
323 | }; |
324 | ||
b0ded00b | 325 | |
f450004a | 326 | static const unsigned char s390_breakpoint[] = { 0, 1 }; |
b0ded00b UW |
327 | #define s390_breakpoint_len 2 |
328 | ||
329 | static CORE_ADDR | |
442ea881 | 330 | s390_get_pc (struct regcache *regcache) |
b0ded00b | 331 | { |
3aee8918 | 332 | if (register_size (regcache->tdesc, 0) == 4) |
d61ddec4 | 333 | { |
d6db1fab UW |
334 | unsigned int pswa; |
335 | collect_register_by_name (regcache, "pswa", &pswa); | |
336 | return pswa & 0x7fffffff; | |
d61ddec4 UW |
337 | } |
338 | else | |
339 | { | |
340 | unsigned long pc; | |
442ea881 | 341 | collect_register_by_name (regcache, "pswa", &pc); |
d61ddec4 UW |
342 | return pc; |
343 | } | |
b0ded00b UW |
344 | } |
345 | ||
346 | static void | |
442ea881 | 347 | s390_set_pc (struct regcache *regcache, CORE_ADDR newpc) |
b0ded00b | 348 | { |
3aee8918 | 349 | if (register_size (regcache->tdesc, 0) == 4) |
d61ddec4 | 350 | { |
d6db1fab UW |
351 | unsigned int pswa; |
352 | collect_register_by_name (regcache, "pswa", &pswa); | |
353 | pswa = (pswa & 0x80000000) | (newpc & 0x7fffffff); | |
354 | supply_register_by_name (regcache, "pswa", &pswa); | |
d61ddec4 UW |
355 | } |
356 | else | |
357 | { | |
358 | unsigned long pc = newpc; | |
442ea881 | 359 | supply_register_by_name (regcache, "pswa", &pc); |
d61ddec4 | 360 | } |
b0ded00b UW |
361 | } |
362 | ||
7803799a UW |
363 | #ifdef __s390x__ |
364 | static unsigned long | |
3aee8918 | 365 | s390_get_hwcap (const struct target_desc *tdesc) |
7803799a | 366 | { |
3aee8918 | 367 | int wordsize = register_size (tdesc, 0); |
7803799a UW |
368 | unsigned char *data = alloca (2 * wordsize); |
369 | int offset = 0; | |
370 | ||
371 | while ((*the_target->read_auxv) (offset, data, 2 * wordsize) == 2 * wordsize) | |
372 | { | |
373 | if (wordsize == 4) | |
374 | { | |
375 | unsigned int *data_p = (unsigned int *)data; | |
376 | if (data_p[0] == AT_HWCAP) | |
377 | return data_p[1]; | |
378 | } | |
379 | else | |
380 | { | |
381 | unsigned long *data_p = (unsigned long *)data; | |
382 | if (data_p[0] == AT_HWCAP) | |
383 | return data_p[1]; | |
384 | } | |
385 | ||
386 | offset += 2 * wordsize; | |
387 | } | |
388 | ||
389 | return 0; | |
390 | } | |
391 | #endif | |
d61ddec4 | 392 | |
c642a434 UW |
393 | static int |
394 | s390_check_regset (int pid, int regset, int regsize) | |
395 | { | |
396 | gdb_byte *buf = alloca (regsize); | |
397 | struct iovec iov; | |
398 | ||
399 | iov.iov_base = buf; | |
400 | iov.iov_len = regsize; | |
401 | ||
4ac33720 UW |
402 | if (ptrace (PTRACE_GETREGSET, pid, (long) regset, (long) &iov) >= 0 |
403 | || errno == ENODATA) | |
c642a434 | 404 | return 1; |
4ac33720 | 405 | return 0; |
c642a434 UW |
406 | } |
407 | ||
3aee8918 PA |
408 | #ifdef __s390x__ |
409 | /* For a 31-bit inferior, whether the kernel supports using the full | |
410 | 64-bit GPRs. */ | |
411 | static int have_hwcap_s390_high_gprs = 0; | |
412 | #endif | |
413 | ||
d61ddec4 UW |
414 | static void |
415 | s390_arch_setup (void) | |
416 | { | |
3aee8918 | 417 | const struct target_desc *tdesc; |
c642a434 UW |
418 | struct regset_info *regset; |
419 | ||
420 | /* Check whether the kernel supports extra register sets. */ | |
421 | int pid = pid_of (get_thread_lwp (current_inferior)); | |
422 | int have_regset_last_break | |
423 | = s390_check_regset (pid, NT_S390_LAST_BREAK, 8); | |
424 | int have_regset_system_call | |
425 | = s390_check_regset (pid, NT_S390_SYSTEM_CALL, 4); | |
4ac33720 | 426 | int have_regset_tdb = s390_check_regset (pid, NT_S390_TDB, 256); |
c642a434 UW |
427 | |
428 | /* Update target_regsets according to available register sets. */ | |
3aee8918 | 429 | for (regset = s390_regsets; regset->fill_function != NULL; regset++) |
c642a434 UW |
430 | if (regset->get_request == PTRACE_GETREGSET) |
431 | switch (regset->nt_type) | |
432 | { | |
433 | case NT_S390_LAST_BREAK: | |
434 | regset->size = have_regset_last_break? 8 : 0; | |
435 | break; | |
436 | case NT_S390_SYSTEM_CALL: | |
437 | regset->size = have_regset_system_call? 4 : 0; | |
438 | break; | |
4ac33720 UW |
439 | case NT_S390_TDB: |
440 | regset->size = have_regset_tdb ? 256 : 0; | |
c642a434 UW |
441 | default: |
442 | break; | |
443 | } | |
444 | ||
d61ddec4 | 445 | /* Assume 31-bit inferior process. */ |
c642a434 | 446 | if (have_regset_system_call) |
3aee8918 | 447 | tdesc = tdesc_s390_linux32v2; |
c642a434 | 448 | else if (have_regset_last_break) |
3aee8918 | 449 | tdesc = tdesc_s390_linux32v1; |
c642a434 | 450 | else |
3aee8918 | 451 | tdesc = tdesc_s390_linux32; |
d61ddec4 UW |
452 | |
453 | /* On a 64-bit host, check the low bit of the (31-bit) PSWM | |
454 | -- if this is one, we actually have a 64-bit inferior. */ | |
455 | #ifdef __s390x__ | |
456 | { | |
457 | unsigned int pswm; | |
3aee8918 PA |
458 | struct regcache *regcache = new_register_cache (tdesc); |
459 | fetch_inferior_registers (regcache, find_regno (tdesc, "pswm")); | |
442ea881 | 460 | collect_register_by_name (regcache, "pswm", &pswm); |
92b72907 UW |
461 | free_register_cache (regcache); |
462 | ||
d61ddec4 | 463 | if (pswm & 1) |
c642a434 | 464 | { |
4ac33720 UW |
465 | if (have_regset_tdb) |
466 | tdesc = tdesc_s390x_te_linux64; | |
c642a434 | 467 | if (have_regset_system_call) |
3aee8918 | 468 | tdesc = tdesc_s390x_linux64v2; |
c642a434 | 469 | else if (have_regset_last_break) |
3aee8918 | 470 | tdesc = tdesc_s390x_linux64v1; |
c642a434 | 471 | else |
3aee8918 | 472 | tdesc = tdesc_s390x_linux64; |
c642a434 | 473 | } |
7803799a UW |
474 | |
475 | /* For a 31-bit inferior, check whether the kernel supports | |
476 | using the full 64-bit GPRs. */ | |
3aee8918 | 477 | else if (s390_get_hwcap (tdesc) & HWCAP_S390_HIGH_GPRS) |
7803799a | 478 | { |
3aee8918 PA |
479 | have_hwcap_s390_high_gprs = 1; |
480 | ||
4ac33720 UW |
481 | if (have_regset_tdb) |
482 | tdesc = tdesc_s390_te_linux64; | |
483 | else if (have_regset_system_call) | |
3aee8918 | 484 | tdesc = tdesc_s390_linux64v2; |
c642a434 | 485 | else if (have_regset_last_break) |
3aee8918 | 486 | tdesc = tdesc_s390_linux64v1; |
c642a434 | 487 | else |
3aee8918 | 488 | tdesc = tdesc_s390_linux64; |
7803799a | 489 | } |
d61ddec4 UW |
490 | } |
491 | #endif | |
3aee8918 | 492 | current_process ()->tdesc = tdesc; |
d61ddec4 UW |
493 | } |
494 | ||
495 | ||
b0ded00b UW |
496 | static int |
497 | s390_breakpoint_at (CORE_ADDR pc) | |
498 | { | |
499 | unsigned char c[s390_breakpoint_len]; | |
500 | read_inferior_memory (pc, c, s390_breakpoint_len); | |
501 | return memcmp (c, s390_breakpoint, s390_breakpoint_len) == 0; | |
502 | } | |
503 | ||
3aee8918 PA |
504 | static struct usrregs_info s390_usrregs_info = |
505 | { | |
506 | s390_num_regs, | |
507 | s390_regmap, | |
508 | }; | |
509 | ||
510 | static struct regsets_info s390_regsets_info = | |
511 | { | |
512 | s390_regsets, /* regsets */ | |
513 | 0, /* num_regsets */ | |
514 | NULL, /* disabled_regsets */ | |
515 | }; | |
516 | ||
517 | static struct regs_info regs_info = | |
518 | { | |
519 | NULL, /* regset_bitmap */ | |
520 | &s390_usrregs_info, | |
521 | &s390_regsets_info | |
522 | }; | |
523 | ||
524 | #ifdef __s390x__ | |
525 | static struct usrregs_info s390_usrregs_info_3264 = | |
526 | { | |
527 | s390_num_regs_3264, | |
528 | s390_regmap_3264 | |
529 | }; | |
530 | ||
531 | static struct regsets_info s390_regsets_info_3264 = | |
532 | { | |
533 | s390_regsets, /* regsets */ | |
534 | 0, /* num_regsets */ | |
535 | NULL, /* disabled_regsets */ | |
536 | }; | |
537 | ||
538 | static struct regs_info regs_info_3264 = | |
539 | { | |
540 | NULL, /* regset_bitmap */ | |
541 | &s390_usrregs_info_3264, | |
542 | &s390_regsets_info_3264 | |
543 | }; | |
544 | #endif | |
545 | ||
546 | static const struct regs_info * | |
547 | s390_regs_info (void) | |
548 | { | |
549 | #ifdef __s390x__ | |
550 | if (have_hwcap_s390_high_gprs) | |
551 | { | |
552 | const struct target_desc *tdesc = current_process ()->tdesc; | |
553 | ||
554 | if (register_size (tdesc, 0) == 4) | |
555 | return ®s_info_3264; | |
556 | } | |
557 | #endif | |
558 | return ®s_info; | |
559 | } | |
b0ded00b | 560 | |
2ec06d2e | 561 | struct linux_target_ops the_low_target = { |
d61ddec4 | 562 | s390_arch_setup, |
3aee8918 | 563 | s390_regs_info, |
2ec06d2e DJ |
564 | s390_cannot_fetch_register, |
565 | s390_cannot_store_register, | |
c14dfd32 | 566 | NULL, /* fetch_register */ |
b0ded00b UW |
567 | s390_get_pc, |
568 | s390_set_pc, | |
569 | s390_breakpoint, | |
570 | s390_breakpoint_len, | |
571 | NULL, | |
572 | s390_breakpoint_len, | |
573 | s390_breakpoint_at, | |
ee1a7ae4 UW |
574 | NULL, |
575 | NULL, | |
576 | NULL, | |
577 | NULL, | |
578 | s390_collect_ptrace_register, | |
579 | s390_supply_ptrace_register, | |
2ec06d2e | 580 | }; |
3aee8918 PA |
581 | |
582 | void | |
583 | initialize_low_arch (void) | |
584 | { | |
585 | /* Initialize the Linux target descriptions. */ | |
586 | ||
587 | init_registers_s390_linux32 (); | |
588 | init_registers_s390_linux32v1 (); | |
589 | init_registers_s390_linux32v2 (); | |
590 | init_registers_s390_linux64 (); | |
591 | init_registers_s390_linux64v1 (); | |
592 | init_registers_s390_linux64v2 (); | |
4ac33720 | 593 | init_registers_s390_te_linux64 (); |
3aee8918 PA |
594 | init_registers_s390x_linux64 (); |
595 | init_registers_s390x_linux64v1 (); | |
596 | init_registers_s390x_linux64v2 (); | |
4ac33720 | 597 | init_registers_s390x_te_linux64 (); |
3aee8918 PA |
598 | |
599 | initialize_regsets_info (&s390_regsets_info); | |
600 | #ifdef __s390x__ | |
601 | initialize_regsets_info (&s390_regsets_info_3264); | |
602 | #endif | |
603 | } |