]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the HP PA architecture, for GDB. |
cda5a58a AC |
2 | |
3 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, | |
adc11376 AC |
4 | 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software |
5 | Foundation, Inc. | |
c906108c SS |
6 | |
7 | Contributed by the Center for Software Science at the | |
8 | University of Utah ([email protected]). | |
9 | ||
c5aa993b | 10 | This file is part of GDB. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is free software; you can redistribute it and/or modify |
13 | it under the terms of the GNU General Public License as published by | |
14 | the Free Software Foundation; either version 2 of the License, or | |
15 | (at your option) any later version. | |
c906108c | 16 | |
c5aa993b JM |
17 | This program is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
c906108c | 21 | |
c5aa993b JM |
22 | You should have received a copy of the GNU General Public License |
23 | along with this program; if not, write to the Free Software | |
24 | Foundation, Inc., 59 Temple Place - Suite 330, | |
25 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
26 | |
27 | #include "defs.h" | |
c906108c SS |
28 | #include "bfd.h" |
29 | #include "inferior.h" | |
4e052eda | 30 | #include "regcache.h" |
e5d66720 | 31 | #include "completer.h" |
59623e27 | 32 | #include "osabi.h" |
a7ff40e7 | 33 | #include "gdb_assert.h" |
343af405 | 34 | #include "arch-utils.h" |
c906108c SS |
35 | /* For argument passing to the inferior */ |
36 | #include "symtab.h" | |
fde2cceb | 37 | #include "dis-asm.h" |
26d08f08 AC |
38 | #include "trad-frame.h" |
39 | #include "frame-unwind.h" | |
40 | #include "frame-base.h" | |
c906108c | 41 | |
c906108c SS |
42 | #include "gdbcore.h" |
43 | #include "gdbcmd.h" | |
c906108c | 44 | #include "objfiles.h" |
3ff7cf9e | 45 | #include "hppa-tdep.h" |
c906108c | 46 | |
369aa520 RC |
47 | static int hppa_debug = 0; |
48 | ||
60383d10 | 49 | /* Some local constants. */ |
3ff7cf9e JB |
50 | static const int hppa32_num_regs = 128; |
51 | static const int hppa64_num_regs = 96; | |
52 | ||
7c46b9fb RC |
53 | /* hppa-specific object data -- unwind and solib info. |
54 | TODO/maybe: think about splitting this into two parts; the unwind data is | |
55 | common to all hppa targets, but is only used in this file; we can register | |
56 | that separately and make this static. The solib data is probably hpux- | |
57 | specific, so we can create a separate extern objfile_data that is registered | |
58 | by hppa-hpux-tdep.c and shared with pa64solib.c and somsolib.c. */ | |
59 | const struct objfile_data *hppa_objfile_priv_data = NULL; | |
60 | ||
e2ac8128 JB |
61 | /* Get at various relevent fields of an instruction word. */ |
62 | #define MASK_5 0x1f | |
63 | #define MASK_11 0x7ff | |
64 | #define MASK_14 0x3fff | |
65 | #define MASK_21 0x1fffff | |
66 | ||
e2ac8128 JB |
67 | /* Sizes (in bytes) of the native unwind entries. */ |
68 | #define UNWIND_ENTRY_SIZE 16 | |
69 | #define STUB_UNWIND_ENTRY_SIZE 8 | |
70 | ||
d709c020 JB |
71 | /* FIXME: brobecker 2002-11-07: We will likely be able to make the |
72 | following functions static, once we hppa is partially multiarched. */ | |
d709c020 | 73 | int hppa_pc_requires_run_before_use (CORE_ADDR pc); |
c906108c | 74 | |
537987fc AC |
75 | /* Handle 32/64-bit struct return conventions. */ |
76 | ||
77 | static enum return_value_convention | |
78 | hppa32_return_value (struct gdbarch *gdbarch, | |
79 | struct type *type, struct regcache *regcache, | |
80 | void *readbuf, const void *writebuf) | |
81 | { | |
537987fc AC |
82 | if (TYPE_LENGTH (type) <= 2 * 4) |
83 | { | |
84 | /* The value always lives in the right hand end of the register | |
85 | (or register pair)? */ | |
86 | int b; | |
34f75cc1 | 87 | int reg = TYPE_CODE (type) == TYPE_CODE_FLT ? HPPA_FP4_REGNUM : 28; |
537987fc AC |
88 | int part = TYPE_LENGTH (type) % 4; |
89 | /* The left hand register contains only part of the value, | |
90 | transfer that first so that the rest can be xfered as entire | |
91 | 4-byte registers. */ | |
92 | if (part > 0) | |
93 | { | |
94 | if (readbuf != NULL) | |
95 | regcache_cooked_read_part (regcache, reg, 4 - part, | |
96 | part, readbuf); | |
97 | if (writebuf != NULL) | |
98 | regcache_cooked_write_part (regcache, reg, 4 - part, | |
99 | part, writebuf); | |
100 | reg++; | |
101 | } | |
102 | /* Now transfer the remaining register values. */ | |
103 | for (b = part; b < TYPE_LENGTH (type); b += 4) | |
104 | { | |
105 | if (readbuf != NULL) | |
106 | regcache_cooked_read (regcache, reg, (char *) readbuf + b); | |
107 | if (writebuf != NULL) | |
108 | regcache_cooked_write (regcache, reg, (const char *) writebuf + b); | |
109 | reg++; | |
110 | } | |
111 | return RETURN_VALUE_REGISTER_CONVENTION; | |
112 | } | |
113 | else | |
114 | return RETURN_VALUE_STRUCT_CONVENTION; | |
115 | } | |
116 | ||
117 | static enum return_value_convention | |
118 | hppa64_return_value (struct gdbarch *gdbarch, | |
119 | struct type *type, struct regcache *regcache, | |
120 | void *readbuf, const void *writebuf) | |
121 | { | |
122 | /* RM: Floats are returned in FR4R, doubles in FR4. Integral values | |
123 | are in r28, padded on the left. Aggregates less that 65 bits are | |
124 | in r28, right padded. Aggregates upto 128 bits are in r28 and | |
125 | r29, right padded. */ | |
449e1137 AC |
126 | if (TYPE_CODE (type) == TYPE_CODE_FLT |
127 | && TYPE_LENGTH (type) <= 8) | |
537987fc AC |
128 | { |
129 | /* Floats are right aligned? */ | |
34f75cc1 | 130 | int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type); |
537987fc | 131 | if (readbuf != NULL) |
34f75cc1 | 132 | regcache_cooked_read_part (regcache, HPPA_FP4_REGNUM, offset, |
537987fc AC |
133 | TYPE_LENGTH (type), readbuf); |
134 | if (writebuf != NULL) | |
34f75cc1 | 135 | regcache_cooked_write_part (regcache, HPPA_FP4_REGNUM, offset, |
537987fc AC |
136 | TYPE_LENGTH (type), writebuf); |
137 | return RETURN_VALUE_REGISTER_CONVENTION; | |
138 | } | |
139 | else if (TYPE_LENGTH (type) <= 8 && is_integral_type (type)) | |
140 | { | |
141 | /* Integrals are right aligned. */ | |
34f75cc1 | 142 | int offset = register_size (gdbarch, HPPA_FP4_REGNUM) - TYPE_LENGTH (type); |
537987fc AC |
143 | if (readbuf != NULL) |
144 | regcache_cooked_read_part (regcache, 28, offset, | |
145 | TYPE_LENGTH (type), readbuf); | |
146 | if (writebuf != NULL) | |
147 | regcache_cooked_write_part (regcache, 28, offset, | |
148 | TYPE_LENGTH (type), writebuf); | |
149 | return RETURN_VALUE_REGISTER_CONVENTION; | |
150 | } | |
151 | else if (TYPE_LENGTH (type) <= 2 * 8) | |
152 | { | |
153 | /* Composite values are left aligned. */ | |
154 | int b; | |
155 | for (b = 0; b < TYPE_LENGTH (type); b += 8) | |
156 | { | |
449e1137 | 157 | int part = min (8, TYPE_LENGTH (type) - b); |
537987fc | 158 | if (readbuf != NULL) |
449e1137 | 159 | regcache_cooked_read_part (regcache, 28 + b / 8, 0, part, |
537987fc AC |
160 | (char *) readbuf + b); |
161 | if (writebuf != NULL) | |
449e1137 | 162 | regcache_cooked_write_part (regcache, 28 + b / 8, 0, part, |
537987fc AC |
163 | (const char *) writebuf + b); |
164 | } | |
449e1137 | 165 | return RETURN_VALUE_REGISTER_CONVENTION; |
537987fc AC |
166 | } |
167 | else | |
168 | return RETURN_VALUE_STRUCT_CONVENTION; | |
169 | } | |
170 | ||
c906108c SS |
171 | /* Routines to extract various sized constants out of hppa |
172 | instructions. */ | |
173 | ||
174 | /* This assumes that no garbage lies outside of the lower bits of | |
175 | value. */ | |
176 | ||
abc485a1 RC |
177 | int |
178 | hppa_sign_extend (unsigned val, unsigned bits) | |
c906108c | 179 | { |
c5aa993b | 180 | return (int) (val >> (bits - 1) ? (-1 << bits) | val : val); |
c906108c SS |
181 | } |
182 | ||
183 | /* For many immediate values the sign bit is the low bit! */ | |
184 | ||
abc485a1 RC |
185 | int |
186 | hppa_low_hppa_sign_extend (unsigned val, unsigned bits) | |
c906108c | 187 | { |
c5aa993b | 188 | return (int) ((val & 0x1 ? (-1 << (bits - 1)) : 0) | val >> 1); |
c906108c SS |
189 | } |
190 | ||
e2ac8128 JB |
191 | /* Extract the bits at positions between FROM and TO, using HP's numbering |
192 | (MSB = 0). */ | |
193 | ||
abc485a1 RC |
194 | int |
195 | hppa_get_field (unsigned word, int from, int to) | |
e2ac8128 JB |
196 | { |
197 | return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1)); | |
198 | } | |
199 | ||
c906108c SS |
200 | /* extract the immediate field from a ld{bhw}s instruction */ |
201 | ||
abc485a1 RC |
202 | int |
203 | hppa_extract_5_load (unsigned word) | |
c906108c | 204 | { |
abc485a1 | 205 | return hppa_low_hppa_sign_extend (word >> 16 & MASK_5, 5); |
c906108c SS |
206 | } |
207 | ||
c906108c SS |
208 | /* extract the immediate field from a break instruction */ |
209 | ||
abc485a1 RC |
210 | unsigned |
211 | hppa_extract_5r_store (unsigned word) | |
c906108c SS |
212 | { |
213 | return (word & MASK_5); | |
214 | } | |
215 | ||
216 | /* extract the immediate field from a {sr}sm instruction */ | |
217 | ||
abc485a1 RC |
218 | unsigned |
219 | hppa_extract_5R_store (unsigned word) | |
c906108c SS |
220 | { |
221 | return (word >> 16 & MASK_5); | |
222 | } | |
223 | ||
c906108c SS |
224 | /* extract a 14 bit immediate field */ |
225 | ||
abc485a1 RC |
226 | int |
227 | hppa_extract_14 (unsigned word) | |
c906108c | 228 | { |
abc485a1 | 229 | return hppa_low_hppa_sign_extend (word & MASK_14, 14); |
c906108c SS |
230 | } |
231 | ||
c906108c SS |
232 | /* extract a 21 bit constant */ |
233 | ||
abc485a1 RC |
234 | int |
235 | hppa_extract_21 (unsigned word) | |
c906108c SS |
236 | { |
237 | int val; | |
238 | ||
239 | word &= MASK_21; | |
240 | word <<= 11; | |
abc485a1 | 241 | val = hppa_get_field (word, 20, 20); |
c906108c | 242 | val <<= 11; |
abc485a1 | 243 | val |= hppa_get_field (word, 9, 19); |
c906108c | 244 | val <<= 2; |
abc485a1 | 245 | val |= hppa_get_field (word, 5, 6); |
c906108c | 246 | val <<= 5; |
abc485a1 | 247 | val |= hppa_get_field (word, 0, 4); |
c906108c | 248 | val <<= 2; |
abc485a1 RC |
249 | val |= hppa_get_field (word, 7, 8); |
250 | return hppa_sign_extend (val, 21) << 11; | |
c906108c SS |
251 | } |
252 | ||
c906108c SS |
253 | /* extract a 17 bit constant from branch instructions, returning the |
254 | 19 bit signed value. */ | |
255 | ||
abc485a1 RC |
256 | int |
257 | hppa_extract_17 (unsigned word) | |
c906108c | 258 | { |
abc485a1 RC |
259 | return hppa_sign_extend (hppa_get_field (word, 19, 28) | |
260 | hppa_get_field (word, 29, 29) << 10 | | |
261 | hppa_get_field (word, 11, 15) << 11 | | |
c906108c SS |
262 | (word & 0x1) << 16, 17) << 2; |
263 | } | |
3388d7ff RC |
264 | |
265 | CORE_ADDR | |
266 | hppa_symbol_address(const char *sym) | |
267 | { | |
268 | struct minimal_symbol *minsym; | |
269 | ||
270 | minsym = lookup_minimal_symbol (sym, NULL, NULL); | |
271 | if (minsym) | |
272 | return SYMBOL_VALUE_ADDRESS (minsym); | |
273 | else | |
274 | return (CORE_ADDR)-1; | |
275 | } | |
c906108c SS |
276 | \f |
277 | ||
278 | /* Compare the start address for two unwind entries returning 1 if | |
279 | the first address is larger than the second, -1 if the second is | |
280 | larger than the first, and zero if they are equal. */ | |
281 | ||
282 | static int | |
fba45db2 | 283 | compare_unwind_entries (const void *arg1, const void *arg2) |
c906108c SS |
284 | { |
285 | const struct unwind_table_entry *a = arg1; | |
286 | const struct unwind_table_entry *b = arg2; | |
287 | ||
288 | if (a->region_start > b->region_start) | |
289 | return 1; | |
290 | else if (a->region_start < b->region_start) | |
291 | return -1; | |
292 | else | |
293 | return 0; | |
294 | } | |
295 | ||
53a5351d | 296 | static void |
fdd72f95 | 297 | record_text_segment_lowaddr (bfd *abfd, asection *section, void *data) |
53a5351d | 298 | { |
fdd72f95 | 299 | if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) |
53a5351d | 300 | == (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) |
fdd72f95 RC |
301 | { |
302 | bfd_vma value = section->vma - section->filepos; | |
303 | CORE_ADDR *low_text_segment_address = (CORE_ADDR *)data; | |
304 | ||
305 | if (value < *low_text_segment_address) | |
306 | *low_text_segment_address = value; | |
307 | } | |
53a5351d JM |
308 | } |
309 | ||
c906108c | 310 | static void |
fba45db2 KB |
311 | internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table, |
312 | asection *section, unsigned int entries, unsigned int size, | |
313 | CORE_ADDR text_offset) | |
c906108c SS |
314 | { |
315 | /* We will read the unwind entries into temporary memory, then | |
316 | fill in the actual unwind table. */ | |
fdd72f95 | 317 | |
c906108c SS |
318 | if (size > 0) |
319 | { | |
320 | unsigned long tmp; | |
321 | unsigned i; | |
322 | char *buf = alloca (size); | |
fdd72f95 | 323 | CORE_ADDR low_text_segment_address; |
c906108c | 324 | |
fdd72f95 | 325 | /* For ELF targets, then unwinds are supposed to |
c2c6d25f JM |
326 | be segment relative offsets instead of absolute addresses. |
327 | ||
328 | Note that when loading a shared library (text_offset != 0) the | |
329 | unwinds are already relative to the text_offset that will be | |
330 | passed in. */ | |
fdd72f95 | 331 | if (gdbarch_tdep (current_gdbarch)->is_elf && text_offset == 0) |
53a5351d | 332 | { |
fdd72f95 RC |
333 | low_text_segment_address = -1; |
334 | ||
53a5351d | 335 | bfd_map_over_sections (objfile->obfd, |
fdd72f95 RC |
336 | record_text_segment_lowaddr, |
337 | &low_text_segment_address); | |
53a5351d | 338 | |
fdd72f95 | 339 | text_offset = low_text_segment_address; |
53a5351d JM |
340 | } |
341 | ||
c906108c SS |
342 | bfd_get_section_contents (objfile->obfd, section, buf, 0, size); |
343 | ||
344 | /* Now internalize the information being careful to handle host/target | |
c5aa993b | 345 | endian issues. */ |
c906108c SS |
346 | for (i = 0; i < entries; i++) |
347 | { | |
348 | table[i].region_start = bfd_get_32 (objfile->obfd, | |
c5aa993b | 349 | (bfd_byte *) buf); |
c906108c SS |
350 | table[i].region_start += text_offset; |
351 | buf += 4; | |
c5aa993b | 352 | table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
353 | table[i].region_end += text_offset; |
354 | buf += 4; | |
c5aa993b | 355 | tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
356 | buf += 4; |
357 | table[i].Cannot_unwind = (tmp >> 31) & 0x1; | |
358 | table[i].Millicode = (tmp >> 30) & 0x1; | |
359 | table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1; | |
360 | table[i].Region_description = (tmp >> 27) & 0x3; | |
361 | table[i].reserved1 = (tmp >> 26) & 0x1; | |
362 | table[i].Entry_SR = (tmp >> 25) & 0x1; | |
363 | table[i].Entry_FR = (tmp >> 21) & 0xf; | |
364 | table[i].Entry_GR = (tmp >> 16) & 0x1f; | |
365 | table[i].Args_stored = (tmp >> 15) & 0x1; | |
366 | table[i].Variable_Frame = (tmp >> 14) & 0x1; | |
367 | table[i].Separate_Package_Body = (tmp >> 13) & 0x1; | |
368 | table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1; | |
369 | table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1; | |
370 | table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1; | |
371 | table[i].Ada_Region = (tmp >> 9) & 0x1; | |
372 | table[i].cxx_info = (tmp >> 8) & 0x1; | |
373 | table[i].cxx_try_catch = (tmp >> 7) & 0x1; | |
374 | table[i].sched_entry_seq = (tmp >> 6) & 0x1; | |
375 | table[i].reserved2 = (tmp >> 5) & 0x1; | |
376 | table[i].Save_SP = (tmp >> 4) & 0x1; | |
377 | table[i].Save_RP = (tmp >> 3) & 0x1; | |
378 | table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1; | |
379 | table[i].extn_ptr_defined = (tmp >> 1) & 0x1; | |
380 | table[i].Cleanup_defined = tmp & 0x1; | |
c5aa993b | 381 | tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf); |
c906108c SS |
382 | buf += 4; |
383 | table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1; | |
384 | table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1; | |
385 | table[i].Large_frame = (tmp >> 29) & 0x1; | |
386 | table[i].Pseudo_SP_Set = (tmp >> 28) & 0x1; | |
387 | table[i].reserved4 = (tmp >> 27) & 0x1; | |
388 | table[i].Total_frame_size = tmp & 0x7ffffff; | |
389 | ||
c5aa993b | 390 | /* Stub unwinds are handled elsewhere. */ |
c906108c SS |
391 | table[i].stub_unwind.stub_type = 0; |
392 | table[i].stub_unwind.padding = 0; | |
393 | } | |
394 | } | |
395 | } | |
396 | ||
397 | /* Read in the backtrace information stored in the `$UNWIND_START$' section of | |
398 | the object file. This info is used mainly by find_unwind_entry() to find | |
399 | out the stack frame size and frame pointer used by procedures. We put | |
400 | everything on the psymbol obstack in the objfile so that it automatically | |
401 | gets freed when the objfile is destroyed. */ | |
402 | ||
403 | static void | |
fba45db2 | 404 | read_unwind_info (struct objfile *objfile) |
c906108c | 405 | { |
d4f3574e SS |
406 | asection *unwind_sec, *stub_unwind_sec; |
407 | unsigned unwind_size, stub_unwind_size, total_size; | |
408 | unsigned index, unwind_entries; | |
c906108c SS |
409 | unsigned stub_entries, total_entries; |
410 | CORE_ADDR text_offset; | |
7c46b9fb RC |
411 | struct hppa_unwind_info *ui; |
412 | struct hppa_objfile_private *obj_private; | |
c906108c SS |
413 | |
414 | text_offset = ANOFFSET (objfile->section_offsets, 0); | |
7c46b9fb RC |
415 | ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack, |
416 | sizeof (struct hppa_unwind_info)); | |
c906108c SS |
417 | |
418 | ui->table = NULL; | |
419 | ui->cache = NULL; | |
420 | ui->last = -1; | |
421 | ||
d4f3574e SS |
422 | /* For reasons unknown the HP PA64 tools generate multiple unwinder |
423 | sections in a single executable. So we just iterate over every | |
424 | section in the BFD looking for unwinder sections intead of trying | |
425 | to do a lookup with bfd_get_section_by_name. | |
c906108c | 426 | |
d4f3574e SS |
427 | First determine the total size of the unwind tables so that we |
428 | can allocate memory in a nice big hunk. */ | |
429 | total_entries = 0; | |
430 | for (unwind_sec = objfile->obfd->sections; | |
431 | unwind_sec; | |
432 | unwind_sec = unwind_sec->next) | |
c906108c | 433 | { |
d4f3574e SS |
434 | if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0 |
435 | || strcmp (unwind_sec->name, ".PARISC.unwind") == 0) | |
436 | { | |
437 | unwind_size = bfd_section_size (objfile->obfd, unwind_sec); | |
438 | unwind_entries = unwind_size / UNWIND_ENTRY_SIZE; | |
c906108c | 439 | |
d4f3574e SS |
440 | total_entries += unwind_entries; |
441 | } | |
c906108c SS |
442 | } |
443 | ||
d4f3574e SS |
444 | /* Now compute the size of the stub unwinds. Note the ELF tools do not |
445 | use stub unwinds at the curren time. */ | |
446 | stub_unwind_sec = bfd_get_section_by_name (objfile->obfd, "$UNWIND_END$"); | |
447 | ||
c906108c SS |
448 | if (stub_unwind_sec) |
449 | { | |
450 | stub_unwind_size = bfd_section_size (objfile->obfd, stub_unwind_sec); | |
451 | stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE; | |
452 | } | |
453 | else | |
454 | { | |
455 | stub_unwind_size = 0; | |
456 | stub_entries = 0; | |
457 | } | |
458 | ||
459 | /* Compute total number of unwind entries and their total size. */ | |
d4f3574e | 460 | total_entries += stub_entries; |
c906108c SS |
461 | total_size = total_entries * sizeof (struct unwind_table_entry); |
462 | ||
463 | /* Allocate memory for the unwind table. */ | |
464 | ui->table = (struct unwind_table_entry *) | |
8b92e4d5 | 465 | obstack_alloc (&objfile->objfile_obstack, total_size); |
c5aa993b | 466 | ui->last = total_entries - 1; |
c906108c | 467 | |
d4f3574e SS |
468 | /* Now read in each unwind section and internalize the standard unwind |
469 | entries. */ | |
c906108c | 470 | index = 0; |
d4f3574e SS |
471 | for (unwind_sec = objfile->obfd->sections; |
472 | unwind_sec; | |
473 | unwind_sec = unwind_sec->next) | |
474 | { | |
475 | if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0 | |
476 | || strcmp (unwind_sec->name, ".PARISC.unwind") == 0) | |
477 | { | |
478 | unwind_size = bfd_section_size (objfile->obfd, unwind_sec); | |
479 | unwind_entries = unwind_size / UNWIND_ENTRY_SIZE; | |
480 | ||
481 | internalize_unwinds (objfile, &ui->table[index], unwind_sec, | |
482 | unwind_entries, unwind_size, text_offset); | |
483 | index += unwind_entries; | |
484 | } | |
485 | } | |
486 | ||
487 | /* Now read in and internalize the stub unwind entries. */ | |
c906108c SS |
488 | if (stub_unwind_size > 0) |
489 | { | |
490 | unsigned int i; | |
491 | char *buf = alloca (stub_unwind_size); | |
492 | ||
493 | /* Read in the stub unwind entries. */ | |
494 | bfd_get_section_contents (objfile->obfd, stub_unwind_sec, buf, | |
495 | 0, stub_unwind_size); | |
496 | ||
497 | /* Now convert them into regular unwind entries. */ | |
498 | for (i = 0; i < stub_entries; i++, index++) | |
499 | { | |
500 | /* Clear out the next unwind entry. */ | |
501 | memset (&ui->table[index], 0, sizeof (struct unwind_table_entry)); | |
502 | ||
503 | /* Convert offset & size into region_start and region_end. | |
504 | Stuff away the stub type into "reserved" fields. */ | |
505 | ui->table[index].region_start = bfd_get_32 (objfile->obfd, | |
506 | (bfd_byte *) buf); | |
507 | ui->table[index].region_start += text_offset; | |
508 | buf += 4; | |
509 | ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd, | |
c5aa993b | 510 | (bfd_byte *) buf); |
c906108c SS |
511 | buf += 2; |
512 | ui->table[index].region_end | |
c5aa993b JM |
513 | = ui->table[index].region_start + 4 * |
514 | (bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1); | |
c906108c SS |
515 | buf += 2; |
516 | } | |
517 | ||
518 | } | |
519 | ||
520 | /* Unwind table needs to be kept sorted. */ | |
521 | qsort (ui->table, total_entries, sizeof (struct unwind_table_entry), | |
522 | compare_unwind_entries); | |
523 | ||
524 | /* Keep a pointer to the unwind information. */ | |
7c46b9fb RC |
525 | obj_private = (struct hppa_objfile_private *) |
526 | objfile_data (objfile, hppa_objfile_priv_data); | |
527 | if (obj_private == NULL) | |
c906108c | 528 | { |
7c46b9fb RC |
529 | obj_private = (struct hppa_objfile_private *) |
530 | obstack_alloc (&objfile->objfile_obstack, | |
531 | sizeof (struct hppa_objfile_private)); | |
532 | set_objfile_data (objfile, hppa_objfile_priv_data, obj_private); | |
c906108c | 533 | obj_private->unwind_info = NULL; |
c5aa993b | 534 | obj_private->so_info = NULL; |
53a5351d | 535 | obj_private->dp = 0; |
c906108c | 536 | } |
c906108c SS |
537 | obj_private->unwind_info = ui; |
538 | } | |
539 | ||
540 | /* Lookup the unwind (stack backtrace) info for the given PC. We search all | |
541 | of the objfiles seeking the unwind table entry for this PC. Each objfile | |
542 | contains a sorted list of struct unwind_table_entry. Since we do a binary | |
543 | search of the unwind tables, we depend upon them to be sorted. */ | |
544 | ||
545 | struct unwind_table_entry * | |
fba45db2 | 546 | find_unwind_entry (CORE_ADDR pc) |
c906108c SS |
547 | { |
548 | int first, middle, last; | |
549 | struct objfile *objfile; | |
7c46b9fb | 550 | struct hppa_objfile_private *priv; |
c906108c | 551 | |
369aa520 RC |
552 | if (hppa_debug) |
553 | fprintf_unfiltered (gdb_stdlog, "{ find_unwind_entry 0x%s -> ", | |
554 | paddr_nz (pc)); | |
555 | ||
c906108c SS |
556 | /* A function at address 0? Not in HP-UX! */ |
557 | if (pc == (CORE_ADDR) 0) | |
369aa520 RC |
558 | { |
559 | if (hppa_debug) | |
560 | fprintf_unfiltered (gdb_stdlog, "NULL }\n"); | |
561 | return NULL; | |
562 | } | |
c906108c SS |
563 | |
564 | ALL_OBJFILES (objfile) | |
c5aa993b | 565 | { |
7c46b9fb | 566 | struct hppa_unwind_info *ui; |
c5aa993b | 567 | ui = NULL; |
7c46b9fb RC |
568 | priv = objfile_data (objfile, hppa_objfile_priv_data); |
569 | if (priv) | |
570 | ui = ((struct hppa_objfile_private *) priv)->unwind_info; | |
c906108c | 571 | |
c5aa993b JM |
572 | if (!ui) |
573 | { | |
574 | read_unwind_info (objfile); | |
7c46b9fb RC |
575 | priv = objfile_data (objfile, hppa_objfile_priv_data); |
576 | if (priv == NULL) | |
104c1213 | 577 | error ("Internal error reading unwind information."); |
7c46b9fb | 578 | ui = ((struct hppa_objfile_private *) priv)->unwind_info; |
c5aa993b | 579 | } |
c906108c | 580 | |
c5aa993b | 581 | /* First, check the cache */ |
c906108c | 582 | |
c5aa993b JM |
583 | if (ui->cache |
584 | && pc >= ui->cache->region_start | |
585 | && pc <= ui->cache->region_end) | |
369aa520 RC |
586 | { |
587 | if (hppa_debug) | |
588 | fprintf_unfiltered (gdb_stdlog, "0x%s (cached) }\n", | |
589 | paddr_nz ((CORE_ADDR) ui->cache)); | |
590 | return ui->cache; | |
591 | } | |
c906108c | 592 | |
c5aa993b | 593 | /* Not in the cache, do a binary search */ |
c906108c | 594 | |
c5aa993b JM |
595 | first = 0; |
596 | last = ui->last; | |
c906108c | 597 | |
c5aa993b JM |
598 | while (first <= last) |
599 | { | |
600 | middle = (first + last) / 2; | |
601 | if (pc >= ui->table[middle].region_start | |
602 | && pc <= ui->table[middle].region_end) | |
603 | { | |
604 | ui->cache = &ui->table[middle]; | |
369aa520 RC |
605 | if (hppa_debug) |
606 | fprintf_unfiltered (gdb_stdlog, "0x%s }\n", | |
607 | paddr_nz ((CORE_ADDR) ui->cache)); | |
c5aa993b JM |
608 | return &ui->table[middle]; |
609 | } | |
c906108c | 610 | |
c5aa993b JM |
611 | if (pc < ui->table[middle].region_start) |
612 | last = middle - 1; | |
613 | else | |
614 | first = middle + 1; | |
615 | } | |
616 | } /* ALL_OBJFILES() */ | |
369aa520 RC |
617 | |
618 | if (hppa_debug) | |
619 | fprintf_unfiltered (gdb_stdlog, "NULL (not found) }\n"); | |
620 | ||
c906108c SS |
621 | return NULL; |
622 | } | |
623 | ||
85f4f2d8 | 624 | static const unsigned char * |
aaab4dba AC |
625 | hppa_breakpoint_from_pc (CORE_ADDR *pc, int *len) |
626 | { | |
56132691 | 627 | static const unsigned char breakpoint[] = {0x00, 0x01, 0x00, 0x04}; |
aaab4dba AC |
628 | (*len) = sizeof (breakpoint); |
629 | return breakpoint; | |
630 | } | |
631 | ||
e23457df AC |
632 | /* Return the name of a register. */ |
633 | ||
4a302917 | 634 | static const char * |
3ff7cf9e | 635 | hppa32_register_name (int i) |
e23457df AC |
636 | { |
637 | static char *names[] = { | |
638 | "flags", "r1", "rp", "r3", | |
639 | "r4", "r5", "r6", "r7", | |
640 | "r8", "r9", "r10", "r11", | |
641 | "r12", "r13", "r14", "r15", | |
642 | "r16", "r17", "r18", "r19", | |
643 | "r20", "r21", "r22", "r23", | |
644 | "r24", "r25", "r26", "dp", | |
645 | "ret0", "ret1", "sp", "r31", | |
646 | "sar", "pcoqh", "pcsqh", "pcoqt", | |
647 | "pcsqt", "eiem", "iir", "isr", | |
648 | "ior", "ipsw", "goto", "sr4", | |
649 | "sr0", "sr1", "sr2", "sr3", | |
650 | "sr5", "sr6", "sr7", "cr0", | |
651 | "cr8", "cr9", "ccr", "cr12", | |
652 | "cr13", "cr24", "cr25", "cr26", | |
653 | "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad", | |
654 | "fpsr", "fpe1", "fpe2", "fpe3", | |
655 | "fpe4", "fpe5", "fpe6", "fpe7", | |
656 | "fr4", "fr4R", "fr5", "fr5R", | |
657 | "fr6", "fr6R", "fr7", "fr7R", | |
658 | "fr8", "fr8R", "fr9", "fr9R", | |
659 | "fr10", "fr10R", "fr11", "fr11R", | |
660 | "fr12", "fr12R", "fr13", "fr13R", | |
661 | "fr14", "fr14R", "fr15", "fr15R", | |
662 | "fr16", "fr16R", "fr17", "fr17R", | |
663 | "fr18", "fr18R", "fr19", "fr19R", | |
664 | "fr20", "fr20R", "fr21", "fr21R", | |
665 | "fr22", "fr22R", "fr23", "fr23R", | |
666 | "fr24", "fr24R", "fr25", "fr25R", | |
667 | "fr26", "fr26R", "fr27", "fr27R", | |
668 | "fr28", "fr28R", "fr29", "fr29R", | |
669 | "fr30", "fr30R", "fr31", "fr31R" | |
670 | }; | |
671 | if (i < 0 || i >= (sizeof (names) / sizeof (*names))) | |
672 | return NULL; | |
673 | else | |
674 | return names[i]; | |
675 | } | |
676 | ||
4a302917 | 677 | static const char * |
e23457df AC |
678 | hppa64_register_name (int i) |
679 | { | |
680 | static char *names[] = { | |
681 | "flags", "r1", "rp", "r3", | |
682 | "r4", "r5", "r6", "r7", | |
683 | "r8", "r9", "r10", "r11", | |
684 | "r12", "r13", "r14", "r15", | |
685 | "r16", "r17", "r18", "r19", | |
686 | "r20", "r21", "r22", "r23", | |
687 | "r24", "r25", "r26", "dp", | |
688 | "ret0", "ret1", "sp", "r31", | |
689 | "sar", "pcoqh", "pcsqh", "pcoqt", | |
690 | "pcsqt", "eiem", "iir", "isr", | |
691 | "ior", "ipsw", "goto", "sr4", | |
692 | "sr0", "sr1", "sr2", "sr3", | |
693 | "sr5", "sr6", "sr7", "cr0", | |
694 | "cr8", "cr9", "ccr", "cr12", | |
695 | "cr13", "cr24", "cr25", "cr26", | |
696 | "mpsfu_high","mpsfu_low","mpsfu_ovflo","pad", | |
697 | "fpsr", "fpe1", "fpe2", "fpe3", | |
698 | "fr4", "fr5", "fr6", "fr7", | |
699 | "fr8", "fr9", "fr10", "fr11", | |
700 | "fr12", "fr13", "fr14", "fr15", | |
701 | "fr16", "fr17", "fr18", "fr19", | |
702 | "fr20", "fr21", "fr22", "fr23", | |
703 | "fr24", "fr25", "fr26", "fr27", | |
704 | "fr28", "fr29", "fr30", "fr31" | |
705 | }; | |
706 | if (i < 0 || i >= (sizeof (names) / sizeof (*names))) | |
707 | return NULL; | |
708 | else | |
709 | return names[i]; | |
710 | } | |
711 | ||
79508e1e AC |
712 | /* This function pushes a stack frame with arguments as part of the |
713 | inferior function calling mechanism. | |
714 | ||
715 | This is the version of the function for the 32-bit PA machines, in | |
716 | which later arguments appear at lower addresses. (The stack always | |
717 | grows towards higher addresses.) | |
718 | ||
719 | We simply allocate the appropriate amount of stack space and put | |
720 | arguments into their proper slots. */ | |
721 | ||
4a302917 | 722 | static CORE_ADDR |
7d9b040b | 723 | hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
79508e1e AC |
724 | struct regcache *regcache, CORE_ADDR bp_addr, |
725 | int nargs, struct value **args, CORE_ADDR sp, | |
726 | int struct_return, CORE_ADDR struct_addr) | |
727 | { | |
79508e1e AC |
728 | /* Stack base address at which any pass-by-reference parameters are |
729 | stored. */ | |
730 | CORE_ADDR struct_end = 0; | |
731 | /* Stack base address at which the first parameter is stored. */ | |
732 | CORE_ADDR param_end = 0; | |
733 | ||
734 | /* The inner most end of the stack after all the parameters have | |
735 | been pushed. */ | |
736 | CORE_ADDR new_sp = 0; | |
737 | ||
738 | /* Two passes. First pass computes the location of everything, | |
739 | second pass writes the bytes out. */ | |
740 | int write_pass; | |
d49771ef RC |
741 | |
742 | /* Global pointer (r19) of the function we are trying to call. */ | |
743 | CORE_ADDR gp; | |
744 | ||
745 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
746 | ||
79508e1e AC |
747 | for (write_pass = 0; write_pass < 2; write_pass++) |
748 | { | |
1797a8f6 | 749 | CORE_ADDR struct_ptr = 0; |
2a6228ef RC |
750 | /* The first parameter goes into sp-36, each stack slot is 4-bytes. |
751 | struct_ptr is adjusted for each argument below, so the first | |
752 | argument will end up at sp-36. */ | |
753 | CORE_ADDR param_ptr = 32; | |
79508e1e | 754 | int i; |
2a6228ef RC |
755 | int small_struct = 0; |
756 | ||
79508e1e AC |
757 | for (i = 0; i < nargs; i++) |
758 | { | |
759 | struct value *arg = args[i]; | |
4991999e | 760 | struct type *type = check_typedef (value_type (arg)); |
79508e1e AC |
761 | /* The corresponding parameter that is pushed onto the |
762 | stack, and [possibly] passed in a register. */ | |
763 | char param_val[8]; | |
764 | int param_len; | |
765 | memset (param_val, 0, sizeof param_val); | |
766 | if (TYPE_LENGTH (type) > 8) | |
767 | { | |
768 | /* Large parameter, pass by reference. Store the value | |
769 | in "struct" area and then pass its address. */ | |
770 | param_len = 4; | |
1797a8f6 | 771 | struct_ptr += align_up (TYPE_LENGTH (type), 8); |
79508e1e | 772 | if (write_pass) |
1797a8f6 | 773 | write_memory (struct_end - struct_ptr, VALUE_CONTENTS (arg), |
79508e1e | 774 | TYPE_LENGTH (type)); |
1797a8f6 | 775 | store_unsigned_integer (param_val, 4, struct_end - struct_ptr); |
79508e1e AC |
776 | } |
777 | else if (TYPE_CODE (type) == TYPE_CODE_INT | |
778 | || TYPE_CODE (type) == TYPE_CODE_ENUM) | |
779 | { | |
780 | /* Integer value store, right aligned. "unpack_long" | |
781 | takes care of any sign-extension problems. */ | |
782 | param_len = align_up (TYPE_LENGTH (type), 4); | |
783 | store_unsigned_integer (param_val, param_len, | |
784 | unpack_long (type, | |
785 | VALUE_CONTENTS (arg))); | |
786 | } | |
2a6228ef RC |
787 | else if (TYPE_CODE (type) == TYPE_CODE_FLT) |
788 | { | |
789 | /* Floating point value store, right aligned. */ | |
790 | param_len = align_up (TYPE_LENGTH (type), 4); | |
791 | memcpy (param_val, VALUE_CONTENTS (arg), param_len); | |
792 | } | |
79508e1e AC |
793 | else |
794 | { | |
79508e1e | 795 | param_len = align_up (TYPE_LENGTH (type), 4); |
2a6228ef RC |
796 | |
797 | /* Small struct value are stored right-aligned. */ | |
79508e1e AC |
798 | memcpy (param_val + param_len - TYPE_LENGTH (type), |
799 | VALUE_CONTENTS (arg), TYPE_LENGTH (type)); | |
2a6228ef RC |
800 | |
801 | /* Structures of size 5, 6 and 7 bytes are special in that | |
802 | the higher-ordered word is stored in the lower-ordered | |
803 | argument, and even though it is a 8-byte quantity the | |
804 | registers need not be 8-byte aligned. */ | |
1b07b470 | 805 | if (param_len > 4 && param_len < 8) |
2a6228ef | 806 | small_struct = 1; |
79508e1e | 807 | } |
2a6228ef | 808 | |
1797a8f6 | 809 | param_ptr += param_len; |
2a6228ef RC |
810 | if (param_len == 8 && !small_struct) |
811 | param_ptr = align_up (param_ptr, 8); | |
812 | ||
813 | /* First 4 non-FP arguments are passed in gr26-gr23. | |
814 | First 4 32-bit FP arguments are passed in fr4L-fr7L. | |
815 | First 2 64-bit FP arguments are passed in fr5 and fr7. | |
816 | ||
817 | The rest go on the stack, starting at sp-36, towards lower | |
818 | addresses. 8-byte arguments must be aligned to a 8-byte | |
819 | stack boundary. */ | |
79508e1e AC |
820 | if (write_pass) |
821 | { | |
1797a8f6 | 822 | write_memory (param_end - param_ptr, param_val, param_len); |
2a6228ef RC |
823 | |
824 | /* There are some cases when we don't know the type | |
825 | expected by the callee (e.g. for variadic functions), so | |
826 | pass the parameters in both general and fp regs. */ | |
827 | if (param_ptr <= 48) | |
79508e1e | 828 | { |
2a6228ef RC |
829 | int grreg = 26 - (param_ptr - 36) / 4; |
830 | int fpLreg = 72 + (param_ptr - 36) / 4 * 2; | |
831 | int fpreg = 74 + (param_ptr - 32) / 8 * 4; | |
832 | ||
833 | regcache_cooked_write (regcache, grreg, param_val); | |
834 | regcache_cooked_write (regcache, fpLreg, param_val); | |
835 | ||
79508e1e | 836 | if (param_len > 4) |
2a6228ef RC |
837 | { |
838 | regcache_cooked_write (regcache, grreg + 1, | |
839 | param_val + 4); | |
840 | ||
841 | regcache_cooked_write (regcache, fpreg, param_val); | |
842 | regcache_cooked_write (regcache, fpreg + 1, | |
843 | param_val + 4); | |
844 | } | |
79508e1e AC |
845 | } |
846 | } | |
847 | } | |
848 | ||
849 | /* Update the various stack pointers. */ | |
850 | if (!write_pass) | |
851 | { | |
2a6228ef | 852 | struct_end = sp + align_up (struct_ptr, 64); |
79508e1e AC |
853 | /* PARAM_PTR already accounts for all the arguments passed |
854 | by the user. However, the ABI mandates minimum stack | |
855 | space allocations for outgoing arguments. The ABI also | |
856 | mandates minimum stack alignments which we must | |
857 | preserve. */ | |
2a6228ef | 858 | param_end = struct_end + align_up (param_ptr, 64); |
79508e1e AC |
859 | } |
860 | } | |
861 | ||
862 | /* If a structure has to be returned, set up register 28 to hold its | |
863 | address */ | |
864 | if (struct_return) | |
865 | write_register (28, struct_addr); | |
866 | ||
d49771ef RC |
867 | gp = tdep->find_global_pointer (function); |
868 | ||
869 | if (gp != 0) | |
870 | write_register (19, gp); | |
871 | ||
79508e1e | 872 | /* Set the return address. */ |
34f75cc1 | 873 | regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr); |
79508e1e | 874 | |
c4557624 | 875 | /* Update the Stack Pointer. */ |
34f75cc1 | 876 | regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end); |
c4557624 | 877 | |
2a6228ef | 878 | return param_end; |
79508e1e AC |
879 | } |
880 | ||
2f690297 AC |
881 | /* This function pushes a stack frame with arguments as part of the |
882 | inferior function calling mechanism. | |
883 | ||
884 | This is the version for the PA64, in which later arguments appear | |
885 | at higher addresses. (The stack always grows towards higher | |
886 | addresses.) | |
887 | ||
888 | We simply allocate the appropriate amount of stack space and put | |
889 | arguments into their proper slots. | |
890 | ||
891 | This ABI also requires that the caller provide an argument pointer | |
892 | to the callee, so we do that too. */ | |
893 | ||
4a302917 | 894 | static CORE_ADDR |
7d9b040b | 895 | hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
2f690297 AC |
896 | struct regcache *regcache, CORE_ADDR bp_addr, |
897 | int nargs, struct value **args, CORE_ADDR sp, | |
898 | int struct_return, CORE_ADDR struct_addr) | |
899 | { | |
449e1137 AC |
900 | /* NOTE: cagney/2004-02-27: This is a guess - its implemented by |
901 | reverse engineering testsuite failures. */ | |
2f690297 | 902 | |
449e1137 AC |
903 | /* Stack base address at which any pass-by-reference parameters are |
904 | stored. */ | |
905 | CORE_ADDR struct_end = 0; | |
906 | /* Stack base address at which the first parameter is stored. */ | |
907 | CORE_ADDR param_end = 0; | |
2f690297 | 908 | |
449e1137 AC |
909 | /* The inner most end of the stack after all the parameters have |
910 | been pushed. */ | |
911 | CORE_ADDR new_sp = 0; | |
2f690297 | 912 | |
449e1137 AC |
913 | /* Two passes. First pass computes the location of everything, |
914 | second pass writes the bytes out. */ | |
915 | int write_pass; | |
916 | for (write_pass = 0; write_pass < 2; write_pass++) | |
2f690297 | 917 | { |
449e1137 AC |
918 | CORE_ADDR struct_ptr = 0; |
919 | CORE_ADDR param_ptr = 0; | |
920 | int i; | |
921 | for (i = 0; i < nargs; i++) | |
2f690297 | 922 | { |
449e1137 | 923 | struct value *arg = args[i]; |
4991999e | 924 | struct type *type = check_typedef (value_type (arg)); |
449e1137 AC |
925 | if ((TYPE_CODE (type) == TYPE_CODE_INT |
926 | || TYPE_CODE (type) == TYPE_CODE_ENUM) | |
927 | && TYPE_LENGTH (type) <= 8) | |
928 | { | |
929 | /* Integer value store, right aligned. "unpack_long" | |
930 | takes care of any sign-extension problems. */ | |
931 | param_ptr += 8; | |
932 | if (write_pass) | |
933 | { | |
934 | ULONGEST val = unpack_long (type, VALUE_CONTENTS (arg)); | |
935 | int reg = 27 - param_ptr / 8; | |
936 | write_memory_unsigned_integer (param_end - param_ptr, | |
937 | val, 8); | |
938 | if (reg >= 19) | |
939 | regcache_cooked_write_unsigned (regcache, reg, val); | |
940 | } | |
941 | } | |
942 | else | |
943 | { | |
944 | /* Small struct value, store left aligned? */ | |
945 | int reg; | |
946 | if (TYPE_LENGTH (type) > 8) | |
947 | { | |
948 | param_ptr = align_up (param_ptr, 16); | |
949 | reg = 26 - param_ptr / 8; | |
950 | param_ptr += align_up (TYPE_LENGTH (type), 16); | |
951 | } | |
952 | else | |
953 | { | |
954 | param_ptr = align_up (param_ptr, 8); | |
955 | reg = 26 - param_ptr / 8; | |
956 | param_ptr += align_up (TYPE_LENGTH (type), 8); | |
957 | } | |
958 | if (write_pass) | |
959 | { | |
960 | int byte; | |
961 | write_memory (param_end - param_ptr, VALUE_CONTENTS (arg), | |
962 | TYPE_LENGTH (type)); | |
963 | for (byte = 0; byte < TYPE_LENGTH (type); byte += 8) | |
964 | { | |
965 | if (reg >= 19) | |
966 | { | |
967 | int len = min (8, TYPE_LENGTH (type) - byte); | |
968 | regcache_cooked_write_part (regcache, reg, 0, len, | |
969 | VALUE_CONTENTS (arg) + byte); | |
970 | } | |
971 | reg--; | |
972 | } | |
973 | } | |
974 | } | |
2f690297 | 975 | } |
449e1137 AC |
976 | /* Update the various stack pointers. */ |
977 | if (!write_pass) | |
2f690297 | 978 | { |
449e1137 AC |
979 | struct_end = sp + struct_ptr; |
980 | /* PARAM_PTR already accounts for all the arguments passed | |
981 | by the user. However, the ABI mandates minimum stack | |
982 | space allocations for outgoing arguments. The ABI also | |
983 | mandates minimum stack alignments which we must | |
984 | preserve. */ | |
d0bd2d18 | 985 | param_end = struct_end + max (align_up (param_ptr, 16), 64); |
2f690297 | 986 | } |
2f690297 AC |
987 | } |
988 | ||
2f690297 AC |
989 | /* If a structure has to be returned, set up register 28 to hold its |
990 | address */ | |
991 | if (struct_return) | |
992 | write_register (28, struct_addr); | |
993 | ||
2f690297 | 994 | /* Set the return address. */ |
34f75cc1 | 995 | regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr); |
2f690297 | 996 | |
c4557624 | 997 | /* Update the Stack Pointer. */ |
34f75cc1 | 998 | regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end + 64); |
c4557624 | 999 | |
449e1137 AC |
1000 | /* The stack will have 32 bytes of additional space for a frame marker. */ |
1001 | return param_end + 64; | |
2f690297 AC |
1002 | } |
1003 | ||
d49771ef RC |
1004 | static CORE_ADDR |
1005 | hppa32_convert_from_func_ptr_addr (struct gdbarch *gdbarch, | |
1006 | CORE_ADDR addr, | |
1007 | struct target_ops *targ) | |
1008 | { | |
1009 | if (addr & 2) | |
1010 | { | |
1011 | CORE_ADDR plabel; | |
1012 | ||
1013 | plabel = addr & ~3; | |
1014 | target_read_memory(plabel, (char *)&addr, 4); | |
1015 | } | |
1016 | ||
1017 | return addr; | |
1018 | } | |
1019 | ||
1797a8f6 AC |
1020 | static CORE_ADDR |
1021 | hppa32_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
1022 | { | |
1023 | /* HP frames are 64-byte (or cache line) aligned (yes that's _byte_ | |
1024 | and not _bit_)! */ | |
1025 | return align_up (addr, 64); | |
1026 | } | |
1027 | ||
2f690297 AC |
1028 | /* Force all frames to 16-byte alignment. Better safe than sorry. */ |
1029 | ||
1030 | static CORE_ADDR | |
1797a8f6 | 1031 | hppa64_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) |
2f690297 AC |
1032 | { |
1033 | /* Just always 16-byte align. */ | |
1034 | return align_up (addr, 16); | |
1035 | } | |
1036 | ||
cc72850f MK |
1037 | CORE_ADDR |
1038 | hppa_read_pc (ptid_t ptid) | |
c906108c | 1039 | { |
cc72850f | 1040 | ULONGEST ipsw; |
fe46cd3a | 1041 | CORE_ADDR pc; |
c906108c | 1042 | |
cc72850f MK |
1043 | ipsw = read_register_pid (HPPA_IPSW_REGNUM, ptid); |
1044 | pc = read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid); | |
fe46cd3a RC |
1045 | |
1046 | /* If the current instruction is nullified, then we are effectively | |
1047 | still executing the previous instruction. Pretend we are still | |
cc72850f MK |
1048 | there. This is needed when single stepping; if the nullified |
1049 | instruction is on a different line, we don't want GDB to think | |
1050 | we've stepped onto that line. */ | |
fe46cd3a RC |
1051 | if (ipsw & 0x00200000) |
1052 | pc -= 4; | |
1053 | ||
cc72850f | 1054 | return pc & ~0x3; |
c906108c SS |
1055 | } |
1056 | ||
cc72850f MK |
1057 | void |
1058 | hppa_write_pc (CORE_ADDR pc, ptid_t ptid) | |
c906108c | 1059 | { |
cc72850f MK |
1060 | write_register_pid (HPPA_PCOQ_HEAD_REGNUM, pc, ptid); |
1061 | write_register_pid (HPPA_PCOQ_TAIL_REGNUM, pc + 4, ptid); | |
c906108c SS |
1062 | } |
1063 | ||
1064 | /* return the alignment of a type in bytes. Structures have the maximum | |
1065 | alignment required by their fields. */ | |
1066 | ||
1067 | static int | |
fba45db2 | 1068 | hppa_alignof (struct type *type) |
c906108c SS |
1069 | { |
1070 | int max_align, align, i; | |
1071 | CHECK_TYPEDEF (type); | |
1072 | switch (TYPE_CODE (type)) | |
1073 | { | |
1074 | case TYPE_CODE_PTR: | |
1075 | case TYPE_CODE_INT: | |
1076 | case TYPE_CODE_FLT: | |
1077 | return TYPE_LENGTH (type); | |
1078 | case TYPE_CODE_ARRAY: | |
1079 | return hppa_alignof (TYPE_FIELD_TYPE (type, 0)); | |
1080 | case TYPE_CODE_STRUCT: | |
1081 | case TYPE_CODE_UNION: | |
1082 | max_align = 1; | |
1083 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
1084 | { | |
1085 | /* Bit fields have no real alignment. */ | |
1086 | /* if (!TYPE_FIELD_BITPOS (type, i)) */ | |
c5aa993b | 1087 | if (!TYPE_FIELD_BITSIZE (type, i)) /* elz: this should be bitsize */ |
c906108c SS |
1088 | { |
1089 | align = hppa_alignof (TYPE_FIELD_TYPE (type, i)); | |
1090 | max_align = max (max_align, align); | |
1091 | } | |
1092 | } | |
1093 | return max_align; | |
1094 | default: | |
1095 | return 4; | |
1096 | } | |
1097 | } | |
1098 | ||
c906108c SS |
1099 | /* For the given instruction (INST), return any adjustment it makes |
1100 | to the stack pointer or zero for no adjustment. | |
1101 | ||
1102 | This only handles instructions commonly found in prologues. */ | |
1103 | ||
1104 | static int | |
fba45db2 | 1105 | prologue_inst_adjust_sp (unsigned long inst) |
c906108c SS |
1106 | { |
1107 | /* This must persist across calls. */ | |
1108 | static int save_high21; | |
1109 | ||
1110 | /* The most common way to perform a stack adjustment ldo X(sp),sp */ | |
1111 | if ((inst & 0xffffc000) == 0x37de0000) | |
abc485a1 | 1112 | return hppa_extract_14 (inst); |
c906108c SS |
1113 | |
1114 | /* stwm X,D(sp) */ | |
1115 | if ((inst & 0xffe00000) == 0x6fc00000) | |
abc485a1 | 1116 | return hppa_extract_14 (inst); |
c906108c | 1117 | |
104c1213 JM |
1118 | /* std,ma X,D(sp) */ |
1119 | if ((inst & 0xffe00008) == 0x73c00008) | |
d4f3574e | 1120 | return (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3); |
104c1213 | 1121 | |
c906108c SS |
1122 | /* addil high21,%r1; ldo low11,(%r1),%r30) |
1123 | save high bits in save_high21 for later use. */ | |
1124 | if ((inst & 0xffe00000) == 0x28200000) | |
1125 | { | |
abc485a1 | 1126 | save_high21 = hppa_extract_21 (inst); |
c906108c SS |
1127 | return 0; |
1128 | } | |
1129 | ||
1130 | if ((inst & 0xffff0000) == 0x343e0000) | |
abc485a1 | 1131 | return save_high21 + hppa_extract_14 (inst); |
c906108c SS |
1132 | |
1133 | /* fstws as used by the HP compilers. */ | |
1134 | if ((inst & 0xffffffe0) == 0x2fd01220) | |
abc485a1 | 1135 | return hppa_extract_5_load (inst); |
c906108c SS |
1136 | |
1137 | /* No adjustment. */ | |
1138 | return 0; | |
1139 | } | |
1140 | ||
1141 | /* Return nonzero if INST is a branch of some kind, else return zero. */ | |
1142 | ||
1143 | static int | |
fba45db2 | 1144 | is_branch (unsigned long inst) |
c906108c SS |
1145 | { |
1146 | switch (inst >> 26) | |
1147 | { | |
1148 | case 0x20: | |
1149 | case 0x21: | |
1150 | case 0x22: | |
1151 | case 0x23: | |
7be570e7 | 1152 | case 0x27: |
c906108c SS |
1153 | case 0x28: |
1154 | case 0x29: | |
1155 | case 0x2a: | |
1156 | case 0x2b: | |
7be570e7 | 1157 | case 0x2f: |
c906108c SS |
1158 | case 0x30: |
1159 | case 0x31: | |
1160 | case 0x32: | |
1161 | case 0x33: | |
1162 | case 0x38: | |
1163 | case 0x39: | |
1164 | case 0x3a: | |
7be570e7 | 1165 | case 0x3b: |
c906108c SS |
1166 | return 1; |
1167 | ||
1168 | default: | |
1169 | return 0; | |
1170 | } | |
1171 | } | |
1172 | ||
1173 | /* Return the register number for a GR which is saved by INST or | |
1174 | zero it INST does not save a GR. */ | |
1175 | ||
1176 | static int | |
fba45db2 | 1177 | inst_saves_gr (unsigned long inst) |
c906108c SS |
1178 | { |
1179 | /* Does it look like a stw? */ | |
7be570e7 JM |
1180 | if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b |
1181 | || (inst >> 26) == 0x1f | |
1182 | || ((inst >> 26) == 0x1f | |
1183 | && ((inst >> 6) == 0xa))) | |
abc485a1 | 1184 | return hppa_extract_5R_store (inst); |
7be570e7 JM |
1185 | |
1186 | /* Does it look like a std? */ | |
1187 | if ((inst >> 26) == 0x1c | |
1188 | || ((inst >> 26) == 0x03 | |
1189 | && ((inst >> 6) & 0xf) == 0xb)) | |
abc485a1 | 1190 | return hppa_extract_5R_store (inst); |
c906108c SS |
1191 | |
1192 | /* Does it look like a stwm? GCC & HPC may use this in prologues. */ | |
1193 | if ((inst >> 26) == 0x1b) | |
abc485a1 | 1194 | return hppa_extract_5R_store (inst); |
c906108c SS |
1195 | |
1196 | /* Does it look like sth or stb? HPC versions 9.0 and later use these | |
1197 | too. */ | |
7be570e7 JM |
1198 | if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18 |
1199 | || ((inst >> 26) == 0x3 | |
1200 | && (((inst >> 6) & 0xf) == 0x8 | |
1201 | || (inst >> 6) & 0xf) == 0x9)) | |
abc485a1 | 1202 | return hppa_extract_5R_store (inst); |
c5aa993b | 1203 | |
c906108c SS |
1204 | return 0; |
1205 | } | |
1206 | ||
1207 | /* Return the register number for a FR which is saved by INST or | |
1208 | zero it INST does not save a FR. | |
1209 | ||
1210 | Note we only care about full 64bit register stores (that's the only | |
1211 | kind of stores the prologue will use). | |
1212 | ||
1213 | FIXME: What about argument stores with the HP compiler in ANSI mode? */ | |
1214 | ||
1215 | static int | |
fba45db2 | 1216 | inst_saves_fr (unsigned long inst) |
c906108c | 1217 | { |
7be570e7 | 1218 | /* is this an FSTD ? */ |
c906108c | 1219 | if ((inst & 0xfc00dfc0) == 0x2c001200) |
abc485a1 | 1220 | return hppa_extract_5r_store (inst); |
7be570e7 | 1221 | if ((inst & 0xfc000002) == 0x70000002) |
abc485a1 | 1222 | return hppa_extract_5R_store (inst); |
7be570e7 | 1223 | /* is this an FSTW ? */ |
c906108c | 1224 | if ((inst & 0xfc00df80) == 0x24001200) |
abc485a1 | 1225 | return hppa_extract_5r_store (inst); |
7be570e7 | 1226 | if ((inst & 0xfc000002) == 0x7c000000) |
abc485a1 | 1227 | return hppa_extract_5R_store (inst); |
c906108c SS |
1228 | return 0; |
1229 | } | |
1230 | ||
1231 | /* Advance PC across any function entry prologue instructions | |
1232 | to reach some "real" code. | |
1233 | ||
1234 | Use information in the unwind table to determine what exactly should | |
1235 | be in the prologue. */ | |
1236 | ||
1237 | ||
a71f8c30 RC |
1238 | static CORE_ADDR |
1239 | skip_prologue_hard_way (CORE_ADDR pc, int stop_before_branch) | |
c906108c SS |
1240 | { |
1241 | char buf[4]; | |
1242 | CORE_ADDR orig_pc = pc; | |
1243 | unsigned long inst, stack_remaining, save_gr, save_fr, save_rp, save_sp; | |
1244 | unsigned long args_stored, status, i, restart_gr, restart_fr; | |
1245 | struct unwind_table_entry *u; | |
a71f8c30 | 1246 | int final_iteration; |
c906108c SS |
1247 | |
1248 | restart_gr = 0; | |
1249 | restart_fr = 0; | |
1250 | ||
1251 | restart: | |
1252 | u = find_unwind_entry (pc); | |
1253 | if (!u) | |
1254 | return pc; | |
1255 | ||
c5aa993b | 1256 | /* If we are not at the beginning of a function, then return now. */ |
c906108c SS |
1257 | if ((pc & ~0x3) != u->region_start) |
1258 | return pc; | |
1259 | ||
1260 | /* This is how much of a frame adjustment we need to account for. */ | |
1261 | stack_remaining = u->Total_frame_size << 3; | |
1262 | ||
1263 | /* Magic register saves we want to know about. */ | |
1264 | save_rp = u->Save_RP; | |
1265 | save_sp = u->Save_SP; | |
1266 | ||
1267 | /* An indication that args may be stored into the stack. Unfortunately | |
1268 | the HPUX compilers tend to set this in cases where no args were | |
1269 | stored too!. */ | |
1270 | args_stored = 1; | |
1271 | ||
1272 | /* Turn the Entry_GR field into a bitmask. */ | |
1273 | save_gr = 0; | |
1274 | for (i = 3; i < u->Entry_GR + 3; i++) | |
1275 | { | |
1276 | /* Frame pointer gets saved into a special location. */ | |
eded0a31 | 1277 | if (u->Save_SP && i == HPPA_FP_REGNUM) |
c906108c SS |
1278 | continue; |
1279 | ||
1280 | save_gr |= (1 << i); | |
1281 | } | |
1282 | save_gr &= ~restart_gr; | |
1283 | ||
1284 | /* Turn the Entry_FR field into a bitmask too. */ | |
1285 | save_fr = 0; | |
1286 | for (i = 12; i < u->Entry_FR + 12; i++) | |
1287 | save_fr |= (1 << i); | |
1288 | save_fr &= ~restart_fr; | |
1289 | ||
a71f8c30 RC |
1290 | final_iteration = 0; |
1291 | ||
c906108c SS |
1292 | /* Loop until we find everything of interest or hit a branch. |
1293 | ||
1294 | For unoptimized GCC code and for any HP CC code this will never ever | |
1295 | examine any user instructions. | |
1296 | ||
1297 | For optimzied GCC code we're faced with problems. GCC will schedule | |
1298 | its prologue and make prologue instructions available for delay slot | |
1299 | filling. The end result is user code gets mixed in with the prologue | |
1300 | and a prologue instruction may be in the delay slot of the first branch | |
1301 | or call. | |
1302 | ||
1303 | Some unexpected things are expected with debugging optimized code, so | |
1304 | we allow this routine to walk past user instructions in optimized | |
1305 | GCC code. */ | |
1306 | while (save_gr || save_fr || save_rp || save_sp || stack_remaining > 0 | |
1307 | || args_stored) | |
1308 | { | |
1309 | unsigned int reg_num; | |
1310 | unsigned long old_stack_remaining, old_save_gr, old_save_fr; | |
1311 | unsigned long old_save_rp, old_save_sp, next_inst; | |
1312 | ||
1313 | /* Save copies of all the triggers so we can compare them later | |
c5aa993b | 1314 | (only for HPC). */ |
c906108c SS |
1315 | old_save_gr = save_gr; |
1316 | old_save_fr = save_fr; | |
1317 | old_save_rp = save_rp; | |
1318 | old_save_sp = save_sp; | |
1319 | old_stack_remaining = stack_remaining; | |
1320 | ||
1f602b35 | 1321 | status = deprecated_read_memory_nobpt (pc, buf, 4); |
c906108c | 1322 | inst = extract_unsigned_integer (buf, 4); |
c5aa993b | 1323 | |
c906108c SS |
1324 | /* Yow! */ |
1325 | if (status != 0) | |
1326 | return pc; | |
1327 | ||
1328 | /* Note the interesting effects of this instruction. */ | |
1329 | stack_remaining -= prologue_inst_adjust_sp (inst); | |
1330 | ||
7be570e7 JM |
1331 | /* There are limited ways to store the return pointer into the |
1332 | stack. */ | |
1333 | if (inst == 0x6bc23fd9 || inst == 0x0fc212c1) | |
c906108c SS |
1334 | save_rp = 0; |
1335 | ||
104c1213 | 1336 | /* These are the only ways we save SP into the stack. At this time |
c5aa993b | 1337 | the HP compilers never bother to save SP into the stack. */ |
104c1213 JM |
1338 | if ((inst & 0xffffc000) == 0x6fc10000 |
1339 | || (inst & 0xffffc00c) == 0x73c10008) | |
c906108c SS |
1340 | save_sp = 0; |
1341 | ||
6426a772 JM |
1342 | /* Are we loading some register with an offset from the argument |
1343 | pointer? */ | |
1344 | if ((inst & 0xffe00000) == 0x37a00000 | |
1345 | || (inst & 0xffffffe0) == 0x081d0240) | |
1346 | { | |
1347 | pc += 4; | |
1348 | continue; | |
1349 | } | |
1350 | ||
c906108c SS |
1351 | /* Account for general and floating-point register saves. */ |
1352 | reg_num = inst_saves_gr (inst); | |
1353 | save_gr &= ~(1 << reg_num); | |
1354 | ||
1355 | /* Ugh. Also account for argument stores into the stack. | |
c5aa993b JM |
1356 | Unfortunately args_stored only tells us that some arguments |
1357 | where stored into the stack. Not how many or what kind! | |
c906108c | 1358 | |
c5aa993b JM |
1359 | This is a kludge as on the HP compiler sets this bit and it |
1360 | never does prologue scheduling. So once we see one, skip past | |
1361 | all of them. We have similar code for the fp arg stores below. | |
c906108c | 1362 | |
c5aa993b JM |
1363 | FIXME. Can still die if we have a mix of GR and FR argument |
1364 | stores! */ | |
6426a772 | 1365 | if (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26) |
c906108c | 1366 | { |
6426a772 | 1367 | while (reg_num >= (TARGET_PTR_BIT == 64 ? 19 : 23) && reg_num <= 26) |
c906108c SS |
1368 | { |
1369 | pc += 4; | |
1f602b35 | 1370 | status = deprecated_read_memory_nobpt (pc, buf, 4); |
c906108c SS |
1371 | inst = extract_unsigned_integer (buf, 4); |
1372 | if (status != 0) | |
1373 | return pc; | |
1374 | reg_num = inst_saves_gr (inst); | |
1375 | } | |
1376 | args_stored = 0; | |
1377 | continue; | |
1378 | } | |
1379 | ||
1380 | reg_num = inst_saves_fr (inst); | |
1381 | save_fr &= ~(1 << reg_num); | |
1382 | ||
1f602b35 | 1383 | status = deprecated_read_memory_nobpt (pc + 4, buf, 4); |
c906108c | 1384 | next_inst = extract_unsigned_integer (buf, 4); |
c5aa993b | 1385 | |
c906108c SS |
1386 | /* Yow! */ |
1387 | if (status != 0) | |
1388 | return pc; | |
1389 | ||
1390 | /* We've got to be read to handle the ldo before the fp register | |
c5aa993b | 1391 | save. */ |
c906108c SS |
1392 | if ((inst & 0xfc000000) == 0x34000000 |
1393 | && inst_saves_fr (next_inst) >= 4 | |
6426a772 | 1394 | && inst_saves_fr (next_inst) <= (TARGET_PTR_BIT == 64 ? 11 : 7)) |
c906108c SS |
1395 | { |
1396 | /* So we drop into the code below in a reasonable state. */ | |
1397 | reg_num = inst_saves_fr (next_inst); | |
1398 | pc -= 4; | |
1399 | } | |
1400 | ||
1401 | /* Ugh. Also account for argument stores into the stack. | |
c5aa993b JM |
1402 | This is a kludge as on the HP compiler sets this bit and it |
1403 | never does prologue scheduling. So once we see one, skip past | |
1404 | all of them. */ | |
6426a772 | 1405 | if (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7)) |
c906108c | 1406 | { |
6426a772 | 1407 | while (reg_num >= 4 && reg_num <= (TARGET_PTR_BIT == 64 ? 11 : 7)) |
c906108c SS |
1408 | { |
1409 | pc += 8; | |
1f602b35 | 1410 | status = deprecated_read_memory_nobpt (pc, buf, 4); |
c906108c SS |
1411 | inst = extract_unsigned_integer (buf, 4); |
1412 | if (status != 0) | |
1413 | return pc; | |
1414 | if ((inst & 0xfc000000) != 0x34000000) | |
1415 | break; | |
1f602b35 | 1416 | status = deprecated_read_memory_nobpt (pc + 4, buf, 4); |
c906108c SS |
1417 | next_inst = extract_unsigned_integer (buf, 4); |
1418 | if (status != 0) | |
1419 | return pc; | |
1420 | reg_num = inst_saves_fr (next_inst); | |
1421 | } | |
1422 | args_stored = 0; | |
1423 | continue; | |
1424 | } | |
1425 | ||
1426 | /* Quit if we hit any kind of branch. This can happen if a prologue | |
c5aa993b | 1427 | instruction is in the delay slot of the first call/branch. */ |
a71f8c30 | 1428 | if (is_branch (inst) && stop_before_branch) |
c906108c SS |
1429 | break; |
1430 | ||
1431 | /* What a crock. The HP compilers set args_stored even if no | |
c5aa993b JM |
1432 | arguments were stored into the stack (boo hiss). This could |
1433 | cause this code to then skip a bunch of user insns (up to the | |
1434 | first branch). | |
1435 | ||
1436 | To combat this we try to identify when args_stored was bogusly | |
1437 | set and clear it. We only do this when args_stored is nonzero, | |
1438 | all other resources are accounted for, and nothing changed on | |
1439 | this pass. */ | |
c906108c | 1440 | if (args_stored |
c5aa993b | 1441 | && !(save_gr || save_fr || save_rp || save_sp || stack_remaining > 0) |
c906108c SS |
1442 | && old_save_gr == save_gr && old_save_fr == save_fr |
1443 | && old_save_rp == save_rp && old_save_sp == save_sp | |
1444 | && old_stack_remaining == stack_remaining) | |
1445 | break; | |
c5aa993b | 1446 | |
c906108c SS |
1447 | /* Bump the PC. */ |
1448 | pc += 4; | |
a71f8c30 RC |
1449 | |
1450 | /* !stop_before_branch, so also look at the insn in the delay slot | |
1451 | of the branch. */ | |
1452 | if (final_iteration) | |
1453 | break; | |
1454 | if (is_branch (inst)) | |
1455 | final_iteration = 1; | |
c906108c SS |
1456 | } |
1457 | ||
1458 | /* We've got a tenative location for the end of the prologue. However | |
1459 | because of limitations in the unwind descriptor mechanism we may | |
1460 | have went too far into user code looking for the save of a register | |
1461 | that does not exist. So, if there registers we expected to be saved | |
1462 | but never were, mask them out and restart. | |
1463 | ||
1464 | This should only happen in optimized code, and should be very rare. */ | |
c5aa993b | 1465 | if (save_gr || (save_fr && !(restart_fr || restart_gr))) |
c906108c SS |
1466 | { |
1467 | pc = orig_pc; | |
1468 | restart_gr = save_gr; | |
1469 | restart_fr = save_fr; | |
1470 | goto restart; | |
1471 | } | |
1472 | ||
1473 | return pc; | |
1474 | } | |
1475 | ||
1476 | ||
7be570e7 JM |
1477 | /* Return the address of the PC after the last prologue instruction if |
1478 | we can determine it from the debug symbols. Else return zero. */ | |
c906108c SS |
1479 | |
1480 | static CORE_ADDR | |
fba45db2 | 1481 | after_prologue (CORE_ADDR pc) |
c906108c SS |
1482 | { |
1483 | struct symtab_and_line sal; | |
1484 | CORE_ADDR func_addr, func_end; | |
1485 | struct symbol *f; | |
1486 | ||
7be570e7 JM |
1487 | /* If we can not find the symbol in the partial symbol table, then |
1488 | there is no hope we can determine the function's start address | |
1489 | with this code. */ | |
c906108c | 1490 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) |
7be570e7 | 1491 | return 0; |
c906108c | 1492 | |
7be570e7 | 1493 | /* Get the line associated with FUNC_ADDR. */ |
c906108c SS |
1494 | sal = find_pc_line (func_addr, 0); |
1495 | ||
7be570e7 JM |
1496 | /* There are only two cases to consider. First, the end of the source line |
1497 | is within the function bounds. In that case we return the end of the | |
1498 | source line. Second is the end of the source line extends beyond the | |
1499 | bounds of the current function. We need to use the slow code to | |
1500 | examine instructions in that case. | |
c906108c | 1501 | |
7be570e7 JM |
1502 | Anything else is simply a bug elsewhere. Fixing it here is absolutely |
1503 | the wrong thing to do. In fact, it should be entirely possible for this | |
1504 | function to always return zero since the slow instruction scanning code | |
1505 | is supposed to *always* work. If it does not, then it is a bug. */ | |
1506 | if (sal.end < func_end) | |
1507 | return sal.end; | |
c5aa993b | 1508 | else |
7be570e7 | 1509 | return 0; |
c906108c SS |
1510 | } |
1511 | ||
1512 | /* To skip prologues, I use this predicate. Returns either PC itself | |
1513 | if the code at PC does not look like a function prologue; otherwise | |
a71f8c30 RC |
1514 | returns an address that (if we're lucky) follows the prologue. |
1515 | ||
1516 | hppa_skip_prologue is called by gdb to place a breakpoint in a function. | |
1517 | It doesn't necessarily skips all the insns in the prologue. In fact | |
1518 | we might not want to skip all the insns because a prologue insn may | |
1519 | appear in the delay slot of the first branch, and we don't want to | |
1520 | skip over the branch in that case. */ | |
c906108c | 1521 | |
8d153463 | 1522 | static CORE_ADDR |
fba45db2 | 1523 | hppa_skip_prologue (CORE_ADDR pc) |
c906108c | 1524 | { |
c5aa993b JM |
1525 | unsigned long inst; |
1526 | int offset; | |
1527 | CORE_ADDR post_prologue_pc; | |
1528 | char buf[4]; | |
c906108c | 1529 | |
c5aa993b JM |
1530 | /* See if we can determine the end of the prologue via the symbol table. |
1531 | If so, then return either PC, or the PC after the prologue, whichever | |
1532 | is greater. */ | |
c906108c | 1533 | |
c5aa993b | 1534 | post_prologue_pc = after_prologue (pc); |
c906108c | 1535 | |
7be570e7 JM |
1536 | /* If after_prologue returned a useful address, then use it. Else |
1537 | fall back on the instruction skipping code. | |
1538 | ||
1539 | Some folks have claimed this causes problems because the breakpoint | |
1540 | may be the first instruction of the prologue. If that happens, then | |
1541 | the instruction skipping code has a bug that needs to be fixed. */ | |
c5aa993b JM |
1542 | if (post_prologue_pc != 0) |
1543 | return max (pc, post_prologue_pc); | |
c5aa993b | 1544 | else |
a71f8c30 | 1545 | return (skip_prologue_hard_way (pc, 1)); |
c906108c SS |
1546 | } |
1547 | ||
26d08f08 AC |
1548 | struct hppa_frame_cache |
1549 | { | |
1550 | CORE_ADDR base; | |
1551 | struct trad_frame_saved_reg *saved_regs; | |
1552 | }; | |
1553 | ||
1554 | static struct hppa_frame_cache * | |
1555 | hppa_frame_cache (struct frame_info *next_frame, void **this_cache) | |
1556 | { | |
1557 | struct hppa_frame_cache *cache; | |
1558 | long saved_gr_mask; | |
1559 | long saved_fr_mask; | |
1560 | CORE_ADDR this_sp; | |
1561 | long frame_size; | |
1562 | struct unwind_table_entry *u; | |
9f7194c3 | 1563 | CORE_ADDR prologue_end; |
50b2f48a | 1564 | int fp_in_r1 = 0; |
26d08f08 AC |
1565 | int i; |
1566 | ||
369aa520 RC |
1567 | if (hppa_debug) |
1568 | fprintf_unfiltered (gdb_stdlog, "{ hppa_frame_cache (frame=%d) -> ", | |
1569 | frame_relative_level(next_frame)); | |
1570 | ||
26d08f08 | 1571 | if ((*this_cache) != NULL) |
369aa520 RC |
1572 | { |
1573 | if (hppa_debug) | |
1574 | fprintf_unfiltered (gdb_stdlog, "base=0x%s (cached) }", | |
1575 | paddr_nz (((struct hppa_frame_cache *)*this_cache)->base)); | |
1576 | return (*this_cache); | |
1577 | } | |
26d08f08 AC |
1578 | cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache); |
1579 | (*this_cache) = cache; | |
1580 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
1581 | ||
1582 | /* Yow! */ | |
d5c27f81 | 1583 | u = find_unwind_entry (frame_pc_unwind (next_frame)); |
26d08f08 | 1584 | if (!u) |
369aa520 RC |
1585 | { |
1586 | if (hppa_debug) | |
1587 | fprintf_unfiltered (gdb_stdlog, "base=NULL (no unwind entry) }"); | |
1588 | return (*this_cache); | |
1589 | } | |
26d08f08 AC |
1590 | |
1591 | /* Turn the Entry_GR field into a bitmask. */ | |
1592 | saved_gr_mask = 0; | |
1593 | for (i = 3; i < u->Entry_GR + 3; i++) | |
1594 | { | |
1595 | /* Frame pointer gets saved into a special location. */ | |
eded0a31 | 1596 | if (u->Save_SP && i == HPPA_FP_REGNUM) |
26d08f08 AC |
1597 | continue; |
1598 | ||
1599 | saved_gr_mask |= (1 << i); | |
1600 | } | |
1601 | ||
1602 | /* Turn the Entry_FR field into a bitmask too. */ | |
1603 | saved_fr_mask = 0; | |
1604 | for (i = 12; i < u->Entry_FR + 12; i++) | |
1605 | saved_fr_mask |= (1 << i); | |
1606 | ||
1607 | /* Loop until we find everything of interest or hit a branch. | |
1608 | ||
1609 | For unoptimized GCC code and for any HP CC code this will never ever | |
1610 | examine any user instructions. | |
1611 | ||
1612 | For optimized GCC code we're faced with problems. GCC will schedule | |
1613 | its prologue and make prologue instructions available for delay slot | |
1614 | filling. The end result is user code gets mixed in with the prologue | |
1615 | and a prologue instruction may be in the delay slot of the first branch | |
1616 | or call. | |
1617 | ||
1618 | Some unexpected things are expected with debugging optimized code, so | |
1619 | we allow this routine to walk past user instructions in optimized | |
1620 | GCC code. */ | |
1621 | { | |
1622 | int final_iteration = 0; | |
9f7194c3 | 1623 | CORE_ADDR pc, end_pc; |
26d08f08 AC |
1624 | int looking_for_sp = u->Save_SP; |
1625 | int looking_for_rp = u->Save_RP; | |
1626 | int fp_loc = -1; | |
9f7194c3 | 1627 | |
a71f8c30 | 1628 | /* We have to use skip_prologue_hard_way instead of just |
9f7194c3 RC |
1629 | skip_prologue_using_sal, in case we stepped into a function without |
1630 | symbol information. hppa_skip_prologue also bounds the returned | |
1631 | pc by the passed in pc, so it will not return a pc in the next | |
a71f8c30 RC |
1632 | function. |
1633 | ||
1634 | We used to call hppa_skip_prologue to find the end of the prologue, | |
1635 | but if some non-prologue instructions get scheduled into the prologue, | |
1636 | and the program is compiled with debug information, the "easy" way | |
1637 | in hppa_skip_prologue will return a prologue end that is too early | |
1638 | for us to notice any potential frame adjustments. */ | |
d5c27f81 RC |
1639 | |
1640 | /* We used to use frame_func_unwind () to locate the beginning of the | |
1641 | function to pass to skip_prologue (). However, when objects are | |
1642 | compiled without debug symbols, frame_func_unwind can return the wrong | |
1643 | function (or 0). We can do better than that by using unwind records. */ | |
1644 | ||
a71f8c30 | 1645 | prologue_end = skip_prologue_hard_way (u->region_start, 0); |
9f7194c3 RC |
1646 | end_pc = frame_pc_unwind (next_frame); |
1647 | ||
1648 | if (prologue_end != 0 && end_pc > prologue_end) | |
1649 | end_pc = prologue_end; | |
1650 | ||
26d08f08 | 1651 | frame_size = 0; |
9f7194c3 | 1652 | |
d5c27f81 | 1653 | for (pc = u->region_start; |
26d08f08 AC |
1654 | ((saved_gr_mask || saved_fr_mask |
1655 | || looking_for_sp || looking_for_rp | |
1656 | || frame_size < (u->Total_frame_size << 3)) | |
9f7194c3 | 1657 | && pc < end_pc); |
26d08f08 AC |
1658 | pc += 4) |
1659 | { | |
1660 | int reg; | |
1661 | char buf4[4]; | |
4a302917 RC |
1662 | long inst; |
1663 | ||
1664 | if (!safe_frame_unwind_memory (next_frame, pc, buf4, | |
1665 | sizeof buf4)) | |
1666 | { | |
1667 | error ("Cannot read instruction at 0x%s\n", paddr_nz (pc)); | |
1668 | return (*this_cache); | |
1669 | } | |
1670 | ||
1671 | inst = extract_unsigned_integer (buf4, sizeof buf4); | |
9f7194c3 | 1672 | |
26d08f08 AC |
1673 | /* Note the interesting effects of this instruction. */ |
1674 | frame_size += prologue_inst_adjust_sp (inst); | |
1675 | ||
1676 | /* There are limited ways to store the return pointer into the | |
1677 | stack. */ | |
1678 | if (inst == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */ | |
1679 | { | |
1680 | looking_for_rp = 0; | |
34f75cc1 | 1681 | cache->saved_regs[HPPA_RP_REGNUM].addr = -20; |
26d08f08 | 1682 | } |
dfaf8edb MK |
1683 | else if (inst == 0x6bc23fd1) /* stw rp,-0x18(sr0,sp) */ |
1684 | { | |
1685 | looking_for_rp = 0; | |
1686 | cache->saved_regs[HPPA_RP_REGNUM].addr = -24; | |
1687 | } | |
26d08f08 AC |
1688 | else if (inst == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */ |
1689 | { | |
1690 | looking_for_rp = 0; | |
34f75cc1 | 1691 | cache->saved_regs[HPPA_RP_REGNUM].addr = -16; |
26d08f08 AC |
1692 | } |
1693 | ||
1694 | /* Check to see if we saved SP into the stack. This also | |
1695 | happens to indicate the location of the saved frame | |
1696 | pointer. */ | |
1697 | if ((inst & 0xffffc000) == 0x6fc10000 /* stw,ma r1,N(sr0,sp) */ | |
1698 | || (inst & 0xffffc00c) == 0x73c10008) /* std,ma r1,N(sr0,sp) */ | |
1699 | { | |
1700 | looking_for_sp = 0; | |
eded0a31 | 1701 | cache->saved_regs[HPPA_FP_REGNUM].addr = 0; |
26d08f08 | 1702 | } |
50b2f48a RC |
1703 | else if (inst == 0x08030241) /* copy %r3, %r1 */ |
1704 | { | |
1705 | fp_in_r1 = 1; | |
1706 | } | |
26d08f08 AC |
1707 | |
1708 | /* Account for general and floating-point register saves. */ | |
1709 | reg = inst_saves_gr (inst); | |
1710 | if (reg >= 3 && reg <= 18 | |
eded0a31 | 1711 | && (!u->Save_SP || reg != HPPA_FP_REGNUM)) |
26d08f08 AC |
1712 | { |
1713 | saved_gr_mask &= ~(1 << reg); | |
abc485a1 | 1714 | if ((inst >> 26) == 0x1b && hppa_extract_14 (inst) >= 0) |
26d08f08 AC |
1715 | /* stwm with a positive displacement is a _post_ |
1716 | _modify_. */ | |
1717 | cache->saved_regs[reg].addr = 0; | |
1718 | else if ((inst & 0xfc00000c) == 0x70000008) | |
1719 | /* A std has explicit post_modify forms. */ | |
1720 | cache->saved_regs[reg].addr = 0; | |
1721 | else | |
1722 | { | |
1723 | CORE_ADDR offset; | |
1724 | ||
1725 | if ((inst >> 26) == 0x1c) | |
1726 | offset = (inst & 0x1 ? -1 << 13 : 0) | (((inst >> 4) & 0x3ff) << 3); | |
1727 | else if ((inst >> 26) == 0x03) | |
abc485a1 | 1728 | offset = hppa_low_hppa_sign_extend (inst & 0x1f, 5); |
26d08f08 | 1729 | else |
abc485a1 | 1730 | offset = hppa_extract_14 (inst); |
26d08f08 AC |
1731 | |
1732 | /* Handle code with and without frame pointers. */ | |
1733 | if (u->Save_SP) | |
1734 | cache->saved_regs[reg].addr = offset; | |
1735 | else | |
1736 | cache->saved_regs[reg].addr = (u->Total_frame_size << 3) + offset; | |
1737 | } | |
1738 | } | |
1739 | ||
1740 | /* GCC handles callee saved FP regs a little differently. | |
1741 | ||
1742 | It emits an instruction to put the value of the start of | |
1743 | the FP store area into %r1. It then uses fstds,ma with a | |
1744 | basereg of %r1 for the stores. | |
1745 | ||
1746 | HP CC emits them at the current stack pointer modifying the | |
1747 | stack pointer as it stores each register. */ | |
1748 | ||
1749 | /* ldo X(%r3),%r1 or ldo X(%r30),%r1. */ | |
1750 | if ((inst & 0xffffc000) == 0x34610000 | |
1751 | || (inst & 0xffffc000) == 0x37c10000) | |
abc485a1 | 1752 | fp_loc = hppa_extract_14 (inst); |
26d08f08 AC |
1753 | |
1754 | reg = inst_saves_fr (inst); | |
1755 | if (reg >= 12 && reg <= 21) | |
1756 | { | |
1757 | /* Note +4 braindamage below is necessary because the FP | |
1758 | status registers are internally 8 registers rather than | |
1759 | the expected 4 registers. */ | |
1760 | saved_fr_mask &= ~(1 << reg); | |
1761 | if (fp_loc == -1) | |
1762 | { | |
1763 | /* 1st HP CC FP register store. After this | |
1764 | instruction we've set enough state that the GCC and | |
1765 | HPCC code are both handled in the same manner. */ | |
34f75cc1 | 1766 | cache->saved_regs[reg + HPPA_FP4_REGNUM + 4].addr = 0; |
26d08f08 AC |
1767 | fp_loc = 8; |
1768 | } | |
1769 | else | |
1770 | { | |
eded0a31 | 1771 | cache->saved_regs[reg + HPPA_FP0_REGNUM + 4].addr = fp_loc; |
26d08f08 AC |
1772 | fp_loc += 8; |
1773 | } | |
1774 | } | |
1775 | ||
1776 | /* Quit if we hit any kind of branch the previous iteration. */ | |
1777 | if (final_iteration) | |
1778 | break; | |
1779 | /* We want to look precisely one instruction beyond the branch | |
1780 | if we have not found everything yet. */ | |
1781 | if (is_branch (inst)) | |
1782 | final_iteration = 1; | |
1783 | } | |
1784 | } | |
1785 | ||
1786 | { | |
1787 | /* The frame base always represents the value of %sp at entry to | |
1788 | the current function (and is thus equivalent to the "saved" | |
1789 | stack pointer. */ | |
eded0a31 | 1790 | CORE_ADDR this_sp = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM); |
ed70ba00 | 1791 | CORE_ADDR fp; |
9f7194c3 RC |
1792 | |
1793 | if (hppa_debug) | |
1794 | fprintf_unfiltered (gdb_stdlog, " (this_sp=0x%s, pc=0x%s, " | |
1795 | "prologue_end=0x%s) ", | |
1796 | paddr_nz (this_sp), | |
1797 | paddr_nz (frame_pc_unwind (next_frame)), | |
1798 | paddr_nz (prologue_end)); | |
1799 | ||
ed70ba00 RC |
1800 | /* Check to see if a frame pointer is available, and use it for |
1801 | frame unwinding if it is. | |
1802 | ||
1803 | There are some situations where we need to rely on the frame | |
1804 | pointer to do stack unwinding. For example, if a function calls | |
1805 | alloca (), the stack pointer can get adjusted inside the body of | |
1806 | the function. In this case, the ABI requires that the compiler | |
1807 | maintain a frame pointer for the function. | |
1808 | ||
1809 | The unwind record has a flag (alloca_frame) that indicates that | |
1810 | a function has a variable frame; unfortunately, gcc/binutils | |
1811 | does not set this flag. Instead, whenever a frame pointer is used | |
1812 | and saved on the stack, the Save_SP flag is set. We use this to | |
1813 | decide whether to use the frame pointer for unwinding. | |
1814 | ||
ed70ba00 RC |
1815 | TODO: For the HP compiler, maybe we should use the alloca_frame flag |
1816 | instead of Save_SP. */ | |
1817 | ||
1818 | fp = frame_unwind_register_unsigned (next_frame, HPPA_FP_REGNUM); | |
1819 | ||
1820 | if (frame_pc_unwind (next_frame) >= prologue_end | |
1821 | && u->Save_SP && fp != 0) | |
1822 | { | |
1823 | cache->base = fp; | |
1824 | ||
1825 | if (hppa_debug) | |
1826 | fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [frame pointer] }", | |
1827 | paddr_nz (cache->base)); | |
1828 | } | |
1658da49 RC |
1829 | else if (u->Save_SP |
1830 | && trad_frame_addr_p (cache->saved_regs, HPPA_SP_REGNUM)) | |
9f7194c3 | 1831 | { |
9f7194c3 RC |
1832 | /* Both we're expecting the SP to be saved and the SP has been |
1833 | saved. The entry SP value is saved at this frame's SP | |
1834 | address. */ | |
1835 | cache->base = read_memory_integer (this_sp, TARGET_PTR_BIT / 8); | |
1836 | ||
1837 | if (hppa_debug) | |
1838 | fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [saved] }", | |
1839 | paddr_nz (cache->base)); | |
9f7194c3 | 1840 | } |
26d08f08 | 1841 | else |
9f7194c3 | 1842 | { |
1658da49 RC |
1843 | /* The prologue has been slowly allocating stack space. Adjust |
1844 | the SP back. */ | |
1845 | cache->base = this_sp - frame_size; | |
9f7194c3 | 1846 | if (hppa_debug) |
1658da49 | 1847 | fprintf_unfiltered (gdb_stdlog, " (base=0x%s) [unwind adjust] } ", |
9f7194c3 RC |
1848 | paddr_nz (cache->base)); |
1849 | ||
1850 | } | |
eded0a31 | 1851 | trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base); |
26d08f08 AC |
1852 | } |
1853 | ||
412275d5 AC |
1854 | /* The PC is found in the "return register", "Millicode" uses "r31" |
1855 | as the return register while normal code uses "rp". */ | |
26d08f08 | 1856 | if (u->Millicode) |
9f7194c3 | 1857 | { |
5859efe5 | 1858 | if (trad_frame_addr_p (cache->saved_regs, 31)) |
34f75cc1 | 1859 | cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[31]; |
9f7194c3 RC |
1860 | else |
1861 | { | |
1862 | ULONGEST r31 = frame_unwind_register_unsigned (next_frame, 31); | |
34f75cc1 | 1863 | trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, r31); |
9f7194c3 RC |
1864 | } |
1865 | } | |
26d08f08 | 1866 | else |
9f7194c3 | 1867 | { |
34f75cc1 RC |
1868 | if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM)) |
1869 | cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM]; | |
9f7194c3 RC |
1870 | else |
1871 | { | |
34f75cc1 RC |
1872 | ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM); |
1873 | trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp); | |
9f7194c3 RC |
1874 | } |
1875 | } | |
26d08f08 | 1876 | |
50b2f48a RC |
1877 | /* If Save_SP is set, then we expect the frame pointer to be saved in the |
1878 | frame. However, there is a one-insn window where we haven't saved it | |
1879 | yet, but we've already clobbered it. Detect this case and fix it up. | |
1880 | ||
1881 | The prologue sequence for frame-pointer functions is: | |
1882 | 0: stw %rp, -20(%sp) | |
1883 | 4: copy %r3, %r1 | |
1884 | 8: copy %sp, %r3 | |
1885 | c: stw,ma %r1, XX(%sp) | |
1886 | ||
1887 | So if we are at offset c, the r3 value that we want is not yet saved | |
1888 | on the stack, but it's been overwritten. The prologue analyzer will | |
1889 | set fp_in_r1 when it sees the copy insn so we know to get the value | |
1890 | from r1 instead. */ | |
1891 | if (u->Save_SP && !trad_frame_addr_p (cache->saved_regs, HPPA_FP_REGNUM) | |
1892 | && fp_in_r1) | |
1893 | { | |
1894 | ULONGEST r1 = frame_unwind_register_unsigned (next_frame, 1); | |
1895 | trad_frame_set_value (cache->saved_regs, HPPA_FP_REGNUM, r1); | |
1896 | } | |
1658da49 | 1897 | |
26d08f08 AC |
1898 | { |
1899 | /* Convert all the offsets into addresses. */ | |
1900 | int reg; | |
1901 | for (reg = 0; reg < NUM_REGS; reg++) | |
1902 | { | |
1903 | if (trad_frame_addr_p (cache->saved_regs, reg)) | |
1904 | cache->saved_regs[reg].addr += cache->base; | |
1905 | } | |
1906 | } | |
1907 | ||
369aa520 RC |
1908 | if (hppa_debug) |
1909 | fprintf_unfiltered (gdb_stdlog, "base=0x%s }", | |
1910 | paddr_nz (((struct hppa_frame_cache *)*this_cache)->base)); | |
26d08f08 AC |
1911 | return (*this_cache); |
1912 | } | |
1913 | ||
1914 | static void | |
1915 | hppa_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
1916 | struct frame_id *this_id) | |
1917 | { | |
d5c27f81 RC |
1918 | struct hppa_frame_cache *info; |
1919 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
1920 | struct unwind_table_entry *u; | |
1921 | ||
1922 | info = hppa_frame_cache (next_frame, this_cache); | |
1923 | u = find_unwind_entry (pc); | |
1924 | ||
1925 | (*this_id) = frame_id_build (info->base, u->region_start); | |
26d08f08 AC |
1926 | } |
1927 | ||
1928 | static void | |
1929 | hppa_frame_prev_register (struct frame_info *next_frame, | |
0da28f8a RC |
1930 | void **this_cache, |
1931 | int regnum, int *optimizedp, | |
1932 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1933 | int *realnump, void *valuep) | |
26d08f08 AC |
1934 | { |
1935 | struct hppa_frame_cache *info = hppa_frame_cache (next_frame, this_cache); | |
0da28f8a RC |
1936 | hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum, |
1937 | optimizedp, lvalp, addrp, realnump, valuep); | |
1938 | } | |
1939 | ||
1940 | static const struct frame_unwind hppa_frame_unwind = | |
1941 | { | |
1942 | NORMAL_FRAME, | |
1943 | hppa_frame_this_id, | |
1944 | hppa_frame_prev_register | |
1945 | }; | |
1946 | ||
1947 | static const struct frame_unwind * | |
1948 | hppa_frame_unwind_sniffer (struct frame_info *next_frame) | |
1949 | { | |
1950 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
1951 | ||
1952 | if (find_unwind_entry (pc)) | |
1953 | return &hppa_frame_unwind; | |
1954 | ||
1955 | return NULL; | |
1956 | } | |
1957 | ||
1958 | /* This is a generic fallback frame unwinder that kicks in if we fail all | |
1959 | the other ones. Normally we would expect the stub and regular unwinder | |
1960 | to work, but in some cases we might hit a function that just doesn't | |
1961 | have any unwind information available. In this case we try to do | |
1962 | unwinding solely based on code reading. This is obviously going to be | |
1963 | slow, so only use this as a last resort. Currently this will only | |
1964 | identify the stack and pc for the frame. */ | |
1965 | ||
1966 | static struct hppa_frame_cache * | |
1967 | hppa_fallback_frame_cache (struct frame_info *next_frame, void **this_cache) | |
1968 | { | |
1969 | struct hppa_frame_cache *cache; | |
6d1be3f1 | 1970 | unsigned int frame_size; |
d5c27f81 | 1971 | int found_rp; |
0da28f8a RC |
1972 | CORE_ADDR pc, start_pc, end_pc, cur_pc; |
1973 | ||
d5c27f81 RC |
1974 | if (hppa_debug) |
1975 | fprintf_unfiltered (gdb_stdlog, "{ hppa_fallback_frame_cache (frame=%d)-> ", | |
1976 | frame_relative_level(next_frame)); | |
1977 | ||
0da28f8a RC |
1978 | cache = FRAME_OBSTACK_ZALLOC (struct hppa_frame_cache); |
1979 | (*this_cache) = cache; | |
1980 | cache->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
1981 | ||
1982 | pc = frame_func_unwind (next_frame); | |
1983 | cur_pc = frame_pc_unwind (next_frame); | |
6d1be3f1 | 1984 | frame_size = 0; |
d5c27f81 | 1985 | found_rp = 0; |
0da28f8a RC |
1986 | |
1987 | find_pc_partial_function (pc, NULL, &start_pc, &end_pc); | |
1988 | ||
1989 | if (start_pc == 0 || end_pc == 0) | |
412275d5 | 1990 | { |
0da28f8a RC |
1991 | error ("Cannot find bounds of current function (@0x%s), unwinding will " |
1992 | "fail.", paddr_nz (pc)); | |
1993 | return cache; | |
1994 | } | |
1995 | ||
1996 | if (end_pc > cur_pc) | |
1997 | end_pc = cur_pc; | |
1998 | ||
1999 | for (pc = start_pc; pc < end_pc; pc += 4) | |
2000 | { | |
2001 | unsigned int insn; | |
2002 | ||
2003 | insn = read_memory_unsigned_integer (pc, 4); | |
2004 | ||
6d1be3f1 RC |
2005 | frame_size += prologue_inst_adjust_sp (insn); |
2006 | ||
0da28f8a RC |
2007 | /* There are limited ways to store the return pointer into the |
2008 | stack. */ | |
2009 | if (insn == 0x6bc23fd9) /* stw rp,-0x14(sr0,sp) */ | |
d5c27f81 RC |
2010 | { |
2011 | cache->saved_regs[HPPA_RP_REGNUM].addr = -20; | |
2012 | found_rp = 1; | |
2013 | } | |
0da28f8a | 2014 | else if (insn == 0x0fc212c1) /* std rp,-0x10(sr0,sp) */ |
d5c27f81 RC |
2015 | { |
2016 | cache->saved_regs[HPPA_RP_REGNUM].addr = -16; | |
2017 | found_rp = 1; | |
2018 | } | |
412275d5 | 2019 | } |
0da28f8a | 2020 | |
d5c27f81 RC |
2021 | if (hppa_debug) |
2022 | fprintf_unfiltered (gdb_stdlog, " frame_size = %d, found_rp = %d }\n", | |
2023 | frame_size, found_rp); | |
2024 | ||
6d1be3f1 RC |
2025 | cache->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM) - frame_size; |
2026 | trad_frame_set_value (cache->saved_regs, HPPA_SP_REGNUM, cache->base); | |
0da28f8a RC |
2027 | |
2028 | if (trad_frame_addr_p (cache->saved_regs, HPPA_RP_REGNUM)) | |
2029 | { | |
2030 | cache->saved_regs[HPPA_RP_REGNUM].addr += cache->base; | |
2031 | cache->saved_regs[HPPA_PCOQ_HEAD_REGNUM] = cache->saved_regs[HPPA_RP_REGNUM]; | |
2032 | } | |
412275d5 AC |
2033 | else |
2034 | { | |
0da28f8a RC |
2035 | ULONGEST rp = frame_unwind_register_unsigned (next_frame, HPPA_RP_REGNUM); |
2036 | trad_frame_set_value (cache->saved_regs, HPPA_PCOQ_HEAD_REGNUM, rp); | |
412275d5 | 2037 | } |
0da28f8a RC |
2038 | |
2039 | return cache; | |
26d08f08 AC |
2040 | } |
2041 | ||
0da28f8a RC |
2042 | static void |
2043 | hppa_fallback_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
2044 | struct frame_id *this_id) | |
2045 | { | |
2046 | struct hppa_frame_cache *info = | |
2047 | hppa_fallback_frame_cache (next_frame, this_cache); | |
2048 | (*this_id) = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
2049 | } | |
2050 | ||
2051 | static void | |
2052 | hppa_fallback_frame_prev_register (struct frame_info *next_frame, | |
2053 | void **this_cache, | |
2054 | int regnum, int *optimizedp, | |
2055 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
2056 | int *realnump, void *valuep) | |
2057 | { | |
2058 | struct hppa_frame_cache *info = | |
2059 | hppa_fallback_frame_cache (next_frame, this_cache); | |
2060 | hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum, | |
2061 | optimizedp, lvalp, addrp, realnump, valuep); | |
2062 | } | |
2063 | ||
2064 | static const struct frame_unwind hppa_fallback_frame_unwind = | |
26d08f08 AC |
2065 | { |
2066 | NORMAL_FRAME, | |
0da28f8a RC |
2067 | hppa_fallback_frame_this_id, |
2068 | hppa_fallback_frame_prev_register | |
26d08f08 AC |
2069 | }; |
2070 | ||
2071 | static const struct frame_unwind * | |
0da28f8a | 2072 | hppa_fallback_unwind_sniffer (struct frame_info *next_frame) |
26d08f08 | 2073 | { |
0da28f8a | 2074 | return &hppa_fallback_frame_unwind; |
26d08f08 AC |
2075 | } |
2076 | ||
7f07c5b6 RC |
2077 | /* Stub frames, used for all kinds of call stubs. */ |
2078 | struct hppa_stub_unwind_cache | |
2079 | { | |
2080 | CORE_ADDR base; | |
2081 | struct trad_frame_saved_reg *saved_regs; | |
2082 | }; | |
2083 | ||
2084 | static struct hppa_stub_unwind_cache * | |
2085 | hppa_stub_frame_unwind_cache (struct frame_info *next_frame, | |
2086 | void **this_cache) | |
2087 | { | |
2088 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
2089 | struct hppa_stub_unwind_cache *info; | |
22b0923d | 2090 | struct unwind_table_entry *u; |
7f07c5b6 RC |
2091 | |
2092 | if (*this_cache) | |
2093 | return *this_cache; | |
2094 | ||
f1b38a57 RC |
2095 | if (frame_pc_unwind (next_frame) == 0) |
2096 | return NULL; | |
2097 | ||
7f07c5b6 RC |
2098 | info = FRAME_OBSTACK_ZALLOC (struct hppa_stub_unwind_cache); |
2099 | *this_cache = info; | |
2100 | info->saved_regs = trad_frame_alloc_saved_regs (next_frame); | |
2101 | ||
7f07c5b6 RC |
2102 | info->base = frame_unwind_register_unsigned (next_frame, HPPA_SP_REGNUM); |
2103 | ||
090ccbb7 | 2104 | if (gdbarch_osabi (gdbarch) == GDB_OSABI_HPUX_SOM) |
22b0923d RC |
2105 | { |
2106 | /* HPUX uses export stubs in function calls; the export stub clobbers | |
2107 | the return value of the caller, and, later restores it from the | |
2108 | stack. */ | |
2109 | u = find_unwind_entry (frame_pc_unwind (next_frame)); | |
2110 | ||
2111 | if (u && u->stub_unwind.stub_type == EXPORT) | |
2112 | { | |
2113 | info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].addr = info->base - 24; | |
2114 | ||
2115 | return info; | |
2116 | } | |
2117 | } | |
2118 | ||
2119 | /* By default we assume that stubs do not change the rp. */ | |
2120 | info->saved_regs[HPPA_PCOQ_HEAD_REGNUM].realreg = HPPA_RP_REGNUM; | |
2121 | ||
7f07c5b6 RC |
2122 | return info; |
2123 | } | |
2124 | ||
2125 | static void | |
2126 | hppa_stub_frame_this_id (struct frame_info *next_frame, | |
2127 | void **this_prologue_cache, | |
2128 | struct frame_id *this_id) | |
2129 | { | |
2130 | struct hppa_stub_unwind_cache *info | |
2131 | = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache); | |
f1b38a57 RC |
2132 | |
2133 | if (info) | |
2134 | *this_id = frame_id_build (info->base, frame_func_unwind (next_frame)); | |
2135 | else | |
2136 | *this_id = null_frame_id; | |
7f07c5b6 RC |
2137 | } |
2138 | ||
2139 | static void | |
2140 | hppa_stub_frame_prev_register (struct frame_info *next_frame, | |
2141 | void **this_prologue_cache, | |
2142 | int regnum, int *optimizedp, | |
2143 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
0da28f8a | 2144 | int *realnump, void *valuep) |
7f07c5b6 RC |
2145 | { |
2146 | struct hppa_stub_unwind_cache *info | |
2147 | = hppa_stub_frame_unwind_cache (next_frame, this_prologue_cache); | |
f1b38a57 RC |
2148 | |
2149 | if (info) | |
2150 | hppa_frame_prev_register_helper (next_frame, info->saved_regs, regnum, | |
2151 | optimizedp, lvalp, addrp, realnump, | |
2152 | valuep); | |
2153 | else | |
2154 | error ("Requesting registers from null frame.\n"); | |
7f07c5b6 RC |
2155 | } |
2156 | ||
2157 | static const struct frame_unwind hppa_stub_frame_unwind = { | |
2158 | NORMAL_FRAME, | |
2159 | hppa_stub_frame_this_id, | |
2160 | hppa_stub_frame_prev_register | |
2161 | }; | |
2162 | ||
2163 | static const struct frame_unwind * | |
2164 | hppa_stub_unwind_sniffer (struct frame_info *next_frame) | |
2165 | { | |
2166 | CORE_ADDR pc = frame_pc_unwind (next_frame); | |
84674fe1 AC |
2167 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
2168 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
7f07c5b6 | 2169 | |
6d1be3f1 | 2170 | if (pc == 0 |
84674fe1 AC |
2171 | || (tdep->in_solib_call_trampoline != NULL |
2172 | && tdep->in_solib_call_trampoline (pc, NULL)) | |
7f07c5b6 RC |
2173 | || IN_SOLIB_RETURN_TRAMPOLINE (pc, NULL)) |
2174 | return &hppa_stub_frame_unwind; | |
2175 | return NULL; | |
2176 | } | |
2177 | ||
26d08f08 AC |
2178 | static struct frame_id |
2179 | hppa_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
2180 | { | |
2181 | return frame_id_build (frame_unwind_register_unsigned (next_frame, | |
eded0a31 | 2182 | HPPA_SP_REGNUM), |
26d08f08 AC |
2183 | frame_pc_unwind (next_frame)); |
2184 | } | |
2185 | ||
cc72850f | 2186 | CORE_ADDR |
26d08f08 AC |
2187 | hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
2188 | { | |
fe46cd3a RC |
2189 | ULONGEST ipsw; |
2190 | CORE_ADDR pc; | |
2191 | ||
cc72850f MK |
2192 | ipsw = frame_unwind_register_unsigned (next_frame, HPPA_IPSW_REGNUM); |
2193 | pc = frame_unwind_register_unsigned (next_frame, HPPA_PCOQ_HEAD_REGNUM); | |
fe46cd3a RC |
2194 | |
2195 | /* If the current instruction is nullified, then we are effectively | |
2196 | still executing the previous instruction. Pretend we are still | |
cc72850f MK |
2197 | there. This is needed when single stepping; if the nullified |
2198 | instruction is on a different line, we don't want GDB to think | |
2199 | we've stepped onto that line. */ | |
fe46cd3a RC |
2200 | if (ipsw & 0x00200000) |
2201 | pc -= 4; | |
2202 | ||
cc72850f | 2203 | return pc & ~0x3; |
26d08f08 AC |
2204 | } |
2205 | ||
9a043c1d AC |
2206 | /* Instead of this nasty cast, add a method pvoid() that prints out a |
2207 | host VOID data type (remember %p isn't portable). */ | |
2208 | ||
2209 | static CORE_ADDR | |
2210 | hppa_pointer_to_address_hack (void *ptr) | |
2211 | { | |
2212 | gdb_assert (sizeof (ptr) == TYPE_LENGTH (builtin_type_void_data_ptr)); | |
2213 | return POINTER_TO_ADDRESS (builtin_type_void_data_ptr, &ptr); | |
2214 | } | |
2215 | ||
c906108c | 2216 | static void |
fba45db2 | 2217 | unwind_command (char *exp, int from_tty) |
c906108c SS |
2218 | { |
2219 | CORE_ADDR address; | |
2220 | struct unwind_table_entry *u; | |
2221 | ||
2222 | /* If we have an expression, evaluate it and use it as the address. */ | |
2223 | ||
2224 | if (exp != 0 && *exp != 0) | |
2225 | address = parse_and_eval_address (exp); | |
2226 | else | |
2227 | return; | |
2228 | ||
2229 | u = find_unwind_entry (address); | |
2230 | ||
2231 | if (!u) | |
2232 | { | |
2233 | printf_unfiltered ("Can't find unwind table entry for %s\n", exp); | |
2234 | return; | |
2235 | } | |
2236 | ||
ce414844 | 2237 | printf_unfiltered ("unwind_table_entry (0x%s):\n", |
9a043c1d | 2238 | paddr_nz (hppa_pointer_to_address_hack (u))); |
c906108c SS |
2239 | |
2240 | printf_unfiltered ("\tregion_start = "); | |
2241 | print_address (u->region_start, gdb_stdout); | |
d5c27f81 | 2242 | gdb_flush (gdb_stdout); |
c906108c SS |
2243 | |
2244 | printf_unfiltered ("\n\tregion_end = "); | |
2245 | print_address (u->region_end, gdb_stdout); | |
d5c27f81 | 2246 | gdb_flush (gdb_stdout); |
c906108c | 2247 | |
c906108c | 2248 | #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD); |
c906108c SS |
2249 | |
2250 | printf_unfiltered ("\n\tflags ="); | |
2251 | pif (Cannot_unwind); | |
2252 | pif (Millicode); | |
2253 | pif (Millicode_save_sr0); | |
2254 | pif (Entry_SR); | |
2255 | pif (Args_stored); | |
2256 | pif (Variable_Frame); | |
2257 | pif (Separate_Package_Body); | |
2258 | pif (Frame_Extension_Millicode); | |
2259 | pif (Stack_Overflow_Check); | |
2260 | pif (Two_Instruction_SP_Increment); | |
2261 | pif (Ada_Region); | |
2262 | pif (Save_SP); | |
2263 | pif (Save_RP); | |
2264 | pif (Save_MRP_in_frame); | |
2265 | pif (extn_ptr_defined); | |
2266 | pif (Cleanup_defined); | |
2267 | pif (MPE_XL_interrupt_marker); | |
2268 | pif (HP_UX_interrupt_marker); | |
2269 | pif (Large_frame); | |
2270 | ||
2271 | putchar_unfiltered ('\n'); | |
2272 | ||
c906108c | 2273 | #define pin(FLD) printf_unfiltered ("\t"#FLD" = 0x%x\n", u->FLD); |
c906108c SS |
2274 | |
2275 | pin (Region_description); | |
2276 | pin (Entry_FR); | |
2277 | pin (Entry_GR); | |
2278 | pin (Total_frame_size); | |
57dac9e1 RC |
2279 | |
2280 | if (u->stub_unwind.stub_type) | |
2281 | { | |
2282 | printf_unfiltered ("\tstub type = "); | |
2283 | switch (u->stub_unwind.stub_type) | |
2284 | { | |
2285 | case LONG_BRANCH: | |
2286 | printf_unfiltered ("long branch\n"); | |
2287 | break; | |
2288 | case PARAMETER_RELOCATION: | |
2289 | printf_unfiltered ("parameter relocation\n"); | |
2290 | break; | |
2291 | case EXPORT: | |
2292 | printf_unfiltered ("export\n"); | |
2293 | break; | |
2294 | case IMPORT: | |
2295 | printf_unfiltered ("import\n"); | |
2296 | break; | |
2297 | case IMPORT_SHLIB: | |
2298 | printf_unfiltered ("import shlib\n"); | |
2299 | break; | |
2300 | default: | |
2301 | printf_unfiltered ("unknown (%d)\n", u->stub_unwind.stub_type); | |
2302 | } | |
2303 | } | |
c906108c | 2304 | } |
c906108c | 2305 | |
d709c020 JB |
2306 | int |
2307 | hppa_pc_requires_run_before_use (CORE_ADDR pc) | |
2308 | { | |
2309 | /* Sometimes we may pluck out a minimal symbol that has a negative address. | |
2310 | ||
2311 | An example of this occurs when an a.out is linked against a foo.sl. | |
2312 | The foo.sl defines a global bar(), and the a.out declares a signature | |
2313 | for bar(). However, the a.out doesn't directly call bar(), but passes | |
2314 | its address in another call. | |
2315 | ||
2316 | If you have this scenario and attempt to "break bar" before running, | |
2317 | gdb will find a minimal symbol for bar() in the a.out. But that | |
2318 | symbol's address will be negative. What this appears to denote is | |
2319 | an index backwards from the base of the procedure linkage table (PLT) | |
2320 | into the data linkage table (DLT), the end of which is contiguous | |
2321 | with the start of the PLT. This is clearly not a valid address for | |
2322 | us to set a breakpoint on. | |
2323 | ||
2324 | Note that one must be careful in how one checks for a negative address. | |
2325 | 0xc0000000 is a legitimate address of something in a shared text | |
2326 | segment, for example. Since I don't know what the possible range | |
2327 | is of these "really, truly negative" addresses that come from the | |
2328 | minimal symbols, I'm resorting to the gross hack of checking the | |
2329 | top byte of the address for all 1's. Sigh. */ | |
2330 | ||
2331 | return (!target_has_stack && (pc & 0xFF000000)); | |
2332 | } | |
2333 | ||
d709c020 JB |
2334 | /* Return the GDB type object for the "standard" data type of data |
2335 | in register N. */ | |
2336 | ||
eded0a31 AC |
2337 | static struct type * |
2338 | hppa32_register_type (struct gdbarch *gdbarch, int reg_nr) | |
d709c020 | 2339 | { |
34f75cc1 | 2340 | if (reg_nr < HPPA_FP4_REGNUM) |
eded0a31 | 2341 | return builtin_type_uint32; |
d709c020 | 2342 | else |
eded0a31 | 2343 | return builtin_type_ieee_single_big; |
d709c020 JB |
2344 | } |
2345 | ||
3ff7cf9e JB |
2346 | /* Return the GDB type object for the "standard" data type of data |
2347 | in register N. hppa64 version. */ | |
2348 | ||
eded0a31 AC |
2349 | static struct type * |
2350 | hppa64_register_type (struct gdbarch *gdbarch, int reg_nr) | |
3ff7cf9e | 2351 | { |
34f75cc1 | 2352 | if (reg_nr < HPPA_FP4_REGNUM) |
eded0a31 | 2353 | return builtin_type_uint64; |
3ff7cf9e | 2354 | else |
eded0a31 | 2355 | return builtin_type_ieee_double_big; |
3ff7cf9e JB |
2356 | } |
2357 | ||
d709c020 JB |
2358 | /* Return True if REGNUM is not a register available to the user |
2359 | through ptrace(). */ | |
2360 | ||
8d153463 | 2361 | static int |
d709c020 JB |
2362 | hppa_cannot_store_register (int regnum) |
2363 | { | |
2364 | return (regnum == 0 | |
34f75cc1 RC |
2365 | || regnum == HPPA_PCSQ_HEAD_REGNUM |
2366 | || (regnum >= HPPA_PCSQ_TAIL_REGNUM && regnum < HPPA_IPSW_REGNUM) | |
2367 | || (regnum > HPPA_IPSW_REGNUM && regnum < HPPA_FP4_REGNUM)); | |
d709c020 JB |
2368 | |
2369 | } | |
2370 | ||
8d153463 | 2371 | static CORE_ADDR |
d709c020 JB |
2372 | hppa_smash_text_address (CORE_ADDR addr) |
2373 | { | |
2374 | /* The low two bits of the PC on the PA contain the privilege level. | |
2375 | Some genius implementing a (non-GCC) compiler apparently decided | |
2376 | this means that "addresses" in a text section therefore include a | |
2377 | privilege level, and thus symbol tables should contain these bits. | |
2378 | This seems like a bonehead thing to do--anyway, it seems to work | |
2379 | for our purposes to just ignore those bits. */ | |
2380 | ||
2381 | return (addr &= ~0x3); | |
2382 | } | |
2383 | ||
143985b7 | 2384 | /* Get the ith function argument for the current function. */ |
4a302917 | 2385 | static CORE_ADDR |
143985b7 AF |
2386 | hppa_fetch_pointer_argument (struct frame_info *frame, int argi, |
2387 | struct type *type) | |
2388 | { | |
2389 | CORE_ADDR addr; | |
34f75cc1 | 2390 | get_frame_register (frame, HPPA_R0_REGNUM + 26 - argi, &addr); |
143985b7 AF |
2391 | return addr; |
2392 | } | |
2393 | ||
0f8d9d59 RC |
2394 | static void |
2395 | hppa_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
2396 | int regnum, void *buf) | |
2397 | { | |
2398 | ULONGEST tmp; | |
2399 | ||
2400 | regcache_raw_read_unsigned (regcache, regnum, &tmp); | |
34f75cc1 | 2401 | if (regnum == HPPA_PCOQ_HEAD_REGNUM || regnum == HPPA_PCOQ_TAIL_REGNUM) |
0f8d9d59 RC |
2402 | tmp &= ~0x3; |
2403 | store_unsigned_integer (buf, sizeof(tmp), tmp); | |
2404 | } | |
2405 | ||
d49771ef RC |
2406 | static CORE_ADDR |
2407 | hppa_find_global_pointer (struct value *function) | |
2408 | { | |
2409 | return 0; | |
2410 | } | |
2411 | ||
0da28f8a RC |
2412 | void |
2413 | hppa_frame_prev_register_helper (struct frame_info *next_frame, | |
2414 | struct trad_frame_saved_reg saved_regs[], | |
2415 | int regnum, int *optimizedp, | |
2416 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
2417 | int *realnump, void *valuep) | |
2418 | { | |
8693c419 MK |
2419 | if (regnum == HPPA_PCOQ_TAIL_REGNUM) |
2420 | { | |
2421 | if (valuep) | |
2422 | { | |
2423 | CORE_ADDR pc; | |
0da28f8a | 2424 | |
1f67027d AC |
2425 | trad_frame_get_prev_register (next_frame, saved_regs, |
2426 | HPPA_PCOQ_HEAD_REGNUM, optimizedp, | |
2427 | lvalp, addrp, realnump, valuep); | |
8693c419 MK |
2428 | |
2429 | pc = extract_unsigned_integer (valuep, 4); | |
2430 | store_unsigned_integer (valuep, 4, pc + 4); | |
2431 | } | |
2432 | ||
2433 | /* It's a computed value. */ | |
2434 | *optimizedp = 0; | |
2435 | *lvalp = not_lval; | |
2436 | *addrp = 0; | |
2437 | *realnump = -1; | |
2438 | return; | |
2439 | } | |
0da28f8a | 2440 | |
cc72850f MK |
2441 | /* Make sure the "flags" register is zero in all unwound frames. |
2442 | The "flags" registers is a HP-UX specific wart, and only the code | |
2443 | in hppa-hpux-tdep.c depends on it. However, it is easier to deal | |
2444 | with it here. This shouldn't affect other systems since those | |
2445 | should provide zero for the "flags" register anyway. */ | |
2446 | if (regnum == HPPA_FLAGS_REGNUM) | |
2447 | { | |
2448 | if (valuep) | |
2449 | store_unsigned_integer (valuep, 4, 0); | |
2450 | ||
2451 | /* It's a computed value. */ | |
2452 | *optimizedp = 0; | |
2453 | *lvalp = not_lval; | |
2454 | *addrp = 0; | |
2455 | *realnump = -1; | |
2456 | return; | |
2457 | } | |
2458 | ||
1f67027d AC |
2459 | trad_frame_get_prev_register (next_frame, saved_regs, regnum, |
2460 | optimizedp, lvalp, addrp, realnump, valuep); | |
0da28f8a | 2461 | } |
8693c419 | 2462 | \f |
0da28f8a | 2463 | |
8e8b2dba MC |
2464 | /* Here is a table of C type sizes on hppa with various compiles |
2465 | and options. I measured this on PA 9000/800 with HP-UX 11.11 | |
2466 | and these compilers: | |
2467 | ||
2468 | /usr/ccs/bin/cc HP92453-01 A.11.01.21 | |
2469 | /opt/ansic/bin/cc HP92453-01 B.11.11.28706.GP | |
2470 | /opt/aCC/bin/aCC B3910B A.03.45 | |
2471 | gcc gcc 3.3.2 native hppa2.0w-hp-hpux11.11 | |
2472 | ||
2473 | cc : 1 2 4 4 8 : 4 8 -- : 4 4 | |
2474 | ansic +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4 | |
2475 | ansic +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4 | |
2476 | ansic +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8 | |
2477 | acc +DA1.1 : 1 2 4 4 8 : 4 8 16 : 4 4 | |
2478 | acc +DA2.0 : 1 2 4 4 8 : 4 8 16 : 4 4 | |
2479 | acc +DA2.0W : 1 2 4 8 8 : 4 8 16 : 8 8 | |
2480 | gcc : 1 2 4 4 8 : 4 8 16 : 4 4 | |
2481 | ||
2482 | Each line is: | |
2483 | ||
2484 | compiler and options | |
2485 | char, short, int, long, long long | |
2486 | float, double, long double | |
2487 | char *, void (*)() | |
2488 | ||
2489 | So all these compilers use either ILP32 or LP64 model. | |
2490 | TODO: gcc has more options so it needs more investigation. | |
2491 | ||
a2379359 MC |
2492 | For floating point types, see: |
2493 | ||
2494 | http://docs.hp.com/hpux/pdf/B3906-90006.pdf | |
2495 | HP-UX floating-point guide, hpux 11.00 | |
2496 | ||
8e8b2dba MC |
2497 | -- chastain 2003-12-18 */ |
2498 | ||
e6e68f1f JB |
2499 | static struct gdbarch * |
2500 | hppa_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
2501 | { | |
3ff7cf9e | 2502 | struct gdbarch_tdep *tdep; |
e6e68f1f | 2503 | struct gdbarch *gdbarch; |
59623e27 JB |
2504 | |
2505 | /* Try to determine the ABI of the object we are loading. */ | |
4be87837 | 2506 | if (info.abfd != NULL && info.osabi == GDB_OSABI_UNKNOWN) |
59623e27 | 2507 | { |
4be87837 DJ |
2508 | /* If it's a SOM file, assume it's HP/UX SOM. */ |
2509 | if (bfd_get_flavour (info.abfd) == bfd_target_som_flavour) | |
2510 | info.osabi = GDB_OSABI_HPUX_SOM; | |
59623e27 | 2511 | } |
e6e68f1f JB |
2512 | |
2513 | /* find a candidate among the list of pre-declared architectures. */ | |
2514 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
2515 | if (arches != NULL) | |
2516 | return (arches->gdbarch); | |
2517 | ||
2518 | /* If none found, then allocate and initialize one. */ | |
fdd72f95 | 2519 | tdep = XZALLOC (struct gdbarch_tdep); |
3ff7cf9e JB |
2520 | gdbarch = gdbarch_alloc (&info, tdep); |
2521 | ||
2522 | /* Determine from the bfd_arch_info structure if we are dealing with | |
2523 | a 32 or 64 bits architecture. If the bfd_arch_info is not available, | |
2524 | then default to a 32bit machine. */ | |
2525 | if (info.bfd_arch_info != NULL) | |
2526 | tdep->bytes_per_address = | |
2527 | info.bfd_arch_info->bits_per_address / info.bfd_arch_info->bits_per_byte; | |
2528 | else | |
2529 | tdep->bytes_per_address = 4; | |
2530 | ||
d49771ef RC |
2531 | tdep->find_global_pointer = hppa_find_global_pointer; |
2532 | ||
3ff7cf9e JB |
2533 | /* Some parts of the gdbarch vector depend on whether we are running |
2534 | on a 32 bits or 64 bits target. */ | |
2535 | switch (tdep->bytes_per_address) | |
2536 | { | |
2537 | case 4: | |
2538 | set_gdbarch_num_regs (gdbarch, hppa32_num_regs); | |
2539 | set_gdbarch_register_name (gdbarch, hppa32_register_name); | |
eded0a31 | 2540 | set_gdbarch_register_type (gdbarch, hppa32_register_type); |
3ff7cf9e JB |
2541 | break; |
2542 | case 8: | |
2543 | set_gdbarch_num_regs (gdbarch, hppa64_num_regs); | |
2544 | set_gdbarch_register_name (gdbarch, hppa64_register_name); | |
eded0a31 | 2545 | set_gdbarch_register_type (gdbarch, hppa64_register_type); |
3ff7cf9e JB |
2546 | break; |
2547 | default: | |
2548 | internal_error (__FILE__, __LINE__, "Unsupported address size: %d", | |
2549 | tdep->bytes_per_address); | |
2550 | } | |
2551 | ||
3ff7cf9e | 2552 | set_gdbarch_long_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT); |
3ff7cf9e | 2553 | set_gdbarch_ptr_bit (gdbarch, tdep->bytes_per_address * TARGET_CHAR_BIT); |
e6e68f1f | 2554 | |
8e8b2dba MC |
2555 | /* The following gdbarch vector elements are the same in both ILP32 |
2556 | and LP64, but might show differences some day. */ | |
2557 | set_gdbarch_long_long_bit (gdbarch, 64); | |
2558 | set_gdbarch_long_double_bit (gdbarch, 128); | |
a2379359 | 2559 | set_gdbarch_long_double_format (gdbarch, &floatformat_ia64_quad_big); |
8e8b2dba | 2560 | |
3ff7cf9e JB |
2561 | /* The following gdbarch vector elements do not depend on the address |
2562 | size, or in any other gdbarch element previously set. */ | |
60383d10 | 2563 | set_gdbarch_skip_prologue (gdbarch, hppa_skip_prologue); |
a2a84a72 | 2564 | set_gdbarch_inner_than (gdbarch, core_addr_greaterthan); |
eded0a31 AC |
2565 | set_gdbarch_sp_regnum (gdbarch, HPPA_SP_REGNUM); |
2566 | set_gdbarch_fp0_regnum (gdbarch, HPPA_FP0_REGNUM); | |
60383d10 | 2567 | set_gdbarch_cannot_store_register (gdbarch, hppa_cannot_store_register); |
50306a9d | 2568 | set_gdbarch_cannot_fetch_register (gdbarch, hppa_cannot_store_register); |
b6fbdd1d | 2569 | set_gdbarch_addr_bits_remove (gdbarch, hppa_smash_text_address); |
60383d10 JB |
2570 | set_gdbarch_smash_text_address (gdbarch, hppa_smash_text_address); |
2571 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); | |
cc72850f MK |
2572 | set_gdbarch_read_pc (gdbarch, hppa_read_pc); |
2573 | set_gdbarch_write_pc (gdbarch, hppa_write_pc); | |
60383d10 | 2574 | |
143985b7 AF |
2575 | /* Helper for function argument information. */ |
2576 | set_gdbarch_fetch_pointer_argument (gdbarch, hppa_fetch_pointer_argument); | |
2577 | ||
36482093 AC |
2578 | set_gdbarch_print_insn (gdbarch, print_insn_hppa); |
2579 | ||
3a3bc038 AC |
2580 | /* When a hardware watchpoint triggers, we'll move the inferior past |
2581 | it by removing all eventpoints; stepping past the instruction | |
2582 | that caused the trigger; reinserting eventpoints; and checking | |
2583 | whether any watched location changed. */ | |
2584 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
2585 | ||
5979bc46 | 2586 | /* Inferior function call methods. */ |
fca7aa43 | 2587 | switch (tdep->bytes_per_address) |
5979bc46 | 2588 | { |
fca7aa43 AC |
2589 | case 4: |
2590 | set_gdbarch_push_dummy_call (gdbarch, hppa32_push_dummy_call); | |
2591 | set_gdbarch_frame_align (gdbarch, hppa32_frame_align); | |
d49771ef RC |
2592 | set_gdbarch_convert_from_func_ptr_addr |
2593 | (gdbarch, hppa32_convert_from_func_ptr_addr); | |
fca7aa43 AC |
2594 | break; |
2595 | case 8: | |
782eae8b AC |
2596 | set_gdbarch_push_dummy_call (gdbarch, hppa64_push_dummy_call); |
2597 | set_gdbarch_frame_align (gdbarch, hppa64_frame_align); | |
fca7aa43 | 2598 | break; |
782eae8b AC |
2599 | default: |
2600 | internal_error (__FILE__, __LINE__, "bad switch"); | |
fad850b2 AC |
2601 | } |
2602 | ||
2603 | /* Struct return methods. */ | |
fca7aa43 | 2604 | switch (tdep->bytes_per_address) |
fad850b2 | 2605 | { |
fca7aa43 AC |
2606 | case 4: |
2607 | set_gdbarch_return_value (gdbarch, hppa32_return_value); | |
2608 | break; | |
2609 | case 8: | |
782eae8b | 2610 | set_gdbarch_return_value (gdbarch, hppa64_return_value); |
f5f907e2 | 2611 | break; |
fca7aa43 AC |
2612 | default: |
2613 | internal_error (__FILE__, __LINE__, "bad switch"); | |
e963316f | 2614 | } |
7f07c5b6 | 2615 | |
85f4f2d8 | 2616 | set_gdbarch_breakpoint_from_pc (gdbarch, hppa_breakpoint_from_pc); |
7f07c5b6 | 2617 | set_gdbarch_pseudo_register_read (gdbarch, hppa_pseudo_register_read); |
85f4f2d8 | 2618 | |
5979bc46 | 2619 | /* Frame unwind methods. */ |
782eae8b AC |
2620 | set_gdbarch_unwind_dummy_id (gdbarch, hppa_unwind_dummy_id); |
2621 | set_gdbarch_unwind_pc (gdbarch, hppa_unwind_pc); | |
7f07c5b6 | 2622 | |
50306a9d RC |
2623 | /* Hook in ABI-specific overrides, if they have been registered. */ |
2624 | gdbarch_init_osabi (info, gdbarch); | |
2625 | ||
7f07c5b6 RC |
2626 | /* Hook in the default unwinders. */ |
2627 | frame_unwind_append_sniffer (gdbarch, hppa_stub_unwind_sniffer); | |
782eae8b | 2628 | frame_unwind_append_sniffer (gdbarch, hppa_frame_unwind_sniffer); |
0da28f8a | 2629 | frame_unwind_append_sniffer (gdbarch, hppa_fallback_unwind_sniffer); |
5979bc46 | 2630 | |
e6e68f1f JB |
2631 | return gdbarch; |
2632 | } | |
2633 | ||
2634 | static void | |
2635 | hppa_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
2636 | { | |
fdd72f95 RC |
2637 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
2638 | ||
2639 | fprintf_unfiltered (file, "bytes_per_address = %d\n", | |
2640 | tdep->bytes_per_address); | |
2641 | fprintf_unfiltered (file, "elf = %s\n", tdep->is_elf ? "yes" : "no"); | |
e6e68f1f JB |
2642 | } |
2643 | ||
4facf7e8 JB |
2644 | void |
2645 | _initialize_hppa_tdep (void) | |
2646 | { | |
2647 | struct cmd_list_element *c; | |
4facf7e8 | 2648 | |
e6e68f1f | 2649 | gdbarch_register (bfd_arch_hppa, hppa_gdbarch_init, hppa_dump_tdep); |
4facf7e8 | 2650 | |
7c46b9fb RC |
2651 | hppa_objfile_priv_data = register_objfile_data (); |
2652 | ||
4facf7e8 JB |
2653 | add_cmd ("unwind", class_maintenance, unwind_command, |
2654 | "Print unwind table entry at given address.", | |
2655 | &maintenanceprintlist); | |
2656 | ||
369aa520 | 2657 | /* Debug this files internals. */ |
4a302917 RC |
2658 | add_setshow_boolean_cmd ("hppa", class_maintenance, &hppa_debug, "\ |
2659 | Set whether hppa target specific debugging information should be displayed.", "\ | |
2660 | Show whether hppa target specific debugging information is displayed.", "\ | |
2661 | This flag controls whether hppa target specific debugging information is\n\ | |
2662 | displayed. This information is particularly useful for debugging frame\n\ | |
2663 | unwinding problems.", "hppa debug flag is %s.", | |
2664 | NULL, NULL, &setdebuglist, &showdebuglist); | |
4facf7e8 | 2665 | } |