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