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