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