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