* config/i386/tm-i386.h (TARGET_LONG_DOUBLE_FORMAT,
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
1 /* Intel 386 target-dependent stuff.
2
3 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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. */
22
23 #include "defs.h"
24 #include "gdb_string.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "gdbcore.h"
28 #include "target.h"
29 #include "floatformat.h"
30 #include "symtab.h"
31 #include "gdbcmd.h"
32 #include "command.h"
33 #include "arch-utils.h"
34 #include "regcache.h"
35 #include "doublest.h"
36 #include "value.h"
37 #include "gdb_assert.h"
38
39 #include "i386-tdep.h"
40
41 /* Names of the registers. The first 10 registers match the register
42 numbering scheme used by GCC for stabs and DWARF. */
43 static char *i386_register_names[] =
44 {
45 "eax", "ecx", "edx", "ebx",
46 "esp", "ebp", "esi", "edi",
47 "eip", "eflags", "cs", "ss",
48 "ds", "es", "fs", "gs",
49 "st0", "st1", "st2", "st3",
50 "st4", "st5", "st6", "st7",
51 "fctrl", "fstat", "ftag", "fiseg",
52 "fioff", "foseg", "fooff", "fop",
53 "xmm0", "xmm1", "xmm2", "xmm3",
54 "xmm4", "xmm5", "xmm6", "xmm7",
55 "mxcsr"
56 };
57
58 /* i386_register_offset[i] is the offset into the register file of the
59 start of register number i. We initialize this from
60 i386_register_size. */
61 static int i386_register_offset[MAX_NUM_REGS];
62
63 /* i386_register_size[i] is the number of bytes of storage in GDB's
64 register array occupied by register i. */
65 static int i386_register_size[MAX_NUM_REGS] = {
66 4, 4, 4, 4,
67 4, 4, 4, 4,
68 4, 4, 4, 4,
69 4, 4, 4, 4,
70 10, 10, 10, 10,
71 10, 10, 10, 10,
72 4, 4, 4, 4,
73 4, 4, 4, 4,
74 16, 16, 16, 16,
75 16, 16, 16, 16,
76 4
77 };
78
79 /* Return the name of register REG. */
80
81 char *
82 i386_register_name (int reg)
83 {
84 if (reg < 0)
85 return NULL;
86 if (reg >= sizeof (i386_register_names) / sizeof (*i386_register_names))
87 return NULL;
88
89 return i386_register_names[reg];
90 }
91
92 /* Return the offset into the register array of the start of register
93 number REG. */
94 int
95 i386_register_byte (int reg)
96 {
97 return i386_register_offset[reg];
98 }
99
100 /* Return the number of bytes of storage in GDB's register array
101 occupied by register REG. */
102
103 int
104 i386_register_raw_size (int reg)
105 {
106 return i386_register_size[reg];
107 }
108
109 /* Return the size in bytes of the virtual type of register REG. */
110
111 int
112 i386_register_virtual_size (int reg)
113 {
114 return TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (reg));
115 }
116
117 /* Convert stabs register number REG to the appropriate register
118 number used by GDB. */
119
120 static int
121 i386_stab_reg_to_regnum (int reg)
122 {
123 /* This implements what GCC calls the "default" register map. */
124 if (reg >= 0 && reg <= 7)
125 {
126 /* General registers. */
127 return reg;
128 }
129 else if (reg >= 12 && reg <= 19)
130 {
131 /* Floating-point registers. */
132 return reg - 12 + FP0_REGNUM;
133 }
134 else if (reg >= 21 && reg <= 28)
135 {
136 /* SSE registers. */
137 return reg - 21 + XMM0_REGNUM;
138 }
139 else if (reg >= 29 && reg <= 36)
140 {
141 /* MMX registers. */
142 /* FIXME: kettenis/2001-07-28: Should we have the MMX registers
143 as pseudo-registers? */
144 return reg - 29 + FP0_REGNUM;
145 }
146
147 /* This will hopefully provoke a warning. */
148 return NUM_REGS + NUM_PSEUDO_REGS;
149 }
150
151 /* Convert DWARF register number REG to the appropriate register
152 number used by GDB. */
153
154 static int
155 i386_dwarf_reg_to_regnum (int reg)
156 {
157 /* The DWARF register numbering includes %eip and %eflags, and
158 numbers the floating point registers differently. */
159 if (reg >= 0 && reg <= 9)
160 {
161 /* General registers. */
162 return reg;
163 }
164 else if (reg >= 11 && reg <= 18)
165 {
166 /* Floating-point registers. */
167 return reg - 11 + FP0_REGNUM;
168 }
169 else if (reg >= 21)
170 {
171 /* The SSE and MMX registers have identical numbers as in stabs. */
172 return i386_stab_reg_to_regnum (reg);
173 }
174
175 /* This will hopefully provoke a warning. */
176 return NUM_REGS + NUM_PSEUDO_REGS;
177 }
178 \f
179
180 /* This is the variable that is set with "set disassembly-flavor", and
181 its legitimate values. */
182 static const char att_flavor[] = "att";
183 static const char intel_flavor[] = "intel";
184 static const char *valid_flavors[] =
185 {
186 att_flavor,
187 intel_flavor,
188 NULL
189 };
190 static const char *disassembly_flavor = att_flavor;
191
192 /* Stdio style buffering was used to minimize calls to ptrace, but
193 this buffering did not take into account that the code section
194 being accessed may not be an even number of buffers long (even if
195 the buffer is only sizeof(int) long). In cases where the code
196 section size happened to be a non-integral number of buffers long,
197 attempting to read the last buffer would fail. Simply using
198 target_read_memory and ignoring errors, rather than read_memory, is
199 not the correct solution, since legitimate access errors would then
200 be totally ignored. To properly handle this situation and continue
201 to use buffering would require that this code be able to determine
202 the minimum code section size granularity (not the alignment of the
203 section itself, since the actual failing case that pointed out this
204 problem had a section alignment of 4 but was not a multiple of 4
205 bytes long), on a target by target basis, and then adjust it's
206 buffer size accordingly. This is messy, but potentially feasible.
207 It probably needs the bfd library's help and support. For now, the
208 buffer size is set to 1. (FIXME -fnf) */
209
210 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
211 static CORE_ADDR codestream_next_addr;
212 static CORE_ADDR codestream_addr;
213 static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
214 static int codestream_off;
215 static int codestream_cnt;
216
217 #define codestream_tell() (codestream_addr + codestream_off)
218 #define codestream_peek() \
219 (codestream_cnt == 0 ? \
220 codestream_fill(1) : codestream_buf[codestream_off])
221 #define codestream_get() \
222 (codestream_cnt-- == 0 ? \
223 codestream_fill(0) : codestream_buf[codestream_off++])
224
225 static unsigned char
226 codestream_fill (int peek_flag)
227 {
228 codestream_addr = codestream_next_addr;
229 codestream_next_addr += CODESTREAM_BUFSIZ;
230 codestream_off = 0;
231 codestream_cnt = CODESTREAM_BUFSIZ;
232 read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
233
234 if (peek_flag)
235 return (codestream_peek ());
236 else
237 return (codestream_get ());
238 }
239
240 static void
241 codestream_seek (CORE_ADDR place)
242 {
243 codestream_next_addr = place / CODESTREAM_BUFSIZ;
244 codestream_next_addr *= CODESTREAM_BUFSIZ;
245 codestream_cnt = 0;
246 codestream_fill (1);
247 while (codestream_tell () != place)
248 codestream_get ();
249 }
250
251 static void
252 codestream_read (unsigned char *buf, int count)
253 {
254 unsigned char *p;
255 int i;
256 p = buf;
257 for (i = 0; i < count; i++)
258 *p++ = codestream_get ();
259 }
260 \f
261
262 /* If the next instruction is a jump, move to its target. */
263
264 static void
265 i386_follow_jump (void)
266 {
267 unsigned char buf[4];
268 long delta;
269
270 int data16;
271 CORE_ADDR pos;
272
273 pos = codestream_tell ();
274
275 data16 = 0;
276 if (codestream_peek () == 0x66)
277 {
278 codestream_get ();
279 data16 = 1;
280 }
281
282 switch (codestream_get ())
283 {
284 case 0xe9:
285 /* Relative jump: if data16 == 0, disp32, else disp16. */
286 if (data16)
287 {
288 codestream_read (buf, 2);
289 delta = extract_signed_integer (buf, 2);
290
291 /* Include the size of the jmp instruction (including the
292 0x66 prefix). */
293 pos += delta + 4;
294 }
295 else
296 {
297 codestream_read (buf, 4);
298 delta = extract_signed_integer (buf, 4);
299
300 pos += delta + 5;
301 }
302 break;
303 case 0xeb:
304 /* Relative jump, disp8 (ignore data16). */
305 codestream_read (buf, 1);
306 /* Sign-extend it. */
307 delta = extract_signed_integer (buf, 1);
308
309 pos += delta + 2;
310 break;
311 }
312 codestream_seek (pos);
313 }
314
315 /* Find & return the amount a local space allocated, and advance the
316 codestream to the first register push (if any).
317
318 If the entry sequence doesn't make sense, return -1, and leave
319 codestream pointer at a random spot. */
320
321 static long
322 i386_get_frame_setup (CORE_ADDR pc)
323 {
324 unsigned char op;
325
326 codestream_seek (pc);
327
328 i386_follow_jump ();
329
330 op = codestream_get ();
331
332 if (op == 0x58) /* popl %eax */
333 {
334 /* This function must start with
335
336 popl %eax 0x58
337 xchgl %eax, (%esp) 0x87 0x04 0x24
338 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
339
340 (the System V compiler puts out the second `xchg'
341 instruction, and the assembler doesn't try to optimize it, so
342 the 'sib' form gets generated). This sequence is used to get
343 the address of the return buffer for a function that returns
344 a structure. */
345 int pos;
346 unsigned char buf[4];
347 static unsigned char proto1[3] = { 0x87, 0x04, 0x24 };
348 static unsigned char proto2[4] = { 0x87, 0x44, 0x24, 0x00 };
349
350 pos = codestream_tell ();
351 codestream_read (buf, 4);
352 if (memcmp (buf, proto1, 3) == 0)
353 pos += 3;
354 else if (memcmp (buf, proto2, 4) == 0)
355 pos += 4;
356
357 codestream_seek (pos);
358 op = codestream_get (); /* Update next opcode. */
359 }
360
361 if (op == 0x68 || op == 0x6a)
362 {
363 /* This function may start with
364
365 pushl constant
366 call _probe
367 addl $4, %esp
368
369 followed by
370
371 pushl %ebp
372
373 etc. */
374 int pos;
375 unsigned char buf[8];
376
377 /* Skip past the `pushl' instruction; it has either a one-byte
378 or a four-byte operand, depending on the opcode. */
379 pos = codestream_tell ();
380 if (op == 0x68)
381 pos += 4;
382 else
383 pos += 1;
384 codestream_seek (pos);
385
386 /* Read the following 8 bytes, which should be "call _probe" (6
387 bytes) followed by "addl $4,%esp" (2 bytes). */
388 codestream_read (buf, sizeof (buf));
389 if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
390 pos += sizeof (buf);
391 codestream_seek (pos);
392 op = codestream_get (); /* Update next opcode. */
393 }
394
395 if (op == 0x55) /* pushl %ebp */
396 {
397 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
398 switch (codestream_get ())
399 {
400 case 0x8b:
401 if (codestream_get () != 0xec)
402 return -1;
403 break;
404 case 0x89:
405 if (codestream_get () != 0xe5)
406 return -1;
407 break;
408 default:
409 return -1;
410 }
411 /* Check for stack adjustment
412
413 subl $XXX, %esp
414
415 NOTE: You can't subtract a 16 bit immediate from a 32 bit
416 reg, so we don't have to worry about a data16 prefix. */
417 op = codestream_peek ();
418 if (op == 0x83)
419 {
420 /* `subl' with 8 bit immediate. */
421 codestream_get ();
422 if (codestream_get () != 0xec)
423 /* Some instruction starting with 0x83 other than `subl'. */
424 {
425 codestream_seek (codestream_tell () - 2);
426 return 0;
427 }
428 /* `subl' with signed byte immediate (though it wouldn't
429 make sense to be negative). */
430 return (codestream_get ());
431 }
432 else if (op == 0x81)
433 {
434 char buf[4];
435 /* Maybe it is `subl' with a 32 bit immedediate. */
436 codestream_get ();
437 if (codestream_get () != 0xec)
438 /* Some instruction starting with 0x81 other than `subl'. */
439 {
440 codestream_seek (codestream_tell () - 2);
441 return 0;
442 }
443 /* It is `subl' with a 32 bit immediate. */
444 codestream_read ((unsigned char *) buf, 4);
445 return extract_signed_integer (buf, 4);
446 }
447 else
448 {
449 return 0;
450 }
451 }
452 else if (op == 0xc8)
453 {
454 char buf[2];
455 /* `enter' with 16 bit unsigned immediate. */
456 codestream_read ((unsigned char *) buf, 2);
457 codestream_get (); /* Flush final byte of enter instruction. */
458 return extract_unsigned_integer (buf, 2);
459 }
460 return (-1);
461 }
462
463 /* Return the chain-pointer for FRAME. In the case of the i386, the
464 frame's nominal address is the address of a 4-byte word containing
465 the calling frame's address. */
466
467 static CORE_ADDR
468 i386_frame_chain (struct frame_info *frame)
469 {
470 if (frame->signal_handler_caller)
471 return frame->frame;
472
473 if (! inside_entry_file (frame->pc))
474 return read_memory_unsigned_integer (frame->frame, 4);
475
476 return 0;
477 }
478
479 /* Determine whether the function invocation represented by FRAME does
480 not have a from on the stack associated with it. If it does not,
481 return non-zero, otherwise return zero. */
482
483 int
484 i386_frameless_function_invocation (struct frame_info *frame)
485 {
486 if (frame->signal_handler_caller)
487 return 0;
488
489 return frameless_look_for_prologue (frame);
490 }
491
492 /* Return the saved program counter for FRAME. */
493
494 static CORE_ADDR
495 i386_frame_saved_pc (struct frame_info *frame)
496 {
497 if (frame->signal_handler_caller)
498 {
499 CORE_ADDR (*sigtramp_saved_pc) (struct frame_info *);
500 sigtramp_saved_pc = gdbarch_tdep (current_gdbarch)->sigtramp_saved_pc;
501
502 gdb_assert (sigtramp_saved_pc != NULL);
503 return sigtramp_saved_pc (frame);
504 }
505
506 return read_memory_unsigned_integer (frame->frame + 4, 4);
507 }
508
509 /* Immediately after a function call, return the saved pc. */
510
511 static CORE_ADDR
512 i386_saved_pc_after_call (struct frame_info *frame)
513 {
514 return read_memory_unsigned_integer (read_register (SP_REGNUM), 4);
515 }
516
517 /* Return number of args passed to a frame.
518 Can return -1, meaning no way to tell. */
519
520 int
521 i386_frame_num_args (struct frame_info *fi)
522 {
523 #if 1
524 return -1;
525 #else
526 /* This loses because not only might the compiler not be popping the
527 args right after the function call, it might be popping args from
528 both this call and a previous one, and we would say there are
529 more args than there really are. */
530
531 int retpc;
532 unsigned char op;
533 struct frame_info *pfi;
534
535 /* On the i386, the instruction following the call could be:
536 popl %ecx - one arg
537 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
538 anything else - zero args. */
539
540 int frameless;
541
542 frameless = FRAMELESS_FUNCTION_INVOCATION (fi);
543 if (frameless)
544 /* In the absence of a frame pointer, GDB doesn't get correct
545 values for nameless arguments. Return -1, so it doesn't print
546 any nameless arguments. */
547 return -1;
548
549 pfi = get_prev_frame (fi);
550 if (pfi == 0)
551 {
552 /* NOTE: This can happen if we are looking at the frame for
553 main, because FRAME_CHAIN_VALID won't let us go into start.
554 If we have debugging symbols, that's not really a big deal;
555 it just means it will only show as many arguments to main as
556 are declared. */
557 return -1;
558 }
559 else
560 {
561 retpc = pfi->pc;
562 op = read_memory_integer (retpc, 1);
563 if (op == 0x59) /* pop %ecx */
564 return 1;
565 else if (op == 0x83)
566 {
567 op = read_memory_integer (retpc + 1, 1);
568 if (op == 0xc4)
569 /* addl $<signed imm 8 bits>, %esp */
570 return (read_memory_integer (retpc + 2, 1) & 0xff) / 4;
571 else
572 return 0;
573 }
574 else if (op == 0x81) /* `add' with 32 bit immediate. */
575 {
576 op = read_memory_integer (retpc + 1, 1);
577 if (op == 0xc4)
578 /* addl $<imm 32>, %esp */
579 return read_memory_integer (retpc + 2, 4) / 4;
580 else
581 return 0;
582 }
583 else
584 {
585 return 0;
586 }
587 }
588 #endif
589 }
590
591 /* Parse the first few instructions the function to see what registers
592 were stored.
593
594 We handle these cases:
595
596 The startup sequence can be at the start of the function, or the
597 function can start with a branch to startup code at the end.
598
599 %ebp can be set up with either the 'enter' instruction, or "pushl
600 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
601 once used in the System V compiler).
602
603 Local space is allocated just below the saved %ebp by either the
604 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
605 bit unsigned argument for space to allocate, and the 'addl'
606 instruction could have either a signed byte, or 32 bit immediate.
607
608 Next, the registers used by this function are pushed. With the
609 System V compiler they will always be in the order: %edi, %esi,
610 %ebx (and sometimes a harmless bug causes it to also save but not
611 restore %eax); however, the code below is willing to see the pushes
612 in any order, and will handle up to 8 of them.
613
614 If the setup sequence is at the end of the function, then the next
615 instruction will be a branch back to the start. */
616
617 void
618 i386_frame_init_saved_regs (struct frame_info *fip)
619 {
620 long locals = -1;
621 unsigned char op;
622 CORE_ADDR dummy_bottom;
623 CORE_ADDR addr;
624 CORE_ADDR pc;
625 int i;
626
627 if (fip->saved_regs)
628 return;
629
630 frame_saved_regs_zalloc (fip);
631
632 /* If the frame is the end of a dummy, compute where the beginning
633 would be. */
634 dummy_bottom = fip->frame - 4 - REGISTER_BYTES - CALL_DUMMY_LENGTH;
635
636 /* Check if the PC points in the stack, in a dummy frame. */
637 if (dummy_bottom <= fip->pc && fip->pc <= fip->frame)
638 {
639 /* All registers were saved by push_call_dummy. */
640 addr = fip->frame;
641 for (i = 0; i < NUM_REGS; i++)
642 {
643 addr -= REGISTER_RAW_SIZE (i);
644 fip->saved_regs[i] = addr;
645 }
646 return;
647 }
648
649 pc = get_pc_function_start (fip->pc);
650 if (pc != 0)
651 locals = i386_get_frame_setup (pc);
652
653 if (locals >= 0)
654 {
655 addr = fip->frame - 4 - locals;
656 for (i = 0; i < 8; i++)
657 {
658 op = codestream_get ();
659 if (op < 0x50 || op > 0x57)
660 break;
661 #ifdef I386_REGNO_TO_SYMMETRY
662 /* Dynix uses different internal numbering. Ick. */
663 fip->saved_regs[I386_REGNO_TO_SYMMETRY (op - 0x50)] = addr;
664 #else
665 fip->saved_regs[op - 0x50] = addr;
666 #endif
667 addr -= 4;
668 }
669 }
670
671 fip->saved_regs[PC_REGNUM] = fip->frame + 4;
672 fip->saved_regs[FP_REGNUM] = fip->frame;
673 }
674
675 /* Return PC of first real instruction. */
676
677 int
678 i386_skip_prologue (int pc)
679 {
680 unsigned char op;
681 int i;
682 static unsigned char pic_pat[6] =
683 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
684 0x5b, /* popl %ebx */
685 };
686 CORE_ADDR pos;
687
688 if (i386_get_frame_setup (pc) < 0)
689 return (pc);
690
691 /* Found valid frame setup -- codestream now points to start of push
692 instructions for saving registers. */
693
694 /* Skip over register saves. */
695 for (i = 0; i < 8; i++)
696 {
697 op = codestream_peek ();
698 /* Break if not `pushl' instrunction. */
699 if (op < 0x50 || op > 0x57)
700 break;
701 codestream_get ();
702 }
703
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
706 %ebx
707
708 call 0x0
709 popl %ebx
710 movl %ebx,x(%ebp) (optional)
711 addl y,%ebx
712
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. */
716
717 pos = codestream_tell ();
718 for (i = 0; i < 6; i++)
719 {
720 op = codestream_get ();
721 if (pic_pat[i] != op)
722 break;
723 }
724 if (i == 6)
725 {
726 unsigned char buf[4];
727 long delta = 6;
728
729 op = codestream_get ();
730 if (op == 0x89) /* movl %ebx, x(%ebp) */
731 {
732 op = codestream_get ();
733 if (op == 0x5d) /* One byte offset from %ebp. */
734 {
735 delta += 3;
736 codestream_read (buf, 1);
737 }
738 else if (op == 0x9d) /* Four byte offset from %ebp. */
739 {
740 delta += 6;
741 codestream_read (buf, 4);
742 }
743 else /* Unexpected instruction. */
744 delta = -1;
745 op = codestream_get ();
746 }
747 /* addl y,%ebx */
748 if (delta > 0 && op == 0x81 && codestream_get () == 0xc3)
749 {
750 pos += delta + 6;
751 }
752 }
753 codestream_seek (pos);
754
755 i386_follow_jump ();
756
757 return (codestream_tell ());
758 }
759
760 void
761 i386_push_dummy_frame (void)
762 {
763 CORE_ADDR sp = read_register (SP_REGNUM);
764 CORE_ADDR fp;
765 int regnum;
766 char regbuf[MAX_REGISTER_RAW_SIZE];
767
768 sp = push_word (sp, read_register (PC_REGNUM));
769 sp = push_word (sp, read_register (FP_REGNUM));
770 fp = sp;
771 for (regnum = 0; regnum < NUM_REGS; regnum++)
772 {
773 read_register_gen (regnum, regbuf);
774 sp = push_bytes (sp, regbuf, REGISTER_RAW_SIZE (regnum));
775 }
776 write_register (SP_REGNUM, sp);
777 write_register (FP_REGNUM, fp);
778 }
779
780 /* Insert the (relative) function address into the call sequence
781 stored at DYMMY. */
782
783 void
784 i386_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs,
785 struct value **args, struct type *type, int gcc_p)
786 {
787 int from, to, delta, loc;
788
789 loc = (int)(read_register (SP_REGNUM) - CALL_DUMMY_LENGTH);
790 from = loc + 5;
791 to = (int)(fun);
792 delta = to - from;
793
794 *((char *)(dummy) + 1) = (delta & 0xff);
795 *((char *)(dummy) + 2) = ((delta >> 8) & 0xff);
796 *((char *)(dummy) + 3) = ((delta >> 16) & 0xff);
797 *((char *)(dummy) + 4) = ((delta >> 24) & 0xff);
798 }
799
800 void
801 i386_pop_frame (void)
802 {
803 struct frame_info *frame = get_current_frame ();
804 CORE_ADDR fp;
805 int regnum;
806 char regbuf[MAX_REGISTER_RAW_SIZE];
807
808 fp = FRAME_FP (frame);
809 i386_frame_init_saved_regs (frame);
810
811 for (regnum = 0; regnum < NUM_REGS; regnum++)
812 {
813 CORE_ADDR addr;
814 addr = frame->saved_regs[regnum];
815 if (addr)
816 {
817 read_memory (addr, regbuf, REGISTER_RAW_SIZE (regnum));
818 write_register_bytes (REGISTER_BYTE (regnum), regbuf,
819 REGISTER_RAW_SIZE (regnum));
820 }
821 }
822 write_register (FP_REGNUM, read_memory_integer (fp, 4));
823 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
824 write_register (SP_REGNUM, fp + 8);
825 flush_cached_frames ();
826 }
827 \f
828
829 /* Figure out where the longjmp will land. Slurp the args out of the
830 stack. We expect the first arg to be a pointer to the jmp_buf
831 structure from which we extract the address that we will land at.
832 This address is copied into PC. This routine returns true on
833 success. */
834
835 static int
836 i386_get_longjmp_target (CORE_ADDR *pc)
837 {
838 char buf[4];
839 CORE_ADDR sp, jb_addr;
840 int jb_pc_offset = gdbarch_tdep (current_gdbarch)->jb_pc_offset;
841
842 /* If JB_PC_OFFSET is -1, we have no way to find out where the
843 longjmp will land. */
844 if (jb_pc_offset == -1)
845 return 0;
846
847 sp = read_register (SP_REGNUM);
848 if (target_read_memory (sp + 4, buf, 4))
849 return 0;
850
851 jb_addr = extract_address (buf, 4);
852 if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
853 return 0;
854
855 *pc = extract_address (buf, 4);
856 return 1;
857 }
858 \f
859
860 CORE_ADDR
861 i386_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
862 int struct_return, CORE_ADDR struct_addr)
863 {
864 sp = default_push_arguments (nargs, args, sp, struct_return, struct_addr);
865
866 if (struct_return)
867 {
868 char buf[4];
869
870 sp -= 4;
871 store_address (buf, 4, struct_addr);
872 write_memory (sp, buf, 4);
873 }
874
875 return sp;
876 }
877
878 void
879 i386_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
880 {
881 /* Do nothing. Everything was already done by i386_push_arguments. */
882 }
883
884 /* These registers are used for returning integers (and on some
885 targets also for returning `struct' and `union' values when their
886 size and alignment match an integer type). */
887 #define LOW_RETURN_REGNUM 0 /* %eax */
888 #define HIGH_RETURN_REGNUM 2 /* %edx */
889
890 /* Extract from an array REGBUF containing the (raw) register state, a
891 function return value of TYPE, and copy that, in virtual format,
892 into VALBUF. */
893
894 void
895 i386_extract_return_value (struct type *type, char *regbuf, char *valbuf)
896 {
897 int len = TYPE_LENGTH (type);
898
899 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
900 && TYPE_NFIELDS (type) == 1)
901 {
902 i386_extract_return_value (TYPE_FIELD_TYPE (type, 0), regbuf, valbuf);
903 return;
904 }
905
906 if (TYPE_CODE (type) == TYPE_CODE_FLT)
907 {
908 if (NUM_FREGS == 0)
909 {
910 warning ("Cannot find floating-point return value.");
911 memset (valbuf, 0, len);
912 return;
913 }
914
915 /* Floating-point return values can be found in %st(0). Convert
916 its contents to the desired type. This is probably not
917 exactly how it would happen on the target itself, but it is
918 the best we can do. */
919 convert_typed_floating (&regbuf[REGISTER_BYTE (FP0_REGNUM)],
920 builtin_type_i387_ext, valbuf, type);
921 }
922 else
923 {
924 int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM);
925 int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM);
926
927 if (len <= low_size)
928 memcpy (valbuf, &regbuf[REGISTER_BYTE (LOW_RETURN_REGNUM)], len);
929 else if (len <= (low_size + high_size))
930 {
931 memcpy (valbuf,
932 &regbuf[REGISTER_BYTE (LOW_RETURN_REGNUM)], low_size);
933 memcpy (valbuf + low_size,
934 &regbuf[REGISTER_BYTE (HIGH_RETURN_REGNUM)], len - low_size);
935 }
936 else
937 internal_error (__FILE__, __LINE__,
938 "Cannot extract return value of %d bytes long.", len);
939 }
940 }
941
942 /* Write into the appropriate registers a function return value stored
943 in VALBUF of type TYPE, given in virtual format. */
944
945 void
946 i386_store_return_value (struct type *type, char *valbuf)
947 {
948 int len = TYPE_LENGTH (type);
949
950 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
951 && TYPE_NFIELDS (type) == 1)
952 {
953 i386_store_return_value (TYPE_FIELD_TYPE (type, 0), valbuf);
954 return;
955 }
956
957 if (TYPE_CODE (type) == TYPE_CODE_FLT)
958 {
959 unsigned int fstat;
960 char buf[FPU_REG_RAW_SIZE];
961
962 if (NUM_FREGS == 0)
963 {
964 warning ("Cannot set floating-point return value.");
965 return;
966 }
967
968 /* Returning floating-point values is a bit tricky. Apart from
969 storing the return value in %st(0), we have to simulate the
970 state of the FPU at function return point. */
971
972 /* Convert the value found in VALBUF to the extended
973 floating-point format used by the FPU. This is probably
974 not exactly how it would happen on the target itself, but
975 it is the best we can do. */
976 convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext);
977 write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
978 FPU_REG_RAW_SIZE);
979
980 /* Set the top of the floating-point register stack to 7. The
981 actual value doesn't really matter, but 7 is what a normal
982 function return would end up with if the program started out
983 with a freshly initialized FPU. */
984 fstat = read_register (FSTAT_REGNUM);
985 fstat |= (7 << 11);
986 write_register (FSTAT_REGNUM, fstat);
987
988 /* Mark %st(1) through %st(7) as empty. Since we set the top of
989 the floating-point register stack to 7, the appropriate value
990 for the tag word is 0x3fff. */
991 write_register (FTAG_REGNUM, 0x3fff);
992 }
993 else
994 {
995 int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM);
996 int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM);
997
998 if (len <= low_size)
999 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM), valbuf, len);
1000 else if (len <= (low_size + high_size))
1001 {
1002 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM),
1003 valbuf, low_size);
1004 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM),
1005 valbuf + low_size, len - low_size);
1006 }
1007 else
1008 internal_error (__FILE__, __LINE__,
1009 "Cannot store return value of %d bytes long.", len);
1010 }
1011 }
1012
1013 /* Extract from an array REGBUF containing the (raw) register state
1014 the address in which a function should return its structure value,
1015 as a CORE_ADDR. */
1016
1017 CORE_ADDR
1018 i386_extract_struct_value_address (char *regbuf)
1019 {
1020 return extract_address (&regbuf[REGISTER_BYTE (LOW_RETURN_REGNUM)],
1021 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM));
1022 }
1023 \f
1024
1025 /* This is the variable that is set with "set struct-convention", and
1026 its legitimate values. */
1027 static const char default_struct_convention[] = "default";
1028 static const char pcc_struct_convention[] = "pcc";
1029 static const char reg_struct_convention[] = "reg";
1030 static const char *valid_conventions[] =
1031 {
1032 default_struct_convention,
1033 pcc_struct_convention,
1034 reg_struct_convention,
1035 NULL
1036 };
1037 static const char *struct_convention = default_struct_convention;
1038
1039 static int
1040 i386_use_struct_convention (int gcc_p, struct type *type)
1041 {
1042 enum struct_return struct_return;
1043
1044 if (struct_convention == default_struct_convention)
1045 struct_return = gdbarch_tdep (current_gdbarch)->struct_return;
1046 else if (struct_convention == pcc_struct_convention)
1047 struct_return = pcc_struct_return;
1048 else
1049 struct_return = reg_struct_return;
1050
1051 return generic_use_struct_convention (struct_return == reg_struct_return,
1052 type);
1053 }
1054 \f
1055
1056 /* Return the GDB type object for the "standard" data type of data in
1057 register REGNUM. Perhaps %esi and %edi should go here, but
1058 potentially they could be used for things other than address. */
1059
1060 struct type *
1061 i386_register_virtual_type (int regnum)
1062 {
1063 if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM)
1064 return lookup_pointer_type (builtin_type_void);
1065
1066 if (IS_FP_REGNUM (regnum))
1067 return builtin_type_i387_ext;
1068
1069 if (IS_SSE_REGNUM (regnum))
1070 return builtin_type_vec128i;
1071
1072 return builtin_type_int;
1073 }
1074
1075 /* Return true iff register REGNUM's virtual format is different from
1076 its raw format. Note that this definition assumes that the host
1077 supports IEEE 32-bit floats, since it doesn't say that SSE
1078 registers need conversion. Even if we can't find a counterexample,
1079 this is still sloppy. */
1080
1081 int
1082 i386_register_convertible (int regnum)
1083 {
1084 return IS_FP_REGNUM (regnum);
1085 }
1086
1087 /* Convert data from raw format for register REGNUM in buffer FROM to
1088 virtual format with type TYPE in buffer TO. */
1089
1090 void
1091 i386_register_convert_to_virtual (int regnum, struct type *type,
1092 char *from, char *to)
1093 {
1094 gdb_assert (IS_FP_REGNUM (regnum));
1095
1096 /* We only support floating-point values. */
1097 if (TYPE_CODE (type) != TYPE_CODE_FLT)
1098 {
1099 warning ("Cannot convert floating-point register value "
1100 "to non-floating-point type.");
1101 memset (to, 0, TYPE_LENGTH (type));
1102 return;
1103 }
1104
1105 /* Convert to TYPE. This should be a no-op if TYPE is equivalent to
1106 the extended floating-point format used by the FPU. */
1107 convert_typed_floating (from, builtin_type_i387_ext, to, type);
1108 }
1109
1110 /* Convert data from virtual format with type TYPE in buffer FROM to
1111 raw format for register REGNUM in buffer TO. */
1112
1113 void
1114 i386_register_convert_to_raw (struct type *type, int regnum,
1115 char *from, char *to)
1116 {
1117 gdb_assert (IS_FP_REGNUM (regnum));
1118
1119 /* We only support floating-point values. */
1120 if (TYPE_CODE (type) != TYPE_CODE_FLT)
1121 {
1122 warning ("Cannot convert non-floating-point type "
1123 "to floating-point register value.");
1124 memset (to, 0, TYPE_LENGTH (type));
1125 return;
1126 }
1127
1128 /* Convert from TYPE. This should be a no-op if TYPE is equivalent
1129 to the extended floating-point format used by the FPU. */
1130 convert_typed_floating (from, type, to, builtin_type_i387_ext);
1131 }
1132 \f
1133
1134 #ifdef STATIC_TRANSFORM_NAME
1135 /* SunPRO encodes the static variables. This is not related to C++
1136 mangling, it is done for C too. */
1137
1138 char *
1139 sunpro_static_transform_name (char *name)
1140 {
1141 char *p;
1142 if (IS_STATIC_TRANSFORM_NAME (name))
1143 {
1144 /* For file-local statics there will be a period, a bunch of
1145 junk (the contents of which match a string given in the
1146 N_OPT), a period and the name. For function-local statics
1147 there will be a bunch of junk (which seems to change the
1148 second character from 'A' to 'B'), a period, the name of the
1149 function, and the name. So just skip everything before the
1150 last period. */
1151 p = strrchr (name, '.');
1152 if (p != NULL)
1153 name = p + 1;
1154 }
1155 return name;
1156 }
1157 #endif /* STATIC_TRANSFORM_NAME */
1158 \f
1159
1160 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
1161
1162 CORE_ADDR
1163 skip_trampoline_code (CORE_ADDR pc, char *name)
1164 {
1165 if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */
1166 {
1167 unsigned long indirect = read_memory_unsigned_integer (pc + 2, 4);
1168 struct minimal_symbol *indsym =
1169 indirect ? lookup_minimal_symbol_by_pc (indirect) : 0;
1170 char *symname = indsym ? SYMBOL_NAME (indsym) : 0;
1171
1172 if (symname)
1173 {
1174 if (strncmp (symname, "__imp_", 6) == 0
1175 || strncmp (symname, "_imp_", 5) == 0)
1176 return name ? 1 : read_memory_unsigned_integer (indirect, 4);
1177 }
1178 }
1179 return 0; /* Not a trampoline. */
1180 }
1181 \f
1182
1183 /* Return non-zero if PC and NAME show that we are in a signal
1184 trampoline. */
1185
1186 static int
1187 i386_pc_in_sigtramp (CORE_ADDR pc, char *name)
1188 {
1189 return (name && strcmp ("_sigtramp", name) == 0);
1190 }
1191 \f
1192
1193 /* We have two flavours of disassembly. The machinery on this page
1194 deals with switching between those. */
1195
1196 static int
1197 gdb_print_insn_i386 (bfd_vma memaddr, disassemble_info *info)
1198 {
1199 if (disassembly_flavor == att_flavor)
1200 return print_insn_i386_att (memaddr, info);
1201 else if (disassembly_flavor == intel_flavor)
1202 return print_insn_i386_intel (memaddr, info);
1203 /* Never reached -- disassembly_flavour is always either att_flavor
1204 or intel_flavor. */
1205 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1206 }
1207 \f
1208
1209 /* There are a few i386 architecture variants that differ only
1210 slightly from the generic i386 target. For now, we don't give them
1211 their own source file, but include them here. As a consequence,
1212 they'll always be included. */
1213
1214 /* System V Release 4 (SVR4). */
1215
1216 static int
1217 i386_svr4_pc_in_sigtramp (CORE_ADDR pc, char *name)
1218 {
1219 return (name && (strcmp ("_sigreturn", name) == 0
1220 || strcmp ("_sigacthandler", name) == 0
1221 || strcmp ("sigvechandler", name) == 0));
1222 }
1223
1224 /* Get saved user PC for sigtramp from the pushed ucontext on the
1225 stack for all three variants of SVR4 sigtramps. */
1226
1227 CORE_ADDR
1228 i386_svr4_sigtramp_saved_pc (struct frame_info *frame)
1229 {
1230 CORE_ADDR saved_pc_offset = 4;
1231 char *name = NULL;
1232
1233 find_pc_partial_function (frame->pc, &name, NULL, NULL);
1234 if (name)
1235 {
1236 if (strcmp (name, "_sigreturn") == 0)
1237 saved_pc_offset = 132 + 14 * 4;
1238 else if (strcmp (name, "_sigacthandler") == 0)
1239 saved_pc_offset = 80 + 14 * 4;
1240 else if (strcmp (name, "sigvechandler") == 0)
1241 saved_pc_offset = 120 + 14 * 4;
1242 }
1243
1244 if (frame->next)
1245 return read_memory_integer (frame->next->frame + saved_pc_offset, 4);
1246 return read_memory_integer (read_register (SP_REGNUM) + saved_pc_offset, 4);
1247 }
1248 \f
1249
1250 /* DJGPP. */
1251
1252 static int
1253 i386_go32_pc_in_sigtramp (CORE_ADDR pc, char *name)
1254 {
1255 /* DJGPP doesn't have any special frames for signal handlers. */
1256 return 0;
1257 }
1258 \f
1259
1260 /* Generic ELF. */
1261
1262 void
1263 i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1264 {
1265 /* We typically use stabs-in-ELF with the DWARF register numbering. */
1266 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1267 }
1268
1269 /* System V Release 4 (SVR4). */
1270
1271 void
1272 i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1273 {
1274 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1275
1276 /* System V Release 4 uses ELF. */
1277 i386_elf_init_abi (info, gdbarch);
1278
1279 /* FIXME: kettenis/20020511: Why do we override this function here? */
1280 set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
1281
1282 set_gdbarch_pc_in_sigtramp (gdbarch, i386_svr4_pc_in_sigtramp);
1283 tdep->sigtramp_saved_pc = i386_svr4_sigtramp_saved_pc;
1284
1285 tdep->jb_pc_offset = 20;
1286 }
1287
1288 /* DJGPP. */
1289
1290 void
1291 i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1292 {
1293 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1294
1295 set_gdbarch_pc_in_sigtramp (gdbarch, i386_go32_pc_in_sigtramp);
1296
1297 tdep->jb_pc_offset = 36;
1298 }
1299
1300 /* NetWare. */
1301
1302 void
1303 i386_nw_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1304 {
1305 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1306
1307 /* FIXME: kettenis/20020511: Why do we override this function here? */
1308 set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid);
1309
1310 tdep->jb_pc_offset = 24;
1311 }
1312 \f
1313
1314 struct gdbarch *
1315 i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1316 {
1317 struct gdbarch_tdep *tdep;
1318 struct gdbarch *gdbarch;
1319 enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
1320
1321 /* Try to determine the OS ABI of the object we're loading. */
1322 if (info.abfd != NULL)
1323 osabi = gdbarch_lookup_osabi (info.abfd);
1324
1325 /* Find a candidate among extant architectures. */
1326 for (arches = gdbarch_list_lookup_by_info (arches, &info);
1327 arches != NULL;
1328 arches = gdbarch_list_lookup_by_info (arches->next, &info))
1329 {
1330 /* Make sure the OS ABI selection matches. */
1331 tdep = gdbarch_tdep (arches->gdbarch);
1332 if (tdep && tdep->osabi == osabi)
1333 return arches->gdbarch;
1334 }
1335
1336 /* Allocate space for the new architecture. */
1337 tdep = XMALLOC (struct gdbarch_tdep);
1338 gdbarch = gdbarch_alloc (&info, tdep);
1339
1340 tdep->osabi = osabi;
1341
1342 /* The i386 default settings don't include the SSE registers.
1343 FIXME: kettenis/20020509: They do include the FPU registers for
1344 now, which is not quite right. */
1345 tdep->num_xmm_regs = 0;
1346
1347 tdep->jb_pc_offset = -1;
1348 tdep->struct_return = pcc_struct_return;
1349 tdep->sigtramp_saved_pc = NULL;
1350 tdep->sigtramp_start = 0;
1351 tdep->sigtramp_end = 0;
1352 tdep->sc_pc_offset = -1;
1353
1354 /* The format used for `long double' on almost all i386 targets is
1355 the i387 extended floating-point format. In fact, of all targets
1356 in the GCC 2.95 tree, only OSF/1 does it different, and insists
1357 on having a `long double' that's not `long' at all. */
1358 set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext);
1359
1360 /* Although the i386 extended floating-point has only 80 significant
1361 bits, a `long double' actually takes up 96, probably to enforce
1362 alignment. */
1363 set_gdbarch_long_double_bit (gdbarch, 96);
1364
1365 set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target);
1366
1367 set_gdbarch_use_generic_dummy_frames (gdbarch, 0);
1368
1369 /* Call dummy code. */
1370 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
1371 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 5);
1372 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
1373 set_gdbarch_call_dummy_p (gdbarch, 1);
1374 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1375
1376 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
1377 set_gdbarch_push_arguments (gdbarch, i386_push_arguments);
1378
1379 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack);
1380
1381 set_gdbarch_use_struct_convention (gdbarch, i386_use_struct_convention);
1382
1383 /* The following redefines make backtracing through sigtramp work.
1384 They manufacture a fake sigtramp frame and obtain the saved pc in
1385 sigtramp from the sigcontext structure which is pushed by the
1386 kernel on the user stack, along with a pointer to it. */
1387
1388 set_gdbarch_frame_chain (gdbarch, i386_frame_chain);
1389 set_gdbarch_frame_chain_valid (gdbarch, file_frame_chain_valid);
1390 set_gdbarch_frame_saved_pc (gdbarch, i386_frame_saved_pc);
1391 set_gdbarch_saved_pc_after_call (gdbarch, i386_saved_pc_after_call);
1392 set_gdbarch_pc_in_sigtramp (gdbarch, i386_pc_in_sigtramp);
1393
1394 /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-ptx.h,
1395 tm-symmetry.h currently override this. Sigh. */
1396 set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS);
1397
1398 /* Use the "default" register numbering scheme for stabs and COFF. */
1399 set_gdbarch_stab_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum);
1400 set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum);
1401
1402 /* Use the DWARF register numbering scheme for DWARF and DWARF 2. */
1403 set_gdbarch_dwarf_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1404 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum);
1405
1406 /* We don't define ECOFF_REG_TO_REGNUM, since ECOFF doesn't seem to
1407 be in use on any of the supported i386 targets. */
1408
1409 set_gdbarch_register_bytes (gdbarch, I386_SIZEOF_GREGS + I386_SIZEOF_FREGS);
1410 set_gdbarch_register_name (gdbarch, i386_register_name);
1411 set_gdbarch_register_byte (gdbarch, i386_register_byte);
1412 set_gdbarch_register_raw_size (gdbarch, i386_register_raw_size);
1413
1414 /* Hook in ABI-specific overrides, if they have been registered. */
1415 gdbarch_init_osabi (info, gdbarch, osabi);
1416
1417 return gdbarch;
1418 }
1419
1420 static enum gdb_osabi
1421 i386_coff_osabi_sniffer (bfd *abfd)
1422 {
1423 if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0)
1424 return GDB_OSABI_GO32;
1425
1426 return GDB_OSABI_UNKNOWN;
1427 }
1428
1429 static enum gdb_osabi
1430 i386_nlm_osabi_sniffer (bfd *abfd)
1431 {
1432 return GDB_OSABI_NETWARE;
1433 }
1434 \f
1435
1436 /* Provide a prototype to silence -Wmissing-prototypes. */
1437 void _initialize_i386_tdep (void);
1438
1439 void
1440 _initialize_i386_tdep (void)
1441 {
1442 register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init);
1443
1444 /* Initialize the table saying where each register starts in the
1445 register file. */
1446 {
1447 int i, offset;
1448
1449 offset = 0;
1450 for (i = 0; i < MAX_NUM_REGS; i++)
1451 {
1452 i386_register_offset[i] = offset;
1453 offset += i386_register_size[i];
1454 }
1455 }
1456
1457 tm_print_insn = gdb_print_insn_i386;
1458 tm_print_insn_info.mach = bfd_lookup_arch (bfd_arch_i386, 0)->mach;
1459
1460 /* Add the variable that controls the disassembly flavor. */
1461 {
1462 struct cmd_list_element *new_cmd;
1463
1464 new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class,
1465 valid_flavors,
1466 &disassembly_flavor,
1467 "\
1468 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1469 and the default value is \"att\".",
1470 &setlist);
1471 add_show_from_set (new_cmd, &showlist);
1472 }
1473
1474 /* Add the variable that controls the convention for returning
1475 structs. */
1476 {
1477 struct cmd_list_element *new_cmd;
1478
1479 new_cmd = add_set_enum_cmd ("struct-convention", no_class,
1480 valid_conventions,
1481 &struct_convention, "\
1482 Set the convention for returning small structs, valid values \
1483 are \"default\", \"pcc\" and \"reg\", and the default value is \"default\".",
1484 &setlist);
1485 add_show_from_set (new_cmd, &showlist);
1486 }
1487
1488 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
1489 i386_coff_osabi_sniffer);
1490 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_nlm_flavour,
1491 i386_nlm_osabi_sniffer);
1492
1493 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_SVR4,
1494 i386_svr4_init_abi);
1495 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_GO32,
1496 i386_go32_init_abi);
1497 gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETWARE,
1498 i386_nw_init_abi);
1499 }
This page took 0.087374 seconds and 4 git commands to generate.