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