Try harder to find the correct symbol to associate with OPEN GNU BUILD notes.
[deliverable/binutils-gdb.git] / gdb / sparc64-tdep.c
1 /* Target-dependent code for UltraSPARC.
2
3 Copyright (C) 2003-2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "dwarf2-frame.h"
23 #include "floatformat.h"
24 #include "frame.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "gdbcore.h"
28 #include "gdbtypes.h"
29 #include "inferior.h"
30 #include "symtab.h"
31 #include "objfiles.h"
32 #include "osabi.h"
33 #include "regcache.h"
34 #include "target-descriptions.h"
35 #include "target.h"
36 #include "value.h"
37
38 #include "sparc64-tdep.h"
39
40 /* This file implements the SPARC 64-bit ABI as defined by the
41 section "Low-Level System Information" of the SPARC Compliance
42 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
43 SPARC. */
44
45 /* Please use the sparc32_-prefix for 32-bit specific code, the
46 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
47 code can handle both. */
48 \f
49 /* The functions on this page are intended to be used to classify
50 function arguments. */
51
52 /* Check whether TYPE is "Integral or Pointer". */
53
54 static int
55 sparc64_integral_or_pointer_p (const struct type *type)
56 {
57 switch (TYPE_CODE (type))
58 {
59 case TYPE_CODE_INT:
60 case TYPE_CODE_BOOL:
61 case TYPE_CODE_CHAR:
62 case TYPE_CODE_ENUM:
63 case TYPE_CODE_RANGE:
64 {
65 int len = TYPE_LENGTH (type);
66 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
67 }
68 return 1;
69 case TYPE_CODE_PTR:
70 case TYPE_CODE_REF:
71 {
72 int len = TYPE_LENGTH (type);
73 gdb_assert (len == 8);
74 }
75 return 1;
76 default:
77 break;
78 }
79
80 return 0;
81 }
82
83 /* Check whether TYPE is "Floating". */
84
85 static int
86 sparc64_floating_p (const struct type *type)
87 {
88 switch (TYPE_CODE (type))
89 {
90 case TYPE_CODE_FLT:
91 {
92 int len = TYPE_LENGTH (type);
93 gdb_assert (len == 4 || len == 8 || len == 16);
94 }
95 return 1;
96 default:
97 break;
98 }
99
100 return 0;
101 }
102
103 /* Check whether TYPE is "Complex Floating". */
104
105 static int
106 sparc64_complex_floating_p (const struct type *type)
107 {
108 switch (TYPE_CODE (type))
109 {
110 case TYPE_CODE_COMPLEX:
111 {
112 int len = TYPE_LENGTH (type);
113 gdb_assert (len == 8 || len == 16 || len == 32);
114 }
115 return 1;
116 default:
117 break;
118 }
119
120 return 0;
121 }
122
123 /* Check whether TYPE is "Structure or Union".
124
125 In terms of Ada subprogram calls, arrays are treated the same as
126 struct and union types. So this function also returns non-zero
127 for array types. */
128
129 static int
130 sparc64_structure_or_union_p (const struct type *type)
131 {
132 switch (TYPE_CODE (type))
133 {
134 case TYPE_CODE_STRUCT:
135 case TYPE_CODE_UNION:
136 case TYPE_CODE_ARRAY:
137 return 1;
138 default:
139 break;
140 }
141
142 return 0;
143 }
144 \f
145
146 /* Construct types for ISA-specific registers. */
147
148 static struct type *
149 sparc64_pstate_type (struct gdbarch *gdbarch)
150 {
151 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
152
153 if (!tdep->sparc64_pstate_type)
154 {
155 struct type *type;
156
157 type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8);
158 append_flags_type_flag (type, 0, "AG");
159 append_flags_type_flag (type, 1, "IE");
160 append_flags_type_flag (type, 2, "PRIV");
161 append_flags_type_flag (type, 3, "AM");
162 append_flags_type_flag (type, 4, "PEF");
163 append_flags_type_flag (type, 5, "RED");
164 append_flags_type_flag (type, 8, "TLE");
165 append_flags_type_flag (type, 9, "CLE");
166 append_flags_type_flag (type, 10, "PID0");
167 append_flags_type_flag (type, 11, "PID1");
168
169 tdep->sparc64_pstate_type = type;
170 }
171
172 return tdep->sparc64_pstate_type;
173 }
174
175 static struct type *
176 sparc64_fsr_type (struct gdbarch *gdbarch)
177 {
178 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
179
180 if (!tdep->sparc64_fsr_type)
181 {
182 struct type *type;
183
184 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8);
185 append_flags_type_flag (type, 0, "NXA");
186 append_flags_type_flag (type, 1, "DZA");
187 append_flags_type_flag (type, 2, "UFA");
188 append_flags_type_flag (type, 3, "OFA");
189 append_flags_type_flag (type, 4, "NVA");
190 append_flags_type_flag (type, 5, "NXC");
191 append_flags_type_flag (type, 6, "DZC");
192 append_flags_type_flag (type, 7, "UFC");
193 append_flags_type_flag (type, 8, "OFC");
194 append_flags_type_flag (type, 9, "NVC");
195 append_flags_type_flag (type, 22, "NS");
196 append_flags_type_flag (type, 23, "NXM");
197 append_flags_type_flag (type, 24, "DZM");
198 append_flags_type_flag (type, 25, "UFM");
199 append_flags_type_flag (type, 26, "OFM");
200 append_flags_type_flag (type, 27, "NVM");
201
202 tdep->sparc64_fsr_type = type;
203 }
204
205 return tdep->sparc64_fsr_type;
206 }
207
208 static struct type *
209 sparc64_fprs_type (struct gdbarch *gdbarch)
210 {
211 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
212
213 if (!tdep->sparc64_fprs_type)
214 {
215 struct type *type;
216
217 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8);
218 append_flags_type_flag (type, 0, "DL");
219 append_flags_type_flag (type, 1, "DU");
220 append_flags_type_flag (type, 2, "FEF");
221
222 tdep->sparc64_fprs_type = type;
223 }
224
225 return tdep->sparc64_fprs_type;
226 }
227
228
229 /* Register information. */
230 #define SPARC64_FPU_REGISTERS \
231 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
232 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
233 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
234 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
235 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
236 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
237 #define SPARC64_CP0_REGISTERS \
238 "pc", "npc", \
239 /* FIXME: Give "state" a name until we start using register groups. */ \
240 "state", \
241 "fsr", \
242 "fprs", \
243 "y"
244
245 static const char *sparc64_fpu_register_names[] = { SPARC64_FPU_REGISTERS };
246 static const char *sparc64_cp0_register_names[] = { SPARC64_CP0_REGISTERS };
247
248 static const char *sparc64_register_names[] =
249 {
250 SPARC_CORE_REGISTERS,
251 SPARC64_FPU_REGISTERS,
252 SPARC64_CP0_REGISTERS
253 };
254
255 /* Total number of registers. */
256 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
257
258 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
259 registers as "psuedo" registers. */
260
261 static const char *sparc64_pseudo_register_names[] =
262 {
263 "cwp", "pstate", "asi", "ccr",
264
265 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
266 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
267 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
268 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
269
270 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
271 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
272 };
273
274 /* Total number of pseudo registers. */
275 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
276
277 /* Return the name of pseudo register REGNUM. */
278
279 static const char *
280 sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
281 {
282 regnum -= gdbarch_num_regs (gdbarch);
283
284 if (regnum < SPARC64_NUM_PSEUDO_REGS)
285 return sparc64_pseudo_register_names[regnum];
286
287 internal_error (__FILE__, __LINE__,
288 _("sparc64_pseudo_register_name: bad register number %d"),
289 regnum);
290 }
291
292 /* Return the name of register REGNUM. */
293
294 static const char *
295 sparc64_register_name (struct gdbarch *gdbarch, int regnum)
296 {
297 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
298 return tdesc_register_name (gdbarch, regnum);
299
300 if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
301 return sparc64_register_names[regnum];
302
303 return sparc64_pseudo_register_name (gdbarch, regnum);
304 }
305
306 /* Return the GDB type object for the "standard" data type of data in
307 pseudo register REGNUM. */
308
309 static struct type *
310 sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
311 {
312 regnum -= gdbarch_num_regs (gdbarch);
313
314 if (regnum == SPARC64_CWP_REGNUM)
315 return builtin_type (gdbarch)->builtin_int64;
316 if (regnum == SPARC64_PSTATE_REGNUM)
317 return sparc64_pstate_type (gdbarch);
318 if (regnum == SPARC64_ASI_REGNUM)
319 return builtin_type (gdbarch)->builtin_int64;
320 if (regnum == SPARC64_CCR_REGNUM)
321 return builtin_type (gdbarch)->builtin_int64;
322 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
323 return builtin_type (gdbarch)->builtin_double;
324 if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
325 return builtin_type (gdbarch)->builtin_long_double;
326
327 internal_error (__FILE__, __LINE__,
328 _("sparc64_pseudo_register_type: bad register number %d"),
329 regnum);
330 }
331
332 /* Return the GDB type object for the "standard" data type of data in
333 register REGNUM. */
334
335 static struct type *
336 sparc64_register_type (struct gdbarch *gdbarch, int regnum)
337 {
338 if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
339 return tdesc_register_type (gdbarch, regnum);
340
341 /* Raw registers. */
342 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
343 return builtin_type (gdbarch)->builtin_data_ptr;
344 if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
345 return builtin_type (gdbarch)->builtin_int64;
346 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
347 return builtin_type (gdbarch)->builtin_float;
348 if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
349 return builtin_type (gdbarch)->builtin_double;
350 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
351 return builtin_type (gdbarch)->builtin_func_ptr;
352 /* This raw register contains the contents of %cwp, %pstate, %asi
353 and %ccr as laid out in a %tstate register. */
354 if (regnum == SPARC64_STATE_REGNUM)
355 return builtin_type (gdbarch)->builtin_int64;
356 if (regnum == SPARC64_FSR_REGNUM)
357 return sparc64_fsr_type (gdbarch);
358 if (regnum == SPARC64_FPRS_REGNUM)
359 return sparc64_fprs_type (gdbarch);
360 /* "Although Y is a 64-bit register, its high-order 32 bits are
361 reserved and always read as 0." */
362 if (regnum == SPARC64_Y_REGNUM)
363 return builtin_type (gdbarch)->builtin_int64;
364
365 /* Pseudo registers. */
366 if (regnum >= gdbarch_num_regs (gdbarch))
367 return sparc64_pseudo_register_type (gdbarch, regnum);
368
369 internal_error (__FILE__, __LINE__, _("invalid regnum"));
370 }
371
372 static enum register_status
373 sparc64_pseudo_register_read (struct gdbarch *gdbarch,
374 struct regcache *regcache,
375 int regnum, gdb_byte *buf)
376 {
377 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
378 enum register_status status;
379
380 regnum -= gdbarch_num_regs (gdbarch);
381
382 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
383 {
384 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
385 status = regcache_raw_read (regcache, regnum, buf);
386 if (status == REG_VALID)
387 status = regcache_raw_read (regcache, regnum + 1, buf + 4);
388 return status;
389 }
390 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
391 {
392 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
393 return regcache_raw_read (regcache, regnum, buf);
394 }
395 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
396 {
397 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
398
399 status = regcache_raw_read (regcache, regnum, buf);
400 if (status == REG_VALID)
401 status = regcache_raw_read (regcache, regnum + 1, buf + 4);
402 if (status == REG_VALID)
403 status = regcache_raw_read (regcache, regnum + 2, buf + 8);
404 if (status == REG_VALID)
405 status = regcache_raw_read (regcache, regnum + 3, buf + 12);
406
407 return status;
408 }
409 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
410 {
411 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
412
413 status = regcache_raw_read (regcache, regnum, buf);
414 if (status == REG_VALID)
415 status = regcache_raw_read (regcache, regnum + 1, buf + 8);
416
417 return status;
418 }
419 else if (regnum == SPARC64_CWP_REGNUM
420 || regnum == SPARC64_PSTATE_REGNUM
421 || regnum == SPARC64_ASI_REGNUM
422 || regnum == SPARC64_CCR_REGNUM)
423 {
424 ULONGEST state;
425
426 status = regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
427 if (status != REG_VALID)
428 return status;
429
430 switch (regnum)
431 {
432 case SPARC64_CWP_REGNUM:
433 state = (state >> 0) & ((1 << 5) - 1);
434 break;
435 case SPARC64_PSTATE_REGNUM:
436 state = (state >> 8) & ((1 << 12) - 1);
437 break;
438 case SPARC64_ASI_REGNUM:
439 state = (state >> 24) & ((1 << 8) - 1);
440 break;
441 case SPARC64_CCR_REGNUM:
442 state = (state >> 32) & ((1 << 8) - 1);
443 break;
444 }
445 store_unsigned_integer (buf, 8, byte_order, state);
446 }
447
448 return REG_VALID;
449 }
450
451 static void
452 sparc64_pseudo_register_write (struct gdbarch *gdbarch,
453 struct regcache *regcache,
454 int regnum, const gdb_byte *buf)
455 {
456 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
457
458 regnum -= gdbarch_num_regs (gdbarch);
459
460 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
461 {
462 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
463 regcache_raw_write (regcache, regnum, buf);
464 regcache_raw_write (regcache, regnum + 1, buf + 4);
465 }
466 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
467 {
468 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
469 regcache_raw_write (regcache, regnum, buf);
470 }
471 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
472 {
473 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
474 regcache_raw_write (regcache, regnum, buf);
475 regcache_raw_write (regcache, regnum + 1, buf + 4);
476 regcache_raw_write (regcache, regnum + 2, buf + 8);
477 regcache_raw_write (regcache, regnum + 3, buf + 12);
478 }
479 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
480 {
481 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
482 regcache_raw_write (regcache, regnum, buf);
483 regcache_raw_write (regcache, regnum + 1, buf + 8);
484 }
485 else if (regnum == SPARC64_CWP_REGNUM
486 || regnum == SPARC64_PSTATE_REGNUM
487 || regnum == SPARC64_ASI_REGNUM
488 || regnum == SPARC64_CCR_REGNUM)
489 {
490 ULONGEST state, bits;
491
492 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
493 bits = extract_unsigned_integer (buf, 8, byte_order);
494 switch (regnum)
495 {
496 case SPARC64_CWP_REGNUM:
497 state |= ((bits & ((1 << 5) - 1)) << 0);
498 break;
499 case SPARC64_PSTATE_REGNUM:
500 state |= ((bits & ((1 << 12) - 1)) << 8);
501 break;
502 case SPARC64_ASI_REGNUM:
503 state |= ((bits & ((1 << 8) - 1)) << 24);
504 break;
505 case SPARC64_CCR_REGNUM:
506 state |= ((bits & ((1 << 8) - 1)) << 32);
507 break;
508 }
509 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
510 }
511 }
512 \f
513
514 /* Return PC of first real instruction of the function starting at
515 START_PC. */
516
517 static CORE_ADDR
518 sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
519 {
520 struct symtab_and_line sal;
521 CORE_ADDR func_start, func_end;
522 struct sparc_frame_cache cache;
523
524 /* This is the preferred method, find the end of the prologue by
525 using the debugging information. */
526 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
527 {
528 sal = find_pc_line (func_start, 0);
529
530 if (sal.end < func_end
531 && start_pc <= sal.end)
532 return sal.end;
533 }
534
535 return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL,
536 &cache);
537 }
538
539 /* Normal frames. */
540
541 static struct sparc_frame_cache *
542 sparc64_frame_cache (struct frame_info *this_frame, void **this_cache)
543 {
544 return sparc_frame_cache (this_frame, this_cache);
545 }
546
547 static void
548 sparc64_frame_this_id (struct frame_info *this_frame, void **this_cache,
549 struct frame_id *this_id)
550 {
551 struct sparc_frame_cache *cache =
552 sparc64_frame_cache (this_frame, this_cache);
553
554 /* This marks the outermost frame. */
555 if (cache->base == 0)
556 return;
557
558 (*this_id) = frame_id_build (cache->base, cache->pc);
559 }
560
561 static struct value *
562 sparc64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
563 int regnum)
564 {
565 struct gdbarch *gdbarch = get_frame_arch (this_frame);
566 struct sparc_frame_cache *cache =
567 sparc64_frame_cache (this_frame, this_cache);
568
569 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
570 {
571 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
572
573 regnum =
574 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
575 pc += get_frame_register_unsigned (this_frame, regnum) + 8;
576 return frame_unwind_got_constant (this_frame, regnum, pc);
577 }
578
579 /* Handle StackGhost. */
580 {
581 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
582
583 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
584 {
585 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
586 ULONGEST i7;
587
588 /* Read the value in from memory. */
589 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
590 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie);
591 }
592 }
593
594 /* The previous frame's `local' and `in' registers may have been saved
595 in the register save area. */
596 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
597 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
598 {
599 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
600
601 return frame_unwind_got_memory (this_frame, regnum, addr);
602 }
603
604 /* The previous frame's `out' registers may be accessible as the current
605 frame's `in' registers. */
606 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
607 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
608 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
609
610 return frame_unwind_got_register (this_frame, regnum, regnum);
611 }
612
613 static const struct frame_unwind sparc64_frame_unwind =
614 {
615 NORMAL_FRAME,
616 default_frame_unwind_stop_reason,
617 sparc64_frame_this_id,
618 sparc64_frame_prev_register,
619 NULL,
620 default_frame_sniffer
621 };
622 \f
623
624 static CORE_ADDR
625 sparc64_frame_base_address (struct frame_info *this_frame, void **this_cache)
626 {
627 struct sparc_frame_cache *cache =
628 sparc64_frame_cache (this_frame, this_cache);
629
630 return cache->base;
631 }
632
633 static const struct frame_base sparc64_frame_base =
634 {
635 &sparc64_frame_unwind,
636 sparc64_frame_base_address,
637 sparc64_frame_base_address,
638 sparc64_frame_base_address
639 };
640 \f
641 /* Check whether TYPE must be 16-byte aligned. */
642
643 static int
644 sparc64_16_byte_align_p (struct type *type)
645 {
646 if (sparc64_floating_p (type) && TYPE_LENGTH (type) == 16)
647 return 1;
648
649 if (sparc64_structure_or_union_p (type))
650 {
651 int i;
652
653 for (i = 0; i < TYPE_NFIELDS (type); i++)
654 {
655 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
656
657 if (sparc64_16_byte_align_p (subtype))
658 return 1;
659 }
660 }
661
662 return 0;
663 }
664
665 /* Store floating fields of element ELEMENT of an "parameter array"
666 that has type TYPE and is stored at BITPOS in VALBUF in the
667 apropriate registers of REGCACHE. This function can be called
668 recursively and therefore handles floating types in addition to
669 structures. */
670
671 static void
672 sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
673 const gdb_byte *valbuf, int element, int bitpos)
674 {
675 struct gdbarch *gdbarch = get_regcache_arch (regcache);
676 int len = TYPE_LENGTH (type);
677
678 gdb_assert (element < 16);
679
680 if (sparc64_floating_p (type)
681 || (sparc64_complex_floating_p (type) && len <= 16))
682 {
683 int regnum;
684
685 if (len == 16)
686 {
687 gdb_assert (bitpos == 0);
688 gdb_assert ((element % 2) == 0);
689
690 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM + element / 2;
691 regcache_cooked_write (regcache, regnum, valbuf);
692 }
693 else if (len == 8)
694 {
695 gdb_assert (bitpos == 0 || bitpos == 64);
696
697 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
698 + element + bitpos / 64;
699 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
700 }
701 else
702 {
703 gdb_assert (len == 4);
704 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
705
706 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
707 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
708 }
709 }
710 else if (sparc64_structure_or_union_p (type))
711 {
712 int i;
713
714 for (i = 0; i < TYPE_NFIELDS (type); i++)
715 {
716 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
717 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
718
719 sparc64_store_floating_fields (regcache, subtype, valbuf,
720 element, subpos);
721 }
722
723 /* GCC has an interesting bug. If TYPE is a structure that has
724 a single `float' member, GCC doesn't treat it as a structure
725 at all, but rather as an ordinary `float' argument. This
726 argument will be stored in %f1, as required by the psABI.
727 However, as a member of a structure the psABI requires it to
728 be stored in %f0. This bug is present in GCC 3.3.2, but
729 probably in older releases to. To appease GCC, if a
730 structure has only a single `float' member, we store its
731 value in %f1 too (we already have stored in %f0). */
732 if (TYPE_NFIELDS (type) == 1)
733 {
734 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0));
735
736 if (sparc64_floating_p (subtype) && TYPE_LENGTH (subtype) == 4)
737 regcache_cooked_write (regcache, SPARC_F1_REGNUM, valbuf);
738 }
739 }
740 }
741
742 /* Fetch floating fields from a variable of type TYPE from the
743 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
744 in VALBUF. This function can be called recursively and therefore
745 handles floating types in addition to structures. */
746
747 static void
748 sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
749 gdb_byte *valbuf, int bitpos)
750 {
751 struct gdbarch *gdbarch = get_regcache_arch (regcache);
752
753 if (sparc64_floating_p (type))
754 {
755 int len = TYPE_LENGTH (type);
756 int regnum;
757
758 if (len == 16)
759 {
760 gdb_assert (bitpos == 0 || bitpos == 128);
761
762 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
763 + bitpos / 128;
764 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
765 }
766 else if (len == 8)
767 {
768 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
769
770 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + bitpos / 64;
771 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
772 }
773 else
774 {
775 gdb_assert (len == 4);
776 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
777
778 regnum = SPARC_F0_REGNUM + bitpos / 32;
779 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
780 }
781 }
782 else if (sparc64_structure_or_union_p (type))
783 {
784 int i;
785
786 for (i = 0; i < TYPE_NFIELDS (type); i++)
787 {
788 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
789 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
790
791 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
792 }
793 }
794 }
795
796 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
797 non-zero) in REGCACHE and on the stack (starting from address SP). */
798
799 static CORE_ADDR
800 sparc64_store_arguments (struct regcache *regcache, int nargs,
801 struct value **args, CORE_ADDR sp,
802 int struct_return, CORE_ADDR struct_addr)
803 {
804 struct gdbarch *gdbarch = get_regcache_arch (regcache);
805 /* Number of extended words in the "parameter array". */
806 int num_elements = 0;
807 int element = 0;
808 int i;
809
810 /* Take BIAS into account. */
811 sp += BIAS;
812
813 /* First we calculate the number of extended words in the "parameter
814 array". While doing so we also convert some of the arguments. */
815
816 if (struct_return)
817 num_elements++;
818
819 for (i = 0; i < nargs; i++)
820 {
821 struct type *type = value_type (args[i]);
822 int len = TYPE_LENGTH (type);
823
824 if (sparc64_structure_or_union_p (type)
825 || (sparc64_complex_floating_p (type) && len == 32))
826 {
827 /* Structure or Union arguments. */
828 if (len <= 16)
829 {
830 if (num_elements % 2 && sparc64_16_byte_align_p (type))
831 num_elements++;
832 num_elements += ((len + 7) / 8);
833 }
834 else
835 {
836 /* The psABI says that "Structures or unions larger than
837 sixteen bytes are copied by the caller and passed
838 indirectly; the caller will pass the address of a
839 correctly aligned structure value. This sixty-four
840 bit address will occupy one word in the parameter
841 array, and may be promoted to an %o register like any
842 other pointer value." Allocate memory for these
843 values on the stack. */
844 sp -= len;
845
846 /* Use 16-byte alignment for these values. That's
847 always correct, and wasting a few bytes shouldn't be
848 a problem. */
849 sp &= ~0xf;
850
851 write_memory (sp, value_contents (args[i]), len);
852 args[i] = value_from_pointer (lookup_pointer_type (type), sp);
853 num_elements++;
854 }
855 }
856 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
857 {
858 /* Floating arguments. */
859 if (len == 16)
860 {
861 /* The psABI says that "Each quad-precision parameter
862 value will be assigned to two extended words in the
863 parameter array. */
864 num_elements += 2;
865
866 /* The psABI says that "Long doubles must be
867 quad-aligned, and thus a hole might be introduced
868 into the parameter array to force alignment." Skip
869 an element if necessary. */
870 if ((num_elements % 2) && sparc64_16_byte_align_p (type))
871 num_elements++;
872 }
873 else
874 num_elements++;
875 }
876 else
877 {
878 /* Integral and pointer arguments. */
879 gdb_assert (sparc64_integral_or_pointer_p (type));
880
881 /* The psABI says that "Each argument value of integral type
882 smaller than an extended word will be widened by the
883 caller to an extended word according to the signed-ness
884 of the argument type." */
885 if (len < 8)
886 args[i] = value_cast (builtin_type (gdbarch)->builtin_int64,
887 args[i]);
888 num_elements++;
889 }
890 }
891
892 /* Allocate the "parameter array". */
893 sp -= num_elements * 8;
894
895 /* The psABI says that "Every stack frame must be 16-byte aligned." */
896 sp &= ~0xf;
897
898 /* Now we store the arguments in to the "paramater array". Some
899 Integer or Pointer arguments and Structure or Union arguments
900 will be passed in %o registers. Some Floating arguments and
901 floating members of structures are passed in floating-point
902 registers. However, for functions with variable arguments,
903 floating arguments are stored in an %0 register, and for
904 functions without a prototype floating arguments are stored in
905 both a floating-point and an %o registers, or a floating-point
906 register and memory. To simplify the logic here we always pass
907 arguments in memory, an %o register, and a floating-point
908 register if appropriate. This should be no problem since the
909 contents of any unused memory or registers in the "parameter
910 array" are undefined. */
911
912 if (struct_return)
913 {
914 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
915 element++;
916 }
917
918 for (i = 0; i < nargs; i++)
919 {
920 const gdb_byte *valbuf = value_contents (args[i]);
921 struct type *type = value_type (args[i]);
922 int len = TYPE_LENGTH (type);
923 int regnum = -1;
924 gdb_byte buf[16];
925
926 if (sparc64_structure_or_union_p (type)
927 || (sparc64_complex_floating_p (type) && len == 32))
928 {
929 /* Structure, Union or long double Complex arguments. */
930 gdb_assert (len <= 16);
931 memset (buf, 0, sizeof (buf));
932 memcpy (buf, valbuf, len);
933 valbuf = buf;
934
935 if (element % 2 && sparc64_16_byte_align_p (type))
936 element++;
937
938 if (element < 6)
939 {
940 regnum = SPARC_O0_REGNUM + element;
941 if (len > 8 && element < 5)
942 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
943 }
944
945 if (element < 16)
946 sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
947 }
948 else if (sparc64_complex_floating_p (type))
949 {
950 /* Float Complex or double Complex arguments. */
951 if (element < 16)
952 {
953 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + element;
954
955 if (len == 16)
956 {
957 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D30_REGNUM)
958 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
959 if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D10_REGNUM)
960 regcache_cooked_write (regcache,
961 SPARC_O0_REGNUM + element + 1,
962 valbuf + 8);
963 }
964 }
965 }
966 else if (sparc64_floating_p (type))
967 {
968 /* Floating arguments. */
969 if (len == 16)
970 {
971 if (element % 2)
972 element++;
973 if (element < 16)
974 regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM
975 + element / 2;
976 }
977 else if (len == 8)
978 {
979 if (element < 16)
980 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
981 + element;
982 }
983 else if (len == 4)
984 {
985 /* The psABI says "Each single-precision parameter value
986 will be assigned to one extended word in the
987 parameter array, and right-justified within that
988 word; the left half (even float register) is
989 undefined." Even though the psABI says that "the
990 left half is undefined", set it to zero here. */
991 memset (buf, 0, 4);
992 memcpy (buf + 4, valbuf, 4);
993 valbuf = buf;
994 len = 8;
995 if (element < 16)
996 regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM
997 + element;
998 }
999 }
1000 else
1001 {
1002 /* Integral and pointer arguments. */
1003 gdb_assert (len == 8);
1004 if (element < 6)
1005 regnum = SPARC_O0_REGNUM + element;
1006 }
1007
1008 if (regnum != -1)
1009 {
1010 regcache_cooked_write (regcache, regnum, valbuf);
1011
1012 /* If we're storing the value in a floating-point register,
1013 also store it in the corresponding %0 register(s). */
1014 if (regnum >= gdbarch_num_regs (gdbarch))
1015 {
1016 regnum -= gdbarch_num_regs (gdbarch);
1017
1018 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
1019 {
1020 gdb_assert (element < 6);
1021 regnum = SPARC_O0_REGNUM + element;
1022 regcache_cooked_write (regcache, regnum, valbuf);
1023 }
1024 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
1025 {
1026 gdb_assert (element < 5);
1027 regnum = SPARC_O0_REGNUM + element;
1028 regcache_cooked_write (regcache, regnum, valbuf);
1029 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
1030 }
1031 }
1032 }
1033
1034 /* Always store the argument in memory. */
1035 write_memory (sp + element * 8, valbuf, len);
1036 element += ((len + 7) / 8);
1037 }
1038
1039 gdb_assert (element == num_elements);
1040
1041 /* Take BIAS into account. */
1042 sp -= BIAS;
1043 return sp;
1044 }
1045
1046 static CORE_ADDR
1047 sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
1048 {
1049 /* The ABI requires 16-byte alignment. */
1050 return address & ~0xf;
1051 }
1052
1053 static CORE_ADDR
1054 sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1055 struct regcache *regcache, CORE_ADDR bp_addr,
1056 int nargs, struct value **args, CORE_ADDR sp,
1057 int struct_return, CORE_ADDR struct_addr)
1058 {
1059 /* Set return address. */
1060 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
1061
1062 /* Set up function arguments. */
1063 sp = sparc64_store_arguments (regcache, nargs, args, sp,
1064 struct_return, struct_addr);
1065
1066 /* Allocate the register save area. */
1067 sp -= 16 * 8;
1068
1069 /* Stack should be 16-byte aligned at this point. */
1070 gdb_assert ((sp + BIAS) % 16 == 0);
1071
1072 /* Finally, update the stack pointer. */
1073 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
1074
1075 return sp + BIAS;
1076 }
1077 \f
1078
1079 /* Extract from an array REGBUF containing the (raw) register state, a
1080 function return value of TYPE, and copy that into VALBUF. */
1081
1082 static void
1083 sparc64_extract_return_value (struct type *type, struct regcache *regcache,
1084 gdb_byte *valbuf)
1085 {
1086 int len = TYPE_LENGTH (type);
1087 gdb_byte buf[32];
1088 int i;
1089
1090 if (sparc64_structure_or_union_p (type))
1091 {
1092 /* Structure or Union return values. */
1093 gdb_assert (len <= 32);
1094
1095 for (i = 0; i < ((len + 7) / 8); i++)
1096 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1097 if (TYPE_CODE (type) != TYPE_CODE_UNION)
1098 sparc64_extract_floating_fields (regcache, type, buf, 0);
1099 memcpy (valbuf, buf, len);
1100 }
1101 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1102 {
1103 /* Floating return values. */
1104 for (i = 0; i < len / 4; i++)
1105 regcache_cooked_read (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
1106 memcpy (valbuf, buf, len);
1107 }
1108 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1109 {
1110 /* Small arrays are returned the same way as small structures. */
1111 gdb_assert (len <= 32);
1112
1113 for (i = 0; i < ((len + 7) / 8); i++)
1114 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1115 memcpy (valbuf, buf, len);
1116 }
1117 else
1118 {
1119 /* Integral and pointer return values. */
1120 gdb_assert (sparc64_integral_or_pointer_p (type));
1121
1122 /* Just stripping off any unused bytes should preserve the
1123 signed-ness just fine. */
1124 regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf);
1125 memcpy (valbuf, buf + 8 - len, len);
1126 }
1127 }
1128
1129 /* Write into the appropriate registers a function return value stored
1130 in VALBUF of type TYPE. */
1131
1132 static void
1133 sparc64_store_return_value (struct type *type, struct regcache *regcache,
1134 const gdb_byte *valbuf)
1135 {
1136 int len = TYPE_LENGTH (type);
1137 gdb_byte buf[16];
1138 int i;
1139
1140 if (sparc64_structure_or_union_p (type))
1141 {
1142 /* Structure or Union return values. */
1143 gdb_assert (len <= 32);
1144
1145 /* Simplify matters by storing the complete value (including
1146 floating members) into %o0 and %o1. Floating members are
1147 also store in the appropriate floating-point registers. */
1148 memset (buf, 0, sizeof (buf));
1149 memcpy (buf, valbuf, len);
1150 for (i = 0; i < ((len + 7) / 8); i++)
1151 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1152 if (TYPE_CODE (type) != TYPE_CODE_UNION)
1153 sparc64_store_floating_fields (regcache, type, buf, 0, 0);
1154 }
1155 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
1156 {
1157 /* Floating return values. */
1158 memcpy (buf, valbuf, len);
1159 for (i = 0; i < len / 4; i++)
1160 regcache_cooked_write (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
1161 }
1162 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1163 {
1164 /* Small arrays are returned the same way as small structures. */
1165 gdb_assert (len <= 32);
1166
1167 memset (buf, 0, sizeof (buf));
1168 memcpy (buf, valbuf, len);
1169 for (i = 0; i < ((len + 7) / 8); i++)
1170 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1171 }
1172 else
1173 {
1174 /* Integral and pointer return values. */
1175 gdb_assert (sparc64_integral_or_pointer_p (type));
1176
1177 /* ??? Do we need to do any sign-extension here? */
1178 memset (buf, 0, 8);
1179 memcpy (buf + 8 - len, valbuf, len);
1180 regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf);
1181 }
1182 }
1183
1184 static enum return_value_convention
1185 sparc64_return_value (struct gdbarch *gdbarch, struct value *function,
1186 struct type *type, struct regcache *regcache,
1187 gdb_byte *readbuf, const gdb_byte *writebuf)
1188 {
1189 if (TYPE_LENGTH (type) > 32)
1190 return RETURN_VALUE_STRUCT_CONVENTION;
1191
1192 if (readbuf)
1193 sparc64_extract_return_value (type, regcache, readbuf);
1194 if (writebuf)
1195 sparc64_store_return_value (type, regcache, writebuf);
1196
1197 return RETURN_VALUE_REGISTER_CONVENTION;
1198 }
1199 \f
1200
1201 static void
1202 sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1203 struct dwarf2_frame_state_reg *reg,
1204 struct frame_info *this_frame)
1205 {
1206 switch (regnum)
1207 {
1208 case SPARC_G0_REGNUM:
1209 /* Since %g0 is always zero, there is no point in saving it, and
1210 people will be inclined omit it from the CFI. Make sure we
1211 don't warn about that. */
1212 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1213 break;
1214 case SPARC_SP_REGNUM:
1215 reg->how = DWARF2_FRAME_REG_CFA;
1216 break;
1217 case SPARC64_PC_REGNUM:
1218 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1219 reg->loc.offset = 8;
1220 break;
1221 case SPARC64_NPC_REGNUM:
1222 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1223 reg->loc.offset = 12;
1224 break;
1225 }
1226 }
1227
1228 void
1229 sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1230 {
1231 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1232
1233 tdep->pc_regnum = SPARC64_PC_REGNUM;
1234 tdep->npc_regnum = SPARC64_NPC_REGNUM;
1235 tdep->fpu_register_names = sparc64_fpu_register_names;
1236 tdep->fpu_registers_num = ARRAY_SIZE (sparc64_fpu_register_names);
1237 tdep->cp0_register_names = sparc64_cp0_register_names;
1238 tdep->cp0_registers_num = ARRAY_SIZE (sparc64_cp0_register_names);
1239
1240 /* This is what all the fuss is about. */
1241 set_gdbarch_long_bit (gdbarch, 64);
1242 set_gdbarch_long_long_bit (gdbarch, 64);
1243 set_gdbarch_ptr_bit (gdbarch, 64);
1244
1245 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
1246 set_gdbarch_register_name (gdbarch, sparc64_register_name);
1247 set_gdbarch_register_type (gdbarch, sparc64_register_type);
1248 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
1249 set_tdesc_pseudo_register_name (gdbarch, sparc64_pseudo_register_name);
1250 set_tdesc_pseudo_register_type (gdbarch, sparc64_pseudo_register_type);
1251 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
1252 set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write);
1253
1254 /* Register numbers of various important registers. */
1255 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
1256
1257 /* Call dummy code. */
1258 set_gdbarch_frame_align (gdbarch, sparc64_frame_align);
1259 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1260 set_gdbarch_push_dummy_code (gdbarch, NULL);
1261 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
1262
1263 set_gdbarch_return_value (gdbarch, sparc64_return_value);
1264 set_gdbarch_stabs_argument_has_addr
1265 (gdbarch, default_stabs_argument_has_addr);
1266
1267 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
1268 set_gdbarch_stack_frame_destroyed_p (gdbarch, sparc_stack_frame_destroyed_p);
1269
1270 /* Hook in the DWARF CFI frame unwinder. */
1271 dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg);
1272 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1273 StackGhost issues have been resolved. */
1274
1275 frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind);
1276 frame_base_set_default (gdbarch, &sparc64_frame_base);
1277 }
1278 \f
1279
1280 /* Helper functions for dealing with register sets. */
1281
1282 #define TSTATE_CWP 0x000000000000001fULL
1283 #define TSTATE_ICC 0x0000000f00000000ULL
1284 #define TSTATE_XCC 0x000000f000000000ULL
1285
1286 #define PSR_S 0x00000080
1287 #define PSR_ICC 0x00f00000
1288 #define PSR_VERS 0x0f000000
1289 #define PSR_IMPL 0xf0000000
1290 #define PSR_V8PLUS 0xff000000
1291 #define PSR_XCC 0x000f0000
1292
1293 void
1294 sparc64_supply_gregset (const struct sparc_gregmap *gregmap,
1295 struct regcache *regcache,
1296 int regnum, const void *gregs)
1297 {
1298 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1299 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1300 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
1301 const gdb_byte *regs = (const gdb_byte *) gregs;
1302 gdb_byte zero[8] = { 0 };
1303 int i;
1304
1305 if (sparc32)
1306 {
1307 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1308 {
1309 int offset = gregmap->r_tstate_offset;
1310 ULONGEST tstate, psr;
1311 gdb_byte buf[4];
1312
1313 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
1314 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
1315 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
1316 store_unsigned_integer (buf, 4, byte_order, psr);
1317 regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, buf);
1318 }
1319
1320 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1321 regcache_raw_supply (regcache, SPARC32_PC_REGNUM,
1322 regs + gregmap->r_pc_offset + 4);
1323
1324 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1325 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM,
1326 regs + gregmap->r_npc_offset + 4);
1327
1328 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1329 {
1330 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
1331 regcache_raw_supply (regcache, SPARC32_Y_REGNUM, regs + offset);
1332 }
1333 }
1334 else
1335 {
1336 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1337 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM,
1338 regs + gregmap->r_tstate_offset);
1339
1340 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1341 regcache_raw_supply (regcache, SPARC64_PC_REGNUM,
1342 regs + gregmap->r_pc_offset);
1343
1344 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1345 regcache_raw_supply (regcache, SPARC64_NPC_REGNUM,
1346 regs + gregmap->r_npc_offset);
1347
1348 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1349 {
1350 gdb_byte buf[8];
1351
1352 memset (buf, 0, 8);
1353 memcpy (buf + 8 - gregmap->r_y_size,
1354 regs + gregmap->r_y_offset, gregmap->r_y_size);
1355 regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf);
1356 }
1357
1358 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1359 && gregmap->r_fprs_offset != -1)
1360 regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM,
1361 regs + gregmap->r_fprs_offset);
1362 }
1363
1364 if (regnum == SPARC_G0_REGNUM || regnum == -1)
1365 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero);
1366
1367 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1368 {
1369 int offset = gregmap->r_g1_offset;
1370
1371 if (sparc32)
1372 offset += 4;
1373
1374 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1375 {
1376 if (regnum == i || regnum == -1)
1377 regcache_raw_supply (regcache, i, regs + offset);
1378 offset += 8;
1379 }
1380 }
1381
1382 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1383 {
1384 /* Not all of the register set variants include Locals and
1385 Inputs. For those that don't, we read them off the stack. */
1386 if (gregmap->r_l0_offset == -1)
1387 {
1388 ULONGEST sp;
1389
1390 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
1391 sparc_supply_rwindow (regcache, sp, regnum);
1392 }
1393 else
1394 {
1395 int offset = gregmap->r_l0_offset;
1396
1397 if (sparc32)
1398 offset += 4;
1399
1400 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1401 {
1402 if (regnum == i || regnum == -1)
1403 regcache_raw_supply (regcache, i, regs + offset);
1404 offset += 8;
1405 }
1406 }
1407 }
1408 }
1409
1410 void
1411 sparc64_collect_gregset (const struct sparc_gregmap *gregmap,
1412 const struct regcache *regcache,
1413 int regnum, void *gregs)
1414 {
1415 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1416 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1417 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
1418 gdb_byte *regs = (gdb_byte *) gregs;
1419 int i;
1420
1421 if (sparc32)
1422 {
1423 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1424 {
1425 int offset = gregmap->r_tstate_offset;
1426 ULONGEST tstate, psr;
1427 gdb_byte buf[8];
1428
1429 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
1430 regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, buf);
1431 psr = extract_unsigned_integer (buf, 4, byte_order);
1432 tstate |= (psr & PSR_ICC) << 12;
1433 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
1434 tstate |= (psr & PSR_XCC) << 20;
1435 store_unsigned_integer (buf, 8, byte_order, tstate);
1436 memcpy (regs + offset, buf, 8);
1437 }
1438
1439 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1440 regcache_raw_collect (regcache, SPARC32_PC_REGNUM,
1441 regs + gregmap->r_pc_offset + 4);
1442
1443 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1444 regcache_raw_collect (regcache, SPARC32_NPC_REGNUM,
1445 regs + gregmap->r_npc_offset + 4);
1446
1447 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
1448 {
1449 int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size;
1450 regcache_raw_collect (regcache, SPARC32_Y_REGNUM, regs + offset);
1451 }
1452 }
1453 else
1454 {
1455 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1456 regcache_raw_collect (regcache, SPARC64_STATE_REGNUM,
1457 regs + gregmap->r_tstate_offset);
1458
1459 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1460 regcache_raw_collect (regcache, SPARC64_PC_REGNUM,
1461 regs + gregmap->r_pc_offset);
1462
1463 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1464 regcache_raw_collect (regcache, SPARC64_NPC_REGNUM,
1465 regs + gregmap->r_npc_offset);
1466
1467 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
1468 {
1469 gdb_byte buf[8];
1470
1471 regcache_raw_collect (regcache, SPARC64_Y_REGNUM, buf);
1472 memcpy (regs + gregmap->r_y_offset,
1473 buf + 8 - gregmap->r_y_size, gregmap->r_y_size);
1474 }
1475
1476 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1477 && gregmap->r_fprs_offset != -1)
1478 regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM,
1479 regs + gregmap->r_fprs_offset);
1480
1481 }
1482
1483 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1484 {
1485 int offset = gregmap->r_g1_offset;
1486
1487 if (sparc32)
1488 offset += 4;
1489
1490 /* %g0 is always zero. */
1491 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1492 {
1493 if (regnum == i || regnum == -1)
1494 regcache_raw_collect (regcache, i, regs + offset);
1495 offset += 8;
1496 }
1497 }
1498
1499 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1500 {
1501 /* Not all of the register set variants include Locals and
1502 Inputs. For those that don't, we read them off the stack. */
1503 if (gregmap->r_l0_offset != -1)
1504 {
1505 int offset = gregmap->r_l0_offset;
1506
1507 if (sparc32)
1508 offset += 4;
1509
1510 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
1511 {
1512 if (regnum == i || regnum == -1)
1513 regcache_raw_collect (regcache, i, regs + offset);
1514 offset += 8;
1515 }
1516 }
1517 }
1518 }
1519
1520 void
1521 sparc64_supply_fpregset (const struct sparc_fpregmap *fpregmap,
1522 struct regcache *regcache,
1523 int regnum, const void *fpregs)
1524 {
1525 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
1526 const gdb_byte *regs = (const gdb_byte *) fpregs;
1527 int i;
1528
1529 for (i = 0; i < 32; i++)
1530 {
1531 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1532 regcache_raw_supply (regcache, SPARC_F0_REGNUM + i,
1533 regs + fpregmap->r_f0_offset + (i * 4));
1534 }
1535
1536 if (sparc32)
1537 {
1538 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1539 regcache_raw_supply (regcache, SPARC32_FSR_REGNUM,
1540 regs + fpregmap->r_fsr_offset);
1541 }
1542 else
1543 {
1544 for (i = 0; i < 16; i++)
1545 {
1546 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1547 regcache_raw_supply (regcache, SPARC64_F32_REGNUM + i,
1548 (regs + fpregmap->r_f0_offset
1549 + (32 * 4) + (i * 8)));
1550 }
1551
1552 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1553 regcache_raw_supply (regcache, SPARC64_FSR_REGNUM,
1554 regs + fpregmap->r_fsr_offset);
1555 }
1556 }
1557
1558 void
1559 sparc64_collect_fpregset (const struct sparc_fpregmap *fpregmap,
1560 const struct regcache *regcache,
1561 int regnum, void *fpregs)
1562 {
1563 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
1564 gdb_byte *regs = (gdb_byte *) fpregs;
1565 int i;
1566
1567 for (i = 0; i < 32; i++)
1568 {
1569 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1570 regcache_raw_collect (regcache, SPARC_F0_REGNUM + i,
1571 regs + fpregmap->r_f0_offset + (i * 4));
1572 }
1573
1574 if (sparc32)
1575 {
1576 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1577 regcache_raw_collect (regcache, SPARC32_FSR_REGNUM,
1578 regs + fpregmap->r_fsr_offset);
1579 }
1580 else
1581 {
1582 for (i = 0; i < 16; i++)
1583 {
1584 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1585 regcache_raw_collect (regcache, SPARC64_F32_REGNUM + i,
1586 (regs + fpregmap->r_f0_offset
1587 + (32 * 4) + (i * 8)));
1588 }
1589
1590 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1591 regcache_raw_collect (regcache, SPARC64_FSR_REGNUM,
1592 regs + fpregmap->r_fsr_offset);
1593 }
1594 }
1595
1596 const struct sparc_fpregmap sparc64_bsd_fpregmap =
1597 {
1598 0 * 8, /* %f0 */
1599 32 * 8, /* %fsr */
1600 };
This page took 0.087378 seconds and 4 git commands to generate.