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