1 /* Target-dependent code for the x86-64 for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003 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"
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
42 #define XMM1_REGNUM 39
51 /* x86_64_register_raw_size_table[i] is the number of bytes of storage in
52 GDB's register array occupied by register i. */
53 static struct register_info x86_64_register_info_table
[] = {
54 /* 0 */ {8, "rax", &builtin_type_int64
},
55 /* 1 */ {8, "rbx", &builtin_type_int64
},
56 /* 2 */ {8, "rcx", &builtin_type_int64
},
57 /* 3 */ {8, "rdx", &builtin_type_int64
},
58 /* 4 */ {8, "rsi", &builtin_type_int64
},
59 /* 5 */ {8, "rdi", &builtin_type_int64
},
60 /* 6 */ {8, "rbp", &builtin_type_void_func_ptr
},
61 /* 7 */ {8, "rsp", &builtin_type_void_func_ptr
},
62 /* 8 */ {8, "r8", &builtin_type_int64
},
63 /* 9 */ {8, "r9", &builtin_type_int64
},
64 /* 10 */ {8, "r10", &builtin_type_int64
},
65 /* 11 */ {8, "r11", &builtin_type_int64
},
66 /* 12 */ {8, "r12", &builtin_type_int64
},
67 /* 13 */ {8, "r13", &builtin_type_int64
},
68 /* 14 */ {8, "r14", &builtin_type_int64
},
69 /* 15 */ {8, "r15", &builtin_type_int64
},
70 /* 16 */ {8, "rip", &builtin_type_void_func_ptr
},
71 /* 17 */ {4, "eflags", &builtin_type_int32
},
72 /* 18 */ {4, "ds", &builtin_type_int32
},
73 /* 19 */ {4, "es", &builtin_type_int32
},
74 /* 20 */ {4, "fs", &builtin_type_int32
},
75 /* 21 */ {4, "gs", &builtin_type_int32
},
76 /* 22 */ {10, "st0", &builtin_type_i387_ext
},
77 /* 23 */ {10, "st1", &builtin_type_i387_ext
},
78 /* 24 */ {10, "st2", &builtin_type_i387_ext
},
79 /* 25 */ {10, "st3", &builtin_type_i387_ext
},
80 /* 26 */ {10, "st4", &builtin_type_i387_ext
},
81 /* 27 */ {10, "st5", &builtin_type_i387_ext
},
82 /* 28 */ {10, "st6", &builtin_type_i387_ext
},
83 /* 29 */ {10, "st7", &builtin_type_i387_ext
},
84 /* 30 */ {4, "fctrl", &builtin_type_int32
},
85 /* 31 */ {4, "fstat", &builtin_type_int32
},
86 /* 32 */ {4, "ftag", &builtin_type_int32
},
87 /* 33 */ {4, "fiseg", &builtin_type_int32
},
88 /* 34 */ {4, "fioff", &builtin_type_int32
},
89 /* 35 */ {4, "foseg", &builtin_type_int32
},
90 /* 36 */ {4, "fooff", &builtin_type_int32
},
91 /* 37 */ {4, "fop", &builtin_type_int32
},
92 /* 38 */ {16, "xmm0", &builtin_type_v4sf
},
93 /* 39 */ {16, "xmm1", &builtin_type_v4sf
},
94 /* 40 */ {16, "xmm2", &builtin_type_v4sf
},
95 /* 41 */ {16, "xmm3", &builtin_type_v4sf
},
96 /* 42 */ {16, "xmm4", &builtin_type_v4sf
},
97 /* 43 */ {16, "xmm5", &builtin_type_v4sf
},
98 /* 44 */ {16, "xmm6", &builtin_type_v4sf
},
99 /* 45 */ {16, "xmm7", &builtin_type_v4sf
},
100 /* 46 */ {16, "xmm8", &builtin_type_v4sf
},
101 /* 47 */ {16, "xmm9", &builtin_type_v4sf
},
102 /* 48 */ {16, "xmm10", &builtin_type_v4sf
},
103 /* 49 */ {16, "xmm11", &builtin_type_v4sf
},
104 /* 50 */ {16, "xmm12", &builtin_type_v4sf
},
105 /* 51 */ {16, "xmm13", &builtin_type_v4sf
},
106 /* 52 */ {16, "xmm14", &builtin_type_v4sf
},
107 /* 53 */ {16, "xmm15", &builtin_type_v4sf
},
108 /* 54 */ {4, "mxcsr", &builtin_type_int32
}
111 /* This array is a mapping from Dwarf-2 register
112 numbering to GDB's one. Dwarf-2 numbering is
113 defined in x86-64 ABI, section 3.6. */
114 static int x86_64_dwarf2gdb_regno_map
[] = {
115 0, 1, 2, 3, /* RAX - RDX */
116 4, 5, 6, 7, /* RSI, RDI, RBP, RSP */
117 8, 9, 10, 11, /* R8 - R11 */
118 12, 13, 14, 15, /* R12 - R15 */
119 -1, /* RA - not mapped */
120 XMM1_REGNUM
- 1, XMM1_REGNUM
, /* XMM0 ... */
121 XMM1_REGNUM
+ 1, XMM1_REGNUM
+ 2,
122 XMM1_REGNUM
+ 3, XMM1_REGNUM
+ 4,
123 XMM1_REGNUM
+ 5, XMM1_REGNUM
+ 6,
124 XMM1_REGNUM
+ 7, XMM1_REGNUM
+ 8,
125 XMM1_REGNUM
+ 9, XMM1_REGNUM
+ 10,
126 XMM1_REGNUM
+ 11, XMM1_REGNUM
+ 12,
127 XMM1_REGNUM
+ 13, XMM1_REGNUM
+ 14, /* ... XMM15 */
128 ST0_REGNUM
+ 0, ST0_REGNUM
+ 1, /* ST0 ... */
129 ST0_REGNUM
+ 2, ST0_REGNUM
+ 3,
130 ST0_REGNUM
+ 4, ST0_REGNUM
+ 5,
131 ST0_REGNUM
+ 6, ST0_REGNUM
+ 7 /* ... ST7 */
134 static int x86_64_dwarf2gdb_regno_map_length
=
135 sizeof (x86_64_dwarf2gdb_regno_map
) /
136 sizeof (x86_64_dwarf2gdb_regno_map
[0]);
138 /* Number of all registers */
139 #define X86_64_NUM_REGS (sizeof (x86_64_register_info_table) / \
140 sizeof (x86_64_register_info_table[0]))
142 /* Number of general registers. */
143 #define X86_64_NUM_GREGS (22)
145 int x86_64_num_regs
= X86_64_NUM_REGS
;
146 int x86_64_num_gregs
= X86_64_NUM_GREGS
;
148 /* Did we already print a note about frame pointer? */
149 int omit_fp_note_printed
= 0;
151 /* Number of bytes of storage in the actual machine representation for
154 x86_64_register_raw_size (int regno
)
156 return x86_64_register_info_table
[regno
].size
;
159 /* x86_64_register_byte_table[i] is the offset into the register file of the
160 start of register number i. We initialize this from
161 x86_64_register_info_table. */
162 int x86_64_register_byte_table
[X86_64_NUM_REGS
];
164 /* Index within `registers' of the first byte of the space for register REGNO. */
166 x86_64_register_byte (int regno
)
168 return x86_64_register_byte_table
[regno
];
171 /* Return the GDB type object for the "standard" data type of data in
174 x86_64_register_virtual_type (int regno
)
176 return *x86_64_register_info_table
[regno
].type
;
179 /* x86_64_register_convertible is true if register N's virtual format is
180 different from its raw format. Note that this definition assumes
181 that the host supports IEEE 32-bit floats, since it doesn't say
182 that SSE registers need conversion. Even if we can't find a
183 counterexample, this is still sloppy. */
185 x86_64_register_convertible (int regno
)
187 return IS_FP_REGNUM (regno
);
190 /* Convert data from raw format for register REGNUM in buffer FROM to
191 virtual format with type TYPE in buffer TO. In principle both
192 formats are identical except that the virtual format has two extra
193 bytes appended that aren't used. We set these to zero. */
195 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
196 char *from
, char *to
)
200 /* We only support floating-point values. */
201 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
203 warning ("Cannot convert floating-point register value "
204 "to non-floating-point type.");
205 memset (to
, 0, TYPE_LENGTH (type
));
208 /* First add the necessary padding. */
209 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
210 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
211 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
212 to the extended floating-point format used by the FPU. */
213 convert_typed_floating (to
, type
, buf
,
214 x86_64_register_virtual_type (regnum
));
217 /* Convert data from virtual format with type TYPE in buffer FROM to
218 raw format for register REGNUM in buffer TO. Simply omit the two
222 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
223 char *from
, char *to
)
225 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 12);
226 /* Simply omit the two unused bytes. */
227 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
230 /* Dwarf-2 <-> GDB register numbers mapping. */
232 x86_64_dwarf2_reg_to_regnum (int dw_reg
)
234 if (dw_reg
< 0 || dw_reg
> x86_64_dwarf2gdb_regno_map_length
)
236 warning ("Dwarf-2 uses unmapped register #%d\n", dw_reg
);
240 return x86_64_dwarf2gdb_regno_map
[dw_reg
];
243 /* This is the variable that is set with "set disassembly-flavour", and
244 its legitimate values. */
245 static const char att_flavour
[] = "att";
246 static const char intel_flavour
[] = "intel";
247 static const char *valid_flavours
[] = {
252 static const char *disassembly_flavour
= att_flavour
;
254 /* Push the return address (pointing to the call dummy) onto the stack
255 and return the new value for the stack pointer. */
258 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
262 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
263 write_memory (sp
- 8, buf
, 8);
268 x86_64_pop_frame (void)
270 generic_pop_current_frame (cfi_pop_frame
);
274 /* The returning of values is done according to the special algorithm.
275 Some types are returned in registers an some (big structures) in memory.
279 #define MAX_CLASSES 4
281 enum x86_64_reg_class
284 X86_64_INTEGER_CLASS
,
285 X86_64_INTEGERSI_CLASS
,
295 /* Return the union class of CLASS1 and CLASS2.
296 See the x86-64 ABI for details. */
298 static enum x86_64_reg_class
299 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
301 /* Rule #1: If both classes are equal, this is the resulting class. */
302 if (class1
== class2
)
305 /* Rule #2: If one of the classes is NO_CLASS, the resulting class
306 is the other class. */
307 if (class1
== X86_64_NO_CLASS
)
309 if (class2
== X86_64_NO_CLASS
)
312 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
313 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
314 return X86_64_MEMORY_CLASS
;
316 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
317 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
318 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
319 return X86_64_INTEGERSI_CLASS
;
320 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
321 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
322 return X86_64_INTEGER_CLASS
;
324 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
325 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
326 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
327 return X86_64_MEMORY_CLASS
;
329 /* Rule #6: Otherwise class SSE is used. */
330 return X86_64_SSE_CLASS
;
333 /* Classify the argument type. CLASSES will be filled by the register
334 class used to pass each word of the operand. The number of words
335 is returned. In case the parameter should be passed in memory, 0
336 is returned. As a special case for zero sized containers,
337 classes[0] will be NO_CLASS and 1 is returned.
339 See the x86-64 psABI for details. */
342 classify_argument (struct type
*type
,
343 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
345 int bytes
= TYPE_LENGTH (type
);
346 int words
= (bytes
+ 8 - 1) / 8;
348 switch (TYPE_CODE (type
))
350 case TYPE_CODE_ARRAY
:
351 case TYPE_CODE_STRUCT
:
352 case TYPE_CODE_UNION
:
355 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
357 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
361 for (i
= 0; i
< words
; i
++)
362 classes
[i
] = X86_64_NO_CLASS
;
364 /* Zero sized arrays or structures are NO_CLASS. We return 0
365 to signalize memory class, so handle it as special case. */
368 classes
[0] = X86_64_NO_CLASS
;
371 switch (TYPE_CODE (type
))
373 case TYPE_CODE_STRUCT
:
376 for (j
= 0; j
< TYPE_NFIELDS (type
); ++j
)
378 int num
= classify_argument (TYPE_FIELDS (type
)[j
].type
,
380 (TYPE_FIELDS (type
)[j
].loc
.
381 bitpos
+ bit_offset
) % 256);
384 for (i
= 0; i
< num
; i
++)
387 (TYPE_FIELDS (type
)[j
].loc
.bitpos
+
390 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
395 case TYPE_CODE_ARRAY
:
399 num
= classify_argument (TYPE_TARGET_TYPE (type
),
400 subclasses
, bit_offset
);
404 /* The partial classes are now full classes. */
405 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
406 subclasses
[0] = X86_64_SSE_CLASS
;
407 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
408 subclasses
[0] = X86_64_INTEGER_CLASS
;
410 for (i
= 0; i
< words
; i
++)
411 classes
[i
] = subclasses
[i
% num
];
414 case TYPE_CODE_UNION
:
418 for (j
= 0; j
< TYPE_NFIELDS (type
); ++j
)
421 num
= classify_argument (TYPE_FIELDS (type
)[j
].type
,
422 subclasses
, bit_offset
);
425 for (i
= 0; i
< num
; i
++)
426 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
434 /* Final merger cleanup. */
435 for (i
= 0; i
< words
; i
++)
437 /* If one class is MEMORY, everything should be passed in
439 if (classes
[i
] == X86_64_MEMORY_CLASS
)
442 /* The X86_64_SSEUP_CLASS should be always preceeded by
444 if (classes
[i
] == X86_64_SSEUP_CLASS
445 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
446 classes
[i
] = X86_64_SSE_CLASS
;
448 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
449 if (classes
[i
] == X86_64_X87UP_CLASS
450 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
451 classes
[i
] = X86_64_SSE_CLASS
;
460 if (!(bit_offset
% 64))
461 classes
[0] = X86_64_SSESF_CLASS
;
463 classes
[0] = X86_64_SSE_CLASS
;
466 classes
[0] = X86_64_SSEDF_CLASS
;
469 classes
[0] = X86_64_X87_CLASS
;
470 classes
[1] = X86_64_X87UP_CLASS
;
482 if (bytes
* 8 + bit_offset
<= 32)
483 classes
[0] = X86_64_INTEGERSI_CLASS
;
485 classes
[0] = X86_64_INTEGER_CLASS
;
488 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
495 default: /* Avoid warning. */
498 internal_error (__FILE__
, __LINE__
,
499 "classify_argument: unknown argument type");
502 /* Examine the argument and set *INT_NREGS and *SSE_NREGS to the
503 number of registers required based on the information passed in
504 CLASSES. Return 0 if parameter should be passed in memory. */
507 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
508 int n
, int *int_nregs
, int *sse_nregs
)
514 for (n
--; n
>= 0; n
--)
517 case X86_64_INTEGER_CLASS
:
518 case X86_64_INTEGERSI_CLASS
:
521 case X86_64_SSE_CLASS
:
522 case X86_64_SSESF_CLASS
:
523 case X86_64_SSEDF_CLASS
:
526 case X86_64_NO_CLASS
:
527 case X86_64_SSEUP_CLASS
:
528 case X86_64_X87_CLASS
:
529 case X86_64_X87UP_CLASS
:
531 case X86_64_MEMORY_CLASS
:
532 internal_error (__FILE__
, __LINE__
,
533 "examine_argument: unexpected memory class");
538 #define RET_INT_REGS 2
539 #define RET_SSE_REGS 2
541 /* Check if the structure in value_type is returned in registers or in
542 memory. If this function returns 1, GDB will call
543 STORE_STRUCT_RETURN and EXTRACT_STRUCT_VALUE_ADDRESS else
544 STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE will be used. */
546 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
548 enum x86_64_reg_class
class[MAX_CLASSES
];
549 int n
= classify_argument (value_type
, class, 0);
554 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
555 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
558 /* Extract from an array REGBUF containing the (raw) register state, a
559 function return value of TYPE, and copy that, in virtual format,
563 x86_64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
566 enum x86_64_reg_class
class[MAX_CLASSES
];
567 int n
= classify_argument (type
, class, 0);
573 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
574 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
577 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
578 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
581 regcache_cooked_read (regcache
, RAX_REGNUM
, &addr
);
582 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
588 for (i
= 0; i
< n
; i
++)
592 case X86_64_NO_CLASS
:
594 case X86_64_INTEGER_CLASS
:
595 regcache_cooked_read (regcache
, ret_int_r
[(intreg
+ 1) / 2],
596 (char *) valbuf
+ offset
);
600 case X86_64_INTEGERSI_CLASS
:
601 regcache_cooked_read_part (regcache
, ret_int_r
[intreg
/ 2],
602 0, 4, (char *) valbuf
+ offset
);
606 case X86_64_SSEDF_CLASS
:
607 case X86_64_SSESF_CLASS
:
608 case X86_64_SSE_CLASS
:
609 regcache_cooked_read_part (regcache
,
610 ret_sse_r
[(ssereg
+ 1) / 2], 0, 8,
611 (char *) valbuf
+ offset
);
615 case X86_64_SSEUP_CLASS
:
616 regcache_cooked_read_part (regcache
, ret_sse_r
[ssereg
/ 2],
617 0, 8, (char *) valbuf
+ offset
);
621 case X86_64_X87_CLASS
:
622 regcache_cooked_read_part (regcache
, FP0_REGNUM
,
623 0, 8, (char *) valbuf
+ offset
);
626 case X86_64_X87UP_CLASS
:
627 regcache_cooked_read_part (regcache
, FP0_REGNUM
,
628 8, 2, (char *) valbuf
+ offset
);
631 case X86_64_MEMORY_CLASS
:
633 internal_error (__FILE__
, __LINE__
,
634 "Unexpected argument class");
641 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
643 /* Do nothing. Everything is handled by the stack unwinding code. */
650 x86_64_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
651 int struct_return
, CORE_ADDR struct_addr
)
656 static int int_parameter_registers
[INT_REGS
] = {
657 5 /* RDI */ , 4 /* RSI */ ,
658 3 /* RDX */ , 2 /* RCX */ ,
659 8 /* R8 */ , 9 /* R9 */
662 static int sse_parameter_registers
[SSE_REGS
] = {
663 XMM1_REGNUM
- 1, XMM1_REGNUM
, XMM1_REGNUM
+ 1, XMM1_REGNUM
+ 2,
664 XMM1_REGNUM
+ 3, XMM1_REGNUM
+ 4, XMM1_REGNUM
+ 5, XMM1_REGNUM
+ 6,
665 XMM1_REGNUM
+ 7, XMM1_REGNUM
+ 8, XMM1_REGNUM
+ 9, XMM1_REGNUM
+ 10,
666 XMM1_REGNUM
+ 11, XMM1_REGNUM
+ 12, XMM1_REGNUM
+ 13, XMM1_REGNUM
+ 14
668 int stack_values_count
= 0;
670 stack_values
= alloca (nargs
* sizeof (int));
671 for (i
= 0; i
< nargs
; i
++)
673 enum x86_64_reg_class
class[MAX_CLASSES
];
674 int n
= classify_argument (args
[i
]->type
, class, 0);
679 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
680 || intreg
/ 2 + needed_intregs
> INT_REGS
681 || ssereg
/ 2 + needed_sseregs
> SSE_REGS
)
683 stack_values
[stack_values_count
++] = i
;
688 for (j
= 0; j
< n
; j
++)
693 case X86_64_NO_CLASS
:
695 case X86_64_INTEGER_CLASS
:
696 deprecated_write_register_gen (int_parameter_registers
698 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
702 case X86_64_INTEGERSI_CLASS
:
703 deprecated_write_register_gen (int_parameter_registers
[intreg
/ 2],
704 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
708 case X86_64_SSEDF_CLASS
:
709 case X86_64_SSESF_CLASS
:
710 case X86_64_SSE_CLASS
:
711 deprecated_write_register_gen (sse_parameter_registers
713 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
717 case X86_64_SSEUP_CLASS
:
718 deprecated_write_register_gen (sse_parameter_registers
[ssereg
/ 2],
719 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
723 case X86_64_X87_CLASS
:
724 case X86_64_MEMORY_CLASS
:
725 stack_values
[stack_values_count
++] = i
;
727 case X86_64_X87UP_CLASS
:
730 internal_error (__FILE__
, __LINE__
,
731 "Unexpected argument class");
733 intreg
+= intreg
% 2;
734 ssereg
+= ssereg
% 2;
738 while (--stack_values_count
>= 0)
740 struct value
*arg
= args
[stack_values
[stack_values_count
]];
741 int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
745 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
750 /* Write into the appropriate registers a function return value stored
751 in VALBUF of type TYPE, given in virtual format. */
753 x86_64_store_return_value (struct type
*type
, struct regcache
*regcache
,
756 int len
= TYPE_LENGTH (type
);
758 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
760 /* Floating-point return values can be found in %st(0). */
761 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
762 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
764 /* Copy straight over. */
765 regcache_cooked_write (regcache
, FP0_REGNUM
, valbuf
);
769 char buf
[FPU_REG_RAW_SIZE
];
772 /* Convert the value found in VALBUF to the extended
773 floating point format used by the FPU. This is probably
774 not exactly how it would happen on the target itself, but
775 it is the best we can do. */
776 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
777 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
778 regcache_cooked_write_part (regcache
, FP0_REGNUM
,
779 0, FPU_REG_RAW_SIZE
, buf
);
784 int low_size
= REGISTER_RAW_SIZE (0);
785 int high_size
= REGISTER_RAW_SIZE (1);
788 regcache_cooked_write_part (regcache
, 0, 0, len
, valbuf
);
789 else if (len
<= (low_size
+ high_size
))
791 regcache_cooked_write_part (regcache
, 0, 0, low_size
, valbuf
);
792 regcache_cooked_write_part (regcache
, 1, 0,
794 (const char *) valbuf
+ low_size
);
797 internal_error (__FILE__
, __LINE__
,
798 "Cannot store return value of %d bytes long.", len
);
804 x86_64_register_name (int reg_nr
)
806 if (reg_nr
< 0 || reg_nr
>= X86_64_NUM_REGS
)
808 return x86_64_register_info_table
[reg_nr
].name
;
812 x86_64_register_number (const char *name
)
816 for (reg_nr
= 0; reg_nr
< X86_64_NUM_REGS
; reg_nr
++)
817 if (strcmp (name
, x86_64_register_info_table
[reg_nr
].name
) == 0)
824 /* We have two flavours of disassembly. The machinery on this page
825 deals with switching between those. */
828 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
830 if (disassembly_flavour
== att_flavour
)
831 return print_insn_i386_att (memaddr
, info
);
832 else if (disassembly_flavour
== intel_flavour
)
833 return print_insn_i386_intel (memaddr
, info
);
834 /* Never reached -- disassembly_flavour is always either att_flavour
836 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
840 /* Store the address of the place in which to copy the structure the
841 subroutine will return. This is called from call_function. */
843 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
845 write_register (RDI_REGNUM
, addr
);
849 x86_64_frameless_function_invocation (struct frame_info
*frame
)
854 /* We will handle only functions beginning with:
856 48 89 e5 movq %rsp,%rbp
857 Any function that doesn't start with this sequence
858 will be assumed to have no prologue and thus no valid
859 frame pointer in %rbp. */
860 #define PROLOG_BUFSIZE 4
862 x86_64_function_has_prologue (CORE_ADDR pc
)
865 unsigned char prolog_expect
[PROLOG_BUFSIZE
] = { 0x55, 0x48, 0x89, 0xe5 },
866 prolog_buf
[PROLOG_BUFSIZE
];
868 read_memory (pc
, (char *) prolog_buf
, PROLOG_BUFSIZE
);
870 /* First check, whether pc points to pushq %rbp, movq %rsp,%rbp. */
871 for (i
= 0; i
< PROLOG_BUFSIZE
; i
++)
872 if (prolog_expect
[i
] != prolog_buf
[i
])
873 return 0; /* ... no, it doesn't. Nothing to skip. */
878 /* If a function with debugging information and known beginning
879 is detected, we will return pc of the next line in the source
880 code. With this approach we effectively skip the prolog. */
883 x86_64_skip_prologue (CORE_ADDR pc
)
886 struct symtab_and_line v_sal
;
887 struct symbol
*v_function
;
890 if (! x86_64_function_has_prologue (pc
))
893 /* OK, we have found the prologue and want PC of the first
894 non-prologue instruction. */
895 pc
+= PROLOG_BUFSIZE
;
897 v_function
= find_pc_function (pc
);
898 v_sal
= find_pc_line (pc
, 0);
900 /* If pc doesn't point to a function with debuginfo, some of the
901 following may be NULL. */
902 if (!v_function
|| !v_function
->ginfo
.value
.block
|| !v_sal
.symtab
)
905 endaddr
= BLOCK_END (SYMBOL_BLOCK_VALUE (v_function
));
907 for (i
= 0; i
< v_sal
.symtab
->linetable
->nitems
; i
++)
908 if (v_sal
.symtab
->linetable
->item
[i
].pc
>= pc
909 && v_sal
.symtab
->linetable
->item
[i
].pc
< endaddr
)
911 pc
= v_sal
.symtab
->linetable
->item
[i
].pc
;
918 /* Sequence of bytes for breakpoint instruction. */
919 static const unsigned char *
920 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
922 static unsigned char breakpoint
[] = { 0xcc };
928 x86_64_save_dummy_frame_tos (CORE_ADDR sp
)
930 /* We must add the size of the return address that is already
932 generic_save_dummy_frame_tos (sp
+
933 TYPE_LENGTH (builtin_type_void_func_ptr
));
936 static struct frame_id
937 x86_64_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*frame
)
941 id
.pc
= frame_pc_unwind (frame
);
942 frame_unwind_unsigned_register (frame
, SP_REGNUM
, &id
.base
);
948 x86_64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
950 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
953 /* The x86-64 has 16 SSE registers. */
954 tdep
->num_xmm_regs
= 16;
956 /* This is what all the fuss is about. */
957 set_gdbarch_long_bit (gdbarch
, 64);
958 set_gdbarch_long_long_bit (gdbarch
, 64);
959 set_gdbarch_ptr_bit (gdbarch
, 64);
961 /* In contrast to the i386, on the x86-64 a `long double' actually
962 takes up 128 bits, even though it's still based on the i387
963 extended floating-point format which has only 80 significant bits. */
964 set_gdbarch_long_double_bit (gdbarch
, 128);
966 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
968 /* Register numbers of various important registers. */
969 set_gdbarch_sp_regnum (gdbarch
, 7); /* %rsp */
970 set_gdbarch_fp_regnum (gdbarch
, 6); /* %rbp */
971 set_gdbarch_pc_regnum (gdbarch
, 16); /* %rip */
972 set_gdbarch_ps_regnum (gdbarch
, 17); /* %eflags */
973 set_gdbarch_fp0_regnum (gdbarch
, X86_64_NUM_GREGS
); /* %st(0) */
975 /* The "default" register numbering scheme for the x86-64 is
976 referred to as the "DWARF register number mapping" in the psABI.
977 The preferred debugging format for all known x86-64 targets is
978 actually DWARF2, and GCC doesn't seem to support DWARF (that is
979 DWARF-1), but we provide the same mapping just in case. This
980 mapping is also used for stabs, which GCC does support. */
981 set_gdbarch_stab_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
982 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
983 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
985 /* We don't override SDB_REG_RO_REGNUM, sice COFF doesn't seem to be
986 in use on any of the supported x86-64 targets. */
988 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
989 set_gdbarch_register_size (gdbarch
, 8);
991 /* Total amount of space needed to store our copies of the machine's
992 register (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS +
994 for (i
= 0, sum
= 0; i
< X86_64_NUM_REGS
; i
++)
995 sum
+= x86_64_register_info_table
[i
].size
;
996 set_gdbarch_register_bytes (gdbarch
, sum
);
998 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
999 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
1000 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
1002 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
1003 set_gdbarch_register_convert_to_virtual (gdbarch
,
1004 x86_64_register_convert_to_virtual
);
1005 set_gdbarch_register_convert_to_raw (gdbarch
,
1006 x86_64_register_convert_to_raw
);
1008 /* Getting saved registers is handled by unwind information. */
1009 set_gdbarch_deprecated_get_saved_register (gdbarch
, cfi_get_saved_register
);
1011 /* FIXME: kettenis/20021026: Should we set parm_boundary to 64 here? */
1012 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
1014 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
1016 set_gdbarch_deprecated_push_arguments (gdbarch
, x86_64_push_arguments
);
1017 set_gdbarch_deprecated_push_return_address (gdbarch
, x86_64_push_return_address
);
1018 set_gdbarch_deprecated_pop_frame (gdbarch
, x86_64_pop_frame
);
1019 set_gdbarch_deprecated_store_struct_return (gdbarch
, x86_64_store_struct_return
);
1020 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
1021 /* Override, since this is handled by x86_64_extract_return_value. */
1022 set_gdbarch_extract_struct_value_address (gdbarch
, NULL
);
1023 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
1025 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
1026 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
1028 set_gdbarch_deprecated_frame_chain (gdbarch
, x86_64_linux_frame_chain
);
1029 set_gdbarch_frameless_function_invocation (gdbarch
,
1030 x86_64_frameless_function_invocation
);
1031 /* FIXME: kettenis/20021026: These two are GNU/Linux-specific and
1032 should be moved elsewhere. */
1033 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
1034 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
1035 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
1036 /* FIXME: kettenis/20021026: This one is GNU/Linux-specific too. */
1037 set_gdbarch_pc_in_sigtramp (gdbarch
, x86_64_linux_in_sigtramp
);
1039 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1041 /* Build call frame information (CFI) from DWARF2 frame debug info. */
1042 set_gdbarch_dwarf2_build_frame_info (gdbarch
, dwarf2_build_frame_info
);
1044 /* Initialization of per-frame CFI. */
1045 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
1047 /* Frame PC initialization is handled by using CFI. */
1048 set_gdbarch_deprecated_init_frame_pc (gdbarch
, x86_64_init_frame_pc
);
1050 /* Cons up virtual frame pointer for trace. */
1051 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
1053 /* FIXME: kettenis/20021026: This is ELF-specific. Fine for now,
1054 since all supported x86-64 targets are ELF, but that might change
1056 set_gdbarch_in_solib_call_trampoline (gdbarch
, in_plt_section
);
1058 /* Dummy frame helper functions. */
1059 set_gdbarch_save_dummy_frame_tos (gdbarch
, x86_64_save_dummy_frame_tos
);
1060 set_gdbarch_unwind_dummy_id (gdbarch
, x86_64_unwind_dummy_id
);
1064 _initialize_x86_64_tdep (void)
1066 /* Initialize the table saying where each register starts in the
1072 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
1074 x86_64_register_byte_table
[i
] = offset
;
1075 offset
+= x86_64_register_info_table
[i
].size
;