1 /* Target-dependent code for the x86-64 for GDB, the GNU debugger.
3 Free Software Foundation, Inc.
4 Contributed by Jiri Smid, SuSE Labs.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "arch-utils.h"
30 #include "x86-64-tdep.h"
31 #include "dwarf2cfi.h"
35 /* Register numbers of various important registers. */
39 #define EFLAGS_REGNUM 17
40 #define XMM1_REGNUM 35
42 /* x86_64_register_raw_size_table[i] is the number of bytes of storage in
43 GDB's register array occupied by register i. */
44 int x86_64_register_raw_size_table
[X86_64_NUM_REGS
] = {
61 /* Number of bytes of storage in the actual machine representation for
64 x86_64_register_raw_size (int regno
)
66 return x86_64_register_raw_size_table
[regno
];
69 /* x86_64_register_byte_table[i] is the offset into the register file of the
70 start of register number i. We initialize this from
71 x86_64_register_raw_size_table. */
72 int x86_64_register_byte_table
[X86_64_NUM_REGS
];
74 /* Index within `registers' of the first byte of the space for register REGNO. */
76 x86_64_register_byte (int regno
)
78 return x86_64_register_byte_table
[regno
];
81 /* Return the GDB type object for the "standard" data type of data in
84 x86_64_register_virtual_type (int regno
)
86 if (regno
== PC_REGNUM
|| regno
== SP_REGNUM
)
87 return lookup_pointer_type (builtin_type_void
);
88 if (IS_FP_REGNUM (regno
))
89 return builtin_type_long_double
;
90 if (IS_SSE_REGNUM (regno
))
91 return builtin_type_v4sf
;
92 if (IS_FPU_CTRL_REGNUM (regno
) || regno
== MXCSR_REGNUM
93 || regno
== EFLAGS_REGNUM
)
94 return builtin_type_int
;
95 return builtin_type_long
;
98 /* Number of bytes of storage in the program's representation
99 for register REGNO. */
101 x86_64_register_virtual_size (int regno
)
103 return (TYPE_LENGTH (x86_64_register_virtual_type (regno
)));
106 /* x86_64_register_convertible is true if register N's virtual format is
107 different from its raw format. Note that this definition assumes
108 that the host supports IEEE 32-bit floats, since it doesn't say
109 that SSE registers need conversion. Even if we can't find a
110 counterexample, this is still sloppy. */
112 x86_64_register_convertible (int regno
)
114 return IS_FP_REGNUM (regno
);
117 /* Convert data from raw format for register REGNUM in buffer FROM to
118 virtual format with type TYPE in buffer TO. In principle both
119 formats are identical except that the virtual format has two extra
120 bytes appended that aren't used. We set these to zero. */
122 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
123 char *from
, char *to
)
125 /* Copy straight over, but take care of the padding. */
126 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
127 memset (to
+ FPU_REG_RAW_SIZE
, 0, TYPE_LENGTH (type
) - FPU_REG_RAW_SIZE
);
130 /* Convert data from virtual format with type TYPE in buffer FROM to
131 raw format for register REGNUM in buffer TO. Simply omit the two
135 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
136 char *from
, char *to
)
138 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
142 /* This is the variable that is set with "set disassembly-flavour", and
143 its legitimate values. */
144 static const char att_flavour
[] = "att";
145 static const char intel_flavour
[] = "intel";
146 static const char *valid_flavours
[] = {
151 static const char *disassembly_flavour
= att_flavour
;
154 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
158 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
160 write_memory (sp
- 8, buf
, 8);
165 x86_64_pop_frame (void)
167 generic_pop_current_frame (cfi_pop_frame
);
171 /* The returning of values is done according to the special algorithm.
172 Some types are returned in registers an some (big structures) in memory.
176 #define MAX_CLASSES 4
178 enum x86_64_reg_class
181 X86_64_INTEGER_CLASS
,
182 X86_64_INTEGERSI_CLASS
,
192 /* Return the union class of CLASS1 and CLASS2.
193 See the x86-64 ABI for details. */
195 static enum x86_64_reg_class
196 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
198 /* Rule #1: If both classes are equal, this is the resulting class. */
199 if (class1
== class2
)
202 /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
204 if (class1
== X86_64_NO_CLASS
)
206 if (class2
== X86_64_NO_CLASS
)
209 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
210 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
211 return X86_64_MEMORY_CLASS
;
213 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
214 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
215 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
216 return X86_64_INTEGERSI_CLASS
;
217 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
218 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
219 return X86_64_INTEGER_CLASS
;
221 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
222 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
223 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
224 return X86_64_MEMORY_CLASS
;
226 /* Rule #6: Otherwise class SSE is used. */
227 return X86_64_SSE_CLASS
;
231 /* Classify the argument type.
232 CLASSES will be filled by the register class used to pass each word
233 of the operand. The number of words is returned. In case the parameter
234 should be passed in memory, 0 is returned. As a special case for zero
235 sized containers, classes[0] will be NO_CLASS and 1 is returned.
237 See the x86-64 PS ABI for details.
241 classify_argument (struct type
*type
,
242 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
244 int bytes
= TYPE_LENGTH (type
);
245 int words
= (bytes
+ 8 - 1) / 8;
247 switch (TYPE_CODE (type
))
249 case TYPE_CODE_ARRAY
:
250 case TYPE_CODE_STRUCT
:
251 case TYPE_CODE_UNION
:
254 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
256 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
260 for (i
= 0; i
< words
; i
++)
261 classes
[i
] = X86_64_NO_CLASS
;
263 /* Zero sized arrays or structures are NO_CLASS. We return 0 to
264 signalize memory class, so handle it as special case. */
267 classes
[0] = X86_64_NO_CLASS
;
270 switch (TYPE_CODE (type
))
272 case TYPE_CODE_STRUCT
:
275 for (j
= 0; j
< type
->nfields
; ++j
)
277 int num
= classify_argument (type
->fields
[j
].type
,
279 (type
->fields
[j
].loc
.bitpos
280 + bit_offset
) % 256);
283 for (i
= 0; i
< num
; i
++)
286 (type
->fields
[j
].loc
.bitpos
+ bit_offset
) / 8 / 8;
288 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
293 case TYPE_CODE_ARRAY
:
297 num
= classify_argument (type
->target_type
,
298 subclasses
, bit_offset
);
302 /* The partial classes are now full classes. */
303 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
304 subclasses
[0] = X86_64_SSE_CLASS
;
305 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
306 subclasses
[0] = X86_64_INTEGER_CLASS
;
308 for (i
= 0; i
< words
; i
++)
309 classes
[i
] = subclasses
[i
% num
];
312 case TYPE_CODE_UNION
:
316 for (j
= 0; j
< type
->nfields
; ++j
)
319 num
= classify_argument (type
->fields
[j
].type
,
320 subclasses
, bit_offset
);
323 for (i
= 0; i
< num
; i
++)
324 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
330 /* Final merger cleanup. */
331 for (i
= 0; i
< words
; i
++)
333 /* If one class is MEMORY, everything should be passed in
335 if (classes
[i
] == X86_64_MEMORY_CLASS
)
338 /* The X86_64_SSEUP_CLASS should be always preceeded by
340 if (classes
[i
] == X86_64_SSEUP_CLASS
341 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
342 classes
[i
] = X86_64_SSE_CLASS
;
344 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
345 if (classes
[i
] == X86_64_X87UP_CLASS
346 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
347 classes
[i
] = X86_64_SSE_CLASS
;
356 if (!(bit_offset
% 64))
357 classes
[0] = X86_64_SSESF_CLASS
;
359 classes
[0] = X86_64_SSE_CLASS
;
362 classes
[0] = X86_64_SSEDF_CLASS
;
365 classes
[0] = X86_64_X87_CLASS
;
366 classes
[1] = X86_64_X87UP_CLASS
;
378 if (bytes
* 8 + bit_offset
<= 32)
379 classes
[0] = X86_64_INTEGERSI_CLASS
;
381 classes
[0] = X86_64_INTEGER_CLASS
;
384 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
392 internal_error (__FILE__
, __LINE__
, "classify_argument: unknown argument type");
395 /* Examine the argument and return set number of register required in each
396 class. Return 0 ifif parameter should be passed in memory. */
399 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
400 int n
, int *int_nregs
, int *sse_nregs
)
406 for (n
--; n
>= 0; n
--)
409 case X86_64_INTEGER_CLASS
:
410 case X86_64_INTEGERSI_CLASS
:
413 case X86_64_SSE_CLASS
:
414 case X86_64_SSESF_CLASS
:
415 case X86_64_SSEDF_CLASS
:
418 case X86_64_NO_CLASS
:
419 case X86_64_SSEUP_CLASS
:
420 case X86_64_X87_CLASS
:
421 case X86_64_X87UP_CLASS
:
423 case X86_64_MEMORY_CLASS
:
424 internal_error (__FILE__
, __LINE__
, "examine_argument: unexpected memory class");
429 #define RET_INT_REGS 2
430 #define RET_SSE_REGS 2
432 /* Check if the structure in value_type is returned in registers or in
433 memory. If this function returns 1, gdb will call STORE_STRUCT_RETURN and
434 EXTRACT_STRUCT_VALUE_ADDRESS else STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE
437 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
439 enum x86_64_reg_class
class[MAX_CLASSES
];
440 int n
= classify_argument (value_type
, class, 0);
445 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
446 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
450 /* Extract from an array REGBUF containing the (raw) register state, a
451 function return value of TYPE, and copy that, in virtual format,
455 x86_64_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
457 enum x86_64_reg_class
class[MAX_CLASSES
];
458 int n
= classify_argument (type
, class, 0);
464 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
465 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
468 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
469 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
472 memcpy (&addr
, regbuf
, REGISTER_RAW_SIZE (RAX_REGNUM
));
473 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
479 for (i
= 0; i
< n
; i
++)
483 case X86_64_NO_CLASS
:
485 case X86_64_INTEGER_CLASS
:
486 memcpy (valbuf
+ offset
,
487 regbuf
+ REGISTER_BYTE (ret_int_r
[(intreg
+ 1) / 2]),
492 case X86_64_INTEGERSI_CLASS
:
493 memcpy (valbuf
+ offset
,
494 regbuf
+ REGISTER_BYTE (ret_int_r
[intreg
/ 2]), 4);
498 case X86_64_SSEDF_CLASS
:
499 case X86_64_SSESF_CLASS
:
500 case X86_64_SSE_CLASS
:
501 memcpy (valbuf
+ offset
,
502 regbuf
+ REGISTER_BYTE (ret_sse_r
[(ssereg
+ 1) / 2]),
507 case X86_64_SSEUP_CLASS
:
508 memcpy (valbuf
+ offset
+ 8,
509 regbuf
+ REGISTER_BYTE (ret_sse_r
[ssereg
/ 2]), 8);
513 case X86_64_X87_CLASS
:
514 memcpy (valbuf
+ offset
, regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
518 case X86_64_X87UP_CLASS
:
519 memcpy (valbuf
+ offset
,
520 regbuf
+ REGISTER_BYTE (FP0_REGNUM
) + 8, 8);
523 case X86_64_MEMORY_CLASS
:
525 internal_error (__FILE__
, __LINE__
,
526 "Unexpected argument class");
532 /* Handled by unwind informations. */
534 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
541 /* Push onto the stack the specified value VALUE. Pad it correctly for
542 it to be an argument to a function. */
545 value_push (register CORE_ADDR sp
, value_ptr arg
)
547 register int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
548 register int container_len
= len
;
550 /* How big is the container we're going to put this value in? */
552 container_len
= ((len
+ PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1)
553 & ~(PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1));
556 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
562 x86_64_push_arguments (int nargs
, value_ptr
*args
, CORE_ADDR sp
,
563 int struct_return
, CORE_ADDR struct_addr
)
568 static int int_parameter_registers
[INT_REGS
] = {5 /*RDI*/, 4 /*RSI*/,
569 1 /*RDX*/, 2 /*RCX*/,
570 8 /*R8 */, 9 /*R9 */};
572 static int sse_parameter_registers
[SSE_REGS
] = {34, 35, 36, 37,
576 for (i
= 0; i
< nargs
; i
++)
578 enum x86_64_reg_class
class[MAX_CLASSES
];
579 int n
= classify_argument (args
[i
]->type
, class, 0);
584 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
585 || intreg
+ needed_intregs
> INT_REGS
586 || ssereg
+ needed_sseregs
> SSE_REGS
)
588 sp
= value_push (sp
, args
[i
]);
593 for (j
= 0; j
< n
; j
++)
598 case X86_64_NO_CLASS
:
600 case X86_64_INTEGER_CLASS
:
601 write_register_gen (int_parameter_registers
[(intreg
+ 1) / 2],
602 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
606 case X86_64_INTEGERSI_CLASS
:
607 write_register_gen (int_parameter_registers
[intreg
/ 2],
608 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
612 case X86_64_SSEDF_CLASS
:
613 case X86_64_SSESF_CLASS
:
614 case X86_64_SSE_CLASS
:
615 write_register_gen (sse_parameter_registers
[(ssereg
+ 1) / 2],
616 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
620 case X86_64_SSEUP_CLASS
:
621 write_register_gen (sse_parameter_registers
[ssereg
/ 2],
622 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
626 case X86_64_X87_CLASS
:
627 case X86_64_X87UP_CLASS
:
628 case X86_64_MEMORY_CLASS
:
629 sp
= value_push (sp
, args
[i
]);
632 internal_error (__FILE__
, __LINE__
,
633 "Unexpected argument class");
635 intreg
+= intreg
% 2;
636 ssereg
+= ssereg
% 2;
643 /* Write into the appropriate registers a function return value stored
644 in VALBUF of type TYPE, given in virtual format. */
646 x86_64_store_return_value (struct type
*type
, char *valbuf
)
648 int len
= TYPE_LENGTH (type
);
650 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
652 /* Floating-point return values can be found in %st(0). */
653 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
654 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
656 /* Copy straight over. */
657 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
662 char buf
[FPU_REG_RAW_SIZE
];
665 /* Convert the value found in VALBUF to the extended
666 floating point format used by the FPU. This is probably
667 not exactly how it would happen on the target itself, but
668 it is the best we can do. */
669 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
670 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
671 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
677 int low_size
= REGISTER_RAW_SIZE (0);
678 int high_size
= REGISTER_RAW_SIZE (1);
681 write_register_bytes (REGISTER_BYTE (0), valbuf
, len
);
682 else if (len
<= (low_size
+ high_size
))
684 write_register_bytes (REGISTER_BYTE (0), valbuf
, low_size
);
685 write_register_bytes (REGISTER_BYTE (1),
686 valbuf
+ low_size
, len
- low_size
);
689 internal_error (__FILE__
, __LINE__
,
690 "Cannot store return value of %d bytes long.", len
);
696 x86_64_register_name (int reg_nr
)
698 static char *register_names
[] = {
699 "rax", "rdx", "rcx", "rbx",
700 "rsi", "rdi", "rbp", "rsp",
701 "r8", "r9", "r10", "r11",
702 "r12", "r13", "r14", "r15",
704 "st0", "st1", "st2", "st3",
705 "st4", "st5", "st6", "st7",
706 "fctrl", "fstat", "ftag", "fiseg",
707 "fioff", "foseg", "fooff", "fop",
708 "xmm0", "xmm1", "xmm2", "xmm3",
709 "xmm4", "xmm5", "xmm6", "xmm7",
710 "xmm8", "xmm9", "xmm10", "xmm11",
711 "xmm12", "xmm13", "xmm14", "xmm15",
716 if (reg_nr
>= (sizeof (register_names
) / sizeof (*register_names
)))
718 return register_names
[reg_nr
];
723 /* We have two flavours of disassembly. The machinery on this page
724 deals with switching between those. */
727 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
729 if (disassembly_flavour
== att_flavour
)
730 return print_insn_i386_att (memaddr
, info
);
731 else if (disassembly_flavour
== intel_flavour
)
732 return print_insn_i386_intel (memaddr
, info
);
733 /* Never reached -- disassembly_flavour is always either att_flavour
735 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
739 /* Store the address of the place in which to copy the structure the
740 subroutine will return. This is called from call_function. */
742 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
744 write_register (RDI_REGNUM
, addr
);
748 x86_64_frameless_function_invocation (struct frame_info
*frame
)
753 /* On x86_64 there are no reasonable prologs. */
755 x86_64_skip_prologue (CORE_ADDR pc
)
760 /* Sequence of bytes for breakpoint instruction. */
761 static unsigned char *
762 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
764 static unsigned char breakpoint
[] = { 0xcc };
769 static struct gdbarch
*
770 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
772 struct gdbarch
*gdbarch
;
773 struct gdbarch_tdep
*tdep
;
775 /* Find a candidate among the list of pre-declared architectures. */
776 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
778 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
780 switch (info
.bfd_arch_info
->mach
)
782 case bfd_mach_x86_64
:
783 case bfd_mach_x86_64_intel_syntax
:
784 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
786 case bfd_mach_x86_64
:
787 case bfd_mach_x86_64_intel_syntax
:
788 return arches
->gdbarch
;
789 case bfd_mach_i386_i386
:
790 case bfd_mach_i386_i8086
:
791 case bfd_mach_i386_i386_intel_syntax
:
794 internal_error (__FILE__
, __LINE__
,
795 "i386_gdbarch_init: unknown machine type");
798 case bfd_mach_i386_i386
:
799 case bfd_mach_i386_i8086
:
800 case bfd_mach_i386_i386_intel_syntax
:
801 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
803 case bfd_mach_x86_64
:
804 case bfd_mach_x86_64_intel_syntax
:
806 case bfd_mach_i386_i386
:
807 case bfd_mach_i386_i8086
:
808 case bfd_mach_i386_i386_intel_syntax
:
809 return arches
->gdbarch
;
811 internal_error (__FILE__
, __LINE__
,
812 "i386_gdbarch_init: unknown machine type");
816 internal_error (__FILE__
, __LINE__
,
817 "i386_gdbarch_init: unknown machine type");
821 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
822 gdbarch
= gdbarch_alloc (&info
, tdep
);
824 switch (info
.bfd_arch_info
->mach
)
826 case bfd_mach_x86_64
:
827 case bfd_mach_x86_64_intel_syntax
:
828 tdep
->last_fpu_regnum
= 25;
829 tdep
->first_xmm_regnum
= 34;
830 tdep
->last_xmm_regnum
= 49;
831 tdep
->mxcsr_regnum
= 50;
832 tdep
->first_fpu_ctrl_regnum
= 26;
834 case bfd_mach_i386_i386
:
835 case bfd_mach_i386_i8086
:
836 case bfd_mach_i386_i386_intel_syntax
:
837 /* This is place for definition of i386 target vector. */
840 internal_error (__FILE__
, __LINE__
,
841 "i386_gdbarch_init: unknown machine type");
844 set_gdbarch_long_bit (gdbarch
, 64);
845 set_gdbarch_long_long_bit (gdbarch
, 64);
846 set_gdbarch_ptr_bit (gdbarch
, 64);
848 set_gdbarch_long_double_format (gdbarch
, &floatformat_i387_ext
);
849 set_gdbarch_ieee_float (gdbarch
, 1);
852 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
853 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
854 set_gdbarch_register_size (gdbarch
, 8);
855 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
856 set_gdbarch_max_register_raw_size (gdbarch
, 16);
857 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
858 /* Total amount of space needed to store our copies of the machine's register
859 (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS + SIZEOF_SSE_REGS) */
860 set_gdbarch_register_bytes (gdbarch
,
861 (18 * 8) + (8 * 10) + (8 * 4) + (8 * 16 + 4));
862 set_gdbarch_register_virtual_size (gdbarch
, x86_64_register_virtual_size
);
863 set_gdbarch_max_register_virtual_size (gdbarch
, 16);
865 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
867 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
868 set_gdbarch_register_convert_to_virtual (gdbarch
,
869 x86_64_register_convert_to_virtual
);
870 set_gdbarch_register_convert_to_raw (gdbarch
,
871 x86_64_register_convert_to_raw
);
873 /* Register numbers of various important registers. */
874 set_gdbarch_sp_regnum (gdbarch
, 7); /* (rsp) Contains address of top of stack. */
875 set_gdbarch_fp_regnum (gdbarch
, 6); /* (rbp) */
876 set_gdbarch_pc_regnum (gdbarch
, 16); /* (rip) Contains program counter. */
878 set_gdbarch_fp0_regnum (gdbarch
, 18); /* First FPU floating-point register. */
880 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
881 set_gdbarch_write_fp (gdbarch
, cfi_write_fp
);
883 /* Discard from the stack the innermost frame, restoring all registers. */
884 set_gdbarch_pop_frame (gdbarch
, x86_64_pop_frame
);
886 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
888 set_gdbarch_frame_chain (gdbarch
, cfi_frame_chain
);
890 set_gdbarch_frameless_function_invocation (gdbarch
,
891 x86_64_frameless_function_invocation
);
892 set_gdbarch_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
894 set_gdbarch_frame_args_address (gdbarch
, default_frame_address
);
895 set_gdbarch_frame_locals_address (gdbarch
, default_frame_address
);
897 /* Return number of bytes at start of arglist that are not really args. */
898 set_gdbarch_frame_args_skip (gdbarch
, 8);
900 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
902 /* Frame pc initialization is handled by unwind informations. */
903 set_gdbarch_init_frame_pc (gdbarch
, cfi_init_frame_pc
);
905 /* Initialization of unwind informations. */
906 set_gdbarch_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
908 /* Getting saved registers is handled by unwind informations. */
909 set_gdbarch_get_saved_register (gdbarch
, cfi_get_saved_register
);
911 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
913 /* Cons up virtual frame pointer for trace */
914 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
917 set_gdbarch_frame_chain_valid (gdbarch
, generic_file_frame_chain_valid
);
919 set_gdbarch_use_generic_dummy_frames (gdbarch
, 1);
920 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
921 set_gdbarch_call_dummy_address (gdbarch
, entry_point_address
);
922 set_gdbarch_call_dummy_length (gdbarch
, 0);
923 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
924 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
925 set_gdbarch_pc_in_call_dummy (gdbarch
, pc_in_call_dummy_at_entry_point
);
926 set_gdbarch_call_dummy_words (gdbarch
, 0);
927 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
928 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
929 set_gdbarch_call_dummy_p (gdbarch
, 1);
930 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
931 set_gdbarch_push_dummy_frame (gdbarch
, generic_push_dummy_frame
);
932 set_gdbarch_fix_call_dummy (gdbarch
, generic_fix_call_dummy
);
933 set_gdbarch_push_return_address (gdbarch
, x86_64_push_return_address
);
934 set_gdbarch_push_arguments (gdbarch
, x86_64_push_arguments
);
936 /* Return number of args passed to a frame, no way to tell. */
937 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
938 /* Don't use default structure extract routine */
939 set_gdbarch_extract_struct_value_address (gdbarch
, 0);
941 /* If USE_STRUCT_CONVENTION retruns 0, then gdb uses STORE_RETURN_VALUE
942 and EXTRACT_RETURN_VALUE to store/fetch the functions return value. It is
943 the case when structure is returned in registers. */
944 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
946 /* Store the address of the place in which to copy the structure the
947 subroutine will return. This is called from call_function. */
948 set_gdbarch_store_struct_return (gdbarch
, x86_64_store_struct_return
);
950 /* Extract from an array REGBUF containing the (raw) register state
951 a function return value of type TYPE, and copy that, in virtual format,
953 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
956 /* Write into the appropriate registers a function return value stored
957 in VALBUF of type TYPE, given in virtual format. */
958 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
961 /* Offset from address of function to start of its code. */
962 set_gdbarch_function_start_offset (gdbarch
, 0);
964 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
966 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
968 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
970 set_gdbarch_breakpoint_from_pc (gdbarch
, x86_64_breakpoint_from_pc
);
973 /* Amount PC must be decremented by after a breakpoint. This is often the
974 number of bytes in BREAKPOINT but not always. */
975 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
981 _initialize_x86_64_tdep (void)
983 register_gdbarch_init (bfd_arch_i386
, i386_gdbarch_init
);
985 /* Initialize the table saying where each register starts in the
991 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
993 x86_64_register_byte_table
[i
] = offset
;
994 offset
+= x86_64_register_raw_size_table
[i
];
998 tm_print_insn
= gdb_print_insn_x86_64
;
999 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 3)->mach
;
1001 /* Add the variable that controls the disassembly flavour. */
1003 struct cmd_list_element
*new_cmd
;
1005 new_cmd
= add_set_enum_cmd ("disassembly-flavour", no_class
,
1006 valid_flavours
, &disassembly_flavour
, "\
1007 Set the disassembly flavour, the valid values are \"att\" and \"intel\", \
1008 and the default value is \"att\".", &setlist
);
1009 add_show_from_set (new_cmd
, &showlist
);