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"
34 /* Register numbers of various important registers. */
38 #define EFLAGS_REGNUM 17
39 #define XMM1_REGNUM 35
41 /* x86_64_register_raw_size_table[i] is the number of bytes of storage in
42 GDB's register array occupied by register i. */
43 int x86_64_register_raw_size_table
[X86_64_NUM_REGS
] = {
60 /* Number of bytes of storage in the actual machine representation for
63 x86_64_register_raw_size (int regno
)
65 return x86_64_register_raw_size_table
[regno
];
68 /* x86_64_register_byte_table[i] is the offset into the register file of the
69 start of register number i. We initialize this from
70 x86_64_register_raw_size_table. */
71 int x86_64_register_byte_table
[X86_64_NUM_REGS
];
73 /* Index within `registers' of the first byte of the space for register REGNO. */
75 x86_64_register_byte (int regno
)
77 return x86_64_register_byte_table
[regno
];
80 /* Return the GDB type object for the "standard" data type of data in
83 x86_64_register_virtual_type (int regno
)
85 if (regno
== PC_REGNUM
|| regno
== SP_REGNUM
)
86 return lookup_pointer_type (builtin_type_void
);
87 if (IS_FP_REGNUM (regno
))
88 return builtin_type_long_double
;
89 if (IS_SSE_REGNUM (regno
))
90 return builtin_type_v4sf
;
91 if (IS_FPU_CTRL_REGNUM (regno
) || regno
== MXCSR_REGNUM
92 || regno
== EFLAGS_REGNUM
)
93 return builtin_type_int
;
94 return builtin_type_long
;
97 /* Number of bytes of storage in the program's representation
98 for register REGNO. */
100 x86_64_register_virtual_size (int regno
)
102 return (TYPE_LENGTH (x86_64_register_virtual_type (regno
)));
105 /* x86_64_register_convertible is true if register N's virtual format is
106 different from its raw format. Note that this definition assumes
107 that the host supports IEEE 32-bit floats, since it doesn't say
108 that SSE registers need conversion. Even if we can't find a
109 counterexample, this is still sloppy. */
111 x86_64_register_convertible (int regno
)
113 return IS_FP_REGNUM (regno
);
116 /* Convert data from raw format for register REGNUM in buffer FROM to
117 virtual format with type TYPE in buffer TO. In principle both
118 formats are identical except that the virtual format has two extra
119 bytes appended that aren't used. We set these to zero. */
121 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
122 char *from
, char *to
)
124 /* Copy straight over, but take care of the padding. */
125 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
126 memset (to
+ FPU_REG_RAW_SIZE
, 0, TYPE_LENGTH (type
) - FPU_REG_RAW_SIZE
);
129 /* Convert data from virtual format with type TYPE in buffer FROM to
130 raw format for register REGNUM in buffer TO. Simply omit the two
134 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
135 char *from
, char *to
)
137 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
141 /* This is the variable that is set with "set disassembly-flavour", and
142 its legitimate values. */
143 static const char att_flavour
[] = "att";
144 static const char intel_flavour
[] = "intel";
145 static const char *valid_flavours
[] = {
150 static const char *disassembly_flavour
= att_flavour
;
153 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
157 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
159 write_memory (sp
- 8, buf
, 8);
164 x86_64_pop_frame (void)
166 generic_pop_current_frame (cfi_pop_frame
);
170 /* The returning of values is done according to the special algorithm.
171 Some types are returned in registers an some (big structures) in memory.
175 #define MAX_CLASSES 4
177 enum x86_64_reg_class
180 X86_64_INTEGER_CLASS
,
181 X86_64_INTEGERSI_CLASS
,
191 /* Return the union class of CLASS1 and CLASS2.
192 See the x86-64 ABI for details. */
194 static enum x86_64_reg_class
195 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
197 /* Rule #1: If both classes are equal, this is the resulting class. */
198 if (class1
== class2
)
201 /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
203 if (class1
== X86_64_NO_CLASS
)
205 if (class2
== X86_64_NO_CLASS
)
208 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
209 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
210 return X86_64_MEMORY_CLASS
;
212 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
213 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
214 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
215 return X86_64_INTEGERSI_CLASS
;
216 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
217 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
218 return X86_64_INTEGER_CLASS
;
220 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
221 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
222 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
223 return X86_64_MEMORY_CLASS
;
225 /* Rule #6: Otherwise class SSE is used. */
226 return X86_64_SSE_CLASS
;
230 /* Classify the argument type.
231 CLASSES will be filled by the register class used to pass each word
232 of the operand. The number of words is returned. In case the parameter
233 should be passed in memory, 0 is returned. As a special case for zero
234 sized containers, classes[0] will be NO_CLASS and 1 is returned.
236 See the x86-64 PS ABI for details.
240 classify_argument (struct type
*type
,
241 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
243 int bytes
= TYPE_LENGTH (type
);
244 int words
= (bytes
+ 8 - 1) / 8;
246 switch (TYPE_CODE (type
))
248 case TYPE_CODE_ARRAY
:
249 case TYPE_CODE_STRUCT
:
250 case TYPE_CODE_UNION
:
253 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
255 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
259 for (i
= 0; i
< words
; i
++)
260 classes
[i
] = X86_64_NO_CLASS
;
262 /* Zero sized arrays or structures are NO_CLASS. We return 0 to
263 signalize memory class, so handle it as special case. */
266 classes
[0] = X86_64_NO_CLASS
;
269 switch (TYPE_CODE (type
))
271 case TYPE_CODE_STRUCT
:
274 for (j
= 0; j
< type
->nfields
; ++j
)
276 int num
= classify_argument (type
->fields
[j
].type
,
278 (type
->fields
[j
].loc
.bitpos
279 + bit_offset
) % 256);
282 for (i
= 0; i
< num
; i
++)
285 (type
->fields
[j
].loc
.bitpos
+ bit_offset
) / 8 / 8;
287 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
292 case TYPE_CODE_ARRAY
:
296 num
= classify_argument (type
->target_type
,
297 subclasses
, bit_offset
);
301 /* The partial classes are now full classes. */
302 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
303 subclasses
[0] = X86_64_SSE_CLASS
;
304 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
305 subclasses
[0] = X86_64_INTEGER_CLASS
;
307 for (i
= 0; i
< words
; i
++)
308 classes
[i
] = subclasses
[i
% num
];
311 case TYPE_CODE_UNION
:
315 for (j
= 0; j
< type
->nfields
; ++j
)
318 num
= classify_argument (type
->fields
[j
].type
,
319 subclasses
, bit_offset
);
322 for (i
= 0; i
< num
; i
++)
323 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
329 /* Final merger cleanup. */
330 for (i
= 0; i
< words
; i
++)
332 /* If one class is MEMORY, everything should be passed in
334 if (classes
[i
] == X86_64_MEMORY_CLASS
)
337 /* The X86_64_SSEUP_CLASS should be always preceeded by
339 if (classes
[i
] == X86_64_SSEUP_CLASS
340 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
341 classes
[i
] = X86_64_SSE_CLASS
;
343 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
344 if (classes
[i
] == X86_64_X87UP_CLASS
345 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
346 classes
[i
] = X86_64_SSE_CLASS
;
355 if (!(bit_offset
% 64))
356 classes
[0] = X86_64_SSESF_CLASS
;
358 classes
[0] = X86_64_SSE_CLASS
;
361 classes
[0] = X86_64_SSEDF_CLASS
;
364 classes
[0] = X86_64_X87_CLASS
;
365 classes
[1] = X86_64_X87UP_CLASS
;
377 if (bytes
* 8 + bit_offset
<= 32)
378 classes
[0] = X86_64_INTEGERSI_CLASS
;
380 classes
[0] = X86_64_INTEGER_CLASS
;
383 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
391 internal_error (__FILE__
, __LINE__
, "classify_argument: unknown argument type");
394 /* Examine the argument and return set number of register required in each
395 class. Return 0 ifif parameter should be passed in memory. */
398 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
399 int n
, int *int_nregs
, int *sse_nregs
)
405 for (n
--; n
>= 0; n
--)
408 case X86_64_INTEGER_CLASS
:
409 case X86_64_INTEGERSI_CLASS
:
412 case X86_64_SSE_CLASS
:
413 case X86_64_SSESF_CLASS
:
414 case X86_64_SSEDF_CLASS
:
417 case X86_64_NO_CLASS
:
418 case X86_64_SSEUP_CLASS
:
419 case X86_64_X87_CLASS
:
420 case X86_64_X87UP_CLASS
:
422 case X86_64_MEMORY_CLASS
:
423 internal_error (__FILE__
, __LINE__
, "examine_argument: unexpected memory class");
428 #define RET_INT_REGS 2
429 #define RET_SSE_REGS 2
431 /* Check if the structure in value_type is returned in registers or in
432 memory. If this function returns 1, gdb will call STORE_STRUCT_RETURN and
433 EXTRACT_STRUCT_VALUE_ADDRESS else STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE
436 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
438 enum x86_64_reg_class
class[MAX_CLASSES
];
439 int n
= classify_argument (value_type
, class, 0);
444 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
445 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
449 /* Extract from an array REGBUF containing the (raw) register state, a
450 function return value of TYPE, and copy that, in virtual format,
454 x86_64_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
456 enum x86_64_reg_class
class[MAX_CLASSES
];
457 int n
= classify_argument (type
, class, 0);
463 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
464 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
467 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
468 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
471 memcpy (&addr
, regbuf
, REGISTER_RAW_SIZE (RAX_REGNUM
));
472 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
478 for (i
= 0; i
< n
; i
++)
482 case X86_64_NO_CLASS
:
484 case X86_64_INTEGER_CLASS
:
485 memcpy (valbuf
+ offset
,
486 regbuf
+ REGISTER_BYTE (ret_int_r
[(intreg
+ 1) / 2]),
491 case X86_64_INTEGERSI_CLASS
:
492 memcpy (valbuf
+ offset
,
493 regbuf
+ REGISTER_BYTE (ret_int_r
[intreg
/ 2]), 4);
497 case X86_64_SSEDF_CLASS
:
498 case X86_64_SSESF_CLASS
:
499 case X86_64_SSE_CLASS
:
500 memcpy (valbuf
+ offset
,
501 regbuf
+ REGISTER_BYTE (ret_sse_r
[(ssereg
+ 1) / 2]),
506 case X86_64_SSEUP_CLASS
:
507 memcpy (valbuf
+ offset
+ 8,
508 regbuf
+ REGISTER_BYTE (ret_sse_r
[ssereg
/ 2]), 8);
512 case X86_64_X87_CLASS
:
513 memcpy (valbuf
+ offset
, regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
517 case X86_64_X87UP_CLASS
:
518 memcpy (valbuf
+ offset
,
519 regbuf
+ REGISTER_BYTE (FP0_REGNUM
) + 8, 8);
522 case X86_64_MEMORY_CLASS
:
524 internal_error (__FILE__
, __LINE__
,
525 "Unexpected argument class");
531 /* Handled by unwind informations. */
533 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
540 /* Push onto the stack the specified value VALUE. Pad it correctly for
541 it to be an argument to a function. */
544 value_push (register CORE_ADDR sp
, value_ptr arg
)
546 register int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
547 register int container_len
= len
;
549 /* How big is the container we're going to put this value in? */
551 container_len
= ((len
+ PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1)
552 & ~(PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1));
555 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
561 x86_64_push_arguments (int nargs
, value_ptr
*args
, CORE_ADDR sp
,
562 int struct_return
, CORE_ADDR struct_addr
)
567 static int int_parameter_registers
[INT_REGS
] = {5 /*RDI*/, 4 /*RSI*/,
568 1 /*RDX*/, 2 /*RCX*/,
569 8 /*R8 */, 9 /*R9 */};
571 static int sse_parameter_registers
[SSE_REGS
] = {34, 35, 36, 37,
575 for (i
= 0; i
< nargs
; i
++)
577 enum x86_64_reg_class
class[MAX_CLASSES
];
578 int n
= classify_argument (args
[i
]->type
, class, 0);
583 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
584 || intreg
+ needed_intregs
> INT_REGS
585 || ssereg
+ needed_sseregs
> SSE_REGS
)
587 sp
= value_push (sp
, args
[i
]);
592 for (j
= 0; j
< n
; j
++)
597 case X86_64_NO_CLASS
:
599 case X86_64_INTEGER_CLASS
:
600 write_register_gen (int_parameter_registers
[(intreg
+ 1) / 2],
601 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
605 case X86_64_INTEGERSI_CLASS
:
606 write_register_gen (int_parameter_registers
[intreg
/ 2],
607 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
611 case X86_64_SSEDF_CLASS
:
612 case X86_64_SSESF_CLASS
:
613 case X86_64_SSE_CLASS
:
614 write_register_gen (sse_parameter_registers
[(ssereg
+ 1) / 2],
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_X87UP_CLASS
:
627 case X86_64_MEMORY_CLASS
:
628 sp
= value_push (sp
, args
[i
]);
631 internal_error (__FILE__
, __LINE__
,
632 "Unexpected argument class");
634 intreg
+= intreg
% 2;
635 ssereg
+= ssereg
% 2;
642 /* Write into the appropriate registers a function return value stored
643 in VALBUF of type TYPE, given in virtual format. */
645 x86_64_store_return_value (struct type
*type
, char *valbuf
)
647 int len
= TYPE_LENGTH (type
);
649 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
651 /* Floating-point return values can be found in %st(0). */
652 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
653 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
655 /* Copy straight over. */
656 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
661 char buf
[FPU_REG_RAW_SIZE
];
664 /* Convert the value found in VALBUF to the extended
665 floating point format used by the FPU. This is probably
666 not exactly how it would happen on the target itself, but
667 it is the best we can do. */
668 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
669 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
670 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
676 int low_size
= REGISTER_RAW_SIZE (0);
677 int high_size
= REGISTER_RAW_SIZE (1);
680 write_register_bytes (REGISTER_BYTE (0), valbuf
, len
);
681 else if (len
<= (low_size
+ high_size
))
683 write_register_bytes (REGISTER_BYTE (0), valbuf
, low_size
);
684 write_register_bytes (REGISTER_BYTE (1),
685 valbuf
+ low_size
, len
- low_size
);
688 internal_error (__FILE__
, __LINE__
,
689 "Cannot store return value of %d bytes long.", len
);
695 x86_64_register_name (int reg_nr
)
697 static char *register_names
[] = {
698 "rax", "rdx", "rcx", "rbx",
699 "rsi", "rdi", "rbp", "rsp",
700 "r8", "r9", "r10", "r11",
701 "r12", "r13", "r14", "r15",
703 "st0", "st1", "st2", "st3",
704 "st4", "st5", "st6", "st7",
705 "fctrl", "fstat", "ftag", "fiseg",
706 "fioff", "foseg", "fooff", "fop",
707 "xmm0", "xmm1", "xmm2", "xmm3",
708 "xmm4", "xmm5", "xmm6", "xmm7",
709 "xmm8", "xmm9", "xmm10", "xmm11",
710 "xmm12", "xmm13", "xmm14", "xmm15",
715 if (reg_nr
>= (sizeof (register_names
) / sizeof (*register_names
)))
717 return register_names
[reg_nr
];
722 /* We have two flavours of disassembly. The machinery on this page
723 deals with switching between those. */
726 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
728 if (disassembly_flavour
== att_flavour
)
729 return print_insn_i386_att (memaddr
, info
);
730 else if (disassembly_flavour
== intel_flavour
)
731 return print_insn_i386_intel (memaddr
, info
);
732 /* Never reached -- disassembly_flavour is always either att_flavour
734 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
738 /* Store the address of the place in which to copy the structure the
739 subroutine will return. This is called from call_function. */
741 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
743 write_register (RDI_REGNUM
, addr
);
747 x86_64_frameless_function_invocation (struct frame_info
*frame
)
752 /* On x86_64 there are no reasonable prologs. */
754 x86_64_skip_prologue (CORE_ADDR pc
)
759 /* Sequence of bytes for breakpoint instruction. */
760 static unsigned char *
761 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
763 static unsigned char breakpoint
[] = { 0xcc };
768 static struct gdbarch
*
769 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
771 struct gdbarch
*gdbarch
;
772 struct gdbarch_tdep
*tdep
;
774 /* Find a candidate among the list of pre-declared architectures. */
775 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
777 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
779 switch (info
.bfd_arch_info
->mach
)
781 case bfd_mach_x86_64
:
782 case bfd_mach_x86_64_intel_syntax
:
783 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
785 case bfd_mach_x86_64
:
786 case bfd_mach_x86_64_intel_syntax
:
787 return arches
->gdbarch
;
788 case bfd_mach_i386_i386
:
789 case bfd_mach_i386_i8086
:
790 case bfd_mach_i386_i386_intel_syntax
:
793 internal_error (__FILE__
, __LINE__
,
794 "i386_gdbarch_init: unknown machine type");
797 case bfd_mach_i386_i386
:
798 case bfd_mach_i386_i8086
:
799 case bfd_mach_i386_i386_intel_syntax
:
800 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
802 case bfd_mach_x86_64
:
803 case bfd_mach_x86_64_intel_syntax
:
805 case bfd_mach_i386_i386
:
806 case bfd_mach_i386_i8086
:
807 case bfd_mach_i386_i386_intel_syntax
:
808 return arches
->gdbarch
;
810 internal_error (__FILE__
, __LINE__
,
811 "i386_gdbarch_init: unknown machine type");
815 internal_error (__FILE__
, __LINE__
,
816 "i386_gdbarch_init: unknown machine type");
820 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
821 gdbarch
= gdbarch_alloc (&info
, tdep
);
823 switch (info
.bfd_arch_info
->mach
)
825 case bfd_mach_x86_64
:
826 case bfd_mach_x86_64_intel_syntax
:
827 tdep
->last_fpu_regnum
= 25;
828 tdep
->first_xmm_regnum
= 34;
829 tdep
->last_xmm_regnum
= 49;
830 tdep
->mxcsr_regnum
= 50;
831 tdep
->first_fpu_ctrl_regnum
= 26;
833 case bfd_mach_i386_i386
:
834 case bfd_mach_i386_i8086
:
835 case bfd_mach_i386_i386_intel_syntax
:
836 /* This is place for definition of i386 target vector. */
839 internal_error (__FILE__
, __LINE__
,
840 "i386_gdbarch_init: unknown machine type");
843 set_gdbarch_long_bit (gdbarch
, 64);
844 set_gdbarch_long_long_bit (gdbarch
, 64);
845 set_gdbarch_ptr_bit (gdbarch
, 64);
847 set_gdbarch_long_double_format (gdbarch
, &floatformat_i387_ext
);
848 set_gdbarch_ieee_float (gdbarch
, 1);
851 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
852 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
853 set_gdbarch_register_size (gdbarch
, 8);
854 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
855 set_gdbarch_max_register_raw_size (gdbarch
, 16);
856 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
857 /* Total amount of space needed to store our copies of the machine's register
858 (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS + SIZEOF_SSE_REGS) */
859 set_gdbarch_register_bytes (gdbarch
,
860 (18 * 8) + (8 * 10) + (8 * 4) + (8 * 16 + 4));
861 set_gdbarch_register_virtual_size (gdbarch
, x86_64_register_virtual_size
);
862 set_gdbarch_max_register_virtual_size (gdbarch
, 16);
864 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
866 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
867 set_gdbarch_register_convert_to_virtual (gdbarch
,
868 x86_64_register_convert_to_virtual
);
869 set_gdbarch_register_convert_to_raw (gdbarch
,
870 x86_64_register_convert_to_raw
);
872 /* Register numbers of various important registers. */
873 set_gdbarch_sp_regnum (gdbarch
, 7); /* (rsp) Contains address of top of stack. */
874 set_gdbarch_fp_regnum (gdbarch
, 6); /* (rbp) */
875 set_gdbarch_pc_regnum (gdbarch
, 16); /* (rip) Contains program counter. */
877 set_gdbarch_fp0_regnum (gdbarch
, 18); /* First FPU floating-point register. */
879 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
880 set_gdbarch_write_fp (gdbarch
, cfi_write_fp
);
882 /* Discard from the stack the innermost frame, restoring all registers. */
883 set_gdbarch_pop_frame (gdbarch
, x86_64_pop_frame
);
885 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
887 set_gdbarch_frame_chain (gdbarch
, cfi_frame_chain
);
889 set_gdbarch_frameless_function_invocation (gdbarch
,
890 x86_64_frameless_function_invocation
);
891 set_gdbarch_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
893 set_gdbarch_frame_args_address (gdbarch
, default_frame_address
);
894 set_gdbarch_frame_locals_address (gdbarch
, default_frame_address
);
896 /* Return number of bytes at start of arglist that are not really args. */
897 set_gdbarch_frame_args_skip (gdbarch
, 8);
899 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
901 /* Frame pc initialization is handled by unwind informations. */
902 set_gdbarch_init_frame_pc (gdbarch
, cfi_init_frame_pc
);
904 /* Initialization of unwind informations. */
905 set_gdbarch_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
907 /* Getting saved registers is handled by unwind informations. */
908 set_gdbarch_get_saved_register (gdbarch
, cfi_get_saved_register
);
910 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
912 /* Cons up virtual frame pointer for trace */
913 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
916 set_gdbarch_frame_chain_valid (gdbarch
, generic_file_frame_chain_valid
);
918 set_gdbarch_use_generic_dummy_frames (gdbarch
, 1);
919 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
920 set_gdbarch_call_dummy_address (gdbarch
, entry_point_address
);
921 set_gdbarch_call_dummy_length (gdbarch
, 0);
922 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
923 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
924 set_gdbarch_pc_in_call_dummy (gdbarch
, pc_in_call_dummy_at_entry_point
);
925 set_gdbarch_call_dummy_words (gdbarch
, 0);
926 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
927 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
928 set_gdbarch_call_dummy_p (gdbarch
, 1);
929 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
930 set_gdbarch_push_dummy_frame (gdbarch
, generic_push_dummy_frame
);
931 set_gdbarch_fix_call_dummy (gdbarch
, generic_fix_call_dummy
);
932 set_gdbarch_push_return_address (gdbarch
, x86_64_push_return_address
);
933 set_gdbarch_push_arguments (gdbarch
, x86_64_push_arguments
);
935 /* Return number of args passed to a frame, no way to tell. */
936 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
937 /* Don't use default structure extract routine */
938 set_gdbarch_extract_struct_value_address (gdbarch
, 0);
940 /* If USE_STRUCT_CONVENTION retruns 0, then gdb uses STORE_RETURN_VALUE
941 and EXTRACT_RETURN_VALUE to store/fetch the functions return value. It is
942 the case when structure is returned in registers. */
943 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
945 /* Store the address of the place in which to copy the structure the
946 subroutine will return. This is called from call_function. */
947 set_gdbarch_store_struct_return (gdbarch
, x86_64_store_struct_return
);
949 /* Extract from an array REGBUF containing the (raw) register state
950 a function return value of type TYPE, and copy that, in virtual format,
952 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
955 /* Write into the appropriate registers a function return value stored
956 in VALBUF of type TYPE, given in virtual format. */
957 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
960 /* Offset from address of function to start of its code. */
961 set_gdbarch_function_start_offset (gdbarch
, 0);
963 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
965 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
967 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
969 set_gdbarch_breakpoint_from_pc (gdbarch
, x86_64_breakpoint_from_pc
);
972 /* Amount PC must be decremented by after a breakpoint. This is often the
973 number of bytes in BREAKPOINT but not always. */
974 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
980 _initialize_x86_64_tdep (void)
982 register_gdbarch_init (bfd_arch_i386
, i386_gdbarch_init
);
984 /* Initialize the table saying where each register starts in the
990 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
992 x86_64_register_byte_table
[i
] = offset
;
993 offset
+= x86_64_register_raw_size_table
[i
];
997 tm_print_insn
= gdb_print_insn_x86_64
;
998 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 3)->mach
;
1000 /* Add the variable that controls the disassembly flavour. */
1002 struct cmd_list_element
*new_cmd
;
1004 new_cmd
= add_set_enum_cmd ("disassembly-flavour", no_class
,
1005 valid_flavours
, &disassembly_flavour
, "\
1006 Set the disassembly flavour, the valid values are \"att\" and \"intel\", \
1007 and the default value is \"att\".", &setlist
);
1008 add_show_from_set (new_cmd
, &showlist
);