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 /* Names of the registers. The first 10 registers match the register
41 numbering scheme used by GCC for stabs and DWARF. */
42 static char *i386_register_names
[] =
44 "eax", "ecx", "edx", "ebx",
45 "esp", "ebp", "esi", "edi",
46 "eip", "eflags", "cs", "ss",
47 "ds", "es", "fs", "gs",
48 "st0", "st1", "st2", "st3",
49 "st4", "st5", "st6", "st7",
50 "fctrl", "fstat", "ftag", "fiseg",
51 "fioff", "foseg", "fooff", "fop",
52 "xmm0", "xmm1", "xmm2", "xmm3",
53 "xmm4", "xmm5", "xmm6", "xmm7",
57 /* i386_register_offset[i] is the offset into the register file of the
58 start of register number i. We initialize this from
59 i386_register_size. */
60 static int i386_register_offset
[MAX_NUM_REGS
];
62 /* i386_register_size[i] is the number of bytes of storage in GDB's
63 register array occupied by register i. */
64 static int i386_register_size
[MAX_NUM_REGS
] = {
78 /* Return the name of register REG. */
81 i386_register_name (int reg
)
85 if (reg
>= sizeof (i386_register_names
) / sizeof (*i386_register_names
))
88 return i386_register_names
[reg
];
91 /* Return the offset into the register array of the start of register
94 i386_register_byte (int reg
)
96 return i386_register_offset
[reg
];
99 /* Return the number of bytes of storage in GDB's register array
100 occupied by register REG. */
103 i386_register_raw_size (int reg
)
105 return i386_register_size
[reg
];
108 /* Return the size in bytes of the virtual type of register REG. */
111 i386_register_virtual_size (int reg
)
113 return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (reg
));
116 /* Convert stabs register number REG to the appropriate register
117 number used by GDB. */
120 i386_stab_reg_to_regnum (int reg
)
122 /* This implements what GCC calls the "default" register map. */
123 if (reg
>= 0 && reg
<= 7)
125 /* General registers. */
128 else if (reg
>= 12 && reg
<= 19)
130 /* Floating-point registers. */
131 return reg
- 12 + FP0_REGNUM
;
133 else if (reg
>= 21 && reg
<= 28)
136 return reg
- 21 + XMM0_REGNUM
;
138 else if (reg
>= 29 && reg
<= 36)
141 /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
142 as pseudo-registers? */
143 return reg
- 29 + FP0_REGNUM
;
146 /* This will hopefully provoke a warning. */
147 return NUM_REGS
+ NUM_PSEUDO_REGS
;
150 /* Convert Dwarf register number REG to the appropriate register
151 number used by GDB. */
154 i386_dwarf_reg_to_regnum (int reg
)
156 /* The DWARF register numbering includes %eip and %eflags, and
157 numbers the floating point registers differently. */
158 if (reg
>= 0 && reg
<= 9)
160 /* General registers. */
163 else if (reg
>= 11 && reg
<= 18)
165 /* Floating-point registers. */
166 return reg
- 11 + FP0_REGNUM
;
170 /* The SSE and MMX registers have identical numbers as in stabs. */
171 return i386_stab_reg_to_regnum (reg
);
174 /* This will hopefully provoke a warning. */
175 return NUM_REGS
+ NUM_PSEUDO_REGS
;
179 /* This is the variable that is set with "set disassembly-flavor", and
180 its legitimate values. */
181 static const char att_flavor
[] = "att";
182 static const char intel_flavor
[] = "intel";
183 static const char *valid_flavors
[] =
189 static const char *disassembly_flavor
= att_flavor
;
191 /* This is used to keep the bfd arch_info in sync with the disassembly
193 static void set_disassembly_flavor_sfunc (char *, int,
194 struct cmd_list_element
*);
195 static void set_disassembly_flavor (void);
198 /* Stdio style buffering was used to minimize calls to ptrace, but
199 this buffering did not take into account that the code section
200 being accessed may not be an even number of buffers long (even if
201 the buffer is only sizeof(int) long). In cases where the code
202 section size happened to be a non-integral number of buffers long,
203 attempting to read the last buffer would fail. Simply using
204 target_read_memory and ignoring errors, rather than read_memory, is
205 not the correct solution, since legitimate access errors would then
206 be totally ignored. To properly handle this situation and continue
207 to use buffering would require that this code be able to determine
208 the minimum code section size granularity (not the alignment of the
209 section itself, since the actual failing case that pointed out this
210 problem had a section alignment of 4 but was not a multiple of 4
211 bytes long), on a target by target basis, and then adjust it's
212 buffer size accordingly. This is messy, but potentially feasible.
213 It probably needs the bfd library's help and support. For now, the
214 buffer size is set to 1. (FIXME -fnf) */
216 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
217 static CORE_ADDR codestream_next_addr
;
218 static CORE_ADDR codestream_addr
;
219 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
220 static int codestream_off
;
221 static int codestream_cnt
;
223 #define codestream_tell() (codestream_addr + codestream_off)
224 #define codestream_peek() \
225 (codestream_cnt == 0 ? \
226 codestream_fill(1) : codestream_buf[codestream_off])
227 #define codestream_get() \
228 (codestream_cnt-- == 0 ? \
229 codestream_fill(0) : codestream_buf[codestream_off++])
232 codestream_fill (int peek_flag
)
234 codestream_addr
= codestream_next_addr
;
235 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
237 codestream_cnt
= CODESTREAM_BUFSIZ
;
238 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
241 return (codestream_peek ());
243 return (codestream_get ());
247 codestream_seek (CORE_ADDR place
)
249 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
250 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
253 while (codestream_tell () != place
)
258 codestream_read (unsigned char *buf
, int count
)
263 for (i
= 0; i
< count
; i
++)
264 *p
++ = codestream_get ();
268 /* If the next instruction is a jump, move to its target. */
271 i386_follow_jump (void)
273 unsigned char buf
[4];
279 pos
= codestream_tell ();
282 if (codestream_peek () == 0x66)
288 switch (codestream_get ())
291 /* Relative jump: if data16 == 0, disp32, else disp16. */
294 codestream_read (buf
, 2);
295 delta
= extract_signed_integer (buf
, 2);
297 /* Include the size of the jmp instruction (including the
303 codestream_read (buf
, 4);
304 delta
= extract_signed_integer (buf
, 4);
310 /* Relative jump, disp8 (ignore data16). */
311 codestream_read (buf
, 1);
312 /* Sign-extend it. */
313 delta
= extract_signed_integer (buf
, 1);
318 codestream_seek (pos
);
321 /* Find & return the amount a local space allocated, and advance the
322 codestream to the first register push (if any).
324 If the entry sequence doesn't make sense, return -1, and leave
325 codestream pointer at a random spot. */
328 i386_get_frame_setup (CORE_ADDR pc
)
332 codestream_seek (pc
);
336 op
= codestream_get ();
338 if (op
== 0x58) /* popl %eax */
340 /* This function must start with
343 xchgl %eax, (%esp) 0x87 0x04 0x24
344 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
346 (the System V compiler puts out the second `xchg'
347 instruction, and the assembler doesn't try to optimize it, so
348 the 'sib' form gets generated). This sequence is used to get
349 the address of the return buffer for a function that returns
352 unsigned char buf
[4];
353 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
354 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
356 pos
= codestream_tell ();
357 codestream_read (buf
, 4);
358 if (memcmp (buf
, proto1
, 3) == 0)
360 else if (memcmp (buf
, proto2
, 4) == 0)
363 codestream_seek (pos
);
364 op
= codestream_get (); /* Update next opcode. */
367 if (op
== 0x68 || op
== 0x6a)
369 /* This function may start with
381 unsigned char buf
[8];
383 /* Skip past the `pushl' instruction; it has either a one-byte
384 or a four-byte operand, depending on the opcode. */
385 pos
= codestream_tell ();
390 codestream_seek (pos
);
392 /* Read the following 8 bytes, which should be "call _probe" (6
393 bytes) followed by "addl $4,%esp" (2 bytes). */
394 codestream_read (buf
, sizeof (buf
));
395 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
397 codestream_seek (pos
);
398 op
= codestream_get (); /* Update next opcode. */
401 if (op
== 0x55) /* pushl %ebp */
403 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
404 switch (codestream_get ())
407 if (codestream_get () != 0xec)
411 if (codestream_get () != 0xe5)
417 /* Check for stack adjustment
421 NOTE: You can't subtract a 16 bit immediate from a 32 bit
422 reg, so we don't have to worry about a data16 prefix. */
423 op
= codestream_peek ();
426 /* `subl' with 8 bit immediate. */
428 if (codestream_get () != 0xec)
429 /* Some instruction starting with 0x83 other than `subl'. */
431 codestream_seek (codestream_tell () - 2);
434 /* `subl' with signed byte immediate (though it wouldn't
435 make sense to be negative). */
436 return (codestream_get ());
441 /* Maybe it is `subl' with a 32 bit immedediate. */
443 if (codestream_get () != 0xec)
444 /* Some instruction starting with 0x81 other than `subl'. */
446 codestream_seek (codestream_tell () - 2);
449 /* It is `subl' with a 32 bit immediate. */
450 codestream_read ((unsigned char *) buf
, 4);
451 return extract_signed_integer (buf
, 4);
461 /* `enter' with 16 bit unsigned immediate. */
462 codestream_read ((unsigned char *) buf
, 2);
463 codestream_get (); /* Flush final byte of enter instruction. */
464 return extract_unsigned_integer (buf
, 2);
469 /* Return the chain-pointer for FRAME. In the case of the i386, the
470 frame's nominal address is the address of a 4-byte word containing
471 the calling frame's address. */
474 i386_frame_chain (struct frame_info
*frame
)
476 if (frame
->signal_handler_caller
)
479 if (! inside_entry_file (frame
->pc
))
480 return read_memory_unsigned_integer (frame
->frame
, 4);
485 /* Determine whether the function invocation represented by FRAME does
486 not have a from on the stack associated with it. If it does not,
487 return non-zero, otherwise return zero. */
490 i386_frameless_function_invocation (struct frame_info
*frame
)
492 if (frame
->signal_handler_caller
)
495 return frameless_look_for_prologue (frame
);
498 /* Return the saved program counter for FRAME. */
501 i386_frame_saved_pc (struct frame_info
*frame
)
503 /* FIXME: kettenis/2001-05-09: Conditionalizing the next bit of code
504 on SIGCONTEXT_PC_OFFSET and I386V4_SIGTRAMP_SAVED_PC should be
505 considered a temporary hack. I plan to come up with something
506 better when we go multi-arch. */
507 #if defined (SIGCONTEXT_PC_OFFSET) || defined (I386V4_SIGTRAMP_SAVED_PC)
508 if (frame
->signal_handler_caller
)
509 return sigtramp_saved_pc (frame
);
512 return read_memory_unsigned_integer (frame
->frame
+ 4, 4);
515 /* Immediately after a function call, return the saved pc. */
518 i386_saved_pc_after_call (struct frame_info
*frame
)
520 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
523 /* Return number of args passed to a frame.
524 Can return -1, meaning no way to tell. */
527 i386_frame_num_args (struct frame_info
*fi
)
532 /* This loses because not only might the compiler not be popping the
533 args right after the function call, it might be popping args from
534 both this call and a previous one, and we would say there are
535 more args than there really are. */
539 struct frame_info
*pfi
;
541 /* On the i386, the instruction following the call could be:
543 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
544 anything else - zero args. */
548 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
550 /* In the absence of a frame pointer, GDB doesn't get correct
551 values for nameless arguments. Return -1, so it doesn't print
552 any nameless arguments. */
555 pfi
= get_prev_frame (fi
);
558 /* NOTE: This can happen if we are looking at the frame for
559 main, because FRAME_CHAIN_VALID won't let us go into start.
560 If we have debugging symbols, that's not really a big deal;
561 it just means it will only show as many arguments to main as
568 op
= read_memory_integer (retpc
, 1);
569 if (op
== 0x59) /* pop %ecx */
573 op
= read_memory_integer (retpc
+ 1, 1);
575 /* addl $<signed imm 8 bits>, %esp */
576 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
580 else if (op
== 0x81) /* `add' with 32 bit immediate. */
582 op
= read_memory_integer (retpc
+ 1, 1);
584 /* addl $<imm 32>, %esp */
585 return read_memory_integer (retpc
+ 2, 4) / 4;
597 /* Parse the first few instructions the function to see what registers
600 We handle these cases:
602 The startup sequence can be at the start of the function, or the
603 function can start with a branch to startup code at the end.
605 %ebp can be set up with either the 'enter' instruction, or "pushl
606 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
607 once used in the System V compiler).
609 Local space is allocated just below the saved %ebp by either the
610 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
611 bit unsigned argument for space to allocate, and the 'addl'
612 instruction could have either a signed byte, or 32 bit immediate.
614 Next, the registers used by this function are pushed. With the
615 System V compiler they will always be in the order: %edi, %esi,
616 %ebx (and sometimes a harmless bug causes it to also save but not
617 restore %eax); however, the code below is willing to see the pushes
618 in any order, and will handle up to 8 of them.
620 If the setup sequence is at the end of the function, then the next
621 instruction will be a branch back to the start. */
624 i386_frame_init_saved_regs (struct frame_info
*fip
)
628 CORE_ADDR dummy_bottom
;
636 frame_saved_regs_zalloc (fip
);
638 /* If the frame is the end of a dummy, compute where the beginning
640 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
642 /* Check if the PC points in the stack, in a dummy frame. */
643 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
645 /* All registers were saved by push_call_dummy. */
647 for (i
= 0; i
< NUM_REGS
; i
++)
649 addr
-= REGISTER_RAW_SIZE (i
);
650 fip
->saved_regs
[i
] = addr
;
655 pc
= get_pc_function_start (fip
->pc
);
657 locals
= i386_get_frame_setup (pc
);
661 addr
= fip
->frame
- 4 - locals
;
662 for (i
= 0; i
< 8; i
++)
664 op
= codestream_get ();
665 if (op
< 0x50 || op
> 0x57)
667 #ifdef I386_REGNO_TO_SYMMETRY
668 /* Dynix uses different internal numbering. Ick. */
669 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
671 fip
->saved_regs
[op
- 0x50] = addr
;
677 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
678 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
681 /* Return PC of first real instruction. */
684 i386_skip_prologue (int pc
)
688 static unsigned char pic_pat
[6] =
689 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
690 0x5b, /* popl %ebx */
694 if (i386_get_frame_setup (pc
) < 0)
697 /* Found valid frame setup -- codestream now points to start of push
698 instructions for saving registers. */
700 /* Skip over register saves. */
701 for (i
= 0; i
< 8; i
++)
703 op
= codestream_peek ();
704 /* Break if not `pushl' instrunction. */
705 if (op
< 0x50 || op
> 0x57)
710 /* The native cc on SVR4 in -K PIC mode inserts the following code
711 to get the address of the global offset table (GOT) into register
716 movl %ebx,x(%ebp) (optional)
719 This code is with the rest of the prologue (at the end of the
720 function), so we have to skip it to get to the first real
721 instruction at the start of the function. */
723 pos
= codestream_tell ();
724 for (i
= 0; i
< 6; i
++)
726 op
= codestream_get ();
727 if (pic_pat
[i
] != op
)
732 unsigned char buf
[4];
735 op
= codestream_get ();
736 if (op
== 0x89) /* movl %ebx, x(%ebp) */
738 op
= codestream_get ();
739 if (op
== 0x5d) /* One byte offset from %ebp. */
742 codestream_read (buf
, 1);
744 else if (op
== 0x9d) /* Four byte offset from %ebp. */
747 codestream_read (buf
, 4);
749 else /* Unexpected instruction. */
751 op
= codestream_get ();
754 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
759 codestream_seek (pos
);
763 return (codestream_tell ());
767 i386_push_dummy_frame (void)
769 CORE_ADDR sp
= read_register (SP_REGNUM
);
771 char regbuf
[MAX_REGISTER_RAW_SIZE
];
773 sp
= push_word (sp
, read_register (PC_REGNUM
));
774 sp
= push_word (sp
, read_register (FP_REGNUM
));
775 write_register (FP_REGNUM
, sp
);
776 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
778 read_register_gen (regnum
, regbuf
);
779 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
781 write_register (SP_REGNUM
, sp
);
784 /* Insert the (relative) function address into the call sequence
788 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
789 struct value
**args
, struct type
*type
, int gcc_p
)
791 int from
, to
, delta
, loc
;
793 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
798 *((char *)(dummy
) + 1) = (delta
& 0xff);
799 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
800 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
801 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
805 i386_pop_frame (void)
807 struct frame_info
*frame
= get_current_frame ();
810 char regbuf
[MAX_REGISTER_RAW_SIZE
];
812 fp
= FRAME_FP (frame
);
813 i386_frame_init_saved_regs (frame
);
815 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
818 addr
= frame
->saved_regs
[regnum
];
821 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
822 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
823 REGISTER_RAW_SIZE (regnum
));
826 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
827 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
828 write_register (SP_REGNUM
, fp
+ 8);
829 flush_cached_frames ();
833 #ifdef GET_LONGJMP_TARGET
835 /* Figure out where the longjmp will land. Slurp the args out of the
836 stack. We expect the first arg to be a pointer to the jmp_buf
837 structure from which we extract the pc (JB_PC) that we will land
838 at. The pc is copied into PC. This routine returns true on
842 get_longjmp_target (CORE_ADDR
*pc
)
844 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
845 CORE_ADDR sp
, jb_addr
;
847 sp
= read_register (SP_REGNUM
);
849 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack. */
851 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
854 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
856 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
857 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
860 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
865 #endif /* GET_LONGJMP_TARGET */
869 i386_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
870 int struct_return
, CORE_ADDR struct_addr
)
872 sp
= default_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
879 store_address (buf
, 4, struct_addr
);
880 write_memory (sp
, buf
, 4);
887 i386_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
889 /* Do nothing. Everything was already done by i386_push_arguments. */
892 /* These registers are used for returning integers (and on some
893 targets also for returning `struct' and `union' values when their
894 size and alignment match an integer type). */
895 #define LOW_RETURN_REGNUM 0 /* %eax */
896 #define HIGH_RETURN_REGNUM 2 /* %edx */
898 /* Extract from an array REGBUF containing the (raw) register state, a
899 function return value of TYPE, and copy that, in virtual format,
903 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
905 int len
= TYPE_LENGTH (type
);
907 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
908 && TYPE_NFIELDS (type
) == 1)
910 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regbuf
, valbuf
);
914 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
918 warning ("Cannot find floating-point return value.");
919 memset (valbuf
, 0, len
);
923 /* Floating-point return values can be found in %st(0). Convert
924 its contents to the desired type. This is probably not
925 exactly how it would happen on the target itself, but it is
926 the best we can do. */
927 convert_typed_floating (®buf
[REGISTER_BYTE (FP0_REGNUM
)],
928 builtin_type_i387_ext
, valbuf
, type
);
932 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
933 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
936 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
937 else if (len
<= (low_size
+ high_size
))
940 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
941 memcpy (valbuf
+ low_size
,
942 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
945 internal_error (__FILE__
, __LINE__
,
946 "Cannot extract return value of %d bytes long.", len
);
950 /* Write into the appropriate registers a function return value stored
951 in VALBUF of type TYPE, given in virtual format. */
954 i386_store_return_value (struct type
*type
, char *valbuf
)
956 int len
= TYPE_LENGTH (type
);
958 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
959 && TYPE_NFIELDS (type
) == 1)
961 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), valbuf
);
965 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
968 char buf
[FPU_REG_RAW_SIZE
];
972 warning ("Cannot set floating-point return value.");
976 /* Returning floating-point values is a bit tricky. Apart from
977 storing the return value in %st(0), we have to simulate the
978 state of the FPU at function return point. */
980 /* Convert the value found in VALBUF to the extended
981 floating-point format used by the FPU. This is probably
982 not exactly how it would happen on the target itself, but
983 it is the best we can do. */
984 convert_typed_floating (valbuf
, type
, buf
, builtin_type_i387_ext
);
985 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
988 /* Set the top of the floating-point register stack to 7. The
989 actual value doesn't really matter, but 7 is what a normal
990 function return would end up with if the program started out
991 with a freshly initialized FPU. */
992 fstat
= read_register (FSTAT_REGNUM
);
994 write_register (FSTAT_REGNUM
, fstat
);
996 /* Mark %st(1) through %st(7) as empty. Since we set the top of
997 the floating-point register stack to 7, the appropriate value
998 for the tag word is 0x3fff. */
999 write_register (FTAG_REGNUM
, 0x3fff);
1003 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
1004 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
1006 if (len
<= low_size
)
1007 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
1008 else if (len
<= (low_size
+ high_size
))
1010 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
1012 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
1013 valbuf
+ low_size
, len
- low_size
);
1016 internal_error (__FILE__
, __LINE__
,
1017 "Cannot store return value of %d bytes long.", len
);
1021 /* Extract from an array REGBUF containing the (raw) register state
1022 the address in which a function should return its structure value,
1026 i386_extract_struct_value_address (char *regbuf
)
1028 return extract_address (®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)],
1029 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
));
1033 /* Return the GDB type object for the "standard" data type of data in
1034 register REGNUM. Perhaps %esi and %edi should go here, but
1035 potentially they could be used for things other than address. */
1038 i386_register_virtual_type (int regnum
)
1040 if (regnum
== PC_REGNUM
|| regnum
== FP_REGNUM
|| regnum
== SP_REGNUM
)
1041 return lookup_pointer_type (builtin_type_void
);
1043 if (IS_FP_REGNUM (regnum
))
1044 return builtin_type_i387_ext
;
1046 if (IS_SSE_REGNUM (regnum
))
1047 return builtin_type_v4sf
;
1049 return builtin_type_int
;
1052 /* Return true iff register REGNUM's virtual format is different from
1053 its raw format. Note that this definition assumes that the host
1054 supports IEEE 32-bit floats, since it doesn't say that SSE
1055 registers need conversion. Even if we can't find a counterexample,
1056 this is still sloppy. */
1059 i386_register_convertible (int regnum
)
1061 return IS_FP_REGNUM (regnum
);
1064 /* Convert data from raw format for register REGNUM in buffer FROM to
1065 virtual format with type TYPE in buffer TO. */
1068 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
1069 char *from
, char *to
)
1071 gdb_assert (IS_FP_REGNUM (regnum
));
1073 /* We only support floating-point values. */
1074 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
1076 warning ("Cannot convert floating-point register value "
1077 "to non-floating-point type.");
1078 memset (to
, 0, TYPE_LENGTH (type
));
1082 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
1083 the extended floating-point format used by the FPU. */
1084 convert_typed_floating (from
, builtin_type_i387_ext
, to
, type
);
1087 /* Convert data from virtual format with type TYPE in buffer FROM to
1088 raw format for register REGNUM in buffer TO. */
1091 i386_register_convert_to_raw (struct type
*type
, int regnum
,
1092 char *from
, char *to
)
1094 gdb_assert (IS_FP_REGNUM (regnum
));
1096 /* We only support floating-point values. */
1097 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
1099 warning ("Cannot convert non-floating-point type "
1100 "to floating-point register value.");
1101 memset (to
, 0, TYPE_LENGTH (type
));
1105 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
1106 to the extended floating-point format used by the FPU. */
1107 convert_typed_floating (from
, type
, to
, builtin_type_i387_ext
);
1111 #ifdef I386V4_SIGTRAMP_SAVED_PC
1112 /* Get saved user PC for sigtramp from the pushed ucontext on the
1113 stack for all three variants of SVR4 sigtramps. */
1116 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
1118 CORE_ADDR saved_pc_offset
= 4;
1121 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
1124 if (STREQ (name
, "_sigreturn"))
1125 saved_pc_offset
= 132 + 14 * 4;
1126 else if (STREQ (name
, "_sigacthandler"))
1127 saved_pc_offset
= 80 + 14 * 4;
1128 else if (STREQ (name
, "sigvechandler"))
1129 saved_pc_offset
= 120 + 14 * 4;
1133 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
1134 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
1136 #endif /* I386V4_SIGTRAMP_SAVED_PC */
1139 #ifdef STATIC_TRANSFORM_NAME
1140 /* SunPRO encodes the static variables. This is not related to C++
1141 mangling, it is done for C too. */
1144 sunpro_static_transform_name (char *name
)
1147 if (IS_STATIC_TRANSFORM_NAME (name
))
1149 /* For file-local statics there will be a period, a bunch of
1150 junk (the contents of which match a string given in the
1151 N_OPT), a period and the name. For function-local statics
1152 there will be a bunch of junk (which seems to change the
1153 second character from 'A' to 'B'), a period, the name of the
1154 function, and the name. So just skip everything before the
1156 p
= strrchr (name
, '.');
1162 #endif /* STATIC_TRANSFORM_NAME */
1165 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1168 skip_trampoline_code (CORE_ADDR pc
, char *name
)
1170 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
1172 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
1173 struct minimal_symbol
*indsym
=
1174 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
1175 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
1179 if (strncmp (symname
, "__imp_", 6) == 0
1180 || strncmp (symname
, "_imp_", 5) == 0)
1181 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
1184 return 0; /* Not a trampoline. */
1188 /* We have two flavours of disassembly. The machinery on this page
1189 deals with switching between those. */
1192 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
1194 if (disassembly_flavor
== att_flavor
)
1195 return print_insn_i386_att (memaddr
, info
);
1196 else if (disassembly_flavor
== intel_flavor
)
1197 return print_insn_i386_intel (memaddr
, info
);
1198 /* Never reached -- disassembly_flavour is always either att_flavor
1200 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1203 /* If the disassembly mode is intel, we have to also switch the bfd
1204 mach_type. This function is run in the set disassembly_flavor
1205 command, and does that. */
1208 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
1209 struct cmd_list_element
*c
)
1211 set_disassembly_flavor ();
1215 set_disassembly_flavor (void)
1217 if (disassembly_flavor
== att_flavor
)
1218 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
1219 else if (disassembly_flavor
== intel_flavor
)
1220 set_architecture_from_arch_mach (bfd_arch_i386
,
1221 bfd_mach_i386_i386_intel_syntax
);
1225 /* Provide a prototype to silence -Wmissing-prototypes. */
1226 void _initialize_i386_tdep (void);
1229 _initialize_i386_tdep (void)
1231 /* Initialize the table saying where each register starts in the
1237 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1239 i386_register_offset
[i
] = offset
;
1240 offset
+= i386_register_size
[i
];
1244 tm_print_insn
= gdb_print_insn_i386
;
1245 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1247 /* Add the variable that controls the disassembly flavor. */
1249 struct cmd_list_element
*new_cmd
;
1251 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1253 &disassembly_flavor
,
1255 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1256 and the default value is \"att\".",
1258 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1259 add_show_from_set (new_cmd
, &showlist
);
1262 /* Finally, initialize the disassembly flavor to the default given
1263 in the disassembly_flavor variable. */
1264 set_disassembly_flavor ();