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"
38 #include "gdb_assert.h"
40 /* i386_register_byte[i] is the offset into the register file of the
41 start of register number i. We initialize this from
42 i386_register_raw_size. */
43 int i386_register_byte
[MAX_NUM_REGS
];
45 /* i386_register_raw_size[i] is the number of bytes of storage in
46 GDB's register array occupied by register i. */
47 int i386_register_raw_size
[MAX_NUM_REGS
] = {
61 /* i386_register_virtual_size[i] is the size in bytes of the virtual
62 type of register i. */
63 int i386_register_virtual_size
[MAX_NUM_REGS
];
65 /* Convert stabs register number REG to the appropriate register
66 number used by GDB. */
69 i386_stab_reg_to_regnum (int reg
)
71 /* This implements what GCC calls the "default" register map. */
72 if (reg
>= 0 && reg
<= 7)
74 /* General registers. */
77 else if (reg
>= 12 && reg
<= 19)
79 /* Floating-point registers. */
80 return reg
- 12 + FP0_REGNUM
;
82 else if (reg
>= 21 && reg
<= 28)
85 return reg
- 21 + XMM0_REGNUM
;
87 else if (reg
>= 29 && reg
<= 36)
90 /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
91 as pseudo-registers? */
92 return reg
- 29 + FP0_REGNUM
;
95 /* This will hopefully provoke a warning. */
96 return NUM_REGS
+ NUM_PSEUDO_REGS
;
99 /* Convert Dwarf register number REG to the appropriate register
100 number used by GDB. */
103 i386_dwarf_reg_to_regnum (int reg
)
105 /* The DWARF register numbering includes %eip and %eflags, and
106 numbers the floating point registers differently. */
107 if (reg
>= 0 && reg
<= 9)
109 /* General registers. */
112 else if (reg
>= 11 && reg
<= 18)
114 /* Floating-point registers. */
115 return reg
- 11 + FP0_REGNUM
;
119 /* The SSE and MMX registers have identical numbers as in stabs. */
120 return i386_stab_reg_to_regnum (reg
);
123 /* This will hopefully provoke a warning. */
124 return NUM_REGS
+ NUM_PSEUDO_REGS
;
128 /* This is the variable that is set with "set disassembly-flavor", and
129 its legitimate values. */
130 static const char att_flavor
[] = "att";
131 static const char intel_flavor
[] = "intel";
132 static const char *valid_flavors
[] =
138 static const char *disassembly_flavor
= att_flavor
;
140 /* This is used to keep the bfd arch_info in sync with the disassembly
142 static void set_disassembly_flavor_sfunc (char *, int,
143 struct cmd_list_element
*);
144 static void set_disassembly_flavor (void);
147 /* Stdio style buffering was used to minimize calls to ptrace, but
148 this buffering did not take into account that the code section
149 being accessed may not be an even number of buffers long (even if
150 the buffer is only sizeof(int) long). In cases where the code
151 section size happened to be a non-integral number of buffers long,
152 attempting to read the last buffer would fail. Simply using
153 target_read_memory and ignoring errors, rather than read_memory, is
154 not the correct solution, since legitimate access errors would then
155 be totally ignored. To properly handle this situation and continue
156 to use buffering would require that this code be able to determine
157 the minimum code section size granularity (not the alignment of the
158 section itself, since the actual failing case that pointed out this
159 problem had a section alignment of 4 but was not a multiple of 4
160 bytes long), on a target by target basis, and then adjust it's
161 buffer size accordingly. This is messy, but potentially feasible.
162 It probably needs the bfd library's help and support. For now, the
163 buffer size is set to 1. (FIXME -fnf) */
165 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
166 static CORE_ADDR codestream_next_addr
;
167 static CORE_ADDR codestream_addr
;
168 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
169 static int codestream_off
;
170 static int codestream_cnt
;
172 #define codestream_tell() (codestream_addr + codestream_off)
173 #define codestream_peek() \
174 (codestream_cnt == 0 ? \
175 codestream_fill(1) : codestream_buf[codestream_off])
176 #define codestream_get() \
177 (codestream_cnt-- == 0 ? \
178 codestream_fill(0) : codestream_buf[codestream_off++])
181 codestream_fill (int peek_flag
)
183 codestream_addr
= codestream_next_addr
;
184 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
186 codestream_cnt
= CODESTREAM_BUFSIZ
;
187 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
190 return (codestream_peek ());
192 return (codestream_get ());
196 codestream_seek (CORE_ADDR place
)
198 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
199 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
202 while (codestream_tell () != place
)
207 codestream_read (unsigned char *buf
, int count
)
212 for (i
= 0; i
< count
; i
++)
213 *p
++ = codestream_get ();
217 /* If the next instruction is a jump, move to its target. */
220 i386_follow_jump (void)
222 unsigned char buf
[4];
228 pos
= codestream_tell ();
231 if (codestream_peek () == 0x66)
237 switch (codestream_get ())
240 /* Relative jump: if data16 == 0, disp32, else disp16. */
243 codestream_read (buf
, 2);
244 delta
= extract_signed_integer (buf
, 2);
246 /* Include the size of the jmp instruction (including the
252 codestream_read (buf
, 4);
253 delta
= extract_signed_integer (buf
, 4);
259 /* Relative jump, disp8 (ignore data16). */
260 codestream_read (buf
, 1);
261 /* Sign-extend it. */
262 delta
= extract_signed_integer (buf
, 1);
267 codestream_seek (pos
);
270 /* Find & return the amount a local space allocated, and advance the
271 codestream to the first register push (if any).
273 If the entry sequence doesn't make sense, return -1, and leave
274 codestream pointer at a random spot. */
277 i386_get_frame_setup (CORE_ADDR pc
)
281 codestream_seek (pc
);
285 op
= codestream_get ();
287 if (op
== 0x58) /* popl %eax */
289 /* This function must start with
292 xchgl %eax, (%esp) 0x87 0x04 0x24
293 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
295 (the System V compiler puts out the second `xchg'
296 instruction, and the assembler doesn't try to optimize it, so
297 the 'sib' form gets generated). This sequence is used to get
298 the address of the return buffer for a function that returns
301 unsigned char buf
[4];
302 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
303 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
305 pos
= codestream_tell ();
306 codestream_read (buf
, 4);
307 if (memcmp (buf
, proto1
, 3) == 0)
309 else if (memcmp (buf
, proto2
, 4) == 0)
312 codestream_seek (pos
);
313 op
= codestream_get (); /* Update next opcode. */
316 if (op
== 0x68 || op
== 0x6a)
318 /* This function may start with
330 unsigned char buf
[8];
332 /* Skip past the `pushl' instruction; it has either a one-byte
333 or a four-byte operand, depending on the opcode. */
334 pos
= codestream_tell ();
339 codestream_seek (pos
);
341 /* Read the following 8 bytes, which should be "call _probe" (6
342 bytes) followed by "addl $4,%esp" (2 bytes). */
343 codestream_read (buf
, sizeof (buf
));
344 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
346 codestream_seek (pos
);
347 op
= codestream_get (); /* Update next opcode. */
350 if (op
== 0x55) /* pushl %ebp */
352 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
353 switch (codestream_get ())
356 if (codestream_get () != 0xec)
360 if (codestream_get () != 0xe5)
366 /* Check for stack adjustment
370 NOTE: You can't subtract a 16 bit immediate from a 32 bit
371 reg, so we don't have to worry about a data16 prefix. */
372 op
= codestream_peek ();
375 /* `subl' with 8 bit immediate. */
377 if (codestream_get () != 0xec)
378 /* Some instruction starting with 0x83 other than `subl'. */
380 codestream_seek (codestream_tell () - 2);
383 /* `subl' with signed byte immediate (though it wouldn't
384 make sense to be negative). */
385 return (codestream_get ());
390 /* Maybe it is `subl' with a 32 bit immedediate. */
392 if (codestream_get () != 0xec)
393 /* Some instruction starting with 0x81 other than `subl'. */
395 codestream_seek (codestream_tell () - 2);
398 /* It is `subl' with a 32 bit immediate. */
399 codestream_read ((unsigned char *) buf
, 4);
400 return extract_signed_integer (buf
, 4);
410 /* `enter' with 16 bit unsigned immediate. */
411 codestream_read ((unsigned char *) buf
, 2);
412 codestream_get (); /* Flush final byte of enter instruction. */
413 return extract_unsigned_integer (buf
, 2);
418 /* Return the chain-pointer for FRAME. In the case of the i386, the
419 frame's nominal address is the address of a 4-byte word containing
420 the calling frame's address. */
423 i386_frame_chain (struct frame_info
*frame
)
425 if (frame
->signal_handler_caller
)
428 if (! inside_entry_file (frame
->pc
))
429 return read_memory_unsigned_integer (frame
->frame
, 4);
434 /* Determine whether the function invocation represented by FRAME does
435 not have a from on the stack associated with it. If it does not,
436 return non-zero, otherwise return zero. */
439 i386_frameless_function_invocation (struct frame_info
*frame
)
441 if (frame
->signal_handler_caller
)
444 return frameless_look_for_prologue (frame
);
447 /* Return the saved program counter for FRAME. */
450 i386_frame_saved_pc (struct frame_info
*frame
)
452 /* FIXME: kettenis/2001-05-09: Conditionalizing the next bit of code
453 on SIGCONTEXT_PC_OFFSET and I386V4_SIGTRAMP_SAVED_PC should be
454 considered a temporary hack. I plan to come up with something
455 better when we go multi-arch. */
456 #if defined (SIGCONTEXT_PC_OFFSET) || defined (I386V4_SIGTRAMP_SAVED_PC)
457 if (frame
->signal_handler_caller
)
458 return sigtramp_saved_pc (frame
);
461 return read_memory_unsigned_integer (frame
->frame
+ 4, 4);
464 /* Immediately after a function call, return the saved pc. */
467 i386_saved_pc_after_call (struct frame_info
*frame
)
469 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
472 /* Return number of args passed to a frame.
473 Can return -1, meaning no way to tell. */
476 i386_frame_num_args (struct frame_info
*fi
)
481 /* This loses because not only might the compiler not be popping the
482 args right after the function call, it might be popping args from
483 both this call and a previous one, and we would say there are
484 more args than there really are. */
488 struct frame_info
*pfi
;
490 /* On the i386, the instruction following the call could be:
492 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
493 anything else - zero args. */
497 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
499 /* In the absence of a frame pointer, GDB doesn't get correct
500 values for nameless arguments. Return -1, so it doesn't print
501 any nameless arguments. */
504 pfi
= get_prev_frame (fi
);
507 /* NOTE: This can happen if we are looking at the frame for
508 main, because FRAME_CHAIN_VALID won't let us go into start.
509 If we have debugging symbols, that's not really a big deal;
510 it just means it will only show as many arguments to main as
517 op
= read_memory_integer (retpc
, 1);
518 if (op
== 0x59) /* pop %ecx */
522 op
= read_memory_integer (retpc
+ 1, 1);
524 /* addl $<signed imm 8 bits>, %esp */
525 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
529 else if (op
== 0x81) /* `add' with 32 bit immediate. */
531 op
= read_memory_integer (retpc
+ 1, 1);
533 /* addl $<imm 32>, %esp */
534 return read_memory_integer (retpc
+ 2, 4) / 4;
546 /* Parse the first few instructions the function to see what registers
549 We handle these cases:
551 The startup sequence can be at the start of the function, or the
552 function can start with a branch to startup code at the end.
554 %ebp can be set up with either the 'enter' instruction, or "pushl
555 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
556 once used in the System V compiler).
558 Local space is allocated just below the saved %ebp by either the
559 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
560 bit unsigned argument for space to allocate, and the 'addl'
561 instruction could have either a signed byte, or 32 bit immediate.
563 Next, the registers used by this function are pushed. With the
564 System V compiler they will always be in the order: %edi, %esi,
565 %ebx (and sometimes a harmless bug causes it to also save but not
566 restore %eax); however, the code below is willing to see the pushes
567 in any order, and will handle up to 8 of them.
569 If the setup sequence is at the end of the function, then the next
570 instruction will be a branch back to the start. */
573 i386_frame_init_saved_regs (struct frame_info
*fip
)
577 CORE_ADDR dummy_bottom
;
585 frame_saved_regs_zalloc (fip
);
587 /* If the frame is the end of a dummy, compute where the beginning
589 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
591 /* Check if the PC points in the stack, in a dummy frame. */
592 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
594 /* All registers were saved by push_call_dummy. */
596 for (i
= 0; i
< NUM_REGS
; i
++)
598 addr
-= REGISTER_RAW_SIZE (i
);
599 fip
->saved_regs
[i
] = addr
;
604 pc
= get_pc_function_start (fip
->pc
);
606 locals
= i386_get_frame_setup (pc
);
610 addr
= fip
->frame
- 4 - locals
;
611 for (i
= 0; i
< 8; i
++)
613 op
= codestream_get ();
614 if (op
< 0x50 || op
> 0x57)
616 #ifdef I386_REGNO_TO_SYMMETRY
617 /* Dynix uses different internal numbering. Ick. */
618 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
620 fip
->saved_regs
[op
- 0x50] = addr
;
626 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
627 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
630 /* Return PC of first real instruction. */
633 i386_skip_prologue (int pc
)
637 static unsigned char pic_pat
[6] =
638 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
639 0x5b, /* popl %ebx */
643 if (i386_get_frame_setup (pc
) < 0)
646 /* Found valid frame setup -- codestream now points to start of push
647 instructions for saving registers. */
649 /* Skip over register saves. */
650 for (i
= 0; i
< 8; i
++)
652 op
= codestream_peek ();
653 /* Break if not `pushl' instrunction. */
654 if (op
< 0x50 || op
> 0x57)
659 /* The native cc on SVR4 in -K PIC mode inserts the following code
660 to get the address of the global offset table (GOT) into register
665 movl %ebx,x(%ebp) (optional)
668 This code is with the rest of the prologue (at the end of the
669 function), so we have to skip it to get to the first real
670 instruction at the start of the function. */
672 pos
= codestream_tell ();
673 for (i
= 0; i
< 6; i
++)
675 op
= codestream_get ();
676 if (pic_pat
[i
] != op
)
681 unsigned char buf
[4];
684 op
= codestream_get ();
685 if (op
== 0x89) /* movl %ebx, x(%ebp) */
687 op
= codestream_get ();
688 if (op
== 0x5d) /* One byte offset from %ebp. */
691 codestream_read (buf
, 1);
693 else if (op
== 0x9d) /* Four byte offset from %ebp. */
696 codestream_read (buf
, 4);
698 else /* Unexpected instruction. */
700 op
= codestream_get ();
703 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
708 codestream_seek (pos
);
712 return (codestream_tell ());
716 i386_push_dummy_frame (void)
718 CORE_ADDR sp
= read_register (SP_REGNUM
);
720 char regbuf
[MAX_REGISTER_RAW_SIZE
];
722 sp
= push_word (sp
, read_register (PC_REGNUM
));
723 sp
= push_word (sp
, read_register (FP_REGNUM
));
724 write_register (FP_REGNUM
, sp
);
725 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
727 read_register_gen (regnum
, regbuf
);
728 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
730 write_register (SP_REGNUM
, sp
);
733 /* Insert the (relative) function address into the call sequence
737 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
738 struct value
**args
, struct type
*type
, int gcc_p
)
740 int from
, to
, delta
, loc
;
742 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
747 *((char *)(dummy
) + 1) = (delta
& 0xff);
748 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
749 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
750 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
754 i386_pop_frame (void)
756 struct frame_info
*frame
= get_current_frame ();
759 char regbuf
[MAX_REGISTER_RAW_SIZE
];
761 fp
= FRAME_FP (frame
);
762 i386_frame_init_saved_regs (frame
);
764 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
767 addr
= frame
->saved_regs
[regnum
];
770 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
771 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
772 REGISTER_RAW_SIZE (regnum
));
775 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
776 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
777 write_register (SP_REGNUM
, fp
+ 8);
778 flush_cached_frames ();
782 #ifdef GET_LONGJMP_TARGET
784 /* Figure out where the longjmp will land. Slurp the args out of the
785 stack. We expect the first arg to be a pointer to the jmp_buf
786 structure from which we extract the pc (JB_PC) that we will land
787 at. The pc is copied into PC. This routine returns true on
791 get_longjmp_target (CORE_ADDR
*pc
)
793 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
794 CORE_ADDR sp
, jb_addr
;
796 sp
= read_register (SP_REGNUM
);
798 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack. */
800 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
803 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
805 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
806 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
809 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
814 #endif /* GET_LONGJMP_TARGET */
818 i386_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
819 int struct_return
, CORE_ADDR struct_addr
)
821 sp
= default_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
828 store_address (buf
, 4, struct_addr
);
829 write_memory (sp
, buf
, 4);
836 i386_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
838 /* Do nothing. Everything was already done by i386_push_arguments. */
841 /* These registers are used for returning integers (and on some
842 targets also for returning `struct' and `union' values when their
843 size and alignment match an integer type). */
844 #define LOW_RETURN_REGNUM 0 /* %eax */
845 #define HIGH_RETURN_REGNUM 2 /* %edx */
847 /* Extract from an array REGBUF containing the (raw) register state, a
848 function return value of TYPE, and copy that, in virtual format,
852 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
854 int len
= TYPE_LENGTH (type
);
856 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
857 && TYPE_NFIELDS (type
) == 1)
859 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regbuf
, valbuf
);
863 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
867 warning ("Cannot find floating-point return value.");
868 memset (valbuf
, 0, len
);
872 /* Floating-point return values can be found in %st(0). */
873 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
874 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
876 /* Copy straight over, but take care of the padding. */
877 memcpy (valbuf
, ®buf
[REGISTER_BYTE (FP0_REGNUM
)],
879 memset (valbuf
+ FPU_REG_RAW_SIZE
, 0, len
- FPU_REG_RAW_SIZE
);
883 /* Convert the extended floating-point number found in
884 %st(0) to the desired type. This is probably not exactly
885 how it would happen on the target itself, but it is the
888 floatformat_to_doublest (&floatformat_i387_ext
,
889 ®buf
[REGISTER_BYTE (FP0_REGNUM
)], &val
);
890 store_floating (valbuf
, TYPE_LENGTH (type
), val
);
895 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
896 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
899 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
900 else if (len
<= (low_size
+ high_size
))
903 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
904 memcpy (valbuf
+ low_size
,
905 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
908 internal_error (__FILE__
, __LINE__
,
909 "Cannot extract return value of %d bytes long.", len
);
913 /* Write into the appropriate registers a function return value stored
914 in VALBUF of type TYPE, given in virtual format. */
917 i386_store_return_value (struct type
*type
, char *valbuf
)
919 int len
= TYPE_LENGTH (type
);
921 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
922 && TYPE_NFIELDS (type
) == 1)
924 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), valbuf
);
928 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
934 warning ("Cannot set floating-point return value.");
938 /* Returning floating-point values is a bit tricky. Apart from
939 storing the return value in %st(0), we have to simulate the
940 state of the FPU at function return point. */
942 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
943 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
945 /* Copy straight over. */
946 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
951 char buf
[FPU_REG_RAW_SIZE
];
954 /* Convert the value found in VALBUF to the extended
955 floating-point format used by the FPU. This is probably
956 not exactly how it would happen on the target itself, but
957 it is the best we can do. */
958 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
959 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
960 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
964 /* Set the top of the floating-point register stack to 7. The
965 actual value doesn't really matter, but 7 is what a normal
966 function return would end up with if the program started out
967 with a freshly initialized FPU. */
968 fstat
= read_register (FSTAT_REGNUM
);
970 write_register (FSTAT_REGNUM
, fstat
);
972 /* Mark %st(1) through %st(7) as empty. Since we set the top of
973 the floating-point register stack to 7, the appropriate value
974 for the tag word is 0x3fff. */
975 write_register (FTAG_REGNUM
, 0x3fff);
979 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
980 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
983 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
984 else if (len
<= (low_size
+ high_size
))
986 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
988 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
989 valbuf
+ low_size
, len
- low_size
);
992 internal_error (__FILE__
, __LINE__
,
993 "Cannot store return value of %d bytes long.", len
);
997 /* Extract from an array REGBUF containing the (raw) register state
998 the address in which a function should return its structure value,
1002 i386_extract_struct_value_address (char *regbuf
)
1004 return extract_address (®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)],
1005 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
));
1009 /* Return the GDB type object for the "standard" data type of data in
1010 register REGNUM. Perhaps %esi and %edi should go here, but
1011 potentially they could be used for things other than address. */
1014 i386_register_virtual_type (int regnum
)
1016 if (regnum
== PC_REGNUM
|| regnum
== FP_REGNUM
|| regnum
== SP_REGNUM
)
1017 return lookup_pointer_type (builtin_type_void
);
1019 if (IS_FP_REGNUM (regnum
))
1020 return builtin_type_long_double
;
1022 if (IS_SSE_REGNUM (regnum
))
1023 return builtin_type_v4sf
;
1025 return builtin_type_int
;
1028 /* Return true iff register REGNUM's virtual format is different from
1029 its raw format. Note that this definition assumes that the host
1030 supports IEEE 32-bit floats, since it doesn't say that SSE
1031 registers need conversion. Even if we can't find a counterexample,
1032 this is still sloppy. */
1035 i386_register_convertible (int regnum
)
1037 return IS_FP_REGNUM (regnum
);
1040 /* Convert data from raw format for register REGNUM in buffer FROM to
1041 virtual format with type TYPE in buffer TO. */
1044 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
1045 char *from
, char *to
)
1050 /* We only support floating-point values. */
1051 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
1053 warning ("Cannot convert floating-point register value "
1054 "to non-floating-point type.");
1055 memset (to
, 0, TYPE_LENGTH (type
));
1059 /* First add the necessary padding. */
1060 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
1061 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
1063 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
1064 to the extended floating-point format used by the FPU. */
1065 d
= extract_floating (buf
, sizeof buf
);
1066 store_floating (to
, TYPE_LENGTH (type
), d
);
1069 /* Convert data from virtual format with type TYPE in buffer FROM to
1070 raw format for register REGNUM in buffer TO. */
1073 i386_register_convert_to_raw (struct type
*type
, int regnum
,
1074 char *from
, char *to
)
1076 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
1077 && TYPE_LENGTH (type
) == 12);
1079 /* Simply omit the two unused bytes. */
1080 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
1084 #ifdef I386V4_SIGTRAMP_SAVED_PC
1085 /* Get saved user PC for sigtramp from the pushed ucontext on the
1086 stack for all three variants of SVR4 sigtramps. */
1089 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
1091 CORE_ADDR saved_pc_offset
= 4;
1094 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
1097 if (STREQ (name
, "_sigreturn"))
1098 saved_pc_offset
= 132 + 14 * 4;
1099 else if (STREQ (name
, "_sigacthandler"))
1100 saved_pc_offset
= 80 + 14 * 4;
1101 else if (STREQ (name
, "sigvechandler"))
1102 saved_pc_offset
= 120 + 14 * 4;
1106 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
1107 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
1109 #endif /* I386V4_SIGTRAMP_SAVED_PC */
1112 #ifdef STATIC_TRANSFORM_NAME
1113 /* SunPRO encodes the static variables. This is not related to C++
1114 mangling, it is done for C too. */
1117 sunpro_static_transform_name (char *name
)
1120 if (IS_STATIC_TRANSFORM_NAME (name
))
1122 /* For file-local statics there will be a period, a bunch of
1123 junk (the contents of which match a string given in the
1124 N_OPT), a period and the name. For function-local statics
1125 there will be a bunch of junk (which seems to change the
1126 second character from 'A' to 'B'), a period, the name of the
1127 function, and the name. So just skip everything before the
1129 p
= strrchr (name
, '.');
1135 #endif /* STATIC_TRANSFORM_NAME */
1138 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1141 skip_trampoline_code (CORE_ADDR pc
, char *name
)
1143 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
1145 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
1146 struct minimal_symbol
*indsym
=
1147 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
1148 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
1152 if (strncmp (symname
, "__imp_", 6) == 0
1153 || strncmp (symname
, "_imp_", 5) == 0)
1154 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
1157 return 0; /* Not a trampoline. */
1161 /* We have two flavours of disassembly. The machinery on this page
1162 deals with switching between those. */
1165 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
1167 if (disassembly_flavor
== att_flavor
)
1168 return print_insn_i386_att (memaddr
, info
);
1169 else if (disassembly_flavor
== intel_flavor
)
1170 return print_insn_i386_intel (memaddr
, info
);
1171 /* Never reached -- disassembly_flavour is always either att_flavor
1173 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1176 /* If the disassembly mode is intel, we have to also switch the bfd
1177 mach_type. This function is run in the set disassembly_flavor
1178 command, and does that. */
1181 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
1182 struct cmd_list_element
*c
)
1184 set_disassembly_flavor ();
1188 set_disassembly_flavor (void)
1190 if (disassembly_flavor
== att_flavor
)
1191 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
1192 else if (disassembly_flavor
== intel_flavor
)
1193 set_architecture_from_arch_mach (bfd_arch_i386
,
1194 bfd_mach_i386_i386_intel_syntax
);
1198 /* Provide a prototype to silence -Wmissing-prototypes. */
1199 void _initialize_i386_tdep (void);
1202 _initialize_i386_tdep (void)
1204 /* Initialize the table saying where each register starts in the
1210 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1212 i386_register_byte
[i
] = offset
;
1213 offset
+= i386_register_raw_size
[i
];
1217 /* Initialize the table of virtual register sizes. */
1221 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1222 i386_register_virtual_size
[i
] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i
));
1225 tm_print_insn
= gdb_print_insn_i386
;
1226 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1228 /* Add the variable that controls the disassembly flavor. */
1230 struct cmd_list_element
*new_cmd
;
1232 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1234 &disassembly_flavor
,
1236 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1237 and the default value is \"att\".",
1239 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1240 add_show_from_set (new_cmd
, &showlist
);
1243 /* Finally, initialize the disassembly flavor to the default given
1244 in the disassembly_flavor variable. */
1245 set_disassembly_flavor ();