Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Intel 386 target-dependent stuff. |
349c5d5f AC |
2 | |
3 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, | |
4 | 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "gdbcore.h" | |
28 | #include "target.h" | |
29 | #include "floatformat.h" | |
30 | #include "symtab.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "command.h" | |
b4a20239 | 33 | #include "arch-utils.h" |
4e052eda | 34 | #include "regcache.h" |
d16aafd8 | 35 | #include "doublest.h" |
fd0407d6 | 36 | #include "value.h" |
3d261580 MK |
37 | #include "gdb_assert.h" |
38 | ||
d2a7c97a MK |
39 | #include "i386-tdep.h" |
40 | ||
fc633446 MK |
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 | ||
1a11ba71 | 58 | /* i386_register_offset[i] is the offset into the register file of the |
917317f4 | 59 | start of register number i. We initialize this from |
1a11ba71 | 60 | i386_register_size. */ |
1cf88de5 | 61 | static int i386_register_offset[I386_SSE_NUM_REGS]; |
917317f4 | 62 | |
1a11ba71 MK |
63 | /* i386_register_size[i] is the number of bytes of storage in GDB's |
64 | register array occupied by register i. */ | |
1cf88de5 | 65 | static int i386_register_size[I386_SSE_NUM_REGS] = { |
917317f4 JM |
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 | ||
fc633446 MK |
79 | /* Return the name of register REG. */ |
80 | ||
fa88f677 | 81 | const char * |
fc633446 MK |
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 | ||
1a11ba71 MK |
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 | ||
85540d8c MK |
109 | /* Convert stabs register number REG to the appropriate register |
110 | number used by GDB. */ | |
111 | ||
8201327c | 112 | static int |
85540d8c MK |
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 | ||
8201327c | 143 | /* Convert DWARF register number REG to the appropriate register |
85540d8c MK |
144 | number used by GDB. */ |
145 | ||
8201327c | 146 | static int |
85540d8c MK |
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 | } | |
fc338970 | 170 | \f |
917317f4 | 171 | |
fc338970 MK |
172 | /* This is the variable that is set with "set disassembly-flavor", and |
173 | its legitimate values. */ | |
53904c9e AC |
174 | static const char att_flavor[] = "att"; |
175 | static const char intel_flavor[] = "intel"; | |
176 | static const char *valid_flavors[] = | |
c5aa993b | 177 | { |
c906108c SS |
178 | att_flavor, |
179 | intel_flavor, | |
180 | NULL | |
181 | }; | |
53904c9e | 182 | static const char *disassembly_flavor = att_flavor; |
c906108c | 183 | |
fc338970 MK |
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. */ | |
c906108c SS |
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) | |
fc338970 MK |
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++]) | |
c906108c | 216 | |
c5aa993b | 217 | static unsigned char |
fba45db2 | 218 | codestream_fill (int peek_flag) |
c906108c SS |
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); | |
c5aa993b | 225 | |
c906108c | 226 | if (peek_flag) |
c5aa993b | 227 | return (codestream_peek ()); |
c906108c | 228 | else |
c5aa993b | 229 | return (codestream_get ()); |
c906108c SS |
230 | } |
231 | ||
232 | static void | |
fba45db2 | 233 | codestream_seek (CORE_ADDR place) |
c906108c SS |
234 | { |
235 | codestream_next_addr = place / CODESTREAM_BUFSIZ; | |
236 | codestream_next_addr *= CODESTREAM_BUFSIZ; | |
237 | codestream_cnt = 0; | |
238 | codestream_fill (1); | |
c5aa993b | 239 | while (codestream_tell () != place) |
c906108c SS |
240 | codestream_get (); |
241 | } | |
242 | ||
243 | static void | |
fba45db2 | 244 | codestream_read (unsigned char *buf, int count) |
c906108c SS |
245 | { |
246 | unsigned char *p; | |
247 | int i; | |
248 | p = buf; | |
249 | for (i = 0; i < count; i++) | |
250 | *p++ = codestream_get (); | |
251 | } | |
fc338970 | 252 | \f |
c906108c | 253 | |
fc338970 | 254 | /* If the next instruction is a jump, move to its target. */ |
c906108c SS |
255 | |
256 | static void | |
fba45db2 | 257 | i386_follow_jump (void) |
c906108c SS |
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: | |
fc338970 | 277 | /* Relative jump: if data16 == 0, disp32, else disp16. */ |
c906108c SS |
278 | if (data16) |
279 | { | |
280 | codestream_read (buf, 2); | |
281 | delta = extract_signed_integer (buf, 2); | |
282 | ||
fc338970 MK |
283 | /* Include the size of the jmp instruction (including the |
284 | 0x66 prefix). */ | |
c5aa993b | 285 | pos += delta + 4; |
c906108c SS |
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: | |
fc338970 | 296 | /* Relative jump, disp8 (ignore data16). */ |
c906108c SS |
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 | ||
fc338970 MK |
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. */ | |
c906108c SS |
312 | |
313 | static long | |
fba45db2 | 314 | i386_get_frame_setup (CORE_ADDR pc) |
c906108c SS |
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 | { | |
fc338970 MK |
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. */ | |
c906108c SS |
337 | int pos; |
338 | unsigned char buf[4]; | |
fc338970 MK |
339 | static unsigned char proto1[3] = { 0x87, 0x04, 0x24 }; |
340 | static unsigned char proto2[4] = { 0x87, 0x44, 0x24, 0x00 }; | |
341 | ||
c906108c SS |
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); | |
fc338970 | 350 | op = codestream_get (); /* Update next opcode. */ |
c906108c SS |
351 | } |
352 | ||
353 | if (op == 0x68 || op == 0x6a) | |
354 | { | |
fc338970 MK |
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. */ | |
c906108c SS |
366 | int pos; |
367 | unsigned char buf[8]; | |
368 | ||
fc338970 | 369 | /* Skip past the `pushl' instruction; it has either a one-byte |
c906108c SS |
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 | ||
fc338970 MK |
378 | /* Read the following 8 bytes, which should be "call _probe" (6 |
379 | bytes) followed by "addl $4,%esp" (2 bytes). */ | |
c906108c SS |
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); | |
fc338970 | 384 | op = codestream_get (); /* Update next opcode. */ |
c906108c SS |
385 | } |
386 | ||
387 | if (op == 0x55) /* pushl %ebp */ | |
c5aa993b | 388 | { |
fc338970 | 389 | /* Check for "movl %esp, %ebp" -- can be written in two ways. */ |
c906108c SS |
390 | switch (codestream_get ()) |
391 | { | |
392 | case 0x8b: | |
393 | if (codestream_get () != 0xec) | |
fc338970 | 394 | return -1; |
c906108c SS |
395 | break; |
396 | case 0x89: | |
397 | if (codestream_get () != 0xe5) | |
fc338970 | 398 | return -1; |
c906108c SS |
399 | break; |
400 | default: | |
fc338970 | 401 | return -1; |
c906108c | 402 | } |
fc338970 MK |
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. */ | |
c906108c SS |
409 | op = codestream_peek (); |
410 | if (op == 0x83) | |
411 | { | |
fc338970 | 412 | /* `subl' with 8 bit immediate. */ |
c906108c SS |
413 | codestream_get (); |
414 | if (codestream_get () != 0xec) | |
fc338970 | 415 | /* Some instruction starting with 0x83 other than `subl'. */ |
c906108c SS |
416 | { |
417 | codestream_seek (codestream_tell () - 2); | |
418 | return 0; | |
419 | } | |
fc338970 MK |
420 | /* `subl' with signed byte immediate (though it wouldn't |
421 | make sense to be negative). */ | |
c5aa993b | 422 | return (codestream_get ()); |
c906108c SS |
423 | } |
424 | else if (op == 0x81) | |
425 | { | |
426 | char buf[4]; | |
fc338970 | 427 | /* Maybe it is `subl' with a 32 bit immedediate. */ |
c5aa993b | 428 | codestream_get (); |
c906108c | 429 | if (codestream_get () != 0xec) |
fc338970 | 430 | /* Some instruction starting with 0x81 other than `subl'. */ |
c906108c SS |
431 | { |
432 | codestream_seek (codestream_tell () - 2); | |
433 | return 0; | |
434 | } | |
fc338970 | 435 | /* It is `subl' with a 32 bit immediate. */ |
c5aa993b | 436 | codestream_read ((unsigned char *) buf, 4); |
c906108c SS |
437 | return extract_signed_integer (buf, 4); |
438 | } | |
439 | else | |
440 | { | |
fc338970 | 441 | return 0; |
c906108c SS |
442 | } |
443 | } | |
444 | else if (op == 0xc8) | |
445 | { | |
446 | char buf[2]; | |
fc338970 | 447 | /* `enter' with 16 bit unsigned immediate. */ |
c5aa993b | 448 | codestream_read ((unsigned char *) buf, 2); |
fc338970 | 449 | codestream_get (); /* Flush final byte of enter instruction. */ |
c906108c SS |
450 | return extract_unsigned_integer (buf, 2); |
451 | } | |
452 | return (-1); | |
453 | } | |
454 | ||
6bff26de MK |
455 | /* Signal trampolines don't have a meaningful frame. The frame |
456 | pointer value we use is actually the frame pointer of the calling | |
457 | frame -- that is, the frame which was in progress when the signal | |
458 | trampoline was entered. GDB mostly treats this frame pointer value | |
459 | as a magic cookie. We detect the case of a signal trampoline by | |
460 | looking at the SIGNAL_HANDLER_CALLER field, which is set based on | |
461 | PC_IN_SIGTRAMP. | |
462 | ||
463 | When a signal trampoline is invoked from a frameless function, we | |
464 | essentially have two frameless functions in a row. In this case, | |
465 | we use the same magic cookie for three frames in a row. We detect | |
466 | this case by seeing whether the next frame has | |
467 | SIGNAL_HANDLER_CALLER set, and, if it does, checking whether the | |
468 | current frame is actually frameless. In this case, we need to get | |
469 | the PC by looking at the SP register value stored in the signal | |
470 | context. | |
471 | ||
472 | This should work in most cases except in horrible situations where | |
473 | a signal occurs just as we enter a function but before the frame | |
474 | has been set up. */ | |
475 | ||
476 | /* Return non-zero if we're dealing with a frameless signal, that is, | |
477 | a signal trampoline invoked from a frameless function. */ | |
478 | ||
479 | static int | |
480 | i386_frameless_signal_p (struct frame_info *frame) | |
481 | { | |
482 | return (frame->next | |
483 | && frame->next->signal_handler_caller | |
484 | && frameless_look_for_prologue); | |
485 | } | |
486 | ||
c833a37e MK |
487 | /* Return the chain-pointer for FRAME. In the case of the i386, the |
488 | frame's nominal address is the address of a 4-byte word containing | |
489 | the calling frame's address. */ | |
490 | ||
8201327c | 491 | static CORE_ADDR |
c833a37e MK |
492 | i386_frame_chain (struct frame_info *frame) |
493 | { | |
6bff26de MK |
494 | if (frame->signal_handler_caller |
495 | || i386_frameless_signal_p (frame)) | |
c833a37e MK |
496 | return frame->frame; |
497 | ||
498 | if (! inside_entry_file (frame->pc)) | |
499 | return read_memory_unsigned_integer (frame->frame, 4); | |
500 | ||
501 | return 0; | |
502 | } | |
503 | ||
539ffe0b MK |
504 | /* Determine whether the function invocation represented by FRAME does |
505 | not have a from on the stack associated with it. If it does not, | |
506 | return non-zero, otherwise return zero. */ | |
507 | ||
3a1e71e3 | 508 | static int |
539ffe0b MK |
509 | i386_frameless_function_invocation (struct frame_info *frame) |
510 | { | |
511 | if (frame->signal_handler_caller) | |
512 | return 0; | |
513 | ||
514 | return frameless_look_for_prologue (frame); | |
515 | } | |
516 | ||
21d0e8a4 MK |
517 | /* Assuming FRAME is for a sigtramp routine, return the saved program |
518 | counter. */ | |
519 | ||
520 | static CORE_ADDR | |
521 | i386_sigtramp_saved_pc (struct frame_info *frame) | |
522 | { | |
523 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
524 | CORE_ADDR addr; | |
525 | ||
526 | addr = tdep->sigcontext_addr (frame); | |
527 | return read_memory_unsigned_integer (addr + tdep->sc_pc_offset, 4); | |
528 | } | |
529 | ||
6bff26de MK |
530 | /* Assuming FRAME is for a sigtramp routine, return the saved stack |
531 | pointer. */ | |
532 | ||
533 | static CORE_ADDR | |
534 | i386_sigtramp_saved_sp (struct frame_info *frame) | |
535 | { | |
536 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
537 | CORE_ADDR addr; | |
538 | ||
539 | addr = tdep->sigcontext_addr (frame); | |
540 | return read_memory_unsigned_integer (addr + tdep->sc_sp_offset, 4); | |
541 | } | |
542 | ||
0d17c81d MK |
543 | /* Return the saved program counter for FRAME. */ |
544 | ||
8201327c | 545 | static CORE_ADDR |
0d17c81d MK |
546 | i386_frame_saved_pc (struct frame_info *frame) |
547 | { | |
0d17c81d | 548 | if (frame->signal_handler_caller) |
21d0e8a4 | 549 | return i386_sigtramp_saved_pc (frame); |
0d17c81d | 550 | |
6bff26de MK |
551 | if (i386_frameless_signal_p (frame)) |
552 | { | |
553 | CORE_ADDR sp = i386_sigtramp_saved_sp (frame->next); | |
554 | return read_memory_unsigned_integer (sp, 4); | |
555 | } | |
556 | ||
8201327c | 557 | return read_memory_unsigned_integer (frame->frame + 4, 4); |
22797942 AC |
558 | } |
559 | ||
ed84f6c1 MK |
560 | /* Immediately after a function call, return the saved pc. */ |
561 | ||
8201327c | 562 | static CORE_ADDR |
ed84f6c1 MK |
563 | i386_saved_pc_after_call (struct frame_info *frame) |
564 | { | |
6bff26de MK |
565 | if (frame->signal_handler_caller) |
566 | return i386_sigtramp_saved_pc (frame); | |
567 | ||
ed84f6c1 MK |
568 | return read_memory_unsigned_integer (read_register (SP_REGNUM), 4); |
569 | } | |
570 | ||
c906108c SS |
571 | /* Return number of args passed to a frame. |
572 | Can return -1, meaning no way to tell. */ | |
573 | ||
3a1e71e3 | 574 | static int |
fba45db2 | 575 | i386_frame_num_args (struct frame_info *fi) |
c906108c SS |
576 | { |
577 | #if 1 | |
578 | return -1; | |
579 | #else | |
580 | /* This loses because not only might the compiler not be popping the | |
fc338970 MK |
581 | args right after the function call, it might be popping args from |
582 | both this call and a previous one, and we would say there are | |
583 | more args than there really are. */ | |
c906108c | 584 | |
c5aa993b JM |
585 | int retpc; |
586 | unsigned char op; | |
c906108c SS |
587 | struct frame_info *pfi; |
588 | ||
fc338970 | 589 | /* On the i386, the instruction following the call could be: |
c906108c SS |
590 | popl %ecx - one arg |
591 | addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits | |
fc338970 | 592 | anything else - zero args. */ |
c906108c SS |
593 | |
594 | int frameless; | |
595 | ||
392a587b | 596 | frameless = FRAMELESS_FUNCTION_INVOCATION (fi); |
c906108c | 597 | if (frameless) |
fc338970 MK |
598 | /* In the absence of a frame pointer, GDB doesn't get correct |
599 | values for nameless arguments. Return -1, so it doesn't print | |
600 | any nameless arguments. */ | |
c906108c SS |
601 | return -1; |
602 | ||
c5aa993b | 603 | pfi = get_prev_frame (fi); |
c906108c SS |
604 | if (pfi == 0) |
605 | { | |
fc338970 MK |
606 | /* NOTE: This can happen if we are looking at the frame for |
607 | main, because FRAME_CHAIN_VALID won't let us go into start. | |
608 | If we have debugging symbols, that's not really a big deal; | |
609 | it just means it will only show as many arguments to main as | |
610 | are declared. */ | |
c906108c SS |
611 | return -1; |
612 | } | |
613 | else | |
614 | { | |
c5aa993b JM |
615 | retpc = pfi->pc; |
616 | op = read_memory_integer (retpc, 1); | |
fc338970 | 617 | if (op == 0x59) /* pop %ecx */ |
c5aa993b | 618 | return 1; |
c906108c SS |
619 | else if (op == 0x83) |
620 | { | |
c5aa993b JM |
621 | op = read_memory_integer (retpc + 1, 1); |
622 | if (op == 0xc4) | |
623 | /* addl $<signed imm 8 bits>, %esp */ | |
624 | return (read_memory_integer (retpc + 2, 1) & 0xff) / 4; | |
c906108c SS |
625 | else |
626 | return 0; | |
627 | } | |
fc338970 MK |
628 | else if (op == 0x81) /* `add' with 32 bit immediate. */ |
629 | { | |
c5aa993b JM |
630 | op = read_memory_integer (retpc + 1, 1); |
631 | if (op == 0xc4) | |
632 | /* addl $<imm 32>, %esp */ | |
633 | return read_memory_integer (retpc + 2, 4) / 4; | |
c906108c SS |
634 | else |
635 | return 0; | |
636 | } | |
637 | else | |
638 | { | |
639 | return 0; | |
640 | } | |
641 | } | |
642 | #endif | |
643 | } | |
644 | ||
fc338970 MK |
645 | /* Parse the first few instructions the function to see what registers |
646 | were stored. | |
647 | ||
648 | We handle these cases: | |
649 | ||
650 | The startup sequence can be at the start of the function, or the | |
651 | function can start with a branch to startup code at the end. | |
652 | ||
653 | %ebp can be set up with either the 'enter' instruction, or "pushl | |
654 | %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was | |
655 | once used in the System V compiler). | |
656 | ||
657 | Local space is allocated just below the saved %ebp by either the | |
658 | 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16 | |
659 | bit unsigned argument for space to allocate, and the 'addl' | |
660 | instruction could have either a signed byte, or 32 bit immediate. | |
661 | ||
662 | Next, the registers used by this function are pushed. With the | |
663 | System V compiler they will always be in the order: %edi, %esi, | |
664 | %ebx (and sometimes a harmless bug causes it to also save but not | |
665 | restore %eax); however, the code below is willing to see the pushes | |
666 | in any order, and will handle up to 8 of them. | |
667 | ||
668 | If the setup sequence is at the end of the function, then the next | |
669 | instruction will be a branch back to the start. */ | |
c906108c | 670 | |
3a1e71e3 | 671 | static void |
fba45db2 | 672 | i386_frame_init_saved_regs (struct frame_info *fip) |
c906108c SS |
673 | { |
674 | long locals = -1; | |
675 | unsigned char op; | |
676 | CORE_ADDR dummy_bottom; | |
fc338970 | 677 | CORE_ADDR addr; |
c906108c SS |
678 | CORE_ADDR pc; |
679 | int i; | |
c5aa993b | 680 | |
1211c4e4 AC |
681 | if (fip->saved_regs) |
682 | return; | |
683 | ||
684 | frame_saved_regs_zalloc (fip); | |
c5aa993b | 685 | |
fc338970 MK |
686 | /* If the frame is the end of a dummy, compute where the beginning |
687 | would be. */ | |
c906108c | 688 | dummy_bottom = fip->frame - 4 - REGISTER_BYTES - CALL_DUMMY_LENGTH; |
c5aa993b | 689 | |
fc338970 | 690 | /* Check if the PC points in the stack, in a dummy frame. */ |
c5aa993b | 691 | if (dummy_bottom <= fip->pc && fip->pc <= fip->frame) |
c906108c | 692 | { |
fc338970 MK |
693 | /* All registers were saved by push_call_dummy. */ |
694 | addr = fip->frame; | |
c5aa993b | 695 | for (i = 0; i < NUM_REGS; i++) |
c906108c | 696 | { |
fc338970 MK |
697 | addr -= REGISTER_RAW_SIZE (i); |
698 | fip->saved_regs[i] = addr; | |
c906108c SS |
699 | } |
700 | return; | |
701 | } | |
c5aa993b | 702 | |
c906108c SS |
703 | pc = get_pc_function_start (fip->pc); |
704 | if (pc != 0) | |
705 | locals = i386_get_frame_setup (pc); | |
c5aa993b JM |
706 | |
707 | if (locals >= 0) | |
c906108c | 708 | { |
fc338970 | 709 | addr = fip->frame - 4 - locals; |
c5aa993b | 710 | for (i = 0; i < 8; i++) |
c906108c SS |
711 | { |
712 | op = codestream_get (); | |
713 | if (op < 0x50 || op > 0x57) | |
714 | break; | |
715 | #ifdef I386_REGNO_TO_SYMMETRY | |
716 | /* Dynix uses different internal numbering. Ick. */ | |
fc338970 | 717 | fip->saved_regs[I386_REGNO_TO_SYMMETRY (op - 0x50)] = addr; |
c906108c | 718 | #else |
fc338970 | 719 | fip->saved_regs[op - 0x50] = addr; |
c906108c | 720 | #endif |
fc338970 | 721 | addr -= 4; |
c906108c SS |
722 | } |
723 | } | |
c5aa993b | 724 | |
1211c4e4 AC |
725 | fip->saved_regs[PC_REGNUM] = fip->frame + 4; |
726 | fip->saved_regs[FP_REGNUM] = fip->frame; | |
c906108c SS |
727 | } |
728 | ||
fc338970 | 729 | /* Return PC of first real instruction. */ |
c906108c | 730 | |
3a1e71e3 | 731 | static CORE_ADDR |
93924b6b | 732 | i386_skip_prologue (CORE_ADDR pc) |
c906108c SS |
733 | { |
734 | unsigned char op; | |
735 | int i; | |
c5aa993b | 736 | static unsigned char pic_pat[6] = |
fc338970 MK |
737 | { 0xe8, 0, 0, 0, 0, /* call 0x0 */ |
738 | 0x5b, /* popl %ebx */ | |
c5aa993b | 739 | }; |
c906108c | 740 | CORE_ADDR pos; |
c5aa993b | 741 | |
c906108c SS |
742 | if (i386_get_frame_setup (pc) < 0) |
743 | return (pc); | |
c5aa993b | 744 | |
fc338970 MK |
745 | /* Found valid frame setup -- codestream now points to start of push |
746 | instructions for saving registers. */ | |
c5aa993b | 747 | |
fc338970 | 748 | /* Skip over register saves. */ |
c906108c SS |
749 | for (i = 0; i < 8; i++) |
750 | { | |
751 | op = codestream_peek (); | |
fc338970 | 752 | /* Break if not `pushl' instrunction. */ |
c5aa993b | 753 | if (op < 0x50 || op > 0x57) |
c906108c SS |
754 | break; |
755 | codestream_get (); | |
756 | } | |
757 | ||
fc338970 MK |
758 | /* The native cc on SVR4 in -K PIC mode inserts the following code |
759 | to get the address of the global offset table (GOT) into register | |
760 | %ebx | |
761 | ||
762 | call 0x0 | |
763 | popl %ebx | |
764 | movl %ebx,x(%ebp) (optional) | |
765 | addl y,%ebx | |
766 | ||
c906108c SS |
767 | This code is with the rest of the prologue (at the end of the |
768 | function), so we have to skip it to get to the first real | |
769 | instruction at the start of the function. */ | |
c5aa993b | 770 | |
c906108c SS |
771 | pos = codestream_tell (); |
772 | for (i = 0; i < 6; i++) | |
773 | { | |
774 | op = codestream_get (); | |
c5aa993b | 775 | if (pic_pat[i] != op) |
c906108c SS |
776 | break; |
777 | } | |
778 | if (i == 6) | |
779 | { | |
780 | unsigned char buf[4]; | |
781 | long delta = 6; | |
782 | ||
783 | op = codestream_get (); | |
c5aa993b | 784 | if (op == 0x89) /* movl %ebx, x(%ebp) */ |
c906108c SS |
785 | { |
786 | op = codestream_get (); | |
fc338970 | 787 | if (op == 0x5d) /* One byte offset from %ebp. */ |
c906108c SS |
788 | { |
789 | delta += 3; | |
790 | codestream_read (buf, 1); | |
791 | } | |
fc338970 | 792 | else if (op == 0x9d) /* Four byte offset from %ebp. */ |
c906108c SS |
793 | { |
794 | delta += 6; | |
795 | codestream_read (buf, 4); | |
796 | } | |
fc338970 | 797 | else /* Unexpected instruction. */ |
c5aa993b JM |
798 | delta = -1; |
799 | op = codestream_get (); | |
c906108c | 800 | } |
c5aa993b JM |
801 | /* addl y,%ebx */ |
802 | if (delta > 0 && op == 0x81 && codestream_get () == 0xc3) | |
c906108c | 803 | { |
c5aa993b | 804 | pos += delta + 6; |
c906108c SS |
805 | } |
806 | } | |
807 | codestream_seek (pos); | |
c5aa993b | 808 | |
c906108c | 809 | i386_follow_jump (); |
c5aa993b | 810 | |
c906108c SS |
811 | return (codestream_tell ()); |
812 | } | |
813 | ||
93924b6b MK |
814 | /* Use the program counter to determine the contents and size of a |
815 | breakpoint instruction. Return a pointer to a string of bytes that | |
816 | encode a breakpoint instruction, store the length of the string in | |
817 | *LEN and optionally adjust *PC to point to the correct memory | |
818 | location for inserting the breakpoint. | |
819 | ||
820 | On the i386 we have a single breakpoint that fits in a single byte | |
821 | and can be inserted anywhere. */ | |
822 | ||
823 | static const unsigned char * | |
824 | i386_breakpoint_from_pc (CORE_ADDR *pc, int *len) | |
825 | { | |
826 | static unsigned char break_insn[] = { 0xcc }; /* int 3 */ | |
827 | ||
828 | *len = sizeof (break_insn); | |
829 | return break_insn; | |
830 | } | |
831 | ||
3a1e71e3 | 832 | static void |
fba45db2 | 833 | i386_push_dummy_frame (void) |
c906108c SS |
834 | { |
835 | CORE_ADDR sp = read_register (SP_REGNUM); | |
ec80a8ea | 836 | CORE_ADDR fp; |
c906108c SS |
837 | int regnum; |
838 | char regbuf[MAX_REGISTER_RAW_SIZE]; | |
c5aa993b | 839 | |
c906108c SS |
840 | sp = push_word (sp, read_register (PC_REGNUM)); |
841 | sp = push_word (sp, read_register (FP_REGNUM)); | |
ec80a8ea | 842 | fp = sp; |
c906108c SS |
843 | for (regnum = 0; regnum < NUM_REGS; regnum++) |
844 | { | |
845 | read_register_gen (regnum, regbuf); | |
846 | sp = push_bytes (sp, regbuf, REGISTER_RAW_SIZE (regnum)); | |
847 | } | |
848 | write_register (SP_REGNUM, sp); | |
ec80a8ea | 849 | write_register (FP_REGNUM, fp); |
c906108c SS |
850 | } |
851 | ||
8758dec1 MK |
852 | /* The i386 call dummy sequence: |
853 | ||
854 | call 11223344 (32-bit relative) | |
855 | int 3 | |
856 | ||
857 | It is 8 bytes long. */ | |
858 | ||
859 | static LONGEST i386_call_dummy_words[] = | |
860 | { | |
861 | 0x223344e8, | |
862 | 0xcc11 | |
863 | }; | |
864 | ||
a7769679 MK |
865 | /* Insert the (relative) function address into the call sequence |
866 | stored at DYMMY. */ | |
867 | ||
3a1e71e3 | 868 | static void |
a7769679 | 869 | i386_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, |
ea7c478f | 870 | struct value **args, struct type *type, int gcc_p) |
a7769679 MK |
871 | { |
872 | int from, to, delta, loc; | |
873 | ||
874 | loc = (int)(read_register (SP_REGNUM) - CALL_DUMMY_LENGTH); | |
875 | from = loc + 5; | |
876 | to = (int)(fun); | |
877 | delta = to - from; | |
878 | ||
879 | *((char *)(dummy) + 1) = (delta & 0xff); | |
880 | *((char *)(dummy) + 2) = ((delta >> 8) & 0xff); | |
881 | *((char *)(dummy) + 3) = ((delta >> 16) & 0xff); | |
882 | *((char *)(dummy) + 4) = ((delta >> 24) & 0xff); | |
883 | } | |
884 | ||
3a1e71e3 | 885 | static void |
fba45db2 | 886 | i386_pop_frame (void) |
c906108c SS |
887 | { |
888 | struct frame_info *frame = get_current_frame (); | |
889 | CORE_ADDR fp; | |
890 | int regnum; | |
c906108c | 891 | char regbuf[MAX_REGISTER_RAW_SIZE]; |
c5aa993b | 892 | |
c906108c | 893 | fp = FRAME_FP (frame); |
1211c4e4 AC |
894 | i386_frame_init_saved_regs (frame); |
895 | ||
c5aa993b | 896 | for (regnum = 0; regnum < NUM_REGS; regnum++) |
c906108c | 897 | { |
fc338970 MK |
898 | CORE_ADDR addr; |
899 | addr = frame->saved_regs[regnum]; | |
900 | if (addr) | |
c906108c | 901 | { |
fc338970 | 902 | read_memory (addr, regbuf, REGISTER_RAW_SIZE (regnum)); |
c906108c SS |
903 | write_register_bytes (REGISTER_BYTE (regnum), regbuf, |
904 | REGISTER_RAW_SIZE (regnum)); | |
905 | } | |
906 | } | |
907 | write_register (FP_REGNUM, read_memory_integer (fp, 4)); | |
908 | write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); | |
909 | write_register (SP_REGNUM, fp + 8); | |
910 | flush_cached_frames (); | |
911 | } | |
fc338970 | 912 | \f |
c906108c | 913 | |
fc338970 MK |
914 | /* Figure out where the longjmp will land. Slurp the args out of the |
915 | stack. We expect the first arg to be a pointer to the jmp_buf | |
8201327c MK |
916 | structure from which we extract the address that we will land at. |
917 | This address is copied into PC. This routine returns true on | |
fc338970 | 918 | success. */ |
c906108c | 919 | |
8201327c MK |
920 | static int |
921 | i386_get_longjmp_target (CORE_ADDR *pc) | |
c906108c | 922 | { |
8201327c | 923 | char buf[4]; |
c906108c | 924 | CORE_ADDR sp, jb_addr; |
8201327c | 925 | int jb_pc_offset = gdbarch_tdep (current_gdbarch)->jb_pc_offset; |
c906108c | 926 | |
8201327c MK |
927 | /* If JB_PC_OFFSET is -1, we have no way to find out where the |
928 | longjmp will land. */ | |
929 | if (jb_pc_offset == -1) | |
c906108c SS |
930 | return 0; |
931 | ||
8201327c MK |
932 | sp = read_register (SP_REGNUM); |
933 | if (target_read_memory (sp + 4, buf, 4)) | |
c906108c SS |
934 | return 0; |
935 | ||
8201327c MK |
936 | jb_addr = extract_address (buf, 4); |
937 | if (target_read_memory (jb_addr + jb_pc_offset, buf, 4)) | |
938 | return 0; | |
c906108c | 939 | |
8201327c | 940 | *pc = extract_address (buf, 4); |
c906108c SS |
941 | return 1; |
942 | } | |
fc338970 | 943 | \f |
c906108c | 944 | |
3a1e71e3 | 945 | static CORE_ADDR |
ea7c478f | 946 | i386_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
22f8ba57 MK |
947 | int struct_return, CORE_ADDR struct_addr) |
948 | { | |
949 | sp = default_push_arguments (nargs, args, sp, struct_return, struct_addr); | |
950 | ||
951 | if (struct_return) | |
952 | { | |
953 | char buf[4]; | |
954 | ||
955 | sp -= 4; | |
956 | store_address (buf, 4, struct_addr); | |
957 | write_memory (sp, buf, 4); | |
958 | } | |
959 | ||
960 | return sp; | |
961 | } | |
962 | ||
3a1e71e3 | 963 | static void |
22f8ba57 MK |
964 | i386_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
965 | { | |
966 | /* Do nothing. Everything was already done by i386_push_arguments. */ | |
967 | } | |
968 | ||
1a309862 MK |
969 | /* These registers are used for returning integers (and on some |
970 | targets also for returning `struct' and `union' values when their | |
ef9dff19 | 971 | size and alignment match an integer type). */ |
1a309862 MK |
972 | #define LOW_RETURN_REGNUM 0 /* %eax */ |
973 | #define HIGH_RETURN_REGNUM 2 /* %edx */ | |
974 | ||
975 | /* Extract from an array REGBUF containing the (raw) register state, a | |
976 | function return value of TYPE, and copy that, in virtual format, | |
977 | into VALBUF. */ | |
978 | ||
3a1e71e3 | 979 | static void |
1a309862 | 980 | i386_extract_return_value (struct type *type, char *regbuf, char *valbuf) |
c906108c | 981 | { |
1a309862 MK |
982 | int len = TYPE_LENGTH (type); |
983 | ||
1e8d0a7b MK |
984 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
985 | && TYPE_NFIELDS (type) == 1) | |
3df1b9b4 MK |
986 | { |
987 | i386_extract_return_value (TYPE_FIELD_TYPE (type, 0), regbuf, valbuf); | |
988 | return; | |
989 | } | |
1e8d0a7b MK |
990 | |
991 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
c906108c | 992 | { |
356a6b3e | 993 | if (FP0_REGNUM == 0) |
1a309862 MK |
994 | { |
995 | warning ("Cannot find floating-point return value."); | |
996 | memset (valbuf, 0, len); | |
ef9dff19 | 997 | return; |
1a309862 MK |
998 | } |
999 | ||
c6ba6f0d MK |
1000 | /* Floating-point return values can be found in %st(0). Convert |
1001 | its contents to the desired type. This is probably not | |
1002 | exactly how it would happen on the target itself, but it is | |
1003 | the best we can do. */ | |
1004 | convert_typed_floating (®buf[REGISTER_BYTE (FP0_REGNUM)], | |
1005 | builtin_type_i387_ext, valbuf, type); | |
c906108c SS |
1006 | } |
1007 | else | |
c5aa993b | 1008 | { |
d4f3574e SS |
1009 | int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM); |
1010 | int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM); | |
1011 | ||
1012 | if (len <= low_size) | |
1a309862 | 1013 | memcpy (valbuf, ®buf[REGISTER_BYTE (LOW_RETURN_REGNUM)], len); |
d4f3574e SS |
1014 | else if (len <= (low_size + high_size)) |
1015 | { | |
1016 | memcpy (valbuf, | |
1a309862 | 1017 | ®buf[REGISTER_BYTE (LOW_RETURN_REGNUM)], low_size); |
d4f3574e | 1018 | memcpy (valbuf + low_size, |
1a309862 | 1019 | ®buf[REGISTER_BYTE (HIGH_RETURN_REGNUM)], len - low_size); |
d4f3574e SS |
1020 | } |
1021 | else | |
8e65ff28 AC |
1022 | internal_error (__FILE__, __LINE__, |
1023 | "Cannot extract return value of %d bytes long.", len); | |
c906108c SS |
1024 | } |
1025 | } | |
1026 | ||
ef9dff19 MK |
1027 | /* Write into the appropriate registers a function return value stored |
1028 | in VALBUF of type TYPE, given in virtual format. */ | |
1029 | ||
3a1e71e3 | 1030 | static void |
ef9dff19 MK |
1031 | i386_store_return_value (struct type *type, char *valbuf) |
1032 | { | |
1033 | int len = TYPE_LENGTH (type); | |
1034 | ||
1e8d0a7b MK |
1035 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1036 | && TYPE_NFIELDS (type) == 1) | |
3df1b9b4 MK |
1037 | { |
1038 | i386_store_return_value (TYPE_FIELD_TYPE (type, 0), valbuf); | |
1039 | return; | |
1040 | } | |
1e8d0a7b MK |
1041 | |
1042 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
ef9dff19 | 1043 | { |
ccb945b8 | 1044 | unsigned int fstat; |
c6ba6f0d | 1045 | char buf[FPU_REG_RAW_SIZE]; |
ccb945b8 | 1046 | |
356a6b3e | 1047 | if (FP0_REGNUM == 0) |
ef9dff19 MK |
1048 | { |
1049 | warning ("Cannot set floating-point return value."); | |
1050 | return; | |
1051 | } | |
1052 | ||
635b0cc1 MK |
1053 | /* Returning floating-point values is a bit tricky. Apart from |
1054 | storing the return value in %st(0), we have to simulate the | |
1055 | state of the FPU at function return point. */ | |
1056 | ||
c6ba6f0d MK |
1057 | /* Convert the value found in VALBUF to the extended |
1058 | floating-point format used by the FPU. This is probably | |
1059 | not exactly how it would happen on the target itself, but | |
1060 | it is the best we can do. */ | |
1061 | convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext); | |
1062 | write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf, | |
1063 | FPU_REG_RAW_SIZE); | |
ccb945b8 | 1064 | |
635b0cc1 MK |
1065 | /* Set the top of the floating-point register stack to 7. The |
1066 | actual value doesn't really matter, but 7 is what a normal | |
1067 | function return would end up with if the program started out | |
1068 | with a freshly initialized FPU. */ | |
ccb945b8 MK |
1069 | fstat = read_register (FSTAT_REGNUM); |
1070 | fstat |= (7 << 11); | |
1071 | write_register (FSTAT_REGNUM, fstat); | |
1072 | ||
635b0cc1 MK |
1073 | /* Mark %st(1) through %st(7) as empty. Since we set the top of |
1074 | the floating-point register stack to 7, the appropriate value | |
1075 | for the tag word is 0x3fff. */ | |
ccb945b8 | 1076 | write_register (FTAG_REGNUM, 0x3fff); |
ef9dff19 MK |
1077 | } |
1078 | else | |
1079 | { | |
1080 | int low_size = REGISTER_RAW_SIZE (LOW_RETURN_REGNUM); | |
1081 | int high_size = REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM); | |
1082 | ||
1083 | if (len <= low_size) | |
1084 | write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM), valbuf, len); | |
1085 | else if (len <= (low_size + high_size)) | |
1086 | { | |
1087 | write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM), | |
1088 | valbuf, low_size); | |
1089 | write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM), | |
1090 | valbuf + low_size, len - low_size); | |
1091 | } | |
1092 | else | |
8e65ff28 AC |
1093 | internal_error (__FILE__, __LINE__, |
1094 | "Cannot store return value of %d bytes long.", len); | |
ef9dff19 MK |
1095 | } |
1096 | } | |
f7af9647 MK |
1097 | |
1098 | /* Extract from an array REGBUF containing the (raw) register state | |
1099 | the address in which a function should return its structure value, | |
1100 | as a CORE_ADDR. */ | |
1101 | ||
3a1e71e3 | 1102 | static CORE_ADDR |
f7af9647 MK |
1103 | i386_extract_struct_value_address (char *regbuf) |
1104 | { | |
1105 | return extract_address (®buf[REGISTER_BYTE (LOW_RETURN_REGNUM)], | |
1106 | REGISTER_RAW_SIZE (LOW_RETURN_REGNUM)); | |
1107 | } | |
fc338970 | 1108 | \f |
ef9dff19 | 1109 | |
8201327c MK |
1110 | /* This is the variable that is set with "set struct-convention", and |
1111 | its legitimate values. */ | |
1112 | static const char default_struct_convention[] = "default"; | |
1113 | static const char pcc_struct_convention[] = "pcc"; | |
1114 | static const char reg_struct_convention[] = "reg"; | |
1115 | static const char *valid_conventions[] = | |
1116 | { | |
1117 | default_struct_convention, | |
1118 | pcc_struct_convention, | |
1119 | reg_struct_convention, | |
1120 | NULL | |
1121 | }; | |
1122 | static const char *struct_convention = default_struct_convention; | |
1123 | ||
1124 | static int | |
1125 | i386_use_struct_convention (int gcc_p, struct type *type) | |
1126 | { | |
1127 | enum struct_return struct_return; | |
1128 | ||
1129 | if (struct_convention == default_struct_convention) | |
1130 | struct_return = gdbarch_tdep (current_gdbarch)->struct_return; | |
1131 | else if (struct_convention == pcc_struct_convention) | |
1132 | struct_return = pcc_struct_return; | |
1133 | else | |
1134 | struct_return = reg_struct_return; | |
1135 | ||
1136 | return generic_use_struct_convention (struct_return == reg_struct_return, | |
1137 | type); | |
1138 | } | |
1139 | \f | |
1140 | ||
d7a0d72c MK |
1141 | /* Return the GDB type object for the "standard" data type of data in |
1142 | register REGNUM. Perhaps %esi and %edi should go here, but | |
1143 | potentially they could be used for things other than address. */ | |
1144 | ||
3a1e71e3 | 1145 | static struct type * |
d7a0d72c MK |
1146 | i386_register_virtual_type (int regnum) |
1147 | { | |
1148 | if (regnum == PC_REGNUM || regnum == FP_REGNUM || regnum == SP_REGNUM) | |
1149 | return lookup_pointer_type (builtin_type_void); | |
1150 | ||
1151 | if (IS_FP_REGNUM (regnum)) | |
c6ba6f0d | 1152 | return builtin_type_i387_ext; |
d7a0d72c MK |
1153 | |
1154 | if (IS_SSE_REGNUM (regnum)) | |
3139facc | 1155 | return builtin_type_vec128i; |
d7a0d72c MK |
1156 | |
1157 | return builtin_type_int; | |
1158 | } | |
1159 | ||
1160 | /* Return true iff register REGNUM's virtual format is different from | |
1161 | its raw format. Note that this definition assumes that the host | |
1162 | supports IEEE 32-bit floats, since it doesn't say that SSE | |
1163 | registers need conversion. Even if we can't find a counterexample, | |
1164 | this is still sloppy. */ | |
1165 | ||
3a1e71e3 | 1166 | static int |
d7a0d72c MK |
1167 | i386_register_convertible (int regnum) |
1168 | { | |
1169 | return IS_FP_REGNUM (regnum); | |
1170 | } | |
1171 | ||
ac27f131 | 1172 | /* Convert data from raw format for register REGNUM in buffer FROM to |
3d261580 | 1173 | virtual format with type TYPE in buffer TO. */ |
ac27f131 | 1174 | |
3a1e71e3 | 1175 | static void |
ac27f131 MK |
1176 | i386_register_convert_to_virtual (int regnum, struct type *type, |
1177 | char *from, char *to) | |
1178 | { | |
c6ba6f0d | 1179 | gdb_assert (IS_FP_REGNUM (regnum)); |
3d261580 MK |
1180 | |
1181 | /* We only support floating-point values. */ | |
8d7f6b4a MK |
1182 | if (TYPE_CODE (type) != TYPE_CODE_FLT) |
1183 | { | |
1184 | warning ("Cannot convert floating-point register value " | |
1185 | "to non-floating-point type."); | |
1186 | memset (to, 0, TYPE_LENGTH (type)); | |
1187 | return; | |
1188 | } | |
3d261580 | 1189 | |
c6ba6f0d MK |
1190 | /* Convert to TYPE. This should be a no-op if TYPE is equivalent to |
1191 | the extended floating-point format used by the FPU. */ | |
1192 | convert_typed_floating (from, builtin_type_i387_ext, to, type); | |
ac27f131 MK |
1193 | } |
1194 | ||
1195 | /* Convert data from virtual format with type TYPE in buffer FROM to | |
3d261580 | 1196 | raw format for register REGNUM in buffer TO. */ |
ac27f131 | 1197 | |
3a1e71e3 | 1198 | static void |
ac27f131 MK |
1199 | i386_register_convert_to_raw (struct type *type, int regnum, |
1200 | char *from, char *to) | |
1201 | { | |
c6ba6f0d MK |
1202 | gdb_assert (IS_FP_REGNUM (regnum)); |
1203 | ||
1204 | /* We only support floating-point values. */ | |
1205 | if (TYPE_CODE (type) != TYPE_CODE_FLT) | |
1206 | { | |
1207 | warning ("Cannot convert non-floating-point type " | |
1208 | "to floating-point register value."); | |
1209 | memset (to, 0, TYPE_LENGTH (type)); | |
1210 | return; | |
1211 | } | |
3d261580 | 1212 | |
c6ba6f0d MK |
1213 | /* Convert from TYPE. This should be a no-op if TYPE is equivalent |
1214 | to the extended floating-point format used by the FPU. */ | |
1215 | convert_typed_floating (from, type, to, builtin_type_i387_ext); | |
ac27f131 | 1216 | } |
ac27f131 | 1217 | \f |
fc338970 | 1218 | |
c906108c | 1219 | #ifdef STATIC_TRANSFORM_NAME |
fc338970 MK |
1220 | /* SunPRO encodes the static variables. This is not related to C++ |
1221 | mangling, it is done for C too. */ | |
c906108c SS |
1222 | |
1223 | char * | |
fba45db2 | 1224 | sunpro_static_transform_name (char *name) |
c906108c SS |
1225 | { |
1226 | char *p; | |
1227 | if (IS_STATIC_TRANSFORM_NAME (name)) | |
1228 | { | |
fc338970 MK |
1229 | /* For file-local statics there will be a period, a bunch of |
1230 | junk (the contents of which match a string given in the | |
c5aa993b JM |
1231 | N_OPT), a period and the name. For function-local statics |
1232 | there will be a bunch of junk (which seems to change the | |
1233 | second character from 'A' to 'B'), a period, the name of the | |
1234 | function, and the name. So just skip everything before the | |
1235 | last period. */ | |
c906108c SS |
1236 | p = strrchr (name, '.'); |
1237 | if (p != NULL) | |
1238 | name = p + 1; | |
1239 | } | |
1240 | return name; | |
1241 | } | |
1242 | #endif /* STATIC_TRANSFORM_NAME */ | |
fc338970 | 1243 | \f |
c906108c | 1244 | |
fc338970 | 1245 | /* Stuff for WIN32 PE style DLL's but is pretty generic really. */ |
c906108c SS |
1246 | |
1247 | CORE_ADDR | |
fba45db2 | 1248 | skip_trampoline_code (CORE_ADDR pc, char *name) |
c906108c | 1249 | { |
fc338970 | 1250 | if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */ |
c906108c | 1251 | { |
c5aa993b | 1252 | unsigned long indirect = read_memory_unsigned_integer (pc + 2, 4); |
c906108c | 1253 | struct minimal_symbol *indsym = |
fc338970 | 1254 | indirect ? lookup_minimal_symbol_by_pc (indirect) : 0; |
c5aa993b | 1255 | char *symname = indsym ? SYMBOL_NAME (indsym) : 0; |
c906108c | 1256 | |
c5aa993b | 1257 | if (symname) |
c906108c | 1258 | { |
c5aa993b JM |
1259 | if (strncmp (symname, "__imp_", 6) == 0 |
1260 | || strncmp (symname, "_imp_", 5) == 0) | |
c906108c SS |
1261 | return name ? 1 : read_memory_unsigned_integer (indirect, 4); |
1262 | } | |
1263 | } | |
fc338970 | 1264 | return 0; /* Not a trampoline. */ |
c906108c | 1265 | } |
fc338970 MK |
1266 | \f |
1267 | ||
8201327c MK |
1268 | /* Return non-zero if PC and NAME show that we are in a signal |
1269 | trampoline. */ | |
1270 | ||
1271 | static int | |
1272 | i386_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
1273 | { | |
1274 | return (name && strcmp ("_sigtramp", name) == 0); | |
1275 | } | |
1276 | \f | |
1277 | ||
fc338970 MK |
1278 | /* We have two flavours of disassembly. The machinery on this page |
1279 | deals with switching between those. */ | |
c906108c SS |
1280 | |
1281 | static int | |
fba45db2 | 1282 | gdb_print_insn_i386 (bfd_vma memaddr, disassemble_info *info) |
c906108c SS |
1283 | { |
1284 | if (disassembly_flavor == att_flavor) | |
1285 | return print_insn_i386_att (memaddr, info); | |
1286 | else if (disassembly_flavor == intel_flavor) | |
1287 | return print_insn_i386_intel (memaddr, info); | |
fc338970 MK |
1288 | /* Never reached -- disassembly_flavour is always either att_flavor |
1289 | or intel_flavor. */ | |
e1e9e218 | 1290 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
7a292a7a | 1291 | } |
fc338970 | 1292 | \f |
3ce1502b | 1293 | |
8201327c MK |
1294 | /* There are a few i386 architecture variants that differ only |
1295 | slightly from the generic i386 target. For now, we don't give them | |
1296 | their own source file, but include them here. As a consequence, | |
1297 | they'll always be included. */ | |
3ce1502b | 1298 | |
8201327c | 1299 | /* System V Release 4 (SVR4). */ |
3ce1502b | 1300 | |
8201327c MK |
1301 | static int |
1302 | i386_svr4_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
d2a7c97a | 1303 | { |
8201327c MK |
1304 | return (name && (strcmp ("_sigreturn", name) == 0 |
1305 | || strcmp ("_sigacthandler", name) == 0 | |
1306 | || strcmp ("sigvechandler", name) == 0)); | |
1307 | } | |
d2a7c97a | 1308 | |
21d0e8a4 MK |
1309 | /* Get address of the pushed ucontext (sigcontext) on the stack for |
1310 | all three variants of SVR4 sigtramps. */ | |
3ce1502b | 1311 | |
3a1e71e3 | 1312 | static CORE_ADDR |
21d0e8a4 | 1313 | i386_svr4_sigcontext_addr (struct frame_info *frame) |
8201327c | 1314 | { |
21d0e8a4 | 1315 | int sigcontext_offset = -1; |
8201327c MK |
1316 | char *name = NULL; |
1317 | ||
1318 | find_pc_partial_function (frame->pc, &name, NULL, NULL); | |
1319 | if (name) | |
d2a7c97a | 1320 | { |
8201327c | 1321 | if (strcmp (name, "_sigreturn") == 0) |
21d0e8a4 | 1322 | sigcontext_offset = 132; |
8201327c | 1323 | else if (strcmp (name, "_sigacthandler") == 0) |
21d0e8a4 | 1324 | sigcontext_offset = 80; |
8201327c | 1325 | else if (strcmp (name, "sigvechandler") == 0) |
21d0e8a4 | 1326 | sigcontext_offset = 120; |
8201327c | 1327 | } |
3ce1502b | 1328 | |
21d0e8a4 MK |
1329 | gdb_assert (sigcontext_offset != -1); |
1330 | ||
8201327c | 1331 | if (frame->next) |
21d0e8a4 MK |
1332 | return frame->next->frame + sigcontext_offset; |
1333 | return read_register (SP_REGNUM) + sigcontext_offset; | |
8201327c MK |
1334 | } |
1335 | \f | |
3ce1502b | 1336 | |
8201327c | 1337 | /* DJGPP. */ |
d2a7c97a | 1338 | |
8201327c MK |
1339 | static int |
1340 | i386_go32_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
1341 | { | |
1342 | /* DJGPP doesn't have any special frames for signal handlers. */ | |
1343 | return 0; | |
1344 | } | |
1345 | \f | |
d2a7c97a | 1346 | |
8201327c | 1347 | /* Generic ELF. */ |
d2a7c97a | 1348 | |
8201327c MK |
1349 | void |
1350 | i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1351 | { | |
1352 | /* We typically use stabs-in-ELF with the DWARF register numbering. */ | |
1353 | set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1354 | } | |
3ce1502b | 1355 | |
8201327c | 1356 | /* System V Release 4 (SVR4). */ |
3ce1502b | 1357 | |
8201327c MK |
1358 | void |
1359 | i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1360 | { | |
1361 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
3ce1502b | 1362 | |
8201327c MK |
1363 | /* System V Release 4 uses ELF. */ |
1364 | i386_elf_init_abi (info, gdbarch); | |
3ce1502b | 1365 | |
8201327c MK |
1366 | /* FIXME: kettenis/20020511: Why do we override this function here? */ |
1367 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); | |
3ce1502b | 1368 | |
8201327c | 1369 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_svr4_pc_in_sigtramp); |
21d0e8a4 MK |
1370 | tdep->sigcontext_addr = i386_svr4_sigcontext_addr; |
1371 | tdep->sc_pc_offset = 14 * 4; | |
1372 | tdep->sc_sp_offset = 7 * 4; | |
3ce1502b | 1373 | |
8201327c | 1374 | tdep->jb_pc_offset = 20; |
3ce1502b MK |
1375 | } |
1376 | ||
8201327c | 1377 | /* DJGPP. */ |
3ce1502b | 1378 | |
3a1e71e3 | 1379 | static void |
8201327c | 1380 | i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
3ce1502b | 1381 | { |
8201327c | 1382 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
3ce1502b | 1383 | |
8201327c | 1384 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_go32_pc_in_sigtramp); |
3ce1502b | 1385 | |
8201327c | 1386 | tdep->jb_pc_offset = 36; |
3ce1502b MK |
1387 | } |
1388 | ||
8201327c | 1389 | /* NetWare. */ |
3ce1502b | 1390 | |
3a1e71e3 | 1391 | static void |
8201327c | 1392 | i386_nw_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
3ce1502b | 1393 | { |
8201327c | 1394 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
3ce1502b | 1395 | |
8201327c MK |
1396 | /* FIXME: kettenis/20020511: Why do we override this function here? */ |
1397 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); | |
1398 | ||
1399 | tdep->jb_pc_offset = 24; | |
d2a7c97a | 1400 | } |
8201327c | 1401 | \f |
2acceee2 | 1402 | |
3a1e71e3 | 1403 | static struct gdbarch * |
a62cc96e AC |
1404 | i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
1405 | { | |
cd3c07fc | 1406 | struct gdbarch_tdep *tdep; |
a62cc96e | 1407 | struct gdbarch *gdbarch; |
8201327c | 1408 | enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; |
a62cc96e | 1409 | |
8201327c | 1410 | /* Try to determine the OS ABI of the object we're loading. */ |
3ce1502b | 1411 | if (info.abfd != NULL) |
8201327c | 1412 | osabi = gdbarch_lookup_osabi (info.abfd); |
d2a7c97a | 1413 | |
3ce1502b | 1414 | /* Find a candidate among extant architectures. */ |
d2a7c97a MK |
1415 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
1416 | arches != NULL; | |
1417 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
1418 | { | |
8201327c | 1419 | /* Make sure the OS ABI selection matches. */ |
65d6d66a | 1420 | tdep = gdbarch_tdep (arches->gdbarch); |
8201327c | 1421 | if (tdep && tdep->osabi == osabi) |
65d6d66a | 1422 | return arches->gdbarch; |
d2a7c97a | 1423 | } |
a62cc96e AC |
1424 | |
1425 | /* Allocate space for the new architecture. */ | |
1426 | tdep = XMALLOC (struct gdbarch_tdep); | |
1427 | gdbarch = gdbarch_alloc (&info, tdep); | |
1428 | ||
8201327c MK |
1429 | tdep->osabi = osabi; |
1430 | ||
1431 | /* The i386 default settings don't include the SSE registers. | |
356a6b3e MK |
1432 | FIXME: kettenis/20020614: They do include the FPU registers for |
1433 | now, which probably is not quite right. */ | |
8201327c | 1434 | tdep->num_xmm_regs = 0; |
d2a7c97a | 1435 | |
8201327c MK |
1436 | tdep->jb_pc_offset = -1; |
1437 | tdep->struct_return = pcc_struct_return; | |
8201327c MK |
1438 | tdep->sigtramp_start = 0; |
1439 | tdep->sigtramp_end = 0; | |
21d0e8a4 | 1440 | tdep->sigcontext_addr = NULL; |
8201327c | 1441 | tdep->sc_pc_offset = -1; |
21d0e8a4 | 1442 | tdep->sc_sp_offset = -1; |
8201327c | 1443 | |
896fb97d MK |
1444 | /* The format used for `long double' on almost all i386 targets is |
1445 | the i387 extended floating-point format. In fact, of all targets | |
1446 | in the GCC 2.95 tree, only OSF/1 does it different, and insists | |
1447 | on having a `long double' that's not `long' at all. */ | |
1448 | set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext); | |
21d0e8a4 | 1449 | |
896fb97d MK |
1450 | /* Although the i386 extended floating-point has only 80 significant |
1451 | bits, a `long double' actually takes up 96, probably to enforce | |
1452 | alignment. */ | |
1453 | set_gdbarch_long_double_bit (gdbarch, 96); | |
1454 | ||
356a6b3e MK |
1455 | /* NOTE: tm-i386aix.h, tm-i386bsd.h, tm-i386os9k.h, tm-ptx.h, |
1456 | tm-symmetry.h currently override this. Sigh. */ | |
1457 | set_gdbarch_num_regs (gdbarch, I386_NUM_GREGS + I386_NUM_FREGS); | |
21d0e8a4 | 1458 | |
356a6b3e MK |
1459 | set_gdbarch_sp_regnum (gdbarch, 4); |
1460 | set_gdbarch_fp_regnum (gdbarch, 5); | |
1461 | set_gdbarch_pc_regnum (gdbarch, 8); | |
1462 | set_gdbarch_ps_regnum (gdbarch, 9); | |
1463 | set_gdbarch_fp0_regnum (gdbarch, 16); | |
1464 | ||
1465 | /* Use the "default" register numbering scheme for stabs and COFF. */ | |
1466 | set_gdbarch_stab_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum); | |
1467 | set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum); | |
1468 | ||
1469 | /* Use the DWARF register numbering scheme for DWARF and DWARF 2. */ | |
1470 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1471 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1472 | ||
1473 | /* We don't define ECOFF_REG_TO_REGNUM, since ECOFF doesn't seem to | |
1474 | be in use on any of the supported i386 targets. */ | |
1475 | ||
1476 | set_gdbarch_register_name (gdbarch, i386_register_name); | |
1477 | set_gdbarch_register_size (gdbarch, 4); | |
1478 | set_gdbarch_register_bytes (gdbarch, I386_SIZEOF_GREGS + I386_SIZEOF_FREGS); | |
1479 | set_gdbarch_register_byte (gdbarch, i386_register_byte); | |
1480 | set_gdbarch_register_raw_size (gdbarch, i386_register_raw_size); | |
1481 | set_gdbarch_max_register_raw_size (gdbarch, 16); | |
1482 | set_gdbarch_max_register_virtual_size (gdbarch, 16); | |
b6197528 | 1483 | set_gdbarch_register_virtual_type (gdbarch, i386_register_virtual_type); |
356a6b3e | 1484 | |
8201327c | 1485 | set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target); |
96297dab | 1486 | |
a62cc96e AC |
1487 | set_gdbarch_use_generic_dummy_frames (gdbarch, 0); |
1488 | ||
1489 | /* Call dummy code. */ | |
1490 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); | |
8758dec1 | 1491 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); |
a62cc96e AC |
1492 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 5); |
1493 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
8758dec1 | 1494 | set_gdbarch_call_dummy_length (gdbarch, 8); |
a62cc96e | 1495 | set_gdbarch_call_dummy_p (gdbarch, 1); |
8758dec1 MK |
1496 | set_gdbarch_call_dummy_words (gdbarch, i386_call_dummy_words); |
1497 | set_gdbarch_sizeof_call_dummy_words (gdbarch, | |
1498 | sizeof (i386_call_dummy_words)); | |
a62cc96e | 1499 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); |
8758dec1 | 1500 | set_gdbarch_fix_call_dummy (gdbarch, i386_fix_call_dummy); |
a62cc96e | 1501 | |
b6197528 MK |
1502 | set_gdbarch_register_convertible (gdbarch, i386_register_convertible); |
1503 | set_gdbarch_register_convert_to_virtual (gdbarch, | |
1504 | i386_register_convert_to_virtual); | |
1505 | set_gdbarch_register_convert_to_raw (gdbarch, i386_register_convert_to_raw); | |
1506 | ||
a62cc96e AC |
1507 | set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); |
1508 | set_gdbarch_push_arguments (gdbarch, i386_push_arguments); | |
1509 | ||
1510 | set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_on_stack); | |
1511 | ||
8758dec1 MK |
1512 | /* "An argument's size is increased, if necessary, to make it a |
1513 | multiple of [32-bit] words. This may require tail padding, | |
1514 | depending on the size of the argument" -- from the x86 ABI. */ | |
1515 | set_gdbarch_parm_boundary (gdbarch, 32); | |
1516 | ||
fc08ec52 MK |
1517 | set_gdbarch_deprecated_extract_return_value (gdbarch, |
1518 | i386_extract_return_value); | |
1519 | set_gdbarch_push_arguments (gdbarch, i386_push_arguments); | |
1520 | set_gdbarch_push_dummy_frame (gdbarch, i386_push_dummy_frame); | |
1521 | set_gdbarch_pop_frame (gdbarch, i386_pop_frame); | |
1522 | set_gdbarch_store_struct_return (gdbarch, i386_store_struct_return); | |
1523 | set_gdbarch_store_return_value (gdbarch, i386_store_return_value); | |
1524 | set_gdbarch_deprecated_extract_struct_value_address (gdbarch, | |
1525 | i386_extract_struct_value_address); | |
8201327c MK |
1526 | set_gdbarch_use_struct_convention (gdbarch, i386_use_struct_convention); |
1527 | ||
42fdc8df | 1528 | set_gdbarch_frame_init_saved_regs (gdbarch, i386_frame_init_saved_regs); |
93924b6b MK |
1529 | set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue); |
1530 | ||
1531 | /* Stack grows downward. */ | |
1532 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1533 | ||
1534 | set_gdbarch_breakpoint_from_pc (gdbarch, i386_breakpoint_from_pc); | |
1535 | set_gdbarch_decr_pc_after_break (gdbarch, 1); | |
1536 | set_gdbarch_function_start_offset (gdbarch, 0); | |
42fdc8df | 1537 | |
8201327c MK |
1538 | /* The following redefines make backtracing through sigtramp work. |
1539 | They manufacture a fake sigtramp frame and obtain the saved pc in | |
1540 | sigtramp from the sigcontext structure which is pushed by the | |
1541 | kernel on the user stack, along with a pointer to it. */ | |
1542 | ||
42fdc8df MK |
1543 | set_gdbarch_frame_args_skip (gdbarch, 8); |
1544 | set_gdbarch_frameless_function_invocation (gdbarch, | |
1545 | i386_frameless_function_invocation); | |
8201327c | 1546 | set_gdbarch_frame_chain (gdbarch, i386_frame_chain); |
a62cc96e | 1547 | set_gdbarch_frame_chain_valid (gdbarch, file_frame_chain_valid); |
8201327c | 1548 | set_gdbarch_frame_saved_pc (gdbarch, i386_frame_saved_pc); |
42fdc8df MK |
1549 | set_gdbarch_frame_args_address (gdbarch, default_frame_address); |
1550 | set_gdbarch_frame_locals_address (gdbarch, default_frame_address); | |
8201327c | 1551 | set_gdbarch_saved_pc_after_call (gdbarch, i386_saved_pc_after_call); |
42fdc8df | 1552 | set_gdbarch_frame_num_args (gdbarch, i386_frame_num_args); |
8201327c MK |
1553 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_pc_in_sigtramp); |
1554 | ||
3ce1502b | 1555 | /* Hook in ABI-specific overrides, if they have been registered. */ |
8201327c | 1556 | gdbarch_init_osabi (info, gdbarch, osabi); |
3ce1502b | 1557 | |
a62cc96e AC |
1558 | return gdbarch; |
1559 | } | |
1560 | ||
8201327c MK |
1561 | static enum gdb_osabi |
1562 | i386_coff_osabi_sniffer (bfd *abfd) | |
1563 | { | |
762c5349 MK |
1564 | if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0 |
1565 | || strcmp (bfd_get_target (abfd), "coff-go32") == 0) | |
8201327c MK |
1566 | return GDB_OSABI_GO32; |
1567 | ||
1568 | return GDB_OSABI_UNKNOWN; | |
1569 | } | |
1570 | ||
1571 | static enum gdb_osabi | |
1572 | i386_nlm_osabi_sniffer (bfd *abfd) | |
1573 | { | |
1574 | return GDB_OSABI_NETWARE; | |
1575 | } | |
1576 | \f | |
1577 | ||
28e9e0f0 MK |
1578 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
1579 | void _initialize_i386_tdep (void); | |
1580 | ||
c906108c | 1581 | void |
fba45db2 | 1582 | _initialize_i386_tdep (void) |
c906108c | 1583 | { |
a62cc96e AC |
1584 | register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init); |
1585 | ||
917317f4 JM |
1586 | /* Initialize the table saying where each register starts in the |
1587 | register file. */ | |
1588 | { | |
1589 | int i, offset; | |
1590 | ||
1591 | offset = 0; | |
1cf88de5 | 1592 | for (i = 0; i < I386_SSE_NUM_REGS; i++) |
917317f4 | 1593 | { |
1a11ba71 MK |
1594 | i386_register_offset[i] = offset; |
1595 | offset += i386_register_size[i]; | |
917317f4 JM |
1596 | } |
1597 | } | |
1598 | ||
c906108c SS |
1599 | tm_print_insn = gdb_print_insn_i386; |
1600 | tm_print_insn_info.mach = bfd_lookup_arch (bfd_arch_i386, 0)->mach; | |
1601 | ||
fc338970 | 1602 | /* Add the variable that controls the disassembly flavor. */ |
917317f4 JM |
1603 | { |
1604 | struct cmd_list_element *new_cmd; | |
7a292a7a | 1605 | |
917317f4 JM |
1606 | new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class, |
1607 | valid_flavors, | |
1ed2a135 | 1608 | &disassembly_flavor, |
fc338970 MK |
1609 | "\ |
1610 | Set the disassembly flavor, the valid values are \"att\" and \"intel\", \ | |
c906108c | 1611 | and the default value is \"att\".", |
917317f4 | 1612 | &setlist); |
917317f4 JM |
1613 | add_show_from_set (new_cmd, &showlist); |
1614 | } | |
8201327c MK |
1615 | |
1616 | /* Add the variable that controls the convention for returning | |
1617 | structs. */ | |
1618 | { | |
1619 | struct cmd_list_element *new_cmd; | |
1620 | ||
1621 | new_cmd = add_set_enum_cmd ("struct-convention", no_class, | |
1622 | valid_conventions, | |
1623 | &struct_convention, "\ | |
1624 | Set the convention for returning small structs, valid values \ | |
1625 | are \"default\", \"pcc\" and \"reg\", and the default value is \"default\".", | |
1626 | &setlist); | |
1627 | add_show_from_set (new_cmd, &showlist); | |
1628 | } | |
1629 | ||
1630 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour, | |
1631 | i386_coff_osabi_sniffer); | |
1632 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_nlm_flavour, | |
1633 | i386_nlm_osabi_sniffer); | |
1634 | ||
1635 | gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_SVR4, | |
1636 | i386_svr4_init_abi); | |
1637 | gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_GO32, | |
1638 | i386_go32_init_abi); | |
1639 | gdbarch_register_osabi (bfd_arch_i386, GDB_OSABI_NETWARE, | |
1640 | i386_nw_init_abi); | |
c906108c | 1641 | } |