* gdbtypes.c (builtin_type_v2_double, builtin_type_v4_float,
[deliverable/binutils-gdb.git] / gdb / amd64-tdep.c
CommitLineData
e53bef9f 1/* Target-dependent code for AMD64.
ce0eebec 2
6aba47ca 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
5ae96ec1
MK
4 Free Software Foundation, Inc.
5
6 Contributed by Jiri Smid, SuSE Labs.
53e95fcf
JS
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
197e01b6
EZ
22 Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, USA. */
53e95fcf
JS
24
25#include "defs.h"
c4f35dd8
MK
26#include "arch-utils.h"
27#include "block.h"
28#include "dummy-frame.h"
29#include "frame.h"
30#include "frame-base.h"
31#include "frame-unwind.h"
53e95fcf 32#include "inferior.h"
53e95fcf 33#include "gdbcmd.h"
c4f35dd8
MK
34#include "gdbcore.h"
35#include "objfiles.h"
53e95fcf 36#include "regcache.h"
2c261fae 37#include "regset.h"
53e95fcf 38#include "symfile.h"
c4f35dd8 39
82dbc5f7 40#include "gdb_assert.h"
c4f35dd8 41
9c1488cb 42#include "amd64-tdep.h"
c4f35dd8 43#include "i387-tdep.h"
53e95fcf 44
e53bef9f
MK
45/* Note that the AMD64 architecture was previously known as x86-64.
46 The latter is (forever) engraved into the canonical system name as
90f90721 47 returned by config.guess, and used as the name for the AMD64 port
e53bef9f
MK
48 of GNU/Linux. The BSD's have renamed their ports to amd64; they
49 don't like to shout. For GDB we prefer the amd64_-prefix over the
50 x86_64_-prefix since it's so much easier to type. */
51
402ecd56 52/* Register information. */
c4f35dd8 53
6707b003 54static const char *amd64_register_names[] =
de220d0f 55{
6707b003 56 "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "rsp",
c4f35dd8
MK
57
58 /* %r8 is indeed register number 8. */
6707b003
UW
59 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
60 "rip", "eflags", "cs", "ss", "ds", "es", "fs", "gs",
c4f35dd8 61
af233647 62 /* %st0 is register number 24. */
6707b003
UW
63 "st0", "st1", "st2", "st3", "st4", "st5", "st6", "st7",
64 "fctrl", "fstat", "ftag", "fiseg", "fioff", "foseg", "fooff", "fop",
c4f35dd8 65
af233647 66 /* %xmm0 is register number 40. */
6707b003
UW
67 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
68 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
69 "mxcsr",
0e04a514
ML
70};
71
c4f35dd8 72/* Total number of registers. */
6707b003 73#define AMD64_NUM_REGS ARRAY_SIZE (amd64_register_names)
de220d0f 74
c4f35dd8 75/* Return the name of register REGNUM. */
b6779aa2 76
8695c747 77const char *
e53bef9f 78amd64_register_name (int regnum)
53e95fcf 79{
e53bef9f 80 if (regnum >= 0 && regnum < AMD64_NUM_REGS)
6707b003 81 return amd64_register_names[regnum];
53e95fcf 82
c4f35dd8 83 return NULL;
53e95fcf
JS
84}
85
86/* Return the GDB type object for the "standard" data type of data in
c4f35dd8 87 register REGNUM. */
53e95fcf 88
8695c747 89struct type *
e53bef9f 90amd64_register_type (struct gdbarch *gdbarch, int regnum)
53e95fcf 91{
6707b003
UW
92 if (regnum >= AMD64_RAX_REGNUM && regnum <= AMD64_RDI_REGNUM)
93 return builtin_type_int64;
94 if (regnum == AMD64_RBP_REGNUM || regnum == AMD64_RSP_REGNUM)
95 return builtin_type_void_data_ptr;
96 if (regnum >= AMD64_R8_REGNUM && regnum <= AMD64_R15_REGNUM)
97 return builtin_type_int64;
98 if (regnum == AMD64_RIP_REGNUM)
99 return builtin_type_void_func_ptr;
100 if (regnum == AMD64_EFLAGS_REGNUM)
101 return i386_eflags_type;
102 if (regnum >= AMD64_CS_REGNUM && regnum <= AMD64_GS_REGNUM)
103 return builtin_type_int32;
104 if (regnum >= AMD64_ST0_REGNUM && regnum <= AMD64_ST0_REGNUM + 7)
105 return builtin_type_i387_ext;
106 if (regnum >= AMD64_FCTRL_REGNUM && regnum <= AMD64_FCTRL_REGNUM + 7)
107 return builtin_type_int32;
108 if (regnum >= AMD64_XMM0_REGNUM && regnum <= AMD64_XMM0_REGNUM + 15)
794ac428 109 return i386_sse_type (gdbarch);
6707b003
UW
110 if (regnum == AMD64_MXCSR_REGNUM)
111 return i386_mxcsr_type;
112
113 internal_error (__FILE__, __LINE__, _("invalid regnum"));
53e95fcf
JS
114}
115
c4f35dd8
MK
116/* DWARF Register Number Mapping as defined in the System V psABI,
117 section 3.6. */
53e95fcf 118
e53bef9f 119static int amd64_dwarf_regmap[] =
0e04a514 120{
c4f35dd8 121 /* General Purpose Registers RAX, RDX, RCX, RBX, RSI, RDI. */
90f90721
MK
122 AMD64_RAX_REGNUM, AMD64_RDX_REGNUM,
123 AMD64_RCX_REGNUM, AMD64_RBX_REGNUM,
124 AMD64_RSI_REGNUM, AMD64_RDI_REGNUM,
c4f35dd8
MK
125
126 /* Frame Pointer Register RBP. */
90f90721 127 AMD64_RBP_REGNUM,
c4f35dd8
MK
128
129 /* Stack Pointer Register RSP. */
90f90721 130 AMD64_RSP_REGNUM,
c4f35dd8
MK
131
132 /* Extended Integer Registers 8 - 15. */
133 8, 9, 10, 11, 12, 13, 14, 15,
134
59207364 135 /* Return Address RA. Mapped to RIP. */
90f90721 136 AMD64_RIP_REGNUM,
c4f35dd8
MK
137
138 /* SSE Registers 0 - 7. */
90f90721
MK
139 AMD64_XMM0_REGNUM + 0, AMD64_XMM1_REGNUM,
140 AMD64_XMM0_REGNUM + 2, AMD64_XMM0_REGNUM + 3,
141 AMD64_XMM0_REGNUM + 4, AMD64_XMM0_REGNUM + 5,
142 AMD64_XMM0_REGNUM + 6, AMD64_XMM0_REGNUM + 7,
c4f35dd8
MK
143
144 /* Extended SSE Registers 8 - 15. */
90f90721
MK
145 AMD64_XMM0_REGNUM + 8, AMD64_XMM0_REGNUM + 9,
146 AMD64_XMM0_REGNUM + 10, AMD64_XMM0_REGNUM + 11,
147 AMD64_XMM0_REGNUM + 12, AMD64_XMM0_REGNUM + 13,
148 AMD64_XMM0_REGNUM + 14, AMD64_XMM0_REGNUM + 15,
c4f35dd8
MK
149
150 /* Floating Point Registers 0-7. */
90f90721
MK
151 AMD64_ST0_REGNUM + 0, AMD64_ST0_REGNUM + 1,
152 AMD64_ST0_REGNUM + 2, AMD64_ST0_REGNUM + 3,
153 AMD64_ST0_REGNUM + 4, AMD64_ST0_REGNUM + 5,
c6f4c129
JB
154 AMD64_ST0_REGNUM + 6, AMD64_ST0_REGNUM + 7,
155
156 /* Control and Status Flags Register. */
157 AMD64_EFLAGS_REGNUM,
158
159 /* Selector Registers. */
160 AMD64_ES_REGNUM,
161 AMD64_CS_REGNUM,
162 AMD64_SS_REGNUM,
163 AMD64_DS_REGNUM,
164 AMD64_FS_REGNUM,
165 AMD64_GS_REGNUM,
166 -1,
167 -1,
168
169 /* Segment Base Address Registers. */
170 -1,
171 -1,
172 -1,
173 -1,
174
175 /* Special Selector Registers. */
176 -1,
177 -1,
178
179 /* Floating Point Control Registers. */
180 AMD64_MXCSR_REGNUM,
181 AMD64_FCTRL_REGNUM,
182 AMD64_FSTAT_REGNUM
c4f35dd8 183};
0e04a514 184
e53bef9f
MK
185static const int amd64_dwarf_regmap_len =
186 (sizeof (amd64_dwarf_regmap) / sizeof (amd64_dwarf_regmap[0]));
0e04a514 187
c4f35dd8
MK
188/* Convert DWARF register number REG to the appropriate register
189 number used by GDB. */
26abbdc4 190
c4f35dd8 191static int
e53bef9f 192amd64_dwarf_reg_to_regnum (int reg)
53e95fcf 193{
c4f35dd8 194 int regnum = -1;
53e95fcf 195
16aff9a6 196 if (reg >= 0 && reg < amd64_dwarf_regmap_len)
e53bef9f 197 regnum = amd64_dwarf_regmap[reg];
53e95fcf 198
c4f35dd8 199 if (regnum == -1)
8a3fe4f8 200 warning (_("Unmapped DWARF Register #%d encountered."), reg);
c4f35dd8
MK
201
202 return regnum;
53e95fcf 203}
d532c08f
MK
204
205/* Return nonzero if a value of type TYPE stored in register REGNUM
206 needs any special handling. */
207
208static int
e53bef9f 209amd64_convert_register_p (int regnum, struct type *type)
d532c08f
MK
210{
211 return i386_fp_regnum_p (regnum);
212}
53e95fcf
JS
213\f
214
efb1c01c
MK
215/* Register classes as defined in the psABI. */
216
217enum amd64_reg_class
218{
219 AMD64_INTEGER,
220 AMD64_SSE,
221 AMD64_SSEUP,
222 AMD64_X87,
223 AMD64_X87UP,
224 AMD64_COMPLEX_X87,
225 AMD64_NO_CLASS,
226 AMD64_MEMORY
227};
228
229/* Return the union class of CLASS1 and CLASS2. See the psABI for
230 details. */
231
232static enum amd64_reg_class
233amd64_merge_classes (enum amd64_reg_class class1, enum amd64_reg_class class2)
234{
235 /* Rule (a): If both classes are equal, this is the resulting class. */
236 if (class1 == class2)
237 return class1;
238
239 /* Rule (b): If one of the classes is NO_CLASS, the resulting class
240 is the other class. */
241 if (class1 == AMD64_NO_CLASS)
242 return class2;
243 if (class2 == AMD64_NO_CLASS)
244 return class1;
245
246 /* Rule (c): If one of the classes is MEMORY, the result is MEMORY. */
247 if (class1 == AMD64_MEMORY || class2 == AMD64_MEMORY)
248 return AMD64_MEMORY;
249
250 /* Rule (d): If one of the classes is INTEGER, the result is INTEGER. */
251 if (class1 == AMD64_INTEGER || class2 == AMD64_INTEGER)
252 return AMD64_INTEGER;
253
254 /* Rule (e): If one of the classes is X87, X87UP, COMPLEX_X87 class,
255 MEMORY is used as class. */
256 if (class1 == AMD64_X87 || class1 == AMD64_X87UP
257 || class1 == AMD64_COMPLEX_X87 || class2 == AMD64_X87
258 || class2 == AMD64_X87UP || class2 == AMD64_COMPLEX_X87)
259 return AMD64_MEMORY;
260
261 /* Rule (f): Otherwise class SSE is used. */
262 return AMD64_SSE;
263}
264
265static void amd64_classify (struct type *type, enum amd64_reg_class class[2]);
266
79b1ab3d
MK
267/* Return non-zero if TYPE is a non-POD structure or union type. */
268
269static int
270amd64_non_pod_p (struct type *type)
271{
272 /* ??? A class with a base class certainly isn't POD, but does this
273 catch all non-POD structure types? */
274 if (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_N_BASECLASSES (type) > 0)
275 return 1;
276
277 return 0;
278}
279
efb1c01c
MK
280/* Classify TYPE according to the rules for aggregate (structures and
281 arrays) and union types, and store the result in CLASS. */
c4f35dd8
MK
282
283static void
efb1c01c 284amd64_classify_aggregate (struct type *type, enum amd64_reg_class class[2])
53e95fcf
JS
285{
286 int len = TYPE_LENGTH (type);
287
efb1c01c
MK
288 /* 1. If the size of an object is larger than two eightbytes, or in
289 C++, is a non-POD structure or union type, or contains
290 unaligned fields, it has class memory. */
79b1ab3d 291 if (len > 16 || amd64_non_pod_p (type))
53e95fcf 292 {
efb1c01c
MK
293 class[0] = class[1] = AMD64_MEMORY;
294 return;
53e95fcf 295 }
efb1c01c
MK
296
297 /* 2. Both eightbytes get initialized to class NO_CLASS. */
298 class[0] = class[1] = AMD64_NO_CLASS;
299
300 /* 3. Each field of an object is classified recursively so that
301 always two fields are considered. The resulting class is
302 calculated according to the classes of the fields in the
303 eightbyte: */
304
305 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
8ffd9b1b 306 {
efb1c01c
MK
307 struct type *subtype = check_typedef (TYPE_TARGET_TYPE (type));
308
309 /* All fields in an array have the same type. */
310 amd64_classify (subtype, class);
311 if (len > 8 && class[1] == AMD64_NO_CLASS)
312 class[1] = class[0];
8ffd9b1b 313 }
53e95fcf
JS
314 else
315 {
efb1c01c 316 int i;
53e95fcf 317
efb1c01c
MK
318 /* Structure or union. */
319 gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
320 || TYPE_CODE (type) == TYPE_CODE_UNION);
321
322 for (i = 0; i < TYPE_NFIELDS (type); i++)
53e95fcf 323 {
efb1c01c
MK
324 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
325 int pos = TYPE_FIELD_BITPOS (type, i) / 64;
326 enum amd64_reg_class subclass[2];
327
562c50c2
MK
328 /* Ignore static fields. */
329 if (TYPE_FIELD_STATIC (type, i))
330 continue;
331
efb1c01c
MK
332 gdb_assert (pos == 0 || pos == 1);
333
334 amd64_classify (subtype, subclass);
335 class[pos] = amd64_merge_classes (class[pos], subclass[0]);
336 if (pos == 0)
337 class[1] = amd64_merge_classes (class[1], subclass[1]);
53e95fcf 338 }
53e95fcf 339 }
efb1c01c
MK
340
341 /* 4. Then a post merger cleanup is done: */
342
343 /* Rule (a): If one of the classes is MEMORY, the whole argument is
344 passed in memory. */
345 if (class[0] == AMD64_MEMORY || class[1] == AMD64_MEMORY)
346 class[0] = class[1] = AMD64_MEMORY;
347
348 /* Rule (b): If SSEUP is not preceeded by SSE, it is converted to
349 SSE. */
350 if (class[0] == AMD64_SSEUP)
351 class[0] = AMD64_SSE;
352 if (class[1] == AMD64_SSEUP && class[0] != AMD64_SSE)
353 class[1] = AMD64_SSE;
354}
355
356/* Classify TYPE, and store the result in CLASS. */
357
358static void
359amd64_classify (struct type *type, enum amd64_reg_class class[2])
360{
361 enum type_code code = TYPE_CODE (type);
362 int len = TYPE_LENGTH (type);
363
364 class[0] = class[1] = AMD64_NO_CLASS;
365
366 /* Arguments of types (signed and unsigned) _Bool, char, short, int,
5a7225ed
JB
367 long, long long, and pointers are in the INTEGER class. Similarly,
368 range types, used by languages such as Ada, are also in the INTEGER
369 class. */
efb1c01c 370 if ((code == TYPE_CODE_INT || code == TYPE_CODE_ENUM
b929c77f 371 || code == TYPE_CODE_BOOL || code == TYPE_CODE_RANGE
efb1c01c
MK
372 || code == TYPE_CODE_PTR || code == TYPE_CODE_REF)
373 && (len == 1 || len == 2 || len == 4 || len == 8))
374 class[0] = AMD64_INTEGER;
375
376 /* Arguments of types float, double and __m64 are in class SSE. */
377 else if (code == TYPE_CODE_FLT && (len == 4 || len == 8))
378 /* FIXME: __m64 . */
379 class[0] = AMD64_SSE;
380
381 /* Arguments of types __float128 and __m128 are split into two
382 halves. The least significant ones belong to class SSE, the most
383 significant one to class SSEUP. */
384 /* FIXME: __float128, __m128. */
385
386 /* The 64-bit mantissa of arguments of type long double belongs to
387 class X87, the 16-bit exponent plus 6 bytes of padding belongs to
388 class X87UP. */
389 else if (code == TYPE_CODE_FLT && len == 16)
390 /* Class X87 and X87UP. */
391 class[0] = AMD64_X87, class[1] = AMD64_X87UP;
392
393 /* Aggregates. */
394 else if (code == TYPE_CODE_ARRAY || code == TYPE_CODE_STRUCT
395 || code == TYPE_CODE_UNION)
396 amd64_classify_aggregate (type, class);
397}
398
399static enum return_value_convention
400amd64_return_value (struct gdbarch *gdbarch, struct type *type,
401 struct regcache *regcache,
42835c2b 402 gdb_byte *readbuf, const gdb_byte *writebuf)
efb1c01c
MK
403{
404 enum amd64_reg_class class[2];
405 int len = TYPE_LENGTH (type);
90f90721
MK
406 static int integer_regnum[] = { AMD64_RAX_REGNUM, AMD64_RDX_REGNUM };
407 static int sse_regnum[] = { AMD64_XMM0_REGNUM, AMD64_XMM1_REGNUM };
efb1c01c
MK
408 int integer_reg = 0;
409 int sse_reg = 0;
410 int i;
411
412 gdb_assert (!(readbuf && writebuf));
413
414 /* 1. Classify the return type with the classification algorithm. */
415 amd64_classify (type, class);
416
417 /* 2. If the type has class MEMORY, then the caller provides space
6fa57a7d
MK
418 for the return value and passes the address of this storage in
419 %rdi as if it were the first argument to the function. In effect,
420 this address becomes a hidden first argument.
421
422 On return %rax will contain the address that has been passed in
423 by the caller in %rdi. */
efb1c01c 424 if (class[0] == AMD64_MEMORY)
6fa57a7d
MK
425 {
426 /* As indicated by the comment above, the ABI guarantees that we
427 can always find the return value just after the function has
428 returned. */
429
430 if (readbuf)
431 {
432 ULONGEST addr;
433
434 regcache_raw_read_unsigned (regcache, AMD64_RAX_REGNUM, &addr);
435 read_memory (addr, readbuf, TYPE_LENGTH (type));
436 }
437
438 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
439 }
efb1c01c
MK
440
441 gdb_assert (class[1] != AMD64_MEMORY);
442 gdb_assert (len <= 16);
443
444 for (i = 0; len > 0; i++, len -= 8)
445 {
446 int regnum = -1;
447 int offset = 0;
448
449 switch (class[i])
450 {
451 case AMD64_INTEGER:
452 /* 3. If the class is INTEGER, the next available register
453 of the sequence %rax, %rdx is used. */
454 regnum = integer_regnum[integer_reg++];
455 break;
456
457 case AMD64_SSE:
458 /* 4. If the class is SSE, the next available SSE register
459 of the sequence %xmm0, %xmm1 is used. */
460 regnum = sse_regnum[sse_reg++];
461 break;
462
463 case AMD64_SSEUP:
464 /* 5. If the class is SSEUP, the eightbyte is passed in the
465 upper half of the last used SSE register. */
466 gdb_assert (sse_reg > 0);
467 regnum = sse_regnum[sse_reg - 1];
468 offset = 8;
469 break;
470
471 case AMD64_X87:
472 /* 6. If the class is X87, the value is returned on the X87
473 stack in %st0 as 80-bit x87 number. */
90f90721 474 regnum = AMD64_ST0_REGNUM;
efb1c01c
MK
475 if (writebuf)
476 i387_return_value (gdbarch, regcache);
477 break;
478
479 case AMD64_X87UP:
480 /* 7. If the class is X87UP, the value is returned together
481 with the previous X87 value in %st0. */
482 gdb_assert (i > 0 && class[0] == AMD64_X87);
90f90721 483 regnum = AMD64_ST0_REGNUM;
efb1c01c
MK
484 offset = 8;
485 len = 2;
486 break;
487
488 case AMD64_NO_CLASS:
489 continue;
490
491 default:
492 gdb_assert (!"Unexpected register class.");
493 }
494
495 gdb_assert (regnum != -1);
496
497 if (readbuf)
498 regcache_raw_read_part (regcache, regnum, offset, min (len, 8),
42835c2b 499 readbuf + i * 8);
efb1c01c
MK
500 if (writebuf)
501 regcache_raw_write_part (regcache, regnum, offset, min (len, 8),
42835c2b 502 writebuf + i * 8);
efb1c01c
MK
503 }
504
505 return RETURN_VALUE_REGISTER_CONVENTION;
53e95fcf
JS
506}
507\f
508
720aa428
MK
509static CORE_ADDR
510amd64_push_arguments (struct regcache *regcache, int nargs,
6470d250 511 struct value **args, CORE_ADDR sp, int struct_return)
720aa428
MK
512{
513 static int integer_regnum[] =
514 {
90f90721
MK
515 AMD64_RDI_REGNUM, /* %rdi */
516 AMD64_RSI_REGNUM, /* %rsi */
517 AMD64_RDX_REGNUM, /* %rdx */
518 AMD64_RCX_REGNUM, /* %rcx */
519 8, /* %r8 */
520 9 /* %r9 */
720aa428
MK
521 };
522 static int sse_regnum[] =
523 {
524 /* %xmm0 ... %xmm7 */
90f90721
MK
525 AMD64_XMM0_REGNUM + 0, AMD64_XMM1_REGNUM,
526 AMD64_XMM0_REGNUM + 2, AMD64_XMM0_REGNUM + 3,
527 AMD64_XMM0_REGNUM + 4, AMD64_XMM0_REGNUM + 5,
528 AMD64_XMM0_REGNUM + 6, AMD64_XMM0_REGNUM + 7,
720aa428
MK
529 };
530 struct value **stack_args = alloca (nargs * sizeof (struct value *));
531 int num_stack_args = 0;
532 int num_elements = 0;
533 int element = 0;
534 int integer_reg = 0;
535 int sse_reg = 0;
536 int i;
537
6470d250
MK
538 /* Reserve a register for the "hidden" argument. */
539 if (struct_return)
540 integer_reg++;
541
720aa428
MK
542 for (i = 0; i < nargs; i++)
543 {
4991999e 544 struct type *type = value_type (args[i]);
720aa428
MK
545 int len = TYPE_LENGTH (type);
546 enum amd64_reg_class class[2];
547 int needed_integer_regs = 0;
548 int needed_sse_regs = 0;
549 int j;
550
551 /* Classify argument. */
552 amd64_classify (type, class);
553
554 /* Calculate the number of integer and SSE registers needed for
555 this argument. */
556 for (j = 0; j < 2; j++)
557 {
558 if (class[j] == AMD64_INTEGER)
559 needed_integer_regs++;
560 else if (class[j] == AMD64_SSE)
561 needed_sse_regs++;
562 }
563
564 /* Check whether enough registers are available, and if the
565 argument should be passed in registers at all. */
566 if (integer_reg + needed_integer_regs > ARRAY_SIZE (integer_regnum)
567 || sse_reg + needed_sse_regs > ARRAY_SIZE (sse_regnum)
568 || (needed_integer_regs == 0 && needed_sse_regs == 0))
569 {
570 /* The argument will be passed on the stack. */
571 num_elements += ((len + 7) / 8);
572 stack_args[num_stack_args++] = args[i];
573 }
574 else
575 {
576 /* The argument will be passed in registers. */
d8de1ef7
MK
577 const gdb_byte *valbuf = value_contents (args[i]);
578 gdb_byte buf[8];
720aa428
MK
579
580 gdb_assert (len <= 16);
581
582 for (j = 0; len > 0; j++, len -= 8)
583 {
584 int regnum = -1;
585 int offset = 0;
586
587 switch (class[j])
588 {
589 case AMD64_INTEGER:
590 regnum = integer_regnum[integer_reg++];
591 break;
592
593 case AMD64_SSE:
594 regnum = sse_regnum[sse_reg++];
595 break;
596
597 case AMD64_SSEUP:
598 gdb_assert (sse_reg > 0);
599 regnum = sse_regnum[sse_reg - 1];
600 offset = 8;
601 break;
602
603 default:
604 gdb_assert (!"Unexpected register class.");
605 }
606
607 gdb_assert (regnum != -1);
608 memset (buf, 0, sizeof buf);
609 memcpy (buf, valbuf + j * 8, min (len, 8));
610 regcache_raw_write_part (regcache, regnum, offset, 8, buf);
611 }
612 }
613 }
614
615 /* Allocate space for the arguments on the stack. */
616 sp -= num_elements * 8;
617
618 /* The psABI says that "The end of the input argument area shall be
619 aligned on a 16 byte boundary." */
620 sp &= ~0xf;
621
622 /* Write out the arguments to the stack. */
623 for (i = 0; i < num_stack_args; i++)
624 {
4991999e 625 struct type *type = value_type (stack_args[i]);
d8de1ef7 626 const gdb_byte *valbuf = value_contents (stack_args[i]);
720aa428
MK
627 int len = TYPE_LENGTH (type);
628
629 write_memory (sp + element * 8, valbuf, len);
630 element += ((len + 7) / 8);
631 }
632
633 /* The psABI says that "For calls that may call functions that use
634 varargs or stdargs (prototype-less calls or calls to functions
635 containing ellipsis (...) in the declaration) %al is used as
636 hidden argument to specify the number of SSE registers used. */
90f90721 637 regcache_raw_write_unsigned (regcache, AMD64_RAX_REGNUM, sse_reg);
720aa428
MK
638 return sp;
639}
640
c4f35dd8 641static CORE_ADDR
7d9b040b 642amd64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
e53bef9f
MK
643 struct regcache *regcache, CORE_ADDR bp_addr,
644 int nargs, struct value **args, CORE_ADDR sp,
645 int struct_return, CORE_ADDR struct_addr)
53e95fcf 646{
d8de1ef7 647 gdb_byte buf[8];
c4f35dd8
MK
648
649 /* Pass arguments. */
6470d250 650 sp = amd64_push_arguments (regcache, nargs, args, sp, struct_return);
c4f35dd8
MK
651
652 /* Pass "hidden" argument". */
653 if (struct_return)
654 {
655 store_unsigned_integer (buf, 8, struct_addr);
90f90721 656 regcache_cooked_write (regcache, AMD64_RDI_REGNUM, buf);
c4f35dd8
MK
657 }
658
659 /* Store return address. */
660 sp -= 8;
10f93086 661 store_unsigned_integer (buf, 8, bp_addr);
c4f35dd8
MK
662 write_memory (sp, buf, 8);
663
664 /* Finally, update the stack pointer... */
665 store_unsigned_integer (buf, 8, sp);
90f90721 666 regcache_cooked_write (regcache, AMD64_RSP_REGNUM, buf);
c4f35dd8
MK
667
668 /* ...and fake a frame pointer. */
90f90721 669 regcache_cooked_write (regcache, AMD64_RBP_REGNUM, buf);
c4f35dd8 670
3e210248 671 return sp + 16;
53e95fcf 672}
c4f35dd8
MK
673\f
674
675/* The maximum number of saved registers. This should include %rip. */
90f90721 676#define AMD64_NUM_SAVED_REGS AMD64_NUM_GREGS
c4f35dd8 677
e53bef9f 678struct amd64_frame_cache
c4f35dd8
MK
679{
680 /* Base address. */
681 CORE_ADDR base;
682 CORE_ADDR sp_offset;
683 CORE_ADDR pc;
684
685 /* Saved registers. */
e53bef9f 686 CORE_ADDR saved_regs[AMD64_NUM_SAVED_REGS];
c4f35dd8
MK
687 CORE_ADDR saved_sp;
688
689 /* Do we have a frame? */
690 int frameless_p;
691};
8dda9770 692
d2449ee8 693/* Initialize a frame cache. */
c4f35dd8 694
d2449ee8
DJ
695static void
696amd64_init_frame_cache (struct amd64_frame_cache *cache)
8dda9770 697{
c4f35dd8
MK
698 int i;
699
c4f35dd8
MK
700 /* Base address. */
701 cache->base = 0;
702 cache->sp_offset = -8;
703 cache->pc = 0;
704
705 /* Saved registers. We initialize these to -1 since zero is a valid
706 offset (that's where %rbp is supposed to be stored). */
e53bef9f 707 for (i = 0; i < AMD64_NUM_SAVED_REGS; i++)
c4f35dd8
MK
708 cache->saved_regs[i] = -1;
709 cache->saved_sp = 0;
710
711 /* Frameless until proven otherwise. */
712 cache->frameless_p = 1;
d2449ee8 713}
c4f35dd8 714
d2449ee8
DJ
715/* Allocate and initialize a frame cache. */
716
717static struct amd64_frame_cache *
718amd64_alloc_frame_cache (void)
719{
720 struct amd64_frame_cache *cache;
721
722 cache = FRAME_OBSTACK_ZALLOC (struct amd64_frame_cache);
723 amd64_init_frame_cache (cache);
c4f35dd8 724 return cache;
8dda9770 725}
53e95fcf 726
c4f35dd8
MK
727/* Do a limited analysis of the prologue at PC and update CACHE
728 accordingly. Bail out early if CURRENT_PC is reached. Return the
729 address where the analysis stopped.
730
731 We will handle only functions beginning with:
732
733 pushq %rbp 0x55
734 movq %rsp, %rbp 0x48 0x89 0xe5
735
736 Any function that doesn't start with this sequence will be assumed
737 to have no prologue and thus no valid frame pointer in %rbp. */
738
739static CORE_ADDR
e53bef9f
MK
740amd64_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
741 struct amd64_frame_cache *cache)
53e95fcf 742{
d8de1ef7
MK
743 static gdb_byte proto[3] = { 0x48, 0x89, 0xe5 }; /* movq %rsp, %rbp */
744 gdb_byte buf[3];
745 gdb_byte op;
c4f35dd8
MK
746
747 if (current_pc <= pc)
748 return current_pc;
749
750 op = read_memory_unsigned_integer (pc, 1);
751
752 if (op == 0x55) /* pushq %rbp */
753 {
754 /* Take into account that we've executed the `pushq %rbp' that
755 starts this instruction sequence. */
90f90721 756 cache->saved_regs[AMD64_RBP_REGNUM] = 0;
c4f35dd8
MK
757 cache->sp_offset += 8;
758
759 /* If that's all, return now. */
760 if (current_pc <= pc + 1)
761 return current_pc;
762
763 /* Check for `movq %rsp, %rbp'. */
764 read_memory (pc + 1, buf, 3);
765 if (memcmp (buf, proto, 3) != 0)
766 return pc + 1;
767
768 /* OK, we actually have a frame. */
769 cache->frameless_p = 0;
770 return pc + 4;
771 }
772
773 return pc;
53e95fcf
JS
774}
775
c4f35dd8
MK
776/* Return PC of first real instruction. */
777
778static CORE_ADDR
e53bef9f 779amd64_skip_prologue (CORE_ADDR start_pc)
53e95fcf 780{
e53bef9f 781 struct amd64_frame_cache cache;
c4f35dd8
MK
782 CORE_ADDR pc;
783
d2449ee8 784 amd64_init_frame_cache (&cache);
594706e6 785 pc = amd64_analyze_prologue (start_pc, 0xffffffffffffffffLL, &cache);
c4f35dd8
MK
786 if (cache.frameless_p)
787 return start_pc;
788
789 return pc;
53e95fcf 790}
c4f35dd8 791\f
53e95fcf 792
c4f35dd8
MK
793/* Normal frames. */
794
e53bef9f
MK
795static struct amd64_frame_cache *
796amd64_frame_cache (struct frame_info *next_frame, void **this_cache)
6d686a84 797{
e53bef9f 798 struct amd64_frame_cache *cache;
d8de1ef7 799 gdb_byte buf[8];
6d686a84 800 int i;
6d686a84 801
c4f35dd8
MK
802 if (*this_cache)
803 return *this_cache;
6d686a84 804
e53bef9f 805 cache = amd64_alloc_frame_cache ();
c4f35dd8
MK
806 *this_cache = cache;
807
93d42b30 808 cache->pc = frame_func_unwind (next_frame, NORMAL_FRAME);
c4f35dd8 809 if (cache->pc != 0)
e53bef9f 810 amd64_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache);
c4f35dd8
MK
811
812 if (cache->frameless_p)
813 {
4a28816e
MK
814 /* We didn't find a valid frame. If we're at the start of a
815 function, or somewhere half-way its prologue, the function's
816 frame probably hasn't been fully setup yet. Try to
817 reconstruct the base address for the stack frame by looking
818 at the stack pointer. For truly "frameless" functions this
819 might work too. */
c4f35dd8 820
90f90721 821 frame_unwind_register (next_frame, AMD64_RSP_REGNUM, buf);
c4f35dd8
MK
822 cache->base = extract_unsigned_integer (buf, 8) + cache->sp_offset;
823 }
35883a3f
MK
824 else
825 {
90f90721 826 frame_unwind_register (next_frame, AMD64_RBP_REGNUM, buf);
35883a3f
MK
827 cache->base = extract_unsigned_integer (buf, 8);
828 }
c4f35dd8
MK
829
830 /* Now that we have the base address for the stack frame we can
831 calculate the value of %rsp in the calling frame. */
832 cache->saved_sp = cache->base + 16;
833
35883a3f
MK
834 /* For normal frames, %rip is stored at 8(%rbp). If we don't have a
835 frame we find it at the same offset from the reconstructed base
836 address. */
90f90721 837 cache->saved_regs[AMD64_RIP_REGNUM] = 8;
35883a3f 838
c4f35dd8
MK
839 /* Adjust all the saved registers such that they contain addresses
840 instead of offsets. */
e53bef9f 841 for (i = 0; i < AMD64_NUM_SAVED_REGS; i++)
c4f35dd8
MK
842 if (cache->saved_regs[i] != -1)
843 cache->saved_regs[i] += cache->base;
844
845 return cache;
6d686a84
ML
846}
847
c4f35dd8 848static void
e53bef9f
MK
849amd64_frame_this_id (struct frame_info *next_frame, void **this_cache,
850 struct frame_id *this_id)
c4f35dd8 851{
e53bef9f
MK
852 struct amd64_frame_cache *cache =
853 amd64_frame_cache (next_frame, this_cache);
c4f35dd8
MK
854
855 /* This marks the outermost frame. */
856 if (cache->base == 0)
857 return;
858
859 (*this_id) = frame_id_build (cache->base + 16, cache->pc);
860}
e76e1718 861
c4f35dd8 862static void
e53bef9f
MK
863amd64_frame_prev_register (struct frame_info *next_frame, void **this_cache,
864 int regnum, int *optimizedp,
865 enum lval_type *lvalp, CORE_ADDR *addrp,
5323dd1d 866 int *realnump, gdb_byte *valuep)
53e95fcf 867{
e53bef9f
MK
868 struct amd64_frame_cache *cache =
869 amd64_frame_cache (next_frame, this_cache);
e76e1718 870
c4f35dd8 871 gdb_assert (regnum >= 0);
b1ab997b 872
c4f35dd8
MK
873 if (regnum == SP_REGNUM && cache->saved_sp)
874 {
875 *optimizedp = 0;
876 *lvalp = not_lval;
877 *addrp = 0;
878 *realnump = -1;
879 if (valuep)
880 {
881 /* Store the value. */
882 store_unsigned_integer (valuep, 8, cache->saved_sp);
883 }
884 return;
885 }
e76e1718 886
e53bef9f 887 if (regnum < AMD64_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1)
c4f35dd8
MK
888 {
889 *optimizedp = 0;
890 *lvalp = lval_memory;
891 *addrp = cache->saved_regs[regnum];
892 *realnump = -1;
893 if (valuep)
894 {
895 /* Read the value in from memory. */
896 read_memory (*addrp, valuep,
897 register_size (current_gdbarch, regnum));
898 }
899 return;
900 }
e76e1718 901
00b25ff3
AC
902 *optimizedp = 0;
903 *lvalp = lval_register;
904 *addrp = 0;
905 *realnump = regnum;
906 if (valuep)
907 frame_unwind_register (next_frame, (*realnump), valuep);
c4f35dd8 908}
e76e1718 909
e53bef9f 910static const struct frame_unwind amd64_frame_unwind =
c4f35dd8
MK
911{
912 NORMAL_FRAME,
e53bef9f
MK
913 amd64_frame_this_id,
914 amd64_frame_prev_register
c4f35dd8 915};
e76e1718 916
c4f35dd8 917static const struct frame_unwind *
e53bef9f 918amd64_frame_sniffer (struct frame_info *next_frame)
c4f35dd8 919{
e53bef9f 920 return &amd64_frame_unwind;
c4f35dd8
MK
921}
922\f
e76e1718 923
c4f35dd8
MK
924/* Signal trampolines. */
925
926/* FIXME: kettenis/20030419: Perhaps, we can unify the 32-bit and
927 64-bit variants. This would require using identical frame caches
928 on both platforms. */
929
e53bef9f
MK
930static struct amd64_frame_cache *
931amd64_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache)
c4f35dd8 932{
e53bef9f 933 struct amd64_frame_cache *cache;
c4f35dd8
MK
934 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
935 CORE_ADDR addr;
d8de1ef7 936 gdb_byte buf[8];
2b5e0749 937 int i;
c4f35dd8
MK
938
939 if (*this_cache)
940 return *this_cache;
941
e53bef9f 942 cache = amd64_alloc_frame_cache ();
c4f35dd8 943
90f90721 944 frame_unwind_register (next_frame, AMD64_RSP_REGNUM, buf);
c4f35dd8
MK
945 cache->base = extract_unsigned_integer (buf, 8) - 8;
946
947 addr = tdep->sigcontext_addr (next_frame);
2b5e0749 948 gdb_assert (tdep->sc_reg_offset);
e53bef9f 949 gdb_assert (tdep->sc_num_regs <= AMD64_NUM_SAVED_REGS);
2b5e0749
MK
950 for (i = 0; i < tdep->sc_num_regs; i++)
951 if (tdep->sc_reg_offset[i] != -1)
952 cache->saved_regs[i] = addr + tdep->sc_reg_offset[i];
c4f35dd8
MK
953
954 *this_cache = cache;
955 return cache;
53e95fcf
JS
956}
957
c4f35dd8 958static void
e53bef9f
MK
959amd64_sigtramp_frame_this_id (struct frame_info *next_frame,
960 void **this_cache, struct frame_id *this_id)
c4f35dd8 961{
e53bef9f
MK
962 struct amd64_frame_cache *cache =
963 amd64_sigtramp_frame_cache (next_frame, this_cache);
c4f35dd8
MK
964
965 (*this_id) = frame_id_build (cache->base + 16, frame_pc_unwind (next_frame));
966}
967
968static void
e53bef9f
MK
969amd64_sigtramp_frame_prev_register (struct frame_info *next_frame,
970 void **this_cache,
971 int regnum, int *optimizedp,
972 enum lval_type *lvalp, CORE_ADDR *addrp,
5323dd1d 973 int *realnump, gdb_byte *valuep)
c4f35dd8
MK
974{
975 /* Make sure we've initialized the cache. */
e53bef9f 976 amd64_sigtramp_frame_cache (next_frame, this_cache);
c4f35dd8 977
e53bef9f
MK
978 amd64_frame_prev_register (next_frame, this_cache, regnum,
979 optimizedp, lvalp, addrp, realnump, valuep);
c4f35dd8
MK
980}
981
e53bef9f 982static const struct frame_unwind amd64_sigtramp_frame_unwind =
c4f35dd8
MK
983{
984 SIGTRAMP_FRAME,
e53bef9f
MK
985 amd64_sigtramp_frame_this_id,
986 amd64_sigtramp_frame_prev_register
c4f35dd8
MK
987};
988
989static const struct frame_unwind *
e53bef9f 990amd64_sigtramp_frame_sniffer (struct frame_info *next_frame)
c4f35dd8 991{
911bc6ee
MK
992 struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (next_frame));
993
994 /* We shouldn't even bother if we don't have a sigcontext_addr
995 handler. */
996 if (tdep->sigcontext_addr == NULL)
997 return NULL;
998
999 if (tdep->sigtramp_p != NULL)
1000 {
1001 if (tdep->sigtramp_p (next_frame))
1002 return &amd64_sigtramp_frame_unwind;
1003 }
c4f35dd8 1004
911bc6ee 1005 if (tdep->sigtramp_start != 0)
1c3545ae 1006 {
911bc6ee 1007 CORE_ADDR pc = frame_pc_unwind (next_frame);
1c3545ae 1008
911bc6ee
MK
1009 gdb_assert (tdep->sigtramp_end != 0);
1010 if (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end)
1011 return &amd64_sigtramp_frame_unwind;
1c3545ae 1012 }
c4f35dd8
MK
1013
1014 return NULL;
1015}
1016\f
1017
1018static CORE_ADDR
e53bef9f 1019amd64_frame_base_address (struct frame_info *next_frame, void **this_cache)
c4f35dd8 1020{
e53bef9f
MK
1021 struct amd64_frame_cache *cache =
1022 amd64_frame_cache (next_frame, this_cache);
c4f35dd8
MK
1023
1024 return cache->base;
1025}
1026
e53bef9f 1027static const struct frame_base amd64_frame_base =
c4f35dd8 1028{
e53bef9f
MK
1029 &amd64_frame_unwind,
1030 amd64_frame_base_address,
1031 amd64_frame_base_address,
1032 amd64_frame_base_address
c4f35dd8
MK
1033};
1034
166f4c7b 1035static struct frame_id
e53bef9f 1036amd64_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
166f4c7b 1037{
d8de1ef7 1038 gdb_byte buf[8];
c4f35dd8
MK
1039 CORE_ADDR fp;
1040
90f90721 1041 frame_unwind_register (next_frame, AMD64_RBP_REGNUM, buf);
c4f35dd8
MK
1042 fp = extract_unsigned_integer (buf, 8);
1043
1044 return frame_id_build (fp + 16, frame_pc_unwind (next_frame));
166f4c7b
ML
1045}
1046
8b148df9
AC
1047/* 16 byte align the SP per frame requirements. */
1048
1049static CORE_ADDR
e53bef9f 1050amd64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
8b148df9
AC
1051{
1052 return sp & -(CORE_ADDR)16;
1053}
473f17b0
MK
1054\f
1055
593adc23
MK
1056/* Supply register REGNUM from the buffer specified by FPREGS and LEN
1057 in the floating-point register set REGSET to register cache
1058 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
473f17b0
MK
1059
1060static void
e53bef9f
MK
1061amd64_supply_fpregset (const struct regset *regset, struct regcache *regcache,
1062 int regnum, const void *fpregs, size_t len)
473f17b0 1063{
9ea75c57 1064 const struct gdbarch_tdep *tdep = gdbarch_tdep (regset->arch);
473f17b0
MK
1065
1066 gdb_assert (len == tdep->sizeof_fpregset);
90f90721 1067 amd64_supply_fxsave (regcache, regnum, fpregs);
473f17b0 1068}
8b148df9 1069
593adc23
MK
1070/* Collect register REGNUM from the register cache REGCACHE and store
1071 it in the buffer specified by FPREGS and LEN as described by the
1072 floating-point register set REGSET. If REGNUM is -1, do this for
1073 all registers in REGSET. */
1074
1075static void
1076amd64_collect_fpregset (const struct regset *regset,
1077 const struct regcache *regcache,
1078 int regnum, void *fpregs, size_t len)
1079{
1080 const struct gdbarch_tdep *tdep = gdbarch_tdep (regset->arch);
1081
1082 gdb_assert (len == tdep->sizeof_fpregset);
1083 amd64_collect_fxsave (regcache, regnum, fpregs);
1084}
1085
c6b33596
MK
1086/* Return the appropriate register set for the core section identified
1087 by SECT_NAME and SECT_SIZE. */
1088
1089static const struct regset *
e53bef9f
MK
1090amd64_regset_from_core_section (struct gdbarch *gdbarch,
1091 const char *sect_name, size_t sect_size)
c6b33596
MK
1092{
1093 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1094
1095 if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
1096 {
1097 if (tdep->fpregset == NULL)
593adc23
MK
1098 tdep->fpregset = regset_alloc (gdbarch, amd64_supply_fpregset,
1099 amd64_collect_fpregset);
c6b33596
MK
1100
1101 return tdep->fpregset;
1102 }
1103
1104 return i386_regset_from_core_section (gdbarch, sect_name, sect_size);
1105}
1106\f
1107
2213a65d 1108void
90f90721 1109amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
53e95fcf 1110{
0c1a73d6 1111 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
53e95fcf 1112
473f17b0
MK
1113 /* AMD64 generally uses `fxsave' instead of `fsave' for saving its
1114 floating-point registers. */
1115 tdep->sizeof_fpregset = I387_SIZEOF_FXSAVE;
1116
5716833c 1117 /* AMD64 has an FPU and 16 SSE registers. */
90f90721 1118 tdep->st0_regnum = AMD64_ST0_REGNUM;
0c1a73d6 1119 tdep->num_xmm_regs = 16;
53e95fcf 1120
0c1a73d6 1121 /* This is what all the fuss is about. */
53e95fcf
JS
1122 set_gdbarch_long_bit (gdbarch, 64);
1123 set_gdbarch_long_long_bit (gdbarch, 64);
1124 set_gdbarch_ptr_bit (gdbarch, 64);
1125
e53bef9f
MK
1126 /* In contrast to the i386, on AMD64 a `long double' actually takes
1127 up 128 bits, even though it's still based on the i387 extended
1128 floating-point format which has only 80 significant bits. */
b83b026c
MK
1129 set_gdbarch_long_double_bit (gdbarch, 128);
1130
e53bef9f
MK
1131 set_gdbarch_num_regs (gdbarch, AMD64_NUM_REGS);
1132 set_gdbarch_register_name (gdbarch, amd64_register_name);
1133 set_gdbarch_register_type (gdbarch, amd64_register_type);
b83b026c
MK
1134
1135 /* Register numbers of various important registers. */
90f90721
MK
1136 set_gdbarch_sp_regnum (gdbarch, AMD64_RSP_REGNUM); /* %rsp */
1137 set_gdbarch_pc_regnum (gdbarch, AMD64_RIP_REGNUM); /* %rip */
1138 set_gdbarch_ps_regnum (gdbarch, AMD64_EFLAGS_REGNUM); /* %eflags */
1139 set_gdbarch_fp0_regnum (gdbarch, AMD64_ST0_REGNUM); /* %st(0) */
b83b026c 1140
e53bef9f
MK
1141 /* The "default" register numbering scheme for AMD64 is referred to
1142 as the "DWARF Register Number Mapping" in the System V psABI.
1143 The preferred debugging format for all known AMD64 targets is
1144 actually DWARF2, and GCC doesn't seem to support DWARF (that is
1145 DWARF-1), but we provide the same mapping just in case. This
1146 mapping is also used for stabs, which GCC does support. */
1147 set_gdbarch_stab_reg_to_regnum (gdbarch, amd64_dwarf_reg_to_regnum);
1148 set_gdbarch_dwarf_reg_to_regnum (gdbarch, amd64_dwarf_reg_to_regnum);
1149 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, amd64_dwarf_reg_to_regnum);
de220d0f 1150
c4f35dd8 1151 /* We don't override SDB_REG_RO_REGNUM, since COFF doesn't seem to
e53bef9f 1152 be in use on any of the supported AMD64 targets. */
53e95fcf 1153
c4f35dd8 1154 /* Call dummy code. */
e53bef9f
MK
1155 set_gdbarch_push_dummy_call (gdbarch, amd64_push_dummy_call);
1156 set_gdbarch_frame_align (gdbarch, amd64_frame_align);
8b148df9 1157 set_gdbarch_frame_red_zone_size (gdbarch, 128);
53e95fcf 1158
e53bef9f 1159 set_gdbarch_convert_register_p (gdbarch, amd64_convert_register_p);
d532c08f
MK
1160 set_gdbarch_register_to_value (gdbarch, i387_register_to_value);
1161 set_gdbarch_value_to_register (gdbarch, i387_value_to_register);
1162
efb1c01c 1163 set_gdbarch_return_value (gdbarch, amd64_return_value);
53e95fcf 1164
e53bef9f 1165 set_gdbarch_skip_prologue (gdbarch, amd64_skip_prologue);
53e95fcf 1166
c4f35dd8 1167 /* Avoid wiring in the MMX registers for now. */
2213a65d 1168 set_gdbarch_num_pseudo_regs (gdbarch, 0);
5716833c 1169 tdep->mm0_regnum = -1;
2213a65d 1170
e53bef9f 1171 set_gdbarch_unwind_dummy_id (gdbarch, amd64_unwind_dummy_id);
53e95fcf 1172
e53bef9f
MK
1173 frame_unwind_append_sniffer (gdbarch, amd64_sigtramp_frame_sniffer);
1174 frame_unwind_append_sniffer (gdbarch, amd64_frame_sniffer);
1175 frame_base_set_default (gdbarch, &amd64_frame_base);
c6b33596
MK
1176
1177 /* If we have a register mapping, enable the generic core file support. */
1178 if (tdep->gregset_reg_offset)
1179 set_gdbarch_regset_from_core_section (gdbarch,
e53bef9f 1180 amd64_regset_from_core_section);
c4f35dd8
MK
1181}
1182\f
1183
90f90721 1184#define I387_ST0_REGNUM AMD64_ST0_REGNUM
c4f35dd8 1185
41d041d6
MK
1186/* The 64-bit FXSAVE format differs from the 32-bit format in the
1187 sense that the instruction pointer and data pointer are simply
1188 64-bit offsets into the code segment and the data segment instead
1189 of a selector offset pair. The functions below store the upper 32
1190 bits of these pointers (instead of just the 16-bits of the segment
1191 selector). */
1192
1193/* Fill register REGNUM in REGCACHE with the appropriate
0485f6ad
MK
1194 floating-point or SSE register value from *FXSAVE. If REGNUM is
1195 -1, do this for all registers. This function masks off any of the
1196 reserved bits in *FXSAVE. */
c4f35dd8
MK
1197
1198void
90f90721 1199amd64_supply_fxsave (struct regcache *regcache, int regnum,
41d041d6 1200 const void *fxsave)
c4f35dd8 1201{
41d041d6 1202 i387_supply_fxsave (regcache, regnum, fxsave);
c4f35dd8 1203
f0ef85a5 1204 if (fxsave && gdbarch_ptr_bit (get_regcache_arch (regcache)) == 64)
c4f35dd8 1205 {
d8de1ef7 1206 const gdb_byte *regs = fxsave;
41d041d6 1207
0485f6ad 1208 if (regnum == -1 || regnum == I387_FISEG_REGNUM)
41d041d6 1209 regcache_raw_supply (regcache, I387_FISEG_REGNUM, regs + 12);
0485f6ad 1210 if (regnum == -1 || regnum == I387_FOSEG_REGNUM)
41d041d6 1211 regcache_raw_supply (regcache, I387_FOSEG_REGNUM, regs + 20);
c4f35dd8 1212 }
0c1a73d6
MK
1213}
1214
3c017e40
MK
1215/* Fill register REGNUM (if it is a floating-point or SSE register) in
1216 *FXSAVE with the value from REGCACHE. If REGNUM is -1, do this for
1217 all registers. This function doesn't touch any of the reserved
1218 bits in *FXSAVE. */
1219
1220void
1221amd64_collect_fxsave (const struct regcache *regcache, int regnum,
1222 void *fxsave)
1223{
d8de1ef7 1224 gdb_byte *regs = fxsave;
3c017e40
MK
1225
1226 i387_collect_fxsave (regcache, regnum, fxsave);
1227
f0ef85a5
MK
1228 if (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 64)
1229 {
1230 if (regnum == -1 || regnum == I387_FISEG_REGNUM)
1231 regcache_raw_collect (regcache, I387_FISEG_REGNUM, regs + 12);
1232 if (regnum == -1 || regnum == I387_FOSEG_REGNUM)
1233 regcache_raw_collect (regcache, I387_FOSEG_REGNUM, regs + 20);
1234 }
3c017e40 1235}
This page took 0.525853 seconds and 4 git commands to generate.