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