1 /* Intel 386 target-dependent stuff.
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003 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"
30 #include "floatformat.h"
35 #include "arch-utils.h"
39 #include "gdb_assert.h"
40 #include "reggroups.h"
41 #include "dummy-frame.h"
44 #include "i386-tdep.h"
45 #include "i387-tdep.h"
47 /* Names of the registers. The first 10 registers match the register
48 numbering scheme used by GCC for stabs and DWARF. */
50 static char *i386_register_names
[] =
52 "eax", "ecx", "edx", "ebx",
53 "esp", "ebp", "esi", "edi",
54 "eip", "eflags", "cs", "ss",
55 "ds", "es", "fs", "gs",
56 "st0", "st1", "st2", "st3",
57 "st4", "st5", "st6", "st7",
58 "fctrl", "fstat", "ftag", "fiseg",
59 "fioff", "foseg", "fooff", "fop",
60 "xmm0", "xmm1", "xmm2", "xmm3",
61 "xmm4", "xmm5", "xmm6", "xmm7",
65 static const int i386_num_register_names
=
66 (sizeof (i386_register_names
) / sizeof (*i386_register_names
));
70 static char *i386_mmx_names
[] =
72 "mm0", "mm1", "mm2", "mm3",
73 "mm4", "mm5", "mm6", "mm7"
76 static const int i386_num_mmx_regs
=
77 (sizeof (i386_mmx_names
) / sizeof (i386_mmx_names
[0]));
79 #define MM0_REGNUM NUM_REGS
82 i386_mmx_regnum_p (int regnum
)
84 return (regnum
>= MM0_REGNUM
85 && regnum
< MM0_REGNUM
+ i386_num_mmx_regs
);
91 i386_fp_regnum_p (int regnum
)
93 return (regnum
< NUM_REGS
94 && (FP0_REGNUM
&& FP0_REGNUM
<= regnum
&& regnum
< FPC_REGNUM
));
98 i386_fpc_regnum_p (int regnum
)
100 return (regnum
< NUM_REGS
101 && (FPC_REGNUM
<= regnum
&& regnum
< XMM0_REGNUM
));
107 i386_sse_regnum_p (int regnum
)
109 return (regnum
< NUM_REGS
110 && (XMM0_REGNUM
<= regnum
&& regnum
< MXCSR_REGNUM
));
114 i386_mxcsr_regnum_p (int regnum
)
116 return (regnum
< NUM_REGS
117 && regnum
== MXCSR_REGNUM
);
120 /* Return the name of register REG. */
123 i386_register_name (int reg
)
125 if (reg
>= 0 && reg
< i386_num_register_names
)
126 return i386_register_names
[reg
];
128 if (i386_mmx_regnum_p (reg
))
129 return i386_mmx_names
[reg
- MM0_REGNUM
];
134 /* Convert stabs register number REG to the appropriate register
135 number used by GDB. */
138 i386_stab_reg_to_regnum (int reg
)
140 /* This implements what GCC calls the "default" register map. */
141 if (reg
>= 0 && reg
<= 7)
143 /* General registers. */
146 else if (reg
>= 12 && reg
<= 19)
148 /* Floating-point registers. */
149 return reg
- 12 + FP0_REGNUM
;
151 else if (reg
>= 21 && reg
<= 28)
154 return reg
- 21 + XMM0_REGNUM
;
156 else if (reg
>= 29 && reg
<= 36)
159 return reg
- 29 + MM0_REGNUM
;
162 /* This will hopefully provoke a warning. */
163 return NUM_REGS
+ NUM_PSEUDO_REGS
;
166 /* Convert DWARF register number REG to the appropriate register
167 number used by GDB. */
170 i386_dwarf_reg_to_regnum (int reg
)
172 /* The DWARF register numbering includes %eip and %eflags, and
173 numbers the floating point registers differently. */
174 if (reg
>= 0 && reg
<= 9)
176 /* General registers. */
179 else if (reg
>= 11 && reg
<= 18)
181 /* Floating-point registers. */
182 return reg
- 11 + FP0_REGNUM
;
186 /* The SSE and MMX registers have identical numbers as in stabs. */
187 return i386_stab_reg_to_regnum (reg
);
190 /* This will hopefully provoke a warning. */
191 return NUM_REGS
+ NUM_PSEUDO_REGS
;
195 /* This is the variable that is set with "set disassembly-flavor", and
196 its legitimate values. */
197 static const char att_flavor
[] = "att";
198 static const char intel_flavor
[] = "intel";
199 static const char *valid_flavors
[] =
205 static const char *disassembly_flavor
= att_flavor
;
207 /* Stdio style buffering was used to minimize calls to ptrace, but
208 this buffering did not take into account that the code section
209 being accessed may not be an even number of buffers long (even if
210 the buffer is only sizeof(int) long). In cases where the code
211 section size happened to be a non-integral number of buffers long,
212 attempting to read the last buffer would fail. Simply using
213 target_read_memory and ignoring errors, rather than read_memory, is
214 not the correct solution, since legitimate access errors would then
215 be totally ignored. To properly handle this situation and continue
216 to use buffering would require that this code be able to determine
217 the minimum code section size granularity (not the alignment of the
218 section itself, since the actual failing case that pointed out this
219 problem had a section alignment of 4 but was not a multiple of 4
220 bytes long), on a target by target basis, and then adjust it's
221 buffer size accordingly. This is messy, but potentially feasible.
222 It probably needs the bfd library's help and support. For now, the
223 buffer size is set to 1. (FIXME -fnf) */
225 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
226 static CORE_ADDR codestream_next_addr
;
227 static CORE_ADDR codestream_addr
;
228 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
229 static int codestream_off
;
230 static int codestream_cnt
;
232 #define codestream_tell() (codestream_addr + codestream_off)
233 #define codestream_peek() \
234 (codestream_cnt == 0 ? \
235 codestream_fill(1) : codestream_buf[codestream_off])
236 #define codestream_get() \
237 (codestream_cnt-- == 0 ? \
238 codestream_fill(0) : codestream_buf[codestream_off++])
241 codestream_fill (int peek_flag
)
243 codestream_addr
= codestream_next_addr
;
244 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
246 codestream_cnt
= CODESTREAM_BUFSIZ
;
247 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
250 return (codestream_peek ());
252 return (codestream_get ());
256 codestream_seek (CORE_ADDR place
)
258 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
259 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
262 while (codestream_tell () != place
)
267 codestream_read (unsigned char *buf
, int count
)
272 for (i
= 0; i
< count
; i
++)
273 *p
++ = codestream_get ();
277 /* If the next instruction is a jump, move to its target. */
280 i386_follow_jump (void)
282 unsigned char buf
[4];
288 pos
= codestream_tell ();
291 if (codestream_peek () == 0x66)
297 switch (codestream_get ())
300 /* Relative jump: if data16 == 0, disp32, else disp16. */
303 codestream_read (buf
, 2);
304 delta
= extract_signed_integer (buf
, 2);
306 /* Include the size of the jmp instruction (including the
312 codestream_read (buf
, 4);
313 delta
= extract_signed_integer (buf
, 4);
319 /* Relative jump, disp8 (ignore data16). */
320 codestream_read (buf
, 1);
321 /* Sign-extend it. */
322 delta
= extract_signed_integer (buf
, 1);
327 codestream_seek (pos
);
330 /* Find & return the amount a local space allocated, and advance the
331 codestream to the first register push (if any).
333 If the entry sequence doesn't make sense, return -1, and leave
334 codestream pointer at a random spot. */
337 i386_get_frame_setup (CORE_ADDR pc
)
341 codestream_seek (pc
);
345 op
= codestream_get ();
347 if (op
== 0x58) /* popl %eax */
349 /* This function must start with
352 xchgl %eax, (%esp) 0x87 0x04 0x24
353 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
355 (the System V compiler puts out the second `xchg'
356 instruction, and the assembler doesn't try to optimize it, so
357 the 'sib' form gets generated). This sequence is used to get
358 the address of the return buffer for a function that returns
361 unsigned char buf
[4];
362 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
363 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
365 pos
= codestream_tell ();
366 codestream_read (buf
, 4);
367 if (memcmp (buf
, proto1
, 3) == 0)
369 else if (memcmp (buf
, proto2
, 4) == 0)
372 codestream_seek (pos
);
373 op
= codestream_get (); /* Update next opcode. */
376 if (op
== 0x68 || op
== 0x6a)
378 /* This function may start with
390 unsigned char buf
[8];
392 /* Skip past the `pushl' instruction; it has either a one-byte
393 or a four-byte operand, depending on the opcode. */
394 pos
= codestream_tell ();
399 codestream_seek (pos
);
401 /* Read the following 8 bytes, which should be "call _probe" (6
402 bytes) followed by "addl $4,%esp" (2 bytes). */
403 codestream_read (buf
, sizeof (buf
));
404 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
406 codestream_seek (pos
);
407 op
= codestream_get (); /* Update next opcode. */
410 if (op
== 0x55) /* pushl %ebp */
412 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
413 switch (codestream_get ())
416 if (codestream_get () != 0xec)
420 if (codestream_get () != 0xe5)
426 /* Check for stack adjustment
430 NOTE: You can't subtract a 16 bit immediate from a 32 bit
431 reg, so we don't have to worry about a data16 prefix. */
432 op
= codestream_peek ();
435 /* `subl' with 8 bit immediate. */
437 if (codestream_get () != 0xec)
438 /* Some instruction starting with 0x83 other than `subl'. */
440 codestream_seek (codestream_tell () - 2);
443 /* `subl' with signed byte immediate (though it wouldn't
444 make sense to be negative). */
445 return (codestream_get ());
450 /* Maybe it is `subl' with a 32 bit immedediate. */
452 if (codestream_get () != 0xec)
453 /* Some instruction starting with 0x81 other than `subl'. */
455 codestream_seek (codestream_tell () - 2);
458 /* It is `subl' with a 32 bit immediate. */
459 codestream_read ((unsigned char *) buf
, 4);
460 return extract_signed_integer (buf
, 4);
470 /* `enter' with 16 bit unsigned immediate. */
471 codestream_read ((unsigned char *) buf
, 2);
472 codestream_get (); /* Flush final byte of enter instruction. */
473 return extract_unsigned_integer (buf
, 2);
478 /* Signal trampolines don't have a meaningful frame. The frame
479 pointer value we use is actually the frame pointer of the calling
480 frame -- that is, the frame which was in progress when the signal
481 trampoline was entered. GDB mostly treats this frame pointer value
482 as a magic cookie. We detect the case of a signal trampoline by
483 testing for get_frame_type() == SIGTRAMP_FRAME, which is set based
486 When a signal trampoline is invoked from a frameless function, we
487 essentially have two frameless functions in a row. In this case,
488 we use the same magic cookie for three frames in a row. We detect
489 this case by seeing whether the next frame is a SIGTRAMP_FRAME,
490 and, if it does, checking whether the current frame is actually
491 frameless. In this case, we need to get the PC by looking at the
492 SP register value stored in the signal context.
494 This should work in most cases except in horrible situations where
495 a signal occurs just as we enter a function but before the frame
496 has been set up. Incidentally, that's just what happens when we
497 call a function from GDB with a signal pending (there's a test in
498 the testsuite that makes this happen). Therefore we pretend that
499 we have a frameless function if we're stopped at the start of a
502 /* Return non-zero if we're dealing with a frameless signal, that is,
503 a signal trampoline invoked from a frameless function. */
506 i386_frameless_signal_p (struct frame_info
*frame
)
508 return (get_next_frame (frame
)
509 && get_frame_type (get_next_frame (frame
)) == SIGTRAMP_FRAME
510 && (frameless_look_for_prologue (frame
)
511 || get_frame_pc (frame
) == get_frame_func (frame
)));
514 /* Return the chain-pointer for FRAME. In the case of the i386, the
515 frame's nominal address is the address of a 4-byte word containing
516 the calling frame's address. */
519 i386_frame_chain (struct frame_info
*frame
)
521 if (pc_in_dummy_frame (get_frame_pc (frame
)))
522 return get_frame_base (frame
);
524 if (get_frame_type (frame
) == SIGTRAMP_FRAME
525 || i386_frameless_signal_p (frame
))
526 return get_frame_base (frame
);
528 if (! inside_entry_file (get_frame_pc (frame
)))
529 return read_memory_unsigned_integer (get_frame_base (frame
), 4);
534 /* Determine whether the function invocation represented by FRAME does
535 not have a from on the stack associated with it. If it does not,
536 return non-zero, otherwise return zero. */
539 i386_frameless_function_invocation (struct frame_info
*frame
)
541 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
544 return frameless_look_for_prologue (frame
);
547 /* Assuming FRAME is for a sigtramp routine, return the saved program
551 i386_sigtramp_saved_pc (struct frame_info
*frame
)
553 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
556 addr
= tdep
->sigcontext_addr (frame
);
557 return read_memory_unsigned_integer (addr
+ tdep
->sc_pc_offset
, 4);
560 /* Assuming FRAME is for a sigtramp routine, return the saved stack
564 i386_sigtramp_saved_sp (struct frame_info
*frame
)
566 struct gdbarch_tdep
*tdep
= gdbarch_tdep (current_gdbarch
);
569 addr
= tdep
->sigcontext_addr (frame
);
570 return read_memory_unsigned_integer (addr
+ tdep
->sc_sp_offset
, 4);
573 /* Return the saved program counter for FRAME. */
576 i386_frame_saved_pc (struct frame_info
*frame
)
578 if (pc_in_dummy_frame (get_frame_pc (frame
)))
582 frame_unwind_unsigned_register (frame
, PC_REGNUM
, &pc
);
586 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
587 return i386_sigtramp_saved_pc (frame
);
589 if (i386_frameless_signal_p (frame
))
591 CORE_ADDR sp
= i386_sigtramp_saved_sp (get_next_frame (frame
));
592 return read_memory_unsigned_integer (sp
, 4);
595 return read_memory_unsigned_integer (get_frame_base (frame
) + 4, 4);
598 /* Immediately after a function call, return the saved pc. */
601 i386_saved_pc_after_call (struct frame_info
*frame
)
603 if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
604 return i386_sigtramp_saved_pc (frame
);
606 return read_memory_unsigned_integer (read_register (SP_REGNUM
), 4);
609 /* Parse the first few instructions the function to see what registers
612 We handle these cases:
614 The startup sequence can be at the start of the function, or the
615 function can start with a branch to startup code at the end.
617 %ebp can be set up with either the 'enter' instruction, or "pushl
618 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
619 once used in the System V compiler).
621 Local space is allocated just below the saved %ebp by either the
622 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
623 bit unsigned argument for space to allocate, and the 'addl'
624 instruction could have either a signed byte, or 32 bit immediate.
626 Next, the registers used by this function are pushed. With the
627 System V compiler they will always be in the order: %edi, %esi,
628 %ebx (and sometimes a harmless bug causes it to also save but not
629 restore %eax); however, the code below is willing to see the pushes
630 in any order, and will handle up to 8 of them.
632 If the setup sequence is at the end of the function, then the next
633 instruction will be a branch back to the start. */
636 i386_frame_init_saved_regs (struct frame_info
*fip
)
644 if (get_frame_saved_regs (fip
))
647 frame_saved_regs_zalloc (fip
);
649 pc
= get_frame_func (fip
);
651 locals
= i386_get_frame_setup (pc
);
655 addr
= get_frame_base (fip
) - 4 - locals
;
656 for (i
= 0; i
< 8; i
++)
658 op
= codestream_get ();
659 if (op
< 0x50 || op
> 0x57)
661 #ifdef I386_REGNO_TO_SYMMETRY
662 /* Dynix uses different internal numbering. Ick. */
663 get_frame_saved_regs (fip
)[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
665 get_frame_saved_regs (fip
)[op
- 0x50] = addr
;
671 get_frame_saved_regs (fip
)[PC_REGNUM
] = get_frame_base (fip
) + 4;
672 get_frame_saved_regs (fip
)[DEPRECATED_FP_REGNUM
] = get_frame_base (fip
);
675 /* Return PC of first real instruction. */
678 i386_skip_prologue (CORE_ADDR pc
)
682 static unsigned char pic_pat
[6] =
683 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
684 0x5b, /* popl %ebx */
688 if (i386_get_frame_setup (pc
) < 0)
691 /* Found valid frame setup -- codestream now points to start of push
692 instructions for saving registers. */
694 /* Skip over register saves. */
695 for (i
= 0; i
< 8; i
++)
697 op
= codestream_peek ();
698 /* Break if not `pushl' instrunction. */
699 if (op
< 0x50 || op
> 0x57)
704 /* The native cc on SVR4 in -K PIC mode inserts the following code
705 to get the address of the global offset table (GOT) into register
710 movl %ebx,x(%ebp) (optional)
713 This code is with the rest of the prologue (at the end of the
714 function), so we have to skip it to get to the first real
715 instruction at the start of the function. */
717 pos
= codestream_tell ();
718 for (i
= 0; i
< 6; i
++)
720 op
= codestream_get ();
721 if (pic_pat
[i
] != op
)
726 unsigned char buf
[4];
729 op
= codestream_get ();
730 if (op
== 0x89) /* movl %ebx, x(%ebp) */
732 op
= codestream_get ();
733 if (op
== 0x5d) /* One byte offset from %ebp. */
736 codestream_read (buf
, 1);
738 else if (op
== 0x9d) /* Four byte offset from %ebp. */
741 codestream_read (buf
, 4);
743 else /* Unexpected instruction. */
745 op
= codestream_get ();
748 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
753 codestream_seek (pos
);
757 return (codestream_tell ());
760 /* Use the program counter to determine the contents and size of a
761 breakpoint instruction. Return a pointer to a string of bytes that
762 encode a breakpoint instruction, store the length of the string in
763 *LEN and optionally adjust *PC to point to the correct memory
764 location for inserting the breakpoint.
766 On the i386 we have a single breakpoint that fits in a single byte
767 and can be inserted anywhere. */
769 static const unsigned char *
770 i386_breakpoint_from_pc (CORE_ADDR
*pc
, int *len
)
772 static unsigned char break_insn
[] = { 0xcc }; /* int 3 */
774 *len
= sizeof (break_insn
);
778 /* Push the return address (pointing to the call dummy) onto the stack
779 and return the new value for the stack pointer. */
782 i386_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
786 store_unsigned_integer (buf
, 4, CALL_DUMMY_ADDRESS ());
787 write_memory (sp
- 4, buf
, 4);
792 i386_do_pop_frame (struct frame_info
*frame
)
796 char regbuf
[I386_MAX_REGISTER_SIZE
];
798 fp
= get_frame_base (frame
);
799 i386_frame_init_saved_regs (frame
);
801 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
804 addr
= get_frame_saved_regs (frame
)[regnum
];
807 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
808 deprecated_write_register_gen (regnum
, regbuf
);
811 write_register (DEPRECATED_FP_REGNUM
, read_memory_integer (fp
, 4));
812 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
813 write_register (SP_REGNUM
, fp
+ 8);
814 flush_cached_frames ();
818 i386_pop_frame (void)
820 generic_pop_current_frame (i386_do_pop_frame
);
824 /* Figure out where the longjmp will land. Slurp the args out of the
825 stack. We expect the first arg to be a pointer to the jmp_buf
826 structure from which we extract the address that we will land at.
827 This address is copied into PC. This routine returns non-zero on
831 i386_get_longjmp_target (CORE_ADDR
*pc
)
834 CORE_ADDR sp
, jb_addr
;
835 int jb_pc_offset
= gdbarch_tdep (current_gdbarch
)->jb_pc_offset
;
836 int len
= TYPE_LENGTH (builtin_type_void_func_ptr
);
838 /* If JB_PC_OFFSET is -1, we have no way to find out where the
839 longjmp will land. */
840 if (jb_pc_offset
== -1)
843 sp
= read_register (SP_REGNUM
);
844 if (target_read_memory (sp
+ len
, buf
, len
))
847 jb_addr
= extract_typed_address (buf
, builtin_type_void_func_ptr
);
848 if (target_read_memory (jb_addr
+ jb_pc_offset
, buf
, len
))
851 *pc
= extract_typed_address (buf
, builtin_type_void_func_ptr
);
857 i386_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
858 int struct_return
, CORE_ADDR struct_addr
)
860 sp
= legacy_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
867 store_address (buf
, 4, struct_addr
);
868 write_memory (sp
, buf
, 4);
874 /* These registers are used for returning integers (and on some
875 targets also for returning `struct' and `union' values when their
876 size and alignment match an integer type). */
877 #define LOW_RETURN_REGNUM 0 /* %eax */
878 #define HIGH_RETURN_REGNUM 2 /* %edx */
880 /* Extract from an array REGBUF containing the (raw) register state, a
881 function return value of TYPE, and copy that, in virtual format,
885 i386_extract_return_value (struct type
*type
, struct regcache
*regcache
,
888 bfd_byte
*valbuf
= dst
;
889 int len
= TYPE_LENGTH (type
);
890 char buf
[I386_MAX_REGISTER_SIZE
];
892 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
893 && TYPE_NFIELDS (type
) == 1)
895 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regcache
, valbuf
);
899 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
903 warning ("Cannot find floating-point return value.");
904 memset (valbuf
, 0, len
);
908 /* Floating-point return values can be found in %st(0). Convert
909 its contents to the desired type. This is probably not
910 exactly how it would happen on the target itself, but it is
911 the best we can do. */
912 regcache_raw_read (regcache
, FP0_REGNUM
, buf
);
913 convert_typed_floating (buf
, builtin_type_i387_ext
, valbuf
, type
);
917 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
918 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
922 regcache_raw_read (regcache
, LOW_RETURN_REGNUM
, buf
);
923 memcpy (valbuf
, buf
, len
);
925 else if (len
<= (low_size
+ high_size
))
927 regcache_raw_read (regcache
, LOW_RETURN_REGNUM
, buf
);
928 memcpy (valbuf
, buf
, low_size
);
929 regcache_raw_read (regcache
, HIGH_RETURN_REGNUM
, buf
);
930 memcpy (valbuf
+ low_size
, buf
, len
- low_size
);
933 internal_error (__FILE__
, __LINE__
,
934 "Cannot extract return value of %d bytes long.", len
);
938 /* Write into the appropriate registers a function return value stored
939 in VALBUF of type TYPE, given in virtual format. */
942 i386_store_return_value (struct type
*type
, struct regcache
*regcache
,
945 int len
= TYPE_LENGTH (type
);
947 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
948 && TYPE_NFIELDS (type
) == 1)
950 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), regcache
, valbuf
);
954 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
957 char buf
[FPU_REG_RAW_SIZE
];
961 warning ("Cannot set floating-point return value.");
965 /* Returning floating-point values is a bit tricky. Apart from
966 storing the return value in %st(0), we have to simulate the
967 state of the FPU at function return point. */
969 /* Convert the value found in VALBUF to the extended
970 floating-point format used by the FPU. This is probably
971 not exactly how it would happen on the target itself, but
972 it is the best we can do. */
973 convert_typed_floating (valbuf
, type
, buf
, builtin_type_i387_ext
);
974 regcache_raw_write (regcache
, FP0_REGNUM
, buf
);
976 /* Set the top of the floating-point register stack to 7. The
977 actual value doesn't really matter, but 7 is what a normal
978 function return would end up with if the program started out
979 with a freshly initialized FPU. */
980 regcache_raw_read_unsigned (regcache
, FSTAT_REGNUM
, &fstat
);
982 regcache_raw_write_unsigned (regcache
, FSTAT_REGNUM
, fstat
);
984 /* Mark %st(1) through %st(7) as empty. Since we set the top of
985 the floating-point register stack to 7, the appropriate value
986 for the tag word is 0x3fff. */
987 regcache_raw_write_unsigned (regcache
, FTAG_REGNUM
, 0x3fff);
991 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
992 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
995 regcache_raw_write_part (regcache
, LOW_RETURN_REGNUM
, 0, len
, valbuf
);
996 else if (len
<= (low_size
+ high_size
))
998 regcache_raw_write (regcache
, LOW_RETURN_REGNUM
, valbuf
);
999 regcache_raw_write_part (regcache
, HIGH_RETURN_REGNUM
, 0,
1000 len
- low_size
, (char *) valbuf
+ low_size
);
1003 internal_error (__FILE__
, __LINE__
,
1004 "Cannot store return value of %d bytes long.", len
);
1008 /* Extract from REGCACHE, which contains the (raw) register state, the
1009 address in which a function should return its structure value, as a
1013 i386_extract_struct_value_address (struct regcache
*regcache
)
1017 regcache_raw_read_unsigned (regcache
, LOW_RETURN_REGNUM
, &addr
);
1022 /* This is the variable that is set with "set struct-convention", and
1023 its legitimate values. */
1024 static const char default_struct_convention
[] = "default";
1025 static const char pcc_struct_convention
[] = "pcc";
1026 static const char reg_struct_convention
[] = "reg";
1027 static const char *valid_conventions
[] =
1029 default_struct_convention
,
1030 pcc_struct_convention
,
1031 reg_struct_convention
,
1034 static const char *struct_convention
= default_struct_convention
;
1037 i386_use_struct_convention (int gcc_p
, struct type
*type
)
1039 enum struct_return struct_return
;
1041 if (struct_convention
== default_struct_convention
)
1042 struct_return
= gdbarch_tdep (current_gdbarch
)->struct_return
;
1043 else if (struct_convention
== pcc_struct_convention
)
1044 struct_return
= pcc_struct_return
;
1046 struct_return
= reg_struct_return
;
1048 return generic_use_struct_convention (struct_return
== reg_struct_return
,
1053 /* Return the GDB type object for the "standard" data type of data in
1054 register REGNUM. Perhaps %esi and %edi should go here, but
1055 potentially they could be used for things other than address. */
1057 static struct type
*
1058 i386_register_type (struct gdbarch
*gdbarch
, int regnum
)
1060 if (regnum
== PC_REGNUM
|| regnum
== DEPRECATED_FP_REGNUM
|| regnum
== SP_REGNUM
)
1061 return lookup_pointer_type (builtin_type_void
);
1063 if (i386_fp_regnum_p (regnum
))
1064 return builtin_type_i387_ext
;
1066 if (i386_sse_regnum_p (regnum
))
1067 return builtin_type_vec128i
;
1069 if (i386_mmx_regnum_p (regnum
))
1070 return builtin_type_vec64i
;
1072 return builtin_type_int
;
1075 /* Map a cooked register onto a raw register or memory. For the i386,
1076 the MMX registers need to be mapped onto floating-point registers. */
1079 i386_mmx_regnum_to_fp_regnum (struct regcache
*regcache
, int regnum
)
1086 mmxi
= regnum
- MM0_REGNUM
;
1087 regcache_raw_read_unsigned (regcache
, FSTAT_REGNUM
, &fstat
);
1088 tos
= (fstat
>> 11) & 0x7;
1089 fpi
= (mmxi
+ tos
) % 8;
1091 return (FP0_REGNUM
+ fpi
);
1095 i386_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1096 int regnum
, void *buf
)
1098 if (i386_mmx_regnum_p (regnum
))
1100 char mmx_buf
[MAX_REGISTER_SIZE
];
1101 int fpnum
= i386_mmx_regnum_to_fp_regnum (regcache
, regnum
);
1103 /* Extract (always little endian). */
1104 regcache_raw_read (regcache
, fpnum
, mmx_buf
);
1105 memcpy (buf
, mmx_buf
, REGISTER_RAW_SIZE (regnum
));
1108 regcache_raw_read (regcache
, regnum
, buf
);
1112 i386_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
1113 int regnum
, const void *buf
)
1115 if (i386_mmx_regnum_p (regnum
))
1117 char mmx_buf
[MAX_REGISTER_SIZE
];
1118 int fpnum
= i386_mmx_regnum_to_fp_regnum (regcache
, regnum
);
1121 regcache_raw_read (regcache
, fpnum
, mmx_buf
);
1122 /* ... Modify ... (always little endian). */
1123 memcpy (mmx_buf
, buf
, REGISTER_RAW_SIZE (regnum
));
1125 regcache_raw_write (regcache
, fpnum
, mmx_buf
);
1128 regcache_raw_write (regcache
, regnum
, buf
);
1131 /* Return true iff register REGNUM's virtual format is different from
1132 its raw format. Note that this definition assumes that the host
1133 supports IEEE 32-bit floats, since it doesn't say that SSE
1134 registers need conversion. Even if we can't find a counterexample,
1135 this is still sloppy. */
1138 i386_register_convertible (int regnum
)
1140 return i386_fp_regnum_p (regnum
);
1143 /* Convert data from raw format for register REGNUM in buffer FROM to
1144 virtual format with type TYPE in buffer TO. */
1147 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
1148 char *from
, char *to
)
1150 gdb_assert (i386_fp_regnum_p (regnum
));
1152 /* We only support floating-point values. */
1153 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
1155 warning ("Cannot convert floating-point register value "
1156 "to non-floating-point type.");
1157 memset (to
, 0, TYPE_LENGTH (type
));
1161 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
1162 the extended floating-point format used by the FPU. */
1163 convert_typed_floating (from
, builtin_type_i387_ext
, to
, type
);
1166 /* Convert data from virtual format with type TYPE in buffer FROM to
1167 raw format for register REGNUM in buffer TO. */
1170 i386_register_convert_to_raw (struct type
*type
, int regnum
,
1171 char *from
, char *to
)
1173 gdb_assert (i386_fp_regnum_p (regnum
));
1175 /* We only support floating-point values. */
1176 if (TYPE_CODE (type
) != TYPE_CODE_FLT
)
1178 warning ("Cannot convert non-floating-point type "
1179 "to floating-point register value.");
1180 memset (to
, 0, TYPE_LENGTH (type
));
1184 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
1185 to the extended floating-point format used by the FPU. */
1186 convert_typed_floating (from
, type
, to
, builtin_type_i387_ext
);
1190 #ifdef STATIC_TRANSFORM_NAME
1191 /* SunPRO encodes the static variables. This is not related to C++
1192 mangling, it is done for C too. */
1195 sunpro_static_transform_name (char *name
)
1198 if (IS_STATIC_TRANSFORM_NAME (name
))
1200 /* For file-local statics there will be a period, a bunch of
1201 junk (the contents of which match a string given in the
1202 N_OPT), a period and the name. For function-local statics
1203 there will be a bunch of junk (which seems to change the
1204 second character from 'A' to 'B'), a period, the name of the
1205 function, and the name. So just skip everything before the
1207 p
= strrchr (name
, '.');
1213 #endif /* STATIC_TRANSFORM_NAME */
1216 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1219 i386_pe_skip_trampoline_code (CORE_ADDR pc
, char *name
)
1221 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
1223 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
1224 struct minimal_symbol
*indsym
=
1225 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
1226 char *symname
= indsym
? SYMBOL_LINKAGE_NAME (indsym
) : 0;
1230 if (strncmp (symname
, "__imp_", 6) == 0
1231 || strncmp (symname
, "_imp_", 5) == 0)
1232 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
1235 return 0; /* Not a trampoline. */
1239 /* Return non-zero if PC and NAME show that we are in a signal
1243 i386_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
1245 return (name
&& strcmp ("_sigtramp", name
) == 0);
1249 /* We have two flavours of disassembly. The machinery on this page
1250 deals with switching between those. */
1253 i386_print_insn (bfd_vma pc
, disassemble_info
*info
)
1255 gdb_assert (disassembly_flavor
== att_flavor
1256 || disassembly_flavor
== intel_flavor
);
1258 /* FIXME: kettenis/20020915: Until disassembler_options is properly
1259 constified, cast to prevent a compiler warning. */
1260 info
->disassembler_options
= (char *) disassembly_flavor
;
1261 info
->mach
= gdbarch_bfd_arch_info (current_gdbarch
)->mach
;
1263 return print_insn_i386 (pc
, info
);
1267 /* There are a few i386 architecture variants that differ only
1268 slightly from the generic i386 target. For now, we don't give them
1269 their own source file, but include them here. As a consequence,
1270 they'll always be included. */
1272 /* System V Release 4 (SVR4). */
1275 i386_svr4_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
1277 return (name
&& (strcmp ("_sigreturn", name
) == 0
1278 || strcmp ("_sigacthandler", name
) == 0
1279 || strcmp ("sigvechandler", name
) == 0));
1282 /* Get address of the pushed ucontext (sigcontext) on the stack for
1283 all three variants of SVR4 sigtramps. */
1286 i386_svr4_sigcontext_addr (struct frame_info
*frame
)
1288 int sigcontext_offset
= -1;
1291 find_pc_partial_function (get_frame_pc (frame
), &name
, NULL
, NULL
);
1294 if (strcmp (name
, "_sigreturn") == 0)
1295 sigcontext_offset
= 132;
1296 else if (strcmp (name
, "_sigacthandler") == 0)
1297 sigcontext_offset
= 80;
1298 else if (strcmp (name
, "sigvechandler") == 0)
1299 sigcontext_offset
= 120;
1302 gdb_assert (sigcontext_offset
!= -1);
1304 if (get_next_frame (frame
))
1305 return get_frame_base (get_next_frame (frame
)) + sigcontext_offset
;
1306 return read_register (SP_REGNUM
) + sigcontext_offset
;
1313 i386_go32_pc_in_sigtramp (CORE_ADDR pc
, char *name
)
1315 /* DJGPP doesn't have any special frames for signal handlers. */
1323 i386_elf_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1325 /* We typically use stabs-in-ELF with the DWARF register numbering. */
1326 set_gdbarch_stab_reg_to_regnum (gdbarch
, i386_dwarf_reg_to_regnum
);
1329 /* System V Release 4 (SVR4). */
1332 i386_svr4_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1334 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1336 /* System V Release 4 uses ELF. */
1337 i386_elf_init_abi (info
, gdbarch
);
1339 /* System V Release 4 has shared libraries. */
1340 set_gdbarch_in_solib_call_trampoline (gdbarch
, in_plt_section
);
1341 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
1343 set_gdbarch_pc_in_sigtramp (gdbarch
, i386_svr4_pc_in_sigtramp
);
1344 tdep
->sigcontext_addr
= i386_svr4_sigcontext_addr
;
1345 tdep
->sc_pc_offset
= 14 * 4;
1346 tdep
->sc_sp_offset
= 7 * 4;
1348 tdep
->jb_pc_offset
= 20;
1354 i386_go32_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1356 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1358 set_gdbarch_pc_in_sigtramp (gdbarch
, i386_go32_pc_in_sigtramp
);
1360 tdep
->jb_pc_offset
= 36;
1366 i386_nw_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1368 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1370 tdep
->jb_pc_offset
= 24;
1374 /* i386 register groups. In addition to the normal groups, add "mmx"
1377 static struct reggroup
*i386_sse_reggroup
;
1378 static struct reggroup
*i386_mmx_reggroup
;
1381 i386_init_reggroups (void)
1383 i386_sse_reggroup
= reggroup_new ("sse", USER_REGGROUP
);
1384 i386_mmx_reggroup
= reggroup_new ("mmx", USER_REGGROUP
);
1388 i386_add_reggroups (struct gdbarch
*gdbarch
)
1390 reggroup_add (gdbarch
, i386_sse_reggroup
);
1391 reggroup_add (gdbarch
, i386_mmx_reggroup
);
1392 reggroup_add (gdbarch
, general_reggroup
);
1393 reggroup_add (gdbarch
, float_reggroup
);
1394 reggroup_add (gdbarch
, all_reggroup
);
1395 reggroup_add (gdbarch
, save_reggroup
);
1396 reggroup_add (gdbarch
, restore_reggroup
);
1397 reggroup_add (gdbarch
, vector_reggroup
);
1398 reggroup_add (gdbarch
, system_reggroup
);
1402 i386_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
1403 struct reggroup
*group
)
1405 int sse_regnum_p
= (i386_sse_regnum_p (regnum
)
1406 || i386_mxcsr_regnum_p (regnum
));
1407 int fp_regnum_p
= (i386_fp_regnum_p (regnum
)
1408 || i386_fpc_regnum_p (regnum
));
1409 int mmx_regnum_p
= (i386_mmx_regnum_p (regnum
));
1410 if (group
== i386_mmx_reggroup
)
1411 return mmx_regnum_p
;
1412 if (group
== i386_sse_reggroup
)
1413 return sse_regnum_p
;
1414 if (group
== vector_reggroup
)
1415 return (mmx_regnum_p
|| sse_regnum_p
);
1416 if (group
== float_reggroup
)
1418 if (group
== general_reggroup
)
1419 return (!fp_regnum_p
&& !mmx_regnum_p
&& !sse_regnum_p
);
1420 return default_register_reggroup_p (gdbarch
, regnum
, group
);
1424 static struct gdbarch
*
1425 i386_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
1427 struct gdbarch_tdep
*tdep
;
1428 struct gdbarch
*gdbarch
;
1430 /* If there is already a candidate, use it. */
1431 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
1433 return arches
->gdbarch
;
1435 /* Allocate space for the new architecture. */
1436 tdep
= XMALLOC (struct gdbarch_tdep
);
1437 gdbarch
= gdbarch_alloc (&info
, tdep
);
1439 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1440 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1441 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
1443 /* The i386 default settings don't include the SSE registers.
1444 FIXME: kettenis/20020614: They do include the FPU registers for
1445 now, which probably is not quite right. */
1446 tdep
->num_xmm_regs
= 0;
1448 tdep
->jb_pc_offset
= -1;
1449 tdep
->struct_return
= pcc_struct_return
;
1450 tdep
->sigtramp_start
= 0;
1451 tdep
->sigtramp_end
= 0;
1452 tdep
->sigcontext_addr
= NULL
;
1453 tdep
->sc_pc_offset
= -1;
1454 tdep
->sc_sp_offset
= -1;
1456 /* The format used for `long double' on almost all i386 targets is
1457 the i387 extended floating-point format. In fact, of all targets
1458 in the GCC 2.95 tree, only OSF/1 does it different, and insists
1459 on having a `long double' that's not `long' at all. */
1460 set_gdbarch_long_double_format (gdbarch
, &floatformat_i387_ext
);
1462 /* Although the i387 extended floating-point has only 80 significant
1463 bits, a `long double' actually takes up 96, probably to enforce
1465 set_gdbarch_long_double_bit (gdbarch
, 96);
1467 /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-ptx.h,
1468 tm-symmetry.h currently override this. Sigh. */
1469 set_gdbarch_num_regs (gdbarch
, I386_NUM_GREGS
+ I386_NUM_FREGS
);
1471 set_gdbarch_sp_regnum (gdbarch
, 4); /* %esp */
1472 set_gdbarch_deprecated_fp_regnum (gdbarch
, 5); /* %ebp */
1473 set_gdbarch_pc_regnum (gdbarch
, 8); /* %eip */
1474 set_gdbarch_ps_regnum (gdbarch
, 9); /* %eflags */
1475 set_gdbarch_fp0_regnum (gdbarch
, 16); /* %st(0) */
1477 /* Use the "default" register numbering scheme for stabs and COFF. */
1478 set_gdbarch_stab_reg_to_regnum (gdbarch
, i386_stab_reg_to_regnum
);
1479 set_gdbarch_sdb_reg_to_regnum (gdbarch
, i386_stab_reg_to_regnum
);
1481 /* Use the DWARF register numbering scheme for DWARF and DWARF 2. */
1482 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, i386_dwarf_reg_to_regnum
);
1483 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, i386_dwarf_reg_to_regnum
);
1485 /* We don't define ECOFF_REG_TO_REGNUM, since ECOFF doesn't seem to
1486 be in use on any of the supported i386 targets. */
1488 set_gdbarch_register_name (gdbarch
, i386_register_name
);
1489 set_gdbarch_deprecated_register_size (gdbarch
, 4);
1490 set_gdbarch_register_bytes (gdbarch
, I386_SIZEOF_GREGS
+ I386_SIZEOF_FREGS
);
1491 set_gdbarch_register_type (gdbarch
, i386_register_type
);
1493 set_gdbarch_print_float_info (gdbarch
, i387_print_float_info
);
1495 set_gdbarch_get_longjmp_target (gdbarch
, i386_get_longjmp_target
);
1497 /* Call dummy code. */
1498 set_gdbarch_deprecated_call_dummy_words (gdbarch
, NULL
);
1499 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, 0);
1501 set_gdbarch_register_convertible (gdbarch
, i386_register_convertible
);
1502 set_gdbarch_register_convert_to_virtual (gdbarch
,
1503 i386_register_convert_to_virtual
);
1504 set_gdbarch_register_convert_to_raw (gdbarch
, i386_register_convert_to_raw
);
1506 /* "An argument's size is increased, if necessary, to make it a
1507 multiple of [32-bit] words. This may require tail padding,
1508 depending on the size of the argument" -- from the x86 ABI. */
1509 set_gdbarch_parm_boundary (gdbarch
, 32);
1511 set_gdbarch_extract_return_value (gdbarch
, i386_extract_return_value
);
1512 set_gdbarch_deprecated_push_arguments (gdbarch
, i386_push_arguments
);
1513 set_gdbarch_deprecated_push_return_address (gdbarch
, i386_push_return_address
);
1514 set_gdbarch_deprecated_pop_frame (gdbarch
, i386_pop_frame
);
1515 set_gdbarch_store_return_value (gdbarch
, i386_store_return_value
);
1516 set_gdbarch_extract_struct_value_address (gdbarch
,
1517 i386_extract_struct_value_address
);
1518 set_gdbarch_use_struct_convention (gdbarch
, i386_use_struct_convention
);
1520 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, i386_frame_init_saved_regs
);
1521 set_gdbarch_skip_prologue (gdbarch
, i386_skip_prologue
);
1523 /* Stack grows downward. */
1524 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1526 set_gdbarch_breakpoint_from_pc (gdbarch
, i386_breakpoint_from_pc
);
1527 set_gdbarch_decr_pc_after_break (gdbarch
, 1);
1528 set_gdbarch_function_start_offset (gdbarch
, 0);
1530 /* The following redefines make backtracing through sigtramp work.
1531 They manufacture a fake sigtramp frame and obtain the saved pc in
1532 sigtramp from the sigcontext structure which is pushed by the
1533 kernel on the user stack, along with a pointer to it. */
1535 set_gdbarch_frame_args_skip (gdbarch
, 8);
1536 set_gdbarch_frameless_function_invocation (gdbarch
,
1537 i386_frameless_function_invocation
);
1538 set_gdbarch_deprecated_frame_chain (gdbarch
, i386_frame_chain
);
1539 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, i386_frame_saved_pc
);
1540 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, i386_saved_pc_after_call
);
1541 set_gdbarch_frame_num_args (gdbarch
, frame_num_args_unknown
);
1542 set_gdbarch_pc_in_sigtramp (gdbarch
, i386_pc_in_sigtramp
);
1544 /* Wire in the MMX registers. */
1545 set_gdbarch_num_pseudo_regs (gdbarch
, i386_num_mmx_regs
);
1546 set_gdbarch_pseudo_register_read (gdbarch
, i386_pseudo_register_read
);
1547 set_gdbarch_pseudo_register_write (gdbarch
, i386_pseudo_register_write
);
1549 set_gdbarch_print_insn (gdbarch
, i386_print_insn
);
1551 /* Add the i386 register groups. */
1552 i386_add_reggroups (gdbarch
);
1553 set_gdbarch_register_reggroup_p (gdbarch
, i386_register_reggroup_p
);
1555 /* Should be using push_dummy_call. */
1556 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, generic_target_write_sp
);
1558 /* Hook in ABI-specific overrides, if they have been registered. */
1559 gdbarch_init_osabi (info
, gdbarch
);
1564 static enum gdb_osabi
1565 i386_coff_osabi_sniffer (bfd
*abfd
)
1567 if (strcmp (bfd_get_target (abfd
), "coff-go32-exe") == 0
1568 || strcmp (bfd_get_target (abfd
), "coff-go32") == 0)
1569 return GDB_OSABI_GO32
;
1571 return GDB_OSABI_UNKNOWN
;
1574 static enum gdb_osabi
1575 i386_nlm_osabi_sniffer (bfd
*abfd
)
1577 return GDB_OSABI_NETWARE
;
1581 /* Provide a prototype to silence -Wmissing-prototypes. */
1582 void _initialize_i386_tdep (void);
1585 _initialize_i386_tdep (void)
1587 register_gdbarch_init (bfd_arch_i386
, i386_gdbarch_init
);
1589 /* Add the variable that controls the disassembly flavor. */
1591 struct cmd_list_element
*new_cmd
;
1593 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1595 &disassembly_flavor
,
1597 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1598 and the default value is \"att\".",
1600 add_show_from_set (new_cmd
, &showlist
);
1603 /* Add the variable that controls the convention for returning
1606 struct cmd_list_element
*new_cmd
;
1608 new_cmd
= add_set_enum_cmd ("struct-convention", no_class
,
1610 &struct_convention
, "\
1611 Set the convention for returning small structs, valid values \
1612 are \"default\", \"pcc\" and \"reg\", and the default value is \"default\".",
1614 add_show_from_set (new_cmd
, &showlist
);
1617 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_coff_flavour
,
1618 i386_coff_osabi_sniffer
);
1619 gdbarch_register_osabi_sniffer (bfd_arch_i386
, bfd_target_nlm_flavour
,
1620 i386_nlm_osabi_sniffer
);
1622 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_SVR4
,
1623 i386_svr4_init_abi
);
1624 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_GO32
,
1625 i386_go32_init_abi
);
1626 gdbarch_register_osabi (bfd_arch_i386
, 0, GDB_OSABI_NETWARE
,
1629 /* Initialize the i386 specific register groups. */
1630 i386_init_reggroups ();