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"
35 /* Register numbers of various important registers. */
39 #define EFLAGS_REGNUM 17
41 #define XMM1_REGNUM 39
50 /* x86_64_register_raw_size_table[i] is the number of bytes of storage in
51 GDB's register array occupied by register i. */
52 static struct register_info x86_64_register_info_table
[] = {
53 /* 0 */ {8, "rax", &builtin_type_int64
},
54 /* 1 */ {8, "rbx", &builtin_type_int64
},
55 /* 2 */ {8, "rcx", &builtin_type_int64
},
56 /* 3 */ {8, "rdx", &builtin_type_int64
},
57 /* 4 */ {8, "rsi", &builtin_type_int64
},
58 /* 5 */ {8, "rdi", &builtin_type_int64
},
59 /* 6 */ {8, "rbp", &builtin_type_void_func_ptr
},
60 /* 7 */ {8, "rsp", &builtin_type_void_func_ptr
},
61 /* 8 */ {8, "r8", &builtin_type_int64
},
62 /* 9 */ {8, "r9", &builtin_type_int64
},
63 /* 10 */ {8, "r10", &builtin_type_int64
},
64 /* 11 */ {8, "r11", &builtin_type_int64
},
65 /* 12 */ {8, "r12", &builtin_type_int64
},
66 /* 13 */ {8, "r13", &builtin_type_int64
},
67 /* 14 */ {8, "r14", &builtin_type_int64
},
68 /* 15 */ {8, "r15", &builtin_type_int64
},
69 /* 16 */ {8, "rip", &builtin_type_void_func_ptr
},
70 /* 17 */ {4, "eflags", &builtin_type_int32
},
71 /* 18 */ {4, "ds", &builtin_type_int32
},
72 /* 19 */ {4, "es", &builtin_type_int32
},
73 /* 20 */ {4, "fs", &builtin_type_int32
},
74 /* 21 */ {4, "gs", &builtin_type_int32
},
75 /* 22 */ {10, "st0", &builtin_type_i387_ext
},
76 /* 23 */ {10, "st1", &builtin_type_i387_ext
},
77 /* 24 */ {10, "st2", &builtin_type_i387_ext
},
78 /* 25 */ {10, "st3", &builtin_type_i387_ext
},
79 /* 26 */ {10, "st4", &builtin_type_i387_ext
},
80 /* 27 */ {10, "st5", &builtin_type_i387_ext
},
81 /* 28 */ {10, "st6", &builtin_type_i387_ext
},
82 /* 29 */ {10, "st7", &builtin_type_i387_ext
},
83 /* 30 */ {4, "fctrl", &builtin_type_int32
},
84 /* 31 */ {4, "fstat", &builtin_type_int32
},
85 /* 32 */ {4, "ftag", &builtin_type_int32
},
86 /* 33 */ {4, "fiseg", &builtin_type_int32
},
87 /* 34 */ {4, "fioff", &builtin_type_int32
},
88 /* 35 */ {4, "foseg", &builtin_type_int32
},
89 /* 36 */ {4, "fooff", &builtin_type_int32
},
90 /* 37 */ {4, "fop", &builtin_type_int32
},
91 /* 38 */ {16, "xmm0", &builtin_type_v4sf
},
92 /* 39 */ {16, "xmm1", &builtin_type_v4sf
},
93 /* 40 */ {16, "xmm2", &builtin_type_v4sf
},
94 /* 41 */ {16, "xmm3", &builtin_type_v4sf
},
95 /* 42 */ {16, "xmm4", &builtin_type_v4sf
},
96 /* 43 */ {16, "xmm5", &builtin_type_v4sf
},
97 /* 44 */ {16, "xmm6", &builtin_type_v4sf
},
98 /* 45 */ {16, "xmm7", &builtin_type_v4sf
},
99 /* 46 */ {16, "xmm8", &builtin_type_v4sf
},
100 /* 47 */ {16, "xmm9", &builtin_type_v4sf
},
101 /* 48 */ {16, "xmm10", &builtin_type_v4sf
},
102 /* 49 */ {16, "xmm11", &builtin_type_v4sf
},
103 /* 50 */ {16, "xmm12", &builtin_type_v4sf
},
104 /* 51 */ {16, "xmm13", &builtin_type_v4sf
},
105 /* 52 */ {16, "xmm14", &builtin_type_v4sf
},
106 /* 53 */ {16, "xmm15", &builtin_type_v4sf
},
107 /* 54 */ {4, "mxcsr", &builtin_type_int32
}
110 /* This array is a mapping from Dwarf-2 register
111 numbering to GDB's one. Dwarf-2 numbering is
112 defined in x86-64 ABI, section 3.6. */
113 static int x86_64_dwarf2gdb_regno_map
[] = {
114 0, 1, 2, 3, /* RAX - RDX */
115 4, 5, 6, 7, /* RSI, RDI, RBP, RSP */
116 8, 9, 10, 11, /* R8 - R11 */
117 12, 13, 14, 15, /* R12 - R15 */
118 -1, /* RA - not mapped */
119 XMM1_REGNUM
- 1, XMM1_REGNUM
, /* XMM0 ... */
120 XMM1_REGNUM
+ 1, XMM1_REGNUM
+ 2,
121 XMM1_REGNUM
+ 3, XMM1_REGNUM
+ 4,
122 XMM1_REGNUM
+ 5, XMM1_REGNUM
+ 6,
123 XMM1_REGNUM
+ 7, XMM1_REGNUM
+ 8,
124 XMM1_REGNUM
+ 9, XMM1_REGNUM
+ 10,
125 XMM1_REGNUM
+ 11, XMM1_REGNUM
+ 12,
126 XMM1_REGNUM
+ 13, XMM1_REGNUM
+ 14, /* ... XMM15 */
127 ST0_REGNUM
+ 0, ST0_REGNUM
+ 1, /* ST0 ... */
128 ST0_REGNUM
+ 2, ST0_REGNUM
+ 3,
129 ST0_REGNUM
+ 4, ST0_REGNUM
+ 5,
130 ST0_REGNUM
+ 6, ST0_REGNUM
+ 7 /* ... ST7 */
133 static int x86_64_dwarf2gdb_regno_map_length
=
134 sizeof (x86_64_dwarf2gdb_regno_map
) /
135 sizeof (x86_64_dwarf2gdb_regno_map
[0]);
137 /* Number of all registers */
138 #define X86_64_NUM_REGS (sizeof (x86_64_register_info_table) / \
139 sizeof (x86_64_register_info_table[0]))
141 /* Number of general registers. */
142 #define X86_64_NUM_GREGS (22)
144 int x86_64_num_regs
= X86_64_NUM_REGS
;
145 int x86_64_num_gregs
= X86_64_NUM_GREGS
;
147 /* Did we already print a note about frame pointer? */
148 int omit_fp_note_printed
= 0;
150 /* Number of bytes of storage in the actual machine representation for
153 x86_64_register_raw_size (int regno
)
155 return x86_64_register_info_table
[regno
].size
;
158 /* x86_64_register_byte_table[i] is the offset into the register file of the
159 start of register number i. We initialize this from
160 x86_64_register_info_table. */
161 int x86_64_register_byte_table
[X86_64_NUM_REGS
];
163 /* Index within `registers' of the first byte of the space for register REGNO. */
165 x86_64_register_byte (int regno
)
167 return x86_64_register_byte_table
[regno
];
170 /* Return the GDB type object for the "standard" data type of data in
173 x86_64_register_virtual_type (int regno
)
175 return *x86_64_register_info_table
[regno
].type
;
178 /* x86_64_register_convertible is true if register N's virtual format is
179 different from its raw format. Note that this definition assumes
180 that the host supports IEEE 32-bit floats, since it doesn't say
181 that SSE registers need conversion. Even if we can't find a
182 counterexample, this is still sloppy. */
184 x86_64_register_convertible (int regno
)
186 return IS_FP_REGNUM (regno
);
189 /* Convert data from raw format for register REGNUM in buffer FROM to
190 virtual format with type TYPE in buffer TO. In principle both
191 formats are identical except that the virtual format has two extra
192 bytes appended that aren't used. We set these to zero. */
194 x86_64_register_convert_to_virtual (int regnum
, struct type
*type
,
195 char *from
, char *to
)
199 /* We only support floating-point values. */
200 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
202 warning ("Cannot convert floating-point register value "
203 "to non-floating-point type.");
204 memset (to
, 0, TYPE_LENGTH (type
));
207 /* First add the necessary padding. */
208 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
209 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
210 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
211 to the extended floating-point format used by the FPU. */
212 convert_typed_floating (to
, type
, buf
,
213 x86_64_register_virtual_type (regnum
));
216 /* Convert data from virtual format with type TYPE in buffer FROM to
217 raw format for register REGNUM in buffer TO. Simply omit the two
221 x86_64_register_convert_to_raw (struct type
*type
, int regnum
,
222 char *from
, char *to
)
224 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
&& TYPE_LENGTH (type
) == 12);
225 /* Simply omit the two unused bytes. */
226 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
229 /* Dwarf-2 <-> GDB register numbers mapping. */
231 x86_64_dwarf2_reg_to_regnum (int dw_reg
)
233 if (dw_reg
< 0 || dw_reg
> x86_64_dwarf2gdb_regno_map_length
)
235 warning ("Dwarf-2 uses unmapped register #%d\n", dw_reg
);
239 return x86_64_dwarf2gdb_regno_map
[dw_reg
];
242 /* This is the variable that is set with "set disassembly-flavour", and
243 its legitimate values. */
244 static const char att_flavour
[] = "att";
245 static const char intel_flavour
[] = "intel";
246 static const char *valid_flavours
[] = {
251 static const char *disassembly_flavour
= att_flavour
;
253 /* Push the return address (pointing to the call dummy) onto the stack
254 and return the new value for the stack pointer. */
257 x86_64_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
261 store_unsigned_integer (buf
, 8, CALL_DUMMY_ADDRESS ());
262 write_memory (sp
- 8, buf
, 8);
267 x86_64_pop_frame (void)
269 generic_pop_current_frame (cfi_pop_frame
);
273 /* The returning of values is done according to the special algorithm.
274 Some types are returned in registers an some (big structures) in memory.
278 #define MAX_CLASSES 4
280 enum x86_64_reg_class
283 X86_64_INTEGER_CLASS
,
284 X86_64_INTEGERSI_CLASS
,
294 /* Return the union class of CLASS1 and CLASS2.
295 See the x86-64 ABI for details. */
297 static enum x86_64_reg_class
298 merge_classes (enum x86_64_reg_class class1
, enum x86_64_reg_class class2
)
300 /* Rule #1: If both classes are equal, this is the resulting class. */
301 if (class1
== class2
)
304 /* Rule #2: If one of the classes is NO_CLASS, the resulting class
305 is the other class. */
306 if (class1
== X86_64_NO_CLASS
)
308 if (class2
== X86_64_NO_CLASS
)
311 /* Rule #3: If one of the classes is MEMORY, the result is MEMORY. */
312 if (class1
== X86_64_MEMORY_CLASS
|| class2
== X86_64_MEMORY_CLASS
)
313 return X86_64_MEMORY_CLASS
;
315 /* Rule #4: If one of the classes is INTEGER, the result is INTEGER. */
316 if ((class1
== X86_64_INTEGERSI_CLASS
&& class2
== X86_64_SSESF_CLASS
)
317 || (class2
== X86_64_INTEGERSI_CLASS
&& class1
== X86_64_SSESF_CLASS
))
318 return X86_64_INTEGERSI_CLASS
;
319 if (class1
== X86_64_INTEGER_CLASS
|| class1
== X86_64_INTEGERSI_CLASS
320 || class2
== X86_64_INTEGER_CLASS
|| class2
== X86_64_INTEGERSI_CLASS
)
321 return X86_64_INTEGER_CLASS
;
323 /* Rule #5: If one of the classes is X87 or X87UP class, MEMORY is used. */
324 if (class1
== X86_64_X87_CLASS
|| class1
== X86_64_X87UP_CLASS
325 || class2
== X86_64_X87_CLASS
|| class2
== X86_64_X87UP_CLASS
)
326 return X86_64_MEMORY_CLASS
;
328 /* Rule #6: Otherwise class SSE is used. */
329 return X86_64_SSE_CLASS
;
332 /* Classify the argument type. CLASSES will be filled by the register
333 class used to pass each word of the operand. The number of words
334 is returned. In case the parameter should be passed in memory, 0
335 is returned. As a special case for zero sized containers,
336 classes[0] will be NO_CLASS and 1 is returned.
338 See the x86-64 psABI for details. */
341 classify_argument (struct type
*type
,
342 enum x86_64_reg_class classes
[MAX_CLASSES
], int bit_offset
)
344 int bytes
= TYPE_LENGTH (type
);
345 int words
= (bytes
+ 8 - 1) / 8;
347 switch (TYPE_CODE (type
))
349 case TYPE_CODE_ARRAY
:
350 case TYPE_CODE_STRUCT
:
351 case TYPE_CODE_UNION
:
354 enum x86_64_reg_class subclasses
[MAX_CLASSES
];
356 /* On x86-64 we pass structures larger than 16 bytes on the stack. */
360 for (i
= 0; i
< words
; i
++)
361 classes
[i
] = X86_64_NO_CLASS
;
363 /* Zero sized arrays or structures are NO_CLASS. We return 0
364 to signalize memory class, so handle it as special case. */
367 classes
[0] = X86_64_NO_CLASS
;
370 switch (TYPE_CODE (type
))
372 case TYPE_CODE_STRUCT
:
375 for (j
= 0; j
< TYPE_NFIELDS (type
); ++j
)
377 int num
= classify_argument (TYPE_FIELDS (type
)[j
].type
,
379 (TYPE_FIELDS (type
)[j
].loc
.
380 bitpos
+ bit_offset
) % 256);
383 for (i
= 0; i
< num
; i
++)
386 (TYPE_FIELDS (type
)[j
].loc
.bitpos
+
389 merge_classes (subclasses
[i
], classes
[i
+ pos
]);
394 case TYPE_CODE_ARRAY
:
398 num
= classify_argument (TYPE_TARGET_TYPE (type
),
399 subclasses
, bit_offset
);
403 /* The partial classes are now full classes. */
404 if (subclasses
[0] == X86_64_SSESF_CLASS
&& bytes
!= 4)
405 subclasses
[0] = X86_64_SSE_CLASS
;
406 if (subclasses
[0] == X86_64_INTEGERSI_CLASS
&& bytes
!= 4)
407 subclasses
[0] = X86_64_INTEGER_CLASS
;
409 for (i
= 0; i
< words
; i
++)
410 classes
[i
] = subclasses
[i
% num
];
413 case TYPE_CODE_UNION
:
417 for (j
= 0; j
< TYPE_NFIELDS (type
); ++j
)
420 num
= classify_argument (TYPE_FIELDS (type
)[j
].type
,
421 subclasses
, bit_offset
);
424 for (i
= 0; i
< num
; i
++)
425 classes
[i
] = merge_classes (subclasses
[i
], classes
[i
]);
433 /* Final merger cleanup. */
434 for (i
= 0; i
< words
; i
++)
436 /* If one class is MEMORY, everything should be passed in
438 if (classes
[i
] == X86_64_MEMORY_CLASS
)
441 /* The X86_64_SSEUP_CLASS should be always preceeded by
443 if (classes
[i
] == X86_64_SSEUP_CLASS
444 && (i
== 0 || classes
[i
- 1] != X86_64_SSE_CLASS
))
445 classes
[i
] = X86_64_SSE_CLASS
;
447 /* X86_64_X87UP_CLASS should be preceeded by X86_64_X87_CLASS. */
448 if (classes
[i
] == X86_64_X87UP_CLASS
449 && (i
== 0 || classes
[i
- 1] != X86_64_X87_CLASS
))
450 classes
[i
] = X86_64_SSE_CLASS
;
459 if (!(bit_offset
% 64))
460 classes
[0] = X86_64_SSESF_CLASS
;
462 classes
[0] = X86_64_SSE_CLASS
;
465 classes
[0] = X86_64_SSEDF_CLASS
;
468 classes
[0] = X86_64_X87_CLASS
;
469 classes
[1] = X86_64_X87UP_CLASS
;
481 if (bytes
* 8 + bit_offset
<= 32)
482 classes
[0] = X86_64_INTEGERSI_CLASS
;
484 classes
[0] = X86_64_INTEGER_CLASS
;
487 classes
[0] = classes
[1] = X86_64_INTEGER_CLASS
;
494 default: /* Avoid warning. */
497 internal_error (__FILE__
, __LINE__
,
498 "classify_argument: unknown argument type");
501 /* Examine the argument and set *INT_NREGS and *SSE_NREGS to the
502 number of registers required based on the information passed in
503 CLASSES. Return 0 if parameter should be passed in memory. */
506 examine_argument (enum x86_64_reg_class classes
[MAX_CLASSES
],
507 int n
, int *int_nregs
, int *sse_nregs
)
513 for (n
--; n
>= 0; n
--)
516 case X86_64_INTEGER_CLASS
:
517 case X86_64_INTEGERSI_CLASS
:
520 case X86_64_SSE_CLASS
:
521 case X86_64_SSESF_CLASS
:
522 case X86_64_SSEDF_CLASS
:
525 case X86_64_NO_CLASS
:
526 case X86_64_SSEUP_CLASS
:
527 case X86_64_X87_CLASS
:
528 case X86_64_X87UP_CLASS
:
530 case X86_64_MEMORY_CLASS
:
531 internal_error (__FILE__
, __LINE__
,
532 "examine_argument: unexpected memory class");
537 #define RET_INT_REGS 2
538 #define RET_SSE_REGS 2
540 /* Check if the structure in value_type is returned in registers or in
541 memory. If this function returns 1, GDB will call
542 STORE_STRUCT_RETURN and EXTRACT_STRUCT_VALUE_ADDRESS else
543 STORE_RETURN_VALUE and EXTRACT_RETURN_VALUE will be used. */
545 x86_64_use_struct_convention (int gcc_p
, struct type
*value_type
)
547 enum x86_64_reg_class
class[MAX_CLASSES
];
548 int n
= classify_argument (value_type
, class, 0);
553 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
554 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
);
557 /* Extract from an array REGBUF containing the (raw) register state, a
558 function return value of TYPE, and copy that, in virtual format,
562 x86_64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
565 enum x86_64_reg_class
class[MAX_CLASSES
];
566 int n
= classify_argument (type
, class, 0);
572 int ret_int_r
[RET_INT_REGS
] = { RAX_REGNUM
, RDX_REGNUM
};
573 int ret_sse_r
[RET_SSE_REGS
] = { XMM0_REGNUM
, XMM1_REGNUM
};
576 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
) ||
577 needed_intregs
> RET_INT_REGS
|| needed_sseregs
> RET_SSE_REGS
)
580 regcache_cooked_read (regcache
, RAX_REGNUM
, &addr
);
581 read_memory (addr
, valbuf
, TYPE_LENGTH (type
));
587 for (i
= 0; i
< n
; i
++)
591 case X86_64_NO_CLASS
:
593 case X86_64_INTEGER_CLASS
:
594 regcache_cooked_read (regcache
, ret_int_r
[(intreg
+ 1) / 2],
595 (char *) valbuf
+ offset
);
599 case X86_64_INTEGERSI_CLASS
:
600 regcache_cooked_read_part (regcache
, ret_int_r
[intreg
/ 2],
601 0, 4, (char *) valbuf
+ offset
);
605 case X86_64_SSEDF_CLASS
:
606 case X86_64_SSESF_CLASS
:
607 case X86_64_SSE_CLASS
:
608 regcache_cooked_read_part (regcache
,
609 ret_sse_r
[(ssereg
+ 1) / 2], 0, 8,
610 (char *) valbuf
+ offset
);
614 case X86_64_SSEUP_CLASS
:
615 regcache_cooked_read_part (regcache
, ret_sse_r
[ssereg
/ 2],
616 0, 8, (char *) valbuf
+ offset
);
620 case X86_64_X87_CLASS
:
621 regcache_cooked_read_part (regcache
, FP0_REGNUM
,
622 0, 8, (char *) valbuf
+ offset
);
625 case X86_64_X87UP_CLASS
:
626 regcache_cooked_read_part (regcache
, FP0_REGNUM
,
627 8, 2, (char *) valbuf
+ offset
);
630 case X86_64_MEMORY_CLASS
:
632 internal_error (__FILE__
, __LINE__
,
633 "Unexpected argument class");
640 x86_64_frame_init_saved_regs (struct frame_info
*fi
)
642 /* Do nothing. Everything is handled by the stack unwinding code. */
649 x86_64_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
650 int struct_return
, CORE_ADDR struct_addr
)
655 static int int_parameter_registers
[INT_REGS
] = {
656 5 /* RDI */ , 4 /* RSI */ ,
657 3 /* RDX */ , 2 /* RCX */ ,
658 8 /* R8 */ , 9 /* R9 */
661 static int sse_parameter_registers
[SSE_REGS
] = {
662 XMM1_REGNUM
- 1, XMM1_REGNUM
, XMM1_REGNUM
+ 1, XMM1_REGNUM
+ 2,
663 XMM1_REGNUM
+ 3, XMM1_REGNUM
+ 4, XMM1_REGNUM
+ 5, XMM1_REGNUM
+ 6,
664 XMM1_REGNUM
+ 7, XMM1_REGNUM
+ 8, XMM1_REGNUM
+ 9, XMM1_REGNUM
+ 10,
665 XMM1_REGNUM
+ 11, XMM1_REGNUM
+ 12, XMM1_REGNUM
+ 13, XMM1_REGNUM
+ 14
667 int stack_values_count
= 0;
669 stack_values
= alloca (nargs
* sizeof (int));
670 for (i
= 0; i
< nargs
; i
++)
672 enum x86_64_reg_class
class[MAX_CLASSES
];
673 int n
= classify_argument (args
[i
]->type
, class, 0);
678 !examine_argument (class, n
, &needed_intregs
, &needed_sseregs
)
679 || intreg
/ 2 + needed_intregs
> INT_REGS
680 || ssereg
/ 2 + needed_sseregs
> SSE_REGS
)
682 stack_values
[stack_values_count
++] = i
;
687 for (j
= 0; j
< n
; j
++)
692 case X86_64_NO_CLASS
:
694 case X86_64_INTEGER_CLASS
:
695 deprecated_write_register_gen (int_parameter_registers
697 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
701 case X86_64_INTEGERSI_CLASS
:
702 deprecated_write_register_gen (int_parameter_registers
[intreg
/ 2],
703 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
707 case X86_64_SSEDF_CLASS
:
708 case X86_64_SSESF_CLASS
:
709 case X86_64_SSE_CLASS
:
710 deprecated_write_register_gen (sse_parameter_registers
712 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
716 case X86_64_SSEUP_CLASS
:
717 deprecated_write_register_gen (sse_parameter_registers
[ssereg
/ 2],
718 VALUE_CONTENTS_ALL (args
[i
]) + offset
);
722 case X86_64_X87_CLASS
:
723 case X86_64_MEMORY_CLASS
:
724 stack_values
[stack_values_count
++] = i
;
726 case X86_64_X87UP_CLASS
:
729 internal_error (__FILE__
, __LINE__
,
730 "Unexpected argument class");
732 intreg
+= intreg
% 2;
733 ssereg
+= ssereg
% 2;
737 while (--stack_values_count
>= 0)
739 struct value
*arg
= args
[stack_values
[stack_values_count
]];
740 int len
= TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg
));
744 write_memory (sp
, VALUE_CONTENTS_ALL (arg
), len
);
749 /* Write into the appropriate registers a function return value stored
750 in VALBUF of type TYPE, given in virtual format. */
752 x86_64_store_return_value (struct type
*type
, struct regcache
*regcache
,
755 int len
= TYPE_LENGTH (type
);
757 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
759 /* Floating-point return values can be found in %st(0). */
760 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
761 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
763 /* Copy straight over. */
764 regcache_cooked_write (regcache
, FP0_REGNUM
, valbuf
);
768 char buf
[FPU_REG_RAW_SIZE
];
771 /* Convert the value found in VALBUF to the extended
772 floating point format used by the FPU. This is probably
773 not exactly how it would happen on the target itself, but
774 it is the best we can do. */
775 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
776 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
777 regcache_cooked_write_part (regcache
, FP0_REGNUM
,
778 0, FPU_REG_RAW_SIZE
, buf
);
783 int low_size
= REGISTER_RAW_SIZE (0);
784 int high_size
= REGISTER_RAW_SIZE (1);
787 regcache_cooked_write_part (regcache
, 0, 0, len
, valbuf
);
788 else if (len
<= (low_size
+ high_size
))
790 regcache_cooked_write_part (regcache
, 0, 0, low_size
, valbuf
);
791 regcache_cooked_write_part (regcache
, 1, 0,
793 (const char *) valbuf
+ low_size
);
796 internal_error (__FILE__
, __LINE__
,
797 "Cannot store return value of %d bytes long.", len
);
803 x86_64_register_name (int reg_nr
)
805 if (reg_nr
< 0 || reg_nr
>= X86_64_NUM_REGS
)
807 return x86_64_register_info_table
[reg_nr
].name
;
811 x86_64_register_number (const char *name
)
815 for (reg_nr
= 0; reg_nr
< X86_64_NUM_REGS
; reg_nr
++)
816 if (strcmp (name
, x86_64_register_info_table
[reg_nr
].name
) == 0)
823 /* We have two flavours of disassembly. The machinery on this page
824 deals with switching between those. */
827 gdb_print_insn_x86_64 (bfd_vma memaddr
, disassemble_info
* info
)
829 if (disassembly_flavour
== att_flavour
)
830 return print_insn_i386_att (memaddr
, info
);
831 else if (disassembly_flavour
== intel_flavour
)
832 return print_insn_i386_intel (memaddr
, info
);
833 /* Never reached -- disassembly_flavour is always either att_flavour
835 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
839 /* Store the address of the place in which to copy the structure the
840 subroutine will return. This is called from call_function. */
842 x86_64_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
844 write_register (RDI_REGNUM
, addr
);
848 x86_64_frameless_function_invocation (struct frame_info
*frame
)
853 /* If a function with debugging information and known beginning
854 is detected, we will return pc of the next line in the source
855 code. With this approach we effectively skip the prolog. */
857 #define PROLOG_BUFSIZE 4
859 x86_64_skip_prologue (CORE_ADDR pc
)
862 struct symtab_and_line v_sal
;
863 struct symbol
*v_function
;
865 unsigned char prolog_buf
[PROLOG_BUFSIZE
];
867 /* We will handle only functions starting with: */
868 static unsigned char prolog_expect
[PROLOG_BUFSIZE
] =
870 0x55, /* pushq %rbp */
871 0x48, 0x89, 0xe5 /* movq %rsp, %rbp */
874 read_memory (pc
, (char *) prolog_buf
, PROLOG_BUFSIZE
);
876 /* First check, whether pc points to pushq %rbp, movq %rsp, %rbp. */
877 for (i
= 0; i
< PROLOG_BUFSIZE
; i
++)
878 if (prolog_expect
[i
] != prolog_buf
[i
])
879 return pc
; /* ... no, it doesn't. Nothing to skip. */
881 /* OK, we have found the prologue and want PC of the first
882 non-prologue instruction. */
883 pc
+= PROLOG_BUFSIZE
;
885 v_function
= find_pc_function (pc
);
886 v_sal
= find_pc_line (pc
, 0);
888 /* If pc doesn't point to a function with debuginfo, some of the
889 following may be NULL. */
890 if (!v_function
|| !v_function
->ginfo
.value
.block
|| !v_sal
.symtab
)
893 endaddr
= BLOCK_END (SYMBOL_BLOCK_VALUE (v_function
));
895 for (i
= 0; i
< v_sal
.symtab
->linetable
->nitems
; i
++)
896 if (v_sal
.symtab
->linetable
->item
[i
].pc
>= pc
897 && v_sal
.symtab
->linetable
->item
[i
].pc
< endaddr
)
899 pc
= v_sal
.symtab
->linetable
->item
[i
].pc
;
906 /* Sequence of bytes for breakpoint instruction. */
907 static const unsigned char *
908 x86_64_breakpoint_from_pc (CORE_ADDR
*pc
, int *lenptr
)
910 static unsigned char breakpoint
[] = { 0xcc };
916 x86_64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
918 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
921 /* The x86-64 has 16 SSE registers. */
922 tdep
->num_xmm_regs
= 16;
924 /* This is what all the fuss is about. */
925 set_gdbarch_long_bit (gdbarch
, 64);
926 set_gdbarch_long_long_bit (gdbarch
, 64);
927 set_gdbarch_ptr_bit (gdbarch
, 64);
929 /* In contrast to the i386, on the x86-64 a `long double' actually
930 takes up 128 bits, even though it's still based on the i387
931 extended floating-point format which has only 80 significant bits. */
932 set_gdbarch_long_double_bit (gdbarch
, 128);
934 set_gdbarch_num_regs (gdbarch
, X86_64_NUM_REGS
);
936 /* Register numbers of various important registers. */
937 set_gdbarch_sp_regnum (gdbarch
, 7); /* %rsp */
938 set_gdbarch_fp_regnum (gdbarch
, 6); /* %rbp */
939 set_gdbarch_pc_regnum (gdbarch
, 16); /* %rip */
940 set_gdbarch_ps_regnum (gdbarch
, 17); /* %eflags */
941 set_gdbarch_fp0_regnum (gdbarch
, X86_64_NUM_GREGS
); /* %st(0) */
943 /* The "default" register numbering scheme for the x86-64 is
944 referred to as the "DWARF register number mapping" in the psABI.
945 The preferred debugging format for all known x86-64 targets is
946 actually DWARF2, and GCC doesn't seem to support DWARF (that is
947 DWARF-1), but we provide the same mapping just in case. This
948 mapping is also used for stabs, which GCC does support. */
949 set_gdbarch_stab_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
950 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
951 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, x86_64_dwarf2_reg_to_regnum
);
953 /* We don't override SDB_REG_RO_REGNUM, sice COFF doesn't seem to be
954 in use on any of the supported x86-64 targets. */
956 set_gdbarch_register_name (gdbarch
, x86_64_register_name
);
957 set_gdbarch_register_size (gdbarch
, 8);
959 /* Total amount of space needed to store our copies of the machine's
960 register (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS +
962 for (i
= 0, sum
= 0; i
< X86_64_NUM_REGS
; i
++)
963 sum
+= x86_64_register_info_table
[i
].size
;
964 set_gdbarch_register_bytes (gdbarch
, sum
);
966 set_gdbarch_register_raw_size (gdbarch
, x86_64_register_raw_size
);
967 set_gdbarch_register_byte (gdbarch
, x86_64_register_byte
);
968 set_gdbarch_register_virtual_type (gdbarch
, x86_64_register_virtual_type
);
970 set_gdbarch_register_convertible (gdbarch
, x86_64_register_convertible
);
971 set_gdbarch_register_convert_to_virtual (gdbarch
,
972 x86_64_register_convert_to_virtual
);
973 set_gdbarch_register_convert_to_raw (gdbarch
,
974 x86_64_register_convert_to_raw
);
976 /* Getting saved registers is handled by unwind information. */
977 set_gdbarch_get_saved_register (gdbarch
, cfi_get_saved_register
);
979 /* FIXME: kettenis/20021026: Should we set parm_boundary to 64 here? */
980 set_gdbarch_read_fp (gdbarch
, cfi_read_fp
);
982 set_gdbarch_extract_return_value (gdbarch
, x86_64_extract_return_value
);
984 set_gdbarch_push_arguments (gdbarch
, x86_64_push_arguments
);
985 set_gdbarch_push_return_address (gdbarch
, x86_64_push_return_address
);
986 set_gdbarch_pop_frame (gdbarch
, x86_64_pop_frame
);
987 set_gdbarch_store_struct_return (gdbarch
, x86_64_store_struct_return
);
988 set_gdbarch_store_return_value (gdbarch
, x86_64_store_return_value
);
989 /* Override, since this is handled by x86_64_extract_return_value. */
990 set_gdbarch_extract_struct_value_address (gdbarch
, NULL
);
991 set_gdbarch_use_struct_convention (gdbarch
, x86_64_use_struct_convention
);
993 set_gdbarch_frame_init_saved_regs (gdbarch
, x86_64_frame_init_saved_regs
);
994 set_gdbarch_skip_prologue (gdbarch
, x86_64_skip_prologue
);
996 set_gdbarch_frame_chain (gdbarch
, x86_64_linux_frame_chain
);
997 set_gdbarch_frameless_function_invocation (gdbarch
,
998 x86_64_frameless_function_invocation
);
999 /* FIXME: kettenis/20021026: These two are GNU/Linux-specific and
1000 should be moved elsewhere. */
1001 set_gdbarch_frame_saved_pc (gdbarch
, x86_64_linux_frame_saved_pc
);
1002 set_gdbarch_saved_pc_after_call (gdbarch
, x86_64_linux_saved_pc_after_call
);
1003 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
1004 /* FIXME: kettenis/20021026: This one is GNU/Linux-specific too. */
1005 set_gdbarch_pc_in_sigtramp (gdbarch
, x86_64_linux_in_sigtramp
);
1007 set_gdbarch_num_pseudo_regs (gdbarch
, 0);
1009 /* Build call frame information (CFI) from DWARF2 frame debug info. */
1010 set_gdbarch_dwarf2_build_frame_info (gdbarch
, dwarf2_build_frame_info
);
1012 /* Initialization of per-frame CFI. */
1013 set_gdbarch_init_extra_frame_info (gdbarch
, cfi_init_extra_frame_info
);
1015 /* Frame PC initialization is handled by using CFI. */
1016 set_gdbarch_deprecated_init_frame_pc (gdbarch
, x86_64_init_frame_pc
);
1018 /* Cons up virtual frame pointer for trace. */
1019 set_gdbarch_virtual_frame_pointer (gdbarch
, cfi_virtual_frame_pointer
);
1021 /* FIXME: kettenis/20021026: This is ELF-specific. Fine for now,
1022 since all supported x86-64 targets are ELF, but that might change
1024 set_gdbarch_in_solib_call_trampoline (gdbarch
, in_plt_section
);
1028 _initialize_x86_64_tdep (void)
1030 /* Initialize the table saying where each register starts in the
1036 for (i
= 0; i
< X86_64_NUM_REGS
; i
++)
1038 x86_64_register_byte_table
[i
] = offset
;
1039 offset
+= x86_64_register_info_table
[i
].size
;