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
];
64 /* This is the variable that is set with "set disassembly-flavor", and
65 its legitimate values. */
66 static const char att_flavor
[] = "att";
67 static const char intel_flavor
[] = "intel";
68 static const char *valid_flavors
[] =
74 static const char *disassembly_flavor
= att_flavor
;
76 /* This is used to keep the bfd arch_info in sync with the disassembly
78 static void set_disassembly_flavor_sfunc (char *, int,
79 struct cmd_list_element
*);
80 static void set_disassembly_flavor (void);
83 /* Stdio style buffering was used to minimize calls to ptrace, but
84 this buffering did not take into account that the code section
85 being accessed may not be an even number of buffers long (even if
86 the buffer is only sizeof(int) long). In cases where the code
87 section size happened to be a non-integral number of buffers long,
88 attempting to read the last buffer would fail. Simply using
89 target_read_memory and ignoring errors, rather than read_memory, is
90 not the correct solution, since legitimate access errors would then
91 be totally ignored. To properly handle this situation and continue
92 to use buffering would require that this code be able to determine
93 the minimum code section size granularity (not the alignment of the
94 section itself, since the actual failing case that pointed out this
95 problem had a section alignment of 4 but was not a multiple of 4
96 bytes long), on a target by target basis, and then adjust it's
97 buffer size accordingly. This is messy, but potentially feasible.
98 It probably needs the bfd library's help and support. For now, the
99 buffer size is set to 1. (FIXME -fnf) */
101 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
102 static CORE_ADDR codestream_next_addr
;
103 static CORE_ADDR codestream_addr
;
104 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
105 static int codestream_off
;
106 static int codestream_cnt
;
108 #define codestream_tell() (codestream_addr + codestream_off)
109 #define codestream_peek() \
110 (codestream_cnt == 0 ? \
111 codestream_fill(1) : codestream_buf[codestream_off])
112 #define codestream_get() \
113 (codestream_cnt-- == 0 ? \
114 codestream_fill(0) : codestream_buf[codestream_off++])
117 codestream_fill (int peek_flag
)
119 codestream_addr
= codestream_next_addr
;
120 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
122 codestream_cnt
= CODESTREAM_BUFSIZ
;
123 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
126 return (codestream_peek ());
128 return (codestream_get ());
132 codestream_seek (CORE_ADDR place
)
134 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
135 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
138 while (codestream_tell () != place
)
143 codestream_read (unsigned char *buf
, int count
)
148 for (i
= 0; i
< count
; i
++)
149 *p
++ = codestream_get ();
153 /* If the next instruction is a jump, move to its target. */
156 i386_follow_jump (void)
158 unsigned char buf
[4];
164 pos
= codestream_tell ();
167 if (codestream_peek () == 0x66)
173 switch (codestream_get ())
176 /* Relative jump: if data16 == 0, disp32, else disp16. */
179 codestream_read (buf
, 2);
180 delta
= extract_signed_integer (buf
, 2);
182 /* Include the size of the jmp instruction (including the
188 codestream_read (buf
, 4);
189 delta
= extract_signed_integer (buf
, 4);
195 /* Relative jump, disp8 (ignore data16). */
196 codestream_read (buf
, 1);
197 /* Sign-extend it. */
198 delta
= extract_signed_integer (buf
, 1);
203 codestream_seek (pos
);
206 /* Find & return the amount a local space allocated, and advance the
207 codestream to the first register push (if any).
209 If the entry sequence doesn't make sense, return -1, and leave
210 codestream pointer at a random spot. */
213 i386_get_frame_setup (CORE_ADDR pc
)
217 codestream_seek (pc
);
221 op
= codestream_get ();
223 if (op
== 0x58) /* popl %eax */
225 /* This function must start with
228 xchgl %eax, (%esp) 0x87 0x04 0x24
229 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
231 (the System V compiler puts out the second `xchg'
232 instruction, and the assembler doesn't try to optimize it, so
233 the 'sib' form gets generated). This sequence is used to get
234 the address of the return buffer for a function that returns
237 unsigned char buf
[4];
238 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
239 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
241 pos
= codestream_tell ();
242 codestream_read (buf
, 4);
243 if (memcmp (buf
, proto1
, 3) == 0)
245 else if (memcmp (buf
, proto2
, 4) == 0)
248 codestream_seek (pos
);
249 op
= codestream_get (); /* Update next opcode. */
252 if (op
== 0x68 || op
== 0x6a)
254 /* This function may start with
266 unsigned char buf
[8];
268 /* Skip past the `pushl' instruction; it has either a one-byte
269 or a four-byte operand, depending on the opcode. */
270 pos
= codestream_tell ();
275 codestream_seek (pos
);
277 /* Read the following 8 bytes, which should be "call _probe" (6
278 bytes) followed by "addl $4,%esp" (2 bytes). */
279 codestream_read (buf
, sizeof (buf
));
280 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
282 codestream_seek (pos
);
283 op
= codestream_get (); /* Update next opcode. */
286 if (op
== 0x55) /* pushl %ebp */
288 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
289 switch (codestream_get ())
292 if (codestream_get () != 0xec)
296 if (codestream_get () != 0xe5)
302 /* Check for stack adjustment
306 NOTE: You can't subtract a 16 bit immediate from a 32 bit
307 reg, so we don't have to worry about a data16 prefix. */
308 op
= codestream_peek ();
311 /* `subl' with 8 bit immediate. */
313 if (codestream_get () != 0xec)
314 /* Some instruction starting with 0x83 other than `subl'. */
316 codestream_seek (codestream_tell () - 2);
319 /* `subl' with signed byte immediate (though it wouldn't
320 make sense to be negative). */
321 return (codestream_get ());
326 /* Maybe it is `subl' with a 32 bit immedediate. */
328 if (codestream_get () != 0xec)
329 /* Some instruction starting with 0x81 other than `subl'. */
331 codestream_seek (codestream_tell () - 2);
334 /* It is `subl' with a 32 bit immediate. */
335 codestream_read ((unsigned char *) buf
, 4);
336 return extract_signed_integer (buf
, 4);
346 /* `enter' with 16 bit unsigned immediate. */
347 codestream_read ((unsigned char *) buf
, 2);
348 codestream_get (); /* Flush final byte of enter instruction. */
349 return extract_unsigned_integer (buf
, 2);
354 /* Return the chain-pointer for FRAME. In the case of the i386, the
355 frame's nominal address is the address of a 4-byte word containing
356 the calling frame's address. */
359 i386_frame_chain (struct frame_info
*frame
)
361 if (frame
->signal_handler_caller
)
364 if (! inside_entry_file (frame
->pc
))
365 return read_memory_unsigned_integer (frame
->frame
, 4);
370 /* Determine whether the function invocation represented by FRAME does
371 not have a from on the stack associated with it. If it does not,
372 return non-zero, otherwise return zero. */
375 i386_frameless_function_invocation (struct frame_info
*frame
)
377 if (frame
->signal_handler_caller
)
380 return frameless_look_for_prologue (frame
);
383 /* Return the saved program counter for FRAME. */
386 i386_frame_saved_pc (struct frame_info
*frame
)
388 /* FIXME: kettenis/2001-05-09: Conditionalizing the next bit of code
389 on SIGCONTEXT_PC_OFFSET and I386V4_SIGTRAMP_SAVED_PC should be
390 considered a temporary hack. I plan to come up with something
391 better when we go multi-arch. */
392 #if defined (SIGCONTEXT_PC_OFFSET) || defined (I386V4_SIGTRAMP_SAVED_PC)
393 if (frame
->signal_handler_caller
)
394 return sigtramp_saved_pc (frame
);
397 return read_memory_unsigned_integer (frame
->frame
+ 4, 4);
400 /* Immediately after a function call, return the saved pc. */
403 i386_saved_pc_after_call (struct frame_info
*frame
)
405 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
408 /* Return number of args passed to a frame.
409 Can return -1, meaning no way to tell. */
412 i386_frame_num_args (struct frame_info
*fi
)
417 /* This loses because not only might the compiler not be popping the
418 args right after the function call, it might be popping args from
419 both this call and a previous one, and we would say there are
420 more args than there really are. */
424 struct frame_info
*pfi
;
426 /* On the i386, the instruction following the call could be:
428 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
429 anything else - zero args. */
433 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
435 /* In the absence of a frame pointer, GDB doesn't get correct
436 values for nameless arguments. Return -1, so it doesn't print
437 any nameless arguments. */
440 pfi
= get_prev_frame (fi
);
443 /* NOTE: This can happen if we are looking at the frame for
444 main, because FRAME_CHAIN_VALID won't let us go into start.
445 If we have debugging symbols, that's not really a big deal;
446 it just means it will only show as many arguments to main as
453 op
= read_memory_integer (retpc
, 1);
454 if (op
== 0x59) /* pop %ecx */
458 op
= read_memory_integer (retpc
+ 1, 1);
460 /* addl $<signed imm 8 bits>, %esp */
461 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
465 else if (op
== 0x81) /* `add' with 32 bit immediate. */
467 op
= read_memory_integer (retpc
+ 1, 1);
469 /* addl $<imm 32>, %esp */
470 return read_memory_integer (retpc
+ 2, 4) / 4;
482 /* Parse the first few instructions the function to see what registers
485 We handle these cases:
487 The startup sequence can be at the start of the function, or the
488 function can start with a branch to startup code at the end.
490 %ebp can be set up with either the 'enter' instruction, or "pushl
491 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
492 once used in the System V compiler).
494 Local space is allocated just below the saved %ebp by either the
495 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
496 bit unsigned argument for space to allocate, and the 'addl'
497 instruction could have either a signed byte, or 32 bit immediate.
499 Next, the registers used by this function are pushed. With the
500 System V compiler they will always be in the order: %edi, %esi,
501 %ebx (and sometimes a harmless bug causes it to also save but not
502 restore %eax); however, the code below is willing to see the pushes
503 in any order, and will handle up to 8 of them.
505 If the setup sequence is at the end of the function, then the next
506 instruction will be a branch back to the start. */
509 i386_frame_init_saved_regs (struct frame_info
*fip
)
513 CORE_ADDR dummy_bottom
;
521 frame_saved_regs_zalloc (fip
);
523 /* If the frame is the end of a dummy, compute where the beginning
525 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
527 /* Check if the PC points in the stack, in a dummy frame. */
528 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
530 /* All registers were saved by push_call_dummy. */
532 for (i
= 0; i
< NUM_REGS
; i
++)
534 addr
-= REGISTER_RAW_SIZE (i
);
535 fip
->saved_regs
[i
] = addr
;
540 pc
= get_pc_function_start (fip
->pc
);
542 locals
= i386_get_frame_setup (pc
);
546 addr
= fip
->frame
- 4 - locals
;
547 for (i
= 0; i
< 8; i
++)
549 op
= codestream_get ();
550 if (op
< 0x50 || op
> 0x57)
552 #ifdef I386_REGNO_TO_SYMMETRY
553 /* Dynix uses different internal numbering. Ick. */
554 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
556 fip
->saved_regs
[op
- 0x50] = addr
;
562 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
563 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
566 /* Return PC of first real instruction. */
569 i386_skip_prologue (int pc
)
573 static unsigned char pic_pat
[6] =
574 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
575 0x5b, /* popl %ebx */
579 if (i386_get_frame_setup (pc
) < 0)
582 /* Found valid frame setup -- codestream now points to start of push
583 instructions for saving registers. */
585 /* Skip over register saves. */
586 for (i
= 0; i
< 8; i
++)
588 op
= codestream_peek ();
589 /* Break if not `pushl' instrunction. */
590 if (op
< 0x50 || op
> 0x57)
595 /* The native cc on SVR4 in -K PIC mode inserts the following code
596 to get the address of the global offset table (GOT) into register
601 movl %ebx,x(%ebp) (optional)
604 This code is with the rest of the prologue (at the end of the
605 function), so we have to skip it to get to the first real
606 instruction at the start of the function. */
608 pos
= codestream_tell ();
609 for (i
= 0; i
< 6; i
++)
611 op
= codestream_get ();
612 if (pic_pat
[i
] != op
)
617 unsigned char buf
[4];
620 op
= codestream_get ();
621 if (op
== 0x89) /* movl %ebx, x(%ebp) */
623 op
= codestream_get ();
624 if (op
== 0x5d) /* One byte offset from %ebp. */
627 codestream_read (buf
, 1);
629 else if (op
== 0x9d) /* Four byte offset from %ebp. */
632 codestream_read (buf
, 4);
634 else /* Unexpected instruction. */
636 op
= codestream_get ();
639 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
644 codestream_seek (pos
);
648 return (codestream_tell ());
652 i386_push_dummy_frame (void)
654 CORE_ADDR sp
= read_register (SP_REGNUM
);
656 char regbuf
[MAX_REGISTER_RAW_SIZE
];
658 sp
= push_word (sp
, read_register (PC_REGNUM
));
659 sp
= push_word (sp
, read_register (FP_REGNUM
));
660 write_register (FP_REGNUM
, sp
);
661 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
663 read_register_gen (regnum
, regbuf
);
664 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
666 write_register (SP_REGNUM
, sp
);
669 /* Insert the (relative) function address into the call sequence
673 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
674 struct value
**args
, struct type
*type
, int gcc_p
)
676 int from
, to
, delta
, loc
;
678 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
683 *((char *)(dummy
) + 1) = (delta
& 0xff);
684 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
685 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
686 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
690 i386_pop_frame (void)
692 struct frame_info
*frame
= get_current_frame ();
695 char regbuf
[MAX_REGISTER_RAW_SIZE
];
697 fp
= FRAME_FP (frame
);
698 i386_frame_init_saved_regs (frame
);
700 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
703 addr
= frame
->saved_regs
[regnum
];
706 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
707 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
708 REGISTER_RAW_SIZE (regnum
));
711 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
712 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
713 write_register (SP_REGNUM
, fp
+ 8);
714 flush_cached_frames ();
718 #ifdef GET_LONGJMP_TARGET
720 /* Figure out where the longjmp will land. Slurp the args out of the
721 stack. We expect the first arg to be a pointer to the jmp_buf
722 structure from which we extract the pc (JB_PC) that we will land
723 at. The pc is copied into PC. This routine returns true on
727 get_longjmp_target (CORE_ADDR
*pc
)
729 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
730 CORE_ADDR sp
, jb_addr
;
732 sp
= read_register (SP_REGNUM
);
734 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack. */
736 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
739 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
741 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
742 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
745 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
750 #endif /* GET_LONGJMP_TARGET */
754 i386_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
755 int struct_return
, CORE_ADDR struct_addr
)
757 sp
= default_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
764 store_address (buf
, 4, struct_addr
);
765 write_memory (sp
, buf
, 4);
772 i386_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
774 /* Do nothing. Everything was already done by i386_push_arguments. */
777 /* These registers are used for returning integers (and on some
778 targets also for returning `struct' and `union' values when their
779 size and alignment match an integer type). */
780 #define LOW_RETURN_REGNUM 0 /* %eax */
781 #define HIGH_RETURN_REGNUM 2 /* %edx */
783 /* Extract from an array REGBUF containing the (raw) register state, a
784 function return value of TYPE, and copy that, in virtual format,
788 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
790 int len
= TYPE_LENGTH (type
);
792 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
793 && TYPE_NFIELDS (type
) == 1)
795 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regbuf
, valbuf
);
799 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
803 warning ("Cannot find floating-point return value.");
804 memset (valbuf
, 0, len
);
808 /* Floating-point return values can be found in %st(0). */
809 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
810 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
812 /* Copy straight over, but take care of the padding. */
813 memcpy (valbuf
, ®buf
[REGISTER_BYTE (FP0_REGNUM
)],
815 memset (valbuf
+ FPU_REG_RAW_SIZE
, 0, len
- FPU_REG_RAW_SIZE
);
819 /* Convert the extended floating-point number found in
820 %st(0) to the desired type. This is probably not exactly
821 how it would happen on the target itself, but it is the
824 floatformat_to_doublest (&floatformat_i387_ext
,
825 ®buf
[REGISTER_BYTE (FP0_REGNUM
)], &val
);
826 store_floating (valbuf
, TYPE_LENGTH (type
), val
);
831 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
832 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
835 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
836 else if (len
<= (low_size
+ high_size
))
839 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
840 memcpy (valbuf
+ low_size
,
841 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
844 internal_error (__FILE__
, __LINE__
,
845 "Cannot extract return value of %d bytes long.", len
);
849 /* Write into the appropriate registers a function return value stored
850 in VALBUF of type TYPE, given in virtual format. */
853 i386_store_return_value (struct type
*type
, char *valbuf
)
855 int len
= TYPE_LENGTH (type
);
857 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
858 && TYPE_NFIELDS (type
) == 1)
860 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), valbuf
);
864 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
870 warning ("Cannot set floating-point return value.");
874 /* Returning floating-point values is a bit tricky. Apart from
875 storing the return value in %st(0), we have to simulate the
876 state of the FPU at function return point. */
878 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
879 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
881 /* Copy straight over. */
882 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
887 char buf
[FPU_REG_RAW_SIZE
];
890 /* Convert the value found in VALBUF to the extended
891 floating-point format used by the FPU. This is probably
892 not exactly how it would happen on the target itself, but
893 it is the best we can do. */
894 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
895 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
896 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
900 /* Set the top of the floating-point register stack to 7. The
901 actual value doesn't really matter, but 7 is what a normal
902 function return would end up with if the program started out
903 with a freshly initialized FPU. */
904 fstat
= read_register (FSTAT_REGNUM
);
906 write_register (FSTAT_REGNUM
, fstat
);
908 /* Mark %st(1) through %st(7) as empty. Since we set the top of
909 the floating-point register stack to 7, the appropriate value
910 for the tag word is 0x3fff. */
911 write_register (FTAG_REGNUM
, 0x3fff);
915 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
916 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
919 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
920 else if (len
<= (low_size
+ high_size
))
922 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
924 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
925 valbuf
+ low_size
, len
- low_size
);
928 internal_error (__FILE__
, __LINE__
,
929 "Cannot store return value of %d bytes long.", len
);
933 /* Extract from an array REGBUF containing the (raw) register state
934 the address in which a function should return its structure value,
938 i386_extract_struct_value_address (char *regbuf
)
940 return extract_address (®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)],
941 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
));
945 /* Return the GDB type object for the "standard" data type of data in
946 register REGNUM. Perhaps %esi and %edi should go here, but
947 potentially they could be used for things other than address. */
950 i386_register_virtual_type (int regnum
)
952 if (regnum
== PC_REGNUM
|| regnum
== FP_REGNUM
|| regnum
== SP_REGNUM
)
953 return lookup_pointer_type (builtin_type_void
);
955 if (IS_FP_REGNUM (regnum
))
956 return builtin_type_long_double
;
958 if (IS_SSE_REGNUM (regnum
))
959 return builtin_type_v4sf
;
961 return builtin_type_int
;
964 /* Return true iff register REGNUM's virtual format is different from
965 its raw format. Note that this definition assumes that the host
966 supports IEEE 32-bit floats, since it doesn't say that SSE
967 registers need conversion. Even if we can't find a counterexample,
968 this is still sloppy. */
971 i386_register_convertible (int regnum
)
973 return IS_FP_REGNUM (regnum
);
976 /* Convert data from raw format for register REGNUM in buffer FROM to
977 virtual format with type TYPE in buffer TO. */
980 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
981 char *from
, char *to
)
986 /* We only support floating-point values. */
987 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
);
989 /* First add the necessary padding. */
990 memcpy (buf
, from
, FPU_REG_RAW_SIZE
);
991 memset (buf
+ FPU_REG_RAW_SIZE
, 0, sizeof buf
- FPU_REG_RAW_SIZE
);
993 /* Convert to TYPE. This should be a no-op, if TYPE is equivalent
994 to the extended floating-point format used by the FPU. */
995 d
= extract_floating (buf
, sizeof buf
);
996 store_floating (to
, TYPE_LENGTH (type
), d
);
999 /* Convert data from virtual format with type TYPE in buffer FROM to
1000 raw format for register REGNUM in buffer TO. */
1003 i386_register_convert_to_raw (struct type
*type
, int regnum
,
1004 char *from
, char *to
)
1006 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_FLT
1007 && TYPE_LENGTH (type
) == 12);
1009 /* Simply omit the two unused bytes. */
1010 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
1014 #ifdef I386V4_SIGTRAMP_SAVED_PC
1015 /* Get saved user PC for sigtramp from the pushed ucontext on the
1016 stack for all three variants of SVR4 sigtramps. */
1019 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
1021 CORE_ADDR saved_pc_offset
= 4;
1024 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
1027 if (STREQ (name
, "_sigreturn"))
1028 saved_pc_offset
= 132 + 14 * 4;
1029 else if (STREQ (name
, "_sigacthandler"))
1030 saved_pc_offset
= 80 + 14 * 4;
1031 else if (STREQ (name
, "sigvechandler"))
1032 saved_pc_offset
= 120 + 14 * 4;
1036 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
1037 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
1039 #endif /* I386V4_SIGTRAMP_SAVED_PC */
1042 #ifdef STATIC_TRANSFORM_NAME
1043 /* SunPRO encodes the static variables. This is not related to C++
1044 mangling, it is done for C too. */
1047 sunpro_static_transform_name (char *name
)
1050 if (IS_STATIC_TRANSFORM_NAME (name
))
1052 /* For file-local statics there will be a period, a bunch of
1053 junk (the contents of which match a string given in the
1054 N_OPT), a period and the name. For function-local statics
1055 there will be a bunch of junk (which seems to change the
1056 second character from 'A' to 'B'), a period, the name of the
1057 function, and the name. So just skip everything before the
1059 p
= strrchr (name
, '.');
1065 #endif /* STATIC_TRANSFORM_NAME */
1068 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1071 skip_trampoline_code (CORE_ADDR pc
, char *name
)
1073 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
1075 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
1076 struct minimal_symbol
*indsym
=
1077 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
1078 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
1082 if (strncmp (symname
, "__imp_", 6) == 0
1083 || strncmp (symname
, "_imp_", 5) == 0)
1084 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
1087 return 0; /* Not a trampoline. */
1091 /* We have two flavours of disassembly. The machinery on this page
1092 deals with switching between those. */
1095 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
1097 if (disassembly_flavor
== att_flavor
)
1098 return print_insn_i386_att (memaddr
, info
);
1099 else if (disassembly_flavor
== intel_flavor
)
1100 return print_insn_i386_intel (memaddr
, info
);
1101 /* Never reached -- disassembly_flavour is always either att_flavor
1103 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1106 /* If the disassembly mode is intel, we have to also switch the bfd
1107 mach_type. This function is run in the set disassembly_flavor
1108 command, and does that. */
1111 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
1112 struct cmd_list_element
*c
)
1114 set_disassembly_flavor ();
1118 set_disassembly_flavor (void)
1120 if (disassembly_flavor
== att_flavor
)
1121 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
1122 else if (disassembly_flavor
== intel_flavor
)
1123 set_architecture_from_arch_mach (bfd_arch_i386
,
1124 bfd_mach_i386_i386_intel_syntax
);
1128 /* Provide a prototype to silence -Wmissing-prototypes. */
1129 void _initialize_i386_tdep (void);
1132 _initialize_i386_tdep (void)
1134 /* Initialize the table saying where each register starts in the
1140 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1142 i386_register_byte
[i
] = offset
;
1143 offset
+= i386_register_raw_size
[i
];
1147 /* Initialize the table of virtual register sizes. */
1151 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1152 i386_register_virtual_size
[i
] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i
));
1155 tm_print_insn
= gdb_print_insn_i386
;
1156 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1158 /* Add the variable that controls the disassembly flavor. */
1160 struct cmd_list_element
*new_cmd
;
1162 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1164 &disassembly_flavor
,
1166 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1167 and the default value is \"att\".",
1169 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1170 add_show_from_set (new_cmd
, &showlist
);
1173 /* Finally, initialize the disassembly flavor to the default given
1174 in the disassembly_flavor variable. */
1175 set_disassembly_flavor ();