| 1 | /* Target-dependent code for GDB, the GNU debugger. |
| 2 | |
| 3 | Copyright (C) 2001-2014 Free Software Foundation, Inc. |
| 4 | |
| 5 | Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 6 | for IBM Deutschland Entwicklung GmbH, IBM Corporation. |
| 7 | |
| 8 | This file is part of GDB. |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 3 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 22 | |
| 23 | #include "defs.h" |
| 24 | #include "arch-utils.h" |
| 25 | #include "frame.h" |
| 26 | #include "inferior.h" |
| 27 | #include "infrun.h" |
| 28 | #include "symtab.h" |
| 29 | #include "target.h" |
| 30 | #include "gdbcore.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "objfiles.h" |
| 33 | #include "floatformat.h" |
| 34 | #include "regcache.h" |
| 35 | #include "trad-frame.h" |
| 36 | #include "frame-base.h" |
| 37 | #include "frame-unwind.h" |
| 38 | #include "dwarf2-frame.h" |
| 39 | #include "reggroups.h" |
| 40 | #include "regset.h" |
| 41 | #include "value.h" |
| 42 | #include "dis-asm.h" |
| 43 | #include "solib-svr4.h" |
| 44 | #include "prologue-value.h" |
| 45 | #include "linux-tdep.h" |
| 46 | #include "s390-linux-tdep.h" |
| 47 | #include "auxv.h" |
| 48 | #include "xml-syscall.h" |
| 49 | |
| 50 | #include "stap-probe.h" |
| 51 | #include "ax.h" |
| 52 | #include "ax-gdb.h" |
| 53 | #include "user-regs.h" |
| 54 | #include "cli/cli-utils.h" |
| 55 | #include <ctype.h> |
| 56 | #include "elf/common.h" |
| 57 | |
| 58 | #include "features/s390-linux32.c" |
| 59 | #include "features/s390-linux32v1.c" |
| 60 | #include "features/s390-linux32v2.c" |
| 61 | #include "features/s390-linux64.c" |
| 62 | #include "features/s390-linux64v1.c" |
| 63 | #include "features/s390-linux64v2.c" |
| 64 | #include "features/s390-te-linux64.c" |
| 65 | #include "features/s390x-linux64.c" |
| 66 | #include "features/s390x-linux64v1.c" |
| 67 | #include "features/s390x-linux64v2.c" |
| 68 | #include "features/s390x-te-linux64.c" |
| 69 | |
| 70 | #define XML_SYSCALL_FILENAME_S390 "syscalls/s390-linux.xml" |
| 71 | #define XML_SYSCALL_FILENAME_S390X "syscalls/s390x-linux.xml" |
| 72 | |
| 73 | /* The tdep structure. */ |
| 74 | |
| 75 | struct gdbarch_tdep |
| 76 | { |
| 77 | /* ABI version. */ |
| 78 | enum { ABI_LINUX_S390, ABI_LINUX_ZSERIES } abi; |
| 79 | |
| 80 | /* Pseudo register numbers. */ |
| 81 | int gpr_full_regnum; |
| 82 | int pc_regnum; |
| 83 | int cc_regnum; |
| 84 | |
| 85 | /* Core file register sets. */ |
| 86 | const struct regset *gregset; |
| 87 | int sizeof_gregset; |
| 88 | |
| 89 | const struct regset *fpregset; |
| 90 | int sizeof_fpregset; |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | /* ABI call-saved register information. */ |
| 95 | |
| 96 | static int |
| 97 | s390_register_call_saved (struct gdbarch *gdbarch, int regnum) |
| 98 | { |
| 99 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 100 | |
| 101 | switch (tdep->abi) |
| 102 | { |
| 103 | case ABI_LINUX_S390: |
| 104 | if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM) |
| 105 | || regnum == S390_F4_REGNUM || regnum == S390_F6_REGNUM |
| 106 | || regnum == S390_A0_REGNUM) |
| 107 | return 1; |
| 108 | |
| 109 | break; |
| 110 | |
| 111 | case ABI_LINUX_ZSERIES: |
| 112 | if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM) |
| 113 | || (regnum >= S390_F8_REGNUM && regnum <= S390_F15_REGNUM) |
| 114 | || (regnum >= S390_A0_REGNUM && regnum <= S390_A1_REGNUM)) |
| 115 | return 1; |
| 116 | |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int |
| 124 | s390_cannot_store_register (struct gdbarch *gdbarch, int regnum) |
| 125 | { |
| 126 | /* The last-break address is read-only. */ |
| 127 | return regnum == S390_LAST_BREAK_REGNUM; |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | s390_write_pc (struct regcache *regcache, CORE_ADDR pc) |
| 132 | { |
| 133 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 134 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 135 | |
| 136 | regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); |
| 137 | |
| 138 | /* Set special SYSTEM_CALL register to 0 to prevent the kernel from |
| 139 | messing with the PC we just installed, if we happen to be within |
| 140 | an interrupted system call that the kernel wants to restart. |
| 141 | |
| 142 | Note that after we return from the dummy call, the SYSTEM_CALL and |
| 143 | ORIG_R2 registers will be automatically restored, and the kernel |
| 144 | continues to restart the system call at this point. */ |
| 145 | if (register_size (gdbarch, S390_SYSTEM_CALL_REGNUM) > 0) |
| 146 | regcache_cooked_write_unsigned (regcache, S390_SYSTEM_CALL_REGNUM, 0); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /* DWARF Register Mapping. */ |
| 151 | |
| 152 | static const short s390_dwarf_regmap[] = |
| 153 | { |
| 154 | /* General Purpose Registers. */ |
| 155 | S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM, |
| 156 | S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM, |
| 157 | S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM, |
| 158 | S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM, |
| 159 | |
| 160 | /* Floating Point Registers. */ |
| 161 | S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM, |
| 162 | S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM, |
| 163 | S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM, |
| 164 | S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM, |
| 165 | |
| 166 | /* Control Registers (not mapped). */ |
| 167 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 168 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 169 | |
| 170 | /* Access Registers. */ |
| 171 | S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM, |
| 172 | S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM, |
| 173 | S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM, |
| 174 | S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM, |
| 175 | |
| 176 | /* Program Status Word. */ |
| 177 | S390_PSWM_REGNUM, |
| 178 | S390_PSWA_REGNUM, |
| 179 | |
| 180 | /* GPR Lower Half Access. */ |
| 181 | S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM, |
| 182 | S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM, |
| 183 | S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM, |
| 184 | S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM, |
| 185 | |
| 186 | /* GNU/Linux-specific registers (not mapped). */ |
| 187 | -1, -1, -1, |
| 188 | }; |
| 189 | |
| 190 | /* Convert DWARF register number REG to the appropriate register |
| 191 | number used by GDB. */ |
| 192 | static int |
| 193 | s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg) |
| 194 | { |
| 195 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 196 | |
| 197 | /* In a 32-on-64 debug scenario, debug info refers to the full 64-bit |
| 198 | GPRs. Note that call frame information still refers to the 32-bit |
| 199 | lower halves, because s390_adjust_frame_regnum uses register numbers |
| 200 | 66 .. 81 to access GPRs. */ |
| 201 | if (tdep->gpr_full_regnum != -1 && reg >= 0 && reg < 16) |
| 202 | return tdep->gpr_full_regnum + reg; |
| 203 | |
| 204 | if (reg >= 0 && reg < ARRAY_SIZE (s390_dwarf_regmap)) |
| 205 | return s390_dwarf_regmap[reg]; |
| 206 | |
| 207 | warning (_("Unmapped DWARF Register #%d encountered."), reg); |
| 208 | return -1; |
| 209 | } |
| 210 | |
| 211 | /* Translate a .eh_frame register to DWARF register, or adjust a |
| 212 | .debug_frame register. */ |
| 213 | static int |
| 214 | s390_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p) |
| 215 | { |
| 216 | /* See s390_dwarf_reg_to_regnum for comments. */ |
| 217 | return (num >= 0 && num < 16)? num + 66 : num; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /* Pseudo registers. */ |
| 222 | |
| 223 | static int |
| 224 | regnum_is_gpr_full (struct gdbarch_tdep *tdep, int regnum) |
| 225 | { |
| 226 | return (tdep->gpr_full_regnum != -1 |
| 227 | && regnum >= tdep->gpr_full_regnum |
| 228 | && regnum <= tdep->gpr_full_regnum + 15); |
| 229 | } |
| 230 | |
| 231 | static const char * |
| 232 | s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum) |
| 233 | { |
| 234 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 235 | |
| 236 | if (regnum == tdep->pc_regnum) |
| 237 | return "pc"; |
| 238 | |
| 239 | if (regnum == tdep->cc_regnum) |
| 240 | return "cc"; |
| 241 | |
| 242 | if (regnum_is_gpr_full (tdep, regnum)) |
| 243 | { |
| 244 | static const char *full_name[] = { |
| 245 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 246 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 247 | }; |
| 248 | return full_name[regnum - tdep->gpr_full_regnum]; |
| 249 | } |
| 250 | |
| 251 | internal_error (__FILE__, __LINE__, _("invalid regnum")); |
| 252 | } |
| 253 | |
| 254 | static struct type * |
| 255 | s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum) |
| 256 | { |
| 257 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 258 | |
| 259 | if (regnum == tdep->pc_regnum) |
| 260 | return builtin_type (gdbarch)->builtin_func_ptr; |
| 261 | |
| 262 | if (regnum == tdep->cc_regnum) |
| 263 | return builtin_type (gdbarch)->builtin_int; |
| 264 | |
| 265 | if (regnum_is_gpr_full (tdep, regnum)) |
| 266 | return builtin_type (gdbarch)->builtin_uint64; |
| 267 | |
| 268 | internal_error (__FILE__, __LINE__, _("invalid regnum")); |
| 269 | } |
| 270 | |
| 271 | static enum register_status |
| 272 | s390_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, |
| 273 | int regnum, gdb_byte *buf) |
| 274 | { |
| 275 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 276 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 277 | int regsize = register_size (gdbarch, regnum); |
| 278 | ULONGEST val; |
| 279 | |
| 280 | if (regnum == tdep->pc_regnum) |
| 281 | { |
| 282 | enum register_status status; |
| 283 | |
| 284 | status = regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &val); |
| 285 | if (status == REG_VALID) |
| 286 | { |
| 287 | if (register_size (gdbarch, S390_PSWA_REGNUM) == 4) |
| 288 | val &= 0x7fffffff; |
| 289 | store_unsigned_integer (buf, regsize, byte_order, val); |
| 290 | } |
| 291 | return status; |
| 292 | } |
| 293 | |
| 294 | if (regnum == tdep->cc_regnum) |
| 295 | { |
| 296 | enum register_status status; |
| 297 | |
| 298 | status = regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val); |
| 299 | if (status == REG_VALID) |
| 300 | { |
| 301 | if (register_size (gdbarch, S390_PSWA_REGNUM) == 4) |
| 302 | val = (val >> 12) & 3; |
| 303 | else |
| 304 | val = (val >> 44) & 3; |
| 305 | store_unsigned_integer (buf, regsize, byte_order, val); |
| 306 | } |
| 307 | return status; |
| 308 | } |
| 309 | |
| 310 | if (regnum_is_gpr_full (tdep, regnum)) |
| 311 | { |
| 312 | enum register_status status; |
| 313 | ULONGEST val_upper; |
| 314 | |
| 315 | regnum -= tdep->gpr_full_regnum; |
| 316 | |
| 317 | status = regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + regnum, &val); |
| 318 | if (status == REG_VALID) |
| 319 | status = regcache_raw_read_unsigned (regcache, S390_R0_UPPER_REGNUM + regnum, |
| 320 | &val_upper); |
| 321 | if (status == REG_VALID) |
| 322 | { |
| 323 | val |= val_upper << 32; |
| 324 | store_unsigned_integer (buf, regsize, byte_order, val); |
| 325 | } |
| 326 | return status; |
| 327 | } |
| 328 | |
| 329 | internal_error (__FILE__, __LINE__, _("invalid regnum")); |
| 330 | } |
| 331 | |
| 332 | static void |
| 333 | s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, |
| 334 | int regnum, const gdb_byte *buf) |
| 335 | { |
| 336 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 337 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 338 | int regsize = register_size (gdbarch, regnum); |
| 339 | ULONGEST val, psw; |
| 340 | |
| 341 | if (regnum == tdep->pc_regnum) |
| 342 | { |
| 343 | val = extract_unsigned_integer (buf, regsize, byte_order); |
| 344 | if (register_size (gdbarch, S390_PSWA_REGNUM) == 4) |
| 345 | { |
| 346 | regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw); |
| 347 | val = (psw & 0x80000000) | (val & 0x7fffffff); |
| 348 | } |
| 349 | regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, val); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | if (regnum == tdep->cc_regnum) |
| 354 | { |
| 355 | val = extract_unsigned_integer (buf, regsize, byte_order); |
| 356 | regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw); |
| 357 | if (register_size (gdbarch, S390_PSWA_REGNUM) == 4) |
| 358 | val = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12); |
| 359 | else |
| 360 | val = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44); |
| 361 | regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, val); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | if (regnum_is_gpr_full (tdep, regnum)) |
| 366 | { |
| 367 | regnum -= tdep->gpr_full_regnum; |
| 368 | val = extract_unsigned_integer (buf, regsize, byte_order); |
| 369 | regcache_raw_write_unsigned (regcache, S390_R0_REGNUM + regnum, |
| 370 | val & 0xffffffff); |
| 371 | regcache_raw_write_unsigned (regcache, S390_R0_UPPER_REGNUM + regnum, |
| 372 | val >> 32); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | internal_error (__FILE__, __LINE__, _("invalid regnum")); |
| 377 | } |
| 378 | |
| 379 | /* 'float' values are stored in the upper half of floating-point |
| 380 | registers, even though we are otherwise a big-endian platform. */ |
| 381 | |
| 382 | static struct value * |
| 383 | s390_value_from_register (struct gdbarch *gdbarch, struct type *type, |
| 384 | int regnum, struct frame_id frame_id) |
| 385 | { |
| 386 | struct value *value = default_value_from_register (gdbarch, type, |
| 387 | regnum, frame_id); |
| 388 | check_typedef (type); |
| 389 | |
| 390 | if (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM |
| 391 | && TYPE_LENGTH (type) < 8) |
| 392 | set_value_offset (value, 0); |
| 393 | |
| 394 | return value; |
| 395 | } |
| 396 | |
| 397 | /* Register groups. */ |
| 398 | |
| 399 | static int |
| 400 | s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum, |
| 401 | struct reggroup *group) |
| 402 | { |
| 403 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 404 | |
| 405 | /* We usually save/restore the whole PSW, which includes PC and CC. |
| 406 | However, some older gdbservers may not support saving/restoring |
| 407 | the whole PSW yet, and will return an XML register description |
| 408 | excluding those from the save/restore register groups. In those |
| 409 | cases, we still need to explicitly save/restore PC and CC in order |
| 410 | to push or pop frames. Since this doesn't hurt anything if we |
| 411 | already save/restore the whole PSW (it's just redundant), we add |
| 412 | PC and CC at this point unconditionally. */ |
| 413 | if (group == save_reggroup || group == restore_reggroup) |
| 414 | return regnum == tdep->pc_regnum || regnum == tdep->cc_regnum; |
| 415 | |
| 416 | return default_register_reggroup_p (gdbarch, regnum, group); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | /* Maps for register sets. */ |
| 421 | |
| 422 | static const struct regcache_map_entry s390_gregmap[] = |
| 423 | { |
| 424 | { 1, S390_PSWM_REGNUM }, |
| 425 | { 1, S390_PSWA_REGNUM }, |
| 426 | { 16, S390_R0_REGNUM }, |
| 427 | { 16, S390_A0_REGNUM }, |
| 428 | { 1, S390_ORIG_R2_REGNUM }, |
| 429 | { 0 } |
| 430 | }; |
| 431 | |
| 432 | static const struct regcache_map_entry s390_fpregmap[] = |
| 433 | { |
| 434 | { 1, S390_FPC_REGNUM, 8 }, |
| 435 | { 16, S390_F0_REGNUM, 8 }, |
| 436 | { 0 } |
| 437 | }; |
| 438 | |
| 439 | static const struct regcache_map_entry s390_regmap_upper[] = |
| 440 | { |
| 441 | { 16, S390_R0_UPPER_REGNUM, 4 }, |
| 442 | { 0 } |
| 443 | }; |
| 444 | |
| 445 | static const struct regcache_map_entry s390_regmap_last_break[] = |
| 446 | { |
| 447 | { 1, REGCACHE_MAP_SKIP, 4 }, |
| 448 | { 1, S390_LAST_BREAK_REGNUM, 4 }, |
| 449 | { 0 } |
| 450 | }; |
| 451 | |
| 452 | static const struct regcache_map_entry s390x_regmap_last_break[] = |
| 453 | { |
| 454 | { 1, S390_LAST_BREAK_REGNUM, 8 }, |
| 455 | { 0 } |
| 456 | }; |
| 457 | |
| 458 | static const struct regcache_map_entry s390_regmap_system_call[] = |
| 459 | { |
| 460 | { 1, S390_SYSTEM_CALL_REGNUM, 4 }, |
| 461 | { 0 } |
| 462 | }; |
| 463 | |
| 464 | static const struct regcache_map_entry s390_regmap_tdb[] = |
| 465 | { |
| 466 | { 1, S390_TDB_DWORD0_REGNUM, 8 }, |
| 467 | { 1, S390_TDB_ABORT_CODE_REGNUM, 8 }, |
| 468 | { 1, S390_TDB_CONFLICT_TOKEN_REGNUM, 8 }, |
| 469 | { 1, S390_TDB_ATIA_REGNUM, 8 }, |
| 470 | { 12, REGCACHE_MAP_SKIP, 8 }, |
| 471 | { 16, S390_TDB_R0_REGNUM, 8 }, |
| 472 | { 0 } |
| 473 | }; |
| 474 | |
| 475 | |
| 476 | /* Supply the TDB regset. Like regcache_supply_regset, but invalidate |
| 477 | the TDB registers unless the TDB format field is valid. */ |
| 478 | |
| 479 | static void |
| 480 | s390_supply_tdb_regset (const struct regset *regset, struct regcache *regcache, |
| 481 | int regnum, const void *regs, size_t len) |
| 482 | { |
| 483 | ULONGEST tdw; |
| 484 | enum register_status ret; |
| 485 | int i; |
| 486 | |
| 487 | regcache_supply_regset (regset, regcache, regnum, regs, len); |
| 488 | ret = regcache_cooked_read_unsigned (regcache, S390_TDB_DWORD0_REGNUM, &tdw); |
| 489 | if (ret != REG_VALID || (tdw >> 56) != 1) |
| 490 | regcache_supply_regset (regset, regcache, regnum, NULL, len); |
| 491 | } |
| 492 | |
| 493 | const struct regset s390_gregset = { |
| 494 | s390_gregmap, |
| 495 | regcache_supply_regset, |
| 496 | regcache_collect_regset |
| 497 | }; |
| 498 | |
| 499 | const struct regset s390_fpregset = { |
| 500 | s390_fpregmap, |
| 501 | regcache_supply_regset, |
| 502 | regcache_collect_regset |
| 503 | }; |
| 504 | |
| 505 | static const struct regset s390_upper_regset = { |
| 506 | s390_regmap_upper, |
| 507 | regcache_supply_regset, |
| 508 | regcache_collect_regset |
| 509 | }; |
| 510 | |
| 511 | const struct regset s390_last_break_regset = { |
| 512 | s390_regmap_last_break, |
| 513 | regcache_supply_regset, |
| 514 | regcache_collect_regset |
| 515 | }; |
| 516 | |
| 517 | const struct regset s390x_last_break_regset = { |
| 518 | s390x_regmap_last_break, |
| 519 | regcache_supply_regset, |
| 520 | regcache_collect_regset |
| 521 | }; |
| 522 | |
| 523 | const struct regset s390_system_call_regset = { |
| 524 | s390_regmap_system_call, |
| 525 | regcache_supply_regset, |
| 526 | regcache_collect_regset |
| 527 | }; |
| 528 | |
| 529 | const struct regset s390_tdb_regset = { |
| 530 | s390_regmap_tdb, |
| 531 | s390_supply_tdb_regset, |
| 532 | regcache_collect_regset |
| 533 | }; |
| 534 | |
| 535 | static struct core_regset_section s390_linux32_regset_sections[] = |
| 536 | { |
| 537 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 538 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 539 | { NULL, 0} |
| 540 | }; |
| 541 | |
| 542 | static struct core_regset_section s390_linux32v1_regset_sections[] = |
| 543 | { |
| 544 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 545 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 546 | { ".reg-s390-last-break", 8, "s390 last-break address" }, |
| 547 | { NULL, 0} |
| 548 | }; |
| 549 | |
| 550 | static struct core_regset_section s390_linux32v2_regset_sections[] = |
| 551 | { |
| 552 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 553 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 554 | { ".reg-s390-last-break", 8, "s390 last-break address" }, |
| 555 | { ".reg-s390-system-call", 4, "s390 system-call" }, |
| 556 | { NULL, 0} |
| 557 | }; |
| 558 | |
| 559 | static struct core_regset_section s390_linux64_regset_sections[] = |
| 560 | { |
| 561 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 562 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 563 | { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" }, |
| 564 | { NULL, 0} |
| 565 | }; |
| 566 | |
| 567 | static struct core_regset_section s390_linux64v1_regset_sections[] = |
| 568 | { |
| 569 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 570 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 571 | { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" }, |
| 572 | { ".reg-s390-last-break", 8, "s930 last-break address" }, |
| 573 | { NULL, 0} |
| 574 | }; |
| 575 | |
| 576 | static struct core_regset_section s390_linux64v2_regset_sections[] = |
| 577 | { |
| 578 | { ".reg", s390_sizeof_gregset, "general-purpose" }, |
| 579 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 580 | { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" }, |
| 581 | { ".reg-s390-last-break", 8, "s930 last-break address" }, |
| 582 | { ".reg-s390-system-call", 4, "s390 system-call" }, |
| 583 | { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" }, |
| 584 | { NULL, 0} |
| 585 | }; |
| 586 | |
| 587 | static struct core_regset_section s390x_linux64_regset_sections[] = |
| 588 | { |
| 589 | { ".reg", s390x_sizeof_gregset, "general-purpose" }, |
| 590 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 591 | { NULL, 0} |
| 592 | }; |
| 593 | |
| 594 | static struct core_regset_section s390x_linux64v1_regset_sections[] = |
| 595 | { |
| 596 | { ".reg", s390x_sizeof_gregset, "general-purpose" }, |
| 597 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 598 | { ".reg-s390-last-break", 8, "s930 last-break address" }, |
| 599 | { NULL, 0} |
| 600 | }; |
| 601 | |
| 602 | static struct core_regset_section s390x_linux64v2_regset_sections[] = |
| 603 | { |
| 604 | { ".reg", s390x_sizeof_gregset, "general-purpose" }, |
| 605 | { ".reg2", s390_sizeof_fpregset, "floating-point" }, |
| 606 | { ".reg-s390-last-break", 8, "s930 last-break address" }, |
| 607 | { ".reg-s390-system-call", 4, "s390 system-call" }, |
| 608 | { ".reg-s390-tdb", s390_sizeof_tdbregset, "s390 TDB" }, |
| 609 | { NULL, 0} |
| 610 | }; |
| 611 | |
| 612 | |
| 613 | /* Return the appropriate register set for the core section identified |
| 614 | by SECT_NAME and SECT_SIZE. */ |
| 615 | static const struct regset * |
| 616 | s390_regset_from_core_section (struct gdbarch *gdbarch, |
| 617 | const char *sect_name, size_t sect_size) |
| 618 | { |
| 619 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 620 | |
| 621 | if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset) |
| 622 | return tdep->gregset; |
| 623 | |
| 624 | if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset) |
| 625 | return tdep->fpregset; |
| 626 | |
| 627 | if (strcmp (sect_name, ".reg-s390-high-gprs") == 0 && sect_size >= 16*4) |
| 628 | return &s390_upper_regset; |
| 629 | |
| 630 | if (strcmp (sect_name, ".reg-s390-last-break") == 0 && sect_size >= 8) |
| 631 | return (gdbarch_ptr_bit (gdbarch) == 32 |
| 632 | ? &s390_last_break_regset : &s390x_last_break_regset); |
| 633 | |
| 634 | if (strcmp (sect_name, ".reg-s390-system-call") == 0 && sect_size >= 4) |
| 635 | return &s390_system_call_regset; |
| 636 | |
| 637 | if (strcmp (sect_name, ".reg-s390-tdb") == 0 && sect_size >= 256) |
| 638 | return &s390_tdb_regset; |
| 639 | |
| 640 | return NULL; |
| 641 | } |
| 642 | |
| 643 | static const struct target_desc * |
| 644 | s390_core_read_description (struct gdbarch *gdbarch, |
| 645 | struct target_ops *target, bfd *abfd) |
| 646 | { |
| 647 | asection *high_gprs = bfd_get_section_by_name (abfd, ".reg-s390-high-gprs"); |
| 648 | asection *v1 = bfd_get_section_by_name (abfd, ".reg-s390-last-break"); |
| 649 | asection *v2 = bfd_get_section_by_name (abfd, ".reg-s390-system-call"); |
| 650 | asection *section = bfd_get_section_by_name (abfd, ".reg"); |
| 651 | CORE_ADDR hwcap = 0; |
| 652 | |
| 653 | target_auxv_search (target, AT_HWCAP, &hwcap); |
| 654 | if (!section) |
| 655 | return NULL; |
| 656 | |
| 657 | switch (bfd_section_size (abfd, section)) |
| 658 | { |
| 659 | case s390_sizeof_gregset: |
| 660 | if (high_gprs) |
| 661 | return ((hwcap & HWCAP_S390_TE) ? tdesc_s390_te_linux64 : |
| 662 | v2? tdesc_s390_linux64v2 : |
| 663 | v1? tdesc_s390_linux64v1 : tdesc_s390_linux64); |
| 664 | else |
| 665 | return (v2? tdesc_s390_linux32v2 : |
| 666 | v1? tdesc_s390_linux32v1 : tdesc_s390_linux32); |
| 667 | |
| 668 | case s390x_sizeof_gregset: |
| 669 | return ((hwcap & HWCAP_S390_TE) ? tdesc_s390x_te_linux64 : |
| 670 | v2? tdesc_s390x_linux64v2 : |
| 671 | v1? tdesc_s390x_linux64v1 : tdesc_s390x_linux64); |
| 672 | |
| 673 | default: |
| 674 | return NULL; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |
| 679 | /* Decoding S/390 instructions. */ |
| 680 | |
| 681 | /* Named opcode values for the S/390 instructions we recognize. Some |
| 682 | instructions have their opcode split across two fields; those are the |
| 683 | op1_* and op2_* enums. */ |
| 684 | enum |
| 685 | { |
| 686 | op1_lhi = 0xa7, op2_lhi = 0x08, |
| 687 | op1_lghi = 0xa7, op2_lghi = 0x09, |
| 688 | op1_lgfi = 0xc0, op2_lgfi = 0x01, |
| 689 | op_lr = 0x18, |
| 690 | op_lgr = 0xb904, |
| 691 | op_l = 0x58, |
| 692 | op1_ly = 0xe3, op2_ly = 0x58, |
| 693 | op1_lg = 0xe3, op2_lg = 0x04, |
| 694 | op_lm = 0x98, |
| 695 | op1_lmy = 0xeb, op2_lmy = 0x98, |
| 696 | op1_lmg = 0xeb, op2_lmg = 0x04, |
| 697 | op_st = 0x50, |
| 698 | op1_sty = 0xe3, op2_sty = 0x50, |
| 699 | op1_stg = 0xe3, op2_stg = 0x24, |
| 700 | op_std = 0x60, |
| 701 | op_stm = 0x90, |
| 702 | op1_stmy = 0xeb, op2_stmy = 0x90, |
| 703 | op1_stmg = 0xeb, op2_stmg = 0x24, |
| 704 | op1_aghi = 0xa7, op2_aghi = 0x0b, |
| 705 | op1_ahi = 0xa7, op2_ahi = 0x0a, |
| 706 | op1_agfi = 0xc2, op2_agfi = 0x08, |
| 707 | op1_afi = 0xc2, op2_afi = 0x09, |
| 708 | op1_algfi= 0xc2, op2_algfi= 0x0a, |
| 709 | op1_alfi = 0xc2, op2_alfi = 0x0b, |
| 710 | op_ar = 0x1a, |
| 711 | op_agr = 0xb908, |
| 712 | op_a = 0x5a, |
| 713 | op1_ay = 0xe3, op2_ay = 0x5a, |
| 714 | op1_ag = 0xe3, op2_ag = 0x08, |
| 715 | op1_slgfi= 0xc2, op2_slgfi= 0x04, |
| 716 | op1_slfi = 0xc2, op2_slfi = 0x05, |
| 717 | op_sr = 0x1b, |
| 718 | op_sgr = 0xb909, |
| 719 | op_s = 0x5b, |
| 720 | op1_sy = 0xe3, op2_sy = 0x5b, |
| 721 | op1_sg = 0xe3, op2_sg = 0x09, |
| 722 | op_nr = 0x14, |
| 723 | op_ngr = 0xb980, |
| 724 | op_la = 0x41, |
| 725 | op1_lay = 0xe3, op2_lay = 0x71, |
| 726 | op1_larl = 0xc0, op2_larl = 0x00, |
| 727 | op_basr = 0x0d, |
| 728 | op_bas = 0x4d, |
| 729 | op_bcr = 0x07, |
| 730 | op_bc = 0x0d, |
| 731 | op_bctr = 0x06, |
| 732 | op_bctgr = 0xb946, |
| 733 | op_bct = 0x46, |
| 734 | op1_bctg = 0xe3, op2_bctg = 0x46, |
| 735 | op_bxh = 0x86, |
| 736 | op1_bxhg = 0xeb, op2_bxhg = 0x44, |
| 737 | op_bxle = 0x87, |
| 738 | op1_bxleg= 0xeb, op2_bxleg= 0x45, |
| 739 | op1_bras = 0xa7, op2_bras = 0x05, |
| 740 | op1_brasl= 0xc0, op2_brasl= 0x05, |
| 741 | op1_brc = 0xa7, op2_brc = 0x04, |
| 742 | op1_brcl = 0xc0, op2_brcl = 0x04, |
| 743 | op1_brct = 0xa7, op2_brct = 0x06, |
| 744 | op1_brctg= 0xa7, op2_brctg= 0x07, |
| 745 | op_brxh = 0x84, |
| 746 | op1_brxhg= 0xec, op2_brxhg= 0x44, |
| 747 | op_brxle = 0x85, |
| 748 | op1_brxlg= 0xec, op2_brxlg= 0x45, |
| 749 | op_svc = 0x0a, |
| 750 | }; |
| 751 | |
| 752 | |
| 753 | /* Read a single instruction from address AT. */ |
| 754 | |
| 755 | #define S390_MAX_INSTR_SIZE 6 |
| 756 | static int |
| 757 | s390_readinstruction (bfd_byte instr[], CORE_ADDR at) |
| 758 | { |
| 759 | static int s390_instrlen[] = { 2, 4, 4, 6 }; |
| 760 | int instrlen; |
| 761 | |
| 762 | if (target_read_memory (at, &instr[0], 2)) |
| 763 | return -1; |
| 764 | instrlen = s390_instrlen[instr[0] >> 6]; |
| 765 | if (instrlen > 2) |
| 766 | { |
| 767 | if (target_read_memory (at + 2, &instr[2], instrlen - 2)) |
| 768 | return -1; |
| 769 | } |
| 770 | return instrlen; |
| 771 | } |
| 772 | |
| 773 | |
| 774 | /* The functions below are for recognizing and decoding S/390 |
| 775 | instructions of various formats. Each of them checks whether INSN |
| 776 | is an instruction of the given format, with the specified opcodes. |
| 777 | If it is, it sets the remaining arguments to the values of the |
| 778 | instruction's fields, and returns a non-zero value; otherwise, it |
| 779 | returns zero. |
| 780 | |
| 781 | These functions' arguments appear in the order they appear in the |
| 782 | instruction, not in the machine-language form. So, opcodes always |
| 783 | come first, even though they're sometimes scattered around the |
| 784 | instructions. And displacements appear before base and extension |
| 785 | registers, as they do in the assembly syntax, not at the end, as |
| 786 | they do in the machine language. */ |
| 787 | static int |
| 788 | is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2) |
| 789 | { |
| 790 | if (insn[0] == op1 && (insn[1] & 0xf) == op2) |
| 791 | { |
| 792 | *r1 = (insn[1] >> 4) & 0xf; |
| 793 | /* i2 is a 16-bit signed quantity. */ |
| 794 | *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; |
| 795 | return 1; |
| 796 | } |
| 797 | else |
| 798 | return 0; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | static int |
| 803 | is_ril (bfd_byte *insn, int op1, int op2, |
| 804 | unsigned int *r1, int *i2) |
| 805 | { |
| 806 | if (insn[0] == op1 && (insn[1] & 0xf) == op2) |
| 807 | { |
| 808 | *r1 = (insn[1] >> 4) & 0xf; |
| 809 | /* i2 is a signed quantity. If the host 'int' is 32 bits long, |
| 810 | no sign extension is necessary, but we don't want to assume |
| 811 | that. */ |
| 812 | *i2 = (((insn[2] << 24) |
| 813 | | (insn[3] << 16) |
| 814 | | (insn[4] << 8) |
| 815 | | (insn[5])) ^ 0x80000000) - 0x80000000; |
| 816 | return 1; |
| 817 | } |
| 818 | else |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | static int |
| 824 | is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2) |
| 825 | { |
| 826 | if (insn[0] == op) |
| 827 | { |
| 828 | *r1 = (insn[1] >> 4) & 0xf; |
| 829 | *r2 = insn[1] & 0xf; |
| 830 | return 1; |
| 831 | } |
| 832 | else |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | |
| 837 | static int |
| 838 | is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2) |
| 839 | { |
| 840 | if (((insn[0] << 8) | insn[1]) == op) |
| 841 | { |
| 842 | /* Yes, insn[3]. insn[2] is unused in RRE format. */ |
| 843 | *r1 = (insn[3] >> 4) & 0xf; |
| 844 | *r2 = insn[3] & 0xf; |
| 845 | return 1; |
| 846 | } |
| 847 | else |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | |
| 852 | static int |
| 853 | is_rs (bfd_byte *insn, int op, |
| 854 | unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2) |
| 855 | { |
| 856 | if (insn[0] == op) |
| 857 | { |
| 858 | *r1 = (insn[1] >> 4) & 0xf; |
| 859 | *r3 = insn[1] & 0xf; |
| 860 | *b2 = (insn[2] >> 4) & 0xf; |
| 861 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; |
| 862 | return 1; |
| 863 | } |
| 864 | else |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | |
| 869 | static int |
| 870 | is_rsy (bfd_byte *insn, int op1, int op2, |
| 871 | unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2) |
| 872 | { |
| 873 | if (insn[0] == op1 |
| 874 | && insn[5] == op2) |
| 875 | { |
| 876 | *r1 = (insn[1] >> 4) & 0xf; |
| 877 | *r3 = insn[1] & 0xf; |
| 878 | *b2 = (insn[2] >> 4) & 0xf; |
| 879 | /* The 'long displacement' is a 20-bit signed integer. */ |
| 880 | *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12)) |
| 881 | ^ 0x80000) - 0x80000; |
| 882 | return 1; |
| 883 | } |
| 884 | else |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | |
| 889 | static int |
| 890 | is_rsi (bfd_byte *insn, int op, |
| 891 | unsigned int *r1, unsigned int *r3, int *i2) |
| 892 | { |
| 893 | if (insn[0] == op) |
| 894 | { |
| 895 | *r1 = (insn[1] >> 4) & 0xf; |
| 896 | *r3 = insn[1] & 0xf; |
| 897 | /* i2 is a 16-bit signed quantity. */ |
| 898 | *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; |
| 899 | return 1; |
| 900 | } |
| 901 | else |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | |
| 906 | static int |
| 907 | is_rie (bfd_byte *insn, int op1, int op2, |
| 908 | unsigned int *r1, unsigned int *r3, int *i2) |
| 909 | { |
| 910 | if (insn[0] == op1 |
| 911 | && insn[5] == op2) |
| 912 | { |
| 913 | *r1 = (insn[1] >> 4) & 0xf; |
| 914 | *r3 = insn[1] & 0xf; |
| 915 | /* i2 is a 16-bit signed quantity. */ |
| 916 | *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; |
| 917 | return 1; |
| 918 | } |
| 919 | else |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | |
| 924 | static int |
| 925 | is_rx (bfd_byte *insn, int op, |
| 926 | unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2) |
| 927 | { |
| 928 | if (insn[0] == op) |
| 929 | { |
| 930 | *r1 = (insn[1] >> 4) & 0xf; |
| 931 | *x2 = insn[1] & 0xf; |
| 932 | *b2 = (insn[2] >> 4) & 0xf; |
| 933 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; |
| 934 | return 1; |
| 935 | } |
| 936 | else |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | |
| 941 | static int |
| 942 | is_rxy (bfd_byte *insn, int op1, int op2, |
| 943 | unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2) |
| 944 | { |
| 945 | if (insn[0] == op1 |
| 946 | && insn[5] == op2) |
| 947 | { |
| 948 | *r1 = (insn[1] >> 4) & 0xf; |
| 949 | *x2 = insn[1] & 0xf; |
| 950 | *b2 = (insn[2] >> 4) & 0xf; |
| 951 | /* The 'long displacement' is a 20-bit signed integer. */ |
| 952 | *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12)) |
| 953 | ^ 0x80000) - 0x80000; |
| 954 | return 1; |
| 955 | } |
| 956 | else |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | |
| 961 | /* Prologue analysis. */ |
| 962 | |
| 963 | #define S390_NUM_GPRS 16 |
| 964 | #define S390_NUM_FPRS 16 |
| 965 | |
| 966 | struct s390_prologue_data { |
| 967 | |
| 968 | /* The stack. */ |
| 969 | struct pv_area *stack; |
| 970 | |
| 971 | /* The size and byte-order of a GPR or FPR. */ |
| 972 | int gpr_size; |
| 973 | int fpr_size; |
| 974 | enum bfd_endian byte_order; |
| 975 | |
| 976 | /* The general-purpose registers. */ |
| 977 | pv_t gpr[S390_NUM_GPRS]; |
| 978 | |
| 979 | /* The floating-point registers. */ |
| 980 | pv_t fpr[S390_NUM_FPRS]; |
| 981 | |
| 982 | /* The offset relative to the CFA where the incoming GPR N was saved |
| 983 | by the function prologue. 0 if not saved or unknown. */ |
| 984 | int gpr_slot[S390_NUM_GPRS]; |
| 985 | |
| 986 | /* Likewise for FPRs. */ |
| 987 | int fpr_slot[S390_NUM_FPRS]; |
| 988 | |
| 989 | /* Nonzero if the backchain was saved. This is assumed to be the |
| 990 | case when the incoming SP is saved at the current SP location. */ |
| 991 | int back_chain_saved_p; |
| 992 | }; |
| 993 | |
| 994 | /* Return the effective address for an X-style instruction, like: |
| 995 | |
| 996 | L R1, D2(X2, B2) |
| 997 | |
| 998 | Here, X2 and B2 are registers, and D2 is a signed 20-bit |
| 999 | constant; the effective address is the sum of all three. If either |
| 1000 | X2 or B2 are zero, then it doesn't contribute to the sum --- this |
| 1001 | means that r0 can't be used as either X2 or B2. */ |
| 1002 | static pv_t |
| 1003 | s390_addr (struct s390_prologue_data *data, |
| 1004 | int d2, unsigned int x2, unsigned int b2) |
| 1005 | { |
| 1006 | pv_t result; |
| 1007 | |
| 1008 | result = pv_constant (d2); |
| 1009 | if (x2) |
| 1010 | result = pv_add (result, data->gpr[x2]); |
| 1011 | if (b2) |
| 1012 | result = pv_add (result, data->gpr[b2]); |
| 1013 | |
| 1014 | return result; |
| 1015 | } |
| 1016 | |
| 1017 | /* Do a SIZE-byte store of VALUE to D2(X2,B2). */ |
| 1018 | static void |
| 1019 | s390_store (struct s390_prologue_data *data, |
| 1020 | int d2, unsigned int x2, unsigned int b2, CORE_ADDR size, |
| 1021 | pv_t value) |
| 1022 | { |
| 1023 | pv_t addr = s390_addr (data, d2, x2, b2); |
| 1024 | pv_t offset; |
| 1025 | |
| 1026 | /* Check whether we are storing the backchain. */ |
| 1027 | offset = pv_subtract (data->gpr[S390_SP_REGNUM - S390_R0_REGNUM], addr); |
| 1028 | |
| 1029 | if (pv_is_constant (offset) && offset.k == 0) |
| 1030 | if (size == data->gpr_size |
| 1031 | && pv_is_register_k (value, S390_SP_REGNUM, 0)) |
| 1032 | { |
| 1033 | data->back_chain_saved_p = 1; |
| 1034 | return; |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | /* Check whether we are storing a register into the stack. */ |
| 1039 | if (!pv_area_store_would_trash (data->stack, addr)) |
| 1040 | pv_area_store (data->stack, addr, size, value); |
| 1041 | |
| 1042 | |
| 1043 | /* Note: If this is some store we cannot identify, you might think we |
| 1044 | should forget our cached values, as any of those might have been hit. |
| 1045 | |
| 1046 | However, we make the assumption that the register save areas are only |
| 1047 | ever stored to once in any given function, and we do recognize these |
| 1048 | stores. Thus every store we cannot recognize does not hit our data. */ |
| 1049 | } |
| 1050 | |
| 1051 | /* Do a SIZE-byte load from D2(X2,B2). */ |
| 1052 | static pv_t |
| 1053 | s390_load (struct s390_prologue_data *data, |
| 1054 | int d2, unsigned int x2, unsigned int b2, CORE_ADDR size) |
| 1055 | |
| 1056 | { |
| 1057 | pv_t addr = s390_addr (data, d2, x2, b2); |
| 1058 | |
| 1059 | /* If it's a load from an in-line constant pool, then we can |
| 1060 | simulate that, under the assumption that the code isn't |
| 1061 | going to change between the time the processor actually |
| 1062 | executed it creating the current frame, and the time when |
| 1063 | we're analyzing the code to unwind past that frame. */ |
| 1064 | if (pv_is_constant (addr)) |
| 1065 | { |
| 1066 | struct target_section *secp; |
| 1067 | secp = target_section_by_addr (¤t_target, addr.k); |
| 1068 | if (secp != NULL |
| 1069 | && (bfd_get_section_flags (secp->the_bfd_section->owner, |
| 1070 | secp->the_bfd_section) |
| 1071 | & SEC_READONLY)) |
| 1072 | return pv_constant (read_memory_integer (addr.k, size, |
| 1073 | data->byte_order)); |
| 1074 | } |
| 1075 | |
| 1076 | /* Check whether we are accessing one of our save slots. */ |
| 1077 | return pv_area_fetch (data->stack, addr, size); |
| 1078 | } |
| 1079 | |
| 1080 | /* Function for finding saved registers in a 'struct pv_area'; we pass |
| 1081 | this to pv_area_scan. |
| 1082 | |
| 1083 | If VALUE is a saved register, ADDR says it was saved at a constant |
| 1084 | offset from the frame base, and SIZE indicates that the whole |
| 1085 | register was saved, record its offset in the reg_offset table in |
| 1086 | PROLOGUE_UNTYPED. */ |
| 1087 | static void |
| 1088 | s390_check_for_saved (void *data_untyped, pv_t addr, |
| 1089 | CORE_ADDR size, pv_t value) |
| 1090 | { |
| 1091 | struct s390_prologue_data *data = data_untyped; |
| 1092 | int i, offset; |
| 1093 | |
| 1094 | if (!pv_is_register (addr, S390_SP_REGNUM)) |
| 1095 | return; |
| 1096 | |
| 1097 | offset = 16 * data->gpr_size + 32 - addr.k; |
| 1098 | |
| 1099 | /* If we are storing the original value of a register, we want to |
| 1100 | record the CFA offset. If the same register is stored multiple |
| 1101 | times, the stack slot with the highest address counts. */ |
| 1102 | |
| 1103 | for (i = 0; i < S390_NUM_GPRS; i++) |
| 1104 | if (size == data->gpr_size |
| 1105 | && pv_is_register_k (value, S390_R0_REGNUM + i, 0)) |
| 1106 | if (data->gpr_slot[i] == 0 |
| 1107 | || data->gpr_slot[i] > offset) |
| 1108 | { |
| 1109 | data->gpr_slot[i] = offset; |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | for (i = 0; i < S390_NUM_FPRS; i++) |
| 1114 | if (size == data->fpr_size |
| 1115 | && pv_is_register_k (value, S390_F0_REGNUM + i, 0)) |
| 1116 | if (data->fpr_slot[i] == 0 |
| 1117 | || data->fpr_slot[i] > offset) |
| 1118 | { |
| 1119 | data->fpr_slot[i] = offset; |
| 1120 | return; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /* Analyze the prologue of the function starting at START_PC, |
| 1125 | continuing at most until CURRENT_PC. Initialize DATA to |
| 1126 | hold all information we find out about the state of the registers |
| 1127 | and stack slots. Return the address of the instruction after |
| 1128 | the last one that changed the SP, FP, or back chain; or zero |
| 1129 | on error. */ |
| 1130 | static CORE_ADDR |
| 1131 | s390_analyze_prologue (struct gdbarch *gdbarch, |
| 1132 | CORE_ADDR start_pc, |
| 1133 | CORE_ADDR current_pc, |
| 1134 | struct s390_prologue_data *data) |
| 1135 | { |
| 1136 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 1137 | |
| 1138 | /* Our return value: |
| 1139 | The address of the instruction after the last one that changed |
| 1140 | the SP, FP, or back chain; zero if we got an error trying to |
| 1141 | read memory. */ |
| 1142 | CORE_ADDR result = start_pc; |
| 1143 | |
| 1144 | /* The current PC for our abstract interpretation. */ |
| 1145 | CORE_ADDR pc; |
| 1146 | |
| 1147 | /* The address of the next instruction after that. */ |
| 1148 | CORE_ADDR next_pc; |
| 1149 | |
| 1150 | /* Set up everything's initial value. */ |
| 1151 | { |
| 1152 | int i; |
| 1153 | |
| 1154 | data->stack = make_pv_area (S390_SP_REGNUM, gdbarch_addr_bit (gdbarch)); |
| 1155 | |
| 1156 | /* For the purpose of prologue tracking, we consider the GPR size to |
| 1157 | be equal to the ABI word size, even if it is actually larger |
| 1158 | (i.e. when running a 32-bit binary under a 64-bit kernel). */ |
| 1159 | data->gpr_size = word_size; |
| 1160 | data->fpr_size = 8; |
| 1161 | data->byte_order = gdbarch_byte_order (gdbarch); |
| 1162 | |
| 1163 | for (i = 0; i < S390_NUM_GPRS; i++) |
| 1164 | data->gpr[i] = pv_register (S390_R0_REGNUM + i, 0); |
| 1165 | |
| 1166 | for (i = 0; i < S390_NUM_FPRS; i++) |
| 1167 | data->fpr[i] = pv_register (S390_F0_REGNUM + i, 0); |
| 1168 | |
| 1169 | for (i = 0; i < S390_NUM_GPRS; i++) |
| 1170 | data->gpr_slot[i] = 0; |
| 1171 | |
| 1172 | for (i = 0; i < S390_NUM_FPRS; i++) |
| 1173 | data->fpr_slot[i] = 0; |
| 1174 | |
| 1175 | data->back_chain_saved_p = 0; |
| 1176 | } |
| 1177 | |
| 1178 | /* Start interpreting instructions, until we hit the frame's |
| 1179 | current PC or the first branch instruction. */ |
| 1180 | for (pc = start_pc; pc > 0 && pc < current_pc; pc = next_pc) |
| 1181 | { |
| 1182 | bfd_byte insn[S390_MAX_INSTR_SIZE]; |
| 1183 | int insn_len = s390_readinstruction (insn, pc); |
| 1184 | |
| 1185 | bfd_byte dummy[S390_MAX_INSTR_SIZE] = { 0 }; |
| 1186 | bfd_byte *insn32 = word_size == 4 ? insn : dummy; |
| 1187 | bfd_byte *insn64 = word_size == 8 ? insn : dummy; |
| 1188 | |
| 1189 | /* Fields for various kinds of instructions. */ |
| 1190 | unsigned int b2, r1, r2, x2, r3; |
| 1191 | int i2, d2; |
| 1192 | |
| 1193 | /* The values of SP and FP before this instruction, |
| 1194 | for detecting instructions that change them. */ |
| 1195 | pv_t pre_insn_sp, pre_insn_fp; |
| 1196 | /* Likewise for the flag whether the back chain was saved. */ |
| 1197 | int pre_insn_back_chain_saved_p; |
| 1198 | |
| 1199 | /* If we got an error trying to read the instruction, report it. */ |
| 1200 | if (insn_len < 0) |
| 1201 | { |
| 1202 | result = 0; |
| 1203 | break; |
| 1204 | } |
| 1205 | |
| 1206 | next_pc = pc + insn_len; |
| 1207 | |
| 1208 | pre_insn_sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM]; |
| 1209 | pre_insn_fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM]; |
| 1210 | pre_insn_back_chain_saved_p = data->back_chain_saved_p; |
| 1211 | |
| 1212 | |
| 1213 | /* LHI r1, i2 --- load halfword immediate. */ |
| 1214 | /* LGHI r1, i2 --- load halfword immediate (64-bit version). */ |
| 1215 | /* LGFI r1, i2 --- load fullword immediate. */ |
| 1216 | if (is_ri (insn32, op1_lhi, op2_lhi, &r1, &i2) |
| 1217 | || is_ri (insn64, op1_lghi, op2_lghi, &r1, &i2) |
| 1218 | || is_ril (insn, op1_lgfi, op2_lgfi, &r1, &i2)) |
| 1219 | data->gpr[r1] = pv_constant (i2); |
| 1220 | |
| 1221 | /* LR r1, r2 --- load from register. */ |
| 1222 | /* LGR r1, r2 --- load from register (64-bit version). */ |
| 1223 | else if (is_rr (insn32, op_lr, &r1, &r2) |
| 1224 | || is_rre (insn64, op_lgr, &r1, &r2)) |
| 1225 | data->gpr[r1] = data->gpr[r2]; |
| 1226 | |
| 1227 | /* L r1, d2(x2, b2) --- load. */ |
| 1228 | /* LY r1, d2(x2, b2) --- load (long-displacement version). */ |
| 1229 | /* LG r1, d2(x2, b2) --- load (64-bit version). */ |
| 1230 | else if (is_rx (insn32, op_l, &r1, &d2, &x2, &b2) |
| 1231 | || is_rxy (insn32, op1_ly, op2_ly, &r1, &d2, &x2, &b2) |
| 1232 | || is_rxy (insn64, op1_lg, op2_lg, &r1, &d2, &x2, &b2)) |
| 1233 | data->gpr[r1] = s390_load (data, d2, x2, b2, data->gpr_size); |
| 1234 | |
| 1235 | /* ST r1, d2(x2, b2) --- store. */ |
| 1236 | /* STY r1, d2(x2, b2) --- store (long-displacement version). */ |
| 1237 | /* STG r1, d2(x2, b2) --- store (64-bit version). */ |
| 1238 | else if (is_rx (insn32, op_st, &r1, &d2, &x2, &b2) |
| 1239 | || is_rxy (insn32, op1_sty, op2_sty, &r1, &d2, &x2, &b2) |
| 1240 | || is_rxy (insn64, op1_stg, op2_stg, &r1, &d2, &x2, &b2)) |
| 1241 | s390_store (data, d2, x2, b2, data->gpr_size, data->gpr[r1]); |
| 1242 | |
| 1243 | /* STD r1, d2(x2,b2) --- store floating-point register. */ |
| 1244 | else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2)) |
| 1245 | s390_store (data, d2, x2, b2, data->fpr_size, data->fpr[r1]); |
| 1246 | |
| 1247 | /* STM r1, r3, d2(b2) --- store multiple. */ |
| 1248 | /* STMY r1, r3, d2(b2) --- store multiple (long-displacement |
| 1249 | version). */ |
| 1250 | /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */ |
| 1251 | else if (is_rs (insn32, op_stm, &r1, &r3, &d2, &b2) |
| 1252 | || is_rsy (insn32, op1_stmy, op2_stmy, &r1, &r3, &d2, &b2) |
| 1253 | || is_rsy (insn64, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2)) |
| 1254 | { |
| 1255 | for (; r1 <= r3; r1++, d2 += data->gpr_size) |
| 1256 | s390_store (data, d2, 0, b2, data->gpr_size, data->gpr[r1]); |
| 1257 | } |
| 1258 | |
| 1259 | /* AHI r1, i2 --- add halfword immediate. */ |
| 1260 | /* AGHI r1, i2 --- add halfword immediate (64-bit version). */ |
| 1261 | /* AFI r1, i2 --- add fullword immediate. */ |
| 1262 | /* AGFI r1, i2 --- add fullword immediate (64-bit version). */ |
| 1263 | else if (is_ri (insn32, op1_ahi, op2_ahi, &r1, &i2) |
| 1264 | || is_ri (insn64, op1_aghi, op2_aghi, &r1, &i2) |
| 1265 | || is_ril (insn32, op1_afi, op2_afi, &r1, &i2) |
| 1266 | || is_ril (insn64, op1_agfi, op2_agfi, &r1, &i2)) |
| 1267 | data->gpr[r1] = pv_add_constant (data->gpr[r1], i2); |
| 1268 | |
| 1269 | /* ALFI r1, i2 --- add logical immediate. */ |
| 1270 | /* ALGFI r1, i2 --- add logical immediate (64-bit version). */ |
| 1271 | else if (is_ril (insn32, op1_alfi, op2_alfi, &r1, &i2) |
| 1272 | || is_ril (insn64, op1_algfi, op2_algfi, &r1, &i2)) |
| 1273 | data->gpr[r1] = pv_add_constant (data->gpr[r1], |
| 1274 | (CORE_ADDR)i2 & 0xffffffff); |
| 1275 | |
| 1276 | /* AR r1, r2 -- add register. */ |
| 1277 | /* AGR r1, r2 -- add register (64-bit version). */ |
| 1278 | else if (is_rr (insn32, op_ar, &r1, &r2) |
| 1279 | || is_rre (insn64, op_agr, &r1, &r2)) |
| 1280 | data->gpr[r1] = pv_add (data->gpr[r1], data->gpr[r2]); |
| 1281 | |
| 1282 | /* A r1, d2(x2, b2) -- add. */ |
| 1283 | /* AY r1, d2(x2, b2) -- add (long-displacement version). */ |
| 1284 | /* AG r1, d2(x2, b2) -- add (64-bit version). */ |
| 1285 | else if (is_rx (insn32, op_a, &r1, &d2, &x2, &b2) |
| 1286 | || is_rxy (insn32, op1_ay, op2_ay, &r1, &d2, &x2, &b2) |
| 1287 | || is_rxy (insn64, op1_ag, op2_ag, &r1, &d2, &x2, &b2)) |
| 1288 | data->gpr[r1] = pv_add (data->gpr[r1], |
| 1289 | s390_load (data, d2, x2, b2, data->gpr_size)); |
| 1290 | |
| 1291 | /* SLFI r1, i2 --- subtract logical immediate. */ |
| 1292 | /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */ |
| 1293 | else if (is_ril (insn32, op1_slfi, op2_slfi, &r1, &i2) |
| 1294 | || is_ril (insn64, op1_slgfi, op2_slgfi, &r1, &i2)) |
| 1295 | data->gpr[r1] = pv_add_constant (data->gpr[r1], |
| 1296 | -((CORE_ADDR)i2 & 0xffffffff)); |
| 1297 | |
| 1298 | /* SR r1, r2 -- subtract register. */ |
| 1299 | /* SGR r1, r2 -- subtract register (64-bit version). */ |
| 1300 | else if (is_rr (insn32, op_sr, &r1, &r2) |
| 1301 | || is_rre (insn64, op_sgr, &r1, &r2)) |
| 1302 | data->gpr[r1] = pv_subtract (data->gpr[r1], data->gpr[r2]); |
| 1303 | |
| 1304 | /* S r1, d2(x2, b2) -- subtract. */ |
| 1305 | /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */ |
| 1306 | /* SG r1, d2(x2, b2) -- subtract (64-bit version). */ |
| 1307 | else if (is_rx (insn32, op_s, &r1, &d2, &x2, &b2) |
| 1308 | || is_rxy (insn32, op1_sy, op2_sy, &r1, &d2, &x2, &b2) |
| 1309 | || is_rxy (insn64, op1_sg, op2_sg, &r1, &d2, &x2, &b2)) |
| 1310 | data->gpr[r1] = pv_subtract (data->gpr[r1], |
| 1311 | s390_load (data, d2, x2, b2, data->gpr_size)); |
| 1312 | |
| 1313 | /* LA r1, d2(x2, b2) --- load address. */ |
| 1314 | /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */ |
| 1315 | else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2) |
| 1316 | || is_rxy (insn, op1_lay, op2_lay, &r1, &d2, &x2, &b2)) |
| 1317 | data->gpr[r1] = s390_addr (data, d2, x2, b2); |
| 1318 | |
| 1319 | /* LARL r1, i2 --- load address relative long. */ |
| 1320 | else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2)) |
| 1321 | data->gpr[r1] = pv_constant (pc + i2 * 2); |
| 1322 | |
| 1323 | /* BASR r1, 0 --- branch and save. |
| 1324 | Since r2 is zero, this saves the PC in r1, but doesn't branch. */ |
| 1325 | else if (is_rr (insn, op_basr, &r1, &r2) |
| 1326 | && r2 == 0) |
| 1327 | data->gpr[r1] = pv_constant (next_pc); |
| 1328 | |
| 1329 | /* BRAS r1, i2 --- branch relative and save. */ |
| 1330 | else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2)) |
| 1331 | { |
| 1332 | data->gpr[r1] = pv_constant (next_pc); |
| 1333 | next_pc = pc + i2 * 2; |
| 1334 | |
| 1335 | /* We'd better not interpret any backward branches. We'll |
| 1336 | never terminate. */ |
| 1337 | if (next_pc <= pc) |
| 1338 | break; |
| 1339 | } |
| 1340 | |
| 1341 | /* Terminate search when hitting any other branch instruction. */ |
| 1342 | else if (is_rr (insn, op_basr, &r1, &r2) |
| 1343 | || is_rx (insn, op_bas, &r1, &d2, &x2, &b2) |
| 1344 | || is_rr (insn, op_bcr, &r1, &r2) |
| 1345 | || is_rx (insn, op_bc, &r1, &d2, &x2, &b2) |
| 1346 | || is_ri (insn, op1_brc, op2_brc, &r1, &i2) |
| 1347 | || is_ril (insn, op1_brcl, op2_brcl, &r1, &i2) |
| 1348 | || is_ril (insn, op1_brasl, op2_brasl, &r2, &i2)) |
| 1349 | break; |
| 1350 | |
| 1351 | else |
| 1352 | { |
| 1353 | /* An instruction we don't know how to simulate. The only |
| 1354 | safe thing to do would be to set every value we're tracking |
| 1355 | to 'unknown'. Instead, we'll be optimistic: we assume that |
| 1356 | we *can* interpret every instruction that the compiler uses |
| 1357 | to manipulate any of the data we're interested in here -- |
| 1358 | then we can just ignore anything else. */ |
| 1359 | } |
| 1360 | |
| 1361 | /* Record the address after the last instruction that changed |
| 1362 | the FP, SP, or backlink. Ignore instructions that changed |
| 1363 | them back to their original values --- those are probably |
| 1364 | restore instructions. (The back chain is never restored, |
| 1365 | just popped.) */ |
| 1366 | { |
| 1367 | pv_t sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM]; |
| 1368 | pv_t fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM]; |
| 1369 | |
| 1370 | if ((! pv_is_identical (pre_insn_sp, sp) |
| 1371 | && ! pv_is_register_k (sp, S390_SP_REGNUM, 0) |
| 1372 | && sp.kind != pvk_unknown) |
| 1373 | || (! pv_is_identical (pre_insn_fp, fp) |
| 1374 | && ! pv_is_register_k (fp, S390_FRAME_REGNUM, 0) |
| 1375 | && fp.kind != pvk_unknown) |
| 1376 | || pre_insn_back_chain_saved_p != data->back_chain_saved_p) |
| 1377 | result = next_pc; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | /* Record where all the registers were saved. */ |
| 1382 | pv_area_scan (data->stack, s390_check_for_saved, data); |
| 1383 | |
| 1384 | free_pv_area (data->stack); |
| 1385 | data->stack = NULL; |
| 1386 | |
| 1387 | return result; |
| 1388 | } |
| 1389 | |
| 1390 | /* Advance PC across any function entry prologue instructions to reach |
| 1391 | some "real" code. */ |
| 1392 | static CORE_ADDR |
| 1393 | s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 1394 | { |
| 1395 | struct s390_prologue_data data; |
| 1396 | CORE_ADDR skip_pc; |
| 1397 | skip_pc = s390_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data); |
| 1398 | return skip_pc ? skip_pc : pc; |
| 1399 | } |
| 1400 | |
| 1401 | /* Return true if we are in the functin's epilogue, i.e. after the |
| 1402 | instruction that destroyed the function's stack frame. */ |
| 1403 | static int |
| 1404 | s390_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 1405 | { |
| 1406 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 1407 | |
| 1408 | /* In frameless functions, there's not frame to destroy and thus |
| 1409 | we don't care about the epilogue. |
| 1410 | |
| 1411 | In functions with frame, the epilogue sequence is a pair of |
| 1412 | a LM-type instruction that restores (amongst others) the |
| 1413 | return register %r14 and the stack pointer %r15, followed |
| 1414 | by a branch 'br %r14' --or equivalent-- that effects the |
| 1415 | actual return. |
| 1416 | |
| 1417 | In that situation, this function needs to return 'true' in |
| 1418 | exactly one case: when pc points to that branch instruction. |
| 1419 | |
| 1420 | Thus we try to disassemble the one instructions immediately |
| 1421 | preceding pc and check whether it is an LM-type instruction |
| 1422 | modifying the stack pointer. |
| 1423 | |
| 1424 | Note that disassembling backwards is not reliable, so there |
| 1425 | is a slight chance of false positives here ... */ |
| 1426 | |
| 1427 | bfd_byte insn[6]; |
| 1428 | unsigned int r1, r3, b2; |
| 1429 | int d2; |
| 1430 | |
| 1431 | if (word_size == 4 |
| 1432 | && !target_read_memory (pc - 4, insn, 4) |
| 1433 | && is_rs (insn, op_lm, &r1, &r3, &d2, &b2) |
| 1434 | && r3 == S390_SP_REGNUM - S390_R0_REGNUM) |
| 1435 | return 1; |
| 1436 | |
| 1437 | if (word_size == 4 |
| 1438 | && !target_read_memory (pc - 6, insn, 6) |
| 1439 | && is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2) |
| 1440 | && r3 == S390_SP_REGNUM - S390_R0_REGNUM) |
| 1441 | return 1; |
| 1442 | |
| 1443 | if (word_size == 8 |
| 1444 | && !target_read_memory (pc - 6, insn, 6) |
| 1445 | && is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2) |
| 1446 | && r3 == S390_SP_REGNUM - S390_R0_REGNUM) |
| 1447 | return 1; |
| 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | /* Displaced stepping. */ |
| 1453 | |
| 1454 | /* Fix up the state of registers and memory after having single-stepped |
| 1455 | a displaced instruction. */ |
| 1456 | static void |
| 1457 | s390_displaced_step_fixup (struct gdbarch *gdbarch, |
| 1458 | struct displaced_step_closure *closure, |
| 1459 | CORE_ADDR from, CORE_ADDR to, |
| 1460 | struct regcache *regs) |
| 1461 | { |
| 1462 | /* Since we use simple_displaced_step_copy_insn, our closure is a |
| 1463 | copy of the instruction. */ |
| 1464 | gdb_byte *insn = (gdb_byte *) closure; |
| 1465 | static int s390_instrlen[] = { 2, 4, 4, 6 }; |
| 1466 | int insnlen = s390_instrlen[insn[0] >> 6]; |
| 1467 | |
| 1468 | /* Fields for various kinds of instructions. */ |
| 1469 | unsigned int b2, r1, r2, x2, r3; |
| 1470 | int i2, d2; |
| 1471 | |
| 1472 | /* Get current PC and addressing mode bit. */ |
| 1473 | CORE_ADDR pc = regcache_read_pc (regs); |
| 1474 | ULONGEST amode = 0; |
| 1475 | |
| 1476 | if (register_size (gdbarch, S390_PSWA_REGNUM) == 4) |
| 1477 | { |
| 1478 | regcache_cooked_read_unsigned (regs, S390_PSWA_REGNUM, &amode); |
| 1479 | amode &= 0x80000000; |
| 1480 | } |
| 1481 | |
| 1482 | if (debug_displaced) |
| 1483 | fprintf_unfiltered (gdb_stdlog, |
| 1484 | "displaced: (s390) fixup (%s, %s) pc %s len %d amode 0x%x\n", |
| 1485 | paddress (gdbarch, from), paddress (gdbarch, to), |
| 1486 | paddress (gdbarch, pc), insnlen, (int) amode); |
| 1487 | |
| 1488 | /* Handle absolute branch and save instructions. */ |
| 1489 | if (is_rr (insn, op_basr, &r1, &r2) |
| 1490 | || is_rx (insn, op_bas, &r1, &d2, &x2, &b2)) |
| 1491 | { |
| 1492 | /* Recompute saved return address in R1. */ |
| 1493 | regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1, |
| 1494 | amode | (from + insnlen)); |
| 1495 | } |
| 1496 | |
| 1497 | /* Handle absolute branch instructions. */ |
| 1498 | else if (is_rr (insn, op_bcr, &r1, &r2) |
| 1499 | || is_rx (insn, op_bc, &r1, &d2, &x2, &b2) |
| 1500 | || is_rr (insn, op_bctr, &r1, &r2) |
| 1501 | || is_rre (insn, op_bctgr, &r1, &r2) |
| 1502 | || is_rx (insn, op_bct, &r1, &d2, &x2, &b2) |
| 1503 | || is_rxy (insn, op1_bctg, op2_brctg, &r1, &d2, &x2, &b2) |
| 1504 | || is_rs (insn, op_bxh, &r1, &r3, &d2, &b2) |
| 1505 | || is_rsy (insn, op1_bxhg, op2_bxhg, &r1, &r3, &d2, &b2) |
| 1506 | || is_rs (insn, op_bxle, &r1, &r3, &d2, &b2) |
| 1507 | || is_rsy (insn, op1_bxleg, op2_bxleg, &r1, &r3, &d2, &b2)) |
| 1508 | { |
| 1509 | /* Update PC iff branch was *not* taken. */ |
| 1510 | if (pc == to + insnlen) |
| 1511 | regcache_write_pc (regs, from + insnlen); |
| 1512 | } |
| 1513 | |
| 1514 | /* Handle PC-relative branch and save instructions. */ |
| 1515 | else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2) |
| 1516 | || is_ril (insn, op1_brasl, op2_brasl, &r1, &i2)) |
| 1517 | { |
| 1518 | /* Update PC. */ |
| 1519 | regcache_write_pc (regs, pc - to + from); |
| 1520 | /* Recompute saved return address in R1. */ |
| 1521 | regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1, |
| 1522 | amode | (from + insnlen)); |
| 1523 | } |
| 1524 | |
| 1525 | /* Handle PC-relative branch instructions. */ |
| 1526 | else if (is_ri (insn, op1_brc, op2_brc, &r1, &i2) |
| 1527 | || is_ril (insn, op1_brcl, op2_brcl, &r1, &i2) |
| 1528 | || is_ri (insn, op1_brct, op2_brct, &r1, &i2) |
| 1529 | || is_ri (insn, op1_brctg, op2_brctg, &r1, &i2) |
| 1530 | || is_rsi (insn, op_brxh, &r1, &r3, &i2) |
| 1531 | || is_rie (insn, op1_brxhg, op2_brxhg, &r1, &r3, &i2) |
| 1532 | || is_rsi (insn, op_brxle, &r1, &r3, &i2) |
| 1533 | || is_rie (insn, op1_brxlg, op2_brxlg, &r1, &r3, &i2)) |
| 1534 | { |
| 1535 | /* Update PC. */ |
| 1536 | regcache_write_pc (regs, pc - to + from); |
| 1537 | } |
| 1538 | |
| 1539 | /* Handle LOAD ADDRESS RELATIVE LONG. */ |
| 1540 | else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2)) |
| 1541 | { |
| 1542 | /* Update PC. */ |
| 1543 | regcache_write_pc (regs, from + insnlen); |
| 1544 | /* Recompute output address in R1. */ |
| 1545 | regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1, |
| 1546 | amode | (from + i2 * 2)); |
| 1547 | } |
| 1548 | |
| 1549 | /* If we executed a breakpoint instruction, point PC right back at it. */ |
| 1550 | else if (insn[0] == 0x0 && insn[1] == 0x1) |
| 1551 | regcache_write_pc (regs, from); |
| 1552 | |
| 1553 | /* For any other insn, PC points right after the original instruction. */ |
| 1554 | else |
| 1555 | regcache_write_pc (regs, from + insnlen); |
| 1556 | |
| 1557 | if (debug_displaced) |
| 1558 | fprintf_unfiltered (gdb_stdlog, |
| 1559 | "displaced: (s390) pc is now %s\n", |
| 1560 | paddress (gdbarch, regcache_read_pc (regs))); |
| 1561 | } |
| 1562 | |
| 1563 | |
| 1564 | /* Helper routine to unwind pseudo registers. */ |
| 1565 | |
| 1566 | static struct value * |
| 1567 | s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum) |
| 1568 | { |
| 1569 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1570 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 1571 | struct type *type = register_type (gdbarch, regnum); |
| 1572 | |
| 1573 | /* Unwind PC via PSW address. */ |
| 1574 | if (regnum == tdep->pc_regnum) |
| 1575 | { |
| 1576 | struct value *val; |
| 1577 | |
| 1578 | val = frame_unwind_register_value (this_frame, S390_PSWA_REGNUM); |
| 1579 | if (!value_optimized_out (val)) |
| 1580 | { |
| 1581 | LONGEST pswa = value_as_long (val); |
| 1582 | |
| 1583 | if (TYPE_LENGTH (type) == 4) |
| 1584 | return value_from_pointer (type, pswa & 0x7fffffff); |
| 1585 | else |
| 1586 | return value_from_pointer (type, pswa); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | /* Unwind CC via PSW mask. */ |
| 1591 | if (regnum == tdep->cc_regnum) |
| 1592 | { |
| 1593 | struct value *val; |
| 1594 | |
| 1595 | val = frame_unwind_register_value (this_frame, S390_PSWM_REGNUM); |
| 1596 | if (!value_optimized_out (val)) |
| 1597 | { |
| 1598 | LONGEST pswm = value_as_long (val); |
| 1599 | |
| 1600 | if (TYPE_LENGTH (type) == 4) |
| 1601 | return value_from_longest (type, (pswm >> 12) & 3); |
| 1602 | else |
| 1603 | return value_from_longest (type, (pswm >> 44) & 3); |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | /* Unwind full GPRs to show at least the lower halves (as the |
| 1608 | upper halves are undefined). */ |
| 1609 | if (regnum_is_gpr_full (tdep, regnum)) |
| 1610 | { |
| 1611 | int reg = regnum - tdep->gpr_full_regnum; |
| 1612 | struct value *val; |
| 1613 | |
| 1614 | val = frame_unwind_register_value (this_frame, S390_R0_REGNUM + reg); |
| 1615 | if (!value_optimized_out (val)) |
| 1616 | return value_cast (type, val); |
| 1617 | } |
| 1618 | |
| 1619 | return allocate_optimized_out_value (type); |
| 1620 | } |
| 1621 | |
| 1622 | static struct value * |
| 1623 | s390_trad_frame_prev_register (struct frame_info *this_frame, |
| 1624 | struct trad_frame_saved_reg saved_regs[], |
| 1625 | int regnum) |
| 1626 | { |
| 1627 | if (regnum < S390_NUM_REGS) |
| 1628 | return trad_frame_get_prev_register (this_frame, saved_regs, regnum); |
| 1629 | else |
| 1630 | return s390_unwind_pseudo_register (this_frame, regnum); |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | /* Normal stack frames. */ |
| 1635 | |
| 1636 | struct s390_unwind_cache { |
| 1637 | |
| 1638 | CORE_ADDR func; |
| 1639 | CORE_ADDR frame_base; |
| 1640 | CORE_ADDR local_base; |
| 1641 | |
| 1642 | struct trad_frame_saved_reg *saved_regs; |
| 1643 | }; |
| 1644 | |
| 1645 | static int |
| 1646 | s390_prologue_frame_unwind_cache (struct frame_info *this_frame, |
| 1647 | struct s390_unwind_cache *info) |
| 1648 | { |
| 1649 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1650 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 1651 | struct s390_prologue_data data; |
| 1652 | pv_t *fp = &data.gpr[S390_FRAME_REGNUM - S390_R0_REGNUM]; |
| 1653 | pv_t *sp = &data.gpr[S390_SP_REGNUM - S390_R0_REGNUM]; |
| 1654 | int i; |
| 1655 | CORE_ADDR cfa; |
| 1656 | CORE_ADDR func; |
| 1657 | CORE_ADDR result; |
| 1658 | ULONGEST reg; |
| 1659 | CORE_ADDR prev_sp; |
| 1660 | int frame_pointer; |
| 1661 | int size; |
| 1662 | struct frame_info *next_frame; |
| 1663 | |
| 1664 | /* Try to find the function start address. If we can't find it, we don't |
| 1665 | bother searching for it -- with modern compilers this would be mostly |
| 1666 | pointless anyway. Trust that we'll either have valid DWARF-2 CFI data |
| 1667 | or else a valid backchain ... */ |
| 1668 | func = get_frame_func (this_frame); |
| 1669 | if (!func) |
| 1670 | return 0; |
| 1671 | |
| 1672 | /* Try to analyze the prologue. */ |
| 1673 | result = s390_analyze_prologue (gdbarch, func, |
| 1674 | get_frame_pc (this_frame), &data); |
| 1675 | if (!result) |
| 1676 | return 0; |
| 1677 | |
| 1678 | /* If this was successful, we should have found the instruction that |
| 1679 | sets the stack pointer register to the previous value of the stack |
| 1680 | pointer minus the frame size. */ |
| 1681 | if (!pv_is_register (*sp, S390_SP_REGNUM)) |
| 1682 | return 0; |
| 1683 | |
| 1684 | /* A frame size of zero at this point can mean either a real |
| 1685 | frameless function, or else a failure to find the prologue. |
| 1686 | Perform some sanity checks to verify we really have a |
| 1687 | frameless function. */ |
| 1688 | if (sp->k == 0) |
| 1689 | { |
| 1690 | /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame |
| 1691 | size zero. This is only possible if the next frame is a sentinel |
| 1692 | frame, a dummy frame, or a signal trampoline frame. */ |
| 1693 | /* FIXME: cagney/2004-05-01: This sanity check shouldn't be |
| 1694 | needed, instead the code should simpliy rely on its |
| 1695 | analysis. */ |
| 1696 | next_frame = get_next_frame (this_frame); |
| 1697 | while (next_frame && get_frame_type (next_frame) == INLINE_FRAME) |
| 1698 | next_frame = get_next_frame (next_frame); |
| 1699 | if (next_frame |
| 1700 | && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME) |
| 1701 | return 0; |
| 1702 | |
| 1703 | /* If we really have a frameless function, %r14 must be valid |
| 1704 | -- in particular, it must point to a different function. */ |
| 1705 | reg = get_frame_register_unsigned (this_frame, S390_RETADDR_REGNUM); |
| 1706 | reg = gdbarch_addr_bits_remove (gdbarch, reg) - 1; |
| 1707 | if (get_pc_function_start (reg) == func) |
| 1708 | { |
| 1709 | /* However, there is one case where it *is* valid for %r14 |
| 1710 | to point to the same function -- if this is a recursive |
| 1711 | call, and we have stopped in the prologue *before* the |
| 1712 | stack frame was allocated. |
| 1713 | |
| 1714 | Recognize this case by looking ahead a bit ... */ |
| 1715 | |
| 1716 | struct s390_prologue_data data2; |
| 1717 | pv_t *sp = &data2.gpr[S390_SP_REGNUM - S390_R0_REGNUM]; |
| 1718 | |
| 1719 | if (!(s390_analyze_prologue (gdbarch, func, (CORE_ADDR)-1, &data2) |
| 1720 | && pv_is_register (*sp, S390_SP_REGNUM) |
| 1721 | && sp->k != 0)) |
| 1722 | return 0; |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | |
| 1727 | /* OK, we've found valid prologue data. */ |
| 1728 | size = -sp->k; |
| 1729 | |
| 1730 | /* If the frame pointer originally also holds the same value |
| 1731 | as the stack pointer, we're probably using it. If it holds |
| 1732 | some other value -- even a constant offset -- it is most |
| 1733 | likely used as temp register. */ |
| 1734 | if (pv_is_identical (*sp, *fp)) |
| 1735 | frame_pointer = S390_FRAME_REGNUM; |
| 1736 | else |
| 1737 | frame_pointer = S390_SP_REGNUM; |
| 1738 | |
| 1739 | /* If we've detected a function with stack frame, we'll still have to |
| 1740 | treat it as frameless if we're currently within the function epilog |
| 1741 | code at a point where the frame pointer has already been restored. |
| 1742 | This can only happen in an innermost frame. */ |
| 1743 | /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed, |
| 1744 | instead the code should simpliy rely on its analysis. */ |
| 1745 | next_frame = get_next_frame (this_frame); |
| 1746 | while (next_frame && get_frame_type (next_frame) == INLINE_FRAME) |
| 1747 | next_frame = get_next_frame (next_frame); |
| 1748 | if (size > 0 |
| 1749 | && (next_frame == NULL |
| 1750 | || get_frame_type (get_next_frame (this_frame)) != NORMAL_FRAME)) |
| 1751 | { |
| 1752 | /* See the comment in s390_in_function_epilogue_p on why this is |
| 1753 | not completely reliable ... */ |
| 1754 | if (s390_in_function_epilogue_p (gdbarch, get_frame_pc (this_frame))) |
| 1755 | { |
| 1756 | memset (&data, 0, sizeof (data)); |
| 1757 | size = 0; |
| 1758 | frame_pointer = S390_SP_REGNUM; |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | /* Once we know the frame register and the frame size, we can unwind |
| 1763 | the current value of the frame register from the next frame, and |
| 1764 | add back the frame size to arrive that the previous frame's |
| 1765 | stack pointer value. */ |
| 1766 | prev_sp = get_frame_register_unsigned (this_frame, frame_pointer) + size; |
| 1767 | cfa = prev_sp + 16*word_size + 32; |
| 1768 | |
| 1769 | /* Set up ABI call-saved/call-clobbered registers. */ |
| 1770 | for (i = 0; i < S390_NUM_REGS; i++) |
| 1771 | if (!s390_register_call_saved (gdbarch, i)) |
| 1772 | trad_frame_set_unknown (info->saved_regs, i); |
| 1773 | |
| 1774 | /* CC is always call-clobbered. */ |
| 1775 | trad_frame_set_unknown (info->saved_regs, S390_PSWM_REGNUM); |
| 1776 | |
| 1777 | /* Record the addresses of all register spill slots the prologue parser |
| 1778 | has recognized. Consider only registers defined as call-saved by the |
| 1779 | ABI; for call-clobbered registers the parser may have recognized |
| 1780 | spurious stores. */ |
| 1781 | |
| 1782 | for (i = 0; i < 16; i++) |
| 1783 | if (s390_register_call_saved (gdbarch, S390_R0_REGNUM + i) |
| 1784 | && data.gpr_slot[i] != 0) |
| 1785 | info->saved_regs[S390_R0_REGNUM + i].addr = cfa - data.gpr_slot[i]; |
| 1786 | |
| 1787 | for (i = 0; i < 16; i++) |
| 1788 | if (s390_register_call_saved (gdbarch, S390_F0_REGNUM + i) |
| 1789 | && data.fpr_slot[i] != 0) |
| 1790 | info->saved_regs[S390_F0_REGNUM + i].addr = cfa - data.fpr_slot[i]; |
| 1791 | |
| 1792 | /* Function return will set PC to %r14. */ |
| 1793 | info->saved_regs[S390_PSWA_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM]; |
| 1794 | |
| 1795 | /* In frameless functions, we unwind simply by moving the return |
| 1796 | address to the PC. However, if we actually stored to the |
| 1797 | save area, use that -- we might only think the function frameless |
| 1798 | because we're in the middle of the prologue ... */ |
| 1799 | if (size == 0 |
| 1800 | && !trad_frame_addr_p (info->saved_regs, S390_PSWA_REGNUM)) |
| 1801 | { |
| 1802 | info->saved_regs[S390_PSWA_REGNUM].realreg = S390_RETADDR_REGNUM; |
| 1803 | } |
| 1804 | |
| 1805 | /* Another sanity check: unless this is a frameless function, |
| 1806 | we should have found spill slots for SP and PC. |
| 1807 | If not, we cannot unwind further -- this happens e.g. in |
| 1808 | libc's thread_start routine. */ |
| 1809 | if (size > 0) |
| 1810 | { |
| 1811 | if (!trad_frame_addr_p (info->saved_regs, S390_SP_REGNUM) |
| 1812 | || !trad_frame_addr_p (info->saved_regs, S390_PSWA_REGNUM)) |
| 1813 | prev_sp = -1; |
| 1814 | } |
| 1815 | |
| 1816 | /* We use the current value of the frame register as local_base, |
| 1817 | and the top of the register save area as frame_base. */ |
| 1818 | if (prev_sp != -1) |
| 1819 | { |
| 1820 | info->frame_base = prev_sp + 16*word_size + 32; |
| 1821 | info->local_base = prev_sp - size; |
| 1822 | } |
| 1823 | |
| 1824 | info->func = func; |
| 1825 | return 1; |
| 1826 | } |
| 1827 | |
| 1828 | static void |
| 1829 | s390_backchain_frame_unwind_cache (struct frame_info *this_frame, |
| 1830 | struct s390_unwind_cache *info) |
| 1831 | { |
| 1832 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1833 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 1834 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 1835 | CORE_ADDR backchain; |
| 1836 | ULONGEST reg; |
| 1837 | LONGEST sp; |
| 1838 | int i; |
| 1839 | |
| 1840 | /* Set up ABI call-saved/call-clobbered registers. */ |
| 1841 | for (i = 0; i < S390_NUM_REGS; i++) |
| 1842 | if (!s390_register_call_saved (gdbarch, i)) |
| 1843 | trad_frame_set_unknown (info->saved_regs, i); |
| 1844 | |
| 1845 | /* CC is always call-clobbered. */ |
| 1846 | trad_frame_set_unknown (info->saved_regs, S390_PSWM_REGNUM); |
| 1847 | |
| 1848 | /* Get the backchain. */ |
| 1849 | reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); |
| 1850 | backchain = read_memory_unsigned_integer (reg, word_size, byte_order); |
| 1851 | |
| 1852 | /* A zero backchain terminates the frame chain. As additional |
| 1853 | sanity check, let's verify that the spill slot for SP in the |
| 1854 | save area pointed to by the backchain in fact links back to |
| 1855 | the save area. */ |
| 1856 | if (backchain != 0 |
| 1857 | && safe_read_memory_integer (backchain + 15*word_size, |
| 1858 | word_size, byte_order, &sp) |
| 1859 | && (CORE_ADDR)sp == backchain) |
| 1860 | { |
| 1861 | /* We don't know which registers were saved, but it will have |
| 1862 | to be at least %r14 and %r15. This will allow us to continue |
| 1863 | unwinding, but other prev-frame registers may be incorrect ... */ |
| 1864 | info->saved_regs[S390_SP_REGNUM].addr = backchain + 15*word_size; |
| 1865 | info->saved_regs[S390_RETADDR_REGNUM].addr = backchain + 14*word_size; |
| 1866 | |
| 1867 | /* Function return will set PC to %r14. */ |
| 1868 | info->saved_regs[S390_PSWA_REGNUM] |
| 1869 | = info->saved_regs[S390_RETADDR_REGNUM]; |
| 1870 | |
| 1871 | /* We use the current value of the frame register as local_base, |
| 1872 | and the top of the register save area as frame_base. */ |
| 1873 | info->frame_base = backchain + 16*word_size + 32; |
| 1874 | info->local_base = reg; |
| 1875 | } |
| 1876 | |
| 1877 | info->func = get_frame_pc (this_frame); |
| 1878 | } |
| 1879 | |
| 1880 | static struct s390_unwind_cache * |
| 1881 | s390_frame_unwind_cache (struct frame_info *this_frame, |
| 1882 | void **this_prologue_cache) |
| 1883 | { |
| 1884 | volatile struct gdb_exception ex; |
| 1885 | struct s390_unwind_cache *info; |
| 1886 | |
| 1887 | if (*this_prologue_cache) |
| 1888 | return *this_prologue_cache; |
| 1889 | |
| 1890 | info = FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache); |
| 1891 | *this_prologue_cache = info; |
| 1892 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
| 1893 | info->func = -1; |
| 1894 | info->frame_base = -1; |
| 1895 | info->local_base = -1; |
| 1896 | |
| 1897 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
| 1898 | { |
| 1899 | /* Try to use prologue analysis to fill the unwind cache. |
| 1900 | If this fails, fall back to reading the stack backchain. */ |
| 1901 | if (!s390_prologue_frame_unwind_cache (this_frame, info)) |
| 1902 | s390_backchain_frame_unwind_cache (this_frame, info); |
| 1903 | } |
| 1904 | if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR) |
| 1905 | throw_exception (ex); |
| 1906 | |
| 1907 | return info; |
| 1908 | } |
| 1909 | |
| 1910 | static void |
| 1911 | s390_frame_this_id (struct frame_info *this_frame, |
| 1912 | void **this_prologue_cache, |
| 1913 | struct frame_id *this_id) |
| 1914 | { |
| 1915 | struct s390_unwind_cache *info |
| 1916 | = s390_frame_unwind_cache (this_frame, this_prologue_cache); |
| 1917 | |
| 1918 | if (info->frame_base == -1) |
| 1919 | return; |
| 1920 | |
| 1921 | *this_id = frame_id_build (info->frame_base, info->func); |
| 1922 | } |
| 1923 | |
| 1924 | static struct value * |
| 1925 | s390_frame_prev_register (struct frame_info *this_frame, |
| 1926 | void **this_prologue_cache, int regnum) |
| 1927 | { |
| 1928 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1929 | struct s390_unwind_cache *info |
| 1930 | = s390_frame_unwind_cache (this_frame, this_prologue_cache); |
| 1931 | |
| 1932 | return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum); |
| 1933 | } |
| 1934 | |
| 1935 | static const struct frame_unwind s390_frame_unwind = { |
| 1936 | NORMAL_FRAME, |
| 1937 | default_frame_unwind_stop_reason, |
| 1938 | s390_frame_this_id, |
| 1939 | s390_frame_prev_register, |
| 1940 | NULL, |
| 1941 | default_frame_sniffer |
| 1942 | }; |
| 1943 | |
| 1944 | |
| 1945 | /* Code stubs and their stack frames. For things like PLTs and NULL |
| 1946 | function calls (where there is no true frame and the return address |
| 1947 | is in the RETADDR register). */ |
| 1948 | |
| 1949 | struct s390_stub_unwind_cache |
| 1950 | { |
| 1951 | CORE_ADDR frame_base; |
| 1952 | struct trad_frame_saved_reg *saved_regs; |
| 1953 | }; |
| 1954 | |
| 1955 | static struct s390_stub_unwind_cache * |
| 1956 | s390_stub_frame_unwind_cache (struct frame_info *this_frame, |
| 1957 | void **this_prologue_cache) |
| 1958 | { |
| 1959 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1960 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 1961 | struct s390_stub_unwind_cache *info; |
| 1962 | ULONGEST reg; |
| 1963 | |
| 1964 | if (*this_prologue_cache) |
| 1965 | return *this_prologue_cache; |
| 1966 | |
| 1967 | info = FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache); |
| 1968 | *this_prologue_cache = info; |
| 1969 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
| 1970 | |
| 1971 | /* The return address is in register %r14. */ |
| 1972 | info->saved_regs[S390_PSWA_REGNUM].realreg = S390_RETADDR_REGNUM; |
| 1973 | |
| 1974 | /* Retrieve stack pointer and determine our frame base. */ |
| 1975 | reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); |
| 1976 | info->frame_base = reg + 16*word_size + 32; |
| 1977 | |
| 1978 | return info; |
| 1979 | } |
| 1980 | |
| 1981 | static void |
| 1982 | s390_stub_frame_this_id (struct frame_info *this_frame, |
| 1983 | void **this_prologue_cache, |
| 1984 | struct frame_id *this_id) |
| 1985 | { |
| 1986 | struct s390_stub_unwind_cache *info |
| 1987 | = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache); |
| 1988 | *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame)); |
| 1989 | } |
| 1990 | |
| 1991 | static struct value * |
| 1992 | s390_stub_frame_prev_register (struct frame_info *this_frame, |
| 1993 | void **this_prologue_cache, int regnum) |
| 1994 | { |
| 1995 | struct s390_stub_unwind_cache *info |
| 1996 | = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache); |
| 1997 | return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum); |
| 1998 | } |
| 1999 | |
| 2000 | static int |
| 2001 | s390_stub_frame_sniffer (const struct frame_unwind *self, |
| 2002 | struct frame_info *this_frame, |
| 2003 | void **this_prologue_cache) |
| 2004 | { |
| 2005 | CORE_ADDR addr_in_block; |
| 2006 | bfd_byte insn[S390_MAX_INSTR_SIZE]; |
| 2007 | |
| 2008 | /* If the current PC points to non-readable memory, we assume we |
| 2009 | have trapped due to an invalid function pointer call. We handle |
| 2010 | the non-existing current function like a PLT stub. */ |
| 2011 | addr_in_block = get_frame_address_in_block (this_frame); |
| 2012 | if (in_plt_section (addr_in_block) |
| 2013 | || s390_readinstruction (insn, get_frame_pc (this_frame)) < 0) |
| 2014 | return 1; |
| 2015 | return 0; |
| 2016 | } |
| 2017 | |
| 2018 | static const struct frame_unwind s390_stub_frame_unwind = { |
| 2019 | NORMAL_FRAME, |
| 2020 | default_frame_unwind_stop_reason, |
| 2021 | s390_stub_frame_this_id, |
| 2022 | s390_stub_frame_prev_register, |
| 2023 | NULL, |
| 2024 | s390_stub_frame_sniffer |
| 2025 | }; |
| 2026 | |
| 2027 | |
| 2028 | /* Signal trampoline stack frames. */ |
| 2029 | |
| 2030 | struct s390_sigtramp_unwind_cache { |
| 2031 | CORE_ADDR frame_base; |
| 2032 | struct trad_frame_saved_reg *saved_regs; |
| 2033 | }; |
| 2034 | |
| 2035 | static struct s390_sigtramp_unwind_cache * |
| 2036 | s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame, |
| 2037 | void **this_prologue_cache) |
| 2038 | { |
| 2039 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 2040 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2041 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 2042 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 2043 | struct s390_sigtramp_unwind_cache *info; |
| 2044 | ULONGEST this_sp, prev_sp; |
| 2045 | CORE_ADDR next_ra, next_cfa, sigreg_ptr, sigreg_high_off; |
| 2046 | int i; |
| 2047 | |
| 2048 | if (*this_prologue_cache) |
| 2049 | return *this_prologue_cache; |
| 2050 | |
| 2051 | info = FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache); |
| 2052 | *this_prologue_cache = info; |
| 2053 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
| 2054 | |
| 2055 | this_sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); |
| 2056 | next_ra = get_frame_pc (this_frame); |
| 2057 | next_cfa = this_sp + 16*word_size + 32; |
| 2058 | |
| 2059 | /* New-style RT frame: |
| 2060 | retcode + alignment (8 bytes) |
| 2061 | siginfo (128 bytes) |
| 2062 | ucontext (contains sigregs at offset 5 words). */ |
| 2063 | if (next_ra == next_cfa) |
| 2064 | { |
| 2065 | sigreg_ptr = next_cfa + 8 + 128 + align_up (5*word_size, 8); |
| 2066 | /* sigregs are followed by uc_sigmask (8 bytes), then by the |
| 2067 | upper GPR halves if present. */ |
| 2068 | sigreg_high_off = 8; |
| 2069 | } |
| 2070 | |
| 2071 | /* Old-style RT frame and all non-RT frames: |
| 2072 | old signal mask (8 bytes) |
| 2073 | pointer to sigregs. */ |
| 2074 | else |
| 2075 | { |
| 2076 | sigreg_ptr = read_memory_unsigned_integer (next_cfa + 8, |
| 2077 | word_size, byte_order); |
| 2078 | /* sigregs are followed by signo (4 bytes), then by the |
| 2079 | upper GPR halves if present. */ |
| 2080 | sigreg_high_off = 4; |
| 2081 | } |
| 2082 | |
| 2083 | /* The sigregs structure looks like this: |
| 2084 | long psw_mask; |
| 2085 | long psw_addr; |
| 2086 | long gprs[16]; |
| 2087 | int acrs[16]; |
| 2088 | int fpc; |
| 2089 | int __pad; |
| 2090 | double fprs[16]; */ |
| 2091 | |
| 2092 | /* PSW mask and address. */ |
| 2093 | info->saved_regs[S390_PSWM_REGNUM].addr = sigreg_ptr; |
| 2094 | sigreg_ptr += word_size; |
| 2095 | info->saved_regs[S390_PSWA_REGNUM].addr = sigreg_ptr; |
| 2096 | sigreg_ptr += word_size; |
| 2097 | |
| 2098 | /* Then the GPRs. */ |
| 2099 | for (i = 0; i < 16; i++) |
| 2100 | { |
| 2101 | info->saved_regs[S390_R0_REGNUM + i].addr = sigreg_ptr; |
| 2102 | sigreg_ptr += word_size; |
| 2103 | } |
| 2104 | |
| 2105 | /* Then the ACRs. */ |
| 2106 | for (i = 0; i < 16; i++) |
| 2107 | { |
| 2108 | info->saved_regs[S390_A0_REGNUM + i].addr = sigreg_ptr; |
| 2109 | sigreg_ptr += 4; |
| 2110 | } |
| 2111 | |
| 2112 | /* The floating-point control word. */ |
| 2113 | info->saved_regs[S390_FPC_REGNUM].addr = sigreg_ptr; |
| 2114 | sigreg_ptr += 8; |
| 2115 | |
| 2116 | /* And finally the FPRs. */ |
| 2117 | for (i = 0; i < 16; i++) |
| 2118 | { |
| 2119 | info->saved_regs[S390_F0_REGNUM + i].addr = sigreg_ptr; |
| 2120 | sigreg_ptr += 8; |
| 2121 | } |
| 2122 | |
| 2123 | /* If we have them, the GPR upper halves are appended at the end. */ |
| 2124 | sigreg_ptr += sigreg_high_off; |
| 2125 | if (tdep->gpr_full_regnum != -1) |
| 2126 | for (i = 0; i < 16; i++) |
| 2127 | { |
| 2128 | info->saved_regs[S390_R0_UPPER_REGNUM + i].addr = sigreg_ptr; |
| 2129 | sigreg_ptr += 4; |
| 2130 | } |
| 2131 | |
| 2132 | /* Restore the previous frame's SP. */ |
| 2133 | prev_sp = read_memory_unsigned_integer ( |
| 2134 | info->saved_regs[S390_SP_REGNUM].addr, |
| 2135 | word_size, byte_order); |
| 2136 | |
| 2137 | /* Determine our frame base. */ |
| 2138 | info->frame_base = prev_sp + 16*word_size + 32; |
| 2139 | |
| 2140 | return info; |
| 2141 | } |
| 2142 | |
| 2143 | static void |
| 2144 | s390_sigtramp_frame_this_id (struct frame_info *this_frame, |
| 2145 | void **this_prologue_cache, |
| 2146 | struct frame_id *this_id) |
| 2147 | { |
| 2148 | struct s390_sigtramp_unwind_cache *info |
| 2149 | = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
| 2150 | *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame)); |
| 2151 | } |
| 2152 | |
| 2153 | static struct value * |
| 2154 | s390_sigtramp_frame_prev_register (struct frame_info *this_frame, |
| 2155 | void **this_prologue_cache, int regnum) |
| 2156 | { |
| 2157 | struct s390_sigtramp_unwind_cache *info |
| 2158 | = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
| 2159 | return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum); |
| 2160 | } |
| 2161 | |
| 2162 | static int |
| 2163 | s390_sigtramp_frame_sniffer (const struct frame_unwind *self, |
| 2164 | struct frame_info *this_frame, |
| 2165 | void **this_prologue_cache) |
| 2166 | { |
| 2167 | CORE_ADDR pc = get_frame_pc (this_frame); |
| 2168 | bfd_byte sigreturn[2]; |
| 2169 | |
| 2170 | if (target_read_memory (pc, sigreturn, 2)) |
| 2171 | return 0; |
| 2172 | |
| 2173 | if (sigreturn[0] != op_svc) |
| 2174 | return 0; |
| 2175 | |
| 2176 | if (sigreturn[1] != 119 /* sigreturn */ |
| 2177 | && sigreturn[1] != 173 /* rt_sigreturn */) |
| 2178 | return 0; |
| 2179 | |
| 2180 | return 1; |
| 2181 | } |
| 2182 | |
| 2183 | static const struct frame_unwind s390_sigtramp_frame_unwind = { |
| 2184 | SIGTRAMP_FRAME, |
| 2185 | default_frame_unwind_stop_reason, |
| 2186 | s390_sigtramp_frame_this_id, |
| 2187 | s390_sigtramp_frame_prev_register, |
| 2188 | NULL, |
| 2189 | s390_sigtramp_frame_sniffer |
| 2190 | }; |
| 2191 | |
| 2192 | /* Retrieve the syscall number at a ptrace syscall-stop. Return -1 |
| 2193 | upon error. */ |
| 2194 | |
| 2195 | static LONGEST |
| 2196 | s390_linux_get_syscall_number (struct gdbarch *gdbarch, |
| 2197 | ptid_t ptid) |
| 2198 | { |
| 2199 | struct regcache *regs = get_thread_regcache (ptid); |
| 2200 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2201 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 2202 | ULONGEST pc; |
| 2203 | ULONGEST svc_number = -1; |
| 2204 | unsigned opcode; |
| 2205 | |
| 2206 | /* Assume that the PC points after the 2-byte SVC instruction. We |
| 2207 | don't currently support SVC via EXECUTE. */ |
| 2208 | regcache_cooked_read_unsigned (regs, tdep->pc_regnum, &pc); |
| 2209 | pc -= 2; |
| 2210 | opcode = read_memory_unsigned_integer ((CORE_ADDR) pc, 1, byte_order); |
| 2211 | if (opcode != op_svc) |
| 2212 | return -1; |
| 2213 | |
| 2214 | svc_number = read_memory_unsigned_integer ((CORE_ADDR) pc + 1, 1, |
| 2215 | byte_order); |
| 2216 | if (svc_number == 0) |
| 2217 | regcache_cooked_read_unsigned (regs, S390_R1_REGNUM, &svc_number); |
| 2218 | |
| 2219 | return svc_number; |
| 2220 | } |
| 2221 | |
| 2222 | |
| 2223 | /* Frame base handling. */ |
| 2224 | |
| 2225 | static CORE_ADDR |
| 2226 | s390_frame_base_address (struct frame_info *this_frame, void **this_cache) |
| 2227 | { |
| 2228 | struct s390_unwind_cache *info |
| 2229 | = s390_frame_unwind_cache (this_frame, this_cache); |
| 2230 | return info->frame_base; |
| 2231 | } |
| 2232 | |
| 2233 | static CORE_ADDR |
| 2234 | s390_local_base_address (struct frame_info *this_frame, void **this_cache) |
| 2235 | { |
| 2236 | struct s390_unwind_cache *info |
| 2237 | = s390_frame_unwind_cache (this_frame, this_cache); |
| 2238 | return info->local_base; |
| 2239 | } |
| 2240 | |
| 2241 | static const struct frame_base s390_frame_base = { |
| 2242 | &s390_frame_unwind, |
| 2243 | s390_frame_base_address, |
| 2244 | s390_local_base_address, |
| 2245 | s390_local_base_address |
| 2246 | }; |
| 2247 | |
| 2248 | static CORE_ADDR |
| 2249 | s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 2250 | { |
| 2251 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2252 | ULONGEST pc; |
| 2253 | pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum); |
| 2254 | return gdbarch_addr_bits_remove (gdbarch, pc); |
| 2255 | } |
| 2256 | |
| 2257 | static CORE_ADDR |
| 2258 | s390_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 2259 | { |
| 2260 | ULONGEST sp; |
| 2261 | sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM); |
| 2262 | return gdbarch_addr_bits_remove (gdbarch, sp); |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | /* DWARF-2 frame support. */ |
| 2267 | |
| 2268 | static struct value * |
| 2269 | s390_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache, |
| 2270 | int regnum) |
| 2271 | { |
| 2272 | return s390_unwind_pseudo_register (this_frame, regnum); |
| 2273 | } |
| 2274 | |
| 2275 | static void |
| 2276 | s390_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, |
| 2277 | struct dwarf2_frame_state_reg *reg, |
| 2278 | struct frame_info *this_frame) |
| 2279 | { |
| 2280 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2281 | |
| 2282 | /* The condition code (and thus PSW mask) is call-clobbered. */ |
| 2283 | if (regnum == S390_PSWM_REGNUM) |
| 2284 | reg->how = DWARF2_FRAME_REG_UNDEFINED; |
| 2285 | |
| 2286 | /* The PSW address unwinds to the return address. */ |
| 2287 | else if (regnum == S390_PSWA_REGNUM) |
| 2288 | reg->how = DWARF2_FRAME_REG_RA; |
| 2289 | |
| 2290 | /* Fixed registers are call-saved or call-clobbered |
| 2291 | depending on the ABI in use. */ |
| 2292 | else if (regnum < S390_NUM_REGS) |
| 2293 | { |
| 2294 | if (s390_register_call_saved (gdbarch, regnum)) |
| 2295 | reg->how = DWARF2_FRAME_REG_SAME_VALUE; |
| 2296 | else |
| 2297 | reg->how = DWARF2_FRAME_REG_UNDEFINED; |
| 2298 | } |
| 2299 | |
| 2300 | /* We install a special function to unwind pseudos. */ |
| 2301 | else |
| 2302 | { |
| 2303 | reg->how = DWARF2_FRAME_REG_FN; |
| 2304 | reg->loc.fn = s390_dwarf2_prev_register; |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | |
| 2309 | /* Dummy function calls. */ |
| 2310 | |
| 2311 | /* Return non-zero if TYPE is an integer-like type, zero otherwise. |
| 2312 | "Integer-like" types are those that should be passed the way |
| 2313 | integers are: integers, enums, ranges, characters, and booleans. */ |
| 2314 | static int |
| 2315 | is_integer_like (struct type *type) |
| 2316 | { |
| 2317 | enum type_code code = TYPE_CODE (type); |
| 2318 | |
| 2319 | return (code == TYPE_CODE_INT |
| 2320 | || code == TYPE_CODE_ENUM |
| 2321 | || code == TYPE_CODE_RANGE |
| 2322 | || code == TYPE_CODE_CHAR |
| 2323 | || code == TYPE_CODE_BOOL); |
| 2324 | } |
| 2325 | |
| 2326 | /* Return non-zero if TYPE is a pointer-like type, zero otherwise. |
| 2327 | "Pointer-like" types are those that should be passed the way |
| 2328 | pointers are: pointers and references. */ |
| 2329 | static int |
| 2330 | is_pointer_like (struct type *type) |
| 2331 | { |
| 2332 | enum type_code code = TYPE_CODE (type); |
| 2333 | |
| 2334 | return (code == TYPE_CODE_PTR |
| 2335 | || code == TYPE_CODE_REF); |
| 2336 | } |
| 2337 | |
| 2338 | |
| 2339 | /* Return non-zero if TYPE is a `float singleton' or `double |
| 2340 | singleton', zero otherwise. |
| 2341 | |
| 2342 | A `T singleton' is a struct type with one member, whose type is |
| 2343 | either T or a `T singleton'. So, the following are all float |
| 2344 | singletons: |
| 2345 | |
| 2346 | struct { float x }; |
| 2347 | struct { struct { float x; } x; }; |
| 2348 | struct { struct { struct { float x; } x; } x; }; |
| 2349 | |
| 2350 | ... and so on. |
| 2351 | |
| 2352 | All such structures are passed as if they were floats or doubles, |
| 2353 | as the (revised) ABI says. */ |
| 2354 | static int |
| 2355 | is_float_singleton (struct type *type) |
| 2356 | { |
| 2357 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1) |
| 2358 | { |
| 2359 | struct type *singleton_type = TYPE_FIELD_TYPE (type, 0); |
| 2360 | CHECK_TYPEDEF (singleton_type); |
| 2361 | |
| 2362 | return (TYPE_CODE (singleton_type) == TYPE_CODE_FLT |
| 2363 | || TYPE_CODE (singleton_type) == TYPE_CODE_DECFLOAT |
| 2364 | || is_float_singleton (singleton_type)); |
| 2365 | } |
| 2366 | |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
| 2370 | |
| 2371 | /* Return non-zero if TYPE is a struct-like type, zero otherwise. |
| 2372 | "Struct-like" types are those that should be passed as structs are: |
| 2373 | structs and unions. |
| 2374 | |
| 2375 | As an odd quirk, not mentioned in the ABI, GCC passes float and |
| 2376 | double singletons as if they were a plain float, double, etc. (The |
| 2377 | corresponding union types are handled normally.) So we exclude |
| 2378 | those types here. *shrug* */ |
| 2379 | static int |
| 2380 | is_struct_like (struct type *type) |
| 2381 | { |
| 2382 | enum type_code code = TYPE_CODE (type); |
| 2383 | |
| 2384 | return (code == TYPE_CODE_UNION |
| 2385 | || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type))); |
| 2386 | } |
| 2387 | |
| 2388 | |
| 2389 | /* Return non-zero if TYPE is a float-like type, zero otherwise. |
| 2390 | "Float-like" types are those that should be passed as |
| 2391 | floating-point values are. |
| 2392 | |
| 2393 | You'd think this would just be floats, doubles, long doubles, etc. |
| 2394 | But as an odd quirk, not mentioned in the ABI, GCC passes float and |
| 2395 | double singletons as if they were a plain float, double, etc. (The |
| 2396 | corresponding union types are handled normally.) So we include |
| 2397 | those types here. *shrug* */ |
| 2398 | static int |
| 2399 | is_float_like (struct type *type) |
| 2400 | { |
| 2401 | return (TYPE_CODE (type) == TYPE_CODE_FLT |
| 2402 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT |
| 2403 | || is_float_singleton (type)); |
| 2404 | } |
| 2405 | |
| 2406 | |
| 2407 | static int |
| 2408 | is_power_of_two (unsigned int n) |
| 2409 | { |
| 2410 | return ((n & (n - 1)) == 0); |
| 2411 | } |
| 2412 | |
| 2413 | /* Return non-zero if TYPE should be passed as a pointer to a copy, |
| 2414 | zero otherwise. */ |
| 2415 | static int |
| 2416 | s390_function_arg_pass_by_reference (struct type *type) |
| 2417 | { |
| 2418 | if (TYPE_LENGTH (type) > 8) |
| 2419 | return 1; |
| 2420 | |
| 2421 | return (is_struct_like (type) && !is_power_of_two (TYPE_LENGTH (type))) |
| 2422 | || TYPE_CODE (type) == TYPE_CODE_COMPLEX |
| 2423 | || (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type)); |
| 2424 | } |
| 2425 | |
| 2426 | /* Return non-zero if TYPE should be passed in a float register |
| 2427 | if possible. */ |
| 2428 | static int |
| 2429 | s390_function_arg_float (struct type *type) |
| 2430 | { |
| 2431 | if (TYPE_LENGTH (type) > 8) |
| 2432 | return 0; |
| 2433 | |
| 2434 | return is_float_like (type); |
| 2435 | } |
| 2436 | |
| 2437 | /* Return non-zero if TYPE should be passed in an integer register |
| 2438 | (or a pair of integer registers) if possible. */ |
| 2439 | static int |
| 2440 | s390_function_arg_integer (struct type *type) |
| 2441 | { |
| 2442 | if (TYPE_LENGTH (type) > 8) |
| 2443 | return 0; |
| 2444 | |
| 2445 | return is_integer_like (type) |
| 2446 | || is_pointer_like (type) |
| 2447 | || (is_struct_like (type) && is_power_of_two (TYPE_LENGTH (type))); |
| 2448 | } |
| 2449 | |
| 2450 | /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full |
| 2451 | word as required for the ABI. */ |
| 2452 | static LONGEST |
| 2453 | extend_simple_arg (struct gdbarch *gdbarch, struct value *arg) |
| 2454 | { |
| 2455 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 2456 | struct type *type = check_typedef (value_type (arg)); |
| 2457 | |
| 2458 | /* Even structs get passed in the least significant bits of the |
| 2459 | register / memory word. It's not really right to extract them as |
| 2460 | an integer, but it does take care of the extension. */ |
| 2461 | if (TYPE_UNSIGNED (type)) |
| 2462 | return extract_unsigned_integer (value_contents (arg), |
| 2463 | TYPE_LENGTH (type), byte_order); |
| 2464 | else |
| 2465 | return extract_signed_integer (value_contents (arg), |
| 2466 | TYPE_LENGTH (type), byte_order); |
| 2467 | } |
| 2468 | |
| 2469 | |
| 2470 | /* Return the alignment required by TYPE. */ |
| 2471 | static int |
| 2472 | alignment_of (struct type *type) |
| 2473 | { |
| 2474 | int alignment; |
| 2475 | |
| 2476 | if (is_integer_like (type) |
| 2477 | || is_pointer_like (type) |
| 2478 | || TYPE_CODE (type) == TYPE_CODE_FLT |
| 2479 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) |
| 2480 | alignment = TYPE_LENGTH (type); |
| 2481 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 2482 | || TYPE_CODE (type) == TYPE_CODE_UNION) |
| 2483 | { |
| 2484 | int i; |
| 2485 | |
| 2486 | alignment = 1; |
| 2487 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
| 2488 | { |
| 2489 | int field_alignment |
| 2490 | = alignment_of (check_typedef (TYPE_FIELD_TYPE (type, i))); |
| 2491 | |
| 2492 | if (field_alignment > alignment) |
| 2493 | alignment = field_alignment; |
| 2494 | } |
| 2495 | } |
| 2496 | else |
| 2497 | alignment = 1; |
| 2498 | |
| 2499 | /* Check that everything we ever return is a power of two. Lots of |
| 2500 | code doesn't want to deal with aligning things to arbitrary |
| 2501 | boundaries. */ |
| 2502 | gdb_assert ((alignment & (alignment - 1)) == 0); |
| 2503 | |
| 2504 | return alignment; |
| 2505 | } |
| 2506 | |
| 2507 | |
| 2508 | /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in |
| 2509 | place to be passed to a function, as specified by the "GNU/Linux |
| 2510 | for S/390 ELF Application Binary Interface Supplement". |
| 2511 | |
| 2512 | SP is the current stack pointer. We must put arguments, links, |
| 2513 | padding, etc. whereever they belong, and return the new stack |
| 2514 | pointer value. |
| 2515 | |
| 2516 | If STRUCT_RETURN is non-zero, then the function we're calling is |
| 2517 | going to return a structure by value; STRUCT_ADDR is the address of |
| 2518 | a block we've allocated for it on the stack. |
| 2519 | |
| 2520 | Our caller has taken care of any type promotions needed to satisfy |
| 2521 | prototypes or the old K&R argument-passing rules. */ |
| 2522 | static CORE_ADDR |
| 2523 | s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 2524 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 2525 | int nargs, struct value **args, CORE_ADDR sp, |
| 2526 | int struct_return, CORE_ADDR struct_addr) |
| 2527 | { |
| 2528 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
| 2529 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 2530 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 2531 | int i; |
| 2532 | |
| 2533 | /* If the i'th argument is passed as a reference to a copy, then |
| 2534 | copy_addr[i] is the address of the copy we made. */ |
| 2535 | CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR)); |
| 2536 | |
| 2537 | /* Reserve space for the reference-to-copy area. */ |
| 2538 | for (i = 0; i < nargs; i++) |
| 2539 | { |
| 2540 | struct value *arg = args[i]; |
| 2541 | struct type *type = check_typedef (value_type (arg)); |
| 2542 | |
| 2543 | if (s390_function_arg_pass_by_reference (type)) |
| 2544 | { |
| 2545 | sp -= TYPE_LENGTH (type); |
| 2546 | sp = align_down (sp, alignment_of (type)); |
| 2547 | copy_addr[i] = sp; |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | /* Reserve space for the parameter area. As a conservative |
| 2552 | simplification, we assume that everything will be passed on the |
| 2553 | stack. Since every argument larger than 8 bytes will be |
| 2554 | passed by reference, we use this simple upper bound. */ |
| 2555 | sp -= nargs * 8; |
| 2556 | |
| 2557 | /* After all that, make sure it's still aligned on an eight-byte |
| 2558 | boundary. */ |
| 2559 | sp = align_down (sp, 8); |
| 2560 | |
| 2561 | /* Allocate the standard frame areas: the register save area, the |
| 2562 | word reserved for the compiler (which seems kind of meaningless), |
| 2563 | and the back chain pointer. */ |
| 2564 | sp -= 16*word_size + 32; |
| 2565 | |
| 2566 | /* Now we have the final SP value. Make sure we didn't underflow; |
| 2567 | on 31-bit, this would result in addresses with the high bit set, |
| 2568 | which causes confusion elsewhere. Note that if we error out |
| 2569 | here, stack and registers remain untouched. */ |
| 2570 | if (gdbarch_addr_bits_remove (gdbarch, sp) != sp) |
| 2571 | error (_("Stack overflow")); |
| 2572 | |
| 2573 | |
| 2574 | /* Finally, place the actual parameters, working from SP towards |
| 2575 | higher addresses. The code above is supposed to reserve enough |
| 2576 | space for this. */ |
| 2577 | { |
| 2578 | int fr = 0; |
| 2579 | int gr = 2; |
| 2580 | CORE_ADDR starg = sp + 16*word_size + 32; |
| 2581 | |
| 2582 | /* A struct is returned using general register 2. */ |
| 2583 | if (struct_return) |
| 2584 | { |
| 2585 | regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr, |
| 2586 | struct_addr); |
| 2587 | gr++; |
| 2588 | } |
| 2589 | |
| 2590 | for (i = 0; i < nargs; i++) |
| 2591 | { |
| 2592 | struct value *arg = args[i]; |
| 2593 | struct type *type = check_typedef (value_type (arg)); |
| 2594 | unsigned length = TYPE_LENGTH (type); |
| 2595 | |
| 2596 | if (s390_function_arg_pass_by_reference (type)) |
| 2597 | { |
| 2598 | /* Actually copy the argument contents to the stack slot |
| 2599 | that was reserved above. */ |
| 2600 | write_memory (copy_addr[i], value_contents (arg), length); |
| 2601 | |
| 2602 | if (gr <= 6) |
| 2603 | { |
| 2604 | regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr, |
| 2605 | copy_addr[i]); |
| 2606 | gr++; |
| 2607 | } |
| 2608 | else |
| 2609 | { |
| 2610 | write_memory_unsigned_integer (starg, word_size, byte_order, |
| 2611 | copy_addr[i]); |
| 2612 | starg += word_size; |
| 2613 | } |
| 2614 | } |
| 2615 | else if (s390_function_arg_float (type)) |
| 2616 | { |
| 2617 | /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments, |
| 2618 | the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */ |
| 2619 | if (fr <= (tdep->abi == ABI_LINUX_S390 ? 2 : 6)) |
| 2620 | { |
| 2621 | /* When we store a single-precision value in an FP register, |
| 2622 | it occupies the leftmost bits. */ |
| 2623 | regcache_cooked_write_part (regcache, S390_F0_REGNUM + fr, |
| 2624 | 0, length, value_contents (arg)); |
| 2625 | fr += 2; |
| 2626 | } |
| 2627 | else |
| 2628 | { |
| 2629 | /* When we store a single-precision value in a stack slot, |
| 2630 | it occupies the rightmost bits. */ |
| 2631 | starg = align_up (starg + length, word_size); |
| 2632 | write_memory (starg - length, value_contents (arg), length); |
| 2633 | } |
| 2634 | } |
| 2635 | else if (s390_function_arg_integer (type) && length <= word_size) |
| 2636 | { |
| 2637 | if (gr <= 6) |
| 2638 | { |
| 2639 | /* Integer arguments are always extended to word size. */ |
| 2640 | regcache_cooked_write_signed (regcache, S390_R0_REGNUM + gr, |
| 2641 | extend_simple_arg (gdbarch, |
| 2642 | arg)); |
| 2643 | gr++; |
| 2644 | } |
| 2645 | else |
| 2646 | { |
| 2647 | /* Integer arguments are always extended to word size. */ |
| 2648 | write_memory_signed_integer (starg, word_size, byte_order, |
| 2649 | extend_simple_arg (gdbarch, arg)); |
| 2650 | starg += word_size; |
| 2651 | } |
| 2652 | } |
| 2653 | else if (s390_function_arg_integer (type) && length == 2*word_size) |
| 2654 | { |
| 2655 | if (gr <= 5) |
| 2656 | { |
| 2657 | regcache_cooked_write (regcache, S390_R0_REGNUM + gr, |
| 2658 | value_contents (arg)); |
| 2659 | regcache_cooked_write (regcache, S390_R0_REGNUM + gr + 1, |
| 2660 | value_contents (arg) + word_size); |
| 2661 | gr += 2; |
| 2662 | } |
| 2663 | else |
| 2664 | { |
| 2665 | /* If we skipped r6 because we couldn't fit a DOUBLE_ARG |
| 2666 | in it, then don't go back and use it again later. */ |
| 2667 | gr = 7; |
| 2668 | |
| 2669 | write_memory (starg, value_contents (arg), length); |
| 2670 | starg += length; |
| 2671 | } |
| 2672 | } |
| 2673 | else |
| 2674 | internal_error (__FILE__, __LINE__, _("unknown argument type")); |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /* Store return PSWA. In 31-bit mode, keep addressing mode bit. */ |
| 2679 | if (word_size == 4) |
| 2680 | { |
| 2681 | ULONGEST pswa; |
| 2682 | regcache_cooked_read_unsigned (regcache, S390_PSWA_REGNUM, &pswa); |
| 2683 | bp_addr = (bp_addr & 0x7fffffff) | (pswa & 0x80000000); |
| 2684 | } |
| 2685 | regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr); |
| 2686 | |
| 2687 | /* Store updated stack pointer. */ |
| 2688 | regcache_cooked_write_unsigned (regcache, S390_SP_REGNUM, sp); |
| 2689 | |
| 2690 | /* We need to return the 'stack part' of the frame ID, |
| 2691 | which is actually the top of the register save area. */ |
| 2692 | return sp + 16*word_size + 32; |
| 2693 | } |
| 2694 | |
| 2695 | /* Assuming THIS_FRAME is a dummy, return the frame ID of that |
| 2696 | dummy frame. The frame ID's base needs to match the TOS value |
| 2697 | returned by push_dummy_call, and the PC match the dummy frame's |
| 2698 | breakpoint. */ |
| 2699 | static struct frame_id |
| 2700 | s390_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) |
| 2701 | { |
| 2702 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 2703 | CORE_ADDR sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); |
| 2704 | sp = gdbarch_addr_bits_remove (gdbarch, sp); |
| 2705 | |
| 2706 | return frame_id_build (sp + 16*word_size + 32, |
| 2707 | get_frame_pc (this_frame)); |
| 2708 | } |
| 2709 | |
| 2710 | static CORE_ADDR |
| 2711 | s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) |
| 2712 | { |
| 2713 | /* Both the 32- and 64-bit ABI's say that the stack pointer should |
| 2714 | always be aligned on an eight-byte boundary. */ |
| 2715 | return (addr & -8); |
| 2716 | } |
| 2717 | |
| 2718 | |
| 2719 | /* Function return value access. */ |
| 2720 | |
| 2721 | static enum return_value_convention |
| 2722 | s390_return_value_convention (struct gdbarch *gdbarch, struct type *type) |
| 2723 | { |
| 2724 | if (TYPE_LENGTH (type) > 8) |
| 2725 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 2726 | |
| 2727 | switch (TYPE_CODE (type)) |
| 2728 | { |
| 2729 | case TYPE_CODE_STRUCT: |
| 2730 | case TYPE_CODE_UNION: |
| 2731 | case TYPE_CODE_ARRAY: |
| 2732 | case TYPE_CODE_COMPLEX: |
| 2733 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 2734 | |
| 2735 | default: |
| 2736 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | static enum return_value_convention |
| 2741 | s390_return_value (struct gdbarch *gdbarch, struct value *function, |
| 2742 | struct type *type, struct regcache *regcache, |
| 2743 | gdb_byte *out, const gdb_byte *in) |
| 2744 | { |
| 2745 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
| 2746 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
| 2747 | enum return_value_convention rvc; |
| 2748 | int length; |
| 2749 | |
| 2750 | type = check_typedef (type); |
| 2751 | rvc = s390_return_value_convention (gdbarch, type); |
| 2752 | length = TYPE_LENGTH (type); |
| 2753 | |
| 2754 | if (in) |
| 2755 | { |
| 2756 | switch (rvc) |
| 2757 | { |
| 2758 | case RETURN_VALUE_REGISTER_CONVENTION: |
| 2759 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 2760 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) |
| 2761 | { |
| 2762 | /* When we store a single-precision value in an FP register, |
| 2763 | it occupies the leftmost bits. */ |
| 2764 | regcache_cooked_write_part (regcache, S390_F0_REGNUM, |
| 2765 | 0, length, in); |
| 2766 | } |
| 2767 | else if (length <= word_size) |
| 2768 | { |
| 2769 | /* Integer arguments are always extended to word size. */ |
| 2770 | if (TYPE_UNSIGNED (type)) |
| 2771 | regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM, |
| 2772 | extract_unsigned_integer (in, length, byte_order)); |
| 2773 | else |
| 2774 | regcache_cooked_write_signed (regcache, S390_R2_REGNUM, |
| 2775 | extract_signed_integer (in, length, byte_order)); |
| 2776 | } |
| 2777 | else if (length == 2*word_size) |
| 2778 | { |
| 2779 | regcache_cooked_write (regcache, S390_R2_REGNUM, in); |
| 2780 | regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size); |
| 2781 | } |
| 2782 | else |
| 2783 | internal_error (__FILE__, __LINE__, _("invalid return type")); |
| 2784 | break; |
| 2785 | |
| 2786 | case RETURN_VALUE_STRUCT_CONVENTION: |
| 2787 | error (_("Cannot set function return value.")); |
| 2788 | break; |
| 2789 | } |
| 2790 | } |
| 2791 | else if (out) |
| 2792 | { |
| 2793 | switch (rvc) |
| 2794 | { |
| 2795 | case RETURN_VALUE_REGISTER_CONVENTION: |
| 2796 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
| 2797 | || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) |
| 2798 | { |
| 2799 | /* When we store a single-precision value in an FP register, |
| 2800 | it occupies the leftmost bits. */ |
| 2801 | regcache_cooked_read_part (regcache, S390_F0_REGNUM, |
| 2802 | 0, length, out); |
| 2803 | } |
| 2804 | else if (length <= word_size) |
| 2805 | { |
| 2806 | /* Integer arguments occupy the rightmost bits. */ |
| 2807 | regcache_cooked_read_part (regcache, S390_R2_REGNUM, |
| 2808 | word_size - length, length, out); |
| 2809 | } |
| 2810 | else if (length == 2*word_size) |
| 2811 | { |
| 2812 | regcache_cooked_read (regcache, S390_R2_REGNUM, out); |
| 2813 | regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size); |
| 2814 | } |
| 2815 | else |
| 2816 | internal_error (__FILE__, __LINE__, _("invalid return type")); |
| 2817 | break; |
| 2818 | |
| 2819 | case RETURN_VALUE_STRUCT_CONVENTION: |
| 2820 | error (_("Function return value unknown.")); |
| 2821 | break; |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | return rvc; |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | /* Breakpoints. */ |
| 2830 | |
| 2831 | static const gdb_byte * |
| 2832 | s390_breakpoint_from_pc (struct gdbarch *gdbarch, |
| 2833 | CORE_ADDR *pcptr, int *lenptr) |
| 2834 | { |
| 2835 | static const gdb_byte breakpoint[] = { 0x0, 0x1 }; |
| 2836 | |
| 2837 | *lenptr = sizeof (breakpoint); |
| 2838 | return breakpoint; |
| 2839 | } |
| 2840 | |
| 2841 | |
| 2842 | /* Address handling. */ |
| 2843 | |
| 2844 | static CORE_ADDR |
| 2845 | s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) |
| 2846 | { |
| 2847 | return addr & 0x7fffffff; |
| 2848 | } |
| 2849 | |
| 2850 | static int |
| 2851 | s390_address_class_type_flags (int byte_size, int dwarf2_addr_class) |
| 2852 | { |
| 2853 | if (byte_size == 4) |
| 2854 | return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; |
| 2855 | else |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | static const char * |
| 2860 | s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags) |
| 2861 | { |
| 2862 | if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1) |
| 2863 | return "mode32"; |
| 2864 | else |
| 2865 | return NULL; |
| 2866 | } |
| 2867 | |
| 2868 | static int |
| 2869 | s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, |
| 2870 | const char *name, |
| 2871 | int *type_flags_ptr) |
| 2872 | { |
| 2873 | if (strcmp (name, "mode32") == 0) |
| 2874 | { |
| 2875 | *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1; |
| 2876 | return 1; |
| 2877 | } |
| 2878 | else |
| 2879 | return 0; |
| 2880 | } |
| 2881 | |
| 2882 | /* Implementation of `gdbarch_stap_is_single_operand', as defined in |
| 2883 | gdbarch.h. */ |
| 2884 | |
| 2885 | static int |
| 2886 | s390_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) |
| 2887 | { |
| 2888 | return ((isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement |
| 2889 | or indirection. */ |
| 2890 | || *s == '%' /* Register access. */ |
| 2891 | || isdigit (*s)); /* Literal number. */ |
| 2892 | } |
| 2893 | |
| 2894 | /* Set up gdbarch struct. */ |
| 2895 | |
| 2896 | static struct gdbarch * |
| 2897 | s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
| 2898 | { |
| 2899 | const struct target_desc *tdesc = info.target_desc; |
| 2900 | struct tdesc_arch_data *tdesc_data = NULL; |
| 2901 | struct gdbarch *gdbarch; |
| 2902 | struct gdbarch_tdep *tdep; |
| 2903 | int tdep_abi; |
| 2904 | int have_upper = 0; |
| 2905 | int have_linux_v1 = 0; |
| 2906 | int have_linux_v2 = 0; |
| 2907 | int first_pseudo_reg, last_pseudo_reg; |
| 2908 | static const char *const stap_register_prefixes[] = { "%", NULL }; |
| 2909 | static const char *const stap_register_indirection_prefixes[] = { "(", |
| 2910 | NULL }; |
| 2911 | static const char *const stap_register_indirection_suffixes[] = { ")", |
| 2912 | NULL }; |
| 2913 | |
| 2914 | /* Default ABI and register size. */ |
| 2915 | switch (info.bfd_arch_info->mach) |
| 2916 | { |
| 2917 | case bfd_mach_s390_31: |
| 2918 | tdep_abi = ABI_LINUX_S390; |
| 2919 | break; |
| 2920 | |
| 2921 | case bfd_mach_s390_64: |
| 2922 | tdep_abi = ABI_LINUX_ZSERIES; |
| 2923 | break; |
| 2924 | |
| 2925 | default: |
| 2926 | return NULL; |
| 2927 | } |
| 2928 | |
| 2929 | /* Use default target description if none provided by the target. */ |
| 2930 | if (!tdesc_has_registers (tdesc)) |
| 2931 | { |
| 2932 | if (tdep_abi == ABI_LINUX_S390) |
| 2933 | tdesc = tdesc_s390_linux32; |
| 2934 | else |
| 2935 | tdesc = tdesc_s390x_linux64; |
| 2936 | } |
| 2937 | |
| 2938 | /* Check any target description for validity. */ |
| 2939 | if (tdesc_has_registers (tdesc)) |
| 2940 | { |
| 2941 | static const char *const gprs[] = { |
| 2942 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 2943 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 2944 | }; |
| 2945 | static const char *const fprs[] = { |
| 2946 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 2947 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15" |
| 2948 | }; |
| 2949 | static const char *const acrs[] = { |
| 2950 | "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7", |
| 2951 | "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15" |
| 2952 | }; |
| 2953 | static const char *const gprs_lower[] = { |
| 2954 | "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l", |
| 2955 | "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l" |
| 2956 | }; |
| 2957 | static const char *const gprs_upper[] = { |
| 2958 | "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h", |
| 2959 | "r8h", "r9h", "r10h", "r11h", "r12h", "r13h", "r14h", "r15h" |
| 2960 | }; |
| 2961 | static const char *const tdb_regs[] = { |
| 2962 | "tdb0", "tac", "tct", "atia", |
| 2963 | "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7", |
| 2964 | "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15" |
| 2965 | }; |
| 2966 | const struct tdesc_feature *feature; |
| 2967 | int i, valid_p = 1; |
| 2968 | |
| 2969 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.core"); |
| 2970 | if (feature == NULL) |
| 2971 | return NULL; |
| 2972 | |
| 2973 | tdesc_data = tdesc_data_alloc (); |
| 2974 | |
| 2975 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 2976 | S390_PSWM_REGNUM, "pswm"); |
| 2977 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 2978 | S390_PSWA_REGNUM, "pswa"); |
| 2979 | |
| 2980 | if (tdesc_unnumbered_register (feature, "r0")) |
| 2981 | { |
| 2982 | for (i = 0; i < 16; i++) |
| 2983 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 2984 | S390_R0_REGNUM + i, gprs[i]); |
| 2985 | } |
| 2986 | else |
| 2987 | { |
| 2988 | have_upper = 1; |
| 2989 | |
| 2990 | for (i = 0; i < 16; i++) |
| 2991 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 2992 | S390_R0_REGNUM + i, |
| 2993 | gprs_lower[i]); |
| 2994 | for (i = 0; i < 16; i++) |
| 2995 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 2996 | S390_R0_UPPER_REGNUM + i, |
| 2997 | gprs_upper[i]); |
| 2998 | } |
| 2999 | |
| 3000 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.fpr"); |
| 3001 | if (feature == NULL) |
| 3002 | { |
| 3003 | tdesc_data_cleanup (tdesc_data); |
| 3004 | return NULL; |
| 3005 | } |
| 3006 | |
| 3007 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 3008 | S390_FPC_REGNUM, "fpc"); |
| 3009 | for (i = 0; i < 16; i++) |
| 3010 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 3011 | S390_F0_REGNUM + i, fprs[i]); |
| 3012 | |
| 3013 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.acr"); |
| 3014 | if (feature == NULL) |
| 3015 | { |
| 3016 | tdesc_data_cleanup (tdesc_data); |
| 3017 | return NULL; |
| 3018 | } |
| 3019 | |
| 3020 | for (i = 0; i < 16; i++) |
| 3021 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 3022 | S390_A0_REGNUM + i, acrs[i]); |
| 3023 | |
| 3024 | /* Optional GNU/Linux-specific "registers". */ |
| 3025 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.linux"); |
| 3026 | if (feature) |
| 3027 | { |
| 3028 | tdesc_numbered_register (feature, tdesc_data, |
| 3029 | S390_ORIG_R2_REGNUM, "orig_r2"); |
| 3030 | |
| 3031 | if (tdesc_numbered_register (feature, tdesc_data, |
| 3032 | S390_LAST_BREAK_REGNUM, "last_break")) |
| 3033 | have_linux_v1 = 1; |
| 3034 | |
| 3035 | if (tdesc_numbered_register (feature, tdesc_data, |
| 3036 | S390_SYSTEM_CALL_REGNUM, "system_call")) |
| 3037 | have_linux_v2 = 1; |
| 3038 | |
| 3039 | if (have_linux_v2 > have_linux_v1) |
| 3040 | valid_p = 0; |
| 3041 | } |
| 3042 | |
| 3043 | /* Transaction diagnostic block. */ |
| 3044 | feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.tdb"); |
| 3045 | if (feature) |
| 3046 | { |
| 3047 | for (i = 0; i < ARRAY_SIZE (tdb_regs); i++) |
| 3048 | valid_p &= tdesc_numbered_register (feature, tdesc_data, |
| 3049 | S390_TDB_DWORD0_REGNUM + i, |
| 3050 | tdb_regs[i]); |
| 3051 | } |
| 3052 | |
| 3053 | if (!valid_p) |
| 3054 | { |
| 3055 | tdesc_data_cleanup (tdesc_data); |
| 3056 | return NULL; |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | /* Find a candidate among extant architectures. */ |
| 3061 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
| 3062 | arches != NULL; |
| 3063 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) |
| 3064 | { |
| 3065 | tdep = gdbarch_tdep (arches->gdbarch); |
| 3066 | if (!tdep) |
| 3067 | continue; |
| 3068 | if (tdep->abi != tdep_abi) |
| 3069 | continue; |
| 3070 | if ((tdep->gpr_full_regnum != -1) != have_upper) |
| 3071 | continue; |
| 3072 | if (tdesc_data != NULL) |
| 3073 | tdesc_data_cleanup (tdesc_data); |
| 3074 | return arches->gdbarch; |
| 3075 | } |
| 3076 | |
| 3077 | /* Otherwise create a new gdbarch for the specified machine type. */ |
| 3078 | tdep = XCNEW (struct gdbarch_tdep); |
| 3079 | tdep->abi = tdep_abi; |
| 3080 | gdbarch = gdbarch_alloc (&info, tdep); |
| 3081 | |
| 3082 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); |
| 3083 | set_gdbarch_char_signed (gdbarch, 0); |
| 3084 | |
| 3085 | /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles. |
| 3086 | We can safely let them default to 128-bit, since the debug info |
| 3087 | will give the size of type actually used in each case. */ |
| 3088 | set_gdbarch_long_double_bit (gdbarch, 128); |
| 3089 | set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); |
| 3090 | |
| 3091 | /* Amount PC must be decremented by after a breakpoint. This is |
| 3092 | often the number of bytes returned by gdbarch_breakpoint_from_pc but not |
| 3093 | always. */ |
| 3094 | set_gdbarch_decr_pc_after_break (gdbarch, 2); |
| 3095 | /* Stack grows downward. */ |
| 3096 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
| 3097 | set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc); |
| 3098 | set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue); |
| 3099 | set_gdbarch_in_function_epilogue_p (gdbarch, s390_in_function_epilogue_p); |
| 3100 | |
| 3101 | set_gdbarch_num_regs (gdbarch, S390_NUM_REGS); |
| 3102 | set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM); |
| 3103 | set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM); |
| 3104 | set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum); |
| 3105 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum); |
| 3106 | set_gdbarch_value_from_register (gdbarch, s390_value_from_register); |
| 3107 | set_gdbarch_regset_from_core_section (gdbarch, |
| 3108 | s390_regset_from_core_section); |
| 3109 | set_gdbarch_core_read_description (gdbarch, s390_core_read_description); |
| 3110 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_store_register); |
| 3111 | set_gdbarch_write_pc (gdbarch, s390_write_pc); |
| 3112 | set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read); |
| 3113 | set_gdbarch_pseudo_register_write (gdbarch, s390_pseudo_register_write); |
| 3114 | set_tdesc_pseudo_register_name (gdbarch, s390_pseudo_register_name); |
| 3115 | set_tdesc_pseudo_register_type (gdbarch, s390_pseudo_register_type); |
| 3116 | set_tdesc_pseudo_register_reggroup_p (gdbarch, |
| 3117 | s390_pseudo_register_reggroup_p); |
| 3118 | tdesc_use_registers (gdbarch, tdesc, tdesc_data); |
| 3119 | |
| 3120 | /* Assign pseudo register numbers. */ |
| 3121 | first_pseudo_reg = gdbarch_num_regs (gdbarch); |
| 3122 | last_pseudo_reg = first_pseudo_reg; |
| 3123 | tdep->gpr_full_regnum = -1; |
| 3124 | if (have_upper) |
| 3125 | { |
| 3126 | tdep->gpr_full_regnum = last_pseudo_reg; |
| 3127 | last_pseudo_reg += 16; |
| 3128 | } |
| 3129 | tdep->pc_regnum = last_pseudo_reg++; |
| 3130 | tdep->cc_regnum = last_pseudo_reg++; |
| 3131 | set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum); |
| 3132 | set_gdbarch_num_pseudo_regs (gdbarch, last_pseudo_reg - first_pseudo_reg); |
| 3133 | |
| 3134 | /* Inferior function calls. */ |
| 3135 | set_gdbarch_push_dummy_call (gdbarch, s390_push_dummy_call); |
| 3136 | set_gdbarch_dummy_id (gdbarch, s390_dummy_id); |
| 3137 | set_gdbarch_frame_align (gdbarch, s390_frame_align); |
| 3138 | set_gdbarch_return_value (gdbarch, s390_return_value); |
| 3139 | |
| 3140 | /* Syscall handling. */ |
| 3141 | set_gdbarch_get_syscall_number (gdbarch, s390_linux_get_syscall_number); |
| 3142 | |
| 3143 | /* Frame handling. */ |
| 3144 | dwarf2_frame_set_init_reg (gdbarch, s390_dwarf2_frame_init_reg); |
| 3145 | dwarf2_frame_set_adjust_regnum (gdbarch, s390_adjust_frame_regnum); |
| 3146 | dwarf2_append_unwinders (gdbarch); |
| 3147 | frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer); |
| 3148 | frame_unwind_append_unwinder (gdbarch, &s390_stub_frame_unwind); |
| 3149 | frame_unwind_append_unwinder (gdbarch, &s390_sigtramp_frame_unwind); |
| 3150 | frame_unwind_append_unwinder (gdbarch, &s390_frame_unwind); |
| 3151 | frame_base_set_default (gdbarch, &s390_frame_base); |
| 3152 | set_gdbarch_unwind_pc (gdbarch, s390_unwind_pc); |
| 3153 | set_gdbarch_unwind_sp (gdbarch, s390_unwind_sp); |
| 3154 | |
| 3155 | /* Displaced stepping. */ |
| 3156 | set_gdbarch_displaced_step_copy_insn (gdbarch, |
| 3157 | simple_displaced_step_copy_insn); |
| 3158 | set_gdbarch_displaced_step_fixup (gdbarch, s390_displaced_step_fixup); |
| 3159 | set_gdbarch_displaced_step_free_closure (gdbarch, |
| 3160 | simple_displaced_step_free_closure); |
| 3161 | set_gdbarch_displaced_step_location (gdbarch, |
| 3162 | displaced_step_at_entry_point); |
| 3163 | set_gdbarch_max_insn_length (gdbarch, S390_MAX_INSTR_SIZE); |
| 3164 | |
| 3165 | /* Note that GNU/Linux is the only OS supported on this |
| 3166 | platform. */ |
| 3167 | linux_init_abi (info, gdbarch); |
| 3168 | |
| 3169 | switch (tdep->abi) |
| 3170 | { |
| 3171 | case ABI_LINUX_S390: |
| 3172 | tdep->gregset = &s390_gregset; |
| 3173 | tdep->sizeof_gregset = s390_sizeof_gregset; |
| 3174 | tdep->fpregset = &s390_fpregset; |
| 3175 | tdep->sizeof_fpregset = s390_sizeof_fpregset; |
| 3176 | |
| 3177 | set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove); |
| 3178 | set_solib_svr4_fetch_link_map_offsets |
| 3179 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); |
| 3180 | |
| 3181 | set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390); |
| 3182 | |
| 3183 | if (have_upper) |
| 3184 | { |
| 3185 | if (have_linux_v2) |
| 3186 | set_gdbarch_core_regset_sections (gdbarch, |
| 3187 | s390_linux64v2_regset_sections); |
| 3188 | else if (have_linux_v1) |
| 3189 | set_gdbarch_core_regset_sections (gdbarch, |
| 3190 | s390_linux64v1_regset_sections); |
| 3191 | else |
| 3192 | set_gdbarch_core_regset_sections (gdbarch, |
| 3193 | s390_linux64_regset_sections); |
| 3194 | } |
| 3195 | else |
| 3196 | { |
| 3197 | if (have_linux_v2) |
| 3198 | set_gdbarch_core_regset_sections (gdbarch, |
| 3199 | s390_linux32v2_regset_sections); |
| 3200 | else if (have_linux_v1) |
| 3201 | set_gdbarch_core_regset_sections (gdbarch, |
| 3202 | s390_linux32v1_regset_sections); |
| 3203 | else |
| 3204 | set_gdbarch_core_regset_sections (gdbarch, |
| 3205 | s390_linux32_regset_sections); |
| 3206 | } |
| 3207 | break; |
| 3208 | |
| 3209 | case ABI_LINUX_ZSERIES: |
| 3210 | tdep->gregset = &s390_gregset; |
| 3211 | tdep->sizeof_gregset = s390x_sizeof_gregset; |
| 3212 | tdep->fpregset = &s390_fpregset; |
| 3213 | tdep->sizeof_fpregset = s390_sizeof_fpregset; |
| 3214 | |
| 3215 | set_gdbarch_long_bit (gdbarch, 64); |
| 3216 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 3217 | set_gdbarch_ptr_bit (gdbarch, 64); |
| 3218 | set_solib_svr4_fetch_link_map_offsets |
| 3219 | (gdbarch, svr4_lp64_fetch_link_map_offsets); |
| 3220 | set_gdbarch_address_class_type_flags (gdbarch, |
| 3221 | s390_address_class_type_flags); |
| 3222 | set_gdbarch_address_class_type_flags_to_name (gdbarch, |
| 3223 | s390_address_class_type_flags_to_name); |
| 3224 | set_gdbarch_address_class_name_to_type_flags (gdbarch, |
| 3225 | s390_address_class_name_to_type_flags); |
| 3226 | |
| 3227 | set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390); |
| 3228 | |
| 3229 | if (have_linux_v2) |
| 3230 | set_gdbarch_core_regset_sections (gdbarch, |
| 3231 | s390x_linux64v2_regset_sections); |
| 3232 | else if (have_linux_v1) |
| 3233 | set_gdbarch_core_regset_sections (gdbarch, |
| 3234 | s390x_linux64v1_regset_sections); |
| 3235 | else |
| 3236 | set_gdbarch_core_regset_sections (gdbarch, |
| 3237 | s390x_linux64_regset_sections); |
| 3238 | break; |
| 3239 | } |
| 3240 | |
| 3241 | set_gdbarch_print_insn (gdbarch, print_insn_s390); |
| 3242 | |
| 3243 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
| 3244 | |
| 3245 | /* Enable TLS support. */ |
| 3246 | set_gdbarch_fetch_tls_load_module_address (gdbarch, |
| 3247 | svr4_fetch_objfile_link_map); |
| 3248 | |
| 3249 | set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type); |
| 3250 | |
| 3251 | /* SystemTap functions. */ |
| 3252 | set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes); |
| 3253 | set_gdbarch_stap_register_indirection_prefixes (gdbarch, |
| 3254 | stap_register_indirection_prefixes); |
| 3255 | set_gdbarch_stap_register_indirection_suffixes (gdbarch, |
| 3256 | stap_register_indirection_suffixes); |
| 3257 | set_gdbarch_stap_is_single_operand (gdbarch, s390_stap_is_single_operand); |
| 3258 | |
| 3259 | return gdbarch; |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */ |
| 3264 | |
| 3265 | void |
| 3266 | _initialize_s390_tdep (void) |
| 3267 | { |
| 3268 | /* Hook us into the gdbarch mechanism. */ |
| 3269 | register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init); |
| 3270 | |
| 3271 | /* Initialize the GNU/Linux target descriptions. */ |
| 3272 | initialize_tdesc_s390_linux32 (); |
| 3273 | initialize_tdesc_s390_linux32v1 (); |
| 3274 | initialize_tdesc_s390_linux32v2 (); |
| 3275 | initialize_tdesc_s390_linux64 (); |
| 3276 | initialize_tdesc_s390_linux64v1 (); |
| 3277 | initialize_tdesc_s390_linux64v2 (); |
| 3278 | initialize_tdesc_s390_te_linux64 (); |
| 3279 | initialize_tdesc_s390x_linux64 (); |
| 3280 | initialize_tdesc_s390x_linux64v1 (); |
| 3281 | initialize_tdesc_s390x_linux64v2 (); |
| 3282 | initialize_tdesc_s390x_te_linux64 (); |
| 3283 | } |