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 /* x86_64_register_convertible is true if register N's virtual format is
99 different from its raw format. Note that this definition assumes
100 that the host supports IEEE 32-bit floats, since it doesn't say
101 that SSE registers need conversion. Even if we can't find a
102 counterexample, this is still sloppy. */
104 x86_64_register_convertible (int regno
)
106 return IS_FP_REGNUM (regno
);
109 /* Convert data from raw format for register REGNUM in buffer FROM to
110 virtual format with type TYPE in buffer TO. In principle both
111 formats are identical except that the virtual format has two extra
112 bytes appended that aren't used. We set these to zero. */
114 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
115 char *from
, char *to
)
117 /* Copy straight over, but take care of the padding. */
118 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
119 memset (to
+ FPU_REG_RAW_SIZE
, 0, TYPE_LENGTH (type
) - FPU_REG_RAW_SIZE
);
122 /* Convert data from virtual format with type TYPE in buffer FROM to
123 raw format for register REGNUM in buffer TO. Simply omit the two
127 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
128 char *from
, char *to
)
130 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
134 /* This is the variable that is set with "set disassembly-flavour", and
135 its legitimate values. */
136 static const char att_flavour
[] = "att";
137 static const char intel_flavour
[] = "intel";
138 static const char *valid_flavours
[] = {
143 static const char *disassembly_flavour
= att_flavour
;
146 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
150 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
152 write_memory (sp
- 8, buf
, 8);
157 x86_64_pop_frame (void)
159 generic_pop_current_frame (cfi_pop_frame
);
163 /* The returning of values is done according to the special algorithm.
164 Some types are returned in registers an some (big structures) in memory.
168 #define MAX_CLASSES 4
170 enum x86_64_reg_class
173 X86_64_INTEGER_CLASS
,
174 X86_64_INTEGERSI_CLASS
,
184 /* Return the union class of CLASS1 and CLASS2.
185 See the x86-64 ABI for details. */
187 static enum x86_64_reg_class
188 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
190 /* Rule #1: If both classes are equal, this is the resulting class. */
191 if (class1
== class2
)
194 /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
196 if (class1
== X86_64_NO_CLASS
)
198 if (class2
== X86_64_NO_CLASS
)
201 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
202 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
203 return X86_64_MEMORY_CLASS
;
205 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
206 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
207 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
208 return X86_64_INTEGERSI_CLASS
;
209 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
210 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
211 return X86_64_INTEGER_CLASS
;
213 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
214 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
215 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
216 return X86_64_MEMORY_CLASS
;
218 /* Rule #6: Otherwise class SSE is used. */
219 return X86_64_SSE_CLASS
;
223 /* Classify the argument type.
224 CLASSES will be filled by the register class used to pass each word
225 of the operand. The number of words is returned. In case the parameter
226 should be passed in memory, 0 is returned. As a special case for zero
227 sized containers, classes[0] will be NO_CLASS and 1 is returned.
229 See the x86-64 PS ABI for details.
233 classify_argument (struct type
*type
,
234 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
236 int bytes
= TYPE_LENGTH (type
);
237 int words
= (bytes
+ 8 - 1) / 8;
239 switch (TYPE_CODE (type
))
241 case TYPE_CODE_ARRAY
:
242 case TYPE_CODE_STRUCT
:
243 case TYPE_CODE_UNION
:
246 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
248 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
252 for (i
= 0; i
< words
; i
++)
253 classes
[i
] = X86_64_NO_CLASS
;
255 /* Zero sized arrays or structures are NO_CLASS. We return 0 to
256 signalize memory class, so handle it as special case. */
259 classes
[0] = X86_64_NO_CLASS
;
262 switch (TYPE_CODE (type
))
264 case TYPE_CODE_STRUCT
:
267 for (j
= 0; j
< type
->nfields
; ++j
)
269 int num
= classify_argument (type
->fields
[j
].type
,
271 (type
->fields
[j
].loc
.bitpos
272 + bit_offset
) % 256);
275 for (i
= 0; i
< num
; i
++)
278 (type
->fields
[j
].loc
.bitpos
+ bit_offset
) / 8 / 8;
280 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
285 case TYPE_CODE_ARRAY
:
289 num
= classify_argument (type
->target_type
,
290 subclasses
, bit_offset
);
294 /* The partial classes are now full classes. */
295 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
296 subclasses
[0] = X86_64_SSE_CLASS
;
297 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
298 subclasses
[0] = X86_64_INTEGER_CLASS
;
300 for (i
= 0; i
< words
; i
++)
301 classes
[i
] = subclasses
[i
% num
];
304 case TYPE_CODE_UNION
:
308 for (j
= 0; j
< type
->nfields
; ++j
)
311 num
= classify_argument (type
->fields
[j
].type
,
312 subclasses
, bit_offset
);
315 for (i
= 0; i
< num
; i
++)
316 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
322 /* Final merger cleanup. */
323 for (i
= 0; i
< words
; i
++)
325 /* If one class is MEMORY, everything should be passed in
327 if (classes
[i
] == X86_64_MEMORY_CLASS
)
330 /* The X86_64_SSEUP_CLASS should be always preceeded by
332 if (classes
[i
] == X86_64_SSEUP_CLASS
333 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
334 classes
[i
] = X86_64_SSE_CLASS
;
336 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
337 if (classes
[i
] == X86_64_X87UP_CLASS
338 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
339 classes
[i
] = X86_64_SSE_CLASS
;
348 if (!(bit_offset
% 64))
349 classes
[0] = X86_64_SSESF_CLASS
;
351 classes
[0] = X86_64_SSE_CLASS
;
354 classes
[0] = X86_64_SSEDF_CLASS
;
357 classes
[0] = X86_64_X87_CLASS
;
358 classes
[1] = X86_64_X87UP_CLASS
;
370 if (bytes
* 8 + bit_offset
<= 32)
371 classes
[0] = X86_64_INTEGERSI_CLASS
;
373 classes
[0] = X86_64_INTEGER_CLASS
;
376 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
384 internal_error (__FILE__
, __LINE__
, "classify_argument: unknown argument type");
387 /* Examine the argument and return set number of register required in each
388 class. Return 0 ifif parameter should be passed in memory. */
391 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
392 int n
, int *int_nregs
, int *sse_nregs
)
398 for (n
--; n
>= 0; n
--)
401 case X86_64_INTEGER_CLASS
:
402 case X86_64_INTEGERSI_CLASS
:
405 case X86_64_SSE_CLASS
:
406 case X86_64_SSESF_CLASS
:
407 case X86_64_SSEDF_CLASS
:
410 case X86_64_NO_CLASS
:
411 case X86_64_SSEUP_CLASS
:
412 case X86_64_X87_CLASS
:
413 case X86_64_X87UP_CLASS
:
415 case X86_64_MEMORY_CLASS
:
416 internal_error (__FILE__
, __LINE__
, "examine_argument: unexpected memory class");
421 #define RET_INT_REGS 2
422 #define RET_SSE_REGS 2
424 /* Check if the structure in value_type is returned in registers or in
425 memory. If this function returns 1, gdb will call STORE_STRUCT_RETURN and
426 EXTRACT_STRUCT_VALUE_ADDRESS else STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE
429 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
431 enum x86_64_reg_class
class[MAX_CLASSES
];
432 int n
= classify_argument (value_type
, class, 0);
437 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
438 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
442 /* Extract from an array REGBUF containing the (raw) register state, a
443 function return value of TYPE, and copy that, in virtual format,
447 x86_64_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
449 enum x86_64_reg_class
class[MAX_CLASSES
];
450 int n
= classify_argument (type
, class, 0);
456 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
457 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
460 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
461 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
464 memcpy (&addr
, regbuf
, REGISTER_RAW_SIZE (RAX_REGNUM
));
465 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
471 for (i
= 0; i
< n
; i
++)
475 case X86_64_NO_CLASS
:
477 case X86_64_INTEGER_CLASS
:
478 memcpy (valbuf
+ offset
,
479 regbuf
+ REGISTER_BYTE (ret_int_r
[(intreg
+ 1) / 2]),
484 case X86_64_INTEGERSI_CLASS
:
485 memcpy (valbuf
+ offset
,
486 regbuf
+ REGISTER_BYTE (ret_int_r
[intreg
/ 2]), 4);
490 case X86_64_SSEDF_CLASS
:
491 case X86_64_SSESF_CLASS
:
492 case X86_64_SSE_CLASS
:
493 memcpy (valbuf
+ offset
,
494 regbuf
+ REGISTER_BYTE (ret_sse_r
[(ssereg
+ 1) / 2]),
499 case X86_64_SSEUP_CLASS
:
500 memcpy (valbuf
+ offset
+ 8,
501 regbuf
+ REGISTER_BYTE (ret_sse_r
[ssereg
/ 2]), 8);
505 case X86_64_X87_CLASS
:
506 memcpy (valbuf
+ offset
, regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
510 case X86_64_X87UP_CLASS
:
511 memcpy (valbuf
+ offset
,
512 regbuf
+ REGISTER_BYTE (FP0_REGNUM
) + 8, 8);
515 case X86_64_MEMORY_CLASS
:
517 internal_error (__FILE__
, __LINE__
,
518 "Unexpected argument class");
524 /* Handled by unwind informations. */
526 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
533 /* Push onto the stack the specified value VALUE. Pad it correctly for
534 it to be an argument to a function. */
537 value_push (register CORE_ADDR sp
, struct value
*arg
)
539 register int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
540 register int container_len
= len
;
542 /* How big is the container we're going to put this value in? */
544 container_len
= ((len
+ PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1)
545 & ~(PARM_BOUNDARY
/ TARGET_CHAR_BIT
- 1));
548 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
554 x86_64_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
555 int struct_return
, CORE_ADDR struct_addr
)
560 static int int_parameter_registers
[INT_REGS
] = {5 /*RDI*/, 4 /*RSI*/,
561 1 /*RDX*/, 2 /*RCX*/,
562 8 /*R8 */, 9 /*R9 */};
564 static int sse_parameter_registers
[SSE_REGS
] = {34, 35, 36, 37,
568 for (i
= 0; i
< nargs
; i
++)
570 enum x86_64_reg_class
class[MAX_CLASSES
];
571 int n
= classify_argument (args
[i
]->type
, class, 0);
576 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
577 || intreg
+ needed_intregs
> INT_REGS
578 || ssereg
+ needed_sseregs
> SSE_REGS
)
580 sp
= value_push (sp
, args
[i
]);
585 for (j
= 0; j
< n
; j
++)
590 case X86_64_NO_CLASS
:
592 case X86_64_INTEGER_CLASS
:
593 write_register_gen (int_parameter_registers
[(intreg
+ 1) / 2],
594 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
598 case X86_64_INTEGERSI_CLASS
:
599 write_register_gen (int_parameter_registers
[intreg
/ 2],
600 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
604 case X86_64_SSEDF_CLASS
:
605 case X86_64_SSESF_CLASS
:
606 case X86_64_SSE_CLASS
:
607 write_register_gen (sse_parameter_registers
[(ssereg
+ 1) / 2],
608 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
612 case X86_64_SSEUP_CLASS
:
613 write_register_gen (sse_parameter_registers
[ssereg
/ 2],
614 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
618 case X86_64_X87_CLASS
:
619 case X86_64_X87UP_CLASS
:
620 case X86_64_MEMORY_CLASS
:
621 sp
= value_push (sp
, args
[i
]);
624 internal_error (__FILE__
, __LINE__
,
625 "Unexpected argument class");
627 intreg
+= intreg
% 2;
628 ssereg
+= ssereg
% 2;
635 /* Write into the appropriate registers a function return value stored
636 in VALBUF of type TYPE, given in virtual format. */
638 x86_64_store_return_value (struct type
*type
, char *valbuf
)
640 int len
= TYPE_LENGTH (type
);
642 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
644 /* Floating-point return values can be found in %st(0). */
645 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
646 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
648 /* Copy straight over. */
649 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
654 char buf
[FPU_REG_RAW_SIZE
];
657 /* Convert the value found in VALBUF to the extended
658 floating point format used by the FPU. This is probably
659 not exactly how it would happen on the target itself, but
660 it is the best we can do. */
661 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
662 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
663 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
669 int low_size
= REGISTER_RAW_SIZE (0);
670 int high_size
= REGISTER_RAW_SIZE (1);
673 write_register_bytes (REGISTER_BYTE (0), valbuf
, len
);
674 else if (len
<= (low_size
+ high_size
))
676 write_register_bytes (REGISTER_BYTE (0), valbuf
, low_size
);
677 write_register_bytes (REGISTER_BYTE (1),
678 valbuf
+ low_size
, len
- low_size
);
681 internal_error (__FILE__
, __LINE__
,
682 "Cannot store return value of %d bytes long.", len
);
688 x86_64_register_name (int reg_nr
)
690 static char *register_names
[] = {
691 "rax", "rdx", "rcx", "rbx",
692 "rsi", "rdi", "rbp", "rsp",
693 "r8", "r9", "r10", "r11",
694 "r12", "r13", "r14", "r15",
696 "st0", "st1", "st2", "st3",
697 "st4", "st5", "st6", "st7",
698 "fctrl", "fstat", "ftag", "fiseg",
699 "fioff", "foseg", "fooff", "fop",
700 "xmm0", "xmm1", "xmm2", "xmm3",
701 "xmm4", "xmm5", "xmm6", "xmm7",
702 "xmm8", "xmm9", "xmm10", "xmm11",
703 "xmm12", "xmm13", "xmm14", "xmm15",
708 if (reg_nr
>= (sizeof (register_names
) / sizeof (*register_names
)))
710 return register_names
[reg_nr
];
715 /* We have two flavours of disassembly. The machinery on this page
716 deals with switching between those. */
719 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
721 if (disassembly_flavour
== att_flavour
)
722 return print_insn_i386_att (memaddr
, info
);
723 else if (disassembly_flavour
== intel_flavour
)
724 return print_insn_i386_intel (memaddr
, info
);
725 /* Never reached -- disassembly_flavour is always either att_flavour
727 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
731 /* Store the address of the place in which to copy the structure the
732 subroutine will return. This is called from call_function. */
734 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
736 write_register (RDI_REGNUM
, addr
);
740 x86_64_frameless_function_invocation (struct frame_info
*frame
)
745 /* On x86_64 there are no reasonable prologs. */
747 x86_64_skip_prologue (CORE_ADDR pc
)
752 /* Sequence of bytes for breakpoint instruction. */
753 static unsigned char *
754 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
756 static unsigned char breakpoint
[] = { 0xcc };
761 static struct gdbarch
*
762 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
764 struct gdbarch
*gdbarch
;
765 struct gdbarch_tdep
*tdep
;
767 /* Find a candidate among the list of pre-declared architectures. */
768 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
770 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
772 switch (info
.bfd_arch_info
->mach
)
774 case bfd_mach_x86_64
:
775 case bfd_mach_x86_64_intel_syntax
:
776 switch (gdbarch_bfd_arch_info (arches
->gdbarch
)->mach
)
778 case bfd_mach_x86_64
:
779 case bfd_mach_x86_64_intel_syntax
:
780 return arches
->gdbarch
;
781 case bfd_mach_i386_i386
:
782 case bfd_mach_i386_i8086
:
783 case bfd_mach_i386_i386_intel_syntax
:
786 internal_error (__FILE__
, __LINE__
,
787 "i386_gdbarch_init: unknown machine type");
790 case bfd_mach_i386_i386
:
791 case bfd_mach_i386_i8086
:
792 case bfd_mach_i386_i386_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
:
798 case bfd_mach_i386_i386
:
799 case bfd_mach_i386_i8086
:
800 case bfd_mach_i386_i386_intel_syntax
:
801 return arches
->gdbarch
;
803 internal_error (__FILE__
, __LINE__
,
804 "i386_gdbarch_init: unknown machine type");
808 internal_error (__FILE__
, __LINE__
,
809 "i386_gdbarch_init: unknown machine type");
813 tdep
= (struct gdbarch_tdep
*) xmalloc (sizeof (struct gdbarch_tdep
));
814 gdbarch
= gdbarch_alloc (&info
, tdep
);
816 switch (info
.bfd_arch_info
->mach
)
818 case bfd_mach_x86_64
:
819 case bfd_mach_x86_64_intel_syntax
:
820 tdep
->num_xmm_regs
= 16;
822 case bfd_mach_i386_i386
:
823 case bfd_mach_i386_i8086
:
824 case bfd_mach_i386_i386_intel_syntax
:
825 /* This is place for definition of i386 target vector. */
828 internal_error (__FILE__
, __LINE__
,
829 "i386_gdbarch_init: unknown machine type");
832 set_gdbarch_long_bit (gdbarch
, 64);
833 set_gdbarch_long_long_bit (gdbarch
, 64);
834 set_gdbarch_ptr_bit (gdbarch
, 64);
836 set_gdbarch_long_double_format (gdbarch
, &floatformat_i387_ext
);
838 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
839 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
840 set_gdbarch_register_size (gdbarch
, 8);
841 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
842 set_gdbarch_max_register_raw_size (gdbarch
, 16);
843 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
844 /* Total amount of space needed to store our copies of the machine's register
845 (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS + SIZEOF_SSE_REGS) */
846 set_gdbarch_register_bytes (gdbarch
,
847 (18 * 8) + (8 * 10) + (8 * 4) + (8 * 16 + 4));
848 set_gdbarch_register_virtual_size (gdbarch
, generic_register_virtual_size
);
849 set_gdbarch_max_register_virtual_size (gdbarch
, 16);
851 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
853 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
854 set_gdbarch_register_convert_to_virtual (gdbarch
,
855 x86_64_register_convert_to_virtual
);
856 set_gdbarch_register_convert_to_raw (gdbarch
,
857 x86_64_register_convert_to_raw
);
859 /* Register numbers of various important registers. */
860 set_gdbarch_sp_regnum (gdbarch
, 7); /* (rsp) Contains address of top of stack. */
861 set_gdbarch_fp_regnum (gdbarch
, 6); /* (rbp) */
862 set_gdbarch_pc_regnum (gdbarch
, 16); /* (rip) Contains program counter. */
864 set_gdbarch_fp0_regnum (gdbarch
, 18); /* First FPU floating-point register. */
866 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
867 set_gdbarch_write_fp (gdbarch
, cfi_write_fp
);
869 /* Discard from the stack the innermost frame, restoring all registers. */
870 set_gdbarch_pop_frame (gdbarch
, x86_64_pop_frame
);
872 /* FRAME_CHAIN takes a frame's nominal address and produces the frame's
874 set_gdbarch_frame_chain (gdbarch
, cfi_frame_chain
);
876 set_gdbarch_frameless_function_invocation (gdbarch
,
877 x86_64_frameless_function_invocation
);
878 set_gdbarch_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
880 set_gdbarch_frame_args_address (gdbarch
, default_frame_address
);
881 set_gdbarch_frame_locals_address (gdbarch
, default_frame_address
);
883 /* Return number of bytes at start of arglist that are not really args. */
884 set_gdbarch_frame_args_skip (gdbarch
, 8);
886 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
888 /* Frame pc initialization is handled by unwind informations. */
889 set_gdbarch_init_frame_pc (gdbarch
, cfi_init_frame_pc
);
891 /* Initialization of unwind informations. */
892 set_gdbarch_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
894 /* Getting saved registers is handled by unwind informations. */
895 set_gdbarch_get_saved_register (gdbarch
, cfi_get_saved_register
);
897 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
899 /* Cons up virtual frame pointer for trace */
900 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
903 set_gdbarch_frame_chain_valid (gdbarch
, generic_file_frame_chain_valid
);
905 set_gdbarch_use_generic_dummy_frames (gdbarch
, 1);
906 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
907 set_gdbarch_call_dummy_address (gdbarch
, entry_point_address
);
908 set_gdbarch_call_dummy_length (gdbarch
, 0);
909 set_gdbarch_call_dummy_breakpoint_offset (gdbarch
, 0);
910 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch
, 1);
911 set_gdbarch_pc_in_call_dummy (gdbarch
, pc_in_call_dummy_at_entry_point
);
912 set_gdbarch_call_dummy_words (gdbarch
, 0);
913 set_gdbarch_sizeof_call_dummy_words (gdbarch
, 0);
914 set_gdbarch_call_dummy_stack_adjust_p (gdbarch
, 0);
915 set_gdbarch_call_dummy_p (gdbarch
, 1);
916 set_gdbarch_call_dummy_start_offset (gdbarch
, 0);
917 set_gdbarch_push_dummy_frame (gdbarch
, generic_push_dummy_frame
);
918 set_gdbarch_fix_call_dummy (gdbarch
, generic_fix_call_dummy
);
919 set_gdbarch_push_return_address (gdbarch
, x86_64_push_return_address
);
920 set_gdbarch_push_arguments (gdbarch
, x86_64_push_arguments
);
922 /* Return number of args passed to a frame, no way to tell. */
923 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
924 /* Don't use default structure extract routine */
925 set_gdbarch_extract_struct_value_address (gdbarch
, 0);
927 /* If USE_STRUCT_CONVENTION retruns 0, then gdb uses STORE_RETURN_VALUE
928 and EXTRACT_RETURN_VALUE to store/fetch the functions return value. It is
929 the case when structure is returned in registers. */
930 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
932 /* Store the address of the place in which to copy the structure the
933 subroutine will return. This is called from call_function. */
934 set_gdbarch_store_struct_return (gdbarch
, x86_64_store_struct_return
);
936 /* Extract from an array REGBUF containing the (raw) register state
937 a function return value of type TYPE, and copy that, in virtual format,
939 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
942 /* Write into the appropriate registers a function return value stored
943 in VALBUF of type TYPE, given in virtual format. */
944 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
947 /* Offset from address of function to start of its code. */
948 set_gdbarch_function_start_offset (gdbarch
, 0);
950 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
952 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
954 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
956 set_gdbarch_breakpoint_from_pc (gdbarch
, x86_64_breakpoint_from_pc
);
959 /* Amount PC must be decremented by after a breakpoint. This is often the
960 number of bytes in BREAKPOINT but not always. */
961 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
963 /* Use dwarf2 debug frame informations. */
964 set_gdbarch_dwarf2_build_frame_info (gdbarch
, dwarf2_build_frame_info
);
969 _initialize_x86_64_tdep (void)
971 register_gdbarch_init (bfd_arch_i386
, i386_gdbarch_init
);
973 /* Initialize the table saying where each register starts in the
979 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
981 x86_64_register_byte_table
[i
] = offset
;
982 offset
+= x86_64_register_raw_size_table
[i
];
986 tm_print_insn
= gdb_print_insn_x86_64
;
987 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 3)->mach
;
989 /* Add the variable that controls the disassembly flavour. */
991 struct cmd_list_element
*new_cmd
;
993 new_cmd
= add_set_enum_cmd ("disassembly-flavour", no_class
,
994 valid_flavours
, &disassembly_flavour
, "\
995 Set the disassembly flavour, the valid values are \"att\" and \"intel\", \
996 and the default value is \"att\".", &setlist
);
997 add_show_from_set (new_cmd
, &showlist
);