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