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