GDB (API)
|
00001 /* Target-dependent code for the IA-64 for GDB, the GNU debugger. 00002 00003 Copyright (C) 1999-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "inferior.h" 00022 #include "gdbcore.h" 00023 #include "arch-utils.h" 00024 #include "floatformat.h" 00025 #include "gdbtypes.h" 00026 #include "regcache.h" 00027 #include "reggroups.h" 00028 #include "frame.h" 00029 #include "frame-base.h" 00030 #include "frame-unwind.h" 00031 #include "doublest.h" 00032 #include "value.h" 00033 #include "gdb_assert.h" 00034 #include "objfiles.h" 00035 #include "elf/common.h" /* for DT_PLTGOT value */ 00036 #include "elf-bfd.h" 00037 #include "dis-asm.h" 00038 #include "infcall.h" 00039 #include "osabi.h" 00040 #include "ia64-tdep.h" 00041 #include "cp-abi.h" 00042 00043 #ifdef HAVE_LIBUNWIND_IA64_H 00044 #include "elf/ia64.h" /* for PT_IA_64_UNWIND value */ 00045 #include "ia64-libunwind-tdep.h" 00046 00047 /* Note: KERNEL_START is supposed to be an address which is not going 00048 to ever contain any valid unwind info. For ia64 linux, the choice 00049 of 0xc000000000000000 is fairly safe since that's uncached space. 00050 00051 We use KERNEL_START as follows: after obtaining the kernel's 00052 unwind table via getunwind(), we project its unwind data into 00053 address-range KERNEL_START-(KERNEL_START+ktab_size) and then 00054 when ia64_access_mem() sees a memory access to this 00055 address-range, we redirect it to ktab instead. 00056 00057 None of this hackery is needed with a modern kernel/libcs 00058 which uses the kernel virtual DSO to provide access to the 00059 kernel's unwind info. In that case, ktab_size remains 0 and 00060 hence the value of KERNEL_START doesn't matter. */ 00061 00062 #define KERNEL_START 0xc000000000000000ULL 00063 00064 static size_t ktab_size = 0; 00065 struct ia64_table_entry 00066 { 00067 uint64_t start_offset; 00068 uint64_t end_offset; 00069 uint64_t info_offset; 00070 }; 00071 00072 static struct ia64_table_entry *ktab = NULL; 00073 00074 #endif 00075 00076 /* An enumeration of the different IA-64 instruction types. */ 00077 00078 typedef enum instruction_type 00079 { 00080 A, /* Integer ALU ; I-unit or M-unit */ 00081 I, /* Non-ALU integer; I-unit */ 00082 M, /* Memory ; M-unit */ 00083 F, /* Floating-point ; F-unit */ 00084 B, /* Branch ; B-unit */ 00085 L, /* Extended (L+X) ; I-unit */ 00086 X, /* Extended (L+X) ; I-unit */ 00087 undefined /* undefined or reserved */ 00088 } instruction_type; 00089 00090 /* We represent IA-64 PC addresses as the value of the instruction 00091 pointer or'd with some bit combination in the low nibble which 00092 represents the slot number in the bundle addressed by the 00093 instruction pointer. The problem is that the Linux kernel 00094 multiplies its slot numbers (for exceptions) by one while the 00095 disassembler multiplies its slot numbers by 6. In addition, I've 00096 heard it said that the simulator uses 1 as the multiplier. 00097 00098 I've fixed the disassembler so that the bytes_per_line field will 00099 be the slot multiplier. If bytes_per_line comes in as zero, it 00100 is set to six (which is how it was set up initially). -- objdump 00101 displays pretty disassembly dumps with this value. For our purposes, 00102 we'll set bytes_per_line to SLOT_MULTIPLIER. This is okay since we 00103 never want to also display the raw bytes the way objdump does. */ 00104 00105 #define SLOT_MULTIPLIER 1 00106 00107 /* Length in bytes of an instruction bundle. */ 00108 00109 #define BUNDLE_LEN 16 00110 00111 /* See the saved memory layout comment for ia64_memory_insert_breakpoint. */ 00112 00113 #if BREAKPOINT_MAX < BUNDLE_LEN - 2 00114 # error "BREAKPOINT_MAX < BUNDLE_LEN - 2" 00115 #endif 00116 00117 static gdbarch_init_ftype ia64_gdbarch_init; 00118 00119 static gdbarch_register_name_ftype ia64_register_name; 00120 static gdbarch_register_type_ftype ia64_register_type; 00121 static gdbarch_breakpoint_from_pc_ftype ia64_breakpoint_from_pc; 00122 static gdbarch_skip_prologue_ftype ia64_skip_prologue; 00123 static struct type *is_float_or_hfa_type (struct type *t); 00124 static CORE_ADDR ia64_find_global_pointer (struct gdbarch *gdbarch, 00125 CORE_ADDR faddr); 00126 00127 #define NUM_IA64_RAW_REGS 462 00128 00129 static int sp_regnum = IA64_GR12_REGNUM; 00130 static int fp_regnum = IA64_VFP_REGNUM; 00131 static int lr_regnum = IA64_VRAP_REGNUM; 00132 00133 /* NOTE: we treat the register stack registers r32-r127 as 00134 pseudo-registers because they may not be accessible via the ptrace 00135 register get/set interfaces. */ 00136 00137 enum pseudo_regs { FIRST_PSEUDO_REGNUM = NUM_IA64_RAW_REGS, 00138 VBOF_REGNUM = IA64_NAT127_REGNUM + 1, V32_REGNUM, 00139 V127_REGNUM = V32_REGNUM + 95, 00140 VP0_REGNUM, VP16_REGNUM = VP0_REGNUM + 16, 00141 VP63_REGNUM = VP0_REGNUM + 63, LAST_PSEUDO_REGNUM }; 00142 00143 /* Array of register names; There should be ia64_num_regs strings in 00144 the initializer. */ 00145 00146 static char *ia64_register_names[] = 00147 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 00148 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 00149 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 00150 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 00151 "", "", "", "", "", "", "", "", 00152 "", "", "", "", "", "", "", "", 00153 "", "", "", "", "", "", "", "", 00154 "", "", "", "", "", "", "", "", 00155 "", "", "", "", "", "", "", "", 00156 "", "", "", "", "", "", "", "", 00157 "", "", "", "", "", "", "", "", 00158 "", "", "", "", "", "", "", "", 00159 "", "", "", "", "", "", "", "", 00160 "", "", "", "", "", "", "", "", 00161 "", "", "", "", "", "", "", "", 00162 "", "", "", "", "", "", "", "", 00163 00164 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", 00165 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", 00166 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", 00167 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", 00168 "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39", 00169 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", 00170 "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55", 00171 "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63", 00172 "f64", "f65", "f66", "f67", "f68", "f69", "f70", "f71", 00173 "f72", "f73", "f74", "f75", "f76", "f77", "f78", "f79", 00174 "f80", "f81", "f82", "f83", "f84", "f85", "f86", "f87", 00175 "f88", "f89", "f90", "f91", "f92", "f93", "f94", "f95", 00176 "f96", "f97", "f98", "f99", "f100", "f101", "f102", "f103", 00177 "f104", "f105", "f106", "f107", "f108", "f109", "f110", "f111", 00178 "f112", "f113", "f114", "f115", "f116", "f117", "f118", "f119", 00179 "f120", "f121", "f122", "f123", "f124", "f125", "f126", "f127", 00180 00181 "", "", "", "", "", "", "", "", 00182 "", "", "", "", "", "", "", "", 00183 "", "", "", "", "", "", "", "", 00184 "", "", "", "", "", "", "", "", 00185 "", "", "", "", "", "", "", "", 00186 "", "", "", "", "", "", "", "", 00187 "", "", "", "", "", "", "", "", 00188 "", "", "", "", "", "", "", "", 00189 00190 "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", 00191 00192 "vfp", "vrap", 00193 00194 "pr", "ip", "psr", "cfm", 00195 00196 "kr0", "kr1", "kr2", "kr3", "kr4", "kr5", "kr6", "kr7", 00197 "", "", "", "", "", "", "", "", 00198 "rsc", "bsp", "bspstore", "rnat", 00199 "", "fcr", "", "", 00200 "eflag", "csd", "ssd", "cflg", "fsr", "fir", "fdr", "", 00201 "ccv", "", "", "", "unat", "", "", "", 00202 "fpsr", "", "", "", "itc", 00203 "", "", "", "", "", "", "", "", "", "", 00204 "", "", "", "", "", "", "", "", "", 00205 "pfs", "lc", "ec", 00206 "", "", "", "", "", "", "", "", "", "", 00207 "", "", "", "", "", "", "", "", "", "", 00208 "", "", "", "", "", "", "", "", "", "", 00209 "", "", "", "", "", "", "", "", "", "", 00210 "", "", "", "", "", "", "", "", "", "", 00211 "", "", "", "", "", "", "", "", "", "", 00212 "", 00213 "nat0", "nat1", "nat2", "nat3", "nat4", "nat5", "nat6", "nat7", 00214 "nat8", "nat9", "nat10", "nat11", "nat12", "nat13", "nat14", "nat15", 00215 "nat16", "nat17", "nat18", "nat19", "nat20", "nat21", "nat22", "nat23", 00216 "nat24", "nat25", "nat26", "nat27", "nat28", "nat29", "nat30", "nat31", 00217 "nat32", "nat33", "nat34", "nat35", "nat36", "nat37", "nat38", "nat39", 00218 "nat40", "nat41", "nat42", "nat43", "nat44", "nat45", "nat46", "nat47", 00219 "nat48", "nat49", "nat50", "nat51", "nat52", "nat53", "nat54", "nat55", 00220 "nat56", "nat57", "nat58", "nat59", "nat60", "nat61", "nat62", "nat63", 00221 "nat64", "nat65", "nat66", "nat67", "nat68", "nat69", "nat70", "nat71", 00222 "nat72", "nat73", "nat74", "nat75", "nat76", "nat77", "nat78", "nat79", 00223 "nat80", "nat81", "nat82", "nat83", "nat84", "nat85", "nat86", "nat87", 00224 "nat88", "nat89", "nat90", "nat91", "nat92", "nat93", "nat94", "nat95", 00225 "nat96", "nat97", "nat98", "nat99", "nat100","nat101","nat102","nat103", 00226 "nat104","nat105","nat106","nat107","nat108","nat109","nat110","nat111", 00227 "nat112","nat113","nat114","nat115","nat116","nat117","nat118","nat119", 00228 "nat120","nat121","nat122","nat123","nat124","nat125","nat126","nat127", 00229 00230 "bof", 00231 00232 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", 00233 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", 00234 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", 00235 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63", 00236 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71", 00237 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79", 00238 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87", 00239 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95", 00240 "r96", "r97", "r98", "r99", "r100", "r101", "r102", "r103", 00241 "r104", "r105", "r106", "r107", "r108", "r109", "r110", "r111", 00242 "r112", "r113", "r114", "r115", "r116", "r117", "r118", "r119", 00243 "r120", "r121", "r122", "r123", "r124", "r125", "r126", "r127", 00244 00245 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", 00246 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", 00247 "p16", "p17", "p18", "p19", "p20", "p21", "p22", "p23", 00248 "p24", "p25", "p26", "p27", "p28", "p29", "p30", "p31", 00249 "p32", "p33", "p34", "p35", "p36", "p37", "p38", "p39", 00250 "p40", "p41", "p42", "p43", "p44", "p45", "p46", "p47", 00251 "p48", "p49", "p50", "p51", "p52", "p53", "p54", "p55", 00252 "p56", "p57", "p58", "p59", "p60", "p61", "p62", "p63", 00253 }; 00254 00255 struct ia64_frame_cache 00256 { 00257 CORE_ADDR base; /* frame pointer base for frame */ 00258 CORE_ADDR pc; /* function start pc for frame */ 00259 CORE_ADDR saved_sp; /* stack pointer for frame */ 00260 CORE_ADDR bsp; /* points at r32 for the current frame */ 00261 CORE_ADDR cfm; /* cfm value for current frame */ 00262 CORE_ADDR prev_cfm; /* cfm value for previous frame */ 00263 int frameless; 00264 int sof; /* Size of frame (decoded from cfm value). */ 00265 int sol; /* Size of locals (decoded from cfm value). */ 00266 int sor; /* Number of rotating registers (decoded from 00267 cfm value). */ 00268 CORE_ADDR after_prologue; 00269 /* Address of first instruction after the last 00270 prologue instruction; Note that there may 00271 be instructions from the function's body 00272 intermingled with the prologue. */ 00273 int mem_stack_frame_size; 00274 /* Size of the memory stack frame (may be zero), 00275 or -1 if it has not been determined yet. */ 00276 int fp_reg; /* Register number (if any) used a frame pointer 00277 for this frame. 0 if no register is being used 00278 as the frame pointer. */ 00279 00280 /* Saved registers. */ 00281 CORE_ADDR saved_regs[NUM_IA64_RAW_REGS]; 00282 00283 }; 00284 00285 static int 00286 floatformat_valid (const struct floatformat *fmt, const void *from) 00287 { 00288 return 1; 00289 } 00290 00291 static const struct floatformat floatformat_ia64_ext_little = 00292 { 00293 floatformat_little, 82, 0, 1, 17, 65535, 0x1ffff, 18, 64, 00294 floatformat_intbit_yes, "floatformat_ia64_ext_little", floatformat_valid, NULL 00295 }; 00296 00297 static const struct floatformat floatformat_ia64_ext_big = 00298 { 00299 floatformat_big, 82, 46, 47, 17, 65535, 0x1ffff, 64, 64, 00300 floatformat_intbit_yes, "floatformat_ia64_ext_big", floatformat_valid 00301 }; 00302 00303 static const struct floatformat *floatformats_ia64_ext[2] = 00304 { 00305 &floatformat_ia64_ext_big, 00306 &floatformat_ia64_ext_little 00307 }; 00308 00309 static struct type * 00310 ia64_ext_type (struct gdbarch *gdbarch) 00311 { 00312 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00313 00314 if (!tdep->ia64_ext_type) 00315 tdep->ia64_ext_type 00316 = arch_float_type (gdbarch, 128, "builtin_type_ia64_ext", 00317 floatformats_ia64_ext); 00318 00319 return tdep->ia64_ext_type; 00320 } 00321 00322 static int 00323 ia64_register_reggroup_p (struct gdbarch *gdbarch, int regnum, 00324 struct reggroup *group) 00325 { 00326 int vector_p; 00327 int float_p; 00328 int raw_p; 00329 if (group == all_reggroup) 00330 return 1; 00331 vector_p = TYPE_VECTOR (register_type (gdbarch, regnum)); 00332 float_p = TYPE_CODE (register_type (gdbarch, regnum)) == TYPE_CODE_FLT; 00333 raw_p = regnum < NUM_IA64_RAW_REGS; 00334 if (group == float_reggroup) 00335 return float_p; 00336 if (group == vector_reggroup) 00337 return vector_p; 00338 if (group == general_reggroup) 00339 return (!vector_p && !float_p); 00340 if (group == save_reggroup || group == restore_reggroup) 00341 return raw_p; 00342 return 0; 00343 } 00344 00345 static const char * 00346 ia64_register_name (struct gdbarch *gdbarch, int reg) 00347 { 00348 return ia64_register_names[reg]; 00349 } 00350 00351 struct type * 00352 ia64_register_type (struct gdbarch *arch, int reg) 00353 { 00354 if (reg >= IA64_FR0_REGNUM && reg <= IA64_FR127_REGNUM) 00355 return ia64_ext_type (arch); 00356 else 00357 return builtin_type (arch)->builtin_long; 00358 } 00359 00360 static int 00361 ia64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg) 00362 { 00363 if (reg >= IA64_GR32_REGNUM && reg <= IA64_GR127_REGNUM) 00364 return V32_REGNUM + (reg - IA64_GR32_REGNUM); 00365 return reg; 00366 } 00367 00368 00369 /* Extract ``len'' bits from an instruction bundle starting at 00370 bit ``from''. */ 00371 00372 static long long 00373 extract_bit_field (const gdb_byte *bundle, int from, int len) 00374 { 00375 long long result = 0LL; 00376 int to = from + len; 00377 int from_byte = from / 8; 00378 int to_byte = to / 8; 00379 unsigned char *b = (unsigned char *) bundle; 00380 unsigned char c; 00381 int lshift; 00382 int i; 00383 00384 c = b[from_byte]; 00385 if (from_byte == to_byte) 00386 c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8); 00387 result = c >> (from % 8); 00388 lshift = 8 - (from % 8); 00389 00390 for (i = from_byte+1; i < to_byte; i++) 00391 { 00392 result |= ((long long) b[i]) << lshift; 00393 lshift += 8; 00394 } 00395 00396 if (from_byte < to_byte && (to % 8 != 0)) 00397 { 00398 c = b[to_byte]; 00399 c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8); 00400 result |= ((long long) c) << lshift; 00401 } 00402 00403 return result; 00404 } 00405 00406 /* Replace the specified bits in an instruction bundle. */ 00407 00408 static void 00409 replace_bit_field (gdb_byte *bundle, long long val, int from, int len) 00410 { 00411 int to = from + len; 00412 int from_byte = from / 8; 00413 int to_byte = to / 8; 00414 unsigned char *b = (unsigned char *) bundle; 00415 unsigned char c; 00416 00417 if (from_byte == to_byte) 00418 { 00419 unsigned char left, right; 00420 c = b[from_byte]; 00421 left = (c >> (to % 8)) << (to % 8); 00422 right = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8); 00423 c = (unsigned char) (val & 0xff); 00424 c = (unsigned char) (c << (from % 8 + 8 - to % 8)) >> (8 - to % 8); 00425 c |= right | left; 00426 b[from_byte] = c; 00427 } 00428 else 00429 { 00430 int i; 00431 c = b[from_byte]; 00432 c = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8); 00433 c = c | (val << (from % 8)); 00434 b[from_byte] = c; 00435 val >>= 8 - from % 8; 00436 00437 for (i = from_byte+1; i < to_byte; i++) 00438 { 00439 c = val & 0xff; 00440 val >>= 8; 00441 b[i] = c; 00442 } 00443 00444 if (to % 8 != 0) 00445 { 00446 unsigned char cv = (unsigned char) val; 00447 c = b[to_byte]; 00448 c = c >> (to % 8) << (to % 8); 00449 c |= ((unsigned char) (cv << (8 - to % 8))) >> (8 - to % 8); 00450 b[to_byte] = c; 00451 } 00452 } 00453 } 00454 00455 /* Return the contents of slot N (for N = 0, 1, or 2) in 00456 and instruction bundle. */ 00457 00458 static long long 00459 slotN_contents (gdb_byte *bundle, int slotnum) 00460 { 00461 return extract_bit_field (bundle, 5+41*slotnum, 41); 00462 } 00463 00464 /* Store an instruction in an instruction bundle. */ 00465 00466 static void 00467 replace_slotN_contents (gdb_byte *bundle, long long instr, int slotnum) 00468 { 00469 replace_bit_field (bundle, instr, 5+41*slotnum, 41); 00470 } 00471 00472 static const enum instruction_type template_encoding_table[32][3] = 00473 { 00474 { M, I, I }, /* 00 */ 00475 { M, I, I }, /* 01 */ 00476 { M, I, I }, /* 02 */ 00477 { M, I, I }, /* 03 */ 00478 { M, L, X }, /* 04 */ 00479 { M, L, X }, /* 05 */ 00480 { undefined, undefined, undefined }, /* 06 */ 00481 { undefined, undefined, undefined }, /* 07 */ 00482 { M, M, I }, /* 08 */ 00483 { M, M, I }, /* 09 */ 00484 { M, M, I }, /* 0A */ 00485 { M, M, I }, /* 0B */ 00486 { M, F, I }, /* 0C */ 00487 { M, F, I }, /* 0D */ 00488 { M, M, F }, /* 0E */ 00489 { M, M, F }, /* 0F */ 00490 { M, I, B }, /* 10 */ 00491 { M, I, B }, /* 11 */ 00492 { M, B, B }, /* 12 */ 00493 { M, B, B }, /* 13 */ 00494 { undefined, undefined, undefined }, /* 14 */ 00495 { undefined, undefined, undefined }, /* 15 */ 00496 { B, B, B }, /* 16 */ 00497 { B, B, B }, /* 17 */ 00498 { M, M, B }, /* 18 */ 00499 { M, M, B }, /* 19 */ 00500 { undefined, undefined, undefined }, /* 1A */ 00501 { undefined, undefined, undefined }, /* 1B */ 00502 { M, F, B }, /* 1C */ 00503 { M, F, B }, /* 1D */ 00504 { undefined, undefined, undefined }, /* 1E */ 00505 { undefined, undefined, undefined }, /* 1F */ 00506 }; 00507 00508 /* Fetch and (partially) decode an instruction at ADDR and return the 00509 address of the next instruction to fetch. */ 00510 00511 static CORE_ADDR 00512 fetch_instruction (CORE_ADDR addr, instruction_type *it, long long *instr) 00513 { 00514 gdb_byte bundle[BUNDLE_LEN]; 00515 int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER; 00516 long long template; 00517 int val; 00518 00519 /* Warn about slot numbers greater than 2. We used to generate 00520 an error here on the assumption that the user entered an invalid 00521 address. But, sometimes GDB itself requests an invalid address. 00522 This can (easily) happen when execution stops in a function for 00523 which there are no symbols. The prologue scanner will attempt to 00524 find the beginning of the function - if the nearest symbol 00525 happens to not be aligned on a bundle boundary (16 bytes), the 00526 resulting starting address will cause GDB to think that the slot 00527 number is too large. 00528 00529 So we warn about it and set the slot number to zero. It is 00530 not necessarily a fatal condition, particularly if debugging 00531 at the assembly language level. */ 00532 if (slotnum > 2) 00533 { 00534 warning (_("Can't fetch instructions for slot numbers greater than 2.\n" 00535 "Using slot 0 instead")); 00536 slotnum = 0; 00537 } 00538 00539 addr &= ~0x0f; 00540 00541 val = target_read_memory (addr, bundle, BUNDLE_LEN); 00542 00543 if (val != 0) 00544 return 0; 00545 00546 *instr = slotN_contents (bundle, slotnum); 00547 template = extract_bit_field (bundle, 0, 5); 00548 *it = template_encoding_table[(int)template][slotnum]; 00549 00550 if (slotnum == 2 || (slotnum == 1 && *it == L)) 00551 addr += 16; 00552 else 00553 addr += (slotnum + 1) * SLOT_MULTIPLIER; 00554 00555 return addr; 00556 } 00557 00558 /* There are 5 different break instructions (break.i, break.b, 00559 break.m, break.f, and break.x), but they all have the same 00560 encoding. (The five bit template in the low five bits of the 00561 instruction bundle distinguishes one from another.) 00562 00563 The runtime architecture manual specifies that break instructions 00564 used for debugging purposes must have the upper two bits of the 21 00565 bit immediate set to a 0 and a 1 respectively. A breakpoint 00566 instruction encodes the most significant bit of its 21 bit 00567 immediate at bit 36 of the 41 bit instruction. The penultimate msb 00568 is at bit 25 which leads to the pattern below. 00569 00570 Originally, I had this set up to do, e.g, a "break.i 0x80000" But 00571 it turns out that 0x80000 was used as the syscall break in the early 00572 simulators. So I changed the pattern slightly to do "break.i 0x080001" 00573 instead. But that didn't work either (I later found out that this 00574 pattern was used by the simulator that I was using.) So I ended up 00575 using the pattern seen below. 00576 00577 SHADOW_CONTENTS has byte-based addressing (PLACED_ADDRESS and SHADOW_LEN) 00578 while we need bit-based addressing as the instructions length is 41 bits and 00579 we must not modify/corrupt the adjacent slots in the same bundle. 00580 Fortunately we may store larger memory incl. the adjacent bits with the 00581 original memory content (not the possibly already stored breakpoints there). 00582 We need to be careful in ia64_memory_remove_breakpoint to always restore 00583 only the specific bits of this instruction ignoring any adjacent stored 00584 bits. 00585 00586 We use the original addressing with the low nibble in the range <0..2> which 00587 gets incorrectly interpreted by generic non-ia64 breakpoint_restore_shadows 00588 as the direct byte offset of SHADOW_CONTENTS. We store whole BUNDLE_LEN 00589 bytes just without these two possibly skipped bytes to not to exceed to the 00590 next bundle. 00591 00592 If we would like to store the whole bundle to SHADOW_CONTENTS we would have 00593 to store already the base address (`address & ~0x0f') into PLACED_ADDRESS. 00594 In such case there is no other place where to store 00595 SLOTNUM (`adress & 0x0f', value in the range <0..2>). We need to know 00596 SLOTNUM in ia64_memory_remove_breakpoint. 00597 00598 There is one special case where we need to be extra careful: 00599 L-X instructions, which are instructions that occupy 2 slots 00600 (The L part is always in slot 1, and the X part is always in 00601 slot 2). We must refuse to insert breakpoints for an address 00602 that points at slot 2 of a bundle where an L-X instruction is 00603 present, since there is logically no instruction at that address. 00604 However, to make things more interesting, the opcode of L-X 00605 instructions is located in slot 2. This means that, to insert 00606 a breakpoint at an address that points to slot 1, we actually 00607 need to write the breakpoint in slot 2! Slot 1 is actually 00608 the extended operand, so writing the breakpoint there would not 00609 have the desired effect. Another side-effect of this issue 00610 is that we need to make sure that the shadow contents buffer 00611 does save byte 15 of our instruction bundle (this is the tail 00612 end of slot 2, which wouldn't be saved if we were to insert 00613 the breakpoint in slot 1). 00614 00615 ia64 16-byte bundle layout: 00616 | 5 bits | slot 0 with 41 bits | slot 1 with 41 bits | slot 2 with 41 bits | 00617 00618 The current addressing used by the code below: 00619 original PC placed_address placed_size required covered 00620 == bp_tgt->shadow_len reqd \subset covered 00621 0xABCDE0 0xABCDE0 0x10 <0x0...0x5> <0x0..0xF> 00622 0xABCDE1 0xABCDE1 0xF <0x5...0xA> <0x1..0xF> 00623 0xABCDE2 0xABCDE2 0xE <0xA...0xF> <0x2..0xF> 00624 00625 L-X instructions are treated a little specially, as explained above: 00626 0xABCDE1 0xABCDE1 0xF <0xA...0xF> <0x1..0xF> 00627 00628 `objdump -d' and some other tools show a bit unjustified offsets: 00629 original PC byte where starts the instruction objdump offset 00630 0xABCDE0 0xABCDE0 0xABCDE0 00631 0xABCDE1 0xABCDE5 0xABCDE6 00632 0xABCDE2 0xABCDEA 0xABCDEC 00633 */ 00634 00635 #define IA64_BREAKPOINT 0x00003333300LL 00636 00637 static int 00638 ia64_memory_insert_breakpoint (struct gdbarch *gdbarch, 00639 struct bp_target_info *bp_tgt) 00640 { 00641 CORE_ADDR addr = bp_tgt->placed_address; 00642 gdb_byte bundle[BUNDLE_LEN]; 00643 int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum; 00644 long long instr_breakpoint; 00645 int val; 00646 int template; 00647 struct cleanup *cleanup; 00648 00649 if (slotnum > 2) 00650 error (_("Can't insert breakpoint for slot numbers greater than 2.")); 00651 00652 addr &= ~0x0f; 00653 00654 /* Enable the automatic memory restoration from breakpoints while 00655 we read our instruction bundle for the purpose of SHADOW_CONTENTS. 00656 Otherwise, we could possibly store into the shadow parts of the adjacent 00657 placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real 00658 breakpoint instruction bits region. */ 00659 cleanup = make_show_memory_breakpoints_cleanup (0); 00660 val = target_read_memory (addr, bundle, BUNDLE_LEN); 00661 if (val != 0) 00662 { 00663 do_cleanups (cleanup); 00664 return val; 00665 } 00666 00667 /* SHADOW_SLOTNUM saves the original slot number as expected by the caller 00668 for addressing the SHADOW_CONTENTS placement. */ 00669 shadow_slotnum = slotnum; 00670 00671 /* Always cover the last byte of the bundle in case we are inserting 00672 a breakpoint on an L-X instruction. */ 00673 bp_tgt->shadow_len = BUNDLE_LEN - shadow_slotnum; 00674 00675 template = extract_bit_field (bundle, 0, 5); 00676 if (template_encoding_table[template][slotnum] == X) 00677 { 00678 /* X unit types can only be used in slot 2, and are actually 00679 part of a 2-slot L-X instruction. We cannot break at this 00680 address, as this is the second half of an instruction that 00681 lives in slot 1 of that bundle. */ 00682 gdb_assert (slotnum == 2); 00683 error (_("Can't insert breakpoint for non-existing slot X")); 00684 } 00685 if (template_encoding_table[template][slotnum] == L) 00686 { 00687 /* L unit types can only be used in slot 1. But the associated 00688 opcode for that instruction is in slot 2, so bump the slot number 00689 accordingly. */ 00690 gdb_assert (slotnum == 1); 00691 slotnum = 2; 00692 } 00693 00694 /* Store the whole bundle, except for the initial skipped bytes by the slot 00695 number interpreted as bytes offset in PLACED_ADDRESS. */ 00696 memcpy (bp_tgt->shadow_contents, bundle + shadow_slotnum, 00697 bp_tgt->shadow_len); 00698 00699 /* Re-read the same bundle as above except that, this time, read it in order 00700 to compute the new bundle inside which we will be inserting the 00701 breakpoint. Therefore, disable the automatic memory restoration from 00702 breakpoints while we read our instruction bundle. Otherwise, the general 00703 restoration mechanism kicks in and we would possibly remove parts of the 00704 adjacent placed breakpoints. It is due to our SHADOW_CONTENTS overlapping 00705 the real breakpoint instruction bits region. */ 00706 make_show_memory_breakpoints_cleanup (1); 00707 val = target_read_memory (addr, bundle, BUNDLE_LEN); 00708 if (val != 0) 00709 { 00710 do_cleanups (cleanup); 00711 return val; 00712 } 00713 00714 /* Breakpoints already present in the code will get deteacted and not get 00715 reinserted by bp_loc_is_permanent. Multiple breakpoints at the same 00716 location cannot induce the internal error as they are optimized into 00717 a single instance by update_global_location_list. */ 00718 instr_breakpoint = slotN_contents (bundle, slotnum); 00719 if (instr_breakpoint == IA64_BREAKPOINT) 00720 internal_error (__FILE__, __LINE__, 00721 _("Address %s already contains a breakpoint."), 00722 paddress (gdbarch, bp_tgt->placed_address)); 00723 replace_slotN_contents (bundle, IA64_BREAKPOINT, slotnum); 00724 00725 bp_tgt->placed_size = bp_tgt->shadow_len; 00726 00727 val = target_write_memory (addr + shadow_slotnum, bundle + shadow_slotnum, 00728 bp_tgt->shadow_len); 00729 00730 do_cleanups (cleanup); 00731 return val; 00732 } 00733 00734 static int 00735 ia64_memory_remove_breakpoint (struct gdbarch *gdbarch, 00736 struct bp_target_info *bp_tgt) 00737 { 00738 CORE_ADDR addr = bp_tgt->placed_address; 00739 gdb_byte bundle_mem[BUNDLE_LEN], bundle_saved[BUNDLE_LEN]; 00740 int slotnum = (addr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum; 00741 long long instr_breakpoint, instr_saved; 00742 int val; 00743 int template; 00744 struct cleanup *cleanup; 00745 00746 addr &= ~0x0f; 00747 00748 /* Disable the automatic memory restoration from breakpoints while 00749 we read our instruction bundle. Otherwise, the general restoration 00750 mechanism kicks in and we would possibly remove parts of the adjacent 00751 placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real 00752 breakpoint instruction bits region. */ 00753 cleanup = make_show_memory_breakpoints_cleanup (1); 00754 val = target_read_memory (addr, bundle_mem, BUNDLE_LEN); 00755 if (val != 0) 00756 { 00757 do_cleanups (cleanup); 00758 return val; 00759 } 00760 00761 /* SHADOW_SLOTNUM saves the original slot number as expected by the caller 00762 for addressing the SHADOW_CONTENTS placement. */ 00763 shadow_slotnum = slotnum; 00764 00765 template = extract_bit_field (bundle_mem, 0, 5); 00766 if (template_encoding_table[template][slotnum] == X) 00767 { 00768 /* X unit types can only be used in slot 2, and are actually 00769 part of a 2-slot L-X instruction. We refuse to insert 00770 breakpoints at this address, so there should be no reason 00771 for us attempting to remove one there, except if the program's 00772 code somehow got modified in memory. */ 00773 gdb_assert (slotnum == 2); 00774 warning (_("Cannot remove breakpoint at address %s from non-existing " 00775 "X-type slot, memory has changed underneath"), 00776 paddress (gdbarch, bp_tgt->placed_address)); 00777 do_cleanups (cleanup); 00778 return -1; 00779 } 00780 if (template_encoding_table[template][slotnum] == L) 00781 { 00782 /* L unit types can only be used in slot 1. But the breakpoint 00783 was actually saved using slot 2, so update the slot number 00784 accordingly. */ 00785 gdb_assert (slotnum == 1); 00786 slotnum = 2; 00787 } 00788 00789 gdb_assert (bp_tgt->placed_size == BUNDLE_LEN - shadow_slotnum); 00790 gdb_assert (bp_tgt->placed_size == bp_tgt->shadow_len); 00791 00792 instr_breakpoint = slotN_contents (bundle_mem, slotnum); 00793 if (instr_breakpoint != IA64_BREAKPOINT) 00794 { 00795 warning (_("Cannot remove breakpoint at address %s, " 00796 "no break instruction at such address."), 00797 paddress (gdbarch, bp_tgt->placed_address)); 00798 do_cleanups (cleanup); 00799 return -1; 00800 } 00801 00802 /* Extract the original saved instruction from SLOTNUM normalizing its 00803 bit-shift for INSTR_SAVED. */ 00804 memcpy (bundle_saved, bundle_mem, BUNDLE_LEN); 00805 memcpy (bundle_saved + shadow_slotnum, bp_tgt->shadow_contents, 00806 bp_tgt->shadow_len); 00807 instr_saved = slotN_contents (bundle_saved, slotnum); 00808 00809 /* In BUNDLE_MEM, be careful to modify only the bits belonging to SLOTNUM 00810 and not any of the other ones that are stored in SHADOW_CONTENTS. */ 00811 replace_slotN_contents (bundle_mem, instr_saved, slotnum); 00812 val = target_write_raw_memory (addr, bundle_mem, BUNDLE_LEN); 00813 00814 do_cleanups (cleanup); 00815 return val; 00816 } 00817 00818 /* As gdbarch_breakpoint_from_pc ranges have byte granularity and ia64 00819 instruction slots ranges are bit-granular (41 bits) we have to provide an 00820 extended range as described for ia64_memory_insert_breakpoint. We also take 00821 care of preserving the `break' instruction 21-bit (or 62-bit) parameter to 00822 make a match for permanent breakpoints. */ 00823 00824 static const gdb_byte * 00825 ia64_breakpoint_from_pc (struct gdbarch *gdbarch, 00826 CORE_ADDR *pcptr, int *lenptr) 00827 { 00828 CORE_ADDR addr = *pcptr; 00829 static gdb_byte bundle[BUNDLE_LEN]; 00830 int slotnum = (int) (*pcptr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum; 00831 long long instr_fetched; 00832 int val; 00833 int template; 00834 struct cleanup *cleanup; 00835 00836 if (slotnum > 2) 00837 error (_("Can't insert breakpoint for slot numbers greater than 2.")); 00838 00839 addr &= ~0x0f; 00840 00841 /* Enable the automatic memory restoration from breakpoints while 00842 we read our instruction bundle to match bp_loc_is_permanent. */ 00843 cleanup = make_show_memory_breakpoints_cleanup (0); 00844 val = target_read_memory (addr, bundle, BUNDLE_LEN); 00845 do_cleanups (cleanup); 00846 00847 /* The memory might be unreachable. This can happen, for instance, 00848 when the user inserts a breakpoint at an invalid address. */ 00849 if (val != 0) 00850 return NULL; 00851 00852 /* SHADOW_SLOTNUM saves the original slot number as expected by the caller 00853 for addressing the SHADOW_CONTENTS placement. */ 00854 shadow_slotnum = slotnum; 00855 00856 /* Cover always the last byte of the bundle for the L-X slot case. */ 00857 *lenptr = BUNDLE_LEN - shadow_slotnum; 00858 00859 /* Check for L type instruction in slot 1, if present then bump up the slot 00860 number to the slot 2. */ 00861 template = extract_bit_field (bundle, 0, 5); 00862 if (template_encoding_table[template][slotnum] == X) 00863 { 00864 gdb_assert (slotnum == 2); 00865 error (_("Can't insert breakpoint for non-existing slot X")); 00866 } 00867 if (template_encoding_table[template][slotnum] == L) 00868 { 00869 gdb_assert (slotnum == 1); 00870 slotnum = 2; 00871 } 00872 00873 /* A break instruction has its all its opcode bits cleared except for 00874 the parameter value. For L+X slot pair we are at the X slot (slot 2) so 00875 we should not touch the L slot - the upper 41 bits of the parameter. */ 00876 instr_fetched = slotN_contents (bundle, slotnum); 00877 instr_fetched &= 0x1003ffffc0LL; 00878 replace_slotN_contents (bundle, instr_fetched, slotnum); 00879 00880 return bundle + shadow_slotnum; 00881 } 00882 00883 static CORE_ADDR 00884 ia64_read_pc (struct regcache *regcache) 00885 { 00886 ULONGEST psr_value, pc_value; 00887 int slot_num; 00888 00889 regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); 00890 regcache_cooked_read_unsigned (regcache, IA64_IP_REGNUM, &pc_value); 00891 slot_num = (psr_value >> 41) & 3; 00892 00893 return pc_value | (slot_num * SLOT_MULTIPLIER); 00894 } 00895 00896 void 00897 ia64_write_pc (struct regcache *regcache, CORE_ADDR new_pc) 00898 { 00899 int slot_num = (int) (new_pc & 0xf) / SLOT_MULTIPLIER; 00900 ULONGEST psr_value; 00901 00902 regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); 00903 psr_value &= ~(3LL << 41); 00904 psr_value |= (ULONGEST)(slot_num & 0x3) << 41; 00905 00906 new_pc &= ~0xfLL; 00907 00908 regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr_value); 00909 regcache_cooked_write_unsigned (regcache, IA64_IP_REGNUM, new_pc); 00910 } 00911 00912 #define IS_NaT_COLLECTION_ADDR(addr) ((((addr) >> 3) & 0x3f) == 0x3f) 00913 00914 /* Returns the address of the slot that's NSLOTS slots away from 00915 the address ADDR. NSLOTS may be positive or negative. */ 00916 static CORE_ADDR 00917 rse_address_add(CORE_ADDR addr, int nslots) 00918 { 00919 CORE_ADDR new_addr; 00920 int mandatory_nat_slots = nslots / 63; 00921 int direction = nslots < 0 ? -1 : 1; 00922 00923 new_addr = addr + 8 * (nslots + mandatory_nat_slots); 00924 00925 if ((new_addr >> 9) != ((addr + 8 * 64 * mandatory_nat_slots) >> 9)) 00926 new_addr += 8 * direction; 00927 00928 if (IS_NaT_COLLECTION_ADDR(new_addr)) 00929 new_addr += 8 * direction; 00930 00931 return new_addr; 00932 } 00933 00934 static enum register_status 00935 ia64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, 00936 int regnum, gdb_byte *buf) 00937 { 00938 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00939 enum register_status status; 00940 00941 if (regnum >= V32_REGNUM && regnum <= V127_REGNUM) 00942 { 00943 #ifdef HAVE_LIBUNWIND_IA64_H 00944 /* First try and use the libunwind special reg accessor, 00945 otherwise fallback to standard logic. */ 00946 if (!libunwind_is_initialized () 00947 || libunwind_get_reg_special (gdbarch, regcache, regnum, buf) != 0) 00948 #endif 00949 { 00950 /* The fallback position is to assume that r32-r127 are 00951 found sequentially in memory starting at $bof. This 00952 isn't always true, but without libunwind, this is the 00953 best we can do. */ 00954 enum register_status status; 00955 ULONGEST cfm; 00956 ULONGEST bsp; 00957 CORE_ADDR reg; 00958 00959 status = regcache_cooked_read_unsigned (regcache, 00960 IA64_BSP_REGNUM, &bsp); 00961 if (status != REG_VALID) 00962 return status; 00963 00964 status = regcache_cooked_read_unsigned (regcache, 00965 IA64_CFM_REGNUM, &cfm); 00966 if (status != REG_VALID) 00967 return status; 00968 00969 /* The bsp points at the end of the register frame so we 00970 subtract the size of frame from it to get start of 00971 register frame. */ 00972 bsp = rse_address_add (bsp, -(cfm & 0x7f)); 00973 00974 if ((cfm & 0x7f) > regnum - V32_REGNUM) 00975 { 00976 ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); 00977 reg = read_memory_integer ((CORE_ADDR)reg_addr, 8, byte_order); 00978 store_unsigned_integer (buf, register_size (gdbarch, regnum), 00979 byte_order, reg); 00980 } 00981 else 00982 store_unsigned_integer (buf, register_size (gdbarch, regnum), 00983 byte_order, 0); 00984 } 00985 } 00986 else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) 00987 { 00988 ULONGEST unatN_val; 00989 ULONGEST unat; 00990 status = regcache_cooked_read_unsigned (regcache, IA64_UNAT_REGNUM, &unat); 00991 if (status != REG_VALID) 00992 return status; 00993 unatN_val = (unat & (1LL << (regnum - IA64_NAT0_REGNUM))) != 0; 00994 store_unsigned_integer (buf, register_size (gdbarch, regnum), 00995 byte_order, unatN_val); 00996 } 00997 else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) 00998 { 00999 ULONGEST natN_val = 0; 01000 ULONGEST bsp; 01001 ULONGEST cfm; 01002 CORE_ADDR gr_addr = 0; 01003 status = regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); 01004 if (status != REG_VALID) 01005 return status; 01006 status = regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01007 if (status != REG_VALID) 01008 return status; 01009 01010 /* The bsp points at the end of the register frame so we 01011 subtract the size of frame from it to get start of register frame. */ 01012 bsp = rse_address_add (bsp, -(cfm & 0x7f)); 01013 01014 if ((cfm & 0x7f) > regnum - V32_REGNUM) 01015 gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); 01016 01017 if (gr_addr != 0) 01018 { 01019 /* Compute address of nat collection bits. */ 01020 CORE_ADDR nat_addr = gr_addr | 0x1f8; 01021 CORE_ADDR nat_collection; 01022 int nat_bit; 01023 /* If our nat collection address is bigger than bsp, we have to get 01024 the nat collection from rnat. Otherwise, we fetch the nat 01025 collection from the computed address. */ 01026 if (nat_addr >= bsp) 01027 regcache_cooked_read_unsigned (regcache, IA64_RNAT_REGNUM, 01028 &nat_collection); 01029 else 01030 nat_collection = read_memory_integer (nat_addr, 8, byte_order); 01031 nat_bit = (gr_addr >> 3) & 0x3f; 01032 natN_val = (nat_collection >> nat_bit) & 1; 01033 } 01034 01035 store_unsigned_integer (buf, register_size (gdbarch, regnum), 01036 byte_order, natN_val); 01037 } 01038 else if (regnum == VBOF_REGNUM) 01039 { 01040 /* A virtual register frame start is provided for user convenience. 01041 It can be calculated as the bsp - sof (sizeof frame). */ 01042 ULONGEST bsp, vbsp; 01043 ULONGEST cfm; 01044 status = regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); 01045 if (status != REG_VALID) 01046 return status; 01047 status = regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01048 if (status != REG_VALID) 01049 return status; 01050 01051 /* The bsp points at the end of the register frame so we 01052 subtract the size of frame from it to get beginning of frame. */ 01053 vbsp = rse_address_add (bsp, -(cfm & 0x7f)); 01054 store_unsigned_integer (buf, register_size (gdbarch, regnum), 01055 byte_order, vbsp); 01056 } 01057 else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) 01058 { 01059 ULONGEST pr; 01060 ULONGEST cfm; 01061 ULONGEST prN_val; 01062 status = regcache_cooked_read_unsigned (regcache, IA64_PR_REGNUM, &pr); 01063 if (status != REG_VALID) 01064 return status; 01065 status = regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01066 if (status != REG_VALID) 01067 return status; 01068 01069 if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) 01070 { 01071 /* Fetch predicate register rename base from current frame 01072 marker for this frame. */ 01073 int rrb_pr = (cfm >> 32) & 0x3f; 01074 01075 /* Adjust the register number to account for register rotation. */ 01076 regnum = VP16_REGNUM 01077 + ((regnum - VP16_REGNUM) + rrb_pr) % 48; 01078 } 01079 prN_val = (pr & (1LL << (regnum - VP0_REGNUM))) != 0; 01080 store_unsigned_integer (buf, register_size (gdbarch, regnum), 01081 byte_order, prN_val); 01082 } 01083 else 01084 memset (buf, 0, register_size (gdbarch, regnum)); 01085 01086 return REG_VALID; 01087 } 01088 01089 static void 01090 ia64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, 01091 int regnum, const gdb_byte *buf) 01092 { 01093 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01094 01095 if (regnum >= V32_REGNUM && regnum <= V127_REGNUM) 01096 { 01097 ULONGEST bsp; 01098 ULONGEST cfm; 01099 regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); 01100 regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01101 01102 bsp = rse_address_add (bsp, -(cfm & 0x7f)); 01103 01104 if ((cfm & 0x7f) > regnum - V32_REGNUM) 01105 { 01106 ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); 01107 write_memory (reg_addr, (void *) buf, 8); 01108 } 01109 } 01110 else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) 01111 { 01112 ULONGEST unatN_val, unat, unatN_mask; 01113 regcache_cooked_read_unsigned (regcache, IA64_UNAT_REGNUM, &unat); 01114 unatN_val = extract_unsigned_integer (buf, register_size (gdbarch, 01115 regnum), 01116 byte_order); 01117 unatN_mask = (1LL << (regnum - IA64_NAT0_REGNUM)); 01118 if (unatN_val == 0) 01119 unat &= ~unatN_mask; 01120 else if (unatN_val == 1) 01121 unat |= unatN_mask; 01122 regcache_cooked_write_unsigned (regcache, IA64_UNAT_REGNUM, unat); 01123 } 01124 else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) 01125 { 01126 ULONGEST natN_val; 01127 ULONGEST bsp; 01128 ULONGEST cfm; 01129 CORE_ADDR gr_addr = 0; 01130 regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); 01131 regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01132 01133 /* The bsp points at the end of the register frame so we 01134 subtract the size of frame from it to get start of register frame. */ 01135 bsp = rse_address_add (bsp, -(cfm & 0x7f)); 01136 01137 if ((cfm & 0x7f) > regnum - V32_REGNUM) 01138 gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM)); 01139 01140 natN_val = extract_unsigned_integer (buf, register_size (gdbarch, 01141 regnum), 01142 byte_order); 01143 01144 if (gr_addr != 0 && (natN_val == 0 || natN_val == 1)) 01145 { 01146 /* Compute address of nat collection bits. */ 01147 CORE_ADDR nat_addr = gr_addr | 0x1f8; 01148 CORE_ADDR nat_collection; 01149 int natN_bit = (gr_addr >> 3) & 0x3f; 01150 ULONGEST natN_mask = (1LL << natN_bit); 01151 /* If our nat collection address is bigger than bsp, we have to get 01152 the nat collection from rnat. Otherwise, we fetch the nat 01153 collection from the computed address. */ 01154 if (nat_addr >= bsp) 01155 { 01156 regcache_cooked_read_unsigned (regcache, 01157 IA64_RNAT_REGNUM, 01158 &nat_collection); 01159 if (natN_val) 01160 nat_collection |= natN_mask; 01161 else 01162 nat_collection &= ~natN_mask; 01163 regcache_cooked_write_unsigned (regcache, IA64_RNAT_REGNUM, 01164 nat_collection); 01165 } 01166 else 01167 { 01168 gdb_byte nat_buf[8]; 01169 nat_collection = read_memory_integer (nat_addr, 8, byte_order); 01170 if (natN_val) 01171 nat_collection |= natN_mask; 01172 else 01173 nat_collection &= ~natN_mask; 01174 store_unsigned_integer (nat_buf, register_size (gdbarch, regnum), 01175 byte_order, nat_collection); 01176 write_memory (nat_addr, nat_buf, 8); 01177 } 01178 } 01179 } 01180 else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) 01181 { 01182 ULONGEST pr; 01183 ULONGEST cfm; 01184 ULONGEST prN_val; 01185 ULONGEST prN_mask; 01186 01187 regcache_cooked_read_unsigned (regcache, IA64_PR_REGNUM, &pr); 01188 regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 01189 01190 if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) 01191 { 01192 /* Fetch predicate register rename base from current frame 01193 marker for this frame. */ 01194 int rrb_pr = (cfm >> 32) & 0x3f; 01195 01196 /* Adjust the register number to account for register rotation. */ 01197 regnum = VP16_REGNUM 01198 + ((regnum - VP16_REGNUM) + rrb_pr) % 48; 01199 } 01200 prN_val = extract_unsigned_integer (buf, register_size (gdbarch, regnum), 01201 byte_order); 01202 prN_mask = (1LL << (regnum - VP0_REGNUM)); 01203 if (prN_val == 0) 01204 pr &= ~prN_mask; 01205 else if (prN_val == 1) 01206 pr |= prN_mask; 01207 regcache_cooked_write_unsigned (regcache, IA64_PR_REGNUM, pr); 01208 } 01209 } 01210 01211 /* The ia64 needs to convert between various ieee floating-point formats 01212 and the special ia64 floating point register format. */ 01213 01214 static int 01215 ia64_convert_register_p (struct gdbarch *gdbarch, int regno, struct type *type) 01216 { 01217 return (regno >= IA64_FR0_REGNUM && regno <= IA64_FR127_REGNUM 01218 && type != ia64_ext_type (gdbarch)); 01219 } 01220 01221 static int 01222 ia64_register_to_value (struct frame_info *frame, int regnum, 01223 struct type *valtype, gdb_byte *out, 01224 int *optimizedp, int *unavailablep) 01225 { 01226 struct gdbarch *gdbarch = get_frame_arch (frame); 01227 gdb_byte in[MAX_REGISTER_SIZE]; 01228 01229 /* Convert to TYPE. */ 01230 if (!get_frame_register_bytes (frame, regnum, 0, 01231 register_size (gdbarch, regnum), 01232 in, optimizedp, unavailablep)) 01233 return 0; 01234 01235 convert_typed_floating (in, ia64_ext_type (gdbarch), out, valtype); 01236 *optimizedp = *unavailablep = 0; 01237 return 1; 01238 } 01239 01240 static void 01241 ia64_value_to_register (struct frame_info *frame, int regnum, 01242 struct type *valtype, const gdb_byte *in) 01243 { 01244 struct gdbarch *gdbarch = get_frame_arch (frame); 01245 gdb_byte out[MAX_REGISTER_SIZE]; 01246 convert_typed_floating (in, valtype, out, ia64_ext_type (gdbarch)); 01247 put_frame_register (frame, regnum, out); 01248 } 01249 01250 01251 /* Limit the number of skipped non-prologue instructions since examining 01252 of the prologue is expensive. */ 01253 static int max_skip_non_prologue_insns = 40; 01254 01255 /* Given PC representing the starting address of a function, and 01256 LIM_PC which is the (sloppy) limit to which to scan when looking 01257 for a prologue, attempt to further refine this limit by using 01258 the line data in the symbol table. If successful, a better guess 01259 on where the prologue ends is returned, otherwise the previous 01260 value of lim_pc is returned. TRUST_LIMIT is a pointer to a flag 01261 which will be set to indicate whether the returned limit may be 01262 used with no further scanning in the event that the function is 01263 frameless. */ 01264 01265 /* FIXME: cagney/2004-02-14: This function and logic have largely been 01266 superseded by skip_prologue_using_sal. */ 01267 01268 static CORE_ADDR 01269 refine_prologue_limit (CORE_ADDR pc, CORE_ADDR lim_pc, int *trust_limit) 01270 { 01271 struct symtab_and_line prologue_sal; 01272 CORE_ADDR start_pc = pc; 01273 CORE_ADDR end_pc; 01274 01275 /* The prologue can not possibly go past the function end itself, 01276 so we can already adjust LIM_PC accordingly. */ 01277 if (find_pc_partial_function (pc, NULL, NULL, &end_pc) && end_pc < lim_pc) 01278 lim_pc = end_pc; 01279 01280 /* Start off not trusting the limit. */ 01281 *trust_limit = 0; 01282 01283 prologue_sal = find_pc_line (pc, 0); 01284 if (prologue_sal.line != 0) 01285 { 01286 int i; 01287 CORE_ADDR addr = prologue_sal.end; 01288 01289 /* Handle the case in which compiler's optimizer/scheduler 01290 has moved instructions into the prologue. We scan ahead 01291 in the function looking for address ranges whose corresponding 01292 line number is less than or equal to the first one that we 01293 found for the function. (It can be less than when the 01294 scheduler puts a body instruction before the first prologue 01295 instruction.) */ 01296 for (i = 2 * max_skip_non_prologue_insns; 01297 i > 0 && (lim_pc == 0 || addr < lim_pc); 01298 i--) 01299 { 01300 struct symtab_and_line sal; 01301 01302 sal = find_pc_line (addr, 0); 01303 if (sal.line == 0) 01304 break; 01305 if (sal.line <= prologue_sal.line 01306 && sal.symtab == prologue_sal.symtab) 01307 { 01308 prologue_sal = sal; 01309 } 01310 addr = sal.end; 01311 } 01312 01313 if (lim_pc == 0 || prologue_sal.end < lim_pc) 01314 { 01315 lim_pc = prologue_sal.end; 01316 if (start_pc == get_pc_function_start (lim_pc)) 01317 *trust_limit = 1; 01318 } 01319 } 01320 return lim_pc; 01321 } 01322 01323 #define isScratch(_regnum_) ((_regnum_) == 2 || (_regnum_) == 3 \ 01324 || (8 <= (_regnum_) && (_regnum_) <= 11) \ 01325 || (14 <= (_regnum_) && (_regnum_) <= 31)) 01326 #define imm9(_instr_) \ 01327 ( ((((_instr_) & 0x01000000000LL) ? -1 : 0) << 8) \ 01328 | (((_instr_) & 0x00008000000LL) >> 20) \ 01329 | (((_instr_) & 0x00000001fc0LL) >> 6)) 01330 01331 /* Allocate and initialize a frame cache. */ 01332 01333 static struct ia64_frame_cache * 01334 ia64_alloc_frame_cache (void) 01335 { 01336 struct ia64_frame_cache *cache; 01337 int i; 01338 01339 cache = FRAME_OBSTACK_ZALLOC (struct ia64_frame_cache); 01340 01341 /* Base address. */ 01342 cache->base = 0; 01343 cache->pc = 0; 01344 cache->cfm = 0; 01345 cache->prev_cfm = 0; 01346 cache->sof = 0; 01347 cache->sol = 0; 01348 cache->sor = 0; 01349 cache->bsp = 0; 01350 cache->fp_reg = 0; 01351 cache->frameless = 1; 01352 01353 for (i = 0; i < NUM_IA64_RAW_REGS; i++) 01354 cache->saved_regs[i] = 0; 01355 01356 return cache; 01357 } 01358 01359 static CORE_ADDR 01360 examine_prologue (CORE_ADDR pc, CORE_ADDR lim_pc, 01361 struct frame_info *this_frame, 01362 struct ia64_frame_cache *cache) 01363 { 01364 CORE_ADDR next_pc; 01365 CORE_ADDR last_prologue_pc = pc; 01366 instruction_type it; 01367 long long instr; 01368 int cfm_reg = 0; 01369 int ret_reg = 0; 01370 int fp_reg = 0; 01371 int unat_save_reg = 0; 01372 int pr_save_reg = 0; 01373 int mem_stack_frame_size = 0; 01374 int spill_reg = 0; 01375 CORE_ADDR spill_addr = 0; 01376 char instores[8]; 01377 char infpstores[8]; 01378 char reg_contents[256]; 01379 int trust_limit; 01380 int frameless = 1; 01381 int i; 01382 CORE_ADDR addr; 01383 gdb_byte buf[8]; 01384 CORE_ADDR bof, sor, sol, sof, cfm, rrb_gr; 01385 01386 memset (instores, 0, sizeof instores); 01387 memset (infpstores, 0, sizeof infpstores); 01388 memset (reg_contents, 0, sizeof reg_contents); 01389 01390 if (cache->after_prologue != 0 01391 && cache->after_prologue <= lim_pc) 01392 return cache->after_prologue; 01393 01394 lim_pc = refine_prologue_limit (pc, lim_pc, &trust_limit); 01395 next_pc = fetch_instruction (pc, &it, &instr); 01396 01397 /* We want to check if we have a recognizable function start before we 01398 look ahead for a prologue. */ 01399 if (pc < lim_pc && next_pc 01400 && it == M && ((instr & 0x1ee0000003fLL) == 0x02c00000000LL)) 01401 { 01402 /* alloc - start of a regular function. */ 01403 int sor = (int) ((instr & 0x00078000000LL) >> 27); 01404 int sol = (int) ((instr & 0x00007f00000LL) >> 20); 01405 int sof = (int) ((instr & 0x000000fe000LL) >> 13); 01406 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01407 01408 /* Verify that the current cfm matches what we think is the 01409 function start. If we have somehow jumped within a function, 01410 we do not want to interpret the prologue and calculate the 01411 addresses of various registers such as the return address. 01412 We will instead treat the frame as frameless. */ 01413 if (!this_frame || 01414 (sof == (cache->cfm & 0x7f) && 01415 sol == ((cache->cfm >> 7) & 0x7f))) 01416 frameless = 0; 01417 01418 cfm_reg = rN; 01419 last_prologue_pc = next_pc; 01420 pc = next_pc; 01421 } 01422 else 01423 { 01424 /* Look for a leaf routine. */ 01425 if (pc < lim_pc && next_pc 01426 && (it == I || it == M) 01427 && ((instr & 0x1ee00000000LL) == 0x10800000000LL)) 01428 { 01429 /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */ 01430 int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13) 01431 | ((instr & 0x001f8000000LL) >> 20) 01432 | ((instr & 0x000000fe000LL) >> 13)); 01433 int rM = (int) ((instr & 0x00007f00000LL) >> 20); 01434 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01435 int qp = (int) (instr & 0x0000000003fLL); 01436 if (qp == 0 && rN == 2 && imm == 0 && rM == 12 && fp_reg == 0) 01437 { 01438 /* mov r2, r12 - beginning of leaf routine. */ 01439 fp_reg = rN; 01440 last_prologue_pc = next_pc; 01441 } 01442 } 01443 01444 /* If we don't recognize a regular function or leaf routine, we are 01445 done. */ 01446 if (!fp_reg) 01447 { 01448 pc = lim_pc; 01449 if (trust_limit) 01450 last_prologue_pc = lim_pc; 01451 } 01452 } 01453 01454 /* Loop, looking for prologue instructions, keeping track of 01455 where preserved registers were spilled. */ 01456 while (pc < lim_pc) 01457 { 01458 next_pc = fetch_instruction (pc, &it, &instr); 01459 if (next_pc == 0) 01460 break; 01461 01462 if (it == B && ((instr & 0x1e1f800003fLL) != 0x04000000000LL)) 01463 { 01464 /* Exit loop upon hitting a non-nop branch instruction. */ 01465 if (trust_limit) 01466 lim_pc = pc; 01467 break; 01468 } 01469 else if (((instr & 0x3fLL) != 0LL) && 01470 (frameless || ret_reg != 0)) 01471 { 01472 /* Exit loop upon hitting a predicated instruction if 01473 we already have the return register or if we are frameless. */ 01474 if (trust_limit) 01475 lim_pc = pc; 01476 break; 01477 } 01478 else if (it == I && ((instr & 0x1eff8000000LL) == 0x00188000000LL)) 01479 { 01480 /* Move from BR */ 01481 int b2 = (int) ((instr & 0x0000000e000LL) >> 13); 01482 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01483 int qp = (int) (instr & 0x0000000003f); 01484 01485 if (qp == 0 && b2 == 0 && rN >= 32 && ret_reg == 0) 01486 { 01487 ret_reg = rN; 01488 last_prologue_pc = next_pc; 01489 } 01490 } 01491 else if ((it == I || it == M) 01492 && ((instr & 0x1ee00000000LL) == 0x10800000000LL)) 01493 { 01494 /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */ 01495 int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13) 01496 | ((instr & 0x001f8000000LL) >> 20) 01497 | ((instr & 0x000000fe000LL) >> 13)); 01498 int rM = (int) ((instr & 0x00007f00000LL) >> 20); 01499 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01500 int qp = (int) (instr & 0x0000000003fLL); 01501 01502 if (qp == 0 && rN >= 32 && imm == 0 && rM == 12 && fp_reg == 0) 01503 { 01504 /* mov rN, r12 */ 01505 fp_reg = rN; 01506 last_prologue_pc = next_pc; 01507 } 01508 else if (qp == 0 && rN == 12 && rM == 12) 01509 { 01510 /* adds r12, -mem_stack_frame_size, r12 */ 01511 mem_stack_frame_size -= imm; 01512 last_prologue_pc = next_pc; 01513 } 01514 else if (qp == 0 && rN == 2 01515 && ((rM == fp_reg && fp_reg != 0) || rM == 12)) 01516 { 01517 gdb_byte buf[MAX_REGISTER_SIZE]; 01518 CORE_ADDR saved_sp = 0; 01519 /* adds r2, spilloffset, rFramePointer 01520 or 01521 adds r2, spilloffset, r12 01522 01523 Get ready for stf.spill or st8.spill instructions. 01524 The address to start spilling at is loaded into r2. 01525 FIXME: Why r2? That's what gcc currently uses; it 01526 could well be different for other compilers. */ 01527 01528 /* Hmm... whether or not this will work will depend on 01529 where the pc is. If it's still early in the prologue 01530 this'll be wrong. FIXME */ 01531 if (this_frame) 01532 { 01533 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01534 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01535 get_frame_register (this_frame, sp_regnum, buf); 01536 saved_sp = extract_unsigned_integer (buf, 8, byte_order); 01537 } 01538 spill_addr = saved_sp 01539 + (rM == 12 ? 0 : mem_stack_frame_size) 01540 + imm; 01541 spill_reg = rN; 01542 last_prologue_pc = next_pc; 01543 } 01544 else if (qp == 0 && rM >= 32 && rM < 40 && !instores[rM-32] && 01545 rN < 256 && imm == 0) 01546 { 01547 /* mov rN, rM where rM is an input register. */ 01548 reg_contents[rN] = rM; 01549 last_prologue_pc = next_pc; 01550 } 01551 else if (frameless && qp == 0 && rN == fp_reg && imm == 0 && 01552 rM == 2) 01553 { 01554 /* mov r12, r2 */ 01555 last_prologue_pc = next_pc; 01556 break; 01557 } 01558 } 01559 else if (it == M 01560 && ( ((instr & 0x1efc0000000LL) == 0x0eec0000000LL) 01561 || ((instr & 0x1ffc8000000LL) == 0x0cec0000000LL) )) 01562 { 01563 /* stf.spill [rN] = fM, imm9 01564 or 01565 stf.spill [rN] = fM */ 01566 01567 int imm = imm9(instr); 01568 int rN = (int) ((instr & 0x00007f00000LL) >> 20); 01569 int fM = (int) ((instr & 0x000000fe000LL) >> 13); 01570 int qp = (int) (instr & 0x0000000003fLL); 01571 if (qp == 0 && rN == spill_reg && spill_addr != 0 01572 && ((2 <= fM && fM <= 5) || (16 <= fM && fM <= 31))) 01573 { 01574 cache->saved_regs[IA64_FR0_REGNUM + fM] = spill_addr; 01575 01576 if ((instr & 0x1efc0000000LL) == 0x0eec0000000LL) 01577 spill_addr += imm; 01578 else 01579 spill_addr = 0; /* last one; must be done. */ 01580 last_prologue_pc = next_pc; 01581 } 01582 } 01583 else if ((it == M && ((instr & 0x1eff8000000LL) == 0x02110000000LL)) 01584 || (it == I && ((instr & 0x1eff8000000LL) == 0x00050000000LL)) ) 01585 { 01586 /* mov.m rN = arM 01587 or 01588 mov.i rN = arM */ 01589 01590 int arM = (int) ((instr & 0x00007f00000LL) >> 20); 01591 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01592 int qp = (int) (instr & 0x0000000003fLL); 01593 if (qp == 0 && isScratch (rN) && arM == 36 /* ar.unat */) 01594 { 01595 /* We have something like "mov.m r3 = ar.unat". Remember the 01596 r3 (or whatever) and watch for a store of this register... */ 01597 unat_save_reg = rN; 01598 last_prologue_pc = next_pc; 01599 } 01600 } 01601 else if (it == I && ((instr & 0x1eff8000000LL) == 0x00198000000LL)) 01602 { 01603 /* mov rN = pr */ 01604 int rN = (int) ((instr & 0x00000001fc0LL) >> 6); 01605 int qp = (int) (instr & 0x0000000003fLL); 01606 if (qp == 0 && isScratch (rN)) 01607 { 01608 pr_save_reg = rN; 01609 last_prologue_pc = next_pc; 01610 } 01611 } 01612 else if (it == M 01613 && ( ((instr & 0x1ffc8000000LL) == 0x08cc0000000LL) 01614 || ((instr & 0x1efc0000000LL) == 0x0acc0000000LL))) 01615 { 01616 /* st8 [rN] = rM 01617 or 01618 st8 [rN] = rM, imm9 */ 01619 int rN = (int) ((instr & 0x00007f00000LL) >> 20); 01620 int rM = (int) ((instr & 0x000000fe000LL) >> 13); 01621 int qp = (int) (instr & 0x0000000003fLL); 01622 int indirect = rM < 256 ? reg_contents[rM] : 0; 01623 if (qp == 0 && rN == spill_reg && spill_addr != 0 01624 && (rM == unat_save_reg || rM == pr_save_reg)) 01625 { 01626 /* We've found a spill of either the UNAT register or the PR 01627 register. (Well, not exactly; what we've actually found is 01628 a spill of the register that UNAT or PR was moved to). 01629 Record that fact and move on... */ 01630 if (rM == unat_save_reg) 01631 { 01632 /* Track UNAT register. */ 01633 cache->saved_regs[IA64_UNAT_REGNUM] = spill_addr; 01634 unat_save_reg = 0; 01635 } 01636 else 01637 { 01638 /* Track PR register. */ 01639 cache->saved_regs[IA64_PR_REGNUM] = spill_addr; 01640 pr_save_reg = 0; 01641 } 01642 if ((instr & 0x1efc0000000LL) == 0x0acc0000000LL) 01643 /* st8 [rN] = rM, imm9 */ 01644 spill_addr += imm9(instr); 01645 else 01646 spill_addr = 0; /* Must be done spilling. */ 01647 last_prologue_pc = next_pc; 01648 } 01649 else if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32]) 01650 { 01651 /* Allow up to one store of each input register. */ 01652 instores[rM-32] = 1; 01653 last_prologue_pc = next_pc; 01654 } 01655 else if (qp == 0 && 32 <= indirect && indirect < 40 && 01656 !instores[indirect-32]) 01657 { 01658 /* Allow an indirect store of an input register. */ 01659 instores[indirect-32] = 1; 01660 last_prologue_pc = next_pc; 01661 } 01662 } 01663 else if (it == M && ((instr & 0x1ff08000000LL) == 0x08c00000000LL)) 01664 { 01665 /* One of 01666 st1 [rN] = rM 01667 st2 [rN] = rM 01668 st4 [rN] = rM 01669 st8 [rN] = rM 01670 Note that the st8 case is handled in the clause above. 01671 01672 Advance over stores of input registers. One store per input 01673 register is permitted. */ 01674 int rM = (int) ((instr & 0x000000fe000LL) >> 13); 01675 int qp = (int) (instr & 0x0000000003fLL); 01676 int indirect = rM < 256 ? reg_contents[rM] : 0; 01677 if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32]) 01678 { 01679 instores[rM-32] = 1; 01680 last_prologue_pc = next_pc; 01681 } 01682 else if (qp == 0 && 32 <= indirect && indirect < 40 && 01683 !instores[indirect-32]) 01684 { 01685 /* Allow an indirect store of an input register. */ 01686 instores[indirect-32] = 1; 01687 last_prologue_pc = next_pc; 01688 } 01689 } 01690 else if (it == M && ((instr & 0x1ff88000000LL) == 0x0cc80000000LL)) 01691 { 01692 /* Either 01693 stfs [rN] = fM 01694 or 01695 stfd [rN] = fM 01696 01697 Advance over stores of floating point input registers. Again 01698 one store per register is permitted. */ 01699 int fM = (int) ((instr & 0x000000fe000LL) >> 13); 01700 int qp = (int) (instr & 0x0000000003fLL); 01701 if (qp == 0 && 8 <= fM && fM < 16 && !infpstores[fM - 8]) 01702 { 01703 infpstores[fM-8] = 1; 01704 last_prologue_pc = next_pc; 01705 } 01706 } 01707 else if (it == M 01708 && ( ((instr & 0x1ffc8000000LL) == 0x08ec0000000LL) 01709 || ((instr & 0x1efc0000000LL) == 0x0aec0000000LL))) 01710 { 01711 /* st8.spill [rN] = rM 01712 or 01713 st8.spill [rN] = rM, imm9 */ 01714 int rN = (int) ((instr & 0x00007f00000LL) >> 20); 01715 int rM = (int) ((instr & 0x000000fe000LL) >> 13); 01716 int qp = (int) (instr & 0x0000000003fLL); 01717 if (qp == 0 && rN == spill_reg && 4 <= rM && rM <= 7) 01718 { 01719 /* We've found a spill of one of the preserved general purpose 01720 regs. Record the spill address and advance the spill 01721 register if appropriate. */ 01722 cache->saved_regs[IA64_GR0_REGNUM + rM] = spill_addr; 01723 if ((instr & 0x1efc0000000LL) == 0x0aec0000000LL) 01724 /* st8.spill [rN] = rM, imm9 */ 01725 spill_addr += imm9(instr); 01726 else 01727 spill_addr = 0; /* Done spilling. */ 01728 last_prologue_pc = next_pc; 01729 } 01730 } 01731 01732 pc = next_pc; 01733 } 01734 01735 /* If not frameless and we aren't called by skip_prologue, then we need 01736 to calculate registers for the previous frame which will be needed 01737 later. */ 01738 01739 if (!frameless && this_frame) 01740 { 01741 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01742 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01743 01744 /* Extract the size of the rotating portion of the stack 01745 frame and the register rename base from the current 01746 frame marker. */ 01747 cfm = cache->cfm; 01748 sor = cache->sor; 01749 sof = cache->sof; 01750 sol = cache->sol; 01751 rrb_gr = (cfm >> 18) & 0x7f; 01752 01753 /* Find the bof (beginning of frame). */ 01754 bof = rse_address_add (cache->bsp, -sof); 01755 01756 for (i = 0, addr = bof; 01757 i < sof; 01758 i++, addr += 8) 01759 { 01760 if (IS_NaT_COLLECTION_ADDR (addr)) 01761 { 01762 addr += 8; 01763 } 01764 if (i+32 == cfm_reg) 01765 cache->saved_regs[IA64_CFM_REGNUM] = addr; 01766 if (i+32 == ret_reg) 01767 cache->saved_regs[IA64_VRAP_REGNUM] = addr; 01768 if (i+32 == fp_reg) 01769 cache->saved_regs[IA64_VFP_REGNUM] = addr; 01770 } 01771 01772 /* For the previous argument registers we require the previous bof. 01773 If we can't find the previous cfm, then we can do nothing. */ 01774 cfm = 0; 01775 if (cache->saved_regs[IA64_CFM_REGNUM] != 0) 01776 { 01777 cfm = read_memory_integer (cache->saved_regs[IA64_CFM_REGNUM], 01778 8, byte_order); 01779 } 01780 else if (cfm_reg != 0) 01781 { 01782 get_frame_register (this_frame, cfm_reg, buf); 01783 cfm = extract_unsigned_integer (buf, 8, byte_order); 01784 } 01785 cache->prev_cfm = cfm; 01786 01787 if (cfm != 0) 01788 { 01789 sor = ((cfm >> 14) & 0xf) * 8; 01790 sof = (cfm & 0x7f); 01791 sol = (cfm >> 7) & 0x7f; 01792 rrb_gr = (cfm >> 18) & 0x7f; 01793 01794 /* The previous bof only requires subtraction of the sol (size of 01795 locals) due to the overlap between output and input of 01796 subsequent frames. */ 01797 bof = rse_address_add (bof, -sol); 01798 01799 for (i = 0, addr = bof; 01800 i < sof; 01801 i++, addr += 8) 01802 { 01803 if (IS_NaT_COLLECTION_ADDR (addr)) 01804 { 01805 addr += 8; 01806 } 01807 if (i < sor) 01808 cache->saved_regs[IA64_GR32_REGNUM 01809 + ((i + (sor - rrb_gr)) % sor)] 01810 = addr; 01811 else 01812 cache->saved_regs[IA64_GR32_REGNUM + i] = addr; 01813 } 01814 01815 } 01816 } 01817 01818 /* Try and trust the lim_pc value whenever possible. */ 01819 if (trust_limit && lim_pc >= last_prologue_pc) 01820 last_prologue_pc = lim_pc; 01821 01822 cache->frameless = frameless; 01823 cache->after_prologue = last_prologue_pc; 01824 cache->mem_stack_frame_size = mem_stack_frame_size; 01825 cache->fp_reg = fp_reg; 01826 01827 return last_prologue_pc; 01828 } 01829 01830 CORE_ADDR 01831 ia64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) 01832 { 01833 struct ia64_frame_cache cache; 01834 cache.base = 0; 01835 cache.after_prologue = 0; 01836 cache.cfm = 0; 01837 cache.bsp = 0; 01838 01839 /* Call examine_prologue with - as third argument since we don't 01840 have a next frame pointer to send. */ 01841 return examine_prologue (pc, pc+1024, 0, &cache); 01842 } 01843 01844 01845 /* Normal frames. */ 01846 01847 static struct ia64_frame_cache * 01848 ia64_frame_cache (struct frame_info *this_frame, void **this_cache) 01849 { 01850 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01851 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01852 struct ia64_frame_cache *cache; 01853 gdb_byte buf[8]; 01854 CORE_ADDR cfm, psr; 01855 01856 if (*this_cache) 01857 return *this_cache; 01858 01859 cache = ia64_alloc_frame_cache (); 01860 *this_cache = cache; 01861 01862 get_frame_register (this_frame, sp_regnum, buf); 01863 cache->saved_sp = extract_unsigned_integer (buf, 8, byte_order); 01864 01865 /* We always want the bsp to point to the end of frame. 01866 This way, we can always get the beginning of frame (bof) 01867 by subtracting frame size. */ 01868 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 01869 cache->bsp = extract_unsigned_integer (buf, 8, byte_order); 01870 01871 get_frame_register (this_frame, IA64_PSR_REGNUM, buf); 01872 psr = extract_unsigned_integer (buf, 8, byte_order); 01873 01874 get_frame_register (this_frame, IA64_CFM_REGNUM, buf); 01875 cfm = extract_unsigned_integer (buf, 8, byte_order); 01876 01877 cache->sof = (cfm & 0x7f); 01878 cache->sol = (cfm >> 7) & 0x7f; 01879 cache->sor = ((cfm >> 14) & 0xf) * 8; 01880 01881 cache->cfm = cfm; 01882 01883 cache->pc = get_frame_func (this_frame); 01884 01885 if (cache->pc != 0) 01886 examine_prologue (cache->pc, get_frame_pc (this_frame), this_frame, cache); 01887 01888 cache->base = cache->saved_sp + cache->mem_stack_frame_size; 01889 01890 return cache; 01891 } 01892 01893 static void 01894 ia64_frame_this_id (struct frame_info *this_frame, void **this_cache, 01895 struct frame_id *this_id) 01896 { 01897 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01898 struct ia64_frame_cache *cache = 01899 ia64_frame_cache (this_frame, this_cache); 01900 01901 /* If outermost frame, mark with null frame id. */ 01902 if (cache->base != 0) 01903 (*this_id) = frame_id_build_special (cache->base, cache->pc, cache->bsp); 01904 if (gdbarch_debug >= 1) 01905 fprintf_unfiltered (gdb_stdlog, 01906 "regular frame id: code %s, stack %s, " 01907 "special %s, this_frame %s\n", 01908 paddress (gdbarch, this_id->code_addr), 01909 paddress (gdbarch, this_id->stack_addr), 01910 paddress (gdbarch, cache->bsp), 01911 host_address_to_string (this_frame)); 01912 } 01913 01914 static struct value * 01915 ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache, 01916 int regnum) 01917 { 01918 struct gdbarch *gdbarch = get_frame_arch (this_frame); 01919 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01920 struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache); 01921 gdb_byte buf[8]; 01922 01923 gdb_assert (regnum >= 0); 01924 01925 if (!target_has_registers) 01926 error (_("No registers.")); 01927 01928 if (regnum == gdbarch_sp_regnum (gdbarch)) 01929 return frame_unwind_got_constant (this_frame, regnum, cache->base); 01930 01931 else if (regnum == IA64_BSP_REGNUM) 01932 { 01933 struct value *val; 01934 CORE_ADDR prev_cfm, bsp, prev_bsp; 01935 01936 /* We want to calculate the previous bsp as the end of the previous 01937 register stack frame. This corresponds to what the hardware bsp 01938 register will be if we pop the frame back which is why we might 01939 have been called. We know the beginning of the current frame is 01940 cache->bsp - cache->sof. This value in the previous frame points 01941 to the start of the output registers. We can calculate the end of 01942 that frame by adding the size of output: 01943 (sof (size of frame) - sol (size of locals)). */ 01944 val = ia64_frame_prev_register (this_frame, this_cache, IA64_CFM_REGNUM); 01945 prev_cfm = extract_unsigned_integer (value_contents_all (val), 01946 8, byte_order); 01947 bsp = rse_address_add (cache->bsp, -(cache->sof)); 01948 prev_bsp = 01949 rse_address_add (bsp, (prev_cfm & 0x7f) - ((prev_cfm >> 7) & 0x7f)); 01950 01951 return frame_unwind_got_constant (this_frame, regnum, prev_bsp); 01952 } 01953 01954 else if (regnum == IA64_CFM_REGNUM) 01955 { 01956 CORE_ADDR addr = cache->saved_regs[IA64_CFM_REGNUM]; 01957 01958 if (addr != 0) 01959 return frame_unwind_got_memory (this_frame, regnum, addr); 01960 01961 if (cache->prev_cfm) 01962 return frame_unwind_got_constant (this_frame, regnum, cache->prev_cfm); 01963 01964 if (cache->frameless) 01965 return frame_unwind_got_register (this_frame, IA64_PFS_REGNUM, 01966 IA64_PFS_REGNUM); 01967 return frame_unwind_got_register (this_frame, regnum, 0); 01968 } 01969 01970 else if (regnum == IA64_VFP_REGNUM) 01971 { 01972 /* If the function in question uses an automatic register (r32-r127) 01973 for the frame pointer, it'll be found by ia64_find_saved_register() 01974 above. If the function lacks one of these frame pointers, we can 01975 still provide a value since we know the size of the frame. */ 01976 return frame_unwind_got_constant (this_frame, regnum, cache->base); 01977 } 01978 01979 else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) 01980 { 01981 struct value *pr_val; 01982 ULONGEST prN; 01983 01984 pr_val = ia64_frame_prev_register (this_frame, this_cache, 01985 IA64_PR_REGNUM); 01986 if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) 01987 { 01988 /* Fetch predicate register rename base from current frame 01989 marker for this frame. */ 01990 int rrb_pr = (cache->cfm >> 32) & 0x3f; 01991 01992 /* Adjust the register number to account for register rotation. */ 01993 regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48; 01994 } 01995 prN = extract_bit_field (value_contents_all (pr_val), 01996 regnum - VP0_REGNUM, 1); 01997 return frame_unwind_got_constant (this_frame, regnum, prN); 01998 } 01999 02000 else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM) 02001 { 02002 struct value *unat_val; 02003 ULONGEST unatN; 02004 unat_val = ia64_frame_prev_register (this_frame, this_cache, 02005 IA64_UNAT_REGNUM); 02006 unatN = extract_bit_field (value_contents_all (unat_val), 02007 regnum - IA64_NAT0_REGNUM, 1); 02008 return frame_unwind_got_constant (this_frame, regnum, unatN); 02009 } 02010 02011 else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) 02012 { 02013 int natval = 0; 02014 /* Find address of general register corresponding to nat bit we're 02015 interested in. */ 02016 CORE_ADDR gr_addr; 02017 02018 gr_addr = cache->saved_regs[regnum - IA64_NAT0_REGNUM + IA64_GR0_REGNUM]; 02019 02020 if (gr_addr != 0) 02021 { 02022 /* Compute address of nat collection bits. */ 02023 CORE_ADDR nat_addr = gr_addr | 0x1f8; 02024 CORE_ADDR bsp; 02025 CORE_ADDR nat_collection; 02026 int nat_bit; 02027 02028 /* If our nat collection address is bigger than bsp, we have to get 02029 the nat collection from rnat. Otherwise, we fetch the nat 02030 collection from the computed address. */ 02031 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 02032 bsp = extract_unsigned_integer (buf, 8, byte_order); 02033 if (nat_addr >= bsp) 02034 { 02035 get_frame_register (this_frame, IA64_RNAT_REGNUM, buf); 02036 nat_collection = extract_unsigned_integer (buf, 8, byte_order); 02037 } 02038 else 02039 nat_collection = read_memory_integer (nat_addr, 8, byte_order); 02040 nat_bit = (gr_addr >> 3) & 0x3f; 02041 natval = (nat_collection >> nat_bit) & 1; 02042 } 02043 02044 return frame_unwind_got_constant (this_frame, regnum, natval); 02045 } 02046 02047 else if (regnum == IA64_IP_REGNUM) 02048 { 02049 CORE_ADDR pc = 0; 02050 CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; 02051 02052 if (addr != 0) 02053 { 02054 read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); 02055 pc = extract_unsigned_integer (buf, 8, byte_order); 02056 } 02057 else if (cache->frameless) 02058 { 02059 get_frame_register (this_frame, IA64_BR0_REGNUM, buf); 02060 pc = extract_unsigned_integer (buf, 8, byte_order); 02061 } 02062 pc &= ~0xf; 02063 return frame_unwind_got_constant (this_frame, regnum, pc); 02064 } 02065 02066 else if (regnum == IA64_PSR_REGNUM) 02067 { 02068 /* We don't know how to get the complete previous PSR, but we need it 02069 for the slot information when we unwind the pc (pc is formed of IP 02070 register plus slot information from PSR). To get the previous 02071 slot information, we mask it off the return address. */ 02072 ULONGEST slot_num = 0; 02073 CORE_ADDR pc = 0; 02074 CORE_ADDR psr = 0; 02075 CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; 02076 02077 get_frame_register (this_frame, IA64_PSR_REGNUM, buf); 02078 psr = extract_unsigned_integer (buf, 8, byte_order); 02079 02080 if (addr != 0) 02081 { 02082 read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); 02083 pc = extract_unsigned_integer (buf, 8, byte_order); 02084 } 02085 else if (cache->frameless) 02086 { 02087 get_frame_register (this_frame, IA64_BR0_REGNUM, buf); 02088 pc = extract_unsigned_integer (buf, 8, byte_order); 02089 } 02090 psr &= ~(3LL << 41); 02091 slot_num = pc & 0x3LL; 02092 psr |= (CORE_ADDR)slot_num << 41; 02093 return frame_unwind_got_constant (this_frame, regnum, psr); 02094 } 02095 02096 else if (regnum == IA64_BR0_REGNUM) 02097 { 02098 CORE_ADDR addr = cache->saved_regs[IA64_BR0_REGNUM]; 02099 02100 if (addr != 0) 02101 return frame_unwind_got_memory (this_frame, regnum, addr); 02102 02103 return frame_unwind_got_constant (this_frame, regnum, 0); 02104 } 02105 02106 else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM) 02107 || (regnum >= V32_REGNUM && regnum <= V127_REGNUM)) 02108 { 02109 CORE_ADDR addr = 0; 02110 02111 if (regnum >= V32_REGNUM) 02112 regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); 02113 addr = cache->saved_regs[regnum]; 02114 if (addr != 0) 02115 return frame_unwind_got_memory (this_frame, regnum, addr); 02116 02117 if (cache->frameless) 02118 { 02119 struct value *reg_val; 02120 CORE_ADDR prev_cfm, prev_bsp, prev_bof; 02121 02122 /* FIXME: brobecker/2008-05-01: Doesn't this seem redundant 02123 with the same code above? */ 02124 if (regnum >= V32_REGNUM) 02125 regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); 02126 reg_val = ia64_frame_prev_register (this_frame, this_cache, 02127 IA64_CFM_REGNUM); 02128 prev_cfm = extract_unsigned_integer (value_contents_all (reg_val), 02129 8, byte_order); 02130 reg_val = ia64_frame_prev_register (this_frame, this_cache, 02131 IA64_BSP_REGNUM); 02132 prev_bsp = extract_unsigned_integer (value_contents_all (reg_val), 02133 8, byte_order); 02134 prev_bof = rse_address_add (prev_bsp, -(prev_cfm & 0x7f)); 02135 02136 addr = rse_address_add (prev_bof, (regnum - IA64_GR32_REGNUM)); 02137 return frame_unwind_got_memory (this_frame, regnum, addr); 02138 } 02139 02140 return frame_unwind_got_constant (this_frame, regnum, 0); 02141 } 02142 02143 else /* All other registers. */ 02144 { 02145 CORE_ADDR addr = 0; 02146 02147 if (IA64_FR32_REGNUM <= regnum && regnum <= IA64_FR127_REGNUM) 02148 { 02149 /* Fetch floating point register rename base from current 02150 frame marker for this frame. */ 02151 int rrb_fr = (cache->cfm >> 25) & 0x7f; 02152 02153 /* Adjust the floating point register number to account for 02154 register rotation. */ 02155 regnum = IA64_FR32_REGNUM 02156 + ((regnum - IA64_FR32_REGNUM) + rrb_fr) % 96; 02157 } 02158 02159 /* If we have stored a memory address, access the register. */ 02160 addr = cache->saved_regs[regnum]; 02161 if (addr != 0) 02162 return frame_unwind_got_memory (this_frame, regnum, addr); 02163 /* Otherwise, punt and get the current value of the register. */ 02164 else 02165 return frame_unwind_got_register (this_frame, regnum, regnum); 02166 } 02167 } 02168 02169 static const struct frame_unwind ia64_frame_unwind = 02170 { 02171 NORMAL_FRAME, 02172 default_frame_unwind_stop_reason, 02173 &ia64_frame_this_id, 02174 &ia64_frame_prev_register, 02175 NULL, 02176 default_frame_sniffer 02177 }; 02178 02179 /* Signal trampolines. */ 02180 02181 static void 02182 ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame, 02183 struct ia64_frame_cache *cache) 02184 { 02185 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02186 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 02187 02188 if (tdep->sigcontext_register_address) 02189 { 02190 int regno; 02191 02192 cache->saved_regs[IA64_VRAP_REGNUM] 02193 = tdep->sigcontext_register_address (gdbarch, cache->base, 02194 IA64_IP_REGNUM); 02195 cache->saved_regs[IA64_CFM_REGNUM] 02196 = tdep->sigcontext_register_address (gdbarch, cache->base, 02197 IA64_CFM_REGNUM); 02198 cache->saved_regs[IA64_PSR_REGNUM] 02199 = tdep->sigcontext_register_address (gdbarch, cache->base, 02200 IA64_PSR_REGNUM); 02201 cache->saved_regs[IA64_BSP_REGNUM] 02202 = tdep->sigcontext_register_address (gdbarch, cache->base, 02203 IA64_BSP_REGNUM); 02204 cache->saved_regs[IA64_RNAT_REGNUM] 02205 = tdep->sigcontext_register_address (gdbarch, cache->base, 02206 IA64_RNAT_REGNUM); 02207 cache->saved_regs[IA64_CCV_REGNUM] 02208 = tdep->sigcontext_register_address (gdbarch, cache->base, 02209 IA64_CCV_REGNUM); 02210 cache->saved_regs[IA64_UNAT_REGNUM] 02211 = tdep->sigcontext_register_address (gdbarch, cache->base, 02212 IA64_UNAT_REGNUM); 02213 cache->saved_regs[IA64_FPSR_REGNUM] 02214 = tdep->sigcontext_register_address (gdbarch, cache->base, 02215 IA64_FPSR_REGNUM); 02216 cache->saved_regs[IA64_PFS_REGNUM] 02217 = tdep->sigcontext_register_address (gdbarch, cache->base, 02218 IA64_PFS_REGNUM); 02219 cache->saved_regs[IA64_LC_REGNUM] 02220 = tdep->sigcontext_register_address (gdbarch, cache->base, 02221 IA64_LC_REGNUM); 02222 02223 for (regno = IA64_GR1_REGNUM; regno <= IA64_GR31_REGNUM; regno++) 02224 cache->saved_regs[regno] = 02225 tdep->sigcontext_register_address (gdbarch, cache->base, regno); 02226 for (regno = IA64_BR0_REGNUM; regno <= IA64_BR7_REGNUM; regno++) 02227 cache->saved_regs[regno] = 02228 tdep->sigcontext_register_address (gdbarch, cache->base, regno); 02229 for (regno = IA64_FR2_REGNUM; regno <= IA64_FR31_REGNUM; regno++) 02230 cache->saved_regs[regno] = 02231 tdep->sigcontext_register_address (gdbarch, cache->base, regno); 02232 } 02233 } 02234 02235 static struct ia64_frame_cache * 02236 ia64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache) 02237 { 02238 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02239 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02240 struct ia64_frame_cache *cache; 02241 gdb_byte buf[8]; 02242 02243 if (*this_cache) 02244 return *this_cache; 02245 02246 cache = ia64_alloc_frame_cache (); 02247 02248 get_frame_register (this_frame, sp_regnum, buf); 02249 /* Note that frame size is hard-coded below. We cannot calculate it 02250 via prologue examination. */ 02251 cache->base = extract_unsigned_integer (buf, 8, byte_order) + 16; 02252 02253 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 02254 cache->bsp = extract_unsigned_integer (buf, 8, byte_order); 02255 02256 get_frame_register (this_frame, IA64_CFM_REGNUM, buf); 02257 cache->cfm = extract_unsigned_integer (buf, 8, byte_order); 02258 cache->sof = cache->cfm & 0x7f; 02259 02260 ia64_sigtramp_frame_init_saved_regs (this_frame, cache); 02261 02262 *this_cache = cache; 02263 return cache; 02264 } 02265 02266 static void 02267 ia64_sigtramp_frame_this_id (struct frame_info *this_frame, 02268 void **this_cache, struct frame_id *this_id) 02269 { 02270 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02271 struct ia64_frame_cache *cache = 02272 ia64_sigtramp_frame_cache (this_frame, this_cache); 02273 02274 (*this_id) = frame_id_build_special (cache->base, 02275 get_frame_pc (this_frame), 02276 cache->bsp); 02277 if (gdbarch_debug >= 1) 02278 fprintf_unfiltered (gdb_stdlog, 02279 "sigtramp frame id: code %s, stack %s, " 02280 "special %s, this_frame %s\n", 02281 paddress (gdbarch, this_id->code_addr), 02282 paddress (gdbarch, this_id->stack_addr), 02283 paddress (gdbarch, cache->bsp), 02284 host_address_to_string (this_frame)); 02285 } 02286 02287 static struct value * 02288 ia64_sigtramp_frame_prev_register (struct frame_info *this_frame, 02289 void **this_cache, int regnum) 02290 { 02291 gdb_byte buf[MAX_REGISTER_SIZE]; 02292 02293 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02294 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02295 struct ia64_frame_cache *cache = 02296 ia64_sigtramp_frame_cache (this_frame, this_cache); 02297 02298 gdb_assert (regnum >= 0); 02299 02300 if (!target_has_registers) 02301 error (_("No registers.")); 02302 02303 if (regnum == IA64_IP_REGNUM) 02304 { 02305 CORE_ADDR pc = 0; 02306 CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM]; 02307 02308 if (addr != 0) 02309 { 02310 read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM)); 02311 pc = extract_unsigned_integer (buf, 8, byte_order); 02312 } 02313 pc &= ~0xf; 02314 return frame_unwind_got_constant (this_frame, regnum, pc); 02315 } 02316 02317 else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM) 02318 || (regnum >= V32_REGNUM && regnum <= V127_REGNUM)) 02319 { 02320 CORE_ADDR addr = 0; 02321 02322 if (regnum >= V32_REGNUM) 02323 regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM); 02324 addr = cache->saved_regs[regnum]; 02325 if (addr != 0) 02326 return frame_unwind_got_memory (this_frame, regnum, addr); 02327 02328 return frame_unwind_got_constant (this_frame, regnum, 0); 02329 } 02330 02331 else /* All other registers not listed above. */ 02332 { 02333 CORE_ADDR addr = cache->saved_regs[regnum]; 02334 02335 if (addr != 0) 02336 return frame_unwind_got_memory (this_frame, regnum, addr); 02337 02338 return frame_unwind_got_constant (this_frame, regnum, 0); 02339 } 02340 } 02341 02342 static int 02343 ia64_sigtramp_frame_sniffer (const struct frame_unwind *self, 02344 struct frame_info *this_frame, 02345 void **this_cache) 02346 { 02347 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame)); 02348 if (tdep->pc_in_sigtramp) 02349 { 02350 CORE_ADDR pc = get_frame_pc (this_frame); 02351 02352 if (tdep->pc_in_sigtramp (pc)) 02353 return 1; 02354 } 02355 02356 return 0; 02357 } 02358 02359 static const struct frame_unwind ia64_sigtramp_frame_unwind = 02360 { 02361 SIGTRAMP_FRAME, 02362 default_frame_unwind_stop_reason, 02363 ia64_sigtramp_frame_this_id, 02364 ia64_sigtramp_frame_prev_register, 02365 NULL, 02366 ia64_sigtramp_frame_sniffer 02367 }; 02368 02369 02370 02371 static CORE_ADDR 02372 ia64_frame_base_address (struct frame_info *this_frame, void **this_cache) 02373 { 02374 struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache); 02375 02376 return cache->base; 02377 } 02378 02379 static const struct frame_base ia64_frame_base = 02380 { 02381 &ia64_frame_unwind, 02382 ia64_frame_base_address, 02383 ia64_frame_base_address, 02384 ia64_frame_base_address 02385 }; 02386 02387 #ifdef HAVE_LIBUNWIND_IA64_H 02388 02389 struct ia64_unwind_table_entry 02390 { 02391 unw_word_t start_offset; 02392 unw_word_t end_offset; 02393 unw_word_t info_offset; 02394 }; 02395 02396 static __inline__ uint64_t 02397 ia64_rse_slot_num (uint64_t addr) 02398 { 02399 return (addr >> 3) & 0x3f; 02400 } 02401 02402 /* Skip over a designated number of registers in the backing 02403 store, remembering every 64th position is for NAT. */ 02404 static __inline__ uint64_t 02405 ia64_rse_skip_regs (uint64_t addr, long num_regs) 02406 { 02407 long delta = ia64_rse_slot_num(addr) + num_regs; 02408 02409 if (num_regs < 0) 02410 delta -= 0x3e; 02411 return addr + ((num_regs + delta/0x3f) << 3); 02412 } 02413 02414 /* Gdb ia64-libunwind-tdep callback function to convert from an ia64 gdb 02415 register number to a libunwind register number. */ 02416 static int 02417 ia64_gdb2uw_regnum (int regnum) 02418 { 02419 if (regnum == sp_regnum) 02420 return UNW_IA64_SP; 02421 else if (regnum == IA64_BSP_REGNUM) 02422 return UNW_IA64_BSP; 02423 else if ((unsigned) (regnum - IA64_GR0_REGNUM) < 128) 02424 return UNW_IA64_GR + (regnum - IA64_GR0_REGNUM); 02425 else if ((unsigned) (regnum - V32_REGNUM) < 95) 02426 return UNW_IA64_GR + 32 + (regnum - V32_REGNUM); 02427 else if ((unsigned) (regnum - IA64_FR0_REGNUM) < 128) 02428 return UNW_IA64_FR + (regnum - IA64_FR0_REGNUM); 02429 else if ((unsigned) (regnum - IA64_PR0_REGNUM) < 64) 02430 return -1; 02431 else if ((unsigned) (regnum - IA64_BR0_REGNUM) < 8) 02432 return UNW_IA64_BR + (regnum - IA64_BR0_REGNUM); 02433 else if (regnum == IA64_PR_REGNUM) 02434 return UNW_IA64_PR; 02435 else if (regnum == IA64_IP_REGNUM) 02436 return UNW_REG_IP; 02437 else if (regnum == IA64_CFM_REGNUM) 02438 return UNW_IA64_CFM; 02439 else if ((unsigned) (regnum - IA64_AR0_REGNUM) < 128) 02440 return UNW_IA64_AR + (regnum - IA64_AR0_REGNUM); 02441 else if ((unsigned) (regnum - IA64_NAT0_REGNUM) < 128) 02442 return UNW_IA64_NAT + (regnum - IA64_NAT0_REGNUM); 02443 else 02444 return -1; 02445 } 02446 02447 /* Gdb ia64-libunwind-tdep callback function to convert from a libunwind 02448 register number to a ia64 gdb register number. */ 02449 static int 02450 ia64_uw2gdb_regnum (int uw_regnum) 02451 { 02452 if (uw_regnum == UNW_IA64_SP) 02453 return sp_regnum; 02454 else if (uw_regnum == UNW_IA64_BSP) 02455 return IA64_BSP_REGNUM; 02456 else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 32) 02457 return IA64_GR0_REGNUM + (uw_regnum - UNW_IA64_GR); 02458 else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 128) 02459 return V32_REGNUM + (uw_regnum - (IA64_GR0_REGNUM + 32)); 02460 else if ((unsigned) (uw_regnum - UNW_IA64_FR) < 128) 02461 return IA64_FR0_REGNUM + (uw_regnum - UNW_IA64_FR); 02462 else if ((unsigned) (uw_regnum - UNW_IA64_BR) < 8) 02463 return IA64_BR0_REGNUM + (uw_regnum - UNW_IA64_BR); 02464 else if (uw_regnum == UNW_IA64_PR) 02465 return IA64_PR_REGNUM; 02466 else if (uw_regnum == UNW_REG_IP) 02467 return IA64_IP_REGNUM; 02468 else if (uw_regnum == UNW_IA64_CFM) 02469 return IA64_CFM_REGNUM; 02470 else if ((unsigned) (uw_regnum - UNW_IA64_AR) < 128) 02471 return IA64_AR0_REGNUM + (uw_regnum - UNW_IA64_AR); 02472 else if ((unsigned) (uw_regnum - UNW_IA64_NAT) < 128) 02473 return IA64_NAT0_REGNUM + (uw_regnum - UNW_IA64_NAT); 02474 else 02475 return -1; 02476 } 02477 02478 /* Gdb ia64-libunwind-tdep callback function to reveal if register is 02479 a float register or not. */ 02480 static int 02481 ia64_is_fpreg (int uw_regnum) 02482 { 02483 return unw_is_fpreg (uw_regnum); 02484 } 02485 02486 /* Libunwind callback accessor function for general registers. */ 02487 static int 02488 ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val, 02489 int write, void *arg) 02490 { 02491 int regnum = ia64_uw2gdb_regnum (uw_regnum); 02492 unw_word_t bsp, sof, sol, cfm, psr, ip; 02493 struct frame_info *this_frame = arg; 02494 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02495 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02496 long new_sof, old_sof; 02497 gdb_byte buf[MAX_REGISTER_SIZE]; 02498 02499 /* We never call any libunwind routines that need to write registers. */ 02500 gdb_assert (!write); 02501 02502 switch (uw_regnum) 02503 { 02504 case UNW_REG_IP: 02505 /* Libunwind expects to see the pc value which means the slot number 02506 from the psr must be merged with the ip word address. */ 02507 get_frame_register (this_frame, IA64_IP_REGNUM, buf); 02508 ip = extract_unsigned_integer (buf, 8, byte_order); 02509 get_frame_register (this_frame, IA64_PSR_REGNUM, buf); 02510 psr = extract_unsigned_integer (buf, 8, byte_order); 02511 *val = ip | ((psr >> 41) & 0x3); 02512 break; 02513 02514 case UNW_IA64_AR_BSP: 02515 /* Libunwind expects to see the beginning of the current 02516 register frame so we must account for the fact that 02517 ptrace() will return a value for bsp that points *after* 02518 the current register frame. */ 02519 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 02520 bsp = extract_unsigned_integer (buf, 8, byte_order); 02521 get_frame_register (this_frame, IA64_CFM_REGNUM, buf); 02522 cfm = extract_unsigned_integer (buf, 8, byte_order); 02523 sof = gdbarch_tdep (gdbarch)->size_of_register_frame (this_frame, cfm); 02524 *val = ia64_rse_skip_regs (bsp, -sof); 02525 break; 02526 02527 case UNW_IA64_AR_BSPSTORE: 02528 /* Libunwind wants bspstore to be after the current register frame. 02529 This is what ptrace() and gdb treats as the regular bsp value. */ 02530 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 02531 *val = extract_unsigned_integer (buf, 8, byte_order); 02532 break; 02533 02534 default: 02535 /* For all other registers, just unwind the value directly. */ 02536 get_frame_register (this_frame, regnum, buf); 02537 *val = extract_unsigned_integer (buf, 8, byte_order); 02538 break; 02539 } 02540 02541 if (gdbarch_debug >= 1) 02542 fprintf_unfiltered (gdb_stdlog, 02543 " access_reg: from cache: %4s=%s\n", 02544 (((unsigned) regnum <= IA64_NAT127_REGNUM) 02545 ? ia64_register_names[regnum] : "r??"), 02546 paddress (gdbarch, *val)); 02547 return 0; 02548 } 02549 02550 /* Libunwind callback accessor function for floating-point registers. */ 02551 static int 02552 ia64_access_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum, 02553 unw_fpreg_t *val, int write, void *arg) 02554 { 02555 int regnum = ia64_uw2gdb_regnum (uw_regnum); 02556 struct frame_info *this_frame = arg; 02557 02558 /* We never call any libunwind routines that need to write registers. */ 02559 gdb_assert (!write); 02560 02561 get_frame_register (this_frame, regnum, (gdb_byte *) val); 02562 02563 return 0; 02564 } 02565 02566 /* Libunwind callback accessor function for top-level rse registers. */ 02567 static int 02568 ia64_access_rse_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, 02569 unw_word_t *val, int write, void *arg) 02570 { 02571 int regnum = ia64_uw2gdb_regnum (uw_regnum); 02572 unw_word_t bsp, sof, sol, cfm, psr, ip; 02573 struct regcache *regcache = arg; 02574 struct gdbarch *gdbarch = get_regcache_arch (regcache); 02575 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02576 long new_sof, old_sof; 02577 gdb_byte buf[MAX_REGISTER_SIZE]; 02578 02579 /* We never call any libunwind routines that need to write registers. */ 02580 gdb_assert (!write); 02581 02582 switch (uw_regnum) 02583 { 02584 case UNW_REG_IP: 02585 /* Libunwind expects to see the pc value which means the slot number 02586 from the psr must be merged with the ip word address. */ 02587 regcache_cooked_read (regcache, IA64_IP_REGNUM, buf); 02588 ip = extract_unsigned_integer (buf, 8, byte_order); 02589 regcache_cooked_read (regcache, IA64_PSR_REGNUM, buf); 02590 psr = extract_unsigned_integer (buf, 8, byte_order); 02591 *val = ip | ((psr >> 41) & 0x3); 02592 break; 02593 02594 case UNW_IA64_AR_BSP: 02595 /* Libunwind expects to see the beginning of the current 02596 register frame so we must account for the fact that 02597 ptrace() will return a value for bsp that points *after* 02598 the current register frame. */ 02599 regcache_cooked_read (regcache, IA64_BSP_REGNUM, buf); 02600 bsp = extract_unsigned_integer (buf, 8, byte_order); 02601 regcache_cooked_read (regcache, IA64_CFM_REGNUM, buf); 02602 cfm = extract_unsigned_integer (buf, 8, byte_order); 02603 sof = (cfm & 0x7f); 02604 *val = ia64_rse_skip_regs (bsp, -sof); 02605 break; 02606 02607 case UNW_IA64_AR_BSPSTORE: 02608 /* Libunwind wants bspstore to be after the current register frame. 02609 This is what ptrace() and gdb treats as the regular bsp value. */ 02610 regcache_cooked_read (regcache, IA64_BSP_REGNUM, buf); 02611 *val = extract_unsigned_integer (buf, 8, byte_order); 02612 break; 02613 02614 default: 02615 /* For all other registers, just unwind the value directly. */ 02616 regcache_cooked_read (regcache, regnum, buf); 02617 *val = extract_unsigned_integer (buf, 8, byte_order); 02618 break; 02619 } 02620 02621 if (gdbarch_debug >= 1) 02622 fprintf_unfiltered (gdb_stdlog, 02623 " access_rse_reg: from cache: %4s=%s\n", 02624 (((unsigned) regnum <= IA64_NAT127_REGNUM) 02625 ? ia64_register_names[regnum] : "r??"), 02626 paddress (gdbarch, *val)); 02627 02628 return 0; 02629 } 02630 02631 /* Libunwind callback accessor function for top-level fp registers. */ 02632 static int 02633 ia64_access_rse_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum, 02634 unw_fpreg_t *val, int write, void *arg) 02635 { 02636 int regnum = ia64_uw2gdb_regnum (uw_regnum); 02637 struct regcache *regcache = arg; 02638 02639 /* We never call any libunwind routines that need to write registers. */ 02640 gdb_assert (!write); 02641 02642 regcache_cooked_read (regcache, regnum, (gdb_byte *) val); 02643 02644 return 0; 02645 } 02646 02647 /* Libunwind callback accessor function for accessing memory. */ 02648 static int 02649 ia64_access_mem (unw_addr_space_t as, 02650 unw_word_t addr, unw_word_t *val, 02651 int write, void *arg) 02652 { 02653 if (addr - KERNEL_START < ktab_size) 02654 { 02655 unw_word_t *laddr = (unw_word_t*) ((char *) ktab 02656 + (addr - KERNEL_START)); 02657 02658 if (write) 02659 *laddr = *val; 02660 else 02661 *val = *laddr; 02662 return 0; 02663 } 02664 02665 /* XXX do we need to normalize byte-order here? */ 02666 if (write) 02667 return target_write_memory (addr, (gdb_byte *) val, sizeof (unw_word_t)); 02668 else 02669 return target_read_memory (addr, (gdb_byte *) val, sizeof (unw_word_t)); 02670 } 02671 02672 /* Call low-level function to access the kernel unwind table. */ 02673 static LONGEST 02674 getunwind_table (gdb_byte **buf_p) 02675 { 02676 LONGEST x; 02677 02678 /* FIXME drow/2005-09-10: This code used to call 02679 ia64_linux_xfer_unwind_table directly to fetch the unwind table 02680 for the currently running ia64-linux kernel. That data should 02681 come from the core file and be accessed via the auxv vector; if 02682 we want to preserve fall back to the running kernel's table, then 02683 we should find a way to override the corefile layer's 02684 xfer_partial method. */ 02685 02686 x = target_read_alloc (¤t_target, TARGET_OBJECT_UNWIND_TABLE, 02687 NULL, buf_p); 02688 02689 return x; 02690 } 02691 02692 /* Get the kernel unwind table. */ 02693 static int 02694 get_kernel_table (unw_word_t ip, unw_dyn_info_t *di) 02695 { 02696 static struct ia64_table_entry *etab; 02697 02698 if (!ktab) 02699 { 02700 gdb_byte *ktab_buf; 02701 LONGEST size; 02702 02703 size = getunwind_table (&ktab_buf); 02704 if (size <= 0) 02705 return -UNW_ENOINFO; 02706 02707 ktab = (struct ia64_table_entry *) ktab_buf; 02708 ktab_size = size; 02709 02710 for (etab = ktab; etab->start_offset; ++etab) 02711 etab->info_offset += KERNEL_START; 02712 } 02713 02714 if (ip < ktab[0].start_offset || ip >= etab[-1].end_offset) 02715 return -UNW_ENOINFO; 02716 02717 di->format = UNW_INFO_FORMAT_TABLE; 02718 di->gp = 0; 02719 di->start_ip = ktab[0].start_offset; 02720 di->end_ip = etab[-1].end_offset; 02721 di->u.ti.name_ptr = (unw_word_t) "<kernel>"; 02722 di->u.ti.segbase = 0; 02723 di->u.ti.table_len = ((char *) etab - (char *) ktab) / sizeof (unw_word_t); 02724 di->u.ti.table_data = (unw_word_t *) ktab; 02725 02726 if (gdbarch_debug >= 1) 02727 fprintf_unfiltered (gdb_stdlog, "get_kernel_table: found table `%s': " 02728 "segbase=%s, length=%s, gp=%s\n", 02729 (char *) di->u.ti.name_ptr, 02730 hex_string (di->u.ti.segbase), 02731 pulongest (di->u.ti.table_len), 02732 hex_string (di->gp)); 02733 return 0; 02734 } 02735 02736 /* Find the unwind table entry for a specified address. */ 02737 static int 02738 ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip, 02739 unw_dyn_info_t *dip, void **buf) 02740 { 02741 Elf_Internal_Phdr *phdr, *p_text = NULL, *p_unwind = NULL; 02742 Elf_Internal_Ehdr *ehdr; 02743 unw_word_t segbase = 0; 02744 CORE_ADDR load_base; 02745 bfd *bfd; 02746 int i; 02747 02748 bfd = objfile->obfd; 02749 02750 ehdr = elf_tdata (bfd)->elf_header; 02751 phdr = elf_tdata (bfd)->phdr; 02752 02753 load_base = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 02754 02755 for (i = 0; i < ehdr->e_phnum; ++i) 02756 { 02757 switch (phdr[i].p_type) 02758 { 02759 case PT_LOAD: 02760 if ((unw_word_t) (ip - load_base - phdr[i].p_vaddr) 02761 < phdr[i].p_memsz) 02762 p_text = phdr + i; 02763 break; 02764 02765 case PT_IA_64_UNWIND: 02766 p_unwind = phdr + i; 02767 break; 02768 02769 default: 02770 break; 02771 } 02772 } 02773 02774 if (!p_text || !p_unwind) 02775 return -UNW_ENOINFO; 02776 02777 /* Verify that the segment that contains the IP also contains 02778 the static unwind table. If not, we may be in the Linux kernel's 02779 DSO gate page in which case the unwind table is another segment. 02780 Otherwise, we are dealing with runtime-generated code, for which we 02781 have no info here. */ 02782 segbase = p_text->p_vaddr + load_base; 02783 02784 if ((p_unwind->p_vaddr - p_text->p_vaddr) >= p_text->p_memsz) 02785 { 02786 int ok = 0; 02787 for (i = 0; i < ehdr->e_phnum; ++i) 02788 { 02789 if (phdr[i].p_type == PT_LOAD 02790 && (p_unwind->p_vaddr - phdr[i].p_vaddr) < phdr[i].p_memsz) 02791 { 02792 ok = 1; 02793 /* Get the segbase from the section containing the 02794 libunwind table. */ 02795 segbase = phdr[i].p_vaddr + load_base; 02796 } 02797 } 02798 if (!ok) 02799 return -UNW_ENOINFO; 02800 } 02801 02802 dip->start_ip = p_text->p_vaddr + load_base; 02803 dip->end_ip = dip->start_ip + p_text->p_memsz; 02804 dip->gp = ia64_find_global_pointer (get_objfile_arch (objfile), ip); 02805 dip->format = UNW_INFO_FORMAT_REMOTE_TABLE; 02806 dip->u.rti.name_ptr = (unw_word_t) bfd_get_filename (bfd); 02807 dip->u.rti.segbase = segbase; 02808 dip->u.rti.table_len = p_unwind->p_memsz / sizeof (unw_word_t); 02809 dip->u.rti.table_data = p_unwind->p_vaddr + load_base; 02810 02811 return 0; 02812 } 02813 02814 /* Libunwind callback accessor function to acquire procedure unwind-info. */ 02815 static int 02816 ia64_find_proc_info_x (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi, 02817 int need_unwind_info, void *arg) 02818 { 02819 struct obj_section *sec = find_pc_section (ip); 02820 unw_dyn_info_t di; 02821 int ret; 02822 void *buf = NULL; 02823 02824 if (!sec) 02825 { 02826 /* XXX This only works if the host and the target architecture are 02827 both ia64 and if the have (more or less) the same kernel 02828 version. */ 02829 if (get_kernel_table (ip, &di) < 0) 02830 return -UNW_ENOINFO; 02831 02832 if (gdbarch_debug >= 1) 02833 fprintf_unfiltered (gdb_stdlog, "ia64_find_proc_info_x: %s -> " 02834 "(name=`%s',segbase=%s,start=%s,end=%s,gp=%s," 02835 "length=%s,data=%s)\n", 02836 hex_string (ip), (char *)di.u.ti.name_ptr, 02837 hex_string (di.u.ti.segbase), 02838 hex_string (di.start_ip), hex_string (di.end_ip), 02839 hex_string (di.gp), 02840 pulongest (di.u.ti.table_len), 02841 hex_string ((CORE_ADDR)di.u.ti.table_data)); 02842 } 02843 else 02844 { 02845 ret = ia64_find_unwind_table (sec->objfile, ip, &di, &buf); 02846 if (ret < 0) 02847 return ret; 02848 02849 if (gdbarch_debug >= 1) 02850 fprintf_unfiltered (gdb_stdlog, "ia64_find_proc_info_x: %s -> " 02851 "(name=`%s',segbase=%s,start=%s,end=%s,gp=%s," 02852 "length=%s,data=%s)\n", 02853 hex_string (ip), (char *)di.u.rti.name_ptr, 02854 hex_string (di.u.rti.segbase), 02855 hex_string (di.start_ip), hex_string (di.end_ip), 02856 hex_string (di.gp), 02857 pulongest (di.u.rti.table_len), 02858 hex_string (di.u.rti.table_data)); 02859 } 02860 02861 ret = libunwind_search_unwind_table (&as, ip, &di, pi, need_unwind_info, 02862 arg); 02863 02864 /* We no longer need the dyn info storage so free it. */ 02865 xfree (buf); 02866 02867 return ret; 02868 } 02869 02870 /* Libunwind callback accessor function for cleanup. */ 02871 static void 02872 ia64_put_unwind_info (unw_addr_space_t as, 02873 unw_proc_info_t *pip, void *arg) 02874 { 02875 /* Nothing required for now. */ 02876 } 02877 02878 /* Libunwind callback accessor function to get head of the dynamic 02879 unwind-info registration list. */ 02880 static int 02881 ia64_get_dyn_info_list (unw_addr_space_t as, 02882 unw_word_t *dilap, void *arg) 02883 { 02884 struct obj_section *text_sec; 02885 struct objfile *objfile; 02886 unw_word_t ip, addr; 02887 unw_dyn_info_t di; 02888 int ret; 02889 02890 if (!libunwind_is_initialized ()) 02891 return -UNW_ENOINFO; 02892 02893 for (objfile = object_files; objfile; objfile = objfile->next) 02894 { 02895 void *buf = NULL; 02896 02897 text_sec = objfile->sections + SECT_OFF_TEXT (objfile); 02898 ip = obj_section_addr (text_sec); 02899 ret = ia64_find_unwind_table (objfile, ip, &di, &buf); 02900 if (ret >= 0) 02901 { 02902 addr = libunwind_find_dyn_list (as, &di, arg); 02903 /* We no longer need the dyn info storage so free it. */ 02904 xfree (buf); 02905 02906 if (addr) 02907 { 02908 if (gdbarch_debug >= 1) 02909 fprintf_unfiltered (gdb_stdlog, 02910 "dynamic unwind table in objfile %s " 02911 "at %s (gp=%s)\n", 02912 bfd_get_filename (objfile->obfd), 02913 hex_string (addr), hex_string (di.gp)); 02914 *dilap = addr; 02915 return 0; 02916 } 02917 } 02918 } 02919 return -UNW_ENOINFO; 02920 } 02921 02922 02923 /* Frame interface functions for libunwind. */ 02924 02925 static void 02926 ia64_libunwind_frame_this_id (struct frame_info *this_frame, void **this_cache, 02927 struct frame_id *this_id) 02928 { 02929 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02930 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02931 struct frame_id id = outer_frame_id; 02932 gdb_byte buf[8]; 02933 CORE_ADDR bsp; 02934 02935 libunwind_frame_this_id (this_frame, this_cache, &id); 02936 if (frame_id_eq (id, outer_frame_id)) 02937 { 02938 (*this_id) = outer_frame_id; 02939 return; 02940 } 02941 02942 /* We must add the bsp as the special address for frame comparison 02943 purposes. */ 02944 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 02945 bsp = extract_unsigned_integer (buf, 8, byte_order); 02946 02947 (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp); 02948 02949 if (gdbarch_debug >= 1) 02950 fprintf_unfiltered (gdb_stdlog, 02951 "libunwind frame id: code %s, stack %s, " 02952 "special %s, this_frame %s\n", 02953 paddress (gdbarch, id.code_addr), 02954 paddress (gdbarch, id.stack_addr), 02955 paddress (gdbarch, bsp), 02956 host_address_to_string (this_frame)); 02957 } 02958 02959 static struct value * 02960 ia64_libunwind_frame_prev_register (struct frame_info *this_frame, 02961 void **this_cache, int regnum) 02962 { 02963 int reg = regnum; 02964 struct gdbarch *gdbarch = get_frame_arch (this_frame); 02965 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 02966 struct value *val; 02967 02968 if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) 02969 reg = IA64_PR_REGNUM; 02970 else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) 02971 reg = IA64_UNAT_REGNUM; 02972 02973 /* Let libunwind do most of the work. */ 02974 val = libunwind_frame_prev_register (this_frame, this_cache, reg); 02975 02976 if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM) 02977 { 02978 ULONGEST prN_val; 02979 02980 if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM) 02981 { 02982 int rrb_pr = 0; 02983 ULONGEST cfm; 02984 gdb_byte buf[MAX_REGISTER_SIZE]; 02985 02986 /* Fetch predicate register rename base from current frame 02987 marker for this frame. */ 02988 get_frame_register (this_frame, IA64_CFM_REGNUM, buf); 02989 cfm = extract_unsigned_integer (buf, 8, byte_order); 02990 rrb_pr = (cfm >> 32) & 0x3f; 02991 02992 /* Adjust the register number to account for register rotation. */ 02993 regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48; 02994 } 02995 prN_val = extract_bit_field (value_contents_all (val), 02996 regnum - VP0_REGNUM, 1); 02997 return frame_unwind_got_constant (this_frame, regnum, prN_val); 02998 } 02999 03000 else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM) 03001 { 03002 ULONGEST unatN_val; 03003 03004 unatN_val = extract_bit_field (value_contents_all (val), 03005 regnum - IA64_NAT0_REGNUM, 1); 03006 return frame_unwind_got_constant (this_frame, regnum, unatN_val); 03007 } 03008 03009 else if (regnum == IA64_BSP_REGNUM) 03010 { 03011 struct value *cfm_val; 03012 CORE_ADDR prev_bsp, prev_cfm; 03013 03014 /* We want to calculate the previous bsp as the end of the previous 03015 register stack frame. This corresponds to what the hardware bsp 03016 register will be if we pop the frame back which is why we might 03017 have been called. We know that libunwind will pass us back the 03018 beginning of the current frame so we should just add sof to it. */ 03019 prev_bsp = extract_unsigned_integer (value_contents_all (val), 03020 8, byte_order); 03021 cfm_val = libunwind_frame_prev_register (this_frame, this_cache, 03022 IA64_CFM_REGNUM); 03023 prev_cfm = extract_unsigned_integer (value_contents_all (cfm_val), 03024 8, byte_order); 03025 prev_bsp = rse_address_add (prev_bsp, (prev_cfm & 0x7f)); 03026 03027 return frame_unwind_got_constant (this_frame, regnum, prev_bsp); 03028 } 03029 else 03030 return val; 03031 } 03032 03033 static int 03034 ia64_libunwind_frame_sniffer (const struct frame_unwind *self, 03035 struct frame_info *this_frame, 03036 void **this_cache) 03037 { 03038 if (libunwind_is_initialized () 03039 && libunwind_frame_sniffer (self, this_frame, this_cache)) 03040 return 1; 03041 03042 return 0; 03043 } 03044 03045 static const struct frame_unwind ia64_libunwind_frame_unwind = 03046 { 03047 NORMAL_FRAME, 03048 default_frame_unwind_stop_reason, 03049 ia64_libunwind_frame_this_id, 03050 ia64_libunwind_frame_prev_register, 03051 NULL, 03052 ia64_libunwind_frame_sniffer, 03053 libunwind_frame_dealloc_cache 03054 }; 03055 03056 static void 03057 ia64_libunwind_sigtramp_frame_this_id (struct frame_info *this_frame, 03058 void **this_cache, 03059 struct frame_id *this_id) 03060 { 03061 struct gdbarch *gdbarch = get_frame_arch (this_frame); 03062 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03063 gdb_byte buf[8]; 03064 CORE_ADDR bsp; 03065 struct frame_id id = outer_frame_id; 03066 CORE_ADDR prev_ip; 03067 03068 libunwind_frame_this_id (this_frame, this_cache, &id); 03069 if (frame_id_eq (id, outer_frame_id)) 03070 { 03071 (*this_id) = outer_frame_id; 03072 return; 03073 } 03074 03075 /* We must add the bsp as the special address for frame comparison 03076 purposes. */ 03077 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 03078 bsp = extract_unsigned_integer (buf, 8, byte_order); 03079 03080 /* For a sigtramp frame, we don't make the check for previous ip being 0. */ 03081 (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp); 03082 03083 if (gdbarch_debug >= 1) 03084 fprintf_unfiltered (gdb_stdlog, 03085 "libunwind sigtramp frame id: code %s, " 03086 "stack %s, special %s, this_frame %s\n", 03087 paddress (gdbarch, id.code_addr), 03088 paddress (gdbarch, id.stack_addr), 03089 paddress (gdbarch, bsp), 03090 host_address_to_string (this_frame)); 03091 } 03092 03093 static struct value * 03094 ia64_libunwind_sigtramp_frame_prev_register (struct frame_info *this_frame, 03095 void **this_cache, int regnum) 03096 { 03097 struct gdbarch *gdbarch = get_frame_arch (this_frame); 03098 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03099 struct value *prev_ip_val; 03100 CORE_ADDR prev_ip; 03101 03102 /* If the previous frame pc value is 0, then we want to use the SIGCONTEXT 03103 method of getting previous registers. */ 03104 prev_ip_val = libunwind_frame_prev_register (this_frame, this_cache, 03105 IA64_IP_REGNUM); 03106 prev_ip = extract_unsigned_integer (value_contents_all (prev_ip_val), 03107 8, byte_order); 03108 03109 if (prev_ip == 0) 03110 { 03111 void *tmp_cache = NULL; 03112 return ia64_sigtramp_frame_prev_register (this_frame, &tmp_cache, 03113 regnum); 03114 } 03115 else 03116 return ia64_libunwind_frame_prev_register (this_frame, this_cache, regnum); 03117 } 03118 03119 static int 03120 ia64_libunwind_sigtramp_frame_sniffer (const struct frame_unwind *self, 03121 struct frame_info *this_frame, 03122 void **this_cache) 03123 { 03124 if (libunwind_is_initialized ()) 03125 { 03126 if (libunwind_sigtramp_frame_sniffer (self, this_frame, this_cache)) 03127 return 1; 03128 return 0; 03129 } 03130 else 03131 return ia64_sigtramp_frame_sniffer (self, this_frame, this_cache); 03132 } 03133 03134 static const struct frame_unwind ia64_libunwind_sigtramp_frame_unwind = 03135 { 03136 SIGTRAMP_FRAME, 03137 default_frame_unwind_stop_reason, 03138 ia64_libunwind_sigtramp_frame_this_id, 03139 ia64_libunwind_sigtramp_frame_prev_register, 03140 NULL, 03141 ia64_libunwind_sigtramp_frame_sniffer 03142 }; 03143 03144 /* Set of libunwind callback acccessor functions. */ 03145 unw_accessors_t ia64_unw_accessors = 03146 { 03147 ia64_find_proc_info_x, 03148 ia64_put_unwind_info, 03149 ia64_get_dyn_info_list, 03150 ia64_access_mem, 03151 ia64_access_reg, 03152 ia64_access_fpreg, 03153 /* resume */ 03154 /* get_proc_name */ 03155 }; 03156 03157 /* Set of special libunwind callback acccessor functions specific for accessing 03158 the rse registers. At the top of the stack, we want libunwind to figure out 03159 how to read r32 - r127. Though usually they are found sequentially in 03160 memory starting from $bof, this is not always true. */ 03161 unw_accessors_t ia64_unw_rse_accessors = 03162 { 03163 ia64_find_proc_info_x, 03164 ia64_put_unwind_info, 03165 ia64_get_dyn_info_list, 03166 ia64_access_mem, 03167 ia64_access_rse_reg, 03168 ia64_access_rse_fpreg, 03169 /* resume */ 03170 /* get_proc_name */ 03171 }; 03172 03173 /* Set of ia64-libunwind-tdep gdb callbacks and data for generic 03174 ia64-libunwind-tdep code to use. */ 03175 struct libunwind_descr ia64_libunwind_descr = 03176 { 03177 ia64_gdb2uw_regnum, 03178 ia64_uw2gdb_regnum, 03179 ia64_is_fpreg, 03180 &ia64_unw_accessors, 03181 &ia64_unw_rse_accessors, 03182 }; 03183 03184 #endif /* HAVE_LIBUNWIND_IA64_H */ 03185 03186 static int 03187 ia64_use_struct_convention (struct type *type) 03188 { 03189 struct type *float_elt_type; 03190 03191 /* Don't use the struct convention for anything but structure, 03192 union, or array types. */ 03193 if (!(TYPE_CODE (type) == TYPE_CODE_STRUCT 03194 || TYPE_CODE (type) == TYPE_CODE_UNION 03195 || TYPE_CODE (type) == TYPE_CODE_ARRAY)) 03196 return 0; 03197 03198 /* HFAs are structures (or arrays) consisting entirely of floating 03199 point values of the same length. Up to 8 of these are returned 03200 in registers. Don't use the struct convention when this is the 03201 case. */ 03202 float_elt_type = is_float_or_hfa_type (type); 03203 if (float_elt_type != NULL 03204 && TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type) <= 8) 03205 return 0; 03206 03207 /* Other structs of length 32 or less are returned in r8-r11. 03208 Don't use the struct convention for those either. */ 03209 return TYPE_LENGTH (type) > 32; 03210 } 03211 03212 /* Return non-zero if TYPE is a structure or union type. */ 03213 03214 static int 03215 ia64_struct_type_p (const struct type *type) 03216 { 03217 return (TYPE_CODE (type) == TYPE_CODE_STRUCT 03218 || TYPE_CODE (type) == TYPE_CODE_UNION); 03219 } 03220 03221 static void 03222 ia64_extract_return_value (struct type *type, struct regcache *regcache, 03223 gdb_byte *valbuf) 03224 { 03225 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03226 struct type *float_elt_type; 03227 03228 float_elt_type = is_float_or_hfa_type (type); 03229 if (float_elt_type != NULL) 03230 { 03231 gdb_byte from[MAX_REGISTER_SIZE]; 03232 int offset = 0; 03233 int regnum = IA64_FR8_REGNUM; 03234 int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type); 03235 03236 while (n-- > 0) 03237 { 03238 regcache_cooked_read (regcache, regnum, from); 03239 convert_typed_floating (from, ia64_ext_type (gdbarch), 03240 (char *)valbuf + offset, float_elt_type); 03241 offset += TYPE_LENGTH (float_elt_type); 03242 regnum++; 03243 } 03244 } 03245 else if (!ia64_struct_type_p (type) && TYPE_LENGTH (type) < 8) 03246 { 03247 /* This is an integral value, and its size is less than 8 bytes. 03248 These values are LSB-aligned, so extract the relevant bytes, 03249 and copy them into VALBUF. */ 03250 /* brobecker/2005-12-30: Actually, all integral values are LSB aligned, 03251 so I suppose we should also add handling here for integral values 03252 whose size is greater than 8. But I wasn't able to create such 03253 a type, neither in C nor in Ada, so not worrying about these yet. */ 03254 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03255 ULONGEST val; 03256 03257 regcache_cooked_read_unsigned (regcache, IA64_GR8_REGNUM, &val); 03258 store_unsigned_integer (valbuf, TYPE_LENGTH (type), byte_order, val); 03259 } 03260 else 03261 { 03262 ULONGEST val; 03263 int offset = 0; 03264 int regnum = IA64_GR8_REGNUM; 03265 int reglen = TYPE_LENGTH (register_type (gdbarch, IA64_GR8_REGNUM)); 03266 int n = TYPE_LENGTH (type) / reglen; 03267 int m = TYPE_LENGTH (type) % reglen; 03268 03269 while (n-- > 0) 03270 { 03271 ULONGEST val; 03272 regcache_cooked_read_unsigned (regcache, regnum, &val); 03273 memcpy ((char *)valbuf + offset, &val, reglen); 03274 offset += reglen; 03275 regnum++; 03276 } 03277 03278 if (m) 03279 { 03280 regcache_cooked_read_unsigned (regcache, regnum, &val); 03281 memcpy ((char *)valbuf + offset, &val, m); 03282 } 03283 } 03284 } 03285 03286 static void 03287 ia64_store_return_value (struct type *type, struct regcache *regcache, 03288 const gdb_byte *valbuf) 03289 { 03290 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03291 struct type *float_elt_type; 03292 03293 float_elt_type = is_float_or_hfa_type (type); 03294 if (float_elt_type != NULL) 03295 { 03296 gdb_byte to[MAX_REGISTER_SIZE]; 03297 int offset = 0; 03298 int regnum = IA64_FR8_REGNUM; 03299 int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type); 03300 03301 while (n-- > 0) 03302 { 03303 convert_typed_floating ((char *)valbuf + offset, float_elt_type, 03304 to, ia64_ext_type (gdbarch)); 03305 regcache_cooked_write (regcache, regnum, to); 03306 offset += TYPE_LENGTH (float_elt_type); 03307 regnum++; 03308 } 03309 } 03310 else 03311 { 03312 ULONGEST val; 03313 int offset = 0; 03314 int regnum = IA64_GR8_REGNUM; 03315 int reglen = TYPE_LENGTH (register_type (gdbarch, IA64_GR8_REGNUM)); 03316 int n = TYPE_LENGTH (type) / reglen; 03317 int m = TYPE_LENGTH (type) % reglen; 03318 03319 while (n-- > 0) 03320 { 03321 ULONGEST val; 03322 memcpy (&val, (char *)valbuf + offset, reglen); 03323 regcache_cooked_write_unsigned (regcache, regnum, val); 03324 offset += reglen; 03325 regnum++; 03326 } 03327 03328 if (m) 03329 { 03330 memcpy (&val, (char *)valbuf + offset, m); 03331 regcache_cooked_write_unsigned (regcache, regnum, val); 03332 } 03333 } 03334 } 03335 03336 static enum return_value_convention 03337 ia64_return_value (struct gdbarch *gdbarch, struct value *function, 03338 struct type *valtype, struct regcache *regcache, 03339 gdb_byte *readbuf, const gdb_byte *writebuf) 03340 { 03341 int struct_return = ia64_use_struct_convention (valtype); 03342 03343 if (writebuf != NULL) 03344 { 03345 gdb_assert (!struct_return); 03346 ia64_store_return_value (valtype, regcache, writebuf); 03347 } 03348 03349 if (readbuf != NULL) 03350 { 03351 gdb_assert (!struct_return); 03352 ia64_extract_return_value (valtype, regcache, readbuf); 03353 } 03354 03355 if (struct_return) 03356 return RETURN_VALUE_STRUCT_CONVENTION; 03357 else 03358 return RETURN_VALUE_REGISTER_CONVENTION; 03359 } 03360 03361 static int 03362 is_float_or_hfa_type_recurse (struct type *t, struct type **etp) 03363 { 03364 switch (TYPE_CODE (t)) 03365 { 03366 case TYPE_CODE_FLT: 03367 if (*etp) 03368 return TYPE_LENGTH (*etp) == TYPE_LENGTH (t); 03369 else 03370 { 03371 *etp = t; 03372 return 1; 03373 } 03374 break; 03375 case TYPE_CODE_ARRAY: 03376 return 03377 is_float_or_hfa_type_recurse (check_typedef (TYPE_TARGET_TYPE (t)), 03378 etp); 03379 break; 03380 case TYPE_CODE_STRUCT: 03381 { 03382 int i; 03383 03384 for (i = 0; i < TYPE_NFIELDS (t); i++) 03385 if (!is_float_or_hfa_type_recurse 03386 (check_typedef (TYPE_FIELD_TYPE (t, i)), etp)) 03387 return 0; 03388 return 1; 03389 } 03390 break; 03391 default: 03392 return 0; 03393 break; 03394 } 03395 } 03396 03397 /* Determine if the given type is one of the floating point types or 03398 and HFA (which is a struct, array, or combination thereof whose 03399 bottom-most elements are all of the same floating point type). */ 03400 03401 static struct type * 03402 is_float_or_hfa_type (struct type *t) 03403 { 03404 struct type *et = 0; 03405 03406 return is_float_or_hfa_type_recurse (t, &et) ? et : 0; 03407 } 03408 03409 03410 /* Return 1 if the alignment of T is such that the next even slot 03411 should be used. Return 0, if the next available slot should 03412 be used. (See section 8.5.1 of the IA-64 Software Conventions 03413 and Runtime manual). */ 03414 03415 static int 03416 slot_alignment_is_next_even (struct type *t) 03417 { 03418 switch (TYPE_CODE (t)) 03419 { 03420 case TYPE_CODE_INT: 03421 case TYPE_CODE_FLT: 03422 if (TYPE_LENGTH (t) > 8) 03423 return 1; 03424 else 03425 return 0; 03426 case TYPE_CODE_ARRAY: 03427 return 03428 slot_alignment_is_next_even (check_typedef (TYPE_TARGET_TYPE (t))); 03429 case TYPE_CODE_STRUCT: 03430 { 03431 int i; 03432 03433 for (i = 0; i < TYPE_NFIELDS (t); i++) 03434 if (slot_alignment_is_next_even 03435 (check_typedef (TYPE_FIELD_TYPE (t, i)))) 03436 return 1; 03437 return 0; 03438 } 03439 default: 03440 return 0; 03441 } 03442 } 03443 03444 /* Attempt to find (and return) the global pointer for the given 03445 function. 03446 03447 This is a rather nasty bit of code searchs for the .dynamic section 03448 in the objfile corresponding to the pc of the function we're trying 03449 to call. Once it finds the addresses at which the .dynamic section 03450 lives in the child process, it scans the Elf64_Dyn entries for a 03451 DT_PLTGOT tag. If it finds one of these, the corresponding 03452 d_un.d_ptr value is the global pointer. */ 03453 03454 static CORE_ADDR 03455 ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch, 03456 CORE_ADDR faddr) 03457 { 03458 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03459 struct obj_section *faddr_sect; 03460 03461 faddr_sect = find_pc_section (faddr); 03462 if (faddr_sect != NULL) 03463 { 03464 struct obj_section *osect; 03465 03466 ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect) 03467 { 03468 if (strcmp (osect->the_bfd_section->name, ".dynamic") == 0) 03469 break; 03470 } 03471 03472 if (osect < faddr_sect->objfile->sections_end) 03473 { 03474 CORE_ADDR addr, endaddr; 03475 03476 addr = obj_section_addr (osect); 03477 endaddr = obj_section_endaddr (osect); 03478 03479 while (addr < endaddr) 03480 { 03481 int status; 03482 LONGEST tag; 03483 gdb_byte buf[8]; 03484 03485 status = target_read_memory (addr, buf, sizeof (buf)); 03486 if (status != 0) 03487 break; 03488 tag = extract_signed_integer (buf, sizeof (buf), byte_order); 03489 03490 if (tag == DT_PLTGOT) 03491 { 03492 CORE_ADDR global_pointer; 03493 03494 status = target_read_memory (addr + 8, buf, sizeof (buf)); 03495 if (status != 0) 03496 break; 03497 global_pointer = extract_unsigned_integer (buf, sizeof (buf), 03498 byte_order); 03499 03500 /* The payoff... */ 03501 return global_pointer; 03502 } 03503 03504 if (tag == DT_NULL) 03505 break; 03506 03507 addr += 16; 03508 } 03509 } 03510 } 03511 return 0; 03512 } 03513 03514 /* Attempt to find (and return) the global pointer for the given 03515 function. We first try the find_global_pointer_from_solib routine 03516 from the gdbarch tdep vector, if provided. And if that does not 03517 work, then we try ia64_find_global_pointer_from_dynamic_section. */ 03518 03519 static CORE_ADDR 03520 ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr) 03521 { 03522 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 03523 CORE_ADDR addr = 0; 03524 03525 if (tdep->find_global_pointer_from_solib) 03526 addr = tdep->find_global_pointer_from_solib (gdbarch, faddr); 03527 if (addr == 0) 03528 addr = ia64_find_global_pointer_from_dynamic_section (gdbarch, faddr); 03529 return addr; 03530 } 03531 03532 /* Given a function's address, attempt to find (and return) the 03533 corresponding (canonical) function descriptor. Return 0 if 03534 not found. */ 03535 static CORE_ADDR 03536 find_extant_func_descr (struct gdbarch *gdbarch, CORE_ADDR faddr) 03537 { 03538 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03539 struct obj_section *faddr_sect; 03540 03541 /* Return early if faddr is already a function descriptor. */ 03542 faddr_sect = find_pc_section (faddr); 03543 if (faddr_sect && strcmp (faddr_sect->the_bfd_section->name, ".opd") == 0) 03544 return faddr; 03545 03546 if (faddr_sect != NULL) 03547 { 03548 struct obj_section *osect; 03549 ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect) 03550 { 03551 if (strcmp (osect->the_bfd_section->name, ".opd") == 0) 03552 break; 03553 } 03554 03555 if (osect < faddr_sect->objfile->sections_end) 03556 { 03557 CORE_ADDR addr, endaddr; 03558 03559 addr = obj_section_addr (osect); 03560 endaddr = obj_section_endaddr (osect); 03561 03562 while (addr < endaddr) 03563 { 03564 int status; 03565 LONGEST faddr2; 03566 gdb_byte buf[8]; 03567 03568 status = target_read_memory (addr, buf, sizeof (buf)); 03569 if (status != 0) 03570 break; 03571 faddr2 = extract_signed_integer (buf, sizeof (buf), byte_order); 03572 03573 if (faddr == faddr2) 03574 return addr; 03575 03576 addr += 16; 03577 } 03578 } 03579 } 03580 return 0; 03581 } 03582 03583 /* Attempt to find a function descriptor corresponding to the 03584 given address. If none is found, construct one on the 03585 stack using the address at fdaptr. */ 03586 03587 static CORE_ADDR 03588 find_func_descr (struct regcache *regcache, CORE_ADDR faddr, CORE_ADDR *fdaptr) 03589 { 03590 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03591 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03592 CORE_ADDR fdesc; 03593 03594 fdesc = find_extant_func_descr (gdbarch, faddr); 03595 03596 if (fdesc == 0) 03597 { 03598 ULONGEST global_pointer; 03599 gdb_byte buf[16]; 03600 03601 fdesc = *fdaptr; 03602 *fdaptr += 16; 03603 03604 global_pointer = ia64_find_global_pointer (gdbarch, faddr); 03605 03606 if (global_pointer == 0) 03607 regcache_cooked_read_unsigned (regcache, 03608 IA64_GR1_REGNUM, &global_pointer); 03609 03610 store_unsigned_integer (buf, 8, byte_order, faddr); 03611 store_unsigned_integer (buf + 8, 8, byte_order, global_pointer); 03612 03613 write_memory (fdesc, buf, 16); 03614 } 03615 03616 return fdesc; 03617 } 03618 03619 /* Use the following routine when printing out function pointers 03620 so the user can see the function address rather than just the 03621 function descriptor. */ 03622 static CORE_ADDR 03623 ia64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr, 03624 struct target_ops *targ) 03625 { 03626 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03627 struct obj_section *s; 03628 gdb_byte buf[8]; 03629 03630 s = find_pc_section (addr); 03631 03632 /* check if ADDR points to a function descriptor. */ 03633 if (s && strcmp (s->the_bfd_section->name, ".opd") == 0) 03634 return read_memory_unsigned_integer (addr, 8, byte_order); 03635 03636 /* Normally, functions live inside a section that is executable. 03637 So, if ADDR points to a non-executable section, then treat it 03638 as a function descriptor and return the target address iff 03639 the target address itself points to a section that is executable. 03640 Check first the memory of the whole length of 8 bytes is readable. */ 03641 if (s && (s->the_bfd_section->flags & SEC_CODE) == 0 03642 && target_read_memory (addr, buf, 8) == 0) 03643 { 03644 CORE_ADDR pc = extract_unsigned_integer (buf, 8, byte_order); 03645 struct obj_section *pc_section = find_pc_section (pc); 03646 03647 if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE)) 03648 return pc; 03649 } 03650 03651 /* There are also descriptors embedded in vtables. */ 03652 if (s) 03653 { 03654 struct bound_minimal_symbol minsym; 03655 03656 minsym = lookup_minimal_symbol_by_pc (addr); 03657 03658 if (minsym.minsym && is_vtable_name (SYMBOL_LINKAGE_NAME (minsym.minsym))) 03659 return read_memory_unsigned_integer (addr, 8, byte_order); 03660 } 03661 03662 return addr; 03663 } 03664 03665 static CORE_ADDR 03666 ia64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) 03667 { 03668 return sp & ~0xfLL; 03669 } 03670 03671 /* The default "allocate_new_rse_frame" ia64_infcall_ops routine for ia64. */ 03672 03673 static void 03674 ia64_allocate_new_rse_frame (struct regcache *regcache, ULONGEST bsp, int sof) 03675 { 03676 ULONGEST cfm, pfs, new_bsp; 03677 03678 regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm); 03679 03680 new_bsp = rse_address_add (bsp, sof); 03681 regcache_cooked_write_unsigned (regcache, IA64_BSP_REGNUM, new_bsp); 03682 03683 regcache_cooked_read_unsigned (regcache, IA64_PFS_REGNUM, &pfs); 03684 pfs &= 0xc000000000000000LL; 03685 pfs |= (cfm & 0xffffffffffffLL); 03686 regcache_cooked_write_unsigned (regcache, IA64_PFS_REGNUM, pfs); 03687 03688 cfm &= 0xc000000000000000LL; 03689 cfm |= sof; 03690 regcache_cooked_write_unsigned (regcache, IA64_CFM_REGNUM, cfm); 03691 } 03692 03693 /* The default "store_argument_in_slot" ia64_infcall_ops routine for 03694 ia64. */ 03695 03696 static void 03697 ia64_store_argument_in_slot (struct regcache *regcache, CORE_ADDR bsp, 03698 int slotnum, gdb_byte *buf) 03699 { 03700 write_memory (rse_address_add (bsp, slotnum), buf, 8); 03701 } 03702 03703 /* The default "set_function_addr" ia64_infcall_ops routine for ia64. */ 03704 03705 static void 03706 ia64_set_function_addr (struct regcache *regcache, CORE_ADDR func_addr) 03707 { 03708 /* Nothing needed. */ 03709 } 03710 03711 static CORE_ADDR 03712 ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, 03713 struct regcache *regcache, CORE_ADDR bp_addr, 03714 int nargs, struct value **args, CORE_ADDR sp, 03715 int struct_return, CORE_ADDR struct_addr) 03716 { 03717 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 03718 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03719 int argno; 03720 struct value *arg; 03721 struct type *type; 03722 int len, argoffset; 03723 int nslots, rseslots, memslots, slotnum, nfuncargs; 03724 int floatreg; 03725 ULONGEST bsp; 03726 CORE_ADDR funcdescaddr, pc, global_pointer; 03727 CORE_ADDR func_addr = find_function_addr (function, NULL); 03728 03729 nslots = 0; 03730 nfuncargs = 0; 03731 /* Count the number of slots needed for the arguments. */ 03732 for (argno = 0; argno < nargs; argno++) 03733 { 03734 arg = args[argno]; 03735 type = check_typedef (value_type (arg)); 03736 len = TYPE_LENGTH (type); 03737 03738 if ((nslots & 1) && slot_alignment_is_next_even (type)) 03739 nslots++; 03740 03741 if (TYPE_CODE (type) == TYPE_CODE_FUNC) 03742 nfuncargs++; 03743 03744 nslots += (len + 7) / 8; 03745 } 03746 03747 /* Divvy up the slots between the RSE and the memory stack. */ 03748 rseslots = (nslots > 8) ? 8 : nslots; 03749 memslots = nslots - rseslots; 03750 03751 /* Allocate a new RSE frame. */ 03752 regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp); 03753 tdep->infcall_ops.allocate_new_rse_frame (regcache, bsp, rseslots); 03754 03755 /* We will attempt to find function descriptors in the .opd segment, 03756 but if we can't we'll construct them ourselves. That being the 03757 case, we'll need to reserve space on the stack for them. */ 03758 funcdescaddr = sp - nfuncargs * 16; 03759 funcdescaddr &= ~0xfLL; 03760 03761 /* Adjust the stack pointer to it's new value. The calling conventions 03762 require us to have 16 bytes of scratch, plus whatever space is 03763 necessary for the memory slots and our function descriptors. */ 03764 sp = sp - 16 - (memslots + nfuncargs) * 8; 03765 sp &= ~0xfLL; /* Maintain 16 byte alignment. */ 03766 03767 /* Place the arguments where they belong. The arguments will be 03768 either placed in the RSE backing store or on the memory stack. 03769 In addition, floating point arguments or HFAs are placed in 03770 floating point registers. */ 03771 slotnum = 0; 03772 floatreg = IA64_FR8_REGNUM; 03773 for (argno = 0; argno < nargs; argno++) 03774 { 03775 struct type *float_elt_type; 03776 03777 arg = args[argno]; 03778 type = check_typedef (value_type (arg)); 03779 len = TYPE_LENGTH (type); 03780 03781 /* Special handling for function parameters. */ 03782 if (len == 8 03783 && TYPE_CODE (type) == TYPE_CODE_PTR 03784 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC) 03785 { 03786 gdb_byte val_buf[8]; 03787 ULONGEST faddr = extract_unsigned_integer (value_contents (arg), 03788 8, byte_order); 03789 store_unsigned_integer (val_buf, 8, byte_order, 03790 find_func_descr (regcache, faddr, 03791 &funcdescaddr)); 03792 if (slotnum < rseslots) 03793 tdep->infcall_ops.store_argument_in_slot (regcache, bsp, 03794 slotnum, val_buf); 03795 else 03796 write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8); 03797 slotnum++; 03798 continue; 03799 } 03800 03801 /* Normal slots. */ 03802 03803 /* Skip odd slot if necessary... */ 03804 if ((slotnum & 1) && slot_alignment_is_next_even (type)) 03805 slotnum++; 03806 03807 argoffset = 0; 03808 while (len > 0) 03809 { 03810 gdb_byte val_buf[8]; 03811 03812 memset (val_buf, 0, 8); 03813 if (!ia64_struct_type_p (type) && len < 8) 03814 { 03815 /* Integral types are LSB-aligned, so we have to be careful 03816 to insert the argument on the correct side of the buffer. 03817 This is why we use store_unsigned_integer. */ 03818 store_unsigned_integer 03819 (val_buf, 8, byte_order, 03820 extract_unsigned_integer (value_contents (arg), len, 03821 byte_order)); 03822 } 03823 else 03824 { 03825 /* This is either an 8bit integral type, or an aggregate. 03826 For 8bit integral type, there is no problem, we just 03827 copy the value over. 03828 03829 For aggregates, the only potentially tricky portion 03830 is to write the last one if it is less than 8 bytes. 03831 In this case, the data is Byte0-aligned. Happy news, 03832 this means that we don't need to differentiate the 03833 handling of 8byte blocks and less-than-8bytes blocks. */ 03834 memcpy (val_buf, value_contents (arg) + argoffset, 03835 (len > 8) ? 8 : len); 03836 } 03837 03838 if (slotnum < rseslots) 03839 tdep->infcall_ops.store_argument_in_slot (regcache, bsp, 03840 slotnum, val_buf); 03841 else 03842 write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8); 03843 03844 argoffset += 8; 03845 len -= 8; 03846 slotnum++; 03847 } 03848 03849 /* Handle floating point types (including HFAs). */ 03850 float_elt_type = is_float_or_hfa_type (type); 03851 if (float_elt_type != NULL) 03852 { 03853 argoffset = 0; 03854 len = TYPE_LENGTH (type); 03855 while (len > 0 && floatreg < IA64_FR16_REGNUM) 03856 { 03857 char to[MAX_REGISTER_SIZE]; 03858 convert_typed_floating (value_contents (arg) + argoffset, 03859 float_elt_type, to, 03860 ia64_ext_type (gdbarch)); 03861 regcache_cooked_write (regcache, floatreg, (void *)to); 03862 floatreg++; 03863 argoffset += TYPE_LENGTH (float_elt_type); 03864 len -= TYPE_LENGTH (float_elt_type); 03865 } 03866 } 03867 } 03868 03869 /* Store the struct return value in r8 if necessary. */ 03870 if (struct_return) 03871 { 03872 regcache_cooked_write_unsigned (regcache, IA64_GR8_REGNUM, 03873 (ULONGEST) struct_addr); 03874 } 03875 03876 global_pointer = ia64_find_global_pointer (gdbarch, func_addr); 03877 03878 if (global_pointer != 0) 03879 regcache_cooked_write_unsigned (regcache, IA64_GR1_REGNUM, global_pointer); 03880 03881 /* The following is not necessary on HP-UX, because we're using 03882 a dummy code sequence pushed on the stack to make the call, and 03883 this sequence doesn't need b0 to be set in order for our dummy 03884 breakpoint to be hit. Nonetheless, this doesn't interfere, and 03885 it's needed for other OSes, so we do this unconditionaly. */ 03886 regcache_cooked_write_unsigned (regcache, IA64_BR0_REGNUM, bp_addr); 03887 03888 regcache_cooked_write_unsigned (regcache, sp_regnum, sp); 03889 03890 tdep->infcall_ops.set_function_addr (regcache, func_addr); 03891 03892 return sp; 03893 } 03894 03895 static const struct ia64_infcall_ops ia64_infcall_ops = 03896 { 03897 ia64_allocate_new_rse_frame, 03898 ia64_store_argument_in_slot, 03899 ia64_set_function_addr 03900 }; 03901 03902 static struct frame_id 03903 ia64_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) 03904 { 03905 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03906 gdb_byte buf[8]; 03907 CORE_ADDR sp, bsp; 03908 03909 get_frame_register (this_frame, sp_regnum, buf); 03910 sp = extract_unsigned_integer (buf, 8, byte_order); 03911 03912 get_frame_register (this_frame, IA64_BSP_REGNUM, buf); 03913 bsp = extract_unsigned_integer (buf, 8, byte_order); 03914 03915 if (gdbarch_debug >= 1) 03916 fprintf_unfiltered (gdb_stdlog, 03917 "dummy frame id: code %s, stack %s, special %s\n", 03918 paddress (gdbarch, get_frame_pc (this_frame)), 03919 paddress (gdbarch, sp), paddress (gdbarch, bsp)); 03920 03921 return frame_id_build_special (sp, get_frame_pc (this_frame), bsp); 03922 } 03923 03924 static CORE_ADDR 03925 ia64_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) 03926 { 03927 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 03928 gdb_byte buf[8]; 03929 CORE_ADDR ip, psr, pc; 03930 03931 frame_unwind_register (next_frame, IA64_IP_REGNUM, buf); 03932 ip = extract_unsigned_integer (buf, 8, byte_order); 03933 frame_unwind_register (next_frame, IA64_PSR_REGNUM, buf); 03934 psr = extract_unsigned_integer (buf, 8, byte_order); 03935 03936 pc = (ip & ~0xf) | ((psr >> 41) & 3); 03937 return pc; 03938 } 03939 03940 static int 03941 ia64_print_insn (bfd_vma memaddr, struct disassemble_info *info) 03942 { 03943 info->bytes_per_line = SLOT_MULTIPLIER; 03944 return print_insn_ia64 (memaddr, info); 03945 } 03946 03947 /* The default "size_of_register_frame" gdbarch_tdep routine for ia64. */ 03948 03949 static int 03950 ia64_size_of_register_frame (struct frame_info *this_frame, ULONGEST cfm) 03951 { 03952 return (cfm & 0x7f); 03953 } 03954 03955 static struct gdbarch * 03956 ia64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) 03957 { 03958 struct gdbarch *gdbarch; 03959 struct gdbarch_tdep *tdep; 03960 03961 /* If there is already a candidate, use it. */ 03962 arches = gdbarch_list_lookup_by_info (arches, &info); 03963 if (arches != NULL) 03964 return arches->gdbarch; 03965 03966 tdep = xzalloc (sizeof (struct gdbarch_tdep)); 03967 gdbarch = gdbarch_alloc (&info, tdep); 03968 03969 tdep->size_of_register_frame = ia64_size_of_register_frame; 03970 03971 /* According to the ia64 specs, instructions that store long double 03972 floats in memory use a long-double format different than that 03973 used in the floating registers. The memory format matches the 03974 x86 extended float format which is 80 bits. An OS may choose to 03975 use this format (e.g. GNU/Linux) or choose to use a different 03976 format for storing long doubles (e.g. HPUX). In the latter case, 03977 the setting of the format may be moved/overridden in an 03978 OS-specific tdep file. */ 03979 set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext); 03980 03981 set_gdbarch_short_bit (gdbarch, 16); 03982 set_gdbarch_int_bit (gdbarch, 32); 03983 set_gdbarch_long_bit (gdbarch, 64); 03984 set_gdbarch_long_long_bit (gdbarch, 64); 03985 set_gdbarch_float_bit (gdbarch, 32); 03986 set_gdbarch_double_bit (gdbarch, 64); 03987 set_gdbarch_long_double_bit (gdbarch, 128); 03988 set_gdbarch_ptr_bit (gdbarch, 64); 03989 03990 set_gdbarch_num_regs (gdbarch, NUM_IA64_RAW_REGS); 03991 set_gdbarch_num_pseudo_regs (gdbarch, 03992 LAST_PSEUDO_REGNUM - FIRST_PSEUDO_REGNUM); 03993 set_gdbarch_sp_regnum (gdbarch, sp_regnum); 03994 set_gdbarch_fp0_regnum (gdbarch, IA64_FR0_REGNUM); 03995 03996 set_gdbarch_register_name (gdbarch, ia64_register_name); 03997 set_gdbarch_register_type (gdbarch, ia64_register_type); 03998 03999 set_gdbarch_pseudo_register_read (gdbarch, ia64_pseudo_register_read); 04000 set_gdbarch_pseudo_register_write (gdbarch, ia64_pseudo_register_write); 04001 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, ia64_dwarf_reg_to_regnum); 04002 set_gdbarch_register_reggroup_p (gdbarch, ia64_register_reggroup_p); 04003 set_gdbarch_convert_register_p (gdbarch, ia64_convert_register_p); 04004 set_gdbarch_register_to_value (gdbarch, ia64_register_to_value); 04005 set_gdbarch_value_to_register (gdbarch, ia64_value_to_register); 04006 04007 set_gdbarch_skip_prologue (gdbarch, ia64_skip_prologue); 04008 04009 set_gdbarch_return_value (gdbarch, ia64_return_value); 04010 04011 set_gdbarch_memory_insert_breakpoint (gdbarch, 04012 ia64_memory_insert_breakpoint); 04013 set_gdbarch_memory_remove_breakpoint (gdbarch, 04014 ia64_memory_remove_breakpoint); 04015 set_gdbarch_breakpoint_from_pc (gdbarch, ia64_breakpoint_from_pc); 04016 set_gdbarch_read_pc (gdbarch, ia64_read_pc); 04017 set_gdbarch_write_pc (gdbarch, ia64_write_pc); 04018 04019 /* Settings for calling functions in the inferior. */ 04020 set_gdbarch_push_dummy_call (gdbarch, ia64_push_dummy_call); 04021 tdep->infcall_ops = ia64_infcall_ops; 04022 set_gdbarch_frame_align (gdbarch, ia64_frame_align); 04023 set_gdbarch_dummy_id (gdbarch, ia64_dummy_id); 04024 04025 set_gdbarch_unwind_pc (gdbarch, ia64_unwind_pc); 04026 #ifdef HAVE_LIBUNWIND_IA64_H 04027 frame_unwind_append_unwinder (gdbarch, 04028 &ia64_libunwind_sigtramp_frame_unwind); 04029 frame_unwind_append_unwinder (gdbarch, &ia64_libunwind_frame_unwind); 04030 frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind); 04031 libunwind_frame_set_descr (gdbarch, &ia64_libunwind_descr); 04032 #else 04033 frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind); 04034 #endif 04035 frame_unwind_append_unwinder (gdbarch, &ia64_frame_unwind); 04036 frame_base_set_default (gdbarch, &ia64_frame_base); 04037 04038 /* Settings that should be unnecessary. */ 04039 set_gdbarch_inner_than (gdbarch, core_addr_lessthan); 04040 04041 set_gdbarch_print_insn (gdbarch, ia64_print_insn); 04042 set_gdbarch_convert_from_func_ptr_addr (gdbarch, 04043 ia64_convert_from_func_ptr_addr); 04044 04045 /* The virtual table contains 16-byte descriptors, not pointers to 04046 descriptors. */ 04047 set_gdbarch_vtable_function_descriptors (gdbarch, 1); 04048 04049 /* Hook in ABI-specific overrides, if they have been registered. */ 04050 gdbarch_init_osabi (info, gdbarch); 04051 04052 return gdbarch; 04053 } 04054 04055 extern initialize_file_ftype _initialize_ia64_tdep; /* -Wmissing-prototypes */ 04056 04057 void 04058 _initialize_ia64_tdep (void) 04059 { 04060 gdbarch_register (bfd_arch_ia64, ia64_gdbarch_init, NULL); 04061 }