1 /* Target-dependent code for the x86-64 for GDB, the GNU debugger.
3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 Contributed by Jiri Smid, SuSE Labs.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "arch-utils.h"
31 #include "x86-64-tdep.h"
32 #include "dwarf2cfi.h"
33 #include "gdb_assert.h"
36 /* Register numbers of various important registers. */
40 #define EFLAGS_REGNUM 17
41 #define XMM1_REGNUM 35
43 /* x86_64_register_raw_size_table[i] is the number of bytes of storage in
44 GDB's register array occupied by register i. */
45 int x86_64_register_raw_size_table
[X86_64_NUM_REGS
] = {
62 /* Number of bytes of storage in the actual machine representation for
65 x86_64_register_raw_size (int regno
)
67 return x86_64_register_raw_size_table
[regno
];
70 /* x86_64_register_byte_table[i] is the offset into the register file of the
71 start of register number i. We initialize this from
72 x86_64_register_raw_size_table. */
73 int x86_64_register_byte_table
[X86_64_NUM_REGS
];
75 /* Index within `registers' of the first byte of the space for register REGNO. */
77 x86_64_register_byte (int regno
)
79 return x86_64_register_byte_table
[regno
];
82 /* Return the GDB type object for the "standard" data type of data in
85 x86_64_register_virtual_type (int regno
)
87 if (regno
== PC_REGNUM
|| regno
== SP_REGNUM
)
88 return builtin_type_void_func_ptr
;
89 if (IS_FP_REGNUM (regno
))
90 return builtin_type_i387_ext
;
91 if (IS_SSE_REGNUM (regno
))
92 return builtin_type_v4sf
;
93 if (IS_FPU_CTRL_REGNUM (regno
) || regno
== MXCSR_REGNUM
94 || regno
== EFLAGS_REGNUM
)
95 return builtin_type_int32
;
96 return builtin_type_int64
;
99 /* x86_64_register_convertible is true if register N's virtual format is
100 different from its raw format. Note that this definition assumes
101 that the host supports IEEE 32-bit floats, since it doesn't say
102 that SSE registers need conversion. Even if we can't find a
103 counterexample, this is still sloppy. */
105 x86_64_register_convertible (int regno
)
107 return IS_FP_REGNUM (regno
);
110 /* Convert data from raw format for register REGNUM in buffer FROM to
111 virtual format with type TYPE in buffer TO. In principle both
112 formats are identical except that the virtual format has two extra
113 bytes appended that aren't used. We set these to zero. */
115 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
116 char *from
, char *to
)
120 /* We only support floating-point values. */
121 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
123 warning ("Cannot convert floating-point register value "
124 "to non-floating-point type.");
125 memset (to
, 0, TYPE_LENGTH (type
));
128 /* First add the necessary padding. */
129 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
130 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
131 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
132 to the extended floating-point format used by the FPU. */
133 convert_typed_floating (to
, type
, buf
,
134 x86_64_register_virtual_type (regnum
));
137 /* Convert data from virtual format with type TYPE in buffer FROM to
138 raw format for register REGNUM in buffer TO. Simply omit the two
142 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
143 char *from
, char *to
)
145 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 12);
146 /* Simply omit the two unused bytes. */
147 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
150 /* This is the variable that is set with "set disassembly-flavour", and
151 its legitimate values. */
152 static const char att_flavour
[] = "att";
153 static const char intel_flavour
[] = "intel";
154 static const char *valid_flavours
[] = {
159 static const char *disassembly_flavour
= att_flavour
;
162 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
166 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
168 write_memory (sp
- 8, buf
, 8);
173 x86_64_pop_frame (void)
175 generic_pop_current_frame (cfi_pop_frame
);
179 /* The returning of values is done according to the special algorithm.
180 Some types are returned in registers an some (big structures) in memory.
184 #define MAX_CLASSES 4
186 enum x86_64_reg_class
189 X86_64_INTEGER_CLASS
,
190 X86_64_INTEGERSI_CLASS
,
200 /* Return the union class of CLASS1 and CLASS2.
201 See the x86-64 ABI for details. */
203 static enum x86_64_reg_class
204 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
206 /* Rule #1: If both classes are equal, this is the resulting class. */
207 if (class1
== class2
)
210 /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
212 if (class1
== X86_64_NO_CLASS
)
214 if (class2
== X86_64_NO_CLASS
)
217 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
218 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
219 return X86_64_MEMORY_CLASS
;
221 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
222 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
223 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
224 return X86_64_INTEGERSI_CLASS
;
225 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
226 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
227 return X86_64_INTEGER_CLASS
;
229 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
230 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
231 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
232 return X86_64_MEMORY_CLASS
;
234 /* Rule #6: Otherwise class SSE is used. */
235 return X86_64_SSE_CLASS
;
239 /* Classify the argument type.
240 CLASSES will be filled by the register class used to pass each word
241 of the operand. The number of words is returned. In case the parameter
242 should be passed in memory, 0 is returned. As a special case for zero
243 sized containers, classes[0] will be NO_CLASS and 1 is returned.
245 See the x86-64 PS ABI for details.
249 classify_argument (struct type
*type
,
250 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
252 int bytes
= TYPE_LENGTH (type
);
253 int words
= (bytes
+ 8 - 1) / 8;
255 switch (TYPE_CODE (type
))
257 case TYPE_CODE_ARRAY
:
258 case TYPE_CODE_STRUCT
:
259 case TYPE_CODE_UNION
:
262 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
264 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
268 for (i
= 0; i
< words
; i
++)
269 classes
[i
] = X86_64_NO_CLASS
;
271 /* Zero sized arrays or structures are NO_CLASS. We return 0 to
272 signalize memory class, so handle it as special case. */
275 classes
[0] = X86_64_NO_CLASS
;
278 switch (TYPE_CODE (type
))
280 case TYPE_CODE_STRUCT
:
283 for (j
= 0; j
< type
->nfields
; ++j
)
285 int num
= classify_argument (type
->fields
[j
].type
,
287 (type
->fields
[j
].loc
.bitpos
288 + bit_offset
) % 256);
291 for (i
= 0; i
< num
; i
++)
294 (type
->fields
[j
].loc
.bitpos
+ bit_offset
) / 8 / 8;
296 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
301 case TYPE_CODE_ARRAY
:
305 num
= classify_argument (type
->target_type
,
306 subclasses
, bit_offset
);
310 /* The partial classes are now full classes. */
311 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
312 subclasses
[0] = X86_64_SSE_CLASS
;
313 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
314 subclasses
[0] = X86_64_INTEGER_CLASS
;
316 for (i
= 0; i
< words
; i
++)
317 classes
[i
] = subclasses
[i
% num
];
320 case TYPE_CODE_UNION
:
324 for (j
= 0; j
< type
->nfields
; ++j
)
327 num
= classify_argument (type
->fields
[j
].type
,
328 subclasses
, bit_offset
);
331 for (i
= 0; i
< num
; i
++)
332 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
338 /* Final merger cleanup. */
339 for (i
= 0; i
< words
; i
++)
341 /* If one class is MEMORY, everything should be passed in
343 if (classes
[i
] == X86_64_MEMORY_CLASS
)
346 /* The X86_64_SSEUP_CLASS should be always preceeded by
348 if (classes
[i
] == X86_64_SSEUP_CLASS
349 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
350 classes
[i
] = X86_64_SSE_CLASS
;
352 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
353 if (classes
[i
] == X86_64_X87UP_CLASS
354 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
355 classes
[i
] = X86_64_SSE_CLASS
;
364 if (!(bit_offset
% 64))
365 classes
[0] = X86_64_SSESF_CLASS
;
367 classes
[0] = X86_64_SSE_CLASS
;
370 classes
[0] = X86_64_SSEDF_CLASS
;
373 classes
[0] = X86_64_X87_CLASS
;
374 classes
[1] = X86_64_X87UP_CLASS
;
386 if (bytes
* 8 + bit_offset
<= 32)
387 classes
[0] = X86_64_INTEGERSI_CLASS
;
389 classes
[0] = X86_64_INTEGER_CLASS
;
392 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
400 internal_error (__FILE__
, __LINE__
,
401 "classify_argument: unknown argument type");
404 /* Examine the argument and return set number of register required in each
405 class. Return 0 ifif parameter should be passed in memory. */
408 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
409 int n
, int *int_nregs
, int *sse_nregs
)
415 for (n
--; n
>= 0; n
--)
418 case X86_64_INTEGER_CLASS
:
419 case X86_64_INTEGERSI_CLASS
:
422 case X86_64_SSE_CLASS
:
423 case X86_64_SSESF_CLASS
:
424 case X86_64_SSEDF_CLASS
:
427 case X86_64_NO_CLASS
:
428 case X86_64_SSEUP_CLASS
:
429 case X86_64_X87_CLASS
:
430 case X86_64_X87UP_CLASS
:
432 case X86_64_MEMORY_CLASS
:
433 internal_error (__FILE__
, __LINE__
,
434 "examine_argument: unexpected memory class");
439 #define RET_INT_REGS 2
440 #define RET_SSE_REGS 2
442 /* Check if the structure in value_type is returned in registers or in
443 memory. If this function returns 1, gdb will call STORE_STRUCT_RETURN and
444 EXTRACT_STRUCT_VALUE_ADDRESS else STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE
447 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
449 enum x86_64_reg_class
class[MAX_CLASSES
];
450 int n
= classify_argument (value_type
, class, 0);
455 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
456 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
460 /* Extract from an array REGBUF containing the (raw) register state, a
461 function return value of TYPE, and copy that, in virtual format,
465 x86_64_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
467 enum x86_64_reg_class
class[MAX_CLASSES
];
468 int n
= classify_argument (type
, class, 0);
474 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
475 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
478 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
479 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
482 memcpy (&addr
, regbuf
, REGISTER_RAW_SIZE (RAX_REGNUM
));
483 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
489 for (i
= 0; i
< n
; i
++)
493 case X86_64_NO_CLASS
:
495 case X86_64_INTEGER_CLASS
:
496 memcpy (valbuf
+ offset
,
497 regbuf
+ REGISTER_BYTE (ret_int_r
[(intreg
+ 1) / 2]),
502 case X86_64_INTEGERSI_CLASS
:
503 memcpy (valbuf
+ offset
,
504 regbuf
+ REGISTER_BYTE (ret_int_r
[intreg
/ 2]), 4);
508 case X86_64_SSEDF_CLASS
:
509 case X86_64_SSESF_CLASS
:
510 case X86_64_SSE_CLASS
:
511 memcpy (valbuf
+ offset
,
512 regbuf
+ REGISTER_BYTE (ret_sse_r
[(ssereg
+ 1) / 2]),
517 case X86_64_SSEUP_CLASS
:
518 memcpy (valbuf
+ offset
+ 8,
519 regbuf
+ REGISTER_BYTE (ret_sse_r
[ssereg
/ 2]), 8);
523 case X86_64_X87_CLASS
:
524 memcpy (valbuf
+ offset
, regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
528 case X86_64_X87UP_CLASS
:
529 memcpy (valbuf
+ offset
,
530 regbuf
+ REGISTER_BYTE (FP0_REGNUM
) + 8, 8);
533 case X86_64_MEMORY_CLASS
:
535 internal_error (__FILE__
, __LINE__
,
536 "Unexpected argument class");
542 /* Handled by unwind informations. */
544 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
552 x86_64_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
553 int struct_return
, CORE_ADDR struct_addr
)
558 static int int_parameter_registers
[INT_REGS
] = {
559 5 /*RDI*/, 4 /*RSI*/,
560 1 /*RDX*/, 2 /*RCX*/,
561 8 /*R8 */ , 9 /*R9 */
564 static int sse_parameter_registers
[SSE_REGS
] = {
570 int stack_values_count
= 0;
572 stack_values
= alloca (naregs
* sizeof (int));
573 for (i
= 0; i
< nargs
; i
++)
575 enum x86_64_reg_class
class[MAX_CLASSES
];
576 int n
= classify_argument (args
[i
]->type
, class, 0);
581 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
582 || intreg
/ 2 + needed_intregs
> INT_REGS
583 || ssereg
/ 2 + needed_sseregs
> SSE_REGS
)
585 stack_values
[stack_values_count
++] = i
;
590 for (j
= 0; j
< n
; j
++)
595 case X86_64_NO_CLASS
:
597 case X86_64_INTEGER_CLASS
:
598 write_register_gen (int_parameter_registers
600 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
604 case X86_64_INTEGERSI_CLASS
:
605 write_register_gen (int_parameter_registers
[intreg
/ 2],
606 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
610 case X86_64_SSEDF_CLASS
:
611 case X86_64_SSESF_CLASS
:
612 case X86_64_SSE_CLASS
:
613 write_register_gen (sse_parameter_registers
615 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
619 case X86_64_SSEUP_CLASS
:
620 write_register_gen (sse_parameter_registers
[ssereg
/ 2],
621 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
625 case X86_64_X87_CLASS
:
626 case X86_64_MEMORY_CLASS
:
627 stack_values
[stack_values_count
++] = i
;
629 case X86_64_X87UP_CLASS
:
632 internal_error (__FILE__
, __LINE__
,
633 "Unexpected argument class");
635 intreg
+= intreg
% 2;
636 ssereg
+= ssereg
% 2;
640 while (--stack_values_count
>= 0)
642 value_ptr arg
= args
[stack_values
[stack_values_count
]];
643 int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
647 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
652 /* Write into the appropriate registers a function return value stored
653 in VALBUF of type TYPE, given in virtual format. */
655 x86_64_store_return_value (struct type
*type
, char *valbuf
)
657 int len
= TYPE_LENGTH (type
);
659 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
661 /* Floating-point return values can be found in %st(0). */
662 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
663 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
665 /* Copy straight over. */
666 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
671 char buf
[FPU_REG_RAW_SIZE
];
674 /* Convert the value found in VALBUF to the extended
675 floating point format used by the FPU. This is probably
676 not exactly how it would happen on the target itself, but
677 it is the best we can do. */
678 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
679 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
680 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
686 int low_size
= REGISTER_RAW_SIZE (0);
687 int high_size
= REGISTER_RAW_SIZE (1);
690 write_register_bytes (REGISTER_BYTE (0), valbuf
, len
);
691 else if (len
<= (low_size
+ high_size
))
693 write_register_bytes (REGISTER_BYTE (0), valbuf
, low_size
);
694 write_register_bytes (REGISTER_BYTE (1),
695 valbuf
+ low_size
, len
- low_size
);
698 internal_error (__FILE__
, __LINE__
,
699 "Cannot store return value of %d bytes long.", len
);
705 x86_64_register_name (int reg_nr
)
707 static char *register_names
[] = {
708 "rax", "rdx", "rcx", "rbx",
709 "rsi", "rdi", "rbp", "rsp",
710 "r8", "r9", "r10", "r11",
711 "r12", "r13", "r14", "r15",
713 "st0", "st1", "st2", "st3",
714 "st4", "st5", "st6", "st7",
715 "fctrl", "fstat", "ftag", "fiseg",
716 "fioff", "foseg", "fooff", "fop",
717 "xmm0", "xmm1", "xmm2", "xmm3",
718 "xmm4", "xmm5", "xmm6", "xmm7",
719 "xmm8", "xmm9", "xmm10", "xmm11",
720 "xmm12", "xmm13", "xmm14", "xmm15",
725 if (reg_nr
>= (sizeof (register_names
) / sizeof (*register_names
)))
727 return register_names
[reg_nr
];
732 /* We have two flavours of disassembly. The machinery on this page
733 deals with switching between those. */
736 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
738 if (disassembly_flavour
== att_flavour
)
739 return print_insn_i386_att (memaddr
, info
);
740 else if (disassembly_flavour
== intel_flavour
)
741 return print_insn_i386_intel (memaddr
, info
);
742 /* Never reached -- disassembly_flavour is always either att_flavour
744 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
748 /* Store the address of the place in which to copy the structure the
749 subroutine will return. This is called from call_function. */
751 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
753 write_register (RDI_REGNUM
, addr
);
757 x86_64_frameless_function_invocation (struct frame_info
*frame
)
762 /* On x86_64 there are no reasonable prologs. */
764 x86_64_skip_prologue (CORE_ADDR pc
)
769 /* Sequence of bytes for breakpoint instruction. */
770 static unsigned char *
771 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
773 static unsigned char breakpoint
[] = { 0xcc };
778 static struct gdbarch
*
779 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
781 struct gdbarch
*gdbarch
;
782 struct gdbarch_tdep
*tdep
;
784 /* Find a candidate among the list of pre-declared architectures. */
785 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
787 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
789 switch (info
.bfd_arch_info
->mach
)
791 case bfd_mach_x86_64
:
792 case bfd_mach_x86_64_intel_syntax
:
793 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
795 case bfd_mach_x86_64
:
796 case bfd_mach_x86_64_intel_syntax
:
797 return arches
->gdbarch
;
798 case bfd_mach_i386_i386
:
799 case bfd_mach_i386_i8086
:
800 case bfd_mach_i386_i386_intel_syntax
:
803 internal_error (__FILE__
, __LINE__
,
804 "i386_gdbarch_init: unknown machine type");
807 case bfd_mach_i386_i386
:
808 case bfd_mach_i386_i8086
:
809 case bfd_mach_i386_i386_intel_syntax
:
810 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
812 case bfd_mach_x86_64
:
813 case bfd_mach_x86_64_intel_syntax
:
815 case bfd_mach_i386_i386
:
816 case bfd_mach_i386_i8086
:
817 case bfd_mach_i386_i386_intel_syntax
:
818 return arches
->gdbarch
;
820 internal_error (__FILE__
, __LINE__
,
821 "i386_gdbarch_init: unknown machine type");
825 internal_error (__FILE__
, __LINE__
,
826 "i386_gdbarch_init: unknown machine type");
830 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
831 gdbarch
= gdbarch_alloc (&info
, tdep
);
833 switch (info
.bfd_arch_info
->mach
)
835 case bfd_mach_x86_64
:
836 case bfd_mach_x86_64_intel_syntax
:
837 tdep
->num_xmm_regs
= 16;
839 case bfd_mach_i386_i386
:
840 case bfd_mach_i386_i8086
:
841 case bfd_mach_i386_i386_intel_syntax
:
842 /* This is place for definition of i386 target vector. */
845 internal_error (__FILE__
, __LINE__
,
846 "i386_gdbarch_init: unknown machine type");
849 set_gdbarch_long_bit (gdbarch
, 64);
850 set_gdbarch_long_long_bit (gdbarch
, 64);
851 set_gdbarch_ptr_bit (gdbarch
, 64);
853 set_gdbarch_long_double_format (gdbarch
, &floatformat_i387_ext
);
855 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
856 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
857 set_gdbarch_register_size (gdbarch
, 8);
858 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
859 set_gdbarch_max_register_raw_size (gdbarch
, 16);
860 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
861 /* Total amount of space needed to store our copies of the machine's register
862 (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS + SIZEOF_SSE_REGS) */
863 set_gdbarch_register_bytes (gdbarch
,
864 (18 * 8) + (8 * 10) + (8 * 4) + (16 * 16 + 4));
865 set_gdbarch_register_virtual_size (gdbarch
, generic_register_virtual_size
);
866 set_gdbarch_max_register_virtual_size (gdbarch
, 16);
868 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
870 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
871 set_gdbarch_register_convert_to_virtual (gdbarch
,
872 x86_64_register_convert_to_virtual
);
873 set_gdbarch_register_convert_to_raw (gdbarch
,
874 x86_64_register_convert_to_raw
);
876 /* Register numbers of various important registers. */
877 set_gdbarch_sp_regnum (gdbarch
, 7); /* (rsp) Contains address of top of stack. */
878 set_gdbarch_fp_regnum (gdbarch
, 6); /* (rbp) */
879 set_gdbarch_pc_regnum (gdbarch
, 16); /* (rip) Contains program counter. */
881 set_gdbarch_fp0_regnum (gdbarch
, 18); /* First FPU floating-point register. */
883 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
884 set_gdbarch_write_fp (gdbarch
, cfi_write_fp
);
886 /* Discard from the stack the innermost frame, restoring all registers. */
887 set_gdbarch_pop_frame (gdbarch
, x86_64_pop_frame
);
889 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
891 set_gdbarch_frame_chain (gdbarch
, cfi_frame_chain
);
893 set_gdbarch_frameless_function_invocation (gdbarch
,
894 x86_64_frameless_function_invocation
);
895 set_gdbarch_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
897 set_gdbarch_frame_args_address (gdbarch
, default_frame_address
);
898 set_gdbarch_frame_locals_address (gdbarch
, default_frame_address
);
900 /* Return number of bytes at start of arglist that are not really args. */
901 set_gdbarch_frame_args_skip (gdbarch
, 8);
903 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
905 /* Frame pc initialization is handled by unwind informations. */
906 set_gdbarch_init_frame_pc (gdbarch
, cfi_init_frame_pc
);
908 /* Initialization of unwind informations. */
909 set_gdbarch_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
911 /* Getting saved registers is handled by unwind informations. */
912 set_gdbarch_get_saved_register (gdbarch
, cfi_get_saved_register
);
914 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
916 /* Cons up virtual frame pointer for trace */
917 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
920 set_gdbarch_frame_chain_valid (gdbarch
, generic_file_frame_chain_valid
);
922 set_gdbarch_use_generic_dummy_frames (gdbarch
, 1);
923 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
924 set_gdbarch_call_dummy_address (gdbarch
, entry_point_address
);
925 set_gdbarch_call_dummy_length (gdbarch
, 0);
926 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
927 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
928 set_gdbarch_pc_in_call_dummy (gdbarch
, pc_in_call_dummy_at_entry_point
);
929 set_gdbarch_call_dummy_words (gdbarch
, 0);
930 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
931 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
932 set_gdbarch_call_dummy_p (gdbarch
, 1);
933 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
934 set_gdbarch_push_dummy_frame (gdbarch
, generic_push_dummy_frame
);
935 set_gdbarch_fix_call_dummy (gdbarch
, generic_fix_call_dummy
);
936 set_gdbarch_push_return_address (gdbarch
, x86_64_push_return_address
);
937 set_gdbarch_push_arguments (gdbarch
, x86_64_push_arguments
);
939 /* Return number of args passed to a frame, no way to tell. */
940 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
941 /* Don't use default structure extract routine */
942 set_gdbarch_extract_struct_value_address (gdbarch
, 0);
944 /* If USE_STRUCT_CONVENTION retruns 0, then gdb uses STORE_RETURN_VALUE
945 and EXTRACT_RETURN_VALUE to store/fetch the functions return value. It is
946 the case when structure is returned in registers. */
947 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
949 /* Store the address of the place in which to copy the structure the
950 subroutine will return. This is called from call_function. */
951 set_gdbarch_store_struct_return (gdbarch
, x86_64_store_struct_return
);
953 /* Extract from an array REGBUF containing the (raw) register state
954 a function return value of type TYPE, and copy that, in virtual format,
956 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
959 /* Write into the appropriate registers a function return value stored
960 in VALBUF of type TYPE, given in virtual format. */
961 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
964 /* Offset from address of function to start of its code. */
965 set_gdbarch_function_start_offset (gdbarch
, 0);
967 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
969 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
971 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
973 set_gdbarch_breakpoint_from_pc (gdbarch
, x86_64_breakpoint_from_pc
);
976 /* Amount PC must be decremented by after a breakpoint. This is often the
977 number of bytes in BREAKPOINT but not always. */
978 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
980 /* Use dwarf2 debug frame informations. */
981 set_gdbarch_dwarf2_build_frame_info (gdbarch
, dwarf2_build_frame_info
);
986 _initialize_x86_64_tdep (void)
988 register_gdbarch_init (bfd_arch_i386
, i386_gdbarch_init
);
990 /* Initialize the table saying where each register starts in the
996 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
998 x86_64_register_byte_table
[i
] = offset
;
999 offset
+= x86_64_register_raw_size_table
[i
];
1003 tm_print_insn
= gdb_print_insn_x86_64
;
1004 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 3)->mach
;
1006 /* Add the variable that controls the disassembly flavour. */
1008 struct cmd_list_element
*new_cmd
;
1010 new_cmd
= add_set_enum_cmd ("disassembly-flavour", no_class
,
1011 valid_flavours
, &disassembly_flavour
, "\
1012 Set the disassembly flavour, the valid values are \"att\" and \"intel\", \
1013 and the default value is \"att\".", &setlist
);
1014 add_show_from_set (new_cmd
, &showlist
);