1 /* Intel 386 target-dependent stuff.
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 Free Software Foundation, Inc.
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. */
24 #include "gdb_string.h"
29 #include "floatformat.h"
33 #include "arch-utils.h"
36 #include "gdb_assert.h"
38 /* i386_register_byte[i] is the offset into the register file of the
39 start of register number i. We initialize this from
40 i386_register_raw_size. */
41 int i386_register_byte
[MAX_NUM_REGS
];
43 /* i386_register_raw_size[i] is the number of bytes of storage in
44 GDB's register array occupied by register i. */
45 int i386_register_raw_size
[MAX_NUM_REGS
] = {
59 /* i386_register_virtual_size[i] is the size in bytes of the virtual
60 type of register i. */
61 int i386_register_virtual_size
[MAX_NUM_REGS
];
63 /* Convert stabs register number REG to the appropriate register
64 number used by GDB. */
67 i386_stab_reg_to_regnum (int reg
)
69 /* This implements what GCC calls the "default" register map. */
70 if (reg
>= 0 && reg
<= 7)
72 /* General registers. */
75 else if (reg
>= 12 && reg
<= 19)
77 /* Floating-point registers. */
78 return reg
- 12 + FP0_REGNUM
;
80 else if (reg
>= 21 && reg
<= 28)
83 return reg
- 21 + XMM0_REGNUM
;
85 else if (reg
>= 29 && reg
<= 36)
88 /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
89 as pseudo-registers? */
90 return reg
- 29 + FP0_REGNUM
;
93 /* This will hopefully provoke a warning. */
94 return NUM_REGS
+ NUM_PSEUDO_REGS
;
97 /* Convert Dwarf register number REG to the appropriate register
98 number used by GDB. */
101 i386_dwarf_reg_to_regnum (int reg
)
103 /* The DWARF register numbering includes %eip and %eflags, and
104 numbers the floating point registers differently. */
105 if (reg
>= 0 && reg
<= 9)
107 /* General registers. */
110 else if (reg
>= 11 && reg
<= 18)
112 /* Floating-point registers. */
113 return reg
- 11 + FP0_REGNUM
;
117 /* The SSE and MMX registers have identical numbers as in stabs. */
118 return i386_stab_reg_to_regnum (reg
);
121 /* This will hopefully provoke a warning. */
122 return NUM_REGS
+ NUM_PSEUDO_REGS
;
126 /* This is the variable that is set with "set disassembly-flavor", and
127 its legitimate values. */
128 static const char att_flavor
[] = "att";
129 static const char intel_flavor
[] = "intel";
130 static const char *valid_flavors
[] =
136 static const char *disassembly_flavor
= att_flavor
;
138 /* This is used to keep the bfd arch_info in sync with the disassembly
140 static void set_disassembly_flavor_sfunc (char *, int,
141 struct cmd_list_element
*);
142 static void set_disassembly_flavor (void);
145 /* Stdio style buffering was used to minimize calls to ptrace, but
146 this buffering did not take into account that the code section
147 being accessed may not be an even number of buffers long (even if
148 the buffer is only sizeof(int) long). In cases where the code
149 section size happened to be a non-integral number of buffers long,
150 attempting to read the last buffer would fail. Simply using
151 target_read_memory and ignoring errors, rather than read_memory, is
152 not the correct solution, since legitimate access errors would then
153 be totally ignored. To properly handle this situation and continue
154 to use buffering would require that this code be able to determine
155 the minimum code section size granularity (not the alignment of the
156 section itself, since the actual failing case that pointed out this
157 problem had a section alignment of 4 but was not a multiple of 4
158 bytes long), on a target by target basis, and then adjust it's
159 buffer size accordingly. This is messy, but potentially feasible.
160 It probably needs the bfd library's help and support. For now, the
161 buffer size is set to 1. (FIXME -fnf) */
163 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
164 static CORE_ADDR codestream_next_addr
;
165 static CORE_ADDR codestream_addr
;
166 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
167 static int codestream_off
;
168 static int codestream_cnt
;
170 #define codestream_tell() (codestream_addr + codestream_off)
171 #define codestream_peek() \
172 (codestream_cnt == 0 ? \
173 codestream_fill(1) : codestream_buf[codestream_off])
174 #define codestream_get() \
175 (codestream_cnt-- == 0 ? \
176 codestream_fill(0) : codestream_buf[codestream_off++])
179 codestream_fill (int peek_flag
)
181 codestream_addr
= codestream_next_addr
;
182 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
184 codestream_cnt
= CODESTREAM_BUFSIZ
;
185 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
188 return (codestream_peek ());
190 return (codestream_get ());
194 codestream_seek (CORE_ADDR place
)
196 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
197 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
200 while (codestream_tell () != place
)
205 codestream_read (unsigned char *buf
, int count
)
210 for (i
= 0; i
< count
; i
++)
211 *p
++ = codestream_get ();
215 /* If the next instruction is a jump, move to its target. */
218 i386_follow_jump (void)
220 unsigned char buf
[4];
226 pos
= codestream_tell ();
229 if (codestream_peek () == 0x66)
235 switch (codestream_get ())
238 /* Relative jump: if data16 == 0, disp32, else disp16. */
241 codestream_read (buf
, 2);
242 delta
= extract_signed_integer (buf
, 2);
244 /* Include the size of the jmp instruction (including the
250 codestream_read (buf
, 4);
251 delta
= extract_signed_integer (buf
, 4);
257 /* Relative jump, disp8 (ignore data16). */
258 codestream_read (buf
, 1);
259 /* Sign-extend it. */
260 delta
= extract_signed_integer (buf
, 1);
265 codestream_seek (pos
);
268 /* Find & return the amount a local space allocated, and advance the
269 codestream to the first register push (if any).
271 If the entry sequence doesn't make sense, return -1, and leave
272 codestream pointer at a random spot. */
275 i386_get_frame_setup (CORE_ADDR pc
)
279 codestream_seek (pc
);
283 op
= codestream_get ();
285 if (op
== 0x58) /* popl %eax */
287 /* This function must start with
290 xchgl %eax, (%esp) 0x87 0x04 0x24
291 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
293 (the System V compiler puts out the second `xchg'
294 instruction, and the assembler doesn't try to optimize it, so
295 the 'sib' form gets generated). This sequence is used to get
296 the address of the return buffer for a function that returns
299 unsigned char buf
[4];
300 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
301 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
303 pos
= codestream_tell ();
304 codestream_read (buf
, 4);
305 if (memcmp (buf
, proto1
, 3) == 0)
307 else if (memcmp (buf
, proto2
, 4) == 0)
310 codestream_seek (pos
);
311 op
= codestream_get (); /* Update next opcode. */
314 if (op
== 0x68 || op
== 0x6a)
316 /* This function may start with
328 unsigned char buf
[8];
330 /* Skip past the `pushl' instruction; it has either a one-byte
331 or a four-byte operand, depending on the opcode. */
332 pos
= codestream_tell ();
337 codestream_seek (pos
);
339 /* Read the following 8 bytes, which should be "call _probe" (6
340 bytes) followed by "addl $4,%esp" (2 bytes). */
341 codestream_read (buf
, sizeof (buf
));
342 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
344 codestream_seek (pos
);
345 op
= codestream_get (); /* Update next opcode. */
348 if (op
== 0x55) /* pushl %ebp */
350 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
351 switch (codestream_get ())
354 if (codestream_get () != 0xec)
358 if (codestream_get () != 0xe5)
364 /* Check for stack adjustment
368 NOTE: You can't subtract a 16 bit immediate from a 32 bit
369 reg, so we don't have to worry about a data16 prefix. */
370 op
= codestream_peek ();
373 /* `subl' with 8 bit immediate. */
375 if (codestream_get () != 0xec)
376 /* Some instruction starting with 0x83 other than `subl'. */
378 codestream_seek (codestream_tell () - 2);
381 /* `subl' with signed byte immediate (though it wouldn't
382 make sense to be negative). */
383 return (codestream_get ());
388 /* Maybe it is `subl' with a 32 bit immedediate. */
390 if (codestream_get () != 0xec)
391 /* Some instruction starting with 0x81 other than `subl'. */
393 codestream_seek (codestream_tell () - 2);
396 /* It is `subl' with a 32 bit immediate. */
397 codestream_read ((unsigned char *) buf
, 4);
398 return extract_signed_integer (buf
, 4);
408 /* `enter' with 16 bit unsigned immediate. */
409 codestream_read ((unsigned char *) buf
, 2);
410 codestream_get (); /* Flush final byte of enter instruction. */
411 return extract_unsigned_integer (buf
, 2);
416 /* Return the chain-pointer for FRAME. In the case of the i386, the
417 frame's nominal address is the address of a 4-byte word containing
418 the calling frame's address. */
421 i386_frame_chain (struct frame_info
*frame
)
423 if (frame
->signal_handler_caller
)
426 if (! inside_entry_file (frame
->pc
))
427 return read_memory_unsigned_integer (frame
->frame
, 4);
432 /* Determine whether the function invocation represented by FRAME does
433 not have a from on the stack associated with it. If it does not,
434 return non-zero, otherwise return zero. */
437 i386_frameless_function_invocation (struct frame_info
*frame
)
439 if (frame
->signal_handler_caller
)
442 return frameless_look_for_prologue (frame
);
445 /* Return the saved program counter for FRAME. */
448 i386_frame_saved_pc (struct frame_info
*frame
)
450 /* FIXME: kettenis/2001-05-09: Conditionalizing the next bit of code
451 on SIGCONTEXT_PC_OFFSET and I386V4_SIGTRAMP_SAVED_PC should be
452 considered a temporary hack. I plan to come up with something
453 better when we go multi-arch. */
454 #if defined (SIGCONTEXT_PC_OFFSET) || defined (I386V4_SIGTRAMP_SAVED_PC)
455 if (frame
->signal_handler_caller
)
456 return sigtramp_saved_pc (frame
);
459 return read_memory_unsigned_integer (frame
->frame
+ 4, 4);
462 /* Immediately after a function call, return the saved pc. */
465 i386_saved_pc_after_call (struct frame_info
*frame
)
467 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
470 /* Return number of args passed to a frame.
471 Can return -1, meaning no way to tell. */
474 i386_frame_num_args (struct frame_info
*fi
)
479 /* This loses because not only might the compiler not be popping the
480 args right after the function call, it might be popping args from
481 both this call and a previous one, and we would say there are
482 more args than there really are. */
486 struct frame_info
*pfi
;
488 /* On the i386, the instruction following the call could be:
490 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
491 anything else - zero args. */
495 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
497 /* In the absence of a frame pointer, GDB doesn't get correct
498 values for nameless arguments. Return -1, so it doesn't print
499 any nameless arguments. */
502 pfi
= get_prev_frame (fi
);
505 /* NOTE: This can happen if we are looking at the frame for
506 main, because FRAME_CHAIN_VALID won't let us go into start.
507 If we have debugging symbols, that's not really a big deal;
508 it just means it will only show as many arguments to main as
515 op
= read_memory_integer (retpc
, 1);
516 if (op
== 0x59) /* pop %ecx */
520 op
= read_memory_integer (retpc
+ 1, 1);
522 /* addl $<signed imm 8 bits>, %esp */
523 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
527 else if (op
== 0x81) /* `add' with 32 bit immediate. */
529 op
= read_memory_integer (retpc
+ 1, 1);
531 /* addl $<imm 32>, %esp */
532 return read_memory_integer (retpc
+ 2, 4) / 4;
544 /* Parse the first few instructions the function to see what registers
547 We handle these cases:
549 The startup sequence can be at the start of the function, or the
550 function can start with a branch to startup code at the end.
552 %ebp can be set up with either the 'enter' instruction, or "pushl
553 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
554 once used in the System V compiler).
556 Local space is allocated just below the saved %ebp by either the
557 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
558 bit unsigned argument for space to allocate, and the 'addl'
559 instruction could have either a signed byte, or 32 bit immediate.
561 Next, the registers used by this function are pushed. With the
562 System V compiler they will always be in the order: %edi, %esi,
563 %ebx (and sometimes a harmless bug causes it to also save but not
564 restore %eax); however, the code below is willing to see the pushes
565 in any order, and will handle up to 8 of them.
567 If the setup sequence is at the end of the function, then the next
568 instruction will be a branch back to the start. */
571 i386_frame_init_saved_regs (struct frame_info
*fip
)
575 CORE_ADDR dummy_bottom
;
583 frame_saved_regs_zalloc (fip
);
585 /* If the frame is the end of a dummy, compute where the beginning
587 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
589 /* Check if the PC points in the stack, in a dummy frame. */
590 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
592 /* All registers were saved by push_call_dummy. */
594 for (i
= 0; i
< NUM_REGS
; i
++)
596 addr
-= REGISTER_RAW_SIZE (i
);
597 fip
->saved_regs
[i
] = addr
;
602 pc
= get_pc_function_start (fip
->pc
);
604 locals
= i386_get_frame_setup (pc
);
608 addr
= fip
->frame
- 4 - locals
;
609 for (i
= 0; i
< 8; i
++)
611 op
= codestream_get ();
612 if (op
< 0x50 || op
> 0x57)
614 #ifdef I386_REGNO_TO_SYMMETRY
615 /* Dynix uses different internal numbering. Ick. */
616 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
618 fip
->saved_regs
[op
- 0x50] = addr
;
624 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
625 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
628 /* Return PC of first real instruction. */
631 i386_skip_prologue (int pc
)
635 static unsigned char pic_pat
[6] =
636 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
637 0x5b, /* popl %ebx */
641 if (i386_get_frame_setup (pc
) < 0)
644 /* Found valid frame setup -- codestream now points to start of push
645 instructions for saving registers. */
647 /* Skip over register saves. */
648 for (i
= 0; i
< 8; i
++)
650 op
= codestream_peek ();
651 /* Break if not `pushl' instrunction. */
652 if (op
< 0x50 || op
> 0x57)
657 /* The native cc on SVR4 in -K PIC mode inserts the following code
658 to get the address of the global offset table (GOT) into register
663 movl %ebx,x(%ebp) (optional)
666 This code is with the rest of the prologue (at the end of the
667 function), so we have to skip it to get to the first real
668 instruction at the start of the function. */
670 pos
= codestream_tell ();
671 for (i
= 0; i
< 6; i
++)
673 op
= codestream_get ();
674 if (pic_pat
[i
] != op
)
679 unsigned char buf
[4];
682 op
= codestream_get ();
683 if (op
== 0x89) /* movl %ebx, x(%ebp) */
685 op
= codestream_get ();
686 if (op
== 0x5d) /* One byte offset from %ebp. */
689 codestream_read (buf
, 1);
691 else if (op
== 0x9d) /* Four byte offset from %ebp. */
694 codestream_read (buf
, 4);
696 else /* Unexpected instruction. */
698 op
= codestream_get ();
701 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
706 codestream_seek (pos
);
710 return (codestream_tell ());
714 i386_push_dummy_frame (void)
716 CORE_ADDR sp
= read_register (SP_REGNUM
);
718 char regbuf
[MAX_REGISTER_RAW_SIZE
];
720 sp
= push_word (sp
, read_register (PC_REGNUM
));
721 sp
= push_word (sp
, read_register (FP_REGNUM
));
722 write_register (FP_REGNUM
, sp
);
723 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
725 read_register_gen (regnum
, regbuf
);
726 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
728 write_register (SP_REGNUM
, sp
);
731 /* Insert the (relative) function address into the call sequence
735 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
736 struct value
**args
, struct type
*type
, int gcc_p
)
738 int from
, to
, delta
, loc
;
740 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
745 *((char *)(dummy
) + 1) = (delta
& 0xff);
746 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
747 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
748 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
752 i386_pop_frame (void)
754 struct frame_info
*frame
= get_current_frame ();
757 char regbuf
[MAX_REGISTER_RAW_SIZE
];
759 fp
= FRAME_FP (frame
);
760 i386_frame_init_saved_regs (frame
);
762 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
765 addr
= frame
->saved_regs
[regnum
];
768 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
769 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
770 REGISTER_RAW_SIZE (regnum
));
773 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
774 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
775 write_register (SP_REGNUM
, fp
+ 8);
776 flush_cached_frames ();
780 #ifdef GET_LONGJMP_TARGET
782 /* Figure out where the longjmp will land. Slurp the args out of the
783 stack. We expect the first arg to be a pointer to the jmp_buf
784 structure from which we extract the pc (JB_PC) that we will land
785 at. The pc is copied into PC. This routine returns true on
789 get_longjmp_target (CORE_ADDR
*pc
)
791 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
792 CORE_ADDR sp
, jb_addr
;
794 sp
= read_register (SP_REGNUM
);
796 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack. */
798 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
801 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
803 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
804 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
807 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
812 #endif /* GET_LONGJMP_TARGET */
816 i386_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
817 int struct_return
, CORE_ADDR struct_addr
)
819 sp
= default_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
826 store_address (buf
, 4, struct_addr
);
827 write_memory (sp
, buf
, 4);
834 i386_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
836 /* Do nothing. Everything was already done by i386_push_arguments. */
839 /* These registers are used for returning integers (and on some
840 targets also for returning `struct' and `union' values when their
841 size and alignment match an integer type). */
842 #define LOW_RETURN_REGNUM 0 /* %eax */
843 #define HIGH_RETURN_REGNUM 2 /* %edx */
845 /* Extract from an array REGBUF containing the (raw) register state, a
846 function return value of TYPE, and copy that, in virtual format,
850 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
852 int len
= TYPE_LENGTH (type
);
854 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
855 && TYPE_NFIELDS (type
) == 1)
857 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regbuf
, valbuf
);
861 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
865 warning ("Cannot find floating-point return value.");
866 memset (valbuf
, 0, len
);
870 /* Floating-point return values can be found in %st(0). */
871 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
872 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
874 /* Copy straight over, but take care of the padding. */
875 memcpy (valbuf
, ®buf
[REGISTER_BYTE (FP0_REGNUM
)],
877 memset (valbuf
+ FPU_REG_RAW_SIZE
, 0, len
- FPU_REG_RAW_SIZE
);
881 /* Convert the extended floating-point number found in
882 %st(0) to the desired type. This is probably not exactly
883 how it would happen on the target itself, but it is the
886 floatformat_to_doublest (&floatformat_i387_ext
,
887 ®buf
[REGISTER_BYTE (FP0_REGNUM
)], &val
);
888 store_floating (valbuf
, TYPE_LENGTH (type
), val
);
893 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
894 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
897 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
898 else if (len
<= (low_size
+ high_size
))
901 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
902 memcpy (valbuf
+ low_size
,
903 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
906 internal_error (__FILE__
, __LINE__
,
907 "Cannot extract return value of %d bytes long.", len
);
911 /* Write into the appropriate registers a function return value stored
912 in VALBUF of type TYPE, given in virtual format. */
915 i386_store_return_value (struct type
*type
, char *valbuf
)
917 int len
= TYPE_LENGTH (type
);
919 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
920 && TYPE_NFIELDS (type
) == 1)
922 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), valbuf
);
926 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
932 warning ("Cannot set floating-point return value.");
936 /* Returning floating-point values is a bit tricky. Apart from
937 storing the return value in %st(0), we have to simulate the
938 state of the FPU at function return point. */
940 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
941 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
943 /* Copy straight over. */
944 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
949 char buf
[FPU_REG_RAW_SIZE
];
952 /* Convert the value found in VALBUF to the extended
953 floating-point format used by the FPU. This is probably
954 not exactly how it would happen on the target itself, but
955 it is the best we can do. */
956 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
957 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
958 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
962 /* Set the top of the floating-point register stack to 7. The
963 actual value doesn't really matter, but 7 is what a normal
964 function return would end up with if the program started out
965 with a freshly initialized FPU. */
966 fstat
= read_register (FSTAT_REGNUM
);
968 write_register (FSTAT_REGNUM
, fstat
);
970 /* Mark %st(1) through %st(7) as empty. Since we set the top of
971 the floating-point register stack to 7, the appropriate value
972 for the tag word is 0x3fff. */
973 write_register (FTAG_REGNUM
, 0x3fff);
977 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
978 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
981 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
982 else if (len
<= (low_size
+ high_size
))
984 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
986 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
987 valbuf
+ low_size
, len
- low_size
);
990 internal_error (__FILE__
, __LINE__
,
991 "Cannot store return value of %d bytes long.", len
);
995 /* Extract from an array REGBUF containing the (raw) register state
996 the address in which a function should return its structure value,
1000 i386_extract_struct_value_address (char *regbuf
)
1002 return extract_address (®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)],
1003 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
));
1007 /* Return the GDB type object for the "standard" data type of data in
1008 register REGNUM. Perhaps %esi and %edi should go here, but
1009 potentially they could be used for things other than address. */
1012 i386_register_virtual_type (int regnum
)
1014 if (regnum
== PC_REGNUM
|| regnum
== FP_REGNUM
|| regnum
== SP_REGNUM
)
1015 return lookup_pointer_type (builtin_type_void
);
1017 if (IS_FP_REGNUM (regnum
))
1018 return builtin_type_long_double
;
1020 if (IS_SSE_REGNUM (regnum
))
1021 return builtin_type_v4sf
;
1023 return builtin_type_int
;
1026 /* Return true iff register REGNUM's virtual format is different from
1027 its raw format. Note that this definition assumes that the host
1028 supports IEEE 32-bit floats, since it doesn't say that SSE
1029 registers need conversion. Even if we can't find a counterexample,
1030 this is still sloppy. */
1033 i386_register_convertible (int regnum
)
1035 return IS_FP_REGNUM (regnum
);
1038 /* Convert data from raw format for register REGNUM in buffer FROM to
1039 virtual format with type TYPE in buffer TO. */
1042 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
1043 char *from
, char *to
)
1048 /* We only support floating-point values. */
1049 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
);
1051 /* First add the necessary padding. */
1052 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
1053 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
1055 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
1056 to the extended floating-point format used by the FPU. */
1057 d
= extract_floating (buf
, sizeof buf
);
1058 store_floating (to
, TYPE_LENGTH (type
), d
);
1061 /* Convert data from virtual format with type TYPE in buffer FROM to
1062 raw format for register REGNUM in buffer TO. */
1065 i386_register_convert_to_raw (struct type
*type
, int regnum
,
1066 char *from
, char *to
)
1068 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
1069 && TYPE_LENGTH (type
) == 12);
1071 /* Simply omit the two unused bytes. */
1072 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
1076 #ifdef I386V4_SIGTRAMP_SAVED_PC
1077 /* Get saved user PC for sigtramp from the pushed ucontext on the
1078 stack for all three variants of SVR4 sigtramps. */
1081 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
1083 CORE_ADDR saved_pc_offset
= 4;
1086 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
1089 if (STREQ (name
, "_sigreturn"))
1090 saved_pc_offset
= 132 + 14 * 4;
1091 else if (STREQ (name
, "_sigacthandler"))
1092 saved_pc_offset
= 80 + 14 * 4;
1093 else if (STREQ (name
, "sigvechandler"))
1094 saved_pc_offset
= 120 + 14 * 4;
1098 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
1099 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
1101 #endif /* I386V4_SIGTRAMP_SAVED_PC */
1104 #ifdef STATIC_TRANSFORM_NAME
1105 /* SunPRO encodes the static variables. This is not related to C++
1106 mangling, it is done for C too. */
1109 sunpro_static_transform_name (char *name
)
1112 if (IS_STATIC_TRANSFORM_NAME (name
))
1114 /* For file-local statics there will be a period, a bunch of
1115 junk (the contents of which match a string given in the
1116 N_OPT), a period and the name. For function-local statics
1117 there will be a bunch of junk (which seems to change the
1118 second character from 'A' to 'B'), a period, the name of the
1119 function, and the name. So just skip everything before the
1121 p
= strrchr (name
, '.');
1127 #endif /* STATIC_TRANSFORM_NAME */
1130 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1133 skip_trampoline_code (CORE_ADDR pc
, char *name
)
1135 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
1137 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
1138 struct minimal_symbol
*indsym
=
1139 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
1140 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
1144 if (strncmp (symname
, "__imp_", 6) == 0
1145 || strncmp (symname
, "_imp_", 5) == 0)
1146 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
1149 return 0; /* Not a trampoline. */
1153 /* We have two flavours of disassembly. The machinery on this page
1154 deals with switching between those. */
1157 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
1159 if (disassembly_flavor
== att_flavor
)
1160 return print_insn_i386_att (memaddr
, info
);
1161 else if (disassembly_flavor
== intel_flavor
)
1162 return print_insn_i386_intel (memaddr
, info
);
1163 /* Never reached -- disassembly_flavour is always either att_flavor
1165 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1168 /* If the disassembly mode is intel, we have to also switch the bfd
1169 mach_type. This function is run in the set disassembly_flavor
1170 command, and does that. */
1173 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
1174 struct cmd_list_element
*c
)
1176 set_disassembly_flavor ();
1180 set_disassembly_flavor (void)
1182 if (disassembly_flavor
== att_flavor
)
1183 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
1184 else if (disassembly_flavor
== intel_flavor
)
1185 set_architecture_from_arch_mach (bfd_arch_i386
,
1186 bfd_mach_i386_i386_intel_syntax
);
1190 /* Provide a prototype to silence -Wmissing-prototypes. */
1191 void _initialize_i386_tdep (void);
1194 _initialize_i386_tdep (void)
1196 /* Initialize the table saying where each register starts in the
1202 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1204 i386_register_byte
[i
] = offset
;
1205 offset
+= i386_register_raw_size
[i
];
1209 /* Initialize the table of virtual register sizes. */
1213 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1214 i386_register_virtual_size
[i
] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i
));
1217 tm_print_insn
= gdb_print_insn_i386
;
1218 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1220 /* Add the variable that controls the disassembly flavor. */
1222 struct cmd_list_element
*new_cmd
;
1224 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1226 &disassembly_flavor
,
1228 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1229 and the default value is \"att\".",
1231 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1232 add_show_from_set (new_cmd
, &showlist
);
1235 /* Finally, initialize the disassembly flavor to the default given
1236 in the disassembly_flavor variable. */
1237 set_disassembly_flavor ();