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