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