]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i386-tdep.c
* breakpoint.c (insert_breakpoints): Skip disabled breakpoints
[thirdparty/binutils-gdb.git] / gdb / i386-tdep.c
CommitLineData
c906108c 1/* Intel 386 target-dependent stuff.
349c5d5f
AC
2
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
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.
c906108c 12
c5aa993b
JM
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.
c906108c 17
c5aa993b
JM
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. */
c906108c
SS
22
23#include "defs.h"
24#include "gdb_string.h"
25#include "frame.h"
26#include "inferior.h"
27#include "gdbcore.h"
dfe01d39 28#include "objfiles.h"
c906108c
SS
29#include "target.h"
30#include "floatformat.h"
c0d1d883 31#include "symfile.h"
c906108c
SS
32#include "symtab.h"
33#include "gdbcmd.h"
34#include "command.h"
b4a20239 35#include "arch-utils.h"
4e052eda 36#include "regcache.h"
d16aafd8 37#include "doublest.h"
fd0407d6 38#include "value.h"
3d261580 39#include "gdb_assert.h"
38c968cf 40#include "reggroups.h"
5a4d6ff4 41#include "dummy-frame.h"
3d261580 42
d2a7c97a 43#include "i386-tdep.h"
61113f8b 44#include "i387-tdep.h"
d2a7c97a 45
fc633446
MK
46/* Names of the registers. The first 10 registers match the register
47 numbering scheme used by GCC for stabs and DWARF. */
48static char *i386_register_names[] =
49{
50 "eax", "ecx", "edx", "ebx",
51 "esp", "ebp", "esi", "edi",
52 "eip", "eflags", "cs", "ss",
53 "ds", "es", "fs", "gs",
54 "st0", "st1", "st2", "st3",
55 "st4", "st5", "st6", "st7",
56 "fctrl", "fstat", "ftag", "fiseg",
57 "fioff", "foseg", "fooff", "fop",
58 "xmm0", "xmm1", "xmm2", "xmm3",
59 "xmm4", "xmm5", "xmm6", "xmm7",
60 "mxcsr"
61};
62
28fc6740
AC
63/* MMX registers. */
64
65static char *i386_mmx_names[] =
66{
67 "mm0", "mm1", "mm2", "mm3",
68 "mm4", "mm5", "mm6", "mm7"
69};
70static const int mmx_num_regs = (sizeof (i386_mmx_names)
71 / sizeof (i386_mmx_names[0]));
72#define MM0_REGNUM (NUM_REGS)
73
74static int
23a34459 75i386_mmx_regnum_p (int reg)
28fc6740
AC
76{
77 return (reg >= MM0_REGNUM && reg < MM0_REGNUM + mmx_num_regs);
78}
79
23a34459
AC
80/* FP register? */
81
82int
83i386_fp_regnum_p (int regnum)
84{
85 return (regnum < NUM_REGS
86 && (FP0_REGNUM && FP0_REGNUM <= (regnum) && (regnum) < FPC_REGNUM));
87}
88
89int
90i386_fpc_regnum_p (int regnum)
91{
92 return (regnum < NUM_REGS
93 && (FPC_REGNUM <= (regnum) && (regnum) < XMM0_REGNUM));
94}
95
96/* SSE register? */
97
98int
99i386_sse_regnum_p (int regnum)
100{
101 return (regnum < NUM_REGS
102 && (XMM0_REGNUM <= (regnum) && (regnum) < MXCSR_REGNUM));
103}
104
105int
106i386_mxcsr_regnum_p (int regnum)
107{
108 return (regnum < NUM_REGS
109 && (regnum == MXCSR_REGNUM));
110}
111
fc633446
MK
112/* Return the name of register REG. */
113
fa88f677 114const char *
fc633446
MK
115i386_register_name (int reg)
116{
117 if (reg < 0)
118 return NULL;
23a34459 119 if (i386_mmx_regnum_p (reg))
28fc6740 120 return i386_mmx_names[reg - MM0_REGNUM];
fc633446
MK
121 if (reg >= sizeof (i386_register_names) / sizeof (*i386_register_names))
122 return NULL;
123
124 return i386_register_names[reg];
125}
126
85540d8c
MK
127/* Convert stabs register number REG to the appropriate register
128 number used by GDB. */
129
8201327c 130static int
85540d8c
MK
131i386_stab_reg_to_regnum (int reg)
132{
133 /* This implements what GCC calls the "default" register map. */
134 if (reg >= 0 && reg <= 7)
135 {
136 /* General registers. */
137 return reg;
138 }
139 else if (reg >= 12 && reg <= 19)
140 {
141 /* Floating-point registers. */
142 return reg - 12 + FP0_REGNUM;
143 }
144 else if (reg >= 21 && reg <= 28)
145 {
146 /* SSE registers. */
147 return reg - 21 + XMM0_REGNUM;
148 }
149 else if (reg >= 29 && reg <= 36)
150 {
151 /* MMX registers. */
7d12f766 152 return reg - 29 + MM0_REGNUM;
85540d8c
MK
153 }
154
155 /* This will hopefully provoke a warning. */
156 return NUM_REGS + NUM_PSEUDO_REGS;
157}
158
8201327c 159/* Convert DWARF register number REG to the appropriate register
85540d8c
MK
160 number used by GDB. */
161
8201327c 162static int
85540d8c
MK
163i386_dwarf_reg_to_regnum (int reg)
164{
165 /* The DWARF register numbering includes %eip and %eflags, and
166 numbers the floating point registers differently. */
167 if (reg >= 0 && reg <= 9)
168 {
169 /* General registers. */
170 return reg;
171 }
172 else if (reg >= 11 && reg <= 18)
173 {
174 /* Floating-point registers. */
175 return reg - 11 + FP0_REGNUM;
176 }
177 else if (reg >= 21)
178 {
179 /* The SSE and MMX registers have identical numbers as in stabs. */
180 return i386_stab_reg_to_regnum (reg);
181 }
182
183 /* This will hopefully provoke a warning. */
184 return NUM_REGS + NUM_PSEUDO_REGS;
185}
fc338970 186\f
917317f4 187
fc338970
MK
188/* This is the variable that is set with "set disassembly-flavor", and
189 its legitimate values. */
53904c9e
AC
190static const char att_flavor[] = "att";
191static const char intel_flavor[] = "intel";
192static const char *valid_flavors[] =
c5aa993b 193{
c906108c
SS
194 att_flavor,
195 intel_flavor,
196 NULL
197};
53904c9e 198static const char *disassembly_flavor = att_flavor;
c906108c 199
fc338970
MK
200/* Stdio style buffering was used to minimize calls to ptrace, but
201 this buffering did not take into account that the code section
202 being accessed may not be an even number of buffers long (even if
203 the buffer is only sizeof(int) long). In cases where the code
204 section size happened to be a non-integral number of buffers long,
205 attempting to read the last buffer would fail. Simply using
206 target_read_memory and ignoring errors, rather than read_memory, is
207 not the correct solution, since legitimate access errors would then
208 be totally ignored. To properly handle this situation and continue
209 to use buffering would require that this code be able to determine
210 the minimum code section size granularity (not the alignment of the
211 section itself, since the actual failing case that pointed out this
212 problem had a section alignment of 4 but was not a multiple of 4
213 bytes long), on a target by target basis, and then adjust it's
214 buffer size accordingly. This is messy, but potentially feasible.
215 It probably needs the bfd library's help and support. For now, the
216 buffer size is set to 1. (FIXME -fnf) */
217
218#define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
c906108c
SS
219static CORE_ADDR codestream_next_addr;
220static CORE_ADDR codestream_addr;
221static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
222static int codestream_off;
223static int codestream_cnt;
224
225#define codestream_tell() (codestream_addr + codestream_off)
fc338970
MK
226#define codestream_peek() \
227 (codestream_cnt == 0 ? \
228 codestream_fill(1) : codestream_buf[codestream_off])
229#define codestream_get() \
230 (codestream_cnt-- == 0 ? \
231 codestream_fill(0) : codestream_buf[codestream_off++])
c906108c 232
c5aa993b 233static unsigned char
fba45db2 234codestream_fill (int peek_flag)
c906108c
SS
235{
236 codestream_addr = codestream_next_addr;
237 codestream_next_addr += CODESTREAM_BUFSIZ;
238 codestream_off = 0;
239 codestream_cnt = CODESTREAM_BUFSIZ;
240 read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
c5aa993b 241
c906108c 242 if (peek_flag)
c5aa993b 243 return (codestream_peek ());
c906108c 244 else
c5aa993b 245 return (codestream_get ());
c906108c
SS
246}
247
248static void
fba45db2 249codestream_seek (CORE_ADDR place)
c906108c
SS
250{
251 codestream_next_addr = place / CODESTREAM_BUFSIZ;
252 codestream_next_addr *= CODESTREAM_BUFSIZ;
253 codestream_cnt = 0;
254 codestream_fill (1);
c5aa993b 255 while (codestream_tell () != place)
c906108c
SS
256 codestream_get ();
257}
258
259static void
fba45db2 260codestream_read (unsigned char *buf, int count)
c906108c
SS
261{
262 unsigned char *p;
263 int i;
264 p = buf;
265 for (i = 0; i < count; i++)
266 *p++ = codestream_get ();
267}
fc338970 268\f
c906108c 269
fc338970 270/* If the next instruction is a jump, move to its target. */
c906108c
SS
271
272static void
fba45db2 273i386_follow_jump (void)
c906108c
SS
274{
275 unsigned char buf[4];
276 long delta;
277
278 int data16;
279 CORE_ADDR pos;
280
281 pos = codestream_tell ();
282
283 data16 = 0;
284 if (codestream_peek () == 0x66)
285 {
286 codestream_get ();
287 data16 = 1;
288 }
289
290 switch (codestream_get ())
291 {
292 case 0xe9:
fc338970 293 /* Relative jump: if data16 == 0, disp32, else disp16. */
c906108c
SS
294 if (data16)
295 {
296 codestream_read (buf, 2);
297 delta = extract_signed_integer (buf, 2);
298
fc338970
MK
299 /* Include the size of the jmp instruction (including the
300 0x66 prefix). */
c5aa993b 301 pos += delta + 4;
c906108c
SS
302 }
303 else
304 {
305 codestream_read (buf, 4);
306 delta = extract_signed_integer (buf, 4);
307
308 pos += delta + 5;
309 }
310 break;
311 case 0xeb:
fc338970 312 /* Relative jump, disp8 (ignore data16). */
c906108c
SS
313 codestream_read (buf, 1);
314 /* Sign-extend it. */
315 delta = extract_signed_integer (buf, 1);
316
317 pos += delta + 2;
318 break;
319 }
320 codestream_seek (pos);
321}
322
fc338970
MK
323/* Find & return the amount a local space allocated, and advance the
324 codestream to the first register push (if any).
325
326 If the entry sequence doesn't make sense, return -1, and leave
327 codestream pointer at a random spot. */
c906108c
SS
328
329static long
fba45db2 330i386_get_frame_setup (CORE_ADDR pc)
c906108c
SS
331{
332 unsigned char op;
333
334 codestream_seek (pc);
335
336 i386_follow_jump ();
337
338 op = codestream_get ();
339
340 if (op == 0x58) /* popl %eax */
341 {
fc338970
MK
342 /* This function must start with
343
344 popl %eax 0x58
345 xchgl %eax, (%esp) 0x87 0x04 0x24
346 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
347
348 (the System V compiler puts out the second `xchg'
349 instruction, and the assembler doesn't try to optimize it, so
350 the 'sib' form gets generated). This sequence is used to get
351 the address of the return buffer for a function that returns
352 a structure. */
c906108c
SS
353 int pos;
354 unsigned char buf[4];
fc338970
MK
355 static unsigned char proto1[3] = { 0x87, 0x04, 0x24 };
356 static unsigned char proto2[4] = { 0x87, 0x44, 0x24, 0x00 };
357
c906108c
SS
358 pos = codestream_tell ();
359 codestream_read (buf, 4);
360 if (memcmp (buf, proto1, 3) == 0)
361 pos += 3;
362 else if (memcmp (buf, proto2, 4) == 0)
363 pos += 4;
364
365 codestream_seek (pos);
fc338970 366 op = codestream_get (); /* Update next opcode. */
c906108c
SS
367 }
368
369 if (op == 0x68 || op == 0x6a)
370 {
fc338970
MK
371 /* This function may start with
372
373 pushl constant
374 call _probe
375 addl $4, %esp
376
377 followed by
378
379 pushl %ebp
380
381 etc. */
c906108c
SS
382 int pos;
383 unsigned char buf[8];
384
fc338970 385 /* Skip past the `pushl' instruction; it has either a one-byte
c906108c
SS
386 or a four-byte operand, depending on the opcode. */
387 pos = codestream_tell ();
388 if (op == 0x68)
389 pos += 4;
390 else
391 pos += 1;
392 codestream_seek (pos);
393
fc338970
MK
394 /* Read the following 8 bytes, which should be "call _probe" (6
395 bytes) followed by "addl $4,%esp" (2 bytes). */
c906108c
SS
396 codestream_read (buf, sizeof (buf));
397 if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
398 pos += sizeof (buf);
399 codestream_seek (pos);
fc338970 400 op = codestream_get (); /* Update next opcode. */
c906108c
SS
401 }
402
403 if (op == 0x55) /* pushl %ebp */
c5aa993b 404 {
fc338970 405 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
c906108c
SS
406 switch (codestream_get ())
407 {
408 case 0x8b:
409 if (codestream_get () != 0xec)
fc338970 410 return -1;
c906108c
SS
411 break;
412 case 0x89:
413 if (codestream_get () != 0xe5)
fc338970 414 return -1;
c906108c
SS
415 break;
416 default:
fc338970 417 return -1;
c906108c 418 }
fc338970
MK
419 /* Check for stack adjustment
420
421 subl $XXX, %esp
422
423 NOTE: You can't subtract a 16 bit immediate from a 32 bit
424 reg, so we don't have to worry about a data16 prefix. */
c906108c
SS
425 op = codestream_peek ();
426 if (op == 0x83)
427 {
fc338970 428 /* `subl' with 8 bit immediate. */
c906108c
SS
429 codestream_get ();
430 if (codestream_get () != 0xec)
fc338970 431 /* Some instruction starting with 0x83 other than `subl'. */
c906108c
SS
432 {
433 codestream_seek (codestream_tell () - 2);
434 return 0;
435 }
fc338970
MK
436 /* `subl' with signed byte immediate (though it wouldn't
437 make sense to be negative). */
c5aa993b 438 return (codestream_get ());
c906108c
SS
439 }
440 else if (op == 0x81)
441 {
442 char buf[4];
fc338970 443 /* Maybe it is `subl' with a 32 bit immedediate. */
c5aa993b 444 codestream_get ();
c906108c 445 if (codestream_get () != 0xec)
fc338970 446 /* Some instruction starting with 0x81 other than `subl'. */
c906108c
SS
447 {
448 codestream_seek (codestream_tell () - 2);
449 return 0;
450 }
fc338970 451 /* It is `subl' with a 32 bit immediate. */
c5aa993b 452 codestream_read ((unsigned char *) buf, 4);
c906108c
SS
453 return extract_signed_integer (buf, 4);
454 }
455 else
456 {
fc338970 457 return 0;
c906108c
SS
458 }
459 }
460 else if (op == 0xc8)
461 {
462 char buf[2];
fc338970 463 /* `enter' with 16 bit unsigned immediate. */
c5aa993b 464 codestream_read ((unsigned char *) buf, 2);
fc338970 465 codestream_get (); /* Flush final byte of enter instruction. */
c906108c
SS
466 return extract_unsigned_integer (buf, 2);
467 }
468 return (-1);
469}
470
6bff26de
MK
471/* Signal trampolines don't have a meaningful frame. The frame
472 pointer value we use is actually the frame pointer of the calling
473 frame -- that is, the frame which was in progress when the signal
474 trampoline was entered. GDB mostly treats this frame pointer value
475 as a magic cookie. We detect the case of a signal trampoline by
5a203e44
AC
476 testing for get_frame_type() == SIGTRAMP_FRAME, which is set based
477 on PC_IN_SIGTRAMP.
6bff26de
MK
478
479 When a signal trampoline is invoked from a frameless function, we
480 essentially have two frameless functions in a row. In this case,
481 we use the same magic cookie for three frames in a row. We detect
5a203e44
AC
482 this case by seeing whether the next frame is a SIGTRAMP_FRAME,
483 and, if it does, checking whether the current frame is actually
484 frameless. In this case, we need to get the PC by looking at the
485 SP register value stored in the signal context.
6bff26de
MK
486
487 This should work in most cases except in horrible situations where
488 a signal occurs just as we enter a function but before the frame
c0d1d883
MK
489 has been set up. Incidentally, that's just what happens when we
490 call a function from GDB with a signal pending (there's a test in
491 the testsuite that makes this happen). Therefore we pretend that
492 we have a frameless function if we're stopped at the start of a
493 function. */
6bff26de
MK
494
495/* Return non-zero if we're dealing with a frameless signal, that is,
496 a signal trampoline invoked from a frameless function. */
497
5512c44a 498int
6bff26de
MK
499i386_frameless_signal_p (struct frame_info *frame)
500{
5a203e44 501 return (frame->next && get_frame_type (frame->next) == SIGTRAMP_FRAME
c0d1d883 502 && (frameless_look_for_prologue (frame)
50abf9e5 503 || get_frame_pc (frame) == get_pc_function_start (get_frame_pc (frame))));
6bff26de
MK
504}
505
c833a37e
MK
506/* Return the chain-pointer for FRAME. In the case of the i386, the
507 frame's nominal address is the address of a 4-byte word containing
508 the calling frame's address. */
509
8201327c 510static CORE_ADDR
c833a37e
MK
511i386_frame_chain (struct frame_info *frame)
512{
50abf9e5 513 if (pc_in_dummy_frame (get_frame_pc (frame)))
c0d1d883
MK
514 return frame->frame;
515
5a203e44 516 if (get_frame_type (frame) == SIGTRAMP_FRAME
6bff26de 517 || i386_frameless_signal_p (frame))
c833a37e
MK
518 return frame->frame;
519
50abf9e5 520 if (! inside_entry_file (get_frame_pc (frame)))
c833a37e
MK
521 return read_memory_unsigned_integer (frame->frame, 4);
522
523 return 0;
524}
525
539ffe0b
MK
526/* Determine whether the function invocation represented by FRAME does
527 not have a from on the stack associated with it. If it does not,
528 return non-zero, otherwise return zero. */
529
3a1e71e3 530static int
539ffe0b
MK
531i386_frameless_function_invocation (struct frame_info *frame)
532{
5a203e44 533 if (get_frame_type (frame) == SIGTRAMP_FRAME)
539ffe0b
MK
534 return 0;
535
536 return frameless_look_for_prologue (frame);
537}
538
21d0e8a4
MK
539/* Assuming FRAME is for a sigtramp routine, return the saved program
540 counter. */
541
542static CORE_ADDR
543i386_sigtramp_saved_pc (struct frame_info *frame)
544{
545 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
546 CORE_ADDR addr;
547
548 addr = tdep->sigcontext_addr (frame);
549 return read_memory_unsigned_integer (addr + tdep->sc_pc_offset, 4);
550}
551
6bff26de
MK
552/* Assuming FRAME is for a sigtramp routine, return the saved stack
553 pointer. */
554
555static CORE_ADDR
556i386_sigtramp_saved_sp (struct frame_info *frame)
557{
558 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
559 CORE_ADDR addr;
560
561 addr = tdep->sigcontext_addr (frame);
562 return read_memory_unsigned_integer (addr + tdep->sc_sp_offset, 4);
563}
564
0d17c81d
MK
565/* Return the saved program counter for FRAME. */
566
8201327c 567static CORE_ADDR
0d17c81d
MK
568i386_frame_saved_pc (struct frame_info *frame)
569{
50abf9e5 570 if (pc_in_dummy_frame (get_frame_pc (frame)))
267bf4bb
MK
571 {
572 ULONGEST pc;
573
574 frame_unwind_unsigned_register (frame, PC_REGNUM, &pc);
575 return pc;
576 }
c0d1d883 577
5a203e44 578 if (get_frame_type (frame) == SIGTRAMP_FRAME)
21d0e8a4 579 return i386_sigtramp_saved_pc (frame);
0d17c81d 580
6bff26de
MK
581 if (i386_frameless_signal_p (frame))
582 {
583 CORE_ADDR sp = i386_sigtramp_saved_sp (frame->next);
584 return read_memory_unsigned_integer (sp, 4);
585 }
586
8201327c 587 return read_memory_unsigned_integer (frame->frame + 4, 4);
22797942
AC
588}
589
ed84f6c1
MK
590/* Immediately after a function call, return the saved pc. */
591
8201327c 592static CORE_ADDR
ed84f6c1
MK
593i386_saved_pc_after_call (struct frame_info *frame)
594{
5a203e44 595 if (get_frame_type (frame) == SIGTRAMP_FRAME)
6bff26de
MK
596 return i386_sigtramp_saved_pc (frame);
597
ed84f6c1
MK
598 return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
599}
600
c906108c
SS
601/* Return number of args passed to a frame.
602 Can return -1, meaning no way to tell. */
603
3a1e71e3 604static int
fba45db2 605i386_frame_num_args (struct frame_info *fi)
c906108c
SS
606{
607#if 1
608 return -1;
609#else
610 /* This loses because not only might the compiler not be popping the
fc338970
MK
611 args right after the function call, it might be popping args from
612 both this call and a previous one, and we would say there are
613 more args than there really are. */
c906108c 614
c5aa993b
JM
615 int retpc;
616 unsigned char op;
c906108c
SS
617 struct frame_info *pfi;
618
fc338970 619 /* On the i386, the instruction following the call could be:
c906108c
SS
620 popl %ecx - one arg
621 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
fc338970 622 anything else - zero args. */
c906108c
SS
623
624 int frameless;
625
392a587b 626 frameless = FRAMELESS_FUNCTION_INVOCATION (fi);
c906108c 627 if (frameless)
fc338970
MK
628 /* In the absence of a frame pointer, GDB doesn't get correct
629 values for nameless arguments. Return -1, so it doesn't print
630 any nameless arguments. */
c906108c
SS
631 return -1;
632
c5aa993b 633 pfi = get_prev_frame (fi);
c906108c
SS
634 if (pfi == 0)
635 {
fc338970
MK
636 /* NOTE: This can happen if we are looking at the frame for
637 main, because FRAME_CHAIN_VALID won't let us go into start.
638 If we have debugging symbols, that's not really a big deal;
639 it just means it will only show as many arguments to main as
640 are declared. */
c906108c
SS
641 return -1;
642 }
643 else
644 {
c5aa993b
JM
645 retpc = pfi->pc;
646 op = read_memory_integer (retpc, 1);
fc338970 647 if (op == 0x59) /* pop %ecx */
c5aa993b 648 return 1;
c906108c
SS
649 else if (op == 0x83)
650 {
c5aa993b
JM
651 op = read_memory_integer (retpc + 1, 1);
652 if (op == 0xc4)
653 /* addl $<signed imm 8 bits>, %esp */
654 return (read_memory_integer (retpc + 2, 1) & 0xff) / 4;
c906108c
SS
655 else
656 return 0;
657 }
fc338970
MK
658 else if (op == 0x81) /* `add' with 32 bit immediate. */
659 {
c5aa993b
JM
660 op = read_memory_integer (retpc + 1, 1);
661 if (op == 0xc4)
662 /* addl $<imm 32>, %esp */
663 return read_memory_integer (retpc + 2, 4) / 4;
c906108c
SS
664 else
665 return 0;
666 }
667 else
668 {
669 return 0;
670 }
671 }
672#endif
673}
674
fc338970
MK
675/* Parse the first few instructions the function to see what registers
676 were stored.
677
678 We handle these cases:
679
680 The startup sequence can be at the start of the function, or the
681 function can start with a branch to startup code at the end.
682
683 %ebp can be set up with either the 'enter' instruction, or "pushl
684 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
685 once used in the System V compiler).
686
687 Local space is allocated just below the saved %ebp by either the
688 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
689 bit unsigned argument for space to allocate, and the 'addl'
690 instruction could have either a signed byte, or 32 bit immediate.
691
692 Next, the registers used by this function are pushed. With the
693 System V compiler they will always be in the order: %edi, %esi,
694 %ebx (and sometimes a harmless bug causes it to also save but not
695 restore %eax); however, the code below is willing to see the pushes
696 in any order, and will handle up to 8 of them.
697
698 If the setup sequence is at the end of the function, then the next
699 instruction will be a branch back to the start. */
c906108c 700
3a1e71e3 701static void
fba45db2 702i386_frame_init_saved_regs (struct frame_info *fip)
c906108c
SS
703{
704 long locals = -1;
705 unsigned char op;
fc338970 706 CORE_ADDR addr;
c906108c
SS
707 CORE_ADDR pc;
708 int i;
c5aa993b 709
b2fb4676 710 if (get_frame_saved_regs (fip))
1211c4e4
AC
711 return;
712
713 frame_saved_regs_zalloc (fip);
c5aa993b 714
50abf9e5 715 pc = get_pc_function_start (get_frame_pc (fip));
c906108c
SS
716 if (pc != 0)
717 locals = i386_get_frame_setup (pc);
c5aa993b
JM
718
719 if (locals >= 0)
c906108c 720 {
fc338970 721 addr = fip->frame - 4 - locals;
c5aa993b 722 for (i = 0; i < 8; i++)
c906108c
SS
723 {
724 op = codestream_get ();
725 if (op < 0x50 || op > 0x57)
726 break;
727#ifdef I386_REGNO_TO_SYMMETRY
728 /* Dynix uses different internal numbering. Ick. */
b2fb4676 729 get_frame_saved_regs (fip)[I386_REGNO_TO_SYMMETRY (op - 0x50)] = addr;
c906108c 730#else
b2fb4676 731 get_frame_saved_regs (fip)[op - 0x50] = addr;
c906108c 732#endif
fc338970 733 addr -= 4;
c906108c
SS
734 }
735 }
c5aa993b 736
b2fb4676
AC
737 get_frame_saved_regs (fip)[PC_REGNUM] = fip->frame + 4;
738 get_frame_saved_regs (fip)[FP_REGNUM] = fip->frame;
c906108c
SS
739}
740
fc338970 741/* Return PC of first real instruction. */
c906108c 742
3a1e71e3 743static CORE_ADDR
93924b6b 744i386_skip_prologue (CORE_ADDR pc)
c906108c
SS
745{
746 unsigned char op;
747 int i;
c5aa993b 748 static unsigned char pic_pat[6] =
fc338970
MK
749 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
750 0x5b, /* popl %ebx */
c5aa993b 751 };
c906108c 752 CORE_ADDR pos;
c5aa993b 753
c906108c
SS
754 if (i386_get_frame_setup (pc) < 0)
755 return (pc);
c5aa993b 756
fc338970
MK
757 /* Found valid frame setup -- codestream now points to start of push
758 instructions for saving registers. */
c5aa993b 759
fc338970 760 /* Skip over register saves. */
c906108c
SS
761 for (i = 0; i < 8; i++)
762 {
763 op = codestream_peek ();
fc338970 764 /* Break if not `pushl' instrunction. */
c5aa993b 765 if (op < 0x50 || op > 0x57)
c906108c
SS
766 break;
767 codestream_get ();
768 }
769
fc338970
MK
770 /* The native cc on SVR4 in -K PIC mode inserts the following code
771 to get the address of the global offset table (GOT) into register
772 %ebx
773
774 call 0x0
775 popl %ebx
776 movl %ebx,x(%ebp) (optional)
777 addl y,%ebx
778
c906108c
SS
779 This code is with the rest of the prologue (at the end of the
780 function), so we have to skip it to get to the first real
781 instruction at the start of the function. */
c5aa993b 782
c906108c
SS
783 pos = codestream_tell ();
784 for (i = 0; i < 6; i++)
785 {
786 op = codestream_get ();
c5aa993b 787 if (pic_pat[i] != op)
c906108c
SS
788 break;
789 }
790 if (i == 6)
791 {
792 unsigned char buf[4];
793 long delta = 6;
794
795 op = codestream_get ();
c5aa993b 796 if (op == 0x89) /* movl %ebx, x(%ebp) */
c906108c
SS
797 {
798 op = codestream_get ();
fc338970 799 if (op == 0x5d) /* One byte offset from %ebp. */
c906108c
SS
800 {
801 delta += 3;
802 codestream_read (buf, 1);
803 }
fc338970 804 else if (op == 0x9d) /* Four byte offset from %ebp. */
c906108c
SS
805 {
806 delta += 6;
807 codestream_read (buf, 4);
808 }
fc338970 809 else /* Unexpected instruction. */
c5aa993b
JM
810 delta = -1;
811 op = codestream_get ();
c906108c 812 }
c5aa993b
JM
813 /* addl y,%ebx */
814 if (delta > 0 && op == 0x81 && codestream_get () == 0xc3)
c906108c 815 {
c5aa993b 816 pos += delta + 6;
c906108c
SS
817 }
818 }
819 codestream_seek (pos);
c5aa993b 820
c906108c 821 i386_follow_jump ();
c5aa993b 822
c906108c
SS
823 return (codestream_tell ());
824}
825
93924b6b
MK
826/* Use the program counter to determine the contents and size of a
827 breakpoint instruction. Return a pointer to a string of bytes that
828 encode a breakpoint instruction, store the length of the string in
829 *LEN and optionally adjust *PC to point to the correct memory
830 location for inserting the breakpoint.
831
832 On the i386 we have a single breakpoint that fits in a single byte
833 and can be inserted anywhere. */
834
835static const unsigned char *
836i386_breakpoint_from_pc (CORE_ADDR *pc, int *len)
837{
838 static unsigned char break_insn[] = { 0xcc }; /* int 3 */
839
840 *len = sizeof (break_insn);
841 return break_insn;
842}
843
c0d1d883
MK
844/* Push the return address (pointing to the call dummy) onto the stack
845 and return the new value for the stack pointer. */
c5aa993b 846
c0d1d883
MK
847static CORE_ADDR
848i386_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
a7769679 849{
c0d1d883 850 char buf[4];
a7769679 851
c0d1d883
MK
852 store_unsigned_integer (buf, 4, CALL_DUMMY_ADDRESS ());
853 write_memory (sp - 4, buf, 4);
854 return sp - 4;
a7769679
MK
855}
856
3a1e71e3 857static void
c0d1d883 858i386_do_pop_frame (struct frame_info *frame)
c906108c 859{
c906108c
SS
860 CORE_ADDR fp;
861 int regnum;
00f8375e 862 char regbuf[I386_MAX_REGISTER_SIZE];
c5aa993b 863
c193f6ac 864 fp = get_frame_base (frame);
1211c4e4
AC
865 i386_frame_init_saved_regs (frame);
866
c5aa993b 867 for (regnum = 0; regnum < NUM_REGS; regnum++)
c906108c 868 {
fc338970 869 CORE_ADDR addr;
b2fb4676 870 addr = get_frame_saved_regs (frame)[regnum];
fc338970 871 if (addr)
c906108c 872 {
fc338970 873 read_memory (addr, regbuf, REGISTER_RAW_SIZE (regnum));
4caf0990 874 deprecated_write_register_gen (regnum, regbuf);
c906108c
SS
875 }
876 }
877 write_register (FP_REGNUM, read_memory_integer (fp, 4));
878 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
879 write_register (SP_REGNUM, fp + 8);
880 flush_cached_frames ();
881}
c0d1d883
MK
882
883static void
884i386_pop_frame (void)
885{
886 generic_pop_current_frame (i386_do_pop_frame);
887}
fc338970 888\f
c906108c 889
fc338970
MK
890/* Figure out where the longjmp will land. Slurp the args out of the
891 stack. We expect the first arg to be a pointer to the jmp_buf
8201327c
MK
892 structure from which we extract the address that we will land at.
893 This address is copied into PC. This routine returns true on
fc338970 894 success. */
c906108c 895
8201327c
MK
896static int
897i386_get_longjmp_target (CORE_ADDR *pc)
c906108c 898{
8201327c 899 char buf[4];
c906108c 900 CORE_ADDR sp, jb_addr;
8201327c 901 int jb_pc_offset = gdbarch_tdep (current_gdbarch)->jb_pc_offset;
c906108c 902
8201327c
MK
903 /* If JB_PC_OFFSET is -1, we have no way to find out where the
904 longjmp will land. */
905 if (jb_pc_offset == -1)
c906108c
SS
906 return 0;
907
8201327c
MK
908 sp = read_register (SP_REGNUM);
909 if (target_read_memory (sp + 4, buf, 4))
c906108c
SS
910 return 0;
911
8201327c
MK
912 jb_addr = extract_address (buf, 4);
913 if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
914 return 0;
c906108c 915
8201327c 916 *pc = extract_address (buf, 4);
c906108c
SS
917 return 1;
918}
fc338970 919\f
c906108c 920
3a1e71e3 921static CORE_ADDR
ea7c478f 922i386_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
22f8ba57
MK
923 int struct_return, CORE_ADDR struct_addr)
924{
925 sp = default_push_arguments (nargs, args, sp, struct_return, struct_addr);
926
927 if (struct_return)
928 {
929 char buf[4];
930
931 sp -= 4;
932 store_address (buf, 4, struct_addr);
933 write_memory (sp, buf, 4);
934 }
935
936 return sp;
937}
938
3a1e71e3 939static void
22f8ba57
MK
940i386_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
941{
942 /* Do nothing. Everything was already done by i386_push_arguments. */
943}
944
1a309862
MK
945/* These registers are used for returning integers (and on some
946 targets also for returning `struct' and `union' values when their
ef9dff19 947 size and alignment match an integer type). */
1a309862
MK
948#define LOW_RETURN_REGNUM 0 /* %eax */
949#define HIGH_RETURN_REGNUM 2 /* %edx */
950
951/* Extract from an array REGBUF containing the (raw) register state, a
952 function return value of TYPE, and copy that, in virtual format,
953 into VALBUF. */
954
3a1e71e3 955static void
00f8375e 956i386_extract_return_value (struct type *type, struct regcache *regcache,
ebba8386 957 void *dst)
c906108c 958{
ebba8386 959 bfd_byte *valbuf = dst;
1a309862 960 int len = TYPE_LENGTH (type);
00f8375e 961 char buf[I386_MAX_REGISTER_SIZE];
1a309862 962
1e8d0a7b
MK
963 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
964 && TYPE_NFIELDS (type) == 1)
3df1b9b4 965 {
00f8375e 966 i386_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf);
3df1b9b4
MK
967 return;
968 }
1e8d0a7b
MK
969
970 if (TYPE_CODE (type) == TYPE_CODE_FLT)
c906108c 971 {
356a6b3e 972 if (FP0_REGNUM == 0)
1a309862
MK
973 {
974 warning ("Cannot find floating-point return value.");
975 memset (valbuf, 0, len);
ef9dff19 976 return;
1a309862
MK
977 }
978
c6ba6f0d
MK
979 /* Floating-point return values can be found in %st(0). Convert
980 its contents to the desired type. This is probably not
981 exactly how it would happen on the target itself, but it is
982 the best we can do. */
0818c12a 983 regcache_raw_read (regcache, FP0_REGNUM, buf);
00f8375e 984 convert_typed_floating (buf, builtin_type_i387_ext, valbuf, type);
c906108c
SS
985 }
986 else
c5aa993b 987 {
d4f3574e
SS
988 int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM);
989 int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM);
990
991 if (len <= low_size)
00f8375e 992 {
0818c12a 993 regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
00f8375e
MK
994 memcpy (valbuf, buf, len);
995 }
d4f3574e
SS
996 else if (len <= (low_size + high_size))
997 {
0818c12a 998 regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf);
00f8375e 999 memcpy (valbuf, buf, low_size);
0818c12a 1000 regcache_raw_read (regcache, HIGH_RETURN_REGNUM, buf);
00f8375e 1001 memcpy (valbuf + low_size, buf, len - low_size);
d4f3574e
SS
1002 }
1003 else
8e65ff28
AC
1004 internal_error (__FILE__, __LINE__,
1005 "Cannot extract return value of %d bytes long.", len);
c906108c
SS
1006 }
1007}
1008
ef9dff19
MK
1009/* Write into the appropriate registers a function return value stored
1010 in VALBUF of type TYPE, given in virtual format. */
1011
3a1e71e3 1012static void
3d7f4f49
MK
1013i386_store_return_value (struct type *type, struct regcache *regcache,
1014 const void *valbuf)
ef9dff19
MK
1015{
1016 int len = TYPE_LENGTH (type);
1017
1e8d0a7b
MK
1018 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1019 && TYPE_NFIELDS (type) == 1)
3df1b9b4 1020 {
3d7f4f49 1021 i386_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf);
3df1b9b4
MK
1022 return;
1023 }
1e8d0a7b
MK
1024
1025 if (TYPE_CODE (type) == TYPE_CODE_FLT)
ef9dff19 1026 {
3d7f4f49 1027 ULONGEST fstat;
c6ba6f0d 1028 char buf[FPU_REG_RAW_SIZE];
ccb945b8 1029
356a6b3e 1030 if (FP0_REGNUM == 0)
ef9dff19
MK
1031 {
1032 warning ("Cannot set floating-point return value.");
1033 return;
1034 }
1035
635b0cc1
MK
1036 /* Returning floating-point values is a bit tricky. Apart from
1037 storing the return value in %st(0), we have to simulate the
1038 state of the FPU at function return point. */
1039
c6ba6f0d
MK
1040 /* Convert the value found in VALBUF to the extended
1041 floating-point format used by the FPU. This is probably
1042 not exactly how it would happen on the target itself, but
1043 it is the best we can do. */
1044 convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
3d7f4f49 1045 regcache_raw_write (regcache, FP0_REGNUM, buf);
ccb945b8 1046
635b0cc1
MK
1047 /* Set the top of the floating-point register stack to 7. The
1048 actual value doesn't really matter, but 7 is what a normal
1049 function return would end up with if the program started out
1050 with a freshly initialized FPU. */
3d7f4f49 1051 regcache_raw_read_unsigned (regcache, FSTAT_REGNUM, &fstat);
ccb945b8 1052 fstat |= (7 << 11);
3d7f4f49 1053 regcache_raw_write_unsigned (regcache, FSTAT_REGNUM, fstat);
ccb945b8 1054
635b0cc1
MK
1055 /* Mark %st(1) through %st(7) as empty. Since we set the top of
1056 the floating-point register stack to 7, the appropriate value
1057 for the tag word is 0x3fff. */
3d7f4f49 1058 regcache_raw_write_unsigned (regcache, FTAG_REGNUM, 0x3fff);
ef9dff19
MK
1059 }
1060 else
1061 {
1062 int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM);
1063 int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM);
1064
1065 if (len <= low_size)
3d7f4f49 1066 regcache_raw_write_part (regcache, LOW_RETURN_REGNUM, 0, len, valbuf);
ef9dff19
MK
1067 else if (len <= (low_size + high_size))
1068 {
3d7f4f49
MK
1069 regcache_raw_write (regcache, LOW_RETURN_REGNUM, valbuf);
1070 regcache_raw_write_part (regcache, HIGH_RETURN_REGNUM, 0,
1071 len - low_size, (char *) valbuf + low_size);
ef9dff19
MK
1072 }
1073 else
8e65ff28
AC
1074 internal_error (__FILE__, __LINE__,
1075 "Cannot store return value of %d bytes long.", len);
ef9dff19
MK
1076 }
1077}
f7af9647 1078
751f1375
MK
1079/* Extract from REGCACHE, which contains the (raw) register state, the
1080 address in which a function should return its structure value, as a
1081 CORE_ADDR. */
f7af9647 1082
3a1e71e3 1083static CORE_ADDR
00f8375e 1084i386_extract_struct_value_address (struct regcache *regcache)
f7af9647 1085{
751f1375
MK
1086 ULONGEST addr;
1087
1088 regcache_raw_read_unsigned (regcache, LOW_RETURN_REGNUM, &addr);
1089 return addr;
f7af9647 1090}
fc338970 1091\f
ef9dff19 1092
8201327c
MK
1093/* This is the variable that is set with "set struct-convention", and
1094 its legitimate values. */
1095static const char default_struct_convention[] = "default";
1096static const char pcc_struct_convention[] = "pcc";
1097static const char reg_struct_convention[] = "reg";
1098static const char *valid_conventions[] =
1099{
1100 default_struct_convention,
1101 pcc_struct_convention,
1102 reg_struct_convention,
1103 NULL
1104};
1105static const char *struct_convention = default_struct_convention;
1106
1107static int
1108i386_use_struct_convention (int gcc_p, struct type *type)
1109{
1110 enum struct_return struct_return;
1111
1112 if (struct_convention == default_struct_convention)
1113 struct_return = gdbarch_tdep (current_gdbarch)->struct_return;
1114 else if (struct_convention == pcc_struct_convention)
1115 struct_return = pcc_struct_return;
1116 else
1117 struct_return = reg_struct_return;
1118
1119 return generic_use_struct_convention (struct_return == reg_struct_return,
1120 type);
1121}
1122\f
1123
d7a0d72c
MK
1124/* Return the GDB type object for the "standard" data type of data in
1125 register REGNUM. Perhaps %esi and %edi should go here, but
1126 potentially they could be used for things other than address. */
1127
3a1e71e3 1128static struct type *
d7a0d72c
MK
1129i386_register_virtual_type (int regnum)
1130{
1131 if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM)
1132 return lookup_pointer_type (builtin_type_void);
1133
23a34459 1134 if (i386_fp_regnum_p (regnum))
c6ba6f0d 1135 return builtin_type_i387_ext;
d7a0d72c 1136
23a34459 1137 if (i386_sse_regnum_p (regnum))
3139facc 1138 return builtin_type_vec128i;
d7a0d72c 1139
23a34459 1140 if (i386_mmx_regnum_p (regnum))
28fc6740
AC
1141 return builtin_type_vec64i;
1142
d7a0d72c
MK
1143 return builtin_type_int;
1144}
1145
28fc6740
AC
1146/* Map a cooked register onto a raw register or memory. For the i386,
1147 the MMX registers need to be mapped onto floating point registers. */
1148
1149static int
1150mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum)
1151{
1152 int mmxi;
1153 ULONGEST fstat;
1154 int tos;
1155 int fpi;
1156 mmxi = regnum - MM0_REGNUM;
1157 regcache_raw_read_unsigned (regcache, FSTAT_REGNUM, &fstat);
1158 tos = (fstat >> 11) & 0x7;
1159 fpi = (mmxi + tos) % 8;
1160 return (FP0_REGNUM + fpi);
1161}
1162
1163static void
1164i386_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
1165 int regnum, void *buf)
1166{
23a34459 1167 if (i386_mmx_regnum_p (regnum))
28fc6740
AC
1168 {
1169 char *mmx_buf = alloca (MAX_REGISTER_RAW_SIZE);
1170 int fpnum = mmx_regnum_to_fp_regnum (regcache, regnum);
1171 regcache_raw_read (regcache, fpnum, mmx_buf);
1172 /* Extract (always little endian). */
1173 memcpy (buf, mmx_buf, REGISTER_RAW_SIZE (regnum));
1174 }
1175 else
1176 regcache_raw_read (regcache, regnum, buf);
1177}
1178
1179static void
1180i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1181 int regnum, const void *buf)
1182{
23a34459 1183 if (i386_mmx_regnum_p (regnum))
28fc6740
AC
1184 {
1185 char *mmx_buf = alloca (MAX_REGISTER_RAW_SIZE);
1186 int fpnum = mmx_regnum_to_fp_regnum (regcache, regnum);
1187 /* Read ... */
1188 regcache_raw_read (regcache, fpnum, mmx_buf);
1189 /* ... Modify ... (always little endian). */
1190 memcpy (mmx_buf, buf, REGISTER_RAW_SIZE (regnum));
1191 /* ... Write. */
1192 regcache_raw_write (regcache, fpnum, mmx_buf);
1193 }
1194 else
1195 regcache_raw_write (regcache, regnum, buf);
1196}
1197
d7a0d72c
MK
1198/* Return true iff register REGNUM's virtual format is different from
1199 its raw format. Note that this definition assumes that the host
1200 supports IEEE 32-bit floats, since it doesn't say that SSE
1201 registers need conversion. Even if we can't find a counterexample,
1202 this is still sloppy. */
1203
3a1e71e3 1204static int
d7a0d72c
MK
1205i386_register_convertible (int regnum)
1206{
23a34459 1207 return i386_fp_regnum_p (regnum);
d7a0d72c
MK
1208}
1209
ac27f131 1210/* Convert data from raw format for register REGNUM in buffer FROM to
3d261580 1211 virtual format with type TYPE in buffer TO. */
ac27f131 1212
3a1e71e3 1213static void
ac27f131
MK
1214i386_register_convert_to_virtual (int regnum, struct type *type,
1215 char *from, char *to)
1216{
23a34459 1217 gdb_assert (i386_fp_regnum_p (regnum));
3d261580
MK
1218
1219 /* We only support floating-point values. */
8d7f6b4a
MK
1220 if (TYPE_CODE (type) != TYPE_CODE_FLT)
1221 {
1222 warning ("Cannot convert floating-point register value "
1223 "to non-floating-point type.");
1224 memset (to, 0, TYPE_LENGTH (type));
1225 return;
1226 }
3d261580 1227
c6ba6f0d
MK
1228 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
1229 the extended floating-point format used by the FPU. */
1230 convert_typed_floating (from, builtin_type_i387_ext, to, type);
ac27f131
MK
1231}
1232
1233/* Convert data from virtual format with type TYPE in buffer FROM to
3d261580 1234 raw format for register REGNUM in buffer TO. */
ac27f131 1235
3a1e71e3 1236static void
ac27f131
MK
1237i386_register_convert_to_raw (struct type *type, int regnum,
1238 char *from, char *to)
1239{
23a34459 1240 gdb_assert (i386_fp_regnum_p (regnum));
c6ba6f0d
MK
1241
1242 /* We only support floating-point values. */
1243 if (TYPE_CODE (type) != TYPE_CODE_FLT)
1244 {
1245 warning ("Cannot convert non-floating-point type "
1246 "to floating-point register value.");
1247 memset (to, 0, TYPE_LENGTH (type));
1248 return;
1249 }
3d261580 1250
c6ba6f0d
MK
1251 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
1252 to the extended floating-point format used by the FPU. */
1253 convert_typed_floating (from, type, to, builtin_type_i387_ext);
ac27f131 1254}
ac27f131 1255\f
fc338970 1256
c906108c 1257#ifdef STATIC_TRANSFORM_NAME
fc338970
MK
1258/* SunPRO encodes the static variables. This is not related to C++
1259 mangling, it is done for C too. */
c906108c
SS
1260
1261char *
fba45db2 1262sunpro_static_transform_name (char *name)
c906108c
SS
1263{
1264 char *p;
1265 if (IS_STATIC_TRANSFORM_NAME (name))
1266 {
fc338970
MK
1267 /* For file-local statics there will be a period, a bunch of
1268 junk (the contents of which match a string given in the
c5aa993b
JM
1269 N_OPT), a period and the name. For function-local statics
1270 there will be a bunch of junk (which seems to change the
1271 second character from 'A' to 'B'), a period, the name of the
1272 function, and the name. So just skip everything before the
1273 last period. */
c906108c
SS
1274 p = strrchr (name, '.');
1275 if (p != NULL)
1276 name = p + 1;
1277 }
1278 return name;
1279}
1280#endif /* STATIC_TRANSFORM_NAME */
fc338970 1281\f
c906108c 1282
fc338970 1283/* Stuff for WIN32 PE style DLL's but is pretty generic really. */
c906108c
SS
1284
1285CORE_ADDR
1cce71eb 1286i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name)
c906108c 1287{
fc338970 1288 if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */
c906108c 1289 {
c5aa993b 1290 unsigned long indirect = read_memory_unsigned_integer (pc + 2, 4);
c906108c 1291 struct minimal_symbol *indsym =
fc338970 1292 indirect ? lookup_minimal_symbol_by_pc (indirect) : 0;
c5aa993b 1293 char *symname = indsym ? SYMBOL_NAME (indsym) : 0;
c906108c 1294
c5aa993b 1295 if (symname)
c906108c 1296 {
c5aa993b
JM
1297 if (strncmp (symname, "__imp_", 6) == 0
1298 || strncmp (symname, "_imp_", 5) == 0)
c906108c
SS
1299 return name ? 1 : read_memory_unsigned_integer (indirect, 4);
1300 }
1301 }
fc338970 1302 return 0; /* Not a trampoline. */
c906108c 1303}
fc338970
MK
1304\f
1305
8201327c
MK
1306/* Return non-zero if PC and NAME show that we are in a signal
1307 trampoline. */
1308
1309static int
1310i386_pc_in_sigtramp (CORE_ADDR pc, char *name)
1311{
1312 return (name && strcmp ("_sigtramp", name) == 0);
1313}
1314\f
1315
fc338970
MK
1316/* We have two flavours of disassembly. The machinery on this page
1317 deals with switching between those. */
c906108c
SS
1318
1319static int
5e3397bb 1320i386_print_insn (bfd_vma pc, disassemble_info *info)
c906108c 1321{
5e3397bb
MK
1322 gdb_assert (disassembly_flavor == att_flavor
1323 || disassembly_flavor == intel_flavor);
1324
1325 /* FIXME: kettenis/20020915: Until disassembler_options is properly
1326 constified, cast to prevent a compiler warning. */
1327 info->disassembler_options = (char *) disassembly_flavor;
1328 info->mach = gdbarch_bfd_arch_info (current_gdbarch)->mach;
1329
1330 return print_insn_i386 (pc, info);
7a292a7a 1331}
fc338970 1332\f
3ce1502b 1333
8201327c
MK
1334/* There are a few i386 architecture variants that differ only
1335 slightly from the generic i386 target. For now, we don't give them
1336 their own source file, but include them here. As a consequence,
1337 they'll always be included. */
3ce1502b 1338
8201327c 1339/* System V Release 4 (SVR4). */
3ce1502b 1340
8201327c
MK
1341static int
1342i386_svr4_pc_in_sigtramp (CORE_ADDR pc, char *name)
d2a7c97a 1343{
8201327c
MK
1344 return (name && (strcmp ("_sigreturn", name) == 0
1345 || strcmp ("_sigacthandler", name) == 0
1346 || strcmp ("sigvechandler", name) == 0));
1347}
d2a7c97a 1348
21d0e8a4
MK
1349/* Get address of the pushed ucontext (sigcontext) on the stack for
1350 all three variants of SVR4 sigtramps. */
3ce1502b 1351
3a1e71e3 1352static CORE_ADDR
21d0e8a4 1353i386_svr4_sigcontext_addr (struct frame_info *frame)
8201327c 1354{
21d0e8a4 1355 int sigcontext_offset = -1;
8201327c
MK
1356 char *name = NULL;
1357
50abf9e5 1358 find_pc_partial_function (get_frame_pc (frame), &name, NULL, NULL);
8201327c 1359 if (name)
d2a7c97a 1360 {
8201327c 1361 if (strcmp (name, "_sigreturn") == 0)
21d0e8a4 1362 sigcontext_offset = 132;
8201327c 1363 else if (strcmp (name, "_sigacthandler") == 0)
21d0e8a4 1364 sigcontext_offset = 80;
8201327c 1365 else if (strcmp (name, "sigvechandler") == 0)
21d0e8a4 1366 sigcontext_offset = 120;
8201327c 1367 }
3ce1502b 1368
21d0e8a4
MK
1369 gdb_assert (sigcontext_offset != -1);
1370
8201327c 1371 if (frame->next)
21d0e8a4
MK
1372 return frame->next->frame + sigcontext_offset;
1373 return read_register (SP_REGNUM) + sigcontext_offset;
8201327c
MK
1374}
1375\f
3ce1502b 1376
8201327c 1377/* DJGPP. */
d2a7c97a 1378
8201327c
MK
1379static int
1380i386_go32_pc_in_sigtramp (CORE_ADDR pc, char *name)
1381{
1382 /* DJGPP doesn't have any special frames for signal handlers. */
1383 return 0;
1384}
1385\f
d2a7c97a 1386
8201327c 1387/* Generic ELF. */
d2a7c97a 1388
8201327c
MK
1389void
1390i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1391{
1392 /* We typically use stabs-in-ELF with the DWARF register numbering. */
1393 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1394}
3ce1502b 1395
8201327c 1396/* System V Release 4 (SVR4). */
3ce1502b 1397
8201327c
MK
1398void
1399i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1400{
1401 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3ce1502b 1402
8201327c
MK
1403 /* System V Release 4 uses ELF. */
1404 i386_elf_init_abi (info, gdbarch);
3ce1502b 1405
dfe01d39
MK
1406 /* System V Release 4 has shared libraries. */
1407 set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section);
1408 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
1409
8201327c 1410 /* FIXME: kettenis/20020511: Why do we override this function here? */
b4671f85 1411 set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
3ce1502b 1412
8201327c 1413 set_gdbarch_pc_in_sigtramp (gdbarch, i386_svr4_pc_in_sigtramp);
21d0e8a4
MK
1414 tdep->sigcontext_addr = i386_svr4_sigcontext_addr;
1415 tdep->sc_pc_offset = 14 * 4;
1416 tdep->sc_sp_offset = 7 * 4;
3ce1502b 1417
8201327c 1418 tdep->jb_pc_offset = 20;
3ce1502b
MK
1419}
1420
8201327c 1421/* DJGPP. */
3ce1502b 1422
3a1e71e3 1423static void
8201327c 1424i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3ce1502b 1425{
8201327c 1426 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3ce1502b 1427
8201327c 1428 set_gdbarch_pc_in_sigtramp (gdbarch, i386_go32_pc_in_sigtramp);
3ce1502b 1429
8201327c 1430 tdep->jb_pc_offset = 36;
3ce1502b
MK
1431}
1432
8201327c 1433/* NetWare. */
3ce1502b 1434
3a1e71e3 1435static void
8201327c 1436i386_nw_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3ce1502b 1437{
8201327c 1438 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3ce1502b 1439
8201327c 1440 /* FIXME: kettenis/20020511: Why do we override this function here? */
b4671f85 1441 set_gdbarch_frame_chain_valid (gdbarch, generic_func_frame_chain_valid);
8201327c
MK
1442
1443 tdep->jb_pc_offset = 24;
d2a7c97a 1444}
8201327c 1445\f
2acceee2 1446
38c968cf
AC
1447/* i386 register groups. In addition to the normal groups, add "mmx"
1448 and "sse". */
1449
1450static struct reggroup *i386_sse_reggroup;
1451static struct reggroup *i386_mmx_reggroup;
1452
1453static void
1454i386_init_reggroups (void)
1455{
1456 i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP);
1457 i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP);
1458}
1459
1460static void
1461i386_add_reggroups (struct gdbarch *gdbarch)
1462{
1463 reggroup_add (gdbarch, i386_sse_reggroup);
1464 reggroup_add (gdbarch, i386_mmx_reggroup);
1465 reggroup_add (gdbarch, general_reggroup);
1466 reggroup_add (gdbarch, float_reggroup);
1467 reggroup_add (gdbarch, all_reggroup);
1468 reggroup_add (gdbarch, save_reggroup);
1469 reggroup_add (gdbarch, restore_reggroup);
1470 reggroup_add (gdbarch, vector_reggroup);
1471 reggroup_add (gdbarch, system_reggroup);
1472}
1473
1474int
1475i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
1476 struct reggroup *group)
1477{
1478 int sse_regnum_p = (i386_sse_regnum_p (regnum)
1479 || i386_mxcsr_regnum_p (regnum));
1480 int fp_regnum_p = (i386_fp_regnum_p (regnum)
1481 || i386_fpc_regnum_p (regnum));
1482 int mmx_regnum_p = (i386_mmx_regnum_p (regnum));
1483 if (group == i386_mmx_reggroup)
1484 return mmx_regnum_p;
1485 if (group == i386_sse_reggroup)
1486 return sse_regnum_p;
1487 if (group == vector_reggroup)
1488 return (mmx_regnum_p || sse_regnum_p);
1489 if (group == float_reggroup)
1490 return fp_regnum_p;
1491 if (group == general_reggroup)
1492 return (!fp_regnum_p && !mmx_regnum_p && !sse_regnum_p);
1493 return default_register_reggroup_p (gdbarch, regnum, group);
1494}
1495
1496\f
3a1e71e3 1497static struct gdbarch *
a62cc96e
AC
1498i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1499{
cd3c07fc 1500 struct gdbarch_tdep *tdep;
a62cc96e 1501 struct gdbarch *gdbarch;
8201327c 1502 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
a62cc96e 1503
8201327c 1504 /* Try to determine the OS ABI of the object we're loading. */
3ce1502b 1505 if (info.abfd != NULL)
8201327c 1506 osabi = gdbarch_lookup_osabi (info.abfd);
d2a7c97a 1507
3ce1502b 1508 /* Find a candidate among extant architectures. */
d2a7c97a
MK
1509 for (arches = gdbarch_list_lookup_by_info (arches, &info);
1510 arches != NULL;
1511 arches = gdbarch_list_lookup_by_info (arches->next, &info))
1512 {
8201327c 1513 /* Make sure the OS ABI selection matches. */
65d6d66a 1514 tdep = gdbarch_tdep (arches->gdbarch);
8201327c 1515 if (tdep && tdep->osabi == osabi)
65d6d66a 1516 return arches->gdbarch;
d2a7c97a 1517 }
a62cc96e
AC
1518
1519 /* Allocate space for the new architecture. */
1520 tdep = XMALLOC (struct gdbarch_tdep);
1521 gdbarch = gdbarch_alloc (&info, tdep);
1522
a5afb99f
AC
1523 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1524 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1525 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
1526
8201327c
MK
1527 tdep->osabi = osabi;
1528
1529 /* The i386 default settings don't include the SSE registers.
356a6b3e
MK
1530 FIXME: kettenis/20020614: They do include the FPU registers for
1531 now, which probably is not quite right. */
8201327c 1532 tdep->num_xmm_regs = 0;
d2a7c97a 1533
8201327c
MK
1534 tdep->jb_pc_offset = -1;
1535 tdep->struct_return = pcc_struct_return;
8201327c
MK
1536 tdep->sigtramp_start = 0;
1537 tdep->sigtramp_end = 0;
21d0e8a4 1538 tdep->sigcontext_addr = NULL;
8201327c 1539 tdep->sc_pc_offset = -1;
21d0e8a4 1540 tdep->sc_sp_offset = -1;
8201327c 1541
896fb97d
MK
1542 /* The format used for `long double' on almost all i386 targets is
1543 the i387 extended floating-point format. In fact, of all targets
1544 in the GCC 2.95 tree, only OSF/1 does it different, and insists
1545 on having a `long double' that's not `long' at all. */
1546 set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext);
21d0e8a4 1547
66da5fd8 1548 /* Although the i387 extended floating-point has only 80 significant
896fb97d
MK
1549 bits, a `long double' actually takes up 96, probably to enforce
1550 alignment. */
1551 set_gdbarch_long_double_bit (gdbarch, 96);
1552
356a6b3e
MK
1553 /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-ptx.h,
1554 tm-symmetry.h currently override this. Sigh. */
1555 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS);
21d0e8a4 1556
66da5fd8
MK
1557 set_gdbarch_sp_regnum (gdbarch, 4); /* %esp */
1558 set_gdbarch_fp_regnum (gdbarch, 5); /* %ebp */
1559 set_gdbarch_pc_regnum (gdbarch, 8); /* %eip */
1560 set_gdbarch_ps_regnum (gdbarch, 9); /* %eflags */
1561 set_gdbarch_fp0_regnum (gdbarch, 16); /* %st(0) */
356a6b3e
MK
1562
1563 /* Use the "default" register numbering scheme for stabs and COFF. */
1564 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum);
1565 set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum);
1566
1567 /* Use the DWARF register numbering scheme for DWARF and DWARF 2. */
1568 set_gdbarch_dwarf_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1569 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1570
1571 /* We don't define ECOFF_REG_TO_REGNUM, since ECOFF doesn't seem to
1572 be in use on any of the supported i386 targets. */
1573
1574 set_gdbarch_register_name (gdbarch, i386_register_name);
1575 set_gdbarch_register_size (gdbarch, 4);
1576 set_gdbarch_register_bytes (gdbarch, I386_SIZEOF_GREGS + I386_SIZEOF_FREGS);
00f8375e
MK
1577 set_gdbarch_max_register_raw_size (gdbarch, I386_MAX_REGISTER_SIZE);
1578 set_gdbarch_max_register_virtual_size (gdbarch, I386_MAX_REGISTER_SIZE);
b6197528 1579 set_gdbarch_register_virtual_type (gdbarch, i386_register_virtual_type);
356a6b3e 1580
61113f8b
MK
1581 set_gdbarch_print_float_info (gdbarch, i387_print_float_info);
1582
8201327c 1583 set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target);
96297dab 1584
a62cc96e 1585 /* Call dummy code. */
c0d1d883 1586 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
8758dec1 1587 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
c0d1d883 1588 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
a62cc96e 1589 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
c0d1d883 1590 set_gdbarch_call_dummy_length (gdbarch, 0);
a62cc96e 1591 set_gdbarch_call_dummy_p (gdbarch, 1);
c0d1d883
MK
1592 set_gdbarch_call_dummy_words (gdbarch, NULL);
1593 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
a62cc96e 1594 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
c0d1d883 1595 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
a62cc96e 1596
b6197528
MK
1597 set_gdbarch_register_convertible (gdbarch, i386_register_convertible);
1598 set_gdbarch_register_convert_to_virtual (gdbarch,
1599 i386_register_convert_to_virtual);
1600 set_gdbarch_register_convert_to_raw (gdbarch, i386_register_convert_to_raw);
1601
8758dec1
MK
1602 /* "An argument's size is increased, if necessary, to make it a
1603 multiple of [32-bit] words. This may require tail padding,
1604 depending on the size of the argument" -- from the x86 ABI. */
1605 set_gdbarch_parm_boundary (gdbarch, 32);
1606
00f8375e 1607 set_gdbarch_extract_return_value (gdbarch, i386_extract_return_value);
fc08ec52 1608 set_gdbarch_push_arguments (gdbarch, i386_push_arguments);
c0d1d883
MK
1609 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
1610 set_gdbarch_push_return_address (gdbarch, i386_push_return_address);
fc08ec52
MK
1611 set_gdbarch_pop_frame (gdbarch, i386_pop_frame);
1612 set_gdbarch_store_struct_return (gdbarch, i386_store_struct_return);
3d7f4f49 1613 set_gdbarch_store_return_value (gdbarch, i386_store_return_value);
00f8375e 1614 set_gdbarch_extract_struct_value_address (gdbarch,
fc08ec52 1615 i386_extract_struct_value_address);
8201327c
MK
1616 set_gdbarch_use_struct_convention (gdbarch, i386_use_struct_convention);
1617
42fdc8df 1618 set_gdbarch_frame_init_saved_regs (gdbarch, i386_frame_init_saved_regs);
93924b6b
MK
1619 set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue);
1620
1621 /* Stack grows downward. */
1622 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1623
1624 set_gdbarch_breakpoint_from_pc (gdbarch, i386_breakpoint_from_pc);
1625 set_gdbarch_decr_pc_after_break (gdbarch, 1);
1626 set_gdbarch_function_start_offset (gdbarch, 0);
42fdc8df 1627
8201327c
MK
1628 /* The following redefines make backtracing through sigtramp work.
1629 They manufacture a fake sigtramp frame and obtain the saved pc in
1630 sigtramp from the sigcontext structure which is pushed by the
1631 kernel on the user stack, along with a pointer to it. */
1632
42fdc8df
MK
1633 set_gdbarch_frame_args_skip (gdbarch, 8);
1634 set_gdbarch_frameless_function_invocation (gdbarch,
1635 i386_frameless_function_invocation);
8201327c 1636 set_gdbarch_frame_chain (gdbarch, i386_frame_chain);
c0d1d883 1637 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
8201327c
MK
1638 set_gdbarch_frame_saved_pc (gdbarch, i386_frame_saved_pc);
1639 set_gdbarch_saved_pc_after_call (gdbarch, i386_saved_pc_after_call);
42fdc8df 1640 set_gdbarch_frame_num_args (gdbarch, i386_frame_num_args);
8201327c
MK
1641 set_gdbarch_pc_in_sigtramp (gdbarch, i386_pc_in_sigtramp);
1642
28fc6740
AC
1643 /* Wire in the MMX registers. */
1644 set_gdbarch_num_pseudo_regs (gdbarch, mmx_num_regs);
1645 set_gdbarch_pseudo_register_read (gdbarch, i386_pseudo_register_read);
1646 set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write);
1647
5e3397bb
MK
1648 set_gdbarch_print_insn (gdbarch, i386_print_insn);
1649
38c968cf
AC
1650 /* Add the i386 register groups. */
1651 i386_add_reggroups (gdbarch);
1652 set_gdbarch_register_reggroup_p (gdbarch, i386_register_reggroup_p);
1653
3ce1502b 1654 /* Hook in ABI-specific overrides, if they have been registered. */
8201327c 1655 gdbarch_init_osabi (info, gdbarch, osabi);
3ce1502b 1656
a62cc96e
AC
1657 return gdbarch;
1658}
1659
8201327c
MK
1660static enum gdb_osabi
1661i386_coff_osabi_sniffer (bfd *abfd)
1662{
762c5349
MK
1663 if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0
1664 || strcmp (bfd_get_target (abfd), "coff-go32") == 0)
8201327c
MK
1665 return GDB_OSABI_GO32;
1666
1667 return GDB_OSABI_UNKNOWN;
1668}
1669
1670static enum gdb_osabi
1671i386_nlm_osabi_sniffer (bfd *abfd)
1672{
1673 return GDB_OSABI_NETWARE;
1674}
1675\f
1676
28e9e0f0
MK
1677/* Provide a prototype to silence -Wmissing-prototypes. */
1678void _initialize_i386_tdep (void);
1679
c906108c 1680void
fba45db2 1681_initialize_i386_tdep (void)
c906108c 1682{
a62cc96e
AC
1683 register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init);
1684
fc338970 1685 /* Add the variable that controls the disassembly flavor. */
917317f4
JM
1686 {
1687 struct cmd_list_element *new_cmd;
7a292a7a 1688
917317f4
JM
1689 new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class,
1690 valid_flavors,
1ed2a135 1691 &disassembly_flavor,
fc338970
MK
1692 "\
1693Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
c906108c 1694and the default value is \"att\".",
917317f4 1695 &setlist);
917317f4
JM
1696 add_show_from_set (new_cmd, &showlist);
1697 }
8201327c
MK
1698
1699 /* Add the variable that controls the convention for returning
1700 structs. */
1701 {
1702 struct cmd_list_element *new_cmd;
1703
1704 new_cmd = add_set_enum_cmd ("struct-convention", no_class,
5e3397bb 1705 valid_conventions,
8201327c
MK
1706 &struct_convention, "\
1707Set the convention for returning small structs, valid values \
1708are \"default\", \"pcc\" and \"reg\", and the default value is \"default\".",
1709 &setlist);
1710 add_show_from_set (new_cmd, &showlist);
1711 }
1712
1713 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
1714 i386_coff_osabi_sniffer);
1715 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_nlm_flavour,
1716 i386_nlm_osabi_sniffer);
1717
05816f70 1718 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
8201327c 1719 i386_svr4_init_abi);
05816f70 1720 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_GO32,
8201327c 1721 i386_go32_init_abi);
05816f70 1722 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETWARE,
8201327c 1723 i386_nw_init_abi);
38c968cf
AC
1724
1725 /* Initialize the i386 specific register groups. */
1726 i386_init_reggroups ();
c906108c 1727}