| 1 | /* Target-dependent code for the IA-64 for GDB, the GNU debugger. |
| 2 | |
| 3 | Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
| 4 | Free Software Foundation, Inc. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "inferior.h" |
| 23 | #include "gdbcore.h" |
| 24 | #include "arch-utils.h" |
| 25 | #include "floatformat.h" |
| 26 | #include "gdbtypes.h" |
| 27 | #include "regcache.h" |
| 28 | #include "reggroups.h" |
| 29 | #include "frame.h" |
| 30 | #include "frame-base.h" |
| 31 | #include "frame-unwind.h" |
| 32 | #include "doublest.h" |
| 33 | #include "value.h" |
| 34 | #include "gdb_assert.h" |
| 35 | #include "objfiles.h" |
| 36 | #include "elf/common.h" /* for DT_PLTGOT value */ |
| 37 | #include "elf-bfd.h" |
| 38 | #include "dis-asm.h" |
| 39 | #include "infcall.h" |
| 40 | #include "osabi.h" |
| 41 | #include "ia64-tdep.h" |
| 42 | #include "cp-abi.h" |
| 43 | |
| 44 | #ifdef HAVE_LIBUNWIND_IA64_H |
| 45 | #include "elf/ia64.h" /* for PT_IA_64_UNWIND value */ |
| 46 | #include "libunwind-frame.h" |
| 47 | #include "libunwind-ia64.h" |
| 48 | |
| 49 | /* Note: KERNEL_START is supposed to be an address which is not going |
| 50 | to ever contain any valid unwind info. For ia64 linux, the choice |
| 51 | of 0xc000000000000000 is fairly safe since that's uncached space. |
| 52 | |
| 53 | We use KERNEL_START as follows: after obtaining the kernel's |
| 54 | unwind table via getunwind(), we project its unwind data into |
| 55 | address-range KERNEL_START-(KERNEL_START+ktab_size) and then |
| 56 | when ia64_access_mem() sees a memory access to this |
| 57 | address-range, we redirect it to ktab instead. |
| 58 | |
| 59 | None of this hackery is needed with a modern kernel/libcs |
| 60 | which uses the kernel virtual DSO to provide access to the |
| 61 | kernel's unwind info. In that case, ktab_size remains 0 and |
| 62 | hence the value of KERNEL_START doesn't matter. */ |
| 63 | |
| 64 | #define KERNEL_START 0xc000000000000000ULL |
| 65 | |
| 66 | static size_t ktab_size = 0; |
| 67 | struct ia64_table_entry |
| 68 | { |
| 69 | uint64_t start_offset; |
| 70 | uint64_t end_offset; |
| 71 | uint64_t info_offset; |
| 72 | }; |
| 73 | |
| 74 | static struct ia64_table_entry *ktab = NULL; |
| 75 | |
| 76 | #endif |
| 77 | |
| 78 | /* An enumeration of the different IA-64 instruction types. */ |
| 79 | |
| 80 | typedef enum instruction_type |
| 81 | { |
| 82 | A, /* Integer ALU ; I-unit or M-unit */ |
| 83 | I, /* Non-ALU integer; I-unit */ |
| 84 | M, /* Memory ; M-unit */ |
| 85 | F, /* Floating-point ; F-unit */ |
| 86 | B, /* Branch ; B-unit */ |
| 87 | L, /* Extended (L+X) ; I-unit */ |
| 88 | X, /* Extended (L+X) ; I-unit */ |
| 89 | undefined /* undefined or reserved */ |
| 90 | } instruction_type; |
| 91 | |
| 92 | /* We represent IA-64 PC addresses as the value of the instruction |
| 93 | pointer or'd with some bit combination in the low nibble which |
| 94 | represents the slot number in the bundle addressed by the |
| 95 | instruction pointer. The problem is that the Linux kernel |
| 96 | multiplies its slot numbers (for exceptions) by one while the |
| 97 | disassembler multiplies its slot numbers by 6. In addition, I've |
| 98 | heard it said that the simulator uses 1 as the multiplier. |
| 99 | |
| 100 | I've fixed the disassembler so that the bytes_per_line field will |
| 101 | be the slot multiplier. If bytes_per_line comes in as zero, it |
| 102 | is set to six (which is how it was set up initially). -- objdump |
| 103 | displays pretty disassembly dumps with this value. For our purposes, |
| 104 | we'll set bytes_per_line to SLOT_MULTIPLIER. This is okay since we |
| 105 | never want to also display the raw bytes the way objdump does. */ |
| 106 | |
| 107 | #define SLOT_MULTIPLIER 1 |
| 108 | |
| 109 | /* Length in bytes of an instruction bundle */ |
| 110 | |
| 111 | #define BUNDLE_LEN 16 |
| 112 | |
| 113 | static gdbarch_init_ftype ia64_gdbarch_init; |
| 114 | |
| 115 | static gdbarch_register_name_ftype ia64_register_name; |
| 116 | static gdbarch_register_type_ftype ia64_register_type; |
| 117 | static gdbarch_breakpoint_from_pc_ftype ia64_breakpoint_from_pc; |
| 118 | static gdbarch_skip_prologue_ftype ia64_skip_prologue; |
| 119 | static struct type *is_float_or_hfa_type (struct type *t); |
| 120 | static CORE_ADDR ia64_find_global_pointer (CORE_ADDR faddr); |
| 121 | |
| 122 | static struct type *builtin_type_ia64_ext; |
| 123 | |
| 124 | #define NUM_IA64_RAW_REGS 462 |
| 125 | |
| 126 | static int sp_regnum = IA64_GR12_REGNUM; |
| 127 | static int fp_regnum = IA64_VFP_REGNUM; |
| 128 | static int lr_regnum = IA64_VRAP_REGNUM; |
| 129 | |
| 130 | /* NOTE: we treat the register stack registers r32-r127 as pseudo-registers because |
| 131 | they may not be accessible via the ptrace register get/set interfaces. */ |
| 132 | enum pseudo_regs { FIRST_PSEUDO_REGNUM = NUM_IA64_RAW_REGS, VBOF_REGNUM = IA64_NAT127_REGNUM + 1, V32_REGNUM, |
| 133 | V127_REGNUM = V32_REGNUM + 95, |
| 134 | VP0_REGNUM, VP16_REGNUM = VP0_REGNUM + 16, VP63_REGNUM = VP0_REGNUM + 63, LAST_PSEUDO_REGNUM }; |
| 135 | |
| 136 | /* Array of register names; There should be ia64_num_regs strings in |
| 137 | the initializer. */ |
| 138 | |
| 139 | static char *ia64_register_names[] = |
| 140 | { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 141 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 142 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 143 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", |
| 144 | "", "", "", "", "", "", "", "", |
| 145 | "", "", "", "", "", "", "", "", |
| 146 | "", "", "", "", "", "", "", "", |
| 147 | "", "", "", "", "", "", "", "", |
| 148 | "", "", "", "", "", "", "", "", |
| 149 | "", "", "", "", "", "", "", "", |
| 150 | "", "", "", "", "", "", "", "", |
| 151 | "", "", "", "", "", "", "", "", |
| 152 | "", "", "", "", "", "", "", "", |
| 153 | "", "", "", "", "", "", "", "", |
| 154 | "", "", "", "", "", "", "", "", |
| 155 | "", "", "", "", "", "", "", "", |
| 156 | |
| 157 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
| 158 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", |
| 159 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", |
| 160 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", |
| 161 | "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39", |
| 162 | "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", |
| 163 | "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55", |
| 164 | "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63", |
| 165 | "f64", "f65", "f66", "f67", "f68", "f69", "f70", "f71", |
| 166 | "f72", "f73", "f74", "f75", "f76", "f77", "f78", "f79", |
| 167 | "f80", "f81", "f82", "f83", "f84", "f85", "f86", "f87", |
| 168 | "f88", "f89", "f90", "f91", "f92", "f93", "f94", "f95", |
| 169 | "f96", "f97", "f98", "f99", "f100", "f101", "f102", "f103", |
| 170 | "f104", "f105", "f106", "f107", "f108", "f109", "f110", "f111", |
| 171 | "f112", "f113", "f114", "f115", "f116", "f117", "f118", "f119", |
| 172 | "f120", "f121", "f122", "f123", "f124", "f125", "f126", "f127", |
| 173 | |
| 174 | "", "", "", "", "", "", "", "", |
| 175 | "", "", "", "", "", "", "", "", |
| 176 | "", "", "", "", "", "", "", "", |
| 177 | "", "", "", "", "", "", "", "", |
| 178 | "", "", "", "", "", "", "", "", |
| 179 | "", "", "", "", "", "", "", "", |
| 180 | "", "", "", "", "", "", "", "", |
| 181 | "", "", "", "", "", "", "", "", |
| 182 | |
| 183 | "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", |
| 184 | |
| 185 | "vfp", "vrap", |
| 186 | |
| 187 | "pr", "ip", "psr", "cfm", |
| 188 | |
| 189 | "kr0", "kr1", "kr2", "kr3", "kr4", "kr5", "kr6", "kr7", |
| 190 | "", "", "", "", "", "", "", "", |
| 191 | "rsc", "bsp", "bspstore", "rnat", |
| 192 | "", "fcr", "", "", |
| 193 | "eflag", "csd", "ssd", "cflg", "fsr", "fir", "fdr", "", |
| 194 | "ccv", "", "", "", "unat", "", "", "", |
| 195 | "fpsr", "", "", "", "itc", |
| 196 | "", "", "", "", "", "", "", "", "", "", |
| 197 | "", "", "", "", "", "", "", "", "", |
| 198 | "pfs", "lc", "ec", |
| 199 | "", "", "", "", "", "", "", "", "", "", |
| 200 | "", "", "", "", "", "", "", "", "", "", |
| 201 | "", "", "", "", "", "", "", "", "", "", |
| 202 | "", "", "", "", "", "", "", "", "", "", |
| 203 | "", "", "", "", "", "", "", "", "", "", |
| 204 | "", "", "", "", "", "", "", "", "", "", |
| 205 | "", |
| 206 | "nat0", "nat1", "nat2", "nat3", "nat4", "nat5", "nat6", "nat7", |
| 207 | "nat8", "nat9", "nat10", "nat11", "nat12", "nat13", "nat14", "nat15", |
| 208 | "nat16", "nat17", "nat18", "nat19", "nat20", "nat21", "nat22", "nat23", |
| 209 | "nat24", "nat25", "nat26", "nat27", "nat28", "nat29", "nat30", "nat31", |
| 210 | "nat32", "nat33", "nat34", "nat35", "nat36", "nat37", "nat38", "nat39", |
| 211 | "nat40", "nat41", "nat42", "nat43", "nat44", "nat45", "nat46", "nat47", |
| 212 | "nat48", "nat49", "nat50", "nat51", "nat52", "nat53", "nat54", "nat55", |
| 213 | "nat56", "nat57", "nat58", "nat59", "nat60", "nat61", "nat62", "nat63", |
| 214 | "nat64", "nat65", "nat66", "nat67", "nat68", "nat69", "nat70", "nat71", |
| 215 | "nat72", "nat73", "nat74", "nat75", "nat76", "nat77", "nat78", "nat79", |
| 216 | "nat80", "nat81", "nat82", "nat83", "nat84", "nat85", "nat86", "nat87", |
| 217 | "nat88", "nat89", "nat90", "nat91", "nat92", "nat93", "nat94", "nat95", |
| 218 | "nat96", "nat97", "nat98", "nat99", "nat100","nat101","nat102","nat103", |
| 219 | "nat104","nat105","nat106","nat107","nat108","nat109","nat110","nat111", |
| 220 | "nat112","nat113","nat114","nat115","nat116","nat117","nat118","nat119", |
| 221 | "nat120","nat121","nat122","nat123","nat124","nat125","nat126","nat127", |
| 222 | |
| 223 | "bof", |
| 224 | |
| 225 | "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", |
| 226 | "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", |
| 227 | "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", |
| 228 | "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63", |
| 229 | "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71", |
| 230 | "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79", |
| 231 | "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87", |
| 232 | "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95", |
| 233 | "r96", "r97", "r98", "r99", "r100", "r101", "r102", "r103", |
| 234 | "r104", "r105", "r106", "r107", "r108", "r109", "r110", "r111", |
| 235 | "r112", "r113", "r114", "r115", "r116", "r117", "r118", "r119", |
| 236 | "r120", "r121", "r122", "r123", "r124", "r125", "r126", "r127", |
| 237 | |
| 238 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", |
| 239 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", |
| 240 | "p16", "p17", "p18", "p19", "p20", "p21", "p22", "p23", |
| 241 | "p24", "p25", "p26", "p27", "p28", "p29", "p30", "p31", |
| 242 | "p32", "p33", "p34", "p35", "p36", "p37", "p38", "p39", |
| 243 | "p40", "p41", "p42", "p43", "p44", "p45", "p46", "p47", |
| 244 | "p48", "p49", "p50", "p51", "p52", "p53", "p54", "p55", |
| 245 | "p56", "p57", "p58", "p59", "p60", "p61", "p62", "p63", |
| 246 | }; |
| 247 | |
| 248 | struct ia64_frame_cache |
| 249 | { |
| 250 | CORE_ADDR base; /* frame pointer base for frame */ |
| 251 | CORE_ADDR pc; /* function start pc for frame */ |
| 252 | CORE_ADDR saved_sp; /* stack pointer for frame */ |
| 253 | CORE_ADDR bsp; /* points at r32 for the current frame */ |
| 254 | CORE_ADDR cfm; /* cfm value for current frame */ |
| 255 | CORE_ADDR prev_cfm; /* cfm value for previous frame */ |
| 256 | int frameless; |
| 257 | int sof; /* Size of frame (decoded from cfm value) */ |
| 258 | int sol; /* Size of locals (decoded from cfm value) */ |
| 259 | int sor; /* Number of rotating registers. (decoded from cfm value) */ |
| 260 | CORE_ADDR after_prologue; |
| 261 | /* Address of first instruction after the last |
| 262 | prologue instruction; Note that there may |
| 263 | be instructions from the function's body |
| 264 | intermingled with the prologue. */ |
| 265 | int mem_stack_frame_size; |
| 266 | /* Size of the memory stack frame (may be zero), |
| 267 | or -1 if it has not been determined yet. */ |
| 268 | int fp_reg; /* Register number (if any) used a frame pointer |
| 269 | for this frame. 0 if no register is being used |
| 270 | as the frame pointer. */ |
| 271 | |
| 272 | /* Saved registers. */ |
| 273 | CORE_ADDR saved_regs[NUM_IA64_RAW_REGS]; |
| 274 | |
| 275 | }; |
| 276 | |
| 277 | int |
| 278 | ia64_register_reggroup_p (struct gdbarch *gdbarch, int regnum, |
| 279 | struct reggroup *group) |
| 280 | { |
| 281 | int vector_p; |
| 282 | int float_p; |
| 283 | int raw_p; |
| 284 | if (group == all_reggroup) |
| 285 | return 1; |
| 286 | vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); |
| 287 | float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; |
| 288 | raw_p = regnum < NUM_IA64_RAW_REGS; |
| 289 | if (group == float_reggroup) |
| 290 | return float_p; |
| 291 | if (group == vector_reggroup) |
| 292 | return vector_p; |
| 293 | if (group == general_reggroup) |
| 294 | return (!vector_p && !float_p); |
| 295 | if (group == save_reggroup || group == restore_reggroup) |
| 296 | return raw_p; |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static const char * |
| 301 | ia64_register_name (struct gdbarch *gdbarch, int reg) |
| 302 | { |
| 303 | return ia64_register_names[reg]; |
| 304 | } |
| 305 | |
| 306 | struct type * |
| 307 | ia64_register_type (struct gdbarch *arch, int reg) |
| 308 | { |
| 309 | if (reg >= IA64_FR0_REGNUM && reg <= IA64_FR127_REGNUM) |
| 310 | return builtin_type_ia64_ext; |
| 311 | else |
| 312 | return builtin_type (arch)->builtin_long; |
| 313 | } |
| 314 | |
| 315 | static int |
| 316 | ia64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg) |
| 317 | { |
| 318 | if (reg >= IA64_GR32_REGNUM && reg <= IA64_GR127_REGNUM) |
| 319 | return V32_REGNUM + (reg - IA64_GR32_REGNUM); |
| 320 | return reg; |
| 321 | } |
| 322 | |
| 323 | static int |
| 324 | floatformat_valid (const struct floatformat *fmt, const void *from) |
| 325 | { |
| 326 | return 1; |
| 327 | } |
| 328 | |
| 329 | const struct floatformat floatformat_ia64_ext = |
| 330 | { |
| 331 | floatformat_little, 82, 0, 1, 17, 65535, 0x1ffff, 18, 64, |
| 332 | floatformat_intbit_yes, "floatformat_ia64_ext", floatformat_valid, NULL |
| 333 | }; |
| 334 | |
| 335 | const struct floatformat *floatformats_ia64_ext[2] = |
| 336 | { |
| 337 | &floatformat_ia64_ext, |
| 338 | &floatformat_ia64_ext |
| 339 | }; |
| 340 | |
| 341 | |
| 342 | /* Extract ``len'' bits from an instruction bundle starting at |
| 343 | bit ``from''. */ |
| 344 | |
| 345 | static long long |
| 346 | extract_bit_field (const char *bundle, int from, int len) |
| 347 | { |
| 348 | long long result = 0LL; |
| 349 | int to = from + len; |
| 350 | int from_byte = from / 8; |
| 351 | int to_byte = to / 8; |
| 352 | unsigned char *b = (unsigned char *) bundle; |
| 353 | unsigned char c; |
| 354 | int lshift; |
| 355 | int i; |
| 356 | |
| 357 | c = b[from_byte]; |
| 358 | if (from_byte == to_byte) |
| 359 | c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8); |
| 360 | result = c >> (from % 8); |
| 361 | lshift = 8 - (from % 8); |
| 362 | |
| 363 | for (i = from_byte+1; i < to_byte; i++) |
| 364 | { |
| 365 | result |= ((long long) b[i]) << lshift; |
| 366 | lshift += 8; |
| 367 | } |
| 368 | |
| 369 | if (from_byte < to_byte && (to % 8 != 0)) |
| 370 | { |
| 371 | c = b[to_byte]; |
| 372 | c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8); |
| 373 | result |= ((long long) c) << lshift; |
| 374 | } |
| 375 | |
| 376 | return result; |
| 377 | } |
| 378 | |
| 379 | /* Replace the specified bits in an instruction bundle */ |
| 380 | |
| 381 | static void |
| 382 | replace_bit_field (char *bundle, long long val, int from, int len) |
| 383 | { |
| 384 | int to = from + len; |
| 385 | int from_byte = from / 8; |
| 386 | int to_byte = to / 8; |
| 387 | unsigned char *b = (unsigned char *) bundle; |
| 388 | unsigned char c; |
| 389 | |
| 390 | if (from_byte == to_byte) |
| 391 | { |
| 392 | unsigned char left, right; |
| 393 | c = b[from_byte]; |
| 394 | left = (c >> (to % 8)) << (to % 8); |
| 395 | right = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8); |
| 396 | c = (unsigned char) (val & 0xff); |
| 397 | c = (unsigned char) (c << (from % 8 + 8 - to % 8)) >> (8 - to % 8); |
| 398 | c |= right | left; |
| 399 | b[from_byte] = c; |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | int i; |
| 404 | c = b[from_byte]; |
| 405 | c = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8); |
| 406 | c = c | (val << (from % 8)); |
| 407 | b[from_byte] = c; |
| 408 | val >>= 8 - from % 8; |
| 409 | |
| 410 | for (i = from_byte+1; i < to_byte; i++) |
| 411 | { |
| 412 | c = val & 0xff; |
| 413 | val >>= 8; |
| 414 | b[i] = c; |
| 415 | } |
| 416 | |
| 417 | if (to % 8 != 0) |
| 418 | { |
| 419 | unsigned char cv = (unsigned char) val; |
| 420 | c = b[to_byte]; |
| 421 | c = c >> (to % 8) << (to % 8); |
| 422 | c |= ((unsigned char) (cv << (8 - to % 8))) >> (8 - to % 8); |
| 423 | b[to_byte] = c; |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | /* Return the contents of slot N (for N = 0, 1, or 2) in |
| 429 | and instruction bundle */ |
| 430 | |
| 431 | static long long |
| 432 | slotN_contents (char *bundle, int slotnum) |
| 433 | { |
| 434 | return extract_bit_field (bundle, 5+41*slotnum, 41); |
| 435 | } |
| 436 | |
| 437 | /* Store an instruction in an instruction bundle */ |
| 438 | |
| 439 | static void |
| 440 | replace_slotN_contents (char *bundle, long long instr, int slotnum) |
| 441 | { |
| 442 | replace_bit_field (bundle, instr, 5+41*slotnum, 41); |
| 443 | } |
| 444 | |
| 445 | static enum instruction_type template_encoding_table[32][3] = |
| 446 | { |
| 447 | { M, I, I }, /* 00 */ |
| 448 | { M, I, I }, /* 01 */ |
| 449 | { M, I, I }, /* 02 */ |
| 450 | { M, I, I }, /* 03 */ |
| 451 | { M, L, X }, /* 04 */ |
| 452 | { M, L, X }, /* 05 */ |
| 453 | { undefined, undefined, undefined }, /* 06 */ |
| 454 | { undefined, undefined, undefined }, /* 07 */ |
| 455 | { M, M, I }, /* 08 */ |
| 456 | { M, M, I }, /* 09 */ |
| 457 | { M, M, I }, /* 0A */ |
| 458 | { M, M, I }, /* 0B */ |
| 459 | { M, F, I }, /* 0C */ |
| 460 | { M, F, I }, /* 0D */ |
| 461 | { M, M, F }, /* 0E */ |
| 462 | { M, M, F }, /* 0F */ |
| 463 | { M, I, B }, /* 10 */ |
| 464 | { M, I, B }, /* 11 */ |
| 465 | { M, B, B }, /* 12 */ |
| 466 | { M, B, B }, /* 13 */ |
| 467 | { undefined, undefined, undefined }, /* 14 */ |
| 468 | { undefined, undefined, undefined }, /* 15 */ |
| 469 | { B, B, B }, /* 16 */ |
| 470 | { B, B, B }, /* 17 */ |
| 471 | { M, M, B }, /* 18 */ |
| 472 | { M, M, B }, /* 19 */ |
| 473 | { undefined, undefined, undefined }, /* 1A */ |
| 474 | { undefined, undefined, undefined }, /* 1B */ |
| 475 | { M, F, B }, /* 1C */ |
| 476 | { M, F, B }, /* 1D */ |
| 477 | { undefined, undefined, undefined }, /* 1E */ |
| 478 | { undefined, undefined, undefined }, /* 1F */ |
| 479 | }; |
| 480 | |
| 481 | /* Fetch and (partially) decode an instruction at ADDR and return the |
| 482 | address of the next instruction to fetch. */ |
| 483 | |
| 484 | static CORE_ADDR |
| 485 | fetch_instruction (CORE_ADDR addr, instruction_type *it, long long *instr) |
| 486 | { |
| 487 | char bundle[BUNDLE_LEN]; |
| 488 | int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER; |
| 489 | long long template; |
| 490 | int val; |
| 491 | |
| 492 | /* Warn about slot numbers greater than 2. We used to generate |
| 493 | an error here on the assumption that the user entered an invalid |
| 494 | address. But, sometimes GDB itself requests an invalid address. |
| 495 | This can (easily) happen when execution stops in a function for |
| 496 | which there are no symbols. The prologue scanner will attempt to |
| 497 | find the beginning of the function - if the nearest symbol |
| 498 | happens to not be aligned on a bundle boundary (16 bytes), the |
| 499 | resulting starting address will cause GDB to think that the slot |
| 500 | number is too large. |
| 501 | |
| 502 | So we warn about it and set the slot number to zero. It is |
| 503 | not necessarily a fatal condition, particularly if debugging |
| 504 | at the assembly language level. */ |
| 505 | if (slotnum > 2) |
| 506 | { |
| 507 | warning (_("Can't fetch instructions for slot numbers greater than 2.\n" |
| 508 | "Using slot 0 instead")); |
| 509 | slotnum = 0; |
| 510 | } |
| 511 | |
| 512 | addr &= ~0x0f; |
| 513 | |
| 514 | val = target_read_memory (addr, bundle, BUNDLE_LEN); |
| 515 | |
| 516 | if (val != 0) |
| 517 | return 0; |
| 518 | |
| 519 | *instr = slotN_contents (bundle, slotnum); |
| 520 | template = extract_bit_field (bundle, 0, 5); |
| 521 | *it = template_encoding_table[(int)template][slotnum]; |
| 522 | |
| 523 | if (slotnum == 2 || (slotnum == 1 && *it == L)) |
| 524 | addr += 16; |
| 525 | else |
| 526 | addr += (slotnum + 1) * SLOT_MULTIPLIER; |
| 527 | |
| 528 | return addr; |
| 529 | } |
| 530 | |
| 531 | /* There are 5 different break instructions (break.i, break.b, |
| 532 | break.m, break.f, and break.x), but they all have the same |
| 533 | encoding. (The five bit template in the low five bits of the |
| 534 | instruction bundle distinguishes one from another.) |
| 535 | |
| 536 | The runtime architecture manual specifies that break instructions |
| 537 | used for debugging purposes must have the upper two bits of the 21 |
| 538 | bit immediate set to a 0 and a 1 respectively. A breakpoint |
| 539 | instruction encodes the most significant bit of its 21 bit |
| 540 | immediate at bit 36 of the 41 bit instruction. The penultimate msb |
| 541 | is at bit 25 which leads to the pattern below. |
| 542 | |
| 543 | Originally, I had this set up to do, e.g, a "break.i 0x80000" But |
| 544 | it turns out that 0x80000 was used as the syscall break in the early |
| 545 | simulators. So I changed the pattern slightly to do "break.i 0x080001" |
| 546 | instead. But that didn't work either (I later found out that this |
| 547 | pattern was used by the simulator that I was using.) So I ended up |
| 548 | using the pattern seen below. */ |
| 549 | |
| 550 | #if 0 |
| 551 | #define IA64_BREAKPOINT 0x00002000040LL |
| 552 | #endif |
| 553 | #define IA64_BREAKPOINT 0x00003333300LL |
| 554 | |
| 555 | static int |
| 556 | ia64_memory_insert_breakpoint (struct gdbarch *gdbarch, |
| 557 | struct bp_target_info *bp_tgt) |
| 558 | { |
| 559 | CORE_ADDR addr = bp_tgt->placed_address; |
| 560 | char bundle[BUNDLE_LEN]; |
| 561 | int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER; |
| 562 | long long instr; |
| 563 | int val; |
| 564 | int template; |
| 565 | |
| 566 | if (slotnum > 2) |
| 567 | error (_("Can't insert breakpoint for slot numbers greater than 2.")); |
| 568 | |
| 569 | addr &= ~0x0f; |
| 570 | |
| 571 | val = target_read_memory (addr, bundle, BUNDLE_LEN); |
| 572 | |
| 573 | /* Check for L type instruction in 2nd slot, if present then |
| 574 | bump up the slot number to the 3rd slot */ |
| 575 | template = extract_bit_field (bundle, 0, 5); |
| 576 | if (slotnum == 1 && template_encoding_table[template][1] == L) |
| 577 | { |
| 578 | slotnum = 2; |
| 579 | } |
| 580 | |
| 581 | instr = slotN_contents (bundle, slotnum); |
| 582 | memcpy (bp_tgt->shadow_contents, &instr, sizeof (instr)); |
| 583 | bp_tgt->placed_size = bp_tgt->shadow_len = sizeof (instr); |
| 584 | replace_slotN_contents (bundle, IA64_BREAKPOINT, slotnum); |
| 585 | if (val == 0) |
| 586 | target_write_memory (addr, bundle, BUNDLE_LEN); |
| 587 | |
| 588 | return val; |
| 589 | } |
| 590 | |
| 591 | static int |
| 592 | ia64_memory_remove_breakpoint (struct gdbarch *gdbarch, |
| 593 | struct bp_target_info *bp_tgt) |
| 594 | { |
| 595 | CORE_ADDR addr = bp_tgt->placed_address; |
| 596 | char bundle[BUNDLE_LEN]; |
| 597 | int slotnum = (addr & 0x0f) / SLOT_MULTIPLIER; |
| 598 | long long instr; |
| 599 | int val; |
| 600 | int template; |
| 601 | struct cleanup *cleanup; |
| 602 | |
| 603 | addr &= ~0x0f; |
| 604 | |
| 605 | /* Disable the automatic memory restoration from breakpoints while |
| 606 | we read our instruction bundle. Otherwise, the general restoration |
| 607 | mechanism kicks in and ends up corrupting our bundle, because it |
| 608 | is not aware of the concept of instruction bundles. */ |
| 609 | cleanup = make_show_memory_breakpoints_cleanup (1); |
| 610 | val = target_read_memory (addr, bundle, BUNDLE_LEN); |
| 611 | |
| 612 | /* Check for L type instruction in 2nd slot, if present then |
| 613 | bump up the slot number to the 3rd slot */ |
| 614 | template = extract_bit_field (bundle, 0, 5); |
| 615 | if (slotnum == 1 && template_encoding_table[template][1] == L) |
| 616 | { |
| 617 | slotnum = 2; |
| 618 | } |
| 619 | |
| 620 | memcpy (&instr, bp_tgt->shadow_contents, sizeof instr); |
| 621 | replace_slotN_contents (bundle, instr, slotnum); |
| 622 | if (val == 0) |
| 623 | target_write_memory (addr, bundle, BUNDLE_LEN); |
| 624 | |
| 625 | do_cleanups (cleanup); |
| 626 | return val; |
| 627 | } |
| 628 | |
| 629 | /* We don't really want to use this, but remote.c needs to call it in order |
| 630 | to figure out if Z-packets are supported or not. Oh, well. */ |
| 631 | const unsigned char * |
| 632 | ia64_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr) |
| 633 | { |
| 634 | static unsigned char breakpoint[] = |
| 635 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 636 | *lenptr = sizeof (breakpoint); |
| 637 | #if 0 |
| 638 | *pcptr &= ~0x0f; |
| 639 | #endif |
| 640 | return breakpoint; |
| 641 | } |
| 642 | |
| 643 | static CORE_ADDR |
| 644 | ia64_read_pc (struct regcache *regcache) |
| 645 | { |
| 646 | ULONGEST psr_value, pc_value; |
| 647 | int slot_num; |
| 648 | |
| 649 | regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); |
| 650 | regcache_cooked_read_unsigned (regcache, IA64_IP_REGNUM, &pc_value); |
| 651 | slot_num = (psr_value >> 41) & 3; |
| 652 | |
| 653 | return pc_value | (slot_num * SLOT_MULTIPLIER); |
| 654 | } |
| 655 | |
| 656 | void |
| 657 | ia64_write_pc (struct regcache *regcache, CORE_ADDR new_pc) |
| 658 | { |
| 659 | int slot_num = (int) (new_pc & 0xf) / SLOT_MULTIPLIER; |
| 660 | ULONGEST psr_value; |
| 661 | |
| 662 | regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); |
| 663 | psr_value &= ~(3LL << 41); |
| 664 | psr_value |= (ULONGEST)(slot_num & 0x3) << 41; |
| 665 | |
| 666 | new_pc &= ~0xfLL; |
| 667 | |
| 668 | regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr_value); |
| 669 | regcache_cooked_write_unsigned (regcache, IA64_IP_REGNUM, new_pc); |
| 670 | } |
| 671 | |
| 672 | #define IS_NaT_COLLECTION_ADDR(addr) ((((addr) >> 3) & 0x3f) == 0x3f) |
| 673 | |
| 674 | /* Returns the address of the slot that's NSLOTS slots away from |
| 675 | the address ADDR. NSLOTS may be positive or negative. */ |
| 676 | static CORE_ADDR |
| 677 | rse_address_add(CORE_ADDR addr, int nslots) |
| 678 | { |
| 679 | CORE_ADDR new_addr; |
| 680 | int mandatory_nat_slots = nslots / 63; |
| 681 | int direction = nslots < 0 ? -1 : 1; |
| 682 | |
| 683 | new_addr = addr + 8 * (nslots + mandatory_nat_slots); |
| 684 | |
| 685 | if ((new_addr >> 9) != ((addr + 8 * 64 * mandatory_nat_slots) >> 9)) |
| 686 | new_addr += 8 * direction; |
| 687 | |
| 688 | if (IS_NaT_COLLECTION_ADDR(new_addr)) |
| 689 | new_addr += 8 * direction; |
| 690 | |
| 691 | return new_addr; |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | ia64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, |
| 696 | int regnum, gdb_byte *buf) |
| 697 | { |
| 698 | if (regnum >= V32_REGNUM && regnum <= V127_REGNUM) |
| 699 | { |
| 700 | #ifdef HAVE_LIBUNWIND_IA64_H |
| 701 | /* First try and use the libunwind special reg accessor, otherwise fallback to |
| 702 | standard logic. */ |
| 703 | if (!libunwind_is_initialized () |
| 704 | || libunwind_get_reg_special (gdbarch, regcache, regnum, buf) != 0) |
| 705 | #endif |
| 706 | { |
| 707 | /* The fallback position is to assume that r32-r127 are found sequentially |
| 708 | in memory starting at $bof. This isn't always true, but without libunwind, |
| 709 | this is the best we can do. */ |
| 710 | ULONGEST cfm; |
| 711 | ULONGEST bsp; |
| 712 | CORE_ADDR reg; |
| 713 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 714 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 715 | |
| 716 | /* The bsp points at the end of the register frame so we |
| 717 | subtract the size of frame from it to get start of register frame. */ |
| 718 | bsp = rse_address_add (bsp, -(cfm & 0x7f)); |
| 719 | |
| 720 | if ((cfm & 0x7f) > regnum - V32_REGNUM) |
| 721 | { |
| 722 | ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); |
| 723 | reg = read_memory_integer ((CORE_ADDR)reg_addr, 8); |
| 724 | store_unsigned_integer (buf, register_size (gdbarch, regnum), reg); |
| 725 | } |
| 726 | else |
| 727 | store_unsigned_integer (buf, register_size (gdbarch, regnum), 0); |
| 728 | } |
| 729 | } |
| 730 | else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) |
| 731 | { |
| 732 | ULONGEST unatN_val; |
| 733 | ULONGEST unat; |
| 734 | regcache_cooked_read_unsigned (regcache, IA64_UNAT_REGNUM, &unat); |
| 735 | unatN_val = (unat & (1LL << (regnum - IA64_NAT0_REGNUM))) != 0; |
| 736 | store_unsigned_integer (buf, register_size (gdbarch, regnum), unatN_val); |
| 737 | } |
| 738 | else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) |
| 739 | { |
| 740 | ULONGEST natN_val = 0; |
| 741 | ULONGEST bsp; |
| 742 | ULONGEST cfm; |
| 743 | CORE_ADDR gr_addr = 0; |
| 744 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 745 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 746 | |
| 747 | /* The bsp points at the end of the register frame so we |
| 748 | subtract the size of frame from it to get start of register frame. */ |
| 749 | bsp = rse_address_add (bsp, -(cfm & 0x7f)); |
| 750 | |
| 751 | if ((cfm & 0x7f) > regnum - V32_REGNUM) |
| 752 | gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); |
| 753 | |
| 754 | if (gr_addr != 0) |
| 755 | { |
| 756 | /* Compute address of nat collection bits. */ |
| 757 | CORE_ADDR nat_addr = gr_addr | 0x1f8; |
| 758 | CORE_ADDR nat_collection; |
| 759 | int nat_bit; |
| 760 | /* If our nat collection address is bigger than bsp, we have to get |
| 761 | the nat collection from rnat. Otherwise, we fetch the nat |
| 762 | collection from the computed address. */ |
| 763 | if (nat_addr >= bsp) |
| 764 | regcache_cooked_read_unsigned (regcache, IA64_RNAT_REGNUM, &nat_collection); |
| 765 | else |
| 766 | nat_collection = read_memory_integer (nat_addr, 8); |
| 767 | nat_bit = (gr_addr >> 3) & 0x3f; |
| 768 | natN_val = (nat_collection >> nat_bit) & 1; |
| 769 | } |
| 770 | |
| 771 | store_unsigned_integer (buf, register_size (gdbarch, regnum), natN_val); |
| 772 | } |
| 773 | else if (regnum == VBOF_REGNUM) |
| 774 | { |
| 775 | /* A virtual register frame start is provided for user convenience. |
| 776 | It can be calculated as the bsp - sof (sizeof frame). */ |
| 777 | ULONGEST bsp, vbsp; |
| 778 | ULONGEST cfm; |
| 779 | CORE_ADDR reg; |
| 780 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 781 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 782 | |
| 783 | /* The bsp points at the end of the register frame so we |
| 784 | subtract the size of frame from it to get beginning of frame. */ |
| 785 | vbsp = rse_address_add (bsp, -(cfm & 0x7f)); |
| 786 | store_unsigned_integer (buf, register_size (gdbarch, regnum), vbsp); |
| 787 | } |
| 788 | else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 789 | { |
| 790 | ULONGEST pr; |
| 791 | ULONGEST cfm; |
| 792 | ULONGEST prN_val; |
| 793 | CORE_ADDR reg; |
| 794 | regcache_cooked_read_unsigned (regcache, IA64_PR_REGNUM, &pr); |
| 795 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 796 | |
| 797 | if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 798 | { |
| 799 | /* Fetch predicate register rename base from current frame |
| 800 | marker for this frame. */ |
| 801 | int rrb_pr = (cfm >> 32) & 0x3f; |
| 802 | |
| 803 | /* Adjust the register number to account for register rotation. */ |
| 804 | regnum = VP16_REGNUM |
| 805 | + ((regnum - VP16_REGNUM) + rrb_pr) % 48; |
| 806 | } |
| 807 | prN_val = (pr & (1LL << (regnum - VP0_REGNUM))) != 0; |
| 808 | store_unsigned_integer (buf, register_size (gdbarch, regnum), prN_val); |
| 809 | } |
| 810 | else |
| 811 | memset (buf, 0, register_size (gdbarch, regnum)); |
| 812 | } |
| 813 | |
| 814 | static void |
| 815 | ia64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, |
| 816 | int regnum, const gdb_byte *buf) |
| 817 | { |
| 818 | if (regnum >= V32_REGNUM && regnum <= V127_REGNUM) |
| 819 | { |
| 820 | ULONGEST bsp; |
| 821 | ULONGEST cfm; |
| 822 | CORE_ADDR reg; |
| 823 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 824 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 825 | |
| 826 | bsp = rse_address_add (bsp, -(cfm & 0x7f)); |
| 827 | |
| 828 | if ((cfm & 0x7f) > regnum - V32_REGNUM) |
| 829 | { |
| 830 | ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); |
| 831 | write_memory (reg_addr, (void *)buf, 8); |
| 832 | } |
| 833 | } |
| 834 | else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) |
| 835 | { |
| 836 | ULONGEST unatN_val, unat, unatN_mask; |
| 837 | regcache_cooked_read_unsigned (regcache, IA64_UNAT_REGNUM, &unat); |
| 838 | unatN_val = extract_unsigned_integer (buf, register_size (gdbarch, regnum)); |
| 839 | unatN_mask = (1LL << (regnum - IA64_NAT0_REGNUM)); |
| 840 | if (unatN_val == 0) |
| 841 | unat &= ~unatN_mask; |
| 842 | else if (unatN_val == 1) |
| 843 | unat |= unatN_mask; |
| 844 | regcache_cooked_write_unsigned (regcache, IA64_UNAT_REGNUM, unat); |
| 845 | } |
| 846 | else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) |
| 847 | { |
| 848 | ULONGEST natN_val; |
| 849 | ULONGEST bsp; |
| 850 | ULONGEST cfm; |
| 851 | CORE_ADDR gr_addr = 0; |
| 852 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 853 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 854 | |
| 855 | /* The bsp points at the end of the register frame so we |
| 856 | subtract the size of frame from it to get start of register frame. */ |
| 857 | bsp = rse_address_add (bsp, -(cfm & 0x7f)); |
| 858 | |
| 859 | if ((cfm & 0x7f) > regnum - V32_REGNUM) |
| 860 | gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); |
| 861 | |
| 862 | natN_val = extract_unsigned_integer (buf, register_size (gdbarch, regnum)); |
| 863 | |
| 864 | if (gr_addr != 0 && (natN_val == 0 || natN_val == 1)) |
| 865 | { |
| 866 | /* Compute address of nat collection bits. */ |
| 867 | CORE_ADDR nat_addr = gr_addr | 0x1f8; |
| 868 | CORE_ADDR nat_collection; |
| 869 | int natN_bit = (gr_addr >> 3) & 0x3f; |
| 870 | ULONGEST natN_mask = (1LL << natN_bit); |
| 871 | /* If our nat collection address is bigger than bsp, we have to get |
| 872 | the nat collection from rnat. Otherwise, we fetch the nat |
| 873 | collection from the computed address. */ |
| 874 | if (nat_addr >= bsp) |
| 875 | { |
| 876 | regcache_cooked_read_unsigned (regcache, IA64_RNAT_REGNUM, &nat_collection); |
| 877 | if (natN_val) |
| 878 | nat_collection |= natN_mask; |
| 879 | else |
| 880 | nat_collection &= ~natN_mask; |
| 881 | regcache_cooked_write_unsigned (regcache, IA64_RNAT_REGNUM, nat_collection); |
| 882 | } |
| 883 | else |
| 884 | { |
| 885 | char nat_buf[8]; |
| 886 | nat_collection = read_memory_integer (nat_addr, 8); |
| 887 | if (natN_val) |
| 888 | nat_collection |= natN_mask; |
| 889 | else |
| 890 | nat_collection &= ~natN_mask; |
| 891 | store_unsigned_integer (nat_buf, register_size (gdbarch, regnum), nat_collection); |
| 892 | write_memory (nat_addr, nat_buf, 8); |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 897 | { |
| 898 | ULONGEST pr; |
| 899 | ULONGEST cfm; |
| 900 | ULONGEST prN_val; |
| 901 | ULONGEST prN_mask; |
| 902 | |
| 903 | regcache_cooked_read_unsigned (regcache, IA64_PR_REGNUM, &pr); |
| 904 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 905 | |
| 906 | if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 907 | { |
| 908 | /* Fetch predicate register rename base from current frame |
| 909 | marker for this frame. */ |
| 910 | int rrb_pr = (cfm >> 32) & 0x3f; |
| 911 | |
| 912 | /* Adjust the register number to account for register rotation. */ |
| 913 | regnum = VP16_REGNUM |
| 914 | + ((regnum - VP16_REGNUM) + rrb_pr) % 48; |
| 915 | } |
| 916 | prN_val = extract_unsigned_integer (buf, register_size (gdbarch, regnum)); |
| 917 | prN_mask = (1LL << (regnum - VP0_REGNUM)); |
| 918 | if (prN_val == 0) |
| 919 | pr &= ~prN_mask; |
| 920 | else if (prN_val == 1) |
| 921 | pr |= prN_mask; |
| 922 | regcache_cooked_write_unsigned (regcache, IA64_PR_REGNUM, pr); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /* The ia64 needs to convert between various ieee floating-point formats |
| 927 | and the special ia64 floating point register format. */ |
| 928 | |
| 929 | static int |
| 930 | ia64_convert_register_p (struct gdbarch *gdbarch, int regno, struct type *type) |
| 931 | { |
| 932 | return (regno >= IA64_FR0_REGNUM && regno <= IA64_FR127_REGNUM |
| 933 | && type != builtin_type_ia64_ext); |
| 934 | } |
| 935 | |
| 936 | static void |
| 937 | ia64_register_to_value (struct frame_info *frame, int regnum, |
| 938 | struct type *valtype, gdb_byte *out) |
| 939 | { |
| 940 | char in[MAX_REGISTER_SIZE]; |
| 941 | frame_register_read (frame, regnum, in); |
| 942 | convert_typed_floating (in, builtin_type_ia64_ext, out, valtype); |
| 943 | } |
| 944 | |
| 945 | static void |
| 946 | ia64_value_to_register (struct frame_info *frame, int regnum, |
| 947 | struct type *valtype, const gdb_byte *in) |
| 948 | { |
| 949 | char out[MAX_REGISTER_SIZE]; |
| 950 | convert_typed_floating (in, valtype, out, builtin_type_ia64_ext); |
| 951 | put_frame_register (frame, regnum, out); |
| 952 | } |
| 953 | |
| 954 | |
| 955 | /* Limit the number of skipped non-prologue instructions since examining |
| 956 | of the prologue is expensive. */ |
| 957 | static int max_skip_non_prologue_insns = 40; |
| 958 | |
| 959 | /* Given PC representing the starting address of a function, and |
| 960 | LIM_PC which is the (sloppy) limit to which to scan when looking |
| 961 | for a prologue, attempt to further refine this limit by using |
| 962 | the line data in the symbol table. If successful, a better guess |
| 963 | on where the prologue ends is returned, otherwise the previous |
| 964 | value of lim_pc is returned. TRUST_LIMIT is a pointer to a flag |
| 965 | which will be set to indicate whether the returned limit may be |
| 966 | used with no further scanning in the event that the function is |
| 967 | frameless. */ |
| 968 | |
| 969 | /* FIXME: cagney/2004-02-14: This function and logic have largely been |
| 970 | superseded by skip_prologue_using_sal. */ |
| 971 | |
| 972 | static CORE_ADDR |
| 973 | refine_prologue_limit (CORE_ADDR pc, CORE_ADDR lim_pc, int *trust_limit) |
| 974 | { |
| 975 | struct symtab_and_line prologue_sal; |
| 976 | CORE_ADDR start_pc = pc; |
| 977 | CORE_ADDR end_pc; |
| 978 | |
| 979 | /* The prologue can not possibly go past the function end itself, |
| 980 | so we can already adjust LIM_PC accordingly. */ |
| 981 | if (find_pc_partial_function (pc, NULL, NULL, &end_pc) && end_pc < lim_pc) |
| 982 | lim_pc = end_pc; |
| 983 | |
| 984 | /* Start off not trusting the limit. */ |
| 985 | *trust_limit = 0; |
| 986 | |
| 987 | prologue_sal = find_pc_line (pc, 0); |
| 988 | if (prologue_sal.line != 0) |
| 989 | { |
| 990 | int i; |
| 991 | CORE_ADDR addr = prologue_sal.end; |
| 992 | |
| 993 | /* Handle the case in which compiler's optimizer/scheduler |
| 994 | has moved instructions into the prologue. We scan ahead |
| 995 | in the function looking for address ranges whose corresponding |
| 996 | line number is less than or equal to the first one that we |
| 997 | found for the function. (It can be less than when the |
| 998 | scheduler puts a body instruction before the first prologue |
| 999 | instruction.) */ |
| 1000 | for (i = 2 * max_skip_non_prologue_insns; |
| 1001 | i > 0 && (lim_pc == 0 || addr < lim_pc); |
| 1002 | i--) |
| 1003 | { |
| 1004 | struct symtab_and_line sal; |
| 1005 | |
| 1006 | sal = find_pc_line (addr, 0); |
| 1007 | if (sal.line == 0) |
| 1008 | break; |
| 1009 | if (sal.line <= prologue_sal.line |
| 1010 | && sal.symtab == prologue_sal.symtab) |
| 1011 | { |
| 1012 | prologue_sal = sal; |
| 1013 | } |
| 1014 | addr = sal.end; |
| 1015 | } |
| 1016 | |
| 1017 | if (lim_pc == 0 || prologue_sal.end < lim_pc) |
| 1018 | { |
| 1019 | lim_pc = prologue_sal.end; |
| 1020 | if (start_pc == get_pc_function_start (lim_pc)) |
| 1021 | *trust_limit = 1; |
| 1022 | } |
| 1023 | } |
| 1024 | return lim_pc; |
| 1025 | } |
| 1026 | |
| 1027 | #define isScratch(_regnum_) ((_regnum_) == 2 || (_regnum_) == 3 \ |
| 1028 | || (8 <= (_regnum_) && (_regnum_) <= 11) \ |
| 1029 | || (14 <= (_regnum_) && (_regnum_) <= 31)) |
| 1030 | #define imm9(_instr_) \ |
| 1031 | ( ((((_instr_) & 0x01000000000LL) ? -1 : 0) << 8) \ |
| 1032 | | (((_instr_) & 0x00008000000LL) >> 20) \ |
| 1033 | | (((_instr_) & 0x00000001fc0LL) >> 6)) |
| 1034 | |
| 1035 | /* Allocate and initialize a frame cache. */ |
| 1036 | |
| 1037 | static struct ia64_frame_cache * |
| 1038 | ia64_alloc_frame_cache (void) |
| 1039 | { |
| 1040 | struct ia64_frame_cache *cache; |
| 1041 | int i; |
| 1042 | |
| 1043 | cache = FRAME_OBSTACK_ZALLOC (struct ia64_frame_cache); |
| 1044 | |
| 1045 | /* Base address. */ |
| 1046 | cache->base = 0; |
| 1047 | cache->pc = 0; |
| 1048 | cache->cfm = 0; |
| 1049 | cache->prev_cfm = 0; |
| 1050 | cache->sof = 0; |
| 1051 | cache->sol = 0; |
| 1052 | cache->sor = 0; |
| 1053 | cache->bsp = 0; |
| 1054 | cache->fp_reg = 0; |
| 1055 | cache->frameless = 1; |
| 1056 | |
| 1057 | for (i = 0; i < NUM_IA64_RAW_REGS; i++) |
| 1058 | cache->saved_regs[i] = 0; |
| 1059 | |
| 1060 | return cache; |
| 1061 | } |
| 1062 | |
| 1063 | static CORE_ADDR |
| 1064 | examine_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, |
| 1065 | struct frame_info *this_frame, |
| 1066 | struct ia64_frame_cache *cache) |
| 1067 | { |
| 1068 | CORE_ADDR next_pc; |
| 1069 | CORE_ADDR last_prologue_pc = pc; |
| 1070 | instruction_type it; |
| 1071 | long long instr; |
| 1072 | int cfm_reg = 0; |
| 1073 | int ret_reg = 0; |
| 1074 | int fp_reg = 0; |
| 1075 | int unat_save_reg = 0; |
| 1076 | int pr_save_reg = 0; |
| 1077 | int mem_stack_frame_size = 0; |
| 1078 | int spill_reg = 0; |
| 1079 | CORE_ADDR spill_addr = 0; |
| 1080 | char instores[8]; |
| 1081 | char infpstores[8]; |
| 1082 | char reg_contents[256]; |
| 1083 | int trust_limit; |
| 1084 | int frameless = 1; |
| 1085 | int i; |
| 1086 | CORE_ADDR addr; |
| 1087 | char buf[8]; |
| 1088 | CORE_ADDR bof, sor, sol, sof, cfm, rrb_gr; |
| 1089 | |
| 1090 | memset (instores, 0, sizeof instores); |
| 1091 | memset (infpstores, 0, sizeof infpstores); |
| 1092 | memset (reg_contents, 0, sizeof reg_contents); |
| 1093 | |
| 1094 | if (cache->after_prologue != 0 |
| 1095 | && cache->after_prologue <= lim_pc) |
| 1096 | return cache->after_prologue; |
| 1097 | |
| 1098 | lim_pc = refine_prologue_limit (pc, lim_pc, &trust_limit); |
| 1099 | next_pc = fetch_instruction (pc, &it, &instr); |
| 1100 | |
| 1101 | /* We want to check if we have a recognizable function start before we |
| 1102 | look ahead for a prologue. */ |
| 1103 | if (pc < lim_pc && next_pc |
| 1104 | && it == M && ((instr & 0x1ee0000003fLL) == 0x02c00000000LL)) |
| 1105 | { |
| 1106 | /* alloc - start of a regular function. */ |
| 1107 | int sor = (int) ((instr & 0x00078000000LL) >> 27); |
| 1108 | int sol = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1109 | int sof = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1110 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1111 | |
| 1112 | /* Verify that the current cfm matches what we think is the |
| 1113 | function start. If we have somehow jumped within a function, |
| 1114 | we do not want to interpret the prologue and calculate the |
| 1115 | addresses of various registers such as the return address. |
| 1116 | We will instead treat the frame as frameless. */ |
| 1117 | if (!this_frame || |
| 1118 | (sof == (cache->cfm & 0x7f) && |
| 1119 | sol == ((cache->cfm >> 7) & 0x7f))) |
| 1120 | frameless = 0; |
| 1121 | |
| 1122 | cfm_reg = rN; |
| 1123 | last_prologue_pc = next_pc; |
| 1124 | pc = next_pc; |
| 1125 | } |
| 1126 | else |
| 1127 | { |
| 1128 | /* Look for a leaf routine. */ |
| 1129 | if (pc < lim_pc && next_pc |
| 1130 | && (it == I || it == M) |
| 1131 | && ((instr & 0x1ee00000000LL) == 0x10800000000LL)) |
| 1132 | { |
| 1133 | /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */ |
| 1134 | int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13) |
| 1135 | | ((instr & 0x001f8000000LL) >> 20) |
| 1136 | | ((instr & 0x000000fe000LL) >> 13)); |
| 1137 | int rM = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1138 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1139 | int qp = (int) (instr & 0x0000000003fLL); |
| 1140 | if (qp == 0 && rN == 2 && imm == 0 && rM == 12 && fp_reg == 0) |
| 1141 | { |
| 1142 | /* mov r2, r12 - beginning of leaf routine */ |
| 1143 | fp_reg = rN; |
| 1144 | last_prologue_pc = next_pc; |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | /* If we don't recognize a regular function or leaf routine, we are |
| 1149 | done. */ |
| 1150 | if (!fp_reg) |
| 1151 | { |
| 1152 | pc = lim_pc; |
| 1153 | if (trust_limit) |
| 1154 | last_prologue_pc = lim_pc; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | /* Loop, looking for prologue instructions, keeping track of |
| 1159 | where preserved registers were spilled. */ |
| 1160 | while (pc < lim_pc) |
| 1161 | { |
| 1162 | next_pc = fetch_instruction (pc, &it, &instr); |
| 1163 | if (next_pc == 0) |
| 1164 | break; |
| 1165 | |
| 1166 | if (it == B && ((instr & 0x1e1f800003fLL) != 0x04000000000LL)) |
| 1167 | { |
| 1168 | /* Exit loop upon hitting a non-nop branch instruction. */ |
| 1169 | if (trust_limit) |
| 1170 | lim_pc = pc; |
| 1171 | break; |
| 1172 | } |
| 1173 | else if (((instr & 0x3fLL) != 0LL) && |
| 1174 | (frameless || ret_reg != 0)) |
| 1175 | { |
| 1176 | /* Exit loop upon hitting a predicated instruction if |
| 1177 | we already have the return register or if we are frameless. */ |
| 1178 | if (trust_limit) |
| 1179 | lim_pc = pc; |
| 1180 | break; |
| 1181 | } |
| 1182 | else if (it == I && ((instr & 0x1eff8000000LL) == 0x00188000000LL)) |
| 1183 | { |
| 1184 | /* Move from BR */ |
| 1185 | int b2 = (int) ((instr & 0x0000000e000LL) >> 13); |
| 1186 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1187 | int qp = (int) (instr & 0x0000000003f); |
| 1188 | |
| 1189 | if (qp == 0 && b2 == 0 && rN >= 32 && ret_reg == 0) |
| 1190 | { |
| 1191 | ret_reg = rN; |
| 1192 | last_prologue_pc = next_pc; |
| 1193 | } |
| 1194 | } |
| 1195 | else if ((it == I || it == M) |
| 1196 | && ((instr & 0x1ee00000000LL) == 0x10800000000LL)) |
| 1197 | { |
| 1198 | /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */ |
| 1199 | int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13) |
| 1200 | | ((instr & 0x001f8000000LL) >> 20) |
| 1201 | | ((instr & 0x000000fe000LL) >> 13)); |
| 1202 | int rM = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1203 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1204 | int qp = (int) (instr & 0x0000000003fLL); |
| 1205 | |
| 1206 | if (qp == 0 && rN >= 32 && imm == 0 && rM == 12 && fp_reg == 0) |
| 1207 | { |
| 1208 | /* mov rN, r12 */ |
| 1209 | fp_reg = rN; |
| 1210 | last_prologue_pc = next_pc; |
| 1211 | } |
| 1212 | else if (qp == 0 && rN == 12 && rM == 12) |
| 1213 | { |
| 1214 | /* adds r12, -mem_stack_frame_size, r12 */ |
| 1215 | mem_stack_frame_size -= imm; |
| 1216 | last_prologue_pc = next_pc; |
| 1217 | } |
| 1218 | else if (qp == 0 && rN == 2 |
| 1219 | && ((rM == fp_reg && fp_reg != 0) || rM == 12)) |
| 1220 | { |
| 1221 | char buf[MAX_REGISTER_SIZE]; |
| 1222 | CORE_ADDR saved_sp = 0; |
| 1223 | /* adds r2, spilloffset, rFramePointer |
| 1224 | or |
| 1225 | adds r2, spilloffset, r12 |
| 1226 | |
| 1227 | Get ready for stf.spill or st8.spill instructions. |
| 1228 | The address to start spilling at is loaded into r2. |
| 1229 | FIXME: Why r2? That's what gcc currently uses; it |
| 1230 | could well be different for other compilers. */ |
| 1231 | |
| 1232 | /* Hmm... whether or not this will work will depend on |
| 1233 | where the pc is. If it's still early in the prologue |
| 1234 | this'll be wrong. FIXME */ |
| 1235 | if (this_frame) |
| 1236 | { |
| 1237 | get_frame_register (this_frame, sp_regnum, buf); |
| 1238 | saved_sp = extract_unsigned_integer (buf, 8); |
| 1239 | } |
| 1240 | spill_addr = saved_sp |
| 1241 | + (rM == 12 ? 0 : mem_stack_frame_size) |
| 1242 | + imm; |
| 1243 | spill_reg = rN; |
| 1244 | last_prologue_pc = next_pc; |
| 1245 | } |
| 1246 | else if (qp == 0 && rM >= 32 && rM < 40 && !instores[rM-32] && |
| 1247 | rN < 256 && imm == 0) |
| 1248 | { |
| 1249 | /* mov rN, rM where rM is an input register */ |
| 1250 | reg_contents[rN] = rM; |
| 1251 | last_prologue_pc = next_pc; |
| 1252 | } |
| 1253 | else if (frameless && qp == 0 && rN == fp_reg && imm == 0 && |
| 1254 | rM == 2) |
| 1255 | { |
| 1256 | /* mov r12, r2 */ |
| 1257 | last_prologue_pc = next_pc; |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | else if (it == M |
| 1262 | && ( ((instr & 0x1efc0000000LL) == 0x0eec0000000LL) |
| 1263 | || ((instr & 0x1ffc8000000LL) == 0x0cec0000000LL) )) |
| 1264 | { |
| 1265 | /* stf.spill [rN] = fM, imm9 |
| 1266 | or |
| 1267 | stf.spill [rN] = fM */ |
| 1268 | |
| 1269 | int imm = imm9(instr); |
| 1270 | int rN = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1271 | int fM = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1272 | int qp = (int) (instr & 0x0000000003fLL); |
| 1273 | if (qp == 0 && rN == spill_reg && spill_addr != 0 |
| 1274 | && ((2 <= fM && fM <= 5) || (16 <= fM && fM <= 31))) |
| 1275 | { |
| 1276 | cache->saved_regs[IA64_FR0_REGNUM + fM] = spill_addr; |
| 1277 | |
| 1278 | if ((instr & 0x1efc0000000LL) == 0x0eec0000000LL) |
| 1279 | spill_addr += imm; |
| 1280 | else |
| 1281 | spill_addr = 0; /* last one; must be done */ |
| 1282 | last_prologue_pc = next_pc; |
| 1283 | } |
| 1284 | } |
| 1285 | else if ((it == M && ((instr & 0x1eff8000000LL) == 0x02110000000LL)) |
| 1286 | || (it == I && ((instr & 0x1eff8000000LL) == 0x00050000000LL)) ) |
| 1287 | { |
| 1288 | /* mov.m rN = arM |
| 1289 | or |
| 1290 | mov.i rN = arM */ |
| 1291 | |
| 1292 | int arM = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1293 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1294 | int qp = (int) (instr & 0x0000000003fLL); |
| 1295 | if (qp == 0 && isScratch (rN) && arM == 36 /* ar.unat */) |
| 1296 | { |
| 1297 | /* We have something like "mov.m r3 = ar.unat". Remember the |
| 1298 | r3 (or whatever) and watch for a store of this register... */ |
| 1299 | unat_save_reg = rN; |
| 1300 | last_prologue_pc = next_pc; |
| 1301 | } |
| 1302 | } |
| 1303 | else if (it == I && ((instr & 0x1eff8000000LL) == 0x00198000000LL)) |
| 1304 | { |
| 1305 | /* mov rN = pr */ |
| 1306 | int rN = (int) ((instr & 0x00000001fc0LL) >> 6); |
| 1307 | int qp = (int) (instr & 0x0000000003fLL); |
| 1308 | if (qp == 0 && isScratch (rN)) |
| 1309 | { |
| 1310 | pr_save_reg = rN; |
| 1311 | last_prologue_pc = next_pc; |
| 1312 | } |
| 1313 | } |
| 1314 | else if (it == M |
| 1315 | && ( ((instr & 0x1ffc8000000LL) == 0x08cc0000000LL) |
| 1316 | || ((instr & 0x1efc0000000LL) == 0x0acc0000000LL))) |
| 1317 | { |
| 1318 | /* st8 [rN] = rM |
| 1319 | or |
| 1320 | st8 [rN] = rM, imm9 */ |
| 1321 | int rN = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1322 | int rM = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1323 | int qp = (int) (instr & 0x0000000003fLL); |
| 1324 | int indirect = rM < 256 ? reg_contents[rM] : 0; |
| 1325 | if (qp == 0 && rN == spill_reg && spill_addr != 0 |
| 1326 | && (rM == unat_save_reg || rM == pr_save_reg)) |
| 1327 | { |
| 1328 | /* We've found a spill of either the UNAT register or the PR |
| 1329 | register. (Well, not exactly; what we've actually found is |
| 1330 | a spill of the register that UNAT or PR was moved to). |
| 1331 | Record that fact and move on... */ |
| 1332 | if (rM == unat_save_reg) |
| 1333 | { |
| 1334 | /* Track UNAT register */ |
| 1335 | cache->saved_regs[IA64_UNAT_REGNUM] = spill_addr; |
| 1336 | unat_save_reg = 0; |
| 1337 | } |
| 1338 | else |
| 1339 | { |
| 1340 | /* Track PR register */ |
| 1341 | cache->saved_regs[IA64_PR_REGNUM] = spill_addr; |
| 1342 | pr_save_reg = 0; |
| 1343 | } |
| 1344 | if ((instr & 0x1efc0000000LL) == 0x0acc0000000LL) |
| 1345 | /* st8 [rN] = rM, imm9 */ |
| 1346 | spill_addr += imm9(instr); |
| 1347 | else |
| 1348 | spill_addr = 0; /* must be done spilling */ |
| 1349 | last_prologue_pc = next_pc; |
| 1350 | } |
| 1351 | else if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32]) |
| 1352 | { |
| 1353 | /* Allow up to one store of each input register. */ |
| 1354 | instores[rM-32] = 1; |
| 1355 | last_prologue_pc = next_pc; |
| 1356 | } |
| 1357 | else if (qp == 0 && 32 <= indirect && indirect < 40 && |
| 1358 | !instores[indirect-32]) |
| 1359 | { |
| 1360 | /* Allow an indirect store of an input register. */ |
| 1361 | instores[indirect-32] = 1; |
| 1362 | last_prologue_pc = next_pc; |
| 1363 | } |
| 1364 | } |
| 1365 | else if (it == M && ((instr & 0x1ff08000000LL) == 0x08c00000000LL)) |
| 1366 | { |
| 1367 | /* One of |
| 1368 | st1 [rN] = rM |
| 1369 | st2 [rN] = rM |
| 1370 | st4 [rN] = rM |
| 1371 | st8 [rN] = rM |
| 1372 | Note that the st8 case is handled in the clause above. |
| 1373 | |
| 1374 | Advance over stores of input registers. One store per input |
| 1375 | register is permitted. */ |
| 1376 | int rM = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1377 | int qp = (int) (instr & 0x0000000003fLL); |
| 1378 | int indirect = rM < 256 ? reg_contents[rM] : 0; |
| 1379 | if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32]) |
| 1380 | { |
| 1381 | instores[rM-32] = 1; |
| 1382 | last_prologue_pc = next_pc; |
| 1383 | } |
| 1384 | else if (qp == 0 && 32 <= indirect && indirect < 40 && |
| 1385 | !instores[indirect-32]) |
| 1386 | { |
| 1387 | /* Allow an indirect store of an input register. */ |
| 1388 | instores[indirect-32] = 1; |
| 1389 | last_prologue_pc = next_pc; |
| 1390 | } |
| 1391 | } |
| 1392 | else if (it == M && ((instr & 0x1ff88000000LL) == 0x0cc80000000LL)) |
| 1393 | { |
| 1394 | /* Either |
| 1395 | stfs [rN] = fM |
| 1396 | or |
| 1397 | stfd [rN] = fM |
| 1398 | |
| 1399 | Advance over stores of floating point input registers. Again |
| 1400 | one store per register is permitted */ |
| 1401 | int fM = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1402 | int qp = (int) (instr & 0x0000000003fLL); |
| 1403 | if (qp == 0 && 8 <= fM && fM < 16 && !infpstores[fM - 8]) |
| 1404 | { |
| 1405 | infpstores[fM-8] = 1; |
| 1406 | last_prologue_pc = next_pc; |
| 1407 | } |
| 1408 | } |
| 1409 | else if (it == M |
| 1410 | && ( ((instr & 0x1ffc8000000LL) == 0x08ec0000000LL) |
| 1411 | || ((instr & 0x1efc0000000LL) == 0x0aec0000000LL))) |
| 1412 | { |
| 1413 | /* st8.spill [rN] = rM |
| 1414 | or |
| 1415 | st8.spill [rN] = rM, imm9 */ |
| 1416 | int rN = (int) ((instr & 0x00007f00000LL) >> 20); |
| 1417 | int rM = (int) ((instr & 0x000000fe000LL) >> 13); |
| 1418 | int qp = (int) (instr & 0x0000000003fLL); |
| 1419 | if (qp == 0 && rN == spill_reg && 4 <= rM && rM <= 7) |
| 1420 | { |
| 1421 | /* We've found a spill of one of the preserved general purpose |
| 1422 | regs. Record the spill address and advance the spill |
| 1423 | register if appropriate. */ |
| 1424 | cache->saved_regs[IA64_GR0_REGNUM + rM] = spill_addr; |
| 1425 | if ((instr & 0x1efc0000000LL) == 0x0aec0000000LL) |
| 1426 | /* st8.spill [rN] = rM, imm9 */ |
| 1427 | spill_addr += imm9(instr); |
| 1428 | else |
| 1429 | spill_addr = 0; /* Done spilling */ |
| 1430 | last_prologue_pc = next_pc; |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | pc = next_pc; |
| 1435 | } |
| 1436 | |
| 1437 | /* If not frameless and we aren't called by skip_prologue, then we need |
| 1438 | to calculate registers for the previous frame which will be needed |
| 1439 | later. */ |
| 1440 | |
| 1441 | if (!frameless && this_frame) |
| 1442 | { |
| 1443 | /* Extract the size of the rotating portion of the stack |
| 1444 | frame and the register rename base from the current |
| 1445 | frame marker. */ |
| 1446 | cfm = cache->cfm; |
| 1447 | sor = cache->sor; |
| 1448 | sof = cache->sof; |
| 1449 | sol = cache->sol; |
| 1450 | rrb_gr = (cfm >> 18) & 0x7f; |
| 1451 | |
| 1452 | /* Find the bof (beginning of frame). */ |
| 1453 | bof = rse_address_add (cache->bsp, -sof); |
| 1454 | |
| 1455 | for (i = 0, addr = bof; |
| 1456 | i < sof; |
| 1457 | i++, addr += 8) |
| 1458 | { |
| 1459 | if (IS_NaT_COLLECTION_ADDR (addr)) |
| 1460 | { |
| 1461 | addr += 8; |
| 1462 | } |
| 1463 | if (i+32 == cfm_reg) |
| 1464 | cache->saved_regs[IA64_CFM_REGNUM] = addr; |
| 1465 | if (i+32 == ret_reg) |
| 1466 | cache->saved_regs[IA64_VRAP_REGNUM] = addr; |
| 1467 | if (i+32 == fp_reg) |
| 1468 | cache->saved_regs[IA64_VFP_REGNUM] = addr; |
| 1469 | } |
| 1470 | |
| 1471 | /* For the previous argument registers we require the previous bof. |
| 1472 | If we can't find the previous cfm, then we can do nothing. */ |
| 1473 | cfm = 0; |
| 1474 | if (cache->saved_regs[IA64_CFM_REGNUM] != 0) |
| 1475 | { |
| 1476 | cfm = read_memory_integer (cache->saved_regs[IA64_CFM_REGNUM], 8); |
| 1477 | } |
| 1478 | else if (cfm_reg != 0) |
| 1479 | { |
| 1480 | get_frame_register (this_frame, cfm_reg, buf); |
| 1481 | cfm = extract_unsigned_integer (buf, 8); |
| 1482 | } |
| 1483 | cache->prev_cfm = cfm; |
| 1484 | |
| 1485 | if (cfm != 0) |
| 1486 | { |
| 1487 | sor = ((cfm >> 14) & 0xf) * 8; |
| 1488 | sof = (cfm & 0x7f); |
| 1489 | sol = (cfm >> 7) & 0x7f; |
| 1490 | rrb_gr = (cfm >> 18) & 0x7f; |
| 1491 | |
| 1492 | /* The previous bof only requires subtraction of the sol (size of |
| 1493 | locals) due to the overlap between output and input of |
| 1494 | subsequent frames. */ |
| 1495 | bof = rse_address_add (bof, -sol); |
| 1496 | |
| 1497 | for (i = 0, addr = bof; |
| 1498 | i < sof; |
| 1499 | i++, addr += 8) |
| 1500 | { |
| 1501 | if (IS_NaT_COLLECTION_ADDR (addr)) |
| 1502 | { |
| 1503 | addr += 8; |
| 1504 | } |
| 1505 | if (i < sor) |
| 1506 | cache->saved_regs[IA64_GR32_REGNUM + ((i + (sor - rrb_gr)) % sor)] |
| 1507 | = addr; |
| 1508 | else |
| 1509 | cache->saved_regs[IA64_GR32_REGNUM + i] = addr; |
| 1510 | } |
| 1511 | |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | /* Try and trust the lim_pc value whenever possible. */ |
| 1516 | if (trust_limit && lim_pc >= last_prologue_pc) |
| 1517 | last_prologue_pc = lim_pc; |
| 1518 | |
| 1519 | cache->frameless = frameless; |
| 1520 | cache->after_prologue = last_prologue_pc; |
| 1521 | cache->mem_stack_frame_size = mem_stack_frame_size; |
| 1522 | cache->fp_reg = fp_reg; |
| 1523 | |
| 1524 | return last_prologue_pc; |
| 1525 | } |
| 1526 | |
| 1527 | CORE_ADDR |
| 1528 | ia64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 1529 | { |
| 1530 | struct ia64_frame_cache cache; |
| 1531 | cache.base = 0; |
| 1532 | cache.after_prologue = 0; |
| 1533 | cache.cfm = 0; |
| 1534 | cache.bsp = 0; |
| 1535 | |
| 1536 | /* Call examine_prologue with - as third argument since we don't have a next frame pointer to send. */ |
| 1537 | return examine_prologue (pc, pc+1024, 0, &cache); |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | /* Normal frames. */ |
| 1542 | |
| 1543 | static struct ia64_frame_cache * |
| 1544 | ia64_frame_cache (struct frame_info *this_frame, void **this_cache) |
| 1545 | { |
| 1546 | struct ia64_frame_cache *cache; |
| 1547 | char buf[8]; |
| 1548 | CORE_ADDR cfm, sof, sol, bsp, psr; |
| 1549 | int i; |
| 1550 | |
| 1551 | if (*this_cache) |
| 1552 | return *this_cache; |
| 1553 | |
| 1554 | cache = ia64_alloc_frame_cache (); |
| 1555 | *this_cache = cache; |
| 1556 | |
| 1557 | get_frame_register (this_frame, sp_regnum, buf); |
| 1558 | cache->saved_sp = extract_unsigned_integer (buf, 8); |
| 1559 | |
| 1560 | /* We always want the bsp to point to the end of frame. |
| 1561 | This way, we can always get the beginning of frame (bof) |
| 1562 | by subtracting frame size. */ |
| 1563 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 1564 | cache->bsp = extract_unsigned_integer (buf, 8); |
| 1565 | |
| 1566 | get_frame_register (this_frame, IA64_PSR_REGNUM, buf); |
| 1567 | psr = extract_unsigned_integer (buf, 8); |
| 1568 | |
| 1569 | get_frame_register (this_frame, IA64_CFM_REGNUM, buf); |
| 1570 | cfm = extract_unsigned_integer (buf, 8); |
| 1571 | |
| 1572 | cache->sof = (cfm & 0x7f); |
| 1573 | cache->sol = (cfm >> 7) & 0x7f; |
| 1574 | cache->sor = ((cfm >> 14) & 0xf) * 8; |
| 1575 | |
| 1576 | cache->cfm = cfm; |
| 1577 | |
| 1578 | cache->pc = get_frame_func (this_frame); |
| 1579 | |
| 1580 | if (cache->pc != 0) |
| 1581 | examine_prologue (cache->pc, get_frame_pc (this_frame), this_frame, cache); |
| 1582 | |
| 1583 | cache->base = cache->saved_sp + cache->mem_stack_frame_size; |
| 1584 | |
| 1585 | return cache; |
| 1586 | } |
| 1587 | |
| 1588 | static void |
| 1589 | ia64_frame_this_id (struct frame_info *this_frame, void **this_cache, |
| 1590 | struct frame_id *this_id) |
| 1591 | { |
| 1592 | struct ia64_frame_cache *cache = |
| 1593 | ia64_frame_cache (this_frame, this_cache); |
| 1594 | |
| 1595 | /* If outermost frame, mark with null frame id. */ |
| 1596 | if (cache->base == 0) |
| 1597 | (*this_id) = null_frame_id; |
| 1598 | else |
| 1599 | (*this_id) = frame_id_build_special (cache->base, cache->pc, cache->bsp); |
| 1600 | if (gdbarch_debug >= 1) |
| 1601 | fprintf_unfiltered (gdb_stdlog, |
| 1602 | "regular frame id: code 0x%s, stack 0x%s, special 0x%s, this_frame %p\n", |
| 1603 | paddr_nz (this_id->code_addr), |
| 1604 | paddr_nz (this_id->stack_addr), |
| 1605 | paddr_nz (cache->bsp), this_frame); |
| 1606 | } |
| 1607 | |
| 1608 | static struct value * |
| 1609 | ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache, |
| 1610 | int regnum) |
| 1611 | { |
| 1612 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1613 | struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache); |
| 1614 | char buf[8]; |
| 1615 | |
| 1616 | gdb_assert (regnum >= 0); |
| 1617 | |
| 1618 | if (!target_has_registers) |
| 1619 | error (_("No registers.")); |
| 1620 | |
| 1621 | if (regnum == gdbarch_sp_regnum (gdbarch)) |
| 1622 | return frame_unwind_got_constant (this_frame, regnum, cache->base); |
| 1623 | |
| 1624 | else if (regnum == IA64_BSP_REGNUM) |
| 1625 | { |
| 1626 | struct value *val; |
| 1627 | CORE_ADDR prev_cfm, bsp, prev_bsp; |
| 1628 | |
| 1629 | /* We want to calculate the previous bsp as the end of the previous |
| 1630 | register stack frame. This corresponds to what the hardware bsp |
| 1631 | register will be if we pop the frame back which is why we might |
| 1632 | have been called. We know the beginning of the current frame is |
| 1633 | cache->bsp - cache->sof. This value in the previous frame points |
| 1634 | to the start of the output registers. We can calculate the end of |
| 1635 | that frame by adding the size of output: |
| 1636 | (sof (size of frame) - sol (size of locals)). */ |
| 1637 | val = ia64_frame_prev_register (this_frame, this_cache, IA64_CFM_REGNUM); |
| 1638 | prev_cfm = extract_unsigned_integer (value_contents_all (val), 8); |
| 1639 | bsp = rse_address_add (cache->bsp, -(cache->sof)); |
| 1640 | prev_bsp = |
| 1641 | rse_address_add (bsp, (prev_cfm & 0x7f) - ((prev_cfm >> 7) & 0x7f)); |
| 1642 | |
| 1643 | return frame_unwind_got_constant (this_frame, regnum, prev_bsp); |
| 1644 | } |
| 1645 | |
| 1646 | else if (regnum == IA64_CFM_REGNUM) |
| 1647 | { |
| 1648 | CORE_ADDR addr = cache->saved_regs[IA64_CFM_REGNUM]; |
| 1649 | |
| 1650 | if (addr != 0) |
| 1651 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 1652 | |
| 1653 | if (cache->prev_cfm) |
| 1654 | return frame_unwind_got_constant (this_frame, regnum, cache->prev_cfm); |
| 1655 | |
| 1656 | if (cache->frameless) |
| 1657 | return frame_unwind_got_register (this_frame, IA64_PFS_REGNUM, |
| 1658 | IA64_PFS_REGNUM); |
| 1659 | return frame_unwind_got_register (this_frame, regnum, 0); |
| 1660 | } |
| 1661 | |
| 1662 | else if (regnum == IA64_VFP_REGNUM) |
| 1663 | { |
| 1664 | /* If the function in question uses an automatic register (r32-r127) |
| 1665 | for the frame pointer, it'll be found by ia64_find_saved_register() |
| 1666 | above. If the function lacks one of these frame pointers, we can |
| 1667 | still provide a value since we know the size of the frame. */ |
| 1668 | return frame_unwind_got_constant (this_frame, regnum, cache->base); |
| 1669 | } |
| 1670 | |
| 1671 | else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 1672 | { |
| 1673 | struct value *pr_val; |
| 1674 | ULONGEST prN; |
| 1675 | |
| 1676 | pr_val = ia64_frame_prev_register (this_frame, this_cache, |
| 1677 | IA64_PR_REGNUM); |
| 1678 | if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 1679 | { |
| 1680 | /* Fetch predicate register rename base from current frame |
| 1681 | marker for this frame. */ |
| 1682 | int rrb_pr = (cache->cfm >> 32) & 0x3f; |
| 1683 | |
| 1684 | /* Adjust the register number to account for register rotation. */ |
| 1685 | regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48; |
| 1686 | } |
| 1687 | prN = extract_bit_field (value_contents_all (pr_val), |
| 1688 | regnum - VP0_REGNUM, 1); |
| 1689 | return frame_unwind_got_constant (this_frame, regnum, prN); |
| 1690 | } |
| 1691 | |
| 1692 | else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) |
| 1693 | { |
| 1694 | struct value *unat_val; |
| 1695 | ULONGEST unatN; |
| 1696 | unat_val = ia64_frame_prev_register (this_frame, this_cache, |
| 1697 | IA64_UNAT_REGNUM); |
| 1698 | unatN = extract_bit_field (value_contents_all (unat_val), |
| 1699 | regnum - IA64_NAT0_REGNUM, 1); |
| 1700 | return frame_unwind_got_constant (this_frame, regnum, unatN); |
| 1701 | } |
| 1702 | |
| 1703 | else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) |
| 1704 | { |
| 1705 | int natval = 0; |
| 1706 | /* Find address of general register corresponding to nat bit we're |
| 1707 | interested in. */ |
| 1708 | CORE_ADDR gr_addr; |
| 1709 | |
| 1710 | gr_addr = cache->saved_regs[regnum - IA64_NAT0_REGNUM + IA64_GR0_REGNUM]; |
| 1711 | |
| 1712 | if (gr_addr != 0) |
| 1713 | { |
| 1714 | /* Compute address of nat collection bits. */ |
| 1715 | CORE_ADDR nat_addr = gr_addr | 0x1f8; |
| 1716 | CORE_ADDR bsp; |
| 1717 | CORE_ADDR nat_collection; |
| 1718 | int nat_bit; |
| 1719 | |
| 1720 | /* If our nat collection address is bigger than bsp, we have to get |
| 1721 | the nat collection from rnat. Otherwise, we fetch the nat |
| 1722 | collection from the computed address. */ |
| 1723 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 1724 | bsp = extract_unsigned_integer (buf, 8); |
| 1725 | if (nat_addr >= bsp) |
| 1726 | { |
| 1727 | get_frame_register (this_frame, IA64_RNAT_REGNUM, buf); |
| 1728 | nat_collection = extract_unsigned_integer (buf, 8); |
| 1729 | } |
| 1730 | else |
| 1731 | nat_collection = read_memory_integer (nat_addr, 8); |
| 1732 | nat_bit = (gr_addr >> 3) & 0x3f; |
| 1733 | natval = (nat_collection >> nat_bit) & 1; |
| 1734 | } |
| 1735 | |
| 1736 | return frame_unwind_got_constant (this_frame, regnum, natval); |
| 1737 | } |
| 1738 | |
| 1739 | else if (regnum == IA64_IP_REGNUM) |
| 1740 | { |
| 1741 | CORE_ADDR pc = 0; |
| 1742 | CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; |
| 1743 | |
| 1744 | if (addr != 0) |
| 1745 | { |
| 1746 | read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); |
| 1747 | pc = extract_unsigned_integer (buf, 8); |
| 1748 | } |
| 1749 | else if (cache->frameless) |
| 1750 | { |
| 1751 | get_frame_register (this_frame, IA64_BR0_REGNUM, buf); |
| 1752 | pc = extract_unsigned_integer (buf, 8); |
| 1753 | } |
| 1754 | pc &= ~0xf; |
| 1755 | return frame_unwind_got_constant (this_frame, regnum, pc); |
| 1756 | } |
| 1757 | |
| 1758 | else if (regnum == IA64_PSR_REGNUM) |
| 1759 | { |
| 1760 | /* We don't know how to get the complete previous PSR, but we need it |
| 1761 | for the slot information when we unwind the pc (pc is formed of IP |
| 1762 | register plus slot information from PSR). To get the previous |
| 1763 | slot information, we mask it off the return address. */ |
| 1764 | ULONGEST slot_num = 0; |
| 1765 | CORE_ADDR pc = 0; |
| 1766 | CORE_ADDR psr = 0; |
| 1767 | CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; |
| 1768 | |
| 1769 | get_frame_register (this_frame, IA64_PSR_REGNUM, buf); |
| 1770 | psr = extract_unsigned_integer (buf, 8); |
| 1771 | |
| 1772 | if (addr != 0) |
| 1773 | { |
| 1774 | read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); |
| 1775 | pc = extract_unsigned_integer (buf, 8); |
| 1776 | } |
| 1777 | else if (cache->frameless) |
| 1778 | { |
| 1779 | get_frame_register (this_frame, IA64_BR0_REGNUM, buf); |
| 1780 | pc = extract_unsigned_integer (buf, 8); |
| 1781 | } |
| 1782 | psr &= ~(3LL << 41); |
| 1783 | slot_num = pc & 0x3LL; |
| 1784 | psr |= (CORE_ADDR)slot_num << 41; |
| 1785 | return frame_unwind_got_constant (this_frame, regnum, psr); |
| 1786 | } |
| 1787 | |
| 1788 | else if (regnum == IA64_BR0_REGNUM) |
| 1789 | { |
| 1790 | CORE_ADDR addr = cache->saved_regs[IA64_BR0_REGNUM]; |
| 1791 | |
| 1792 | if (addr != 0) |
| 1793 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 1794 | |
| 1795 | return frame_unwind_got_constant (this_frame, regnum, 0); |
| 1796 | } |
| 1797 | |
| 1798 | else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM) |
| 1799 | || (regnum >= V32_REGNUM && regnum <= V127_REGNUM)) |
| 1800 | { |
| 1801 | CORE_ADDR addr = 0; |
| 1802 | |
| 1803 | if (regnum >= V32_REGNUM) |
| 1804 | regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); |
| 1805 | addr = cache->saved_regs[regnum]; |
| 1806 | if (addr != 0) |
| 1807 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 1808 | |
| 1809 | if (cache->frameless) |
| 1810 | { |
| 1811 | struct value *reg_val; |
| 1812 | CORE_ADDR prev_cfm, prev_bsp, prev_bof; |
| 1813 | |
| 1814 | /* FIXME: brobecker/2008-05-01: Doesn't this seem redundant |
| 1815 | with the same code above? */ |
| 1816 | if (regnum >= V32_REGNUM) |
| 1817 | regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); |
| 1818 | reg_val = ia64_frame_prev_register (this_frame, this_cache, |
| 1819 | IA64_CFM_REGNUM); |
| 1820 | prev_cfm = extract_unsigned_integer (value_contents_all (reg_val), |
| 1821 | 8); |
| 1822 | reg_val = ia64_frame_prev_register (this_frame, this_cache, |
| 1823 | IA64_BSP_REGNUM); |
| 1824 | prev_bsp = extract_unsigned_integer (value_contents_all (reg_val), |
| 1825 | 8); |
| 1826 | prev_bof = rse_address_add (prev_bsp, -(prev_cfm & 0x7f)); |
| 1827 | |
| 1828 | addr = rse_address_add (prev_bof, (regnum - IA64_GR32_REGNUM)); |
| 1829 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 1830 | } |
| 1831 | |
| 1832 | return frame_unwind_got_constant (this_frame, regnum, 0); |
| 1833 | } |
| 1834 | |
| 1835 | else /* All other registers. */ |
| 1836 | { |
| 1837 | CORE_ADDR addr = 0; |
| 1838 | |
| 1839 | if (IA64_FR32_REGNUM <= regnum && regnum <= IA64_FR127_REGNUM) |
| 1840 | { |
| 1841 | /* Fetch floating point register rename base from current |
| 1842 | frame marker for this frame. */ |
| 1843 | int rrb_fr = (cache->cfm >> 25) & 0x7f; |
| 1844 | |
| 1845 | /* Adjust the floating point register number to account for |
| 1846 | register rotation. */ |
| 1847 | regnum = IA64_FR32_REGNUM |
| 1848 | + ((regnum - IA64_FR32_REGNUM) + rrb_fr) % 96; |
| 1849 | } |
| 1850 | |
| 1851 | /* If we have stored a memory address, access the register. */ |
| 1852 | addr = cache->saved_regs[regnum]; |
| 1853 | if (addr != 0) |
| 1854 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 1855 | /* Otherwise, punt and get the current value of the register. */ |
| 1856 | else |
| 1857 | return frame_unwind_got_register (this_frame, regnum, regnum); |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | static const struct frame_unwind ia64_frame_unwind = |
| 1862 | { |
| 1863 | NORMAL_FRAME, |
| 1864 | &ia64_frame_this_id, |
| 1865 | &ia64_frame_prev_register, |
| 1866 | NULL, |
| 1867 | default_frame_sniffer |
| 1868 | }; |
| 1869 | |
| 1870 | /* Signal trampolines. */ |
| 1871 | |
| 1872 | static void |
| 1873 | ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame, |
| 1874 | struct ia64_frame_cache *cache) |
| 1875 | { |
| 1876 | struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame)); |
| 1877 | |
| 1878 | if (tdep->sigcontext_register_address) |
| 1879 | { |
| 1880 | int regno; |
| 1881 | |
| 1882 | cache->saved_regs[IA64_VRAP_REGNUM] = |
| 1883 | tdep->sigcontext_register_address (cache->base, IA64_IP_REGNUM); |
| 1884 | cache->saved_regs[IA64_CFM_REGNUM] = |
| 1885 | tdep->sigcontext_register_address (cache->base, IA64_CFM_REGNUM); |
| 1886 | cache->saved_regs[IA64_PSR_REGNUM] = |
| 1887 | tdep->sigcontext_register_address (cache->base, IA64_PSR_REGNUM); |
| 1888 | cache->saved_regs[IA64_BSP_REGNUM] = |
| 1889 | tdep->sigcontext_register_address (cache->base, IA64_BSP_REGNUM); |
| 1890 | cache->saved_regs[IA64_RNAT_REGNUM] = |
| 1891 | tdep->sigcontext_register_address (cache->base, IA64_RNAT_REGNUM); |
| 1892 | cache->saved_regs[IA64_CCV_REGNUM] = |
| 1893 | tdep->sigcontext_register_address (cache->base, IA64_CCV_REGNUM); |
| 1894 | cache->saved_regs[IA64_UNAT_REGNUM] = |
| 1895 | tdep->sigcontext_register_address (cache->base, IA64_UNAT_REGNUM); |
| 1896 | cache->saved_regs[IA64_FPSR_REGNUM] = |
| 1897 | tdep->sigcontext_register_address (cache->base, IA64_FPSR_REGNUM); |
| 1898 | cache->saved_regs[IA64_PFS_REGNUM] = |
| 1899 | tdep->sigcontext_register_address (cache->base, IA64_PFS_REGNUM); |
| 1900 | cache->saved_regs[IA64_LC_REGNUM] = |
| 1901 | tdep->sigcontext_register_address (cache->base, IA64_LC_REGNUM); |
| 1902 | for (regno = IA64_GR1_REGNUM; regno <= IA64_GR31_REGNUM; regno++) |
| 1903 | cache->saved_regs[regno] = |
| 1904 | tdep->sigcontext_register_address (cache->base, regno); |
| 1905 | for (regno = IA64_BR0_REGNUM; regno <= IA64_BR7_REGNUM; regno++) |
| 1906 | cache->saved_regs[regno] = |
| 1907 | tdep->sigcontext_register_address (cache->base, regno); |
| 1908 | for (regno = IA64_FR2_REGNUM; regno <= IA64_FR31_REGNUM; regno++) |
| 1909 | cache->saved_regs[regno] = |
| 1910 | tdep->sigcontext_register_address (cache->base, regno); |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | static struct ia64_frame_cache * |
| 1915 | ia64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache) |
| 1916 | { |
| 1917 | struct ia64_frame_cache *cache; |
| 1918 | CORE_ADDR addr; |
| 1919 | char buf[8]; |
| 1920 | int i; |
| 1921 | |
| 1922 | if (*this_cache) |
| 1923 | return *this_cache; |
| 1924 | |
| 1925 | cache = ia64_alloc_frame_cache (); |
| 1926 | |
| 1927 | get_frame_register (this_frame, sp_regnum, buf); |
| 1928 | /* Note that frame size is hard-coded below. We cannot calculate it |
| 1929 | via prologue examination. */ |
| 1930 | cache->base = extract_unsigned_integer (buf, 8) + 16; |
| 1931 | |
| 1932 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 1933 | cache->bsp = extract_unsigned_integer (buf, 8); |
| 1934 | |
| 1935 | get_frame_register (this_frame, IA64_CFM_REGNUM, buf); |
| 1936 | cache->cfm = extract_unsigned_integer (buf, 8); |
| 1937 | cache->sof = cache->cfm & 0x7f; |
| 1938 | |
| 1939 | ia64_sigtramp_frame_init_saved_regs (this_frame, cache); |
| 1940 | |
| 1941 | *this_cache = cache; |
| 1942 | return cache; |
| 1943 | } |
| 1944 | |
| 1945 | static void |
| 1946 | ia64_sigtramp_frame_this_id (struct frame_info *this_frame, |
| 1947 | void **this_cache, struct frame_id *this_id) |
| 1948 | { |
| 1949 | struct ia64_frame_cache *cache = |
| 1950 | ia64_sigtramp_frame_cache (this_frame, this_cache); |
| 1951 | |
| 1952 | (*this_id) = frame_id_build_special (cache->base, |
| 1953 | get_frame_pc (this_frame), |
| 1954 | cache->bsp); |
| 1955 | if (gdbarch_debug >= 1) |
| 1956 | fprintf_unfiltered (gdb_stdlog, |
| 1957 | "sigtramp frame id: code 0x%s, stack 0x%s, special 0x%s, this_frame %p\n", |
| 1958 | paddr_nz (this_id->code_addr), |
| 1959 | paddr_nz (this_id->stack_addr), |
| 1960 | paddr_nz (cache->bsp), this_frame); |
| 1961 | } |
| 1962 | |
| 1963 | static struct value * |
| 1964 | ia64_sigtramp_frame_prev_register (struct frame_info *this_frame, |
| 1965 | void **this_cache, int regnum) |
| 1966 | { |
| 1967 | char buf[MAX_REGISTER_SIZE]; |
| 1968 | |
| 1969 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 1970 | struct ia64_frame_cache *cache = |
| 1971 | ia64_sigtramp_frame_cache (this_frame, this_cache); |
| 1972 | |
| 1973 | gdb_assert (regnum >= 0); |
| 1974 | |
| 1975 | if (!target_has_registers) |
| 1976 | error (_("No registers.")); |
| 1977 | |
| 1978 | if (regnum == IA64_IP_REGNUM) |
| 1979 | { |
| 1980 | CORE_ADDR pc = 0; |
| 1981 | CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; |
| 1982 | |
| 1983 | if (addr != 0) |
| 1984 | { |
| 1985 | read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); |
| 1986 | pc = extract_unsigned_integer (buf, 8); |
| 1987 | } |
| 1988 | pc &= ~0xf; |
| 1989 | return frame_unwind_got_constant (this_frame, regnum, pc); |
| 1990 | } |
| 1991 | |
| 1992 | else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM) |
| 1993 | || (regnum >= V32_REGNUM && regnum <= V127_REGNUM)) |
| 1994 | { |
| 1995 | CORE_ADDR addr = 0; |
| 1996 | |
| 1997 | if (regnum >= V32_REGNUM) |
| 1998 | regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); |
| 1999 | addr = cache->saved_regs[regnum]; |
| 2000 | if (addr != 0) |
| 2001 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 2002 | |
| 2003 | return frame_unwind_got_constant (this_frame, regnum, 0); |
| 2004 | } |
| 2005 | |
| 2006 | else /* All other registers not listed above. */ |
| 2007 | { |
| 2008 | CORE_ADDR addr = cache->saved_regs[regnum]; |
| 2009 | |
| 2010 | if (addr != 0) |
| 2011 | return frame_unwind_got_memory (this_frame, regnum, addr); |
| 2012 | |
| 2013 | return frame_unwind_got_constant (this_frame, regnum, 0); |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | static int |
| 2018 | ia64_sigtramp_frame_sniffer (const struct frame_unwind *self, |
| 2019 | struct frame_info *this_frame, |
| 2020 | void **this_cache) |
| 2021 | { |
| 2022 | struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame)); |
| 2023 | if (tdep->pc_in_sigtramp) |
| 2024 | { |
| 2025 | CORE_ADDR pc = get_frame_pc (this_frame); |
| 2026 | |
| 2027 | if (tdep->pc_in_sigtramp (pc)) |
| 2028 | return 1; |
| 2029 | } |
| 2030 | |
| 2031 | return 0; |
| 2032 | } |
| 2033 | |
| 2034 | static const struct frame_unwind ia64_sigtramp_frame_unwind = |
| 2035 | { |
| 2036 | SIGTRAMP_FRAME, |
| 2037 | ia64_sigtramp_frame_this_id, |
| 2038 | ia64_sigtramp_frame_prev_register, |
| 2039 | NULL, |
| 2040 | ia64_sigtramp_frame_sniffer |
| 2041 | }; |
| 2042 | |
| 2043 | \f |
| 2044 | |
| 2045 | static CORE_ADDR |
| 2046 | ia64_frame_base_address (struct frame_info *this_frame, void **this_cache) |
| 2047 | { |
| 2048 | struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache); |
| 2049 | |
| 2050 | return cache->base; |
| 2051 | } |
| 2052 | |
| 2053 | static const struct frame_base ia64_frame_base = |
| 2054 | { |
| 2055 | &ia64_frame_unwind, |
| 2056 | ia64_frame_base_address, |
| 2057 | ia64_frame_base_address, |
| 2058 | ia64_frame_base_address |
| 2059 | }; |
| 2060 | |
| 2061 | #ifdef HAVE_LIBUNWIND_IA64_H |
| 2062 | |
| 2063 | struct ia64_unwind_table_entry |
| 2064 | { |
| 2065 | unw_word_t start_offset; |
| 2066 | unw_word_t end_offset; |
| 2067 | unw_word_t info_offset; |
| 2068 | }; |
| 2069 | |
| 2070 | static __inline__ uint64_t |
| 2071 | ia64_rse_slot_num (uint64_t addr) |
| 2072 | { |
| 2073 | return (addr >> 3) & 0x3f; |
| 2074 | } |
| 2075 | |
| 2076 | /* Skip over a designated number of registers in the backing |
| 2077 | store, remembering every 64th position is for NAT. */ |
| 2078 | static __inline__ uint64_t |
| 2079 | ia64_rse_skip_regs (uint64_t addr, long num_regs) |
| 2080 | { |
| 2081 | long delta = ia64_rse_slot_num(addr) + num_regs; |
| 2082 | |
| 2083 | if (num_regs < 0) |
| 2084 | delta -= 0x3e; |
| 2085 | return addr + ((num_regs + delta/0x3f) << 3); |
| 2086 | } |
| 2087 | |
| 2088 | /* Gdb libunwind-frame callback function to convert from an ia64 gdb register |
| 2089 | number to a libunwind register number. */ |
| 2090 | static int |
| 2091 | ia64_gdb2uw_regnum (int regnum) |
| 2092 | { |
| 2093 | if (regnum == sp_regnum) |
| 2094 | return UNW_IA64_SP; |
| 2095 | else if (regnum == IA64_BSP_REGNUM) |
| 2096 | return UNW_IA64_BSP; |
| 2097 | else if ((unsigned) (regnum - IA64_GR0_REGNUM) < 128) |
| 2098 | return UNW_IA64_GR + (regnum - IA64_GR0_REGNUM); |
| 2099 | else if ((unsigned) (regnum - V32_REGNUM) < 95) |
| 2100 | return UNW_IA64_GR + 32 + (regnum - V32_REGNUM); |
| 2101 | else if ((unsigned) (regnum - IA64_FR0_REGNUM) < 128) |
| 2102 | return UNW_IA64_FR + (regnum - IA64_FR0_REGNUM); |
| 2103 | else if ((unsigned) (regnum - IA64_PR0_REGNUM) < 64) |
| 2104 | return -1; |
| 2105 | else if ((unsigned) (regnum - IA64_BR0_REGNUM) < 8) |
| 2106 | return UNW_IA64_BR + (regnum - IA64_BR0_REGNUM); |
| 2107 | else if (regnum == IA64_PR_REGNUM) |
| 2108 | return UNW_IA64_PR; |
| 2109 | else if (regnum == IA64_IP_REGNUM) |
| 2110 | return UNW_REG_IP; |
| 2111 | else if (regnum == IA64_CFM_REGNUM) |
| 2112 | return UNW_IA64_CFM; |
| 2113 | else if ((unsigned) (regnum - IA64_AR0_REGNUM) < 128) |
| 2114 | return UNW_IA64_AR + (regnum - IA64_AR0_REGNUM); |
| 2115 | else if ((unsigned) (regnum - IA64_NAT0_REGNUM) < 128) |
| 2116 | return UNW_IA64_NAT + (regnum - IA64_NAT0_REGNUM); |
| 2117 | else |
| 2118 | return -1; |
| 2119 | } |
| 2120 | |
| 2121 | /* Gdb libunwind-frame callback function to convert from a libunwind register |
| 2122 | number to a ia64 gdb register number. */ |
| 2123 | static int |
| 2124 | ia64_uw2gdb_regnum (int uw_regnum) |
| 2125 | { |
| 2126 | if (uw_regnum == UNW_IA64_SP) |
| 2127 | return sp_regnum; |
| 2128 | else if (uw_regnum == UNW_IA64_BSP) |
| 2129 | return IA64_BSP_REGNUM; |
| 2130 | else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 32) |
| 2131 | return IA64_GR0_REGNUM + (uw_regnum - UNW_IA64_GR); |
| 2132 | else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 128) |
| 2133 | return V32_REGNUM + (uw_regnum - (IA64_GR0_REGNUM + 32)); |
| 2134 | else if ((unsigned) (uw_regnum - UNW_IA64_FR) < 128) |
| 2135 | return IA64_FR0_REGNUM + (uw_regnum - UNW_IA64_FR); |
| 2136 | else if ((unsigned) (uw_regnum - UNW_IA64_BR) < 8) |
| 2137 | return IA64_BR0_REGNUM + (uw_regnum - UNW_IA64_BR); |
| 2138 | else if (uw_regnum == UNW_IA64_PR) |
| 2139 | return IA64_PR_REGNUM; |
| 2140 | else if (uw_regnum == UNW_REG_IP) |
| 2141 | return IA64_IP_REGNUM; |
| 2142 | else if (uw_regnum == UNW_IA64_CFM) |
| 2143 | return IA64_CFM_REGNUM; |
| 2144 | else if ((unsigned) (uw_regnum - UNW_IA64_AR) < 128) |
| 2145 | return IA64_AR0_REGNUM + (uw_regnum - UNW_IA64_AR); |
| 2146 | else if ((unsigned) (uw_regnum - UNW_IA64_NAT) < 128) |
| 2147 | return IA64_NAT0_REGNUM + (uw_regnum - UNW_IA64_NAT); |
| 2148 | else |
| 2149 | return -1; |
| 2150 | } |
| 2151 | |
| 2152 | /* Gdb libunwind-frame callback function to reveal if register is a float |
| 2153 | register or not. */ |
| 2154 | static int |
| 2155 | ia64_is_fpreg (int uw_regnum) |
| 2156 | { |
| 2157 | return unw_is_fpreg (uw_regnum); |
| 2158 | } |
| 2159 | |
| 2160 | /* Libunwind callback accessor function for general registers. */ |
| 2161 | static int |
| 2162 | ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val, |
| 2163 | int write, void *arg) |
| 2164 | { |
| 2165 | int regnum = ia64_uw2gdb_regnum (uw_regnum); |
| 2166 | unw_word_t bsp, sof, sol, cfm, psr, ip; |
| 2167 | struct frame_info *this_frame = arg; |
| 2168 | long new_sof, old_sof; |
| 2169 | char buf[MAX_REGISTER_SIZE]; |
| 2170 | |
| 2171 | /* We never call any libunwind routines that need to write registers. */ |
| 2172 | gdb_assert (!write); |
| 2173 | |
| 2174 | switch (uw_regnum) |
| 2175 | { |
| 2176 | case UNW_REG_IP: |
| 2177 | /* Libunwind expects to see the pc value which means the slot number |
| 2178 | from the psr must be merged with the ip word address. */ |
| 2179 | get_frame_register (this_frame, IA64_IP_REGNUM, buf); |
| 2180 | ip = extract_unsigned_integer (buf, 8); |
| 2181 | get_frame_register (this_frame, IA64_PSR_REGNUM, buf); |
| 2182 | psr = extract_unsigned_integer (buf, 8); |
| 2183 | *val = ip | ((psr >> 41) & 0x3); |
| 2184 | break; |
| 2185 | |
| 2186 | case UNW_IA64_AR_BSP: |
| 2187 | /* Libunwind expects to see the beginning of the current register |
| 2188 | frame so we must account for the fact that ptrace() will return a value |
| 2189 | for bsp that points *after* the current register frame. */ |
| 2190 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 2191 | bsp = extract_unsigned_integer (buf, 8); |
| 2192 | get_frame_register (this_frame, IA64_CFM_REGNUM, buf); |
| 2193 | cfm = extract_unsigned_integer (buf, 8); |
| 2194 | sof = (cfm & 0x7f); |
| 2195 | *val = ia64_rse_skip_regs (bsp, -sof); |
| 2196 | break; |
| 2197 | |
| 2198 | case UNW_IA64_AR_BSPSTORE: |
| 2199 | /* Libunwind wants bspstore to be after the current register frame. |
| 2200 | This is what ptrace() and gdb treats as the regular bsp value. */ |
| 2201 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 2202 | *val = extract_unsigned_integer (buf, 8); |
| 2203 | break; |
| 2204 | |
| 2205 | default: |
| 2206 | /* For all other registers, just unwind the value directly. */ |
| 2207 | get_frame_register (this_frame, regnum, buf); |
| 2208 | *val = extract_unsigned_integer (buf, 8); |
| 2209 | break; |
| 2210 | } |
| 2211 | |
| 2212 | if (gdbarch_debug >= 1) |
| 2213 | fprintf_unfiltered (gdb_stdlog, |
| 2214 | " access_reg: from cache: %4s=0x%s\n", |
| 2215 | (((unsigned) regnum <= IA64_NAT127_REGNUM) |
| 2216 | ? ia64_register_names[regnum] : "r??"), |
| 2217 | paddr_nz (*val)); |
| 2218 | return 0; |
| 2219 | } |
| 2220 | |
| 2221 | /* Libunwind callback accessor function for floating-point registers. */ |
| 2222 | static int |
| 2223 | ia64_access_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_fpreg_t *val, |
| 2224 | int write, void *arg) |
| 2225 | { |
| 2226 | int regnum = ia64_uw2gdb_regnum (uw_regnum); |
| 2227 | struct frame_info *this_frame = arg; |
| 2228 | |
| 2229 | /* We never call any libunwind routines that need to write registers. */ |
| 2230 | gdb_assert (!write); |
| 2231 | |
| 2232 | get_frame_register (this_frame, regnum, (char *) val); |
| 2233 | |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
| 2237 | /* Libunwind callback accessor function for top-level rse registers. */ |
| 2238 | static int |
| 2239 | ia64_access_rse_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val, |
| 2240 | int write, void *arg) |
| 2241 | { |
| 2242 | int regnum = ia64_uw2gdb_regnum (uw_regnum); |
| 2243 | unw_word_t bsp, sof, sol, cfm, psr, ip; |
| 2244 | struct regcache *regcache = arg; |
| 2245 | long new_sof, old_sof; |
| 2246 | char buf[MAX_REGISTER_SIZE]; |
| 2247 | |
| 2248 | /* We never call any libunwind routines that need to write registers. */ |
| 2249 | gdb_assert (!write); |
| 2250 | |
| 2251 | switch (uw_regnum) |
| 2252 | { |
| 2253 | case UNW_REG_IP: |
| 2254 | /* Libunwind expects to see the pc value which means the slot number |
| 2255 | from the psr must be merged with the ip word address. */ |
| 2256 | regcache_cooked_read (regcache, IA64_IP_REGNUM, buf); |
| 2257 | ip = extract_unsigned_integer (buf, 8); |
| 2258 | regcache_cooked_read (regcache, IA64_PSR_REGNUM, buf); |
| 2259 | psr = extract_unsigned_integer (buf, 8); |
| 2260 | *val = ip | ((psr >> 41) & 0x3); |
| 2261 | break; |
| 2262 | |
| 2263 | case UNW_IA64_AR_BSP: |
| 2264 | /* Libunwind expects to see the beginning of the current register |
| 2265 | frame so we must account for the fact that ptrace() will return a value |
| 2266 | for bsp that points *after* the current register frame. */ |
| 2267 | regcache_cooked_read (regcache, IA64_BSP_REGNUM, buf); |
| 2268 | bsp = extract_unsigned_integer (buf, 8); |
| 2269 | regcache_cooked_read (regcache, IA64_CFM_REGNUM, buf); |
| 2270 | cfm = extract_unsigned_integer (buf, 8); |
| 2271 | sof = (cfm & 0x7f); |
| 2272 | *val = ia64_rse_skip_regs (bsp, -sof); |
| 2273 | break; |
| 2274 | |
| 2275 | case UNW_IA64_AR_BSPSTORE: |
| 2276 | /* Libunwind wants bspstore to be after the current register frame. |
| 2277 | This is what ptrace() and gdb treats as the regular bsp value. */ |
| 2278 | regcache_cooked_read (regcache, IA64_BSP_REGNUM, buf); |
| 2279 | *val = extract_unsigned_integer (buf, 8); |
| 2280 | break; |
| 2281 | |
| 2282 | default: |
| 2283 | /* For all other registers, just unwind the value directly. */ |
| 2284 | regcache_cooked_read (regcache, regnum, buf); |
| 2285 | *val = extract_unsigned_integer (buf, 8); |
| 2286 | break; |
| 2287 | } |
| 2288 | |
| 2289 | if (gdbarch_debug >= 1) |
| 2290 | fprintf_unfiltered (gdb_stdlog, |
| 2291 | " access_rse_reg: from cache: %4s=0x%s\n", |
| 2292 | (((unsigned) regnum <= IA64_NAT127_REGNUM) |
| 2293 | ? ia64_register_names[regnum] : "r??"), |
| 2294 | paddr_nz (*val)); |
| 2295 | |
| 2296 | return 0; |
| 2297 | } |
| 2298 | |
| 2299 | /* Libunwind callback accessor function for top-level fp registers. */ |
| 2300 | static int |
| 2301 | ia64_access_rse_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum, |
| 2302 | unw_fpreg_t *val, int write, void *arg) |
| 2303 | { |
| 2304 | int regnum = ia64_uw2gdb_regnum (uw_regnum); |
| 2305 | struct regcache *regcache = arg; |
| 2306 | |
| 2307 | /* We never call any libunwind routines that need to write registers. */ |
| 2308 | gdb_assert (!write); |
| 2309 | |
| 2310 | regcache_cooked_read (regcache, regnum, (char *) val); |
| 2311 | |
| 2312 | return 0; |
| 2313 | } |
| 2314 | |
| 2315 | /* Libunwind callback accessor function for accessing memory. */ |
| 2316 | static int |
| 2317 | ia64_access_mem (unw_addr_space_t as, |
| 2318 | unw_word_t addr, unw_word_t *val, |
| 2319 | int write, void *arg) |
| 2320 | { |
| 2321 | if (addr - KERNEL_START < ktab_size) |
| 2322 | { |
| 2323 | unw_word_t *laddr = (unw_word_t*) ((char *) ktab |
| 2324 | + (addr - KERNEL_START)); |
| 2325 | |
| 2326 | if (write) |
| 2327 | *laddr = *val; |
| 2328 | else |
| 2329 | *val = *laddr; |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
| 2333 | /* XXX do we need to normalize byte-order here? */ |
| 2334 | if (write) |
| 2335 | return target_write_memory (addr, (char *) val, sizeof (unw_word_t)); |
| 2336 | else |
| 2337 | return target_read_memory (addr, (char *) val, sizeof (unw_word_t)); |
| 2338 | } |
| 2339 | |
| 2340 | /* Call low-level function to access the kernel unwind table. */ |
| 2341 | static LONGEST |
| 2342 | getunwind_table (gdb_byte **buf_p) |
| 2343 | { |
| 2344 | LONGEST x; |
| 2345 | |
| 2346 | /* FIXME drow/2005-09-10: This code used to call |
| 2347 | ia64_linux_xfer_unwind_table directly to fetch the unwind table |
| 2348 | for the currently running ia64-linux kernel. That data should |
| 2349 | come from the core file and be accessed via the auxv vector; if |
| 2350 | we want to preserve fall back to the running kernel's table, then |
| 2351 | we should find a way to override the corefile layer's |
| 2352 | xfer_partial method. */ |
| 2353 | |
| 2354 | x = target_read_alloc (¤t_target, TARGET_OBJECT_UNWIND_TABLE, |
| 2355 | NULL, buf_p); |
| 2356 | |
| 2357 | return x; |
| 2358 | } |
| 2359 | |
| 2360 | /* Get the kernel unwind table. */ |
| 2361 | static int |
| 2362 | get_kernel_table (unw_word_t ip, unw_dyn_info_t *di) |
| 2363 | { |
| 2364 | static struct ia64_table_entry *etab; |
| 2365 | |
| 2366 | if (!ktab) |
| 2367 | { |
| 2368 | gdb_byte *ktab_buf; |
| 2369 | LONGEST size; |
| 2370 | |
| 2371 | size = getunwind_table (&ktab_buf); |
| 2372 | if (size <= 0) |
| 2373 | return -UNW_ENOINFO; |
| 2374 | |
| 2375 | ktab = (struct ia64_table_entry *) ktab_buf; |
| 2376 | ktab_size = size; |
| 2377 | |
| 2378 | for (etab = ktab; etab->start_offset; ++etab) |
| 2379 | etab->info_offset += KERNEL_START; |
| 2380 | } |
| 2381 | |
| 2382 | if (ip < ktab[0].start_offset || ip >= etab[-1].end_offset) |
| 2383 | return -UNW_ENOINFO; |
| 2384 | |
| 2385 | di->format = UNW_INFO_FORMAT_TABLE; |
| 2386 | di->gp = 0; |
| 2387 | di->start_ip = ktab[0].start_offset; |
| 2388 | di->end_ip = etab[-1].end_offset; |
| 2389 | di->u.ti.name_ptr = (unw_word_t) "<kernel>"; |
| 2390 | di->u.ti.segbase = 0; |
| 2391 | di->u.ti.table_len = ((char *) etab - (char *) ktab) / sizeof (unw_word_t); |
| 2392 | di->u.ti.table_data = (unw_word_t *) ktab; |
| 2393 | |
| 2394 | if (gdbarch_debug >= 1) |
| 2395 | fprintf_unfiltered (gdb_stdlog, "get_kernel_table: found table `%s': " |
| 2396 | "segbase=0x%s, length=%s, gp=0x%s\n", |
| 2397 | (char *) di->u.ti.name_ptr, |
| 2398 | paddr_nz (di->u.ti.segbase), |
| 2399 | pulongest (di->u.ti.table_len), |
| 2400 | paddr_nz (di->gp)); |
| 2401 | return 0; |
| 2402 | } |
| 2403 | |
| 2404 | /* Find the unwind table entry for a specified address. */ |
| 2405 | static int |
| 2406 | ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip, |
| 2407 | unw_dyn_info_t *dip, void **buf) |
| 2408 | { |
| 2409 | Elf_Internal_Phdr *phdr, *p_text = NULL, *p_unwind = NULL; |
| 2410 | Elf_Internal_Ehdr *ehdr; |
| 2411 | unw_word_t segbase = 0; |
| 2412 | CORE_ADDR load_base; |
| 2413 | bfd *bfd; |
| 2414 | int i; |
| 2415 | |
| 2416 | bfd = objfile->obfd; |
| 2417 | |
| 2418 | ehdr = elf_tdata (bfd)->elf_header; |
| 2419 | phdr = elf_tdata (bfd)->phdr; |
| 2420 | |
| 2421 | load_base = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 2422 | |
| 2423 | for (i = 0; i < ehdr->e_phnum; ++i) |
| 2424 | { |
| 2425 | switch (phdr[i].p_type) |
| 2426 | { |
| 2427 | case PT_LOAD: |
| 2428 | if ((unw_word_t) (ip - load_base - phdr[i].p_vaddr) |
| 2429 | < phdr[i].p_memsz) |
| 2430 | p_text = phdr + i; |
| 2431 | break; |
| 2432 | |
| 2433 | case PT_IA_64_UNWIND: |
| 2434 | p_unwind = phdr + i; |
| 2435 | break; |
| 2436 | |
| 2437 | default: |
| 2438 | break; |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | if (!p_text || !p_unwind) |
| 2443 | return -UNW_ENOINFO; |
| 2444 | |
| 2445 | /* Verify that the segment that contains the IP also contains |
| 2446 | the static unwind table. If not, we may be in the Linux kernel's |
| 2447 | DSO gate page in which case the unwind table is another segment. |
| 2448 | Otherwise, we are dealing with runtime-generated code, for which we |
| 2449 | have no info here. */ |
| 2450 | segbase = p_text->p_vaddr + load_base; |
| 2451 | |
| 2452 | if ((p_unwind->p_vaddr - p_text->p_vaddr) >= p_text->p_memsz) |
| 2453 | { |
| 2454 | int ok = 0; |
| 2455 | for (i = 0; i < ehdr->e_phnum; ++i) |
| 2456 | { |
| 2457 | if (phdr[i].p_type == PT_LOAD |
| 2458 | && (p_unwind->p_vaddr - phdr[i].p_vaddr) < phdr[i].p_memsz) |
| 2459 | { |
| 2460 | ok = 1; |
| 2461 | /* Get the segbase from the section containing the |
| 2462 | libunwind table. */ |
| 2463 | segbase = phdr[i].p_vaddr + load_base; |
| 2464 | } |
| 2465 | } |
| 2466 | if (!ok) |
| 2467 | return -UNW_ENOINFO; |
| 2468 | } |
| 2469 | |
| 2470 | dip->start_ip = p_text->p_vaddr + load_base; |
| 2471 | dip->end_ip = dip->start_ip + p_text->p_memsz; |
| 2472 | dip->gp = ia64_find_global_pointer (ip); |
| 2473 | dip->format = UNW_INFO_FORMAT_REMOTE_TABLE; |
| 2474 | dip->u.rti.name_ptr = (unw_word_t) bfd_get_filename (bfd); |
| 2475 | dip->u.rti.segbase = segbase; |
| 2476 | dip->u.rti.table_len = p_unwind->p_memsz / sizeof (unw_word_t); |
| 2477 | dip->u.rti.table_data = p_unwind->p_vaddr + load_base; |
| 2478 | |
| 2479 | return 0; |
| 2480 | } |
| 2481 | |
| 2482 | /* Libunwind callback accessor function to acquire procedure unwind-info. */ |
| 2483 | static int |
| 2484 | ia64_find_proc_info_x (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi, |
| 2485 | int need_unwind_info, void *arg) |
| 2486 | { |
| 2487 | struct obj_section *sec = find_pc_section (ip); |
| 2488 | unw_dyn_info_t di; |
| 2489 | int ret; |
| 2490 | void *buf = NULL; |
| 2491 | |
| 2492 | if (!sec) |
| 2493 | { |
| 2494 | /* XXX This only works if the host and the target architecture are |
| 2495 | both ia64 and if the have (more or less) the same kernel |
| 2496 | version. */ |
| 2497 | if (get_kernel_table (ip, &di) < 0) |
| 2498 | return -UNW_ENOINFO; |
| 2499 | |
| 2500 | if (gdbarch_debug >= 1) |
| 2501 | fprintf_unfiltered (gdb_stdlog, "ia64_find_proc_info_x: 0x%s -> " |
| 2502 | "(name=`%s',segbase=0x%s,start=0x%s,end=0x%s,gp=0x%s," |
| 2503 | "length=%s,data=0x%s)\n", |
| 2504 | paddr_nz (ip), (char *)di.u.ti.name_ptr, |
| 2505 | paddr_nz (di.u.ti.segbase), |
| 2506 | paddr_nz (di.start_ip), paddr_nz (di.end_ip), |
| 2507 | paddr_nz (di.gp), |
| 2508 | pulongest (di.u.ti.table_len), |
| 2509 | paddr_nz ((CORE_ADDR)di.u.ti.table_data)); |
| 2510 | } |
| 2511 | else |
| 2512 | { |
| 2513 | ret = ia64_find_unwind_table (sec->objfile, ip, &di, &buf); |
| 2514 | if (ret < 0) |
| 2515 | return ret; |
| 2516 | |
| 2517 | if (gdbarch_debug >= 1) |
| 2518 | fprintf_unfiltered (gdb_stdlog, "ia64_find_proc_info_x: 0x%s -> " |
| 2519 | "(name=`%s',segbase=0x%s,start=0x%s,end=0x%s,gp=0x%s," |
| 2520 | "length=%s,data=0x%s)\n", |
| 2521 | paddr_nz (ip), (char *)di.u.rti.name_ptr, |
| 2522 | paddr_nz (di.u.rti.segbase), |
| 2523 | paddr_nz (di.start_ip), paddr_nz (di.end_ip), |
| 2524 | paddr_nz (di.gp), |
| 2525 | pulongest (di.u.rti.table_len), |
| 2526 | paddr_nz (di.u.rti.table_data)); |
| 2527 | } |
| 2528 | |
| 2529 | ret = libunwind_search_unwind_table (&as, ip, &di, pi, need_unwind_info, |
| 2530 | arg); |
| 2531 | |
| 2532 | /* We no longer need the dyn info storage so free it. */ |
| 2533 | xfree (buf); |
| 2534 | |
| 2535 | return ret; |
| 2536 | } |
| 2537 | |
| 2538 | /* Libunwind callback accessor function for cleanup. */ |
| 2539 | static void |
| 2540 | ia64_put_unwind_info (unw_addr_space_t as, |
| 2541 | unw_proc_info_t *pip, void *arg) |
| 2542 | { |
| 2543 | /* Nothing required for now. */ |
| 2544 | } |
| 2545 | |
| 2546 | /* Libunwind callback accessor function to get head of the dynamic |
| 2547 | unwind-info registration list. */ |
| 2548 | static int |
| 2549 | ia64_get_dyn_info_list (unw_addr_space_t as, |
| 2550 | unw_word_t *dilap, void *arg) |
| 2551 | { |
| 2552 | struct obj_section *text_sec; |
| 2553 | struct objfile *objfile; |
| 2554 | unw_word_t ip, addr; |
| 2555 | unw_dyn_info_t di; |
| 2556 | int ret; |
| 2557 | |
| 2558 | if (!libunwind_is_initialized ()) |
| 2559 | return -UNW_ENOINFO; |
| 2560 | |
| 2561 | for (objfile = object_files; objfile; objfile = objfile->next) |
| 2562 | { |
| 2563 | void *buf = NULL; |
| 2564 | |
| 2565 | text_sec = objfile->sections + SECT_OFF_TEXT (objfile); |
| 2566 | ip = obj_section_addr (text_sec); |
| 2567 | ret = ia64_find_unwind_table (objfile, ip, &di, &buf); |
| 2568 | if (ret >= 0) |
| 2569 | { |
| 2570 | addr = libunwind_find_dyn_list (as, &di, arg); |
| 2571 | /* We no longer need the dyn info storage so free it. */ |
| 2572 | xfree (buf); |
| 2573 | |
| 2574 | if (addr) |
| 2575 | { |
| 2576 | if (gdbarch_debug >= 1) |
| 2577 | fprintf_unfiltered (gdb_stdlog, |
| 2578 | "dynamic unwind table in objfile %s " |
| 2579 | "at 0x%s (gp=0x%s)\n", |
| 2580 | bfd_get_filename (objfile->obfd), |
| 2581 | paddr_nz (addr), paddr_nz (di.gp)); |
| 2582 | *dilap = addr; |
| 2583 | return 0; |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | return -UNW_ENOINFO; |
| 2588 | } |
| 2589 | |
| 2590 | |
| 2591 | /* Frame interface functions for libunwind. */ |
| 2592 | |
| 2593 | static void |
| 2594 | ia64_libunwind_frame_this_id (struct frame_info *this_frame, void **this_cache, |
| 2595 | struct frame_id *this_id) |
| 2596 | { |
| 2597 | struct frame_id id; |
| 2598 | char buf[8]; |
| 2599 | CORE_ADDR bsp; |
| 2600 | |
| 2601 | |
| 2602 | libunwind_frame_this_id (this_frame, this_cache, &id); |
| 2603 | if (frame_id_eq (id, null_frame_id)) |
| 2604 | { |
| 2605 | (*this_id) = null_frame_id; |
| 2606 | return; |
| 2607 | } |
| 2608 | |
| 2609 | /* We must add the bsp as the special address for frame comparison |
| 2610 | purposes. */ |
| 2611 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 2612 | bsp = extract_unsigned_integer (buf, 8); |
| 2613 | |
| 2614 | (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp); |
| 2615 | |
| 2616 | if (gdbarch_debug >= 1) |
| 2617 | fprintf_unfiltered (gdb_stdlog, |
| 2618 | "libunwind frame id: code 0x%s, stack 0x%s, special 0x%s, this_frame %p\n", |
| 2619 | paddr_nz (id.code_addr), paddr_nz (id.stack_addr), |
| 2620 | paddr_nz (bsp), this_frame); |
| 2621 | } |
| 2622 | |
| 2623 | static struct value * |
| 2624 | ia64_libunwind_frame_prev_register (struct frame_info *this_frame, |
| 2625 | void **this_cache, int regnum) |
| 2626 | { |
| 2627 | int reg = regnum; |
| 2628 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
| 2629 | struct value *val; |
| 2630 | |
| 2631 | if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 2632 | reg = IA64_PR_REGNUM; |
| 2633 | else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) |
| 2634 | reg = IA64_UNAT_REGNUM; |
| 2635 | |
| 2636 | /* Let libunwind do most of the work. */ |
| 2637 | val = libunwind_frame_prev_register (this_frame, this_cache, reg); |
| 2638 | |
| 2639 | if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 2640 | { |
| 2641 | ULONGEST prN_val; |
| 2642 | |
| 2643 | if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) |
| 2644 | { |
| 2645 | int rrb_pr = 0; |
| 2646 | ULONGEST cfm; |
| 2647 | unsigned char buf[MAX_REGISTER_SIZE]; |
| 2648 | |
| 2649 | /* Fetch predicate register rename base from current frame |
| 2650 | marker for this frame. */ |
| 2651 | get_frame_register (this_frame, IA64_CFM_REGNUM, buf); |
| 2652 | cfm = extract_unsigned_integer (buf, 8); |
| 2653 | rrb_pr = (cfm >> 32) & 0x3f; |
| 2654 | |
| 2655 | /* Adjust the register number to account for register rotation. */ |
| 2656 | regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48; |
| 2657 | } |
| 2658 | prN_val = extract_bit_field (value_contents_all (val), |
| 2659 | regnum - VP0_REGNUM, 1); |
| 2660 | return frame_unwind_got_constant (this_frame, regnum, prN_val); |
| 2661 | } |
| 2662 | |
| 2663 | else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) |
| 2664 | { |
| 2665 | ULONGEST unatN_val; |
| 2666 | |
| 2667 | unatN_val = extract_bit_field (value_contents_all (val), |
| 2668 | regnum - IA64_NAT0_REGNUM, 1); |
| 2669 | return frame_unwind_got_constant (this_frame, regnum, unatN_val); |
| 2670 | } |
| 2671 | |
| 2672 | else if (regnum == IA64_BSP_REGNUM) |
| 2673 | { |
| 2674 | struct value *cfm_val; |
| 2675 | CORE_ADDR prev_bsp, prev_cfm; |
| 2676 | |
| 2677 | /* We want to calculate the previous bsp as the end of the previous |
| 2678 | register stack frame. This corresponds to what the hardware bsp |
| 2679 | register will be if we pop the frame back which is why we might |
| 2680 | have been called. We know that libunwind will pass us back the |
| 2681 | beginning of the current frame so we should just add sof to it. */ |
| 2682 | prev_bsp = extract_unsigned_integer (value_contents_all (val), 8); |
| 2683 | cfm_val = libunwind_frame_prev_register (this_frame, this_cache, |
| 2684 | IA64_CFM_REGNUM); |
| 2685 | prev_cfm = extract_unsigned_integer (value_contents_all (cfm_val), 8); |
| 2686 | prev_bsp = rse_address_add (prev_bsp, (prev_cfm & 0x7f)); |
| 2687 | |
| 2688 | return frame_unwind_got_constant (this_frame, regnum, prev_bsp); |
| 2689 | } |
| 2690 | else |
| 2691 | return val; |
| 2692 | } |
| 2693 | |
| 2694 | static int |
| 2695 | ia64_libunwind_frame_sniffer (const struct frame_unwind *self, |
| 2696 | struct frame_info *this_frame, |
| 2697 | void **this_cache) |
| 2698 | { |
| 2699 | if (libunwind_is_initialized () |
| 2700 | && libunwind_frame_sniffer (self, this_frame, this_cache)) |
| 2701 | return 1; |
| 2702 | |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
| 2706 | static const struct frame_unwind ia64_libunwind_frame_unwind = |
| 2707 | { |
| 2708 | NORMAL_FRAME, |
| 2709 | ia64_libunwind_frame_this_id, |
| 2710 | ia64_libunwind_frame_prev_register, |
| 2711 | NULL, |
| 2712 | ia64_libunwind_frame_sniffer, |
| 2713 | libunwind_frame_dealloc_cache |
| 2714 | }; |
| 2715 | |
| 2716 | static void |
| 2717 | ia64_libunwind_sigtramp_frame_this_id (struct frame_info *this_frame, |
| 2718 | void **this_cache, |
| 2719 | struct frame_id *this_id) |
| 2720 | { |
| 2721 | char buf[8]; |
| 2722 | CORE_ADDR bsp; |
| 2723 | struct frame_id id; |
| 2724 | CORE_ADDR prev_ip; |
| 2725 | |
| 2726 | libunwind_frame_this_id (this_frame, this_cache, &id); |
| 2727 | if (frame_id_eq (id, null_frame_id)) |
| 2728 | { |
| 2729 | (*this_id) = null_frame_id; |
| 2730 | return; |
| 2731 | } |
| 2732 | |
| 2733 | /* We must add the bsp as the special address for frame comparison |
| 2734 | purposes. */ |
| 2735 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 2736 | bsp = extract_unsigned_integer (buf, 8); |
| 2737 | |
| 2738 | /* For a sigtramp frame, we don't make the check for previous ip being 0. */ |
| 2739 | (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp); |
| 2740 | |
| 2741 | if (gdbarch_debug >= 1) |
| 2742 | fprintf_unfiltered (gdb_stdlog, |
| 2743 | "libunwind sigtramp frame id: code 0x%s, stack 0x%s, special 0x%s, this_frame %p\n", |
| 2744 | paddr_nz (id.code_addr), paddr_nz (id.stack_addr), |
| 2745 | paddr_nz (bsp), this_frame); |
| 2746 | } |
| 2747 | |
| 2748 | static struct value * |
| 2749 | ia64_libunwind_sigtramp_frame_prev_register (struct frame_info *this_frame, |
| 2750 | void **this_cache, int regnum) |
| 2751 | { |
| 2752 | struct value *prev_ip_val; |
| 2753 | CORE_ADDR prev_ip; |
| 2754 | |
| 2755 | /* If the previous frame pc value is 0, then we want to use the SIGCONTEXT |
| 2756 | method of getting previous registers. */ |
| 2757 | prev_ip_val = libunwind_frame_prev_register (this_frame, this_cache, |
| 2758 | IA64_IP_REGNUM); |
| 2759 | prev_ip = extract_unsigned_integer (value_contents_all (prev_ip_val), 8); |
| 2760 | |
| 2761 | if (prev_ip == 0) |
| 2762 | { |
| 2763 | void *tmp_cache = NULL; |
| 2764 | return ia64_sigtramp_frame_prev_register (this_frame, &tmp_cache, |
| 2765 | regnum); |
| 2766 | } |
| 2767 | else |
| 2768 | return ia64_libunwind_frame_prev_register (this_frame, this_cache, regnum); |
| 2769 | } |
| 2770 | |
| 2771 | static int |
| 2772 | ia64_libunwind_sigtramp_frame_sniffer (const struct frame_unwind *self, |
| 2773 | struct frame_info *this_frame, |
| 2774 | void **this_cache) |
| 2775 | { |
| 2776 | if (libunwind_is_initialized ()) |
| 2777 | { |
| 2778 | if (libunwind_sigtramp_frame_sniffer (self, this_frame, this_cache)) |
| 2779 | return 1; |
| 2780 | return 0; |
| 2781 | } |
| 2782 | else |
| 2783 | return ia64_sigtramp_frame_sniffer (self, this_frame, this_cache); |
| 2784 | } |
| 2785 | |
| 2786 | static const struct frame_unwind ia64_libunwind_sigtramp_frame_unwind = |
| 2787 | { |
| 2788 | SIGTRAMP_FRAME, |
| 2789 | ia64_libunwind_sigtramp_frame_this_id, |
| 2790 | ia64_libunwind_sigtramp_frame_prev_register, |
| 2791 | NULL, |
| 2792 | ia64_libunwind_sigtramp_frame_sniffer |
| 2793 | }; |
| 2794 | |
| 2795 | /* Set of libunwind callback acccessor functions. */ |
| 2796 | static unw_accessors_t ia64_unw_accessors = |
| 2797 | { |
| 2798 | ia64_find_proc_info_x, |
| 2799 | ia64_put_unwind_info, |
| 2800 | ia64_get_dyn_info_list, |
| 2801 | ia64_access_mem, |
| 2802 | ia64_access_reg, |
| 2803 | ia64_access_fpreg, |
| 2804 | /* resume */ |
| 2805 | /* get_proc_name */ |
| 2806 | }; |
| 2807 | |
| 2808 | /* Set of special libunwind callback acccessor functions specific for accessing |
| 2809 | the rse registers. At the top of the stack, we want libunwind to figure out |
| 2810 | how to read r32 - r127. Though usually they are found sequentially in memory |
| 2811 | starting from $bof, this is not always true. */ |
| 2812 | static unw_accessors_t ia64_unw_rse_accessors = |
| 2813 | { |
| 2814 | ia64_find_proc_info_x, |
| 2815 | ia64_put_unwind_info, |
| 2816 | ia64_get_dyn_info_list, |
| 2817 | ia64_access_mem, |
| 2818 | ia64_access_rse_reg, |
| 2819 | ia64_access_rse_fpreg, |
| 2820 | /* resume */ |
| 2821 | /* get_proc_name */ |
| 2822 | }; |
| 2823 | |
| 2824 | /* Set of ia64 gdb libunwind-frame callbacks and data for generic libunwind-frame code to use. */ |
| 2825 | static struct libunwind_descr ia64_libunwind_descr = |
| 2826 | { |
| 2827 | ia64_gdb2uw_regnum, |
| 2828 | ia64_uw2gdb_regnum, |
| 2829 | ia64_is_fpreg, |
| 2830 | &ia64_unw_accessors, |
| 2831 | &ia64_unw_rse_accessors, |
| 2832 | }; |
| 2833 | |
| 2834 | #endif /* HAVE_LIBUNWIND_IA64_H */ |
| 2835 | |
| 2836 | static int |
| 2837 | ia64_use_struct_convention (struct type *type) |
| 2838 | { |
| 2839 | struct type *float_elt_type; |
| 2840 | |
| 2841 | /* Don't use the struct convention for anything but structure, |
| 2842 | union, or array types. */ |
| 2843 | if (!(TYPE_CODE (type) == TYPE_CODE_STRUCT |
| 2844 | || TYPE_CODE (type) == TYPE_CODE_UNION |
| 2845 | || TYPE_CODE (type) == TYPE_CODE_ARRAY)) |
| 2846 | return 0; |
| 2847 | |
| 2848 | /* HFAs are structures (or arrays) consisting entirely of floating |
| 2849 | point values of the same length. Up to 8 of these are returned |
| 2850 | in registers. Don't use the struct convention when this is the |
| 2851 | case. */ |
| 2852 | float_elt_type = is_float_or_hfa_type (type); |
| 2853 | if (float_elt_type != NULL |
| 2854 | && TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type) <= 8) |
| 2855 | return 0; |
| 2856 | |
| 2857 | /* Other structs of length 32 or less are returned in r8-r11. |
| 2858 | Don't use the struct convention for those either. */ |
| 2859 | return TYPE_LENGTH (type) > 32; |
| 2860 | } |
| 2861 | |
| 2862 | static void |
| 2863 | ia64_extract_return_value (struct type *type, struct regcache *regcache, |
| 2864 | gdb_byte *valbuf) |
| 2865 | { |
| 2866 | struct type *float_elt_type; |
| 2867 | |
| 2868 | float_elt_type = is_float_or_hfa_type (type); |
| 2869 | if (float_elt_type != NULL) |
| 2870 | { |
| 2871 | char from[MAX_REGISTER_SIZE]; |
| 2872 | int offset = 0; |
| 2873 | int regnum = IA64_FR8_REGNUM; |
| 2874 | int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type); |
| 2875 | |
| 2876 | while (n-- > 0) |
| 2877 | { |
| 2878 | regcache_cooked_read (regcache, regnum, from); |
| 2879 | convert_typed_floating (from, builtin_type_ia64_ext, |
| 2880 | (char *)valbuf + offset, float_elt_type); |
| 2881 | offset += TYPE_LENGTH (float_elt_type); |
| 2882 | regnum++; |
| 2883 | } |
| 2884 | } |
| 2885 | else |
| 2886 | { |
| 2887 | ULONGEST val; |
| 2888 | int offset = 0; |
| 2889 | int regnum = IA64_GR8_REGNUM; |
| 2890 | int reglen = TYPE_LENGTH (register_type (get_regcache_arch (regcache), |
| 2891 | IA64_GR8_REGNUM)); |
| 2892 | int n = TYPE_LENGTH (type) / reglen; |
| 2893 | int m = TYPE_LENGTH (type) % reglen; |
| 2894 | |
| 2895 | while (n-- > 0) |
| 2896 | { |
| 2897 | ULONGEST val; |
| 2898 | regcache_cooked_read_unsigned (regcache, regnum, &val); |
| 2899 | memcpy ((char *)valbuf + offset, &val, reglen); |
| 2900 | offset += reglen; |
| 2901 | regnum++; |
| 2902 | } |
| 2903 | |
| 2904 | if (m) |
| 2905 | { |
| 2906 | regcache_cooked_read_unsigned (regcache, regnum, &val); |
| 2907 | memcpy ((char *)valbuf + offset, &val, m); |
| 2908 | } |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | static void |
| 2913 | ia64_store_return_value (struct type *type, struct regcache *regcache, |
| 2914 | const gdb_byte *valbuf) |
| 2915 | { |
| 2916 | struct type *float_elt_type; |
| 2917 | |
| 2918 | float_elt_type = is_float_or_hfa_type (type); |
| 2919 | if (float_elt_type != NULL) |
| 2920 | { |
| 2921 | char to[MAX_REGISTER_SIZE]; |
| 2922 | int offset = 0; |
| 2923 | int regnum = IA64_FR8_REGNUM; |
| 2924 | int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type); |
| 2925 | |
| 2926 | while (n-- > 0) |
| 2927 | { |
| 2928 | convert_typed_floating ((char *)valbuf + offset, float_elt_type, |
| 2929 | to, builtin_type_ia64_ext); |
| 2930 | regcache_cooked_write (regcache, regnum, to); |
| 2931 | offset += TYPE_LENGTH (float_elt_type); |
| 2932 | regnum++; |
| 2933 | } |
| 2934 | } |
| 2935 | else |
| 2936 | { |
| 2937 | ULONGEST val; |
| 2938 | int offset = 0; |
| 2939 | int regnum = IA64_GR8_REGNUM; |
| 2940 | int reglen = TYPE_LENGTH (register_type (get_regcache_arch (regcache), |
| 2941 | IA64_GR8_REGNUM)); |
| 2942 | int n = TYPE_LENGTH (type) / reglen; |
| 2943 | int m = TYPE_LENGTH (type) % reglen; |
| 2944 | |
| 2945 | while (n-- > 0) |
| 2946 | { |
| 2947 | ULONGEST val; |
| 2948 | memcpy (&val, (char *)valbuf + offset, reglen); |
| 2949 | regcache_cooked_write_unsigned (regcache, regnum, val); |
| 2950 | offset += reglen; |
| 2951 | regnum++; |
| 2952 | } |
| 2953 | |
| 2954 | if (m) |
| 2955 | { |
| 2956 | memcpy (&val, (char *)valbuf + offset, m); |
| 2957 | regcache_cooked_write_unsigned (regcache, regnum, val); |
| 2958 | } |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | static enum return_value_convention |
| 2963 | ia64_return_value (struct gdbarch *gdbarch, struct type *func_type, |
| 2964 | struct type *valtype, struct regcache *regcache, |
| 2965 | gdb_byte *readbuf, const gdb_byte *writebuf) |
| 2966 | { |
| 2967 | int struct_return = ia64_use_struct_convention (valtype); |
| 2968 | |
| 2969 | if (writebuf != NULL) |
| 2970 | { |
| 2971 | gdb_assert (!struct_return); |
| 2972 | ia64_store_return_value (valtype, regcache, writebuf); |
| 2973 | } |
| 2974 | |
| 2975 | if (readbuf != NULL) |
| 2976 | { |
| 2977 | gdb_assert (!struct_return); |
| 2978 | ia64_extract_return_value (valtype, regcache, readbuf); |
| 2979 | } |
| 2980 | |
| 2981 | if (struct_return) |
| 2982 | return RETURN_VALUE_STRUCT_CONVENTION; |
| 2983 | else |
| 2984 | return RETURN_VALUE_REGISTER_CONVENTION; |
| 2985 | } |
| 2986 | |
| 2987 | static int |
| 2988 | is_float_or_hfa_type_recurse (struct type *t, struct type **etp) |
| 2989 | { |
| 2990 | switch (TYPE_CODE (t)) |
| 2991 | { |
| 2992 | case TYPE_CODE_FLT: |
| 2993 | if (*etp) |
| 2994 | return TYPE_LENGTH (*etp) == TYPE_LENGTH (t); |
| 2995 | else |
| 2996 | { |
| 2997 | *etp = t; |
| 2998 | return 1; |
| 2999 | } |
| 3000 | break; |
| 3001 | case TYPE_CODE_ARRAY: |
| 3002 | return |
| 3003 | is_float_or_hfa_type_recurse (check_typedef (TYPE_TARGET_TYPE (t)), |
| 3004 | etp); |
| 3005 | break; |
| 3006 | case TYPE_CODE_STRUCT: |
| 3007 | { |
| 3008 | int i; |
| 3009 | |
| 3010 | for (i = 0; i < TYPE_NFIELDS (t); i++) |
| 3011 | if (!is_float_or_hfa_type_recurse |
| 3012 | (check_typedef (TYPE_FIELD_TYPE (t, i)), etp)) |
| 3013 | return 0; |
| 3014 | return 1; |
| 3015 | } |
| 3016 | break; |
| 3017 | default: |
| 3018 | return 0; |
| 3019 | break; |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | /* Determine if the given type is one of the floating point types or |
| 3024 | and HFA (which is a struct, array, or combination thereof whose |
| 3025 | bottom-most elements are all of the same floating point type). */ |
| 3026 | |
| 3027 | static struct type * |
| 3028 | is_float_or_hfa_type (struct type *t) |
| 3029 | { |
| 3030 | struct type *et = 0; |
| 3031 | |
| 3032 | return is_float_or_hfa_type_recurse (t, &et) ? et : 0; |
| 3033 | } |
| 3034 | |
| 3035 | |
| 3036 | /* Return 1 if the alignment of T is such that the next even slot |
| 3037 | should be used. Return 0, if the next available slot should |
| 3038 | be used. (See section 8.5.1 of the IA-64 Software Conventions |
| 3039 | and Runtime manual). */ |
| 3040 | |
| 3041 | static int |
| 3042 | slot_alignment_is_next_even (struct type *t) |
| 3043 | { |
| 3044 | switch (TYPE_CODE (t)) |
| 3045 | { |
| 3046 | case TYPE_CODE_INT: |
| 3047 | case TYPE_CODE_FLT: |
| 3048 | if (TYPE_LENGTH (t) > 8) |
| 3049 | return 1; |
| 3050 | else |
| 3051 | return 0; |
| 3052 | case TYPE_CODE_ARRAY: |
| 3053 | return |
| 3054 | slot_alignment_is_next_even (check_typedef (TYPE_TARGET_TYPE (t))); |
| 3055 | case TYPE_CODE_STRUCT: |
| 3056 | { |
| 3057 | int i; |
| 3058 | |
| 3059 | for (i = 0; i < TYPE_NFIELDS (t); i++) |
| 3060 | if (slot_alignment_is_next_even |
| 3061 | (check_typedef (TYPE_FIELD_TYPE (t, i)))) |
| 3062 | return 1; |
| 3063 | return 0; |
| 3064 | } |
| 3065 | default: |
| 3066 | return 0; |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | /* Attempt to find (and return) the global pointer for the given |
| 3071 | function. |
| 3072 | |
| 3073 | This is a rather nasty bit of code searchs for the .dynamic section |
| 3074 | in the objfile corresponding to the pc of the function we're trying |
| 3075 | to call. Once it finds the addresses at which the .dynamic section |
| 3076 | lives in the child process, it scans the Elf64_Dyn entries for a |
| 3077 | DT_PLTGOT tag. If it finds one of these, the corresponding |
| 3078 | d_un.d_ptr value is the global pointer. */ |
| 3079 | |
| 3080 | static CORE_ADDR |
| 3081 | ia64_find_global_pointer (CORE_ADDR faddr) |
| 3082 | { |
| 3083 | struct obj_section *faddr_sect; |
| 3084 | |
| 3085 | faddr_sect = find_pc_section (faddr); |
| 3086 | if (faddr_sect != NULL) |
| 3087 | { |
| 3088 | struct obj_section *osect; |
| 3089 | |
| 3090 | ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect) |
| 3091 | { |
| 3092 | if (strcmp (osect->the_bfd_section->name, ".dynamic") == 0) |
| 3093 | break; |
| 3094 | } |
| 3095 | |
| 3096 | if (osect < faddr_sect->objfile->sections_end) |
| 3097 | { |
| 3098 | CORE_ADDR addr, endaddr; |
| 3099 | |
| 3100 | addr = obj_section_addr (osect); |
| 3101 | endaddr = obj_section_endaddr (osect); |
| 3102 | |
| 3103 | while (addr < endaddr) |
| 3104 | { |
| 3105 | int status; |
| 3106 | LONGEST tag; |
| 3107 | char buf[8]; |
| 3108 | |
| 3109 | status = target_read_memory (addr, buf, sizeof (buf)); |
| 3110 | if (status != 0) |
| 3111 | break; |
| 3112 | tag = extract_signed_integer (buf, sizeof (buf)); |
| 3113 | |
| 3114 | if (tag == DT_PLTGOT) |
| 3115 | { |
| 3116 | CORE_ADDR global_pointer; |
| 3117 | |
| 3118 | status = target_read_memory (addr + 8, buf, sizeof (buf)); |
| 3119 | if (status != 0) |
| 3120 | break; |
| 3121 | global_pointer = extract_unsigned_integer (buf, sizeof (buf)); |
| 3122 | |
| 3123 | /* The payoff... */ |
| 3124 | return global_pointer; |
| 3125 | } |
| 3126 | |
| 3127 | if (tag == DT_NULL) |
| 3128 | break; |
| 3129 | |
| 3130 | addr += 16; |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | return 0; |
| 3135 | } |
| 3136 | |
| 3137 | /* Given a function's address, attempt to find (and return) the |
| 3138 | corresponding (canonical) function descriptor. Return 0 if |
| 3139 | not found. */ |
| 3140 | static CORE_ADDR |
| 3141 | find_extant_func_descr (CORE_ADDR faddr) |
| 3142 | { |
| 3143 | struct obj_section *faddr_sect; |
| 3144 | |
| 3145 | /* Return early if faddr is already a function descriptor. */ |
| 3146 | faddr_sect = find_pc_section (faddr); |
| 3147 | if (faddr_sect && strcmp (faddr_sect->the_bfd_section->name, ".opd") == 0) |
| 3148 | return faddr; |
| 3149 | |
| 3150 | if (faddr_sect != NULL) |
| 3151 | { |
| 3152 | struct obj_section *osect; |
| 3153 | ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect) |
| 3154 | { |
| 3155 | if (strcmp (osect->the_bfd_section->name, ".opd") == 0) |
| 3156 | break; |
| 3157 | } |
| 3158 | |
| 3159 | if (osect < faddr_sect->objfile->sections_end) |
| 3160 | { |
| 3161 | CORE_ADDR addr, endaddr; |
| 3162 | |
| 3163 | addr = obj_section_addr (osect); |
| 3164 | endaddr = obj_section_endaddr (osect); |
| 3165 | |
| 3166 | while (addr < endaddr) |
| 3167 | { |
| 3168 | int status; |
| 3169 | LONGEST faddr2; |
| 3170 | char buf[8]; |
| 3171 | |
| 3172 | status = target_read_memory (addr, buf, sizeof (buf)); |
| 3173 | if (status != 0) |
| 3174 | break; |
| 3175 | faddr2 = extract_signed_integer (buf, sizeof (buf)); |
| 3176 | |
| 3177 | if (faddr == faddr2) |
| 3178 | return addr; |
| 3179 | |
| 3180 | addr += 16; |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | return 0; |
| 3185 | } |
| 3186 | |
| 3187 | /* Attempt to find a function descriptor corresponding to the |
| 3188 | given address. If none is found, construct one on the |
| 3189 | stack using the address at fdaptr. */ |
| 3190 | |
| 3191 | static CORE_ADDR |
| 3192 | find_func_descr (struct regcache *regcache, CORE_ADDR faddr, CORE_ADDR *fdaptr) |
| 3193 | { |
| 3194 | CORE_ADDR fdesc; |
| 3195 | |
| 3196 | fdesc = find_extant_func_descr (faddr); |
| 3197 | |
| 3198 | if (fdesc == 0) |
| 3199 | { |
| 3200 | ULONGEST global_pointer; |
| 3201 | char buf[16]; |
| 3202 | |
| 3203 | fdesc = *fdaptr; |
| 3204 | *fdaptr += 16; |
| 3205 | |
| 3206 | global_pointer = ia64_find_global_pointer (faddr); |
| 3207 | |
| 3208 | if (global_pointer == 0) |
| 3209 | regcache_cooked_read_unsigned (regcache, |
| 3210 | IA64_GR1_REGNUM, &global_pointer); |
| 3211 | |
| 3212 | store_unsigned_integer (buf, 8, faddr); |
| 3213 | store_unsigned_integer (buf + 8, 8, global_pointer); |
| 3214 | |
| 3215 | write_memory (fdesc, buf, 16); |
| 3216 | } |
| 3217 | |
| 3218 | return fdesc; |
| 3219 | } |
| 3220 | |
| 3221 | /* Use the following routine when printing out function pointers |
| 3222 | so the user can see the function address rather than just the |
| 3223 | function descriptor. */ |
| 3224 | static CORE_ADDR |
| 3225 | ia64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr, |
| 3226 | struct target_ops *targ) |
| 3227 | { |
| 3228 | struct obj_section *s; |
| 3229 | |
| 3230 | s = find_pc_section (addr); |
| 3231 | |
| 3232 | /* check if ADDR points to a function descriptor. */ |
| 3233 | if (s && strcmp (s->the_bfd_section->name, ".opd") == 0) |
| 3234 | return read_memory_unsigned_integer (addr, 8); |
| 3235 | |
| 3236 | /* Normally, functions live inside a section that is executable. |
| 3237 | So, if ADDR points to a non-executable section, then treat it |
| 3238 | as a function descriptor and return the target address iff |
| 3239 | the target address itself points to a section that is executable. */ |
| 3240 | if (s && (s->the_bfd_section->flags & SEC_CODE) == 0) |
| 3241 | { |
| 3242 | CORE_ADDR pc = read_memory_unsigned_integer (addr, 8); |
| 3243 | struct obj_section *pc_section = find_pc_section (pc); |
| 3244 | |
| 3245 | if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE)) |
| 3246 | return pc; |
| 3247 | } |
| 3248 | |
| 3249 | /* There are also descriptors embedded in vtables. */ |
| 3250 | if (s) |
| 3251 | { |
| 3252 | struct minimal_symbol *minsym; |
| 3253 | |
| 3254 | minsym = lookup_minimal_symbol_by_pc (addr); |
| 3255 | |
| 3256 | if (minsym && is_vtable_name (SYMBOL_LINKAGE_NAME (minsym))) |
| 3257 | return read_memory_unsigned_integer (addr, 8); |
| 3258 | } |
| 3259 | |
| 3260 | return addr; |
| 3261 | } |
| 3262 | |
| 3263 | static CORE_ADDR |
| 3264 | ia64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) |
| 3265 | { |
| 3266 | return sp & ~0xfLL; |
| 3267 | } |
| 3268 | |
| 3269 | static CORE_ADDR |
| 3270 | ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
| 3271 | struct regcache *regcache, CORE_ADDR bp_addr, |
| 3272 | int nargs, struct value **args, CORE_ADDR sp, |
| 3273 | int struct_return, CORE_ADDR struct_addr) |
| 3274 | { |
| 3275 | int argno; |
| 3276 | struct value *arg; |
| 3277 | struct type *type; |
| 3278 | int len, argoffset; |
| 3279 | int nslots, rseslots, memslots, slotnum, nfuncargs; |
| 3280 | int floatreg; |
| 3281 | ULONGEST bsp, cfm, pfs, new_bsp; |
| 3282 | CORE_ADDR funcdescaddr, pc, global_pointer; |
| 3283 | CORE_ADDR func_addr = find_function_addr (function, NULL); |
| 3284 | |
| 3285 | nslots = 0; |
| 3286 | nfuncargs = 0; |
| 3287 | /* Count the number of slots needed for the arguments. */ |
| 3288 | for (argno = 0; argno < nargs; argno++) |
| 3289 | { |
| 3290 | arg = args[argno]; |
| 3291 | type = check_typedef (value_type (arg)); |
| 3292 | len = TYPE_LENGTH (type); |
| 3293 | |
| 3294 | if ((nslots & 1) && slot_alignment_is_next_even (type)) |
| 3295 | nslots++; |
| 3296 | |
| 3297 | if (TYPE_CODE (type) == TYPE_CODE_FUNC) |
| 3298 | nfuncargs++; |
| 3299 | |
| 3300 | nslots += (len + 7) / 8; |
| 3301 | } |
| 3302 | |
| 3303 | /* Divvy up the slots between the RSE and the memory stack. */ |
| 3304 | rseslots = (nslots > 8) ? 8 : nslots; |
| 3305 | memslots = nslots - rseslots; |
| 3306 | |
| 3307 | /* Allocate a new RSE frame. */ |
| 3308 | regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); |
| 3309 | |
| 3310 | regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); |
| 3311 | new_bsp = rse_address_add (bsp, rseslots); |
| 3312 | regcache_cooked_write_unsigned (regcache, IA64_BSP_REGNUM, new_bsp); |
| 3313 | |
| 3314 | regcache_cooked_read_unsigned (regcache, IA64_PFS_REGNUM, &pfs); |
| 3315 | pfs &= 0xc000000000000000LL; |
| 3316 | pfs |= (cfm & 0xffffffffffffLL); |
| 3317 | regcache_cooked_write_unsigned (regcache, IA64_PFS_REGNUM, pfs); |
| 3318 | |
| 3319 | cfm &= 0xc000000000000000LL; |
| 3320 | cfm |= rseslots; |
| 3321 | regcache_cooked_write_unsigned (regcache, IA64_CFM_REGNUM, cfm); |
| 3322 | |
| 3323 | /* We will attempt to find function descriptors in the .opd segment, |
| 3324 | but if we can't we'll construct them ourselves. That being the |
| 3325 | case, we'll need to reserve space on the stack for them. */ |
| 3326 | funcdescaddr = sp - nfuncargs * 16; |
| 3327 | funcdescaddr &= ~0xfLL; |
| 3328 | |
| 3329 | /* Adjust the stack pointer to it's new value. The calling conventions |
| 3330 | require us to have 16 bytes of scratch, plus whatever space is |
| 3331 | necessary for the memory slots and our function descriptors. */ |
| 3332 | sp = sp - 16 - (memslots + nfuncargs) * 8; |
| 3333 | sp &= ~0xfLL; /* Maintain 16 byte alignment. */ |
| 3334 | |
| 3335 | /* Place the arguments where they belong. The arguments will be |
| 3336 | either placed in the RSE backing store or on the memory stack. |
| 3337 | In addition, floating point arguments or HFAs are placed in |
| 3338 | floating point registers. */ |
| 3339 | slotnum = 0; |
| 3340 | floatreg = IA64_FR8_REGNUM; |
| 3341 | for (argno = 0; argno < nargs; argno++) |
| 3342 | { |
| 3343 | struct type *float_elt_type; |
| 3344 | |
| 3345 | arg = args[argno]; |
| 3346 | type = check_typedef (value_type (arg)); |
| 3347 | len = TYPE_LENGTH (type); |
| 3348 | |
| 3349 | /* Special handling for function parameters. */ |
| 3350 | if (len == 8 |
| 3351 | && TYPE_CODE (type) == TYPE_CODE_PTR |
| 3352 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC) |
| 3353 | { |
| 3354 | char val_buf[8]; |
| 3355 | ULONGEST faddr = extract_unsigned_integer (value_contents (arg), 8); |
| 3356 | store_unsigned_integer (val_buf, 8, |
| 3357 | find_func_descr (regcache, faddr, |
| 3358 | &funcdescaddr)); |
| 3359 | if (slotnum < rseslots) |
| 3360 | write_memory (rse_address_add (bsp, slotnum), val_buf, 8); |
| 3361 | else |
| 3362 | write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8); |
| 3363 | slotnum++; |
| 3364 | continue; |
| 3365 | } |
| 3366 | |
| 3367 | /* Normal slots. */ |
| 3368 | |
| 3369 | /* Skip odd slot if necessary... */ |
| 3370 | if ((slotnum & 1) && slot_alignment_is_next_even (type)) |
| 3371 | slotnum++; |
| 3372 | |
| 3373 | argoffset = 0; |
| 3374 | while (len > 0) |
| 3375 | { |
| 3376 | char val_buf[8]; |
| 3377 | |
| 3378 | memset (val_buf, 0, 8); |
| 3379 | memcpy (val_buf, value_contents (arg) + argoffset, (len > 8) ? 8 : len); |
| 3380 | |
| 3381 | if (slotnum < rseslots) |
| 3382 | write_memory (rse_address_add (bsp, slotnum), val_buf, 8); |
| 3383 | else |
| 3384 | write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8); |
| 3385 | |
| 3386 | argoffset += 8; |
| 3387 | len -= 8; |
| 3388 | slotnum++; |
| 3389 | } |
| 3390 | |
| 3391 | /* Handle floating point types (including HFAs). */ |
| 3392 | float_elt_type = is_float_or_hfa_type (type); |
| 3393 | if (float_elt_type != NULL) |
| 3394 | { |
| 3395 | argoffset = 0; |
| 3396 | len = TYPE_LENGTH (type); |
| 3397 | while (len > 0 && floatreg < IA64_FR16_REGNUM) |
| 3398 | { |
| 3399 | char to[MAX_REGISTER_SIZE]; |
| 3400 | convert_typed_floating (value_contents (arg) + argoffset, float_elt_type, |
| 3401 | to, builtin_type_ia64_ext); |
| 3402 | regcache_cooked_write (regcache, floatreg, (void *)to); |
| 3403 | floatreg++; |
| 3404 | argoffset += TYPE_LENGTH (float_elt_type); |
| 3405 | len -= TYPE_LENGTH (float_elt_type); |
| 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | /* Store the struct return value in r8 if necessary. */ |
| 3411 | if (struct_return) |
| 3412 | { |
| 3413 | regcache_cooked_write_unsigned (regcache, IA64_GR8_REGNUM, (ULONGEST)struct_addr); |
| 3414 | } |
| 3415 | |
| 3416 | global_pointer = ia64_find_global_pointer (func_addr); |
| 3417 | |
| 3418 | if (global_pointer != 0) |
| 3419 | regcache_cooked_write_unsigned (regcache, IA64_GR1_REGNUM, global_pointer); |
| 3420 | |
| 3421 | regcache_cooked_write_unsigned (regcache, IA64_BR0_REGNUM, bp_addr); |
| 3422 | |
| 3423 | regcache_cooked_write_unsigned (regcache, sp_regnum, sp); |
| 3424 | |
| 3425 | return sp; |
| 3426 | } |
| 3427 | |
| 3428 | static struct frame_id |
| 3429 | ia64_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) |
| 3430 | { |
| 3431 | char buf[8]; |
| 3432 | CORE_ADDR sp, bsp; |
| 3433 | |
| 3434 | get_frame_register (this_frame, sp_regnum, buf); |
| 3435 | sp = extract_unsigned_integer (buf, 8); |
| 3436 | |
| 3437 | get_frame_register (this_frame, IA64_BSP_REGNUM, buf); |
| 3438 | bsp = extract_unsigned_integer (buf, 8); |
| 3439 | |
| 3440 | if (gdbarch_debug >= 1) |
| 3441 | fprintf_unfiltered (gdb_stdlog, |
| 3442 | "dummy frame id: code 0x%s, stack 0x%s, special 0x%s\n", |
| 3443 | paddr_nz (get_frame_pc (this_frame)), |
| 3444 | paddr_nz (sp), paddr_nz (bsp)); |
| 3445 | |
| 3446 | return frame_id_build_special (sp, get_frame_pc (this_frame), bsp); |
| 3447 | } |
| 3448 | |
| 3449 | static CORE_ADDR |
| 3450 | ia64_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
| 3451 | { |
| 3452 | char buf[8]; |
| 3453 | CORE_ADDR ip, psr, pc; |
| 3454 | |
| 3455 | frame_unwind_register (next_frame, IA64_IP_REGNUM, buf); |
| 3456 | ip = extract_unsigned_integer (buf, 8); |
| 3457 | frame_unwind_register (next_frame, IA64_PSR_REGNUM, buf); |
| 3458 | psr = extract_unsigned_integer (buf, 8); |
| 3459 | |
| 3460 | pc = (ip & ~0xf) | ((psr >> 41) & 3); |
| 3461 | return pc; |
| 3462 | } |
| 3463 | |
| 3464 | static int |
| 3465 | ia64_print_insn (bfd_vma memaddr, struct disassemble_info *info) |
| 3466 | { |
| 3467 | info->bytes_per_line = SLOT_MULTIPLIER; |
| 3468 | return print_insn_ia64 (memaddr, info); |
| 3469 | } |
| 3470 | |
| 3471 | static struct gdbarch * |
| 3472 | ia64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
| 3473 | { |
| 3474 | struct gdbarch *gdbarch; |
| 3475 | struct gdbarch_tdep *tdep; |
| 3476 | |
| 3477 | /* If there is already a candidate, use it. */ |
| 3478 | arches = gdbarch_list_lookup_by_info (arches, &info); |
| 3479 | if (arches != NULL) |
| 3480 | return arches->gdbarch; |
| 3481 | |
| 3482 | tdep = xmalloc (sizeof (struct gdbarch_tdep)); |
| 3483 | gdbarch = gdbarch_alloc (&info, tdep); |
| 3484 | |
| 3485 | tdep->sigcontext_register_address = 0; |
| 3486 | tdep->pc_in_sigtramp = 0; |
| 3487 | |
| 3488 | /* According to the ia64 specs, instructions that store long double |
| 3489 | floats in memory use a long-double format different than that |
| 3490 | used in the floating registers. The memory format matches the |
| 3491 | x86 extended float format which is 80 bits. An OS may choose to |
| 3492 | use this format (e.g. GNU/Linux) or choose to use a different |
| 3493 | format for storing long doubles (e.g. HPUX). In the latter case, |
| 3494 | the setting of the format may be moved/overridden in an |
| 3495 | OS-specific tdep file. */ |
| 3496 | set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext); |
| 3497 | |
| 3498 | set_gdbarch_short_bit (gdbarch, 16); |
| 3499 | set_gdbarch_int_bit (gdbarch, 32); |
| 3500 | set_gdbarch_long_bit (gdbarch, 64); |
| 3501 | set_gdbarch_long_long_bit (gdbarch, 64); |
| 3502 | set_gdbarch_float_bit (gdbarch, 32); |
| 3503 | set_gdbarch_double_bit (gdbarch, 64); |
| 3504 | set_gdbarch_long_double_bit (gdbarch, 128); |
| 3505 | set_gdbarch_ptr_bit (gdbarch, 64); |
| 3506 | |
| 3507 | set_gdbarch_num_regs (gdbarch, NUM_IA64_RAW_REGS); |
| 3508 | set_gdbarch_num_pseudo_regs (gdbarch, LAST_PSEUDO_REGNUM - FIRST_PSEUDO_REGNUM); |
| 3509 | set_gdbarch_sp_regnum (gdbarch, sp_regnum); |
| 3510 | set_gdbarch_fp0_regnum (gdbarch, IA64_FR0_REGNUM); |
| 3511 | |
| 3512 | set_gdbarch_register_name (gdbarch, ia64_register_name); |
| 3513 | set_gdbarch_register_type (gdbarch, ia64_register_type); |
| 3514 | |
| 3515 | set_gdbarch_pseudo_register_read (gdbarch, ia64_pseudo_register_read); |
| 3516 | set_gdbarch_pseudo_register_write (gdbarch, ia64_pseudo_register_write); |
| 3517 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, ia64_dwarf_reg_to_regnum); |
| 3518 | set_gdbarch_register_reggroup_p (gdbarch, ia64_register_reggroup_p); |
| 3519 | set_gdbarch_convert_register_p (gdbarch, ia64_convert_register_p); |
| 3520 | set_gdbarch_register_to_value (gdbarch, ia64_register_to_value); |
| 3521 | set_gdbarch_value_to_register (gdbarch, ia64_value_to_register); |
| 3522 | |
| 3523 | set_gdbarch_skip_prologue (gdbarch, ia64_skip_prologue); |
| 3524 | |
| 3525 | set_gdbarch_return_value (gdbarch, ia64_return_value); |
| 3526 | |
| 3527 | set_gdbarch_memory_insert_breakpoint (gdbarch, ia64_memory_insert_breakpoint); |
| 3528 | set_gdbarch_memory_remove_breakpoint (gdbarch, ia64_memory_remove_breakpoint); |
| 3529 | set_gdbarch_breakpoint_from_pc (gdbarch, ia64_breakpoint_from_pc); |
| 3530 | set_gdbarch_read_pc (gdbarch, ia64_read_pc); |
| 3531 | set_gdbarch_write_pc (gdbarch, ia64_write_pc); |
| 3532 | |
| 3533 | /* Settings for calling functions in the inferior. */ |
| 3534 | set_gdbarch_push_dummy_call (gdbarch, ia64_push_dummy_call); |
| 3535 | set_gdbarch_frame_align (gdbarch, ia64_frame_align); |
| 3536 | set_gdbarch_dummy_id (gdbarch, ia64_dummy_id); |
| 3537 | |
| 3538 | set_gdbarch_unwind_pc (gdbarch, ia64_unwind_pc); |
| 3539 | #ifdef HAVE_LIBUNWIND_IA64_H |
| 3540 | frame_unwind_append_unwinder (gdbarch, |
| 3541 | &ia64_libunwind_sigtramp_frame_unwind); |
| 3542 | frame_unwind_append_unwinder (gdbarch, &ia64_libunwind_frame_unwind); |
| 3543 | frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind); |
| 3544 | libunwind_frame_set_descr (gdbarch, &ia64_libunwind_descr); |
| 3545 | #else |
| 3546 | frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind); |
| 3547 | #endif |
| 3548 | frame_unwind_append_unwinder (gdbarch, &ia64_frame_unwind); |
| 3549 | frame_base_set_default (gdbarch, &ia64_frame_base); |
| 3550 | |
| 3551 | /* Settings that should be unnecessary. */ |
| 3552 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); |
| 3553 | |
| 3554 | set_gdbarch_print_insn (gdbarch, ia64_print_insn); |
| 3555 | set_gdbarch_convert_from_func_ptr_addr (gdbarch, ia64_convert_from_func_ptr_addr); |
| 3556 | |
| 3557 | /* The virtual table contains 16-byte descriptors, not pointers to |
| 3558 | descriptors. */ |
| 3559 | set_gdbarch_vtable_function_descriptors (gdbarch, 1); |
| 3560 | |
| 3561 | /* Hook in ABI-specific overrides, if they have been registered. */ |
| 3562 | gdbarch_init_osabi (info, gdbarch); |
| 3563 | |
| 3564 | return gdbarch; |
| 3565 | } |
| 3566 | |
| 3567 | extern initialize_file_ftype _initialize_ia64_tdep; /* -Wmissing-prototypes */ |
| 3568 | |
| 3569 | void |
| 3570 | _initialize_ia64_tdep (void) |
| 3571 | { |
| 3572 | /* Define the ia64 floating-point format to gdb. */ |
| 3573 | builtin_type_ia64_ext = |
| 3574 | init_type (TYPE_CODE_FLT, 128 / 8, |
| 3575 | 0, "builtin_type_ia64_ext", NULL); |
| 3576 | TYPE_FLOATFORMAT (builtin_type_ia64_ext) = floatformats_ia64_ext; |
| 3577 | |
| 3578 | gdbarch_register (bfd_arch_ia64, ia64_gdbarch_init, NULL); |
| 3579 | } |