]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Intel 386 target-dependent stuff. |
349c5d5f AC |
2 | |
3 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, | |
4be87837 | 4 | 1997, 1998, 1999, 2000, 2001, 2002, 2003 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" | |
acd5c798 MK |
24 | #include "arch-utils.h" |
25 | #include "command.h" | |
26 | #include "dummy-frame.h" | |
6405b0a6 | 27 | #include "dwarf2-frame.h" |
acd5c798 MK |
28 | #include "doublest.h" |
29 | #include "floatformat.h" | |
c906108c | 30 | #include "frame.h" |
acd5c798 MK |
31 | #include "frame-base.h" |
32 | #include "frame-unwind.h" | |
c906108c | 33 | #include "inferior.h" |
acd5c798 | 34 | #include "gdbcmd.h" |
c906108c | 35 | #include "gdbcore.h" |
dfe01d39 | 36 | #include "objfiles.h" |
acd5c798 MK |
37 | #include "osabi.h" |
38 | #include "regcache.h" | |
39 | #include "reggroups.h" | |
c0d1d883 | 40 | #include "symfile.h" |
c906108c | 41 | #include "symtab.h" |
acd5c798 | 42 | #include "target.h" |
fd0407d6 | 43 | #include "value.h" |
a89aa300 | 44 | #include "dis-asm.h" |
acd5c798 | 45 | |
3d261580 | 46 | #include "gdb_assert.h" |
acd5c798 | 47 | #include "gdb_string.h" |
3d261580 | 48 | |
d2a7c97a | 49 | #include "i386-tdep.h" |
61113f8b | 50 | #include "i387-tdep.h" |
d2a7c97a | 51 | |
fc633446 MK |
52 | /* Names of the registers. The first 10 registers match the register |
53 | numbering scheme used by GCC for stabs and DWARF. */ | |
c40e1eab | 54 | |
fc633446 MK |
55 | static char *i386_register_names[] = |
56 | { | |
57 | "eax", "ecx", "edx", "ebx", | |
58 | "esp", "ebp", "esi", "edi", | |
59 | "eip", "eflags", "cs", "ss", | |
60 | "ds", "es", "fs", "gs", | |
61 | "st0", "st1", "st2", "st3", | |
62 | "st4", "st5", "st6", "st7", | |
63 | "fctrl", "fstat", "ftag", "fiseg", | |
64 | "fioff", "foseg", "fooff", "fop", | |
65 | "xmm0", "xmm1", "xmm2", "xmm3", | |
66 | "xmm4", "xmm5", "xmm6", "xmm7", | |
67 | "mxcsr" | |
68 | }; | |
69 | ||
1cb97e17 | 70 | static const int i386_num_register_names = ARRAY_SIZE (i386_register_names); |
c40e1eab | 71 | |
28fc6740 AC |
72 | /* MMX registers. */ |
73 | ||
74 | static char *i386_mmx_names[] = | |
75 | { | |
76 | "mm0", "mm1", "mm2", "mm3", | |
77 | "mm4", "mm5", "mm6", "mm7" | |
78 | }; | |
c40e1eab | 79 | |
1cb97e17 | 80 | static const int i386_num_mmx_regs = ARRAY_SIZE (i386_mmx_names); |
c40e1eab MK |
81 | |
82 | #define MM0_REGNUM NUM_REGS | |
28fc6740 AC |
83 | |
84 | static int | |
c40e1eab | 85 | i386_mmx_regnum_p (int regnum) |
28fc6740 | 86 | { |
c40e1eab MK |
87 | return (regnum >= MM0_REGNUM |
88 | && regnum < MM0_REGNUM + i386_num_mmx_regs); | |
28fc6740 AC |
89 | } |
90 | ||
23a34459 AC |
91 | /* FP register? */ |
92 | ||
93 | int | |
94 | i386_fp_regnum_p (int regnum) | |
95 | { | |
96 | return (regnum < NUM_REGS | |
c40e1eab | 97 | && (FP0_REGNUM && FP0_REGNUM <= regnum && regnum < FPC_REGNUM)); |
23a34459 AC |
98 | } |
99 | ||
100 | int | |
101 | i386_fpc_regnum_p (int regnum) | |
102 | { | |
103 | return (regnum < NUM_REGS | |
c40e1eab | 104 | && (FPC_REGNUM <= regnum && regnum < XMM0_REGNUM)); |
23a34459 AC |
105 | } |
106 | ||
107 | /* SSE register? */ | |
108 | ||
109 | int | |
110 | i386_sse_regnum_p (int regnum) | |
111 | { | |
112 | return (regnum < NUM_REGS | |
c40e1eab | 113 | && (XMM0_REGNUM <= regnum && regnum < MXCSR_REGNUM)); |
23a34459 AC |
114 | } |
115 | ||
116 | int | |
117 | i386_mxcsr_regnum_p (int regnum) | |
118 | { | |
119 | return (regnum < NUM_REGS | |
c40e1eab | 120 | && regnum == MXCSR_REGNUM); |
23a34459 AC |
121 | } |
122 | ||
fc633446 MK |
123 | /* Return the name of register REG. */ |
124 | ||
fa88f677 | 125 | const char * |
fc633446 MK |
126 | i386_register_name (int reg) |
127 | { | |
23a34459 | 128 | if (i386_mmx_regnum_p (reg)) |
28fc6740 | 129 | return i386_mmx_names[reg - MM0_REGNUM]; |
fc633446 | 130 | |
70913449 MK |
131 | if (reg >= 0 && reg < i386_num_register_names) |
132 | return i386_register_names[reg]; | |
133 | ||
c40e1eab | 134 | return NULL; |
fc633446 MK |
135 | } |
136 | ||
85540d8c MK |
137 | /* Convert stabs register number REG to the appropriate register |
138 | number used by GDB. */ | |
139 | ||
8201327c | 140 | static int |
85540d8c MK |
141 | i386_stab_reg_to_regnum (int reg) |
142 | { | |
143 | /* This implements what GCC calls the "default" register map. */ | |
144 | if (reg >= 0 && reg <= 7) | |
145 | { | |
acd5c798 | 146 | /* General-purpose registers. */ |
85540d8c MK |
147 | return reg; |
148 | } | |
149 | else if (reg >= 12 && reg <= 19) | |
150 | { | |
151 | /* Floating-point registers. */ | |
152 | return reg - 12 + FP0_REGNUM; | |
153 | } | |
154 | else if (reg >= 21 && reg <= 28) | |
155 | { | |
156 | /* SSE registers. */ | |
157 | return reg - 21 + XMM0_REGNUM; | |
158 | } | |
159 | else if (reg >= 29 && reg <= 36) | |
160 | { | |
161 | /* MMX registers. */ | |
7d12f766 | 162 | return reg - 29 + MM0_REGNUM; |
85540d8c MK |
163 | } |
164 | ||
165 | /* This will hopefully provoke a warning. */ | |
166 | return NUM_REGS + NUM_PSEUDO_REGS; | |
167 | } | |
168 | ||
8201327c | 169 | /* Convert DWARF register number REG to the appropriate register |
85540d8c MK |
170 | number used by GDB. */ |
171 | ||
8201327c | 172 | static int |
85540d8c MK |
173 | i386_dwarf_reg_to_regnum (int reg) |
174 | { | |
175 | /* The DWARF register numbering includes %eip and %eflags, and | |
176 | numbers the floating point registers differently. */ | |
177 | if (reg >= 0 && reg <= 9) | |
178 | { | |
acd5c798 | 179 | /* General-purpose registers. */ |
85540d8c MK |
180 | return reg; |
181 | } | |
182 | else if (reg >= 11 && reg <= 18) | |
183 | { | |
184 | /* Floating-point registers. */ | |
185 | return reg - 11 + FP0_REGNUM; | |
186 | } | |
187 | else if (reg >= 21) | |
188 | { | |
189 | /* The SSE and MMX registers have identical numbers as in stabs. */ | |
190 | return i386_stab_reg_to_regnum (reg); | |
191 | } | |
192 | ||
193 | /* This will hopefully provoke a warning. */ | |
194 | return NUM_REGS + NUM_PSEUDO_REGS; | |
195 | } | |
fc338970 | 196 | \f |
917317f4 | 197 | |
fc338970 MK |
198 | /* This is the variable that is set with "set disassembly-flavor", and |
199 | its legitimate values. */ | |
53904c9e AC |
200 | static const char att_flavor[] = "att"; |
201 | static const char intel_flavor[] = "intel"; | |
202 | static const char *valid_flavors[] = | |
c5aa993b | 203 | { |
c906108c SS |
204 | att_flavor, |
205 | intel_flavor, | |
206 | NULL | |
207 | }; | |
53904c9e | 208 | static const char *disassembly_flavor = att_flavor; |
acd5c798 | 209 | \f |
c906108c | 210 | |
acd5c798 MK |
211 | /* Use the program counter to determine the contents and size of a |
212 | breakpoint instruction. Return a pointer to a string of bytes that | |
213 | encode a breakpoint instruction, store the length of the string in | |
214 | *LEN and optionally adjust *PC to point to the correct memory | |
215 | location for inserting the breakpoint. | |
c906108c | 216 | |
acd5c798 MK |
217 | On the i386 we have a single breakpoint that fits in a single byte |
218 | and can be inserted anywhere. | |
c906108c | 219 | |
acd5c798 MK |
220 | This function is 64-bit safe. */ |
221 | ||
222 | static const unsigned char * | |
223 | i386_breakpoint_from_pc (CORE_ADDR *pc, int *len) | |
c906108c | 224 | { |
acd5c798 MK |
225 | static unsigned char break_insn[] = { 0xcc }; /* int 3 */ |
226 | ||
227 | *len = sizeof (break_insn); | |
228 | return break_insn; | |
c906108c | 229 | } |
fc338970 | 230 | \f |
acd5c798 MK |
231 | #ifdef I386_REGNO_TO_SYMMETRY |
232 | #error "The Sequent Symmetry is no longer supported." | |
233 | #endif | |
c906108c | 234 | |
acd5c798 MK |
235 | /* According to the System V ABI, the registers %ebp, %ebx, %edi, %esi |
236 | and %esp "belong" to the calling function. Therefore these | |
237 | registers should be saved if they're going to be modified. */ | |
c906108c | 238 | |
acd5c798 MK |
239 | /* The maximum number of saved registers. This should include all |
240 | registers mentioned above, and %eip. */ | |
a3386186 | 241 | #define I386_NUM_SAVED_REGS I386_NUM_GREGS |
acd5c798 MK |
242 | |
243 | struct i386_frame_cache | |
c906108c | 244 | { |
acd5c798 MK |
245 | /* Base address. */ |
246 | CORE_ADDR base; | |
247 | CORE_ADDR sp_offset; | |
248 | CORE_ADDR pc; | |
249 | ||
fd13a04a AC |
250 | /* Saved registers. */ |
251 | CORE_ADDR saved_regs[I386_NUM_SAVED_REGS]; | |
acd5c798 MK |
252 | CORE_ADDR saved_sp; |
253 | int pc_in_eax; | |
254 | ||
255 | /* Stack space reserved for local variables. */ | |
256 | long locals; | |
257 | }; | |
258 | ||
259 | /* Allocate and initialize a frame cache. */ | |
260 | ||
261 | static struct i386_frame_cache * | |
fd13a04a | 262 | i386_alloc_frame_cache (void) |
acd5c798 MK |
263 | { |
264 | struct i386_frame_cache *cache; | |
265 | int i; | |
266 | ||
267 | cache = FRAME_OBSTACK_ZALLOC (struct i386_frame_cache); | |
268 | ||
269 | /* Base address. */ | |
270 | cache->base = 0; | |
271 | cache->sp_offset = -4; | |
272 | cache->pc = 0; | |
273 | ||
fd13a04a AC |
274 | /* Saved registers. We initialize these to -1 since zero is a valid |
275 | offset (that's where %ebp is supposed to be stored). */ | |
276 | for (i = 0; i < I386_NUM_SAVED_REGS; i++) | |
277 | cache->saved_regs[i] = -1; | |
acd5c798 MK |
278 | cache->saved_sp = 0; |
279 | cache->pc_in_eax = 0; | |
280 | ||
281 | /* Frameless until proven otherwise. */ | |
282 | cache->locals = -1; | |
283 | ||
284 | return cache; | |
285 | } | |
c906108c | 286 | |
acd5c798 MK |
287 | /* If the instruction at PC is a jump, return the address of its |
288 | target. Otherwise, return PC. */ | |
c906108c | 289 | |
acd5c798 MK |
290 | static CORE_ADDR |
291 | i386_follow_jump (CORE_ADDR pc) | |
292 | { | |
293 | unsigned char op; | |
294 | long delta = 0; | |
295 | int data16 = 0; | |
c906108c | 296 | |
acd5c798 MK |
297 | op = read_memory_unsigned_integer (pc, 1); |
298 | if (op == 0x66) | |
c906108c | 299 | { |
c906108c | 300 | data16 = 1; |
acd5c798 | 301 | op = read_memory_unsigned_integer (pc + 1, 1); |
c906108c SS |
302 | } |
303 | ||
acd5c798 | 304 | switch (op) |
c906108c SS |
305 | { |
306 | case 0xe9: | |
fc338970 | 307 | /* Relative jump: if data16 == 0, disp32, else disp16. */ |
c906108c SS |
308 | if (data16) |
309 | { | |
acd5c798 | 310 | delta = read_memory_integer (pc + 2, 2); |
c906108c | 311 | |
fc338970 MK |
312 | /* Include the size of the jmp instruction (including the |
313 | 0x66 prefix). */ | |
acd5c798 | 314 | delta += 4; |
c906108c SS |
315 | } |
316 | else | |
317 | { | |
acd5c798 | 318 | delta = read_memory_integer (pc + 1, 4); |
c906108c | 319 | |
acd5c798 MK |
320 | /* Include the size of the jmp instruction. */ |
321 | delta += 5; | |
c906108c SS |
322 | } |
323 | break; | |
324 | case 0xeb: | |
fc338970 | 325 | /* Relative jump, disp8 (ignore data16). */ |
acd5c798 | 326 | delta = read_memory_integer (pc + data16 + 1, 1); |
c906108c | 327 | |
acd5c798 | 328 | delta += data16 + 2; |
c906108c SS |
329 | break; |
330 | } | |
c906108c | 331 | |
acd5c798 MK |
332 | return pc + delta; |
333 | } | |
fc338970 | 334 | |
acd5c798 MK |
335 | /* Check whether PC points at a prologue for a function returning a |
336 | structure or union. If so, it updates CACHE and returns the | |
337 | address of the first instruction after the code sequence that | |
338 | removes the "hidden" argument from the stack or CURRENT_PC, | |
339 | whichever is smaller. Otherwise, return PC. */ | |
c906108c | 340 | |
acd5c798 MK |
341 | static CORE_ADDR |
342 | i386_analyze_struct_return (CORE_ADDR pc, CORE_ADDR current_pc, | |
343 | struct i386_frame_cache *cache) | |
c906108c | 344 | { |
acd5c798 MK |
345 | /* Functions that return a structure or union start with: |
346 | ||
347 | popl %eax 0x58 | |
348 | xchgl %eax, (%esp) 0x87 0x04 0x24 | |
349 | or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00 | |
350 | ||
351 | (the System V compiler puts out the second `xchg' instruction, | |
352 | and the assembler doesn't try to optimize it, so the 'sib' form | |
353 | gets generated). This sequence is used to get the address of the | |
354 | return buffer for a function that returns a structure. */ | |
355 | static unsigned char proto1[3] = { 0x87, 0x04, 0x24 }; | |
356 | static unsigned char proto2[4] = { 0x87, 0x44, 0x24, 0x00 }; | |
357 | unsigned char buf[4]; | |
c906108c SS |
358 | unsigned char op; |
359 | ||
acd5c798 MK |
360 | if (current_pc <= pc) |
361 | return pc; | |
362 | ||
363 | op = read_memory_unsigned_integer (pc, 1); | |
c906108c | 364 | |
acd5c798 MK |
365 | if (op != 0x58) /* popl %eax */ |
366 | return pc; | |
c906108c | 367 | |
acd5c798 MK |
368 | read_memory (pc + 1, buf, 4); |
369 | if (memcmp (buf, proto1, 3) != 0 && memcmp (buf, proto2, 4) != 0) | |
370 | return pc; | |
c906108c | 371 | |
acd5c798 | 372 | if (current_pc == pc) |
c906108c | 373 | { |
acd5c798 MK |
374 | cache->sp_offset += 4; |
375 | return current_pc; | |
c906108c SS |
376 | } |
377 | ||
acd5c798 | 378 | if (current_pc == pc + 1) |
c906108c | 379 | { |
acd5c798 MK |
380 | cache->pc_in_eax = 1; |
381 | return current_pc; | |
382 | } | |
383 | ||
384 | if (buf[1] == proto1[1]) | |
385 | return pc + 4; | |
386 | else | |
387 | return pc + 5; | |
388 | } | |
389 | ||
390 | static CORE_ADDR | |
391 | i386_skip_probe (CORE_ADDR pc) | |
392 | { | |
393 | /* A function may start with | |
fc338970 | 394 | |
acd5c798 MK |
395 | pushl constant |
396 | call _probe | |
397 | addl $4, %esp | |
fc338970 | 398 | |
acd5c798 MK |
399 | followed by |
400 | ||
401 | pushl %ebp | |
fc338970 | 402 | |
acd5c798 MK |
403 | etc. */ |
404 | unsigned char buf[8]; | |
405 | unsigned char op; | |
fc338970 | 406 | |
acd5c798 MK |
407 | op = read_memory_unsigned_integer (pc, 1); |
408 | ||
409 | if (op == 0x68 || op == 0x6a) | |
410 | { | |
411 | int delta; | |
c906108c | 412 | |
acd5c798 MK |
413 | /* Skip past the `pushl' instruction; it has either a one-byte or a |
414 | four-byte operand, depending on the opcode. */ | |
c906108c | 415 | if (op == 0x68) |
acd5c798 | 416 | delta = 5; |
c906108c | 417 | else |
acd5c798 | 418 | delta = 2; |
c906108c | 419 | |
acd5c798 MK |
420 | /* Read the following 8 bytes, which should be `call _probe' (6 |
421 | bytes) followed by `addl $4,%esp' (2 bytes). */ | |
422 | read_memory (pc + delta, buf, sizeof (buf)); | |
c906108c | 423 | if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4) |
acd5c798 | 424 | pc += delta + sizeof (buf); |
c906108c SS |
425 | } |
426 | ||
acd5c798 MK |
427 | return pc; |
428 | } | |
429 | ||
430 | /* Check whether PC points at a code that sets up a new stack frame. | |
431 | If so, it updates CACHE and returns the address of the first | |
432 | instruction after the sequence that sets removes the "hidden" | |
433 | argument from the stack or CURRENT_PC, whichever is smaller. | |
434 | Otherwise, return PC. */ | |
435 | ||
436 | static CORE_ADDR | |
437 | i386_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc, | |
438 | struct i386_frame_cache *cache) | |
439 | { | |
440 | unsigned char op; | |
26604a34 | 441 | int skip = 0; |
acd5c798 MK |
442 | |
443 | if (current_pc <= pc) | |
444 | return current_pc; | |
445 | ||
446 | op = read_memory_unsigned_integer (pc, 1); | |
447 | ||
c906108c | 448 | if (op == 0x55) /* pushl %ebp */ |
c5aa993b | 449 | { |
acd5c798 MK |
450 | /* Take into account that we've executed the `pushl %ebp' that |
451 | starts this instruction sequence. */ | |
fd13a04a | 452 | cache->saved_regs[I386_EBP_REGNUM] = 0; |
acd5c798 MK |
453 | cache->sp_offset += 4; |
454 | ||
455 | /* If that's all, return now. */ | |
456 | if (current_pc <= pc + 1) | |
457 | return current_pc; | |
458 | ||
acd5c798 | 459 | op = read_memory_unsigned_integer (pc + 1, 1); |
26604a34 MK |
460 | |
461 | /* Check for some special instructions that might be migrated | |
462 | by GCC into the prologue. We check for | |
463 | ||
464 | xorl %ebx, %ebx | |
465 | xorl %ecx, %ecx | |
466 | xorl %edx, %edx | |
467 | ||
468 | and the equivalent | |
469 | ||
470 | subl %ebx, %ebx | |
471 | subl %ecx, %ecx | |
472 | subl %edx, %edx | |
473 | ||
474 | Make sure we only skip these instructions if we later see the | |
475 | `movl %esp, %ebp' that actually sets up the frame. */ | |
476 | while (op == 0x29 || op == 0x31) | |
477 | { | |
478 | op = read_memory_unsigned_integer (pc + skip + 2, 1); | |
479 | switch (op) | |
480 | { | |
481 | case 0xdb: /* %ebx */ | |
482 | case 0xc9: /* %ecx */ | |
483 | case 0xd2: /* %edx */ | |
484 | skip += 2; | |
485 | break; | |
486 | default: | |
487 | return pc + 1; | |
488 | } | |
489 | ||
490 | op = read_memory_unsigned_integer (pc + skip + 1, 1); | |
491 | } | |
492 | ||
493 | /* Check for `movl %esp, %ebp' -- can be written in two ways. */ | |
acd5c798 | 494 | switch (op) |
c906108c SS |
495 | { |
496 | case 0x8b: | |
26604a34 | 497 | if (read_memory_unsigned_integer (pc + skip + 2, 1) != 0xec) |
acd5c798 | 498 | return pc + 1; |
c906108c SS |
499 | break; |
500 | case 0x89: | |
26604a34 | 501 | if (read_memory_unsigned_integer (pc + skip + 2, 1) != 0xe5) |
acd5c798 | 502 | return pc + 1; |
c906108c SS |
503 | break; |
504 | default: | |
acd5c798 | 505 | return pc + 1; |
c906108c | 506 | } |
acd5c798 | 507 | |
26604a34 MK |
508 | /* OK, we actually have a frame. We just don't know how large |
509 | it is yet. Set its size to zero. We'll adjust it if | |
510 | necessary. We also now commit to skipping the special | |
511 | instructions mentioned before. */ | |
acd5c798 | 512 | cache->locals = 0; |
26604a34 | 513 | pc += skip; |
acd5c798 MK |
514 | |
515 | /* If that's all, return now. */ | |
516 | if (current_pc <= pc + 3) | |
517 | return current_pc; | |
518 | ||
fc338970 MK |
519 | /* Check for stack adjustment |
520 | ||
acd5c798 | 521 | subl $XXX, %esp |
fc338970 MK |
522 | |
523 | NOTE: You can't subtract a 16 bit immediate from a 32 bit | |
524 | reg, so we don't have to worry about a data16 prefix. */ | |
acd5c798 | 525 | op = read_memory_unsigned_integer (pc + 3, 1); |
c906108c SS |
526 | if (op == 0x83) |
527 | { | |
fc338970 | 528 | /* `subl' with 8 bit immediate. */ |
acd5c798 | 529 | if (read_memory_unsigned_integer (pc + 4, 1) != 0xec) |
fc338970 | 530 | /* Some instruction starting with 0x83 other than `subl'. */ |
acd5c798 MK |
531 | return pc + 3; |
532 | ||
533 | /* `subl' with signed byte immediate (though it wouldn't make | |
534 | sense to be negative). */ | |
535 | cache->locals = read_memory_integer (pc + 5, 1); | |
536 | return pc + 6; | |
c906108c SS |
537 | } |
538 | else if (op == 0x81) | |
539 | { | |
fc338970 | 540 | /* Maybe it is `subl' with a 32 bit immedediate. */ |
acd5c798 | 541 | if (read_memory_unsigned_integer (pc + 4, 1) != 0xec) |
fc338970 | 542 | /* Some instruction starting with 0x81 other than `subl'. */ |
acd5c798 MK |
543 | return pc + 3; |
544 | ||
fc338970 | 545 | /* It is `subl' with a 32 bit immediate. */ |
acd5c798 MK |
546 | cache->locals = read_memory_integer (pc + 5, 4); |
547 | return pc + 9; | |
c906108c SS |
548 | } |
549 | else | |
550 | { | |
acd5c798 MK |
551 | /* Some instruction other than `subl'. */ |
552 | return pc + 3; | |
c906108c SS |
553 | } |
554 | } | |
acd5c798 | 555 | else if (op == 0xc8) /* enter $XXX */ |
c906108c | 556 | { |
acd5c798 MK |
557 | cache->locals = read_memory_unsigned_integer (pc + 1, 2); |
558 | return pc + 4; | |
c906108c | 559 | } |
21d0e8a4 | 560 | |
acd5c798 | 561 | return pc; |
21d0e8a4 MK |
562 | } |
563 | ||
acd5c798 MK |
564 | /* Check whether PC points at code that saves registers on the stack. |
565 | If so, it updates CACHE and returns the address of the first | |
566 | instruction after the register saves or CURRENT_PC, whichever is | |
567 | smaller. Otherwise, return PC. */ | |
6bff26de MK |
568 | |
569 | static CORE_ADDR | |
acd5c798 MK |
570 | i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc, |
571 | struct i386_frame_cache *cache) | |
6bff26de | 572 | { |
99ab4326 MK |
573 | CORE_ADDR offset = 0; |
574 | unsigned char op; | |
575 | int i; | |
c0d1d883 | 576 | |
99ab4326 MK |
577 | if (cache->locals > 0) |
578 | offset -= cache->locals; | |
579 | for (i = 0; i < 8 && pc < current_pc; i++) | |
580 | { | |
581 | op = read_memory_unsigned_integer (pc, 1); | |
582 | if (op < 0x50 || op > 0x57) | |
583 | break; | |
0d17c81d | 584 | |
99ab4326 MK |
585 | offset -= 4; |
586 | cache->saved_regs[op - 0x50] = offset; | |
587 | cache->sp_offset += 4; | |
588 | pc++; | |
6bff26de MK |
589 | } |
590 | ||
acd5c798 | 591 | return pc; |
22797942 AC |
592 | } |
593 | ||
acd5c798 MK |
594 | /* Do a full analysis of the prologue at PC and update CACHE |
595 | accordingly. Bail out early if CURRENT_PC is reached. Return the | |
596 | address where the analysis stopped. | |
ed84f6c1 | 597 | |
fc338970 MK |
598 | We handle these cases: |
599 | ||
600 | The startup sequence can be at the start of the function, or the | |
601 | function can start with a branch to startup code at the end. | |
602 | ||
603 | %ebp can be set up with either the 'enter' instruction, or "pushl | |
604 | %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was | |
605 | once used in the System V compiler). | |
606 | ||
607 | Local space is allocated just below the saved %ebp by either the | |
608 | 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16 | |
609 | bit unsigned argument for space to allocate, and the 'addl' | |
610 | instruction could have either a signed byte, or 32 bit immediate. | |
611 | ||
612 | Next, the registers used by this function are pushed. With the | |
613 | System V compiler they will always be in the order: %edi, %esi, | |
614 | %ebx (and sometimes a harmless bug causes it to also save but not | |
615 | restore %eax); however, the code below is willing to see the pushes | |
616 | in any order, and will handle up to 8 of them. | |
617 | ||
618 | If the setup sequence is at the end of the function, then the next | |
619 | instruction will be a branch back to the start. */ | |
c906108c | 620 | |
acd5c798 MK |
621 | static CORE_ADDR |
622 | i386_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc, | |
623 | struct i386_frame_cache *cache) | |
c906108c | 624 | { |
acd5c798 MK |
625 | pc = i386_follow_jump (pc); |
626 | pc = i386_analyze_struct_return (pc, current_pc, cache); | |
627 | pc = i386_skip_probe (pc); | |
628 | pc = i386_analyze_frame_setup (pc, current_pc, cache); | |
629 | return i386_analyze_register_saves (pc, current_pc, cache); | |
c906108c SS |
630 | } |
631 | ||
fc338970 | 632 | /* Return PC of first real instruction. */ |
c906108c | 633 | |
3a1e71e3 | 634 | static CORE_ADDR |
acd5c798 | 635 | i386_skip_prologue (CORE_ADDR start_pc) |
c906108c | 636 | { |
c5aa993b | 637 | static unsigned char pic_pat[6] = |
acd5c798 MK |
638 | { |
639 | 0xe8, 0, 0, 0, 0, /* call 0x0 */ | |
640 | 0x5b, /* popl %ebx */ | |
c5aa993b | 641 | }; |
acd5c798 MK |
642 | struct i386_frame_cache cache; |
643 | CORE_ADDR pc; | |
644 | unsigned char op; | |
645 | int i; | |
c5aa993b | 646 | |
acd5c798 MK |
647 | cache.locals = -1; |
648 | pc = i386_analyze_prologue (start_pc, 0xffffffff, &cache); | |
649 | if (cache.locals < 0) | |
650 | return start_pc; | |
c5aa993b | 651 | |
acd5c798 | 652 | /* Found valid frame setup. */ |
c906108c | 653 | |
fc338970 MK |
654 | /* The native cc on SVR4 in -K PIC mode inserts the following code |
655 | to get the address of the global offset table (GOT) into register | |
acd5c798 MK |
656 | %ebx: |
657 | ||
fc338970 MK |
658 | call 0x0 |
659 | popl %ebx | |
660 | movl %ebx,x(%ebp) (optional) | |
661 | addl y,%ebx | |
662 | ||
c906108c SS |
663 | This code is with the rest of the prologue (at the end of the |
664 | function), so we have to skip it to get to the first real | |
665 | instruction at the start of the function. */ | |
c5aa993b | 666 | |
c906108c SS |
667 | for (i = 0; i < 6; i++) |
668 | { | |
acd5c798 | 669 | op = read_memory_unsigned_integer (pc + i, 1); |
c5aa993b | 670 | if (pic_pat[i] != op) |
c906108c SS |
671 | break; |
672 | } | |
673 | if (i == 6) | |
674 | { | |
acd5c798 MK |
675 | int delta = 6; |
676 | ||
677 | op = read_memory_unsigned_integer (pc + delta, 1); | |
c906108c | 678 | |
c5aa993b | 679 | if (op == 0x89) /* movl %ebx, x(%ebp) */ |
c906108c | 680 | { |
acd5c798 MK |
681 | op = read_memory_unsigned_integer (pc + delta + 1, 1); |
682 | ||
fc338970 | 683 | if (op == 0x5d) /* One byte offset from %ebp. */ |
acd5c798 | 684 | delta += 3; |
fc338970 | 685 | else if (op == 0x9d) /* Four byte offset from %ebp. */ |
acd5c798 | 686 | delta += 6; |
fc338970 | 687 | else /* Unexpected instruction. */ |
acd5c798 MK |
688 | delta = 0; |
689 | ||
690 | op = read_memory_unsigned_integer (pc + delta, 1); | |
c906108c | 691 | } |
acd5c798 | 692 | |
c5aa993b | 693 | /* addl y,%ebx */ |
acd5c798 MK |
694 | if (delta > 0 && op == 0x81 |
695 | && read_memory_unsigned_integer (pc + delta + 1, 1) == 0xc3); | |
c906108c | 696 | { |
acd5c798 | 697 | pc += delta + 6; |
c906108c SS |
698 | } |
699 | } | |
c5aa993b | 700 | |
acd5c798 | 701 | return i386_follow_jump (pc); |
c906108c SS |
702 | } |
703 | ||
acd5c798 | 704 | /* This function is 64-bit safe. */ |
93924b6b | 705 | |
acd5c798 MK |
706 | static CORE_ADDR |
707 | i386_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
93924b6b | 708 | { |
acd5c798 MK |
709 | char buf[8]; |
710 | ||
711 | frame_unwind_register (next_frame, PC_REGNUM, buf); | |
712 | return extract_typed_address (buf, builtin_type_void_func_ptr); | |
93924b6b | 713 | } |
acd5c798 | 714 | \f |
93924b6b | 715 | |
acd5c798 | 716 | /* Normal frames. */ |
c5aa993b | 717 | |
acd5c798 MK |
718 | static struct i386_frame_cache * |
719 | i386_frame_cache (struct frame_info *next_frame, void **this_cache) | |
a7769679 | 720 | { |
acd5c798 | 721 | struct i386_frame_cache *cache; |
c0d1d883 | 722 | char buf[4]; |
acd5c798 MK |
723 | int i; |
724 | ||
725 | if (*this_cache) | |
726 | return *this_cache; | |
727 | ||
fd13a04a | 728 | cache = i386_alloc_frame_cache (); |
acd5c798 MK |
729 | *this_cache = cache; |
730 | ||
731 | /* In principle, for normal frames, %ebp holds the frame pointer, | |
732 | which holds the base address for the current stack frame. | |
733 | However, for functions that don't need it, the frame pointer is | |
734 | optional. For these "frameless" functions the frame pointer is | |
735 | actually the frame pointer of the calling frame. Signal | |
736 | trampolines are just a special case of a "frameless" function. | |
737 | They (usually) share their frame pointer with the frame that was | |
738 | in progress when the signal occurred. */ | |
739 | ||
740 | frame_unwind_register (next_frame, I386_EBP_REGNUM, buf); | |
741 | cache->base = extract_unsigned_integer (buf, 4); | |
742 | if (cache->base == 0) | |
743 | return cache; | |
744 | ||
745 | /* For normal frames, %eip is stored at 4(%ebp). */ | |
fd13a04a | 746 | cache->saved_regs[I386_EIP_REGNUM] = 4; |
acd5c798 MK |
747 | |
748 | cache->pc = frame_func_unwind (next_frame); | |
749 | if (cache->pc != 0) | |
750 | i386_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache); | |
751 | ||
752 | if (cache->locals < 0) | |
753 | { | |
754 | /* We didn't find a valid frame, which means that CACHE->base | |
755 | currently holds the frame pointer for our calling frame. If | |
756 | we're at the start of a function, or somewhere half-way its | |
757 | prologue, the function's frame probably hasn't been fully | |
758 | setup yet. Try to reconstruct the base address for the stack | |
759 | frame by looking at the stack pointer. For truly "frameless" | |
760 | functions this might work too. */ | |
761 | ||
762 | frame_unwind_register (next_frame, I386_ESP_REGNUM, buf); | |
763 | cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset; | |
764 | } | |
765 | ||
766 | /* Now that we have the base address for the stack frame we can | |
767 | calculate the value of %esp in the calling frame. */ | |
768 | cache->saved_sp = cache->base + 8; | |
a7769679 | 769 | |
acd5c798 MK |
770 | /* Adjust all the saved registers such that they contain addresses |
771 | instead of offsets. */ | |
772 | for (i = 0; i < I386_NUM_SAVED_REGS; i++) | |
fd13a04a AC |
773 | if (cache->saved_regs[i] != -1) |
774 | cache->saved_regs[i] += cache->base; | |
acd5c798 MK |
775 | |
776 | return cache; | |
a7769679 MK |
777 | } |
778 | ||
3a1e71e3 | 779 | static void |
acd5c798 MK |
780 | i386_frame_this_id (struct frame_info *next_frame, void **this_cache, |
781 | struct frame_id *this_id) | |
c906108c | 782 | { |
acd5c798 MK |
783 | struct i386_frame_cache *cache = i386_frame_cache (next_frame, this_cache); |
784 | ||
785 | /* This marks the outermost frame. */ | |
786 | if (cache->base == 0) | |
787 | return; | |
788 | ||
3e210248 | 789 | /* See the end of i386_push_dummy_call. */ |
acd5c798 MK |
790 | (*this_id) = frame_id_build (cache->base + 8, cache->pc); |
791 | } | |
792 | ||
793 | static void | |
794 | i386_frame_prev_register (struct frame_info *next_frame, void **this_cache, | |
795 | int regnum, int *optimizedp, | |
796 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
797 | int *realnump, void *valuep) | |
798 | { | |
799 | struct i386_frame_cache *cache = i386_frame_cache (next_frame, this_cache); | |
800 | ||
801 | gdb_assert (regnum >= 0); | |
802 | ||
803 | /* The System V ABI says that: | |
804 | ||
805 | "The flags register contains the system flags, such as the | |
806 | direction flag and the carry flag. The direction flag must be | |
807 | set to the forward (that is, zero) direction before entry and | |
808 | upon exit from a function. Other user flags have no specified | |
809 | role in the standard calling sequence and are not preserved." | |
810 | ||
811 | To guarantee the "upon exit" part of that statement we fake a | |
812 | saved flags register that has its direction flag cleared. | |
813 | ||
814 | Note that GCC doesn't seem to rely on the fact that the direction | |
815 | flag is cleared after a function return; it always explicitly | |
816 | clears the flag before operations where it matters. | |
817 | ||
818 | FIXME: kettenis/20030316: I'm not quite sure whether this is the | |
819 | right thing to do. The way we fake the flags register here makes | |
820 | it impossible to change it. */ | |
821 | ||
822 | if (regnum == I386_EFLAGS_REGNUM) | |
823 | { | |
824 | *optimizedp = 0; | |
825 | *lvalp = not_lval; | |
826 | *addrp = 0; | |
827 | *realnump = -1; | |
828 | if (valuep) | |
829 | { | |
830 | ULONGEST val; | |
c5aa993b | 831 | |
acd5c798 | 832 | /* Clear the direction flag. */ |
f837910f MK |
833 | val = frame_unwind_register_unsigned (next_frame, |
834 | I386_EFLAGS_REGNUM); | |
acd5c798 MK |
835 | val &= ~(1 << 10); |
836 | store_unsigned_integer (valuep, 4, val); | |
837 | } | |
838 | ||
839 | return; | |
840 | } | |
1211c4e4 | 841 | |
acd5c798 | 842 | if (regnum == I386_EIP_REGNUM && cache->pc_in_eax) |
c906108c | 843 | { |
acd5c798 MK |
844 | frame_register_unwind (next_frame, I386_EAX_REGNUM, |
845 | optimizedp, lvalp, addrp, realnump, valuep); | |
846 | return; | |
847 | } | |
848 | ||
849 | if (regnum == I386_ESP_REGNUM && cache->saved_sp) | |
850 | { | |
851 | *optimizedp = 0; | |
852 | *lvalp = not_lval; | |
853 | *addrp = 0; | |
854 | *realnump = -1; | |
855 | if (valuep) | |
c906108c | 856 | { |
acd5c798 MK |
857 | /* Store the value. */ |
858 | store_unsigned_integer (valuep, 4, cache->saved_sp); | |
c906108c | 859 | } |
acd5c798 | 860 | return; |
c906108c | 861 | } |
acd5c798 | 862 | |
fd13a04a AC |
863 | if (regnum < I386_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1) |
864 | { | |
865 | *optimizedp = 0; | |
866 | *lvalp = lval_memory; | |
867 | *addrp = cache->saved_regs[regnum]; | |
868 | *realnump = -1; | |
869 | if (valuep) | |
870 | { | |
871 | /* Read the value in from memory. */ | |
872 | read_memory (*addrp, valuep, | |
873 | register_size (current_gdbarch, regnum)); | |
874 | } | |
875 | return; | |
876 | } | |
877 | ||
878 | frame_register_unwind (next_frame, regnum, | |
879 | optimizedp, lvalp, addrp, realnump, valuep); | |
acd5c798 MK |
880 | } |
881 | ||
882 | static const struct frame_unwind i386_frame_unwind = | |
883 | { | |
884 | NORMAL_FRAME, | |
885 | i386_frame_this_id, | |
886 | i386_frame_prev_register | |
887 | }; | |
888 | ||
889 | static const struct frame_unwind * | |
336d1bba | 890 | i386_frame_sniffer (struct frame_info *next_frame) |
acd5c798 MK |
891 | { |
892 | return &i386_frame_unwind; | |
893 | } | |
894 | \f | |
895 | ||
896 | /* Signal trampolines. */ | |
897 | ||
898 | static struct i386_frame_cache * | |
899 | i386_sigtramp_frame_cache (struct frame_info *next_frame, void **this_cache) | |
900 | { | |
901 | struct i386_frame_cache *cache; | |
902 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
903 | CORE_ADDR addr; | |
904 | char buf[4]; | |
905 | ||
906 | if (*this_cache) | |
907 | return *this_cache; | |
908 | ||
fd13a04a | 909 | cache = i386_alloc_frame_cache (); |
acd5c798 MK |
910 | |
911 | frame_unwind_register (next_frame, I386_ESP_REGNUM, buf); | |
912 | cache->base = extract_unsigned_integer (buf, 4) - 4; | |
913 | ||
914 | addr = tdep->sigcontext_addr (next_frame); | |
a3386186 MK |
915 | if (tdep->sc_reg_offset) |
916 | { | |
917 | int i; | |
918 | ||
919 | gdb_assert (tdep->sc_num_regs <= I386_NUM_SAVED_REGS); | |
920 | ||
921 | for (i = 0; i < tdep->sc_num_regs; i++) | |
922 | if (tdep->sc_reg_offset[i] != -1) | |
fd13a04a | 923 | cache->saved_regs[i] = addr + tdep->sc_reg_offset[i]; |
a3386186 MK |
924 | } |
925 | else | |
926 | { | |
fd13a04a AC |
927 | cache->saved_regs[I386_EIP_REGNUM] = addr + tdep->sc_pc_offset; |
928 | cache->saved_regs[I386_ESP_REGNUM] = addr + tdep->sc_sp_offset; | |
a3386186 | 929 | } |
acd5c798 MK |
930 | |
931 | *this_cache = cache; | |
932 | return cache; | |
933 | } | |
934 | ||
935 | static void | |
936 | i386_sigtramp_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
937 | struct frame_id *this_id) | |
938 | { | |
939 | struct i386_frame_cache *cache = | |
940 | i386_sigtramp_frame_cache (next_frame, this_cache); | |
941 | ||
3e210248 | 942 | /* See the end of i386_push_dummy_call. */ |
acd5c798 MK |
943 | (*this_id) = frame_id_build (cache->base + 8, frame_pc_unwind (next_frame)); |
944 | } | |
945 | ||
946 | static void | |
947 | i386_sigtramp_frame_prev_register (struct frame_info *next_frame, | |
948 | void **this_cache, | |
949 | int regnum, int *optimizedp, | |
950 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
951 | int *realnump, void *valuep) | |
952 | { | |
953 | /* Make sure we've initialized the cache. */ | |
954 | i386_sigtramp_frame_cache (next_frame, this_cache); | |
955 | ||
956 | i386_frame_prev_register (next_frame, this_cache, regnum, | |
957 | optimizedp, lvalp, addrp, realnump, valuep); | |
c906108c | 958 | } |
c0d1d883 | 959 | |
acd5c798 MK |
960 | static const struct frame_unwind i386_sigtramp_frame_unwind = |
961 | { | |
962 | SIGTRAMP_FRAME, | |
963 | i386_sigtramp_frame_this_id, | |
964 | i386_sigtramp_frame_prev_register | |
965 | }; | |
966 | ||
967 | static const struct frame_unwind * | |
336d1bba | 968 | i386_sigtramp_frame_sniffer (struct frame_info *next_frame) |
acd5c798 | 969 | { |
336d1bba | 970 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
acd5c798 MK |
971 | char *name; |
972 | ||
1c3545ae MK |
973 | /* We shouldn't even bother to try if the OSABI didn't register |
974 | a sigcontext_addr handler. */ | |
975 | if (!gdbarch_tdep (current_gdbarch)->sigcontext_addr) | |
976 | return NULL; | |
977 | ||
acd5c798 MK |
978 | find_pc_partial_function (pc, &name, NULL, NULL); |
979 | if (PC_IN_SIGTRAMP (pc, name)) | |
980 | return &i386_sigtramp_frame_unwind; | |
981 | ||
982 | return NULL; | |
983 | } | |
984 | \f | |
985 | ||
986 | static CORE_ADDR | |
987 | i386_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
988 | { | |
989 | struct i386_frame_cache *cache = i386_frame_cache (next_frame, this_cache); | |
990 | ||
991 | return cache->base; | |
992 | } | |
993 | ||
994 | static const struct frame_base i386_frame_base = | |
995 | { | |
996 | &i386_frame_unwind, | |
997 | i386_frame_base_address, | |
998 | i386_frame_base_address, | |
999 | i386_frame_base_address | |
1000 | }; | |
1001 | ||
acd5c798 MK |
1002 | static struct frame_id |
1003 | i386_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1004 | { | |
1005 | char buf[4]; | |
1006 | CORE_ADDR fp; | |
1007 | ||
1008 | frame_unwind_register (next_frame, I386_EBP_REGNUM, buf); | |
1009 | fp = extract_unsigned_integer (buf, 4); | |
1010 | ||
3e210248 | 1011 | /* See the end of i386_push_dummy_call. */ |
acd5c798 | 1012 | return frame_id_build (fp + 8, frame_pc_unwind (next_frame)); |
c0d1d883 | 1013 | } |
fc338970 | 1014 | \f |
c906108c | 1015 | |
fc338970 MK |
1016 | /* Figure out where the longjmp will land. Slurp the args out of the |
1017 | stack. We expect the first arg to be a pointer to the jmp_buf | |
8201327c | 1018 | structure from which we extract the address that we will land at. |
28bcfd30 | 1019 | This address is copied into PC. This routine returns non-zero on |
acd5c798 MK |
1020 | success. |
1021 | ||
1022 | This function is 64-bit safe. */ | |
c906108c | 1023 | |
8201327c MK |
1024 | static int |
1025 | i386_get_longjmp_target (CORE_ADDR *pc) | |
c906108c | 1026 | { |
28bcfd30 | 1027 | char buf[8]; |
c906108c | 1028 | CORE_ADDR sp, jb_addr; |
8201327c | 1029 | int jb_pc_offset = gdbarch_tdep (current_gdbarch)->jb_pc_offset; |
f9d3c2a8 | 1030 | int len = TYPE_LENGTH (builtin_type_void_func_ptr); |
c906108c | 1031 | |
8201327c MK |
1032 | /* If JB_PC_OFFSET is -1, we have no way to find out where the |
1033 | longjmp will land. */ | |
1034 | if (jb_pc_offset == -1) | |
c906108c SS |
1035 | return 0; |
1036 | ||
f837910f MK |
1037 | /* Don't use I386_ESP_REGNUM here, since this function is also used |
1038 | for AMD64. */ | |
1039 | regcache_cooked_read (current_regcache, SP_REGNUM, buf); | |
1040 | sp = extract_typed_address (buf, builtin_type_void_data_ptr); | |
28bcfd30 | 1041 | if (target_read_memory (sp + len, buf, len)) |
c906108c SS |
1042 | return 0; |
1043 | ||
f837910f | 1044 | jb_addr = extract_typed_address (buf, builtin_type_void_data_ptr); |
28bcfd30 | 1045 | if (target_read_memory (jb_addr + jb_pc_offset, buf, len)) |
8201327c | 1046 | return 0; |
c906108c | 1047 | |
f9d3c2a8 | 1048 | *pc = extract_typed_address (buf, builtin_type_void_func_ptr); |
c906108c SS |
1049 | return 1; |
1050 | } | |
fc338970 | 1051 | \f |
c906108c | 1052 | |
3a1e71e3 | 1053 | static CORE_ADDR |
6a65450a AC |
1054 | i386_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr, |
1055 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, | |
1056 | struct value **args, CORE_ADDR sp, int struct_return, | |
1057 | CORE_ADDR struct_addr) | |
22f8ba57 | 1058 | { |
acd5c798 MK |
1059 | char buf[4]; |
1060 | int i; | |
1061 | ||
1062 | /* Push arguments in reverse order. */ | |
1063 | for (i = nargs - 1; i >= 0; i--) | |
22f8ba57 | 1064 | { |
acd5c798 MK |
1065 | int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (args[i])); |
1066 | ||
1067 | /* The System V ABI says that: | |
1068 | ||
1069 | "An argument's size is increased, if necessary, to make it a | |
1070 | multiple of [32-bit] words. This may require tail padding, | |
1071 | depending on the size of the argument." | |
1072 | ||
1073 | This makes sure the stack says word-aligned. */ | |
1074 | sp -= (len + 3) & ~3; | |
1075 | write_memory (sp, VALUE_CONTENTS_ALL (args[i]), len); | |
1076 | } | |
22f8ba57 | 1077 | |
acd5c798 MK |
1078 | /* Push value address. */ |
1079 | if (struct_return) | |
1080 | { | |
22f8ba57 | 1081 | sp -= 4; |
fbd9dcd3 | 1082 | store_unsigned_integer (buf, 4, struct_addr); |
22f8ba57 MK |
1083 | write_memory (sp, buf, 4); |
1084 | } | |
1085 | ||
acd5c798 MK |
1086 | /* Store return address. */ |
1087 | sp -= 4; | |
6a65450a | 1088 | store_unsigned_integer (buf, 4, bp_addr); |
acd5c798 MK |
1089 | write_memory (sp, buf, 4); |
1090 | ||
1091 | /* Finally, update the stack pointer... */ | |
1092 | store_unsigned_integer (buf, 4, sp); | |
1093 | regcache_cooked_write (regcache, I386_ESP_REGNUM, buf); | |
1094 | ||
1095 | /* ...and fake a frame pointer. */ | |
1096 | regcache_cooked_write (regcache, I386_EBP_REGNUM, buf); | |
1097 | ||
3e210248 AC |
1098 | /* MarkK wrote: This "+ 8" is all over the place: |
1099 | (i386_frame_this_id, i386_sigtramp_frame_this_id, | |
1100 | i386_unwind_dummy_id). It's there, since all frame unwinders for | |
1101 | a given target have to agree (within a certain margin) on the | |
1102 | defenition of the stack address of a frame. Otherwise | |
1103 | frame_id_inner() won't work correctly. Since DWARF2/GCC uses the | |
1104 | stack address *before* the function call as a frame's CFA. On | |
1105 | the i386, when %ebp is used as a frame pointer, the offset | |
1106 | between the contents %ebp and the CFA as defined by GCC. */ | |
1107 | return sp + 8; | |
22f8ba57 MK |
1108 | } |
1109 | ||
1a309862 MK |
1110 | /* These registers are used for returning integers (and on some |
1111 | targets also for returning `struct' and `union' values when their | |
ef9dff19 | 1112 | size and alignment match an integer type). */ |
acd5c798 MK |
1113 | #define LOW_RETURN_REGNUM I386_EAX_REGNUM /* %eax */ |
1114 | #define HIGH_RETURN_REGNUM I386_EDX_REGNUM /* %edx */ | |
1a309862 MK |
1115 | |
1116 | /* Extract from an array REGBUF containing the (raw) register state, a | |
1117 | function return value of TYPE, and copy that, in virtual format, | |
1118 | into VALBUF. */ | |
1119 | ||
3a1e71e3 | 1120 | static void |
00f8375e | 1121 | i386_extract_return_value (struct type *type, struct regcache *regcache, |
ebba8386 | 1122 | void *dst) |
c906108c | 1123 | { |
ebba8386 | 1124 | bfd_byte *valbuf = dst; |
1a309862 | 1125 | int len = TYPE_LENGTH (type); |
00f8375e | 1126 | char buf[I386_MAX_REGISTER_SIZE]; |
1a309862 | 1127 | |
1e8d0a7b MK |
1128 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1129 | && TYPE_NFIELDS (type) == 1) | |
3df1b9b4 | 1130 | { |
00f8375e | 1131 | i386_extract_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf); |
3df1b9b4 MK |
1132 | return; |
1133 | } | |
1e8d0a7b MK |
1134 | |
1135 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
c906108c | 1136 | { |
94ea66b3 | 1137 | if (FP0_REGNUM < 0) |
1a309862 MK |
1138 | { |
1139 | warning ("Cannot find floating-point return value."); | |
1140 | memset (valbuf, 0, len); | |
ef9dff19 | 1141 | return; |
1a309862 MK |
1142 | } |
1143 | ||
c6ba6f0d MK |
1144 | /* Floating-point return values can be found in %st(0). Convert |
1145 | its contents to the desired type. This is probably not | |
1146 | exactly how it would happen on the target itself, but it is | |
1147 | the best we can do. */ | |
acd5c798 | 1148 | regcache_raw_read (regcache, I386_ST0_REGNUM, buf); |
00f8375e | 1149 | convert_typed_floating (buf, builtin_type_i387_ext, valbuf, type); |
c906108c SS |
1150 | } |
1151 | else | |
c5aa993b | 1152 | { |
f837910f MK |
1153 | int low_size = register_size (current_gdbarch, LOW_RETURN_REGNUM); |
1154 | int high_size = register_size (current_gdbarch, HIGH_RETURN_REGNUM); | |
d4f3574e SS |
1155 | |
1156 | if (len <= low_size) | |
00f8375e | 1157 | { |
0818c12a | 1158 | regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf); |
00f8375e MK |
1159 | memcpy (valbuf, buf, len); |
1160 | } | |
d4f3574e SS |
1161 | else if (len <= (low_size + high_size)) |
1162 | { | |
0818c12a | 1163 | regcache_raw_read (regcache, LOW_RETURN_REGNUM, buf); |
00f8375e | 1164 | memcpy (valbuf, buf, low_size); |
0818c12a | 1165 | regcache_raw_read (regcache, HIGH_RETURN_REGNUM, buf); |
00f8375e | 1166 | memcpy (valbuf + low_size, buf, len - low_size); |
d4f3574e SS |
1167 | } |
1168 | else | |
8e65ff28 AC |
1169 | internal_error (__FILE__, __LINE__, |
1170 | "Cannot extract return value of %d bytes long.", len); | |
c906108c SS |
1171 | } |
1172 | } | |
1173 | ||
ef9dff19 MK |
1174 | /* Write into the appropriate registers a function return value stored |
1175 | in VALBUF of type TYPE, given in virtual format. */ | |
1176 | ||
3a1e71e3 | 1177 | static void |
3d7f4f49 MK |
1178 | i386_store_return_value (struct type *type, struct regcache *regcache, |
1179 | const void *valbuf) | |
ef9dff19 MK |
1180 | { |
1181 | int len = TYPE_LENGTH (type); | |
1182 | ||
1e8d0a7b MK |
1183 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1184 | && TYPE_NFIELDS (type) == 1) | |
3df1b9b4 | 1185 | { |
3d7f4f49 | 1186 | i386_store_return_value (TYPE_FIELD_TYPE (type, 0), regcache, valbuf); |
3df1b9b4 MK |
1187 | return; |
1188 | } | |
1e8d0a7b MK |
1189 | |
1190 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
ef9dff19 | 1191 | { |
3d7f4f49 | 1192 | ULONGEST fstat; |
c6ba6f0d | 1193 | char buf[FPU_REG_RAW_SIZE]; |
ccb945b8 | 1194 | |
94ea66b3 | 1195 | if (FP0_REGNUM < 0) |
ef9dff19 MK |
1196 | { |
1197 | warning ("Cannot set floating-point return value."); | |
1198 | return; | |
1199 | } | |
1200 | ||
635b0cc1 MK |
1201 | /* Returning floating-point values is a bit tricky. Apart from |
1202 | storing the return value in %st(0), we have to simulate the | |
1203 | state of the FPU at function return point. */ | |
1204 | ||
c6ba6f0d MK |
1205 | /* Convert the value found in VALBUF to the extended |
1206 | floating-point format used by the FPU. This is probably | |
1207 | not exactly how it would happen on the target itself, but | |
1208 | it is the best we can do. */ | |
1209 | convert_typed_floating (valbuf, type, buf, builtin_type_i387_ext); | |
acd5c798 | 1210 | regcache_raw_write (regcache, I386_ST0_REGNUM, buf); |
ccb945b8 | 1211 | |
635b0cc1 MK |
1212 | /* Set the top of the floating-point register stack to 7. The |
1213 | actual value doesn't really matter, but 7 is what a normal | |
1214 | function return would end up with if the program started out | |
1215 | with a freshly initialized FPU. */ | |
3d7f4f49 | 1216 | regcache_raw_read_unsigned (regcache, FSTAT_REGNUM, &fstat); |
ccb945b8 | 1217 | fstat |= (7 << 11); |
3d7f4f49 | 1218 | regcache_raw_write_unsigned (regcache, FSTAT_REGNUM, fstat); |
ccb945b8 | 1219 | |
635b0cc1 MK |
1220 | /* Mark %st(1) through %st(7) as empty. Since we set the top of |
1221 | the floating-point register stack to 7, the appropriate value | |
1222 | for the tag word is 0x3fff. */ | |
3d7f4f49 | 1223 | regcache_raw_write_unsigned (regcache, FTAG_REGNUM, 0x3fff); |
ef9dff19 MK |
1224 | } |
1225 | else | |
1226 | { | |
f837910f MK |
1227 | int low_size = register_size (current_gdbarch, LOW_RETURN_REGNUM); |
1228 | int high_size = register_size (current_gdbarch, HIGH_RETURN_REGNUM); | |
ef9dff19 MK |
1229 | |
1230 | if (len <= low_size) | |
3d7f4f49 | 1231 | regcache_raw_write_part (regcache, LOW_RETURN_REGNUM, 0, len, valbuf); |
ef9dff19 MK |
1232 | else if (len <= (low_size + high_size)) |
1233 | { | |
3d7f4f49 MK |
1234 | regcache_raw_write (regcache, LOW_RETURN_REGNUM, valbuf); |
1235 | regcache_raw_write_part (regcache, HIGH_RETURN_REGNUM, 0, | |
1236 | len - low_size, (char *) valbuf + low_size); | |
ef9dff19 MK |
1237 | } |
1238 | else | |
8e65ff28 AC |
1239 | internal_error (__FILE__, __LINE__, |
1240 | "Cannot store return value of %d bytes long.", len); | |
ef9dff19 MK |
1241 | } |
1242 | } | |
f7af9647 | 1243 | |
751f1375 MK |
1244 | /* Extract from REGCACHE, which contains the (raw) register state, the |
1245 | address in which a function should return its structure value, as a | |
1246 | CORE_ADDR. */ | |
f7af9647 | 1247 | |
3a1e71e3 | 1248 | static CORE_ADDR |
00f8375e | 1249 | i386_extract_struct_value_address (struct regcache *regcache) |
f7af9647 | 1250 | { |
acd5c798 | 1251 | char buf[4]; |
751f1375 | 1252 | |
acd5c798 MK |
1253 | regcache_cooked_read (regcache, I386_EAX_REGNUM, buf); |
1254 | return extract_unsigned_integer (buf, 4); | |
f7af9647 | 1255 | } |
fc338970 | 1256 | \f |
ef9dff19 | 1257 | |
8201327c MK |
1258 | /* This is the variable that is set with "set struct-convention", and |
1259 | its legitimate values. */ | |
1260 | static const char default_struct_convention[] = "default"; | |
1261 | static const char pcc_struct_convention[] = "pcc"; | |
1262 | static const char reg_struct_convention[] = "reg"; | |
1263 | static const char *valid_conventions[] = | |
1264 | { | |
1265 | default_struct_convention, | |
1266 | pcc_struct_convention, | |
1267 | reg_struct_convention, | |
1268 | NULL | |
1269 | }; | |
1270 | static const char *struct_convention = default_struct_convention; | |
1271 | ||
1272 | static int | |
1273 | i386_use_struct_convention (int gcc_p, struct type *type) | |
1274 | { | |
1275 | enum struct_return struct_return; | |
1276 | ||
1277 | if (struct_convention == default_struct_convention) | |
1278 | struct_return = gdbarch_tdep (current_gdbarch)->struct_return; | |
1279 | else if (struct_convention == pcc_struct_convention) | |
1280 | struct_return = pcc_struct_return; | |
1281 | else | |
1282 | struct_return = reg_struct_return; | |
1283 | ||
1284 | return generic_use_struct_convention (struct_return == reg_struct_return, | |
1285 | type); | |
1286 | } | |
1287 | \f | |
1288 | ||
d7a0d72c MK |
1289 | /* Return the GDB type object for the "standard" data type of data in |
1290 | register REGNUM. Perhaps %esi and %edi should go here, but | |
1291 | potentially they could be used for things other than address. */ | |
1292 | ||
3a1e71e3 | 1293 | static struct type * |
4e259f09 | 1294 | i386_register_type (struct gdbarch *gdbarch, int regnum) |
d7a0d72c | 1295 | { |
acd5c798 MK |
1296 | if (regnum == I386_EIP_REGNUM |
1297 | || regnum == I386_EBP_REGNUM || regnum == I386_ESP_REGNUM) | |
d7a0d72c MK |
1298 | return lookup_pointer_type (builtin_type_void); |
1299 | ||
23a34459 | 1300 | if (i386_fp_regnum_p (regnum)) |
c6ba6f0d | 1301 | return builtin_type_i387_ext; |
d7a0d72c | 1302 | |
23a34459 | 1303 | if (i386_sse_regnum_p (regnum)) |
3139facc | 1304 | return builtin_type_vec128i; |
d7a0d72c | 1305 | |
23a34459 | 1306 | if (i386_mmx_regnum_p (regnum)) |
28fc6740 AC |
1307 | return builtin_type_vec64i; |
1308 | ||
d7a0d72c MK |
1309 | return builtin_type_int; |
1310 | } | |
1311 | ||
28fc6740 | 1312 | /* Map a cooked register onto a raw register or memory. For the i386, |
acd5c798 | 1313 | the MMX registers need to be mapped onto floating point registers. */ |
28fc6740 AC |
1314 | |
1315 | static int | |
c86c27af | 1316 | i386_mmx_regnum_to_fp_regnum (struct regcache *regcache, int regnum) |
28fc6740 AC |
1317 | { |
1318 | int mmxi; | |
1319 | ULONGEST fstat; | |
1320 | int tos; | |
1321 | int fpi; | |
c86c27af | 1322 | |
28fc6740 AC |
1323 | mmxi = regnum - MM0_REGNUM; |
1324 | regcache_raw_read_unsigned (regcache, FSTAT_REGNUM, &fstat); | |
1325 | tos = (fstat >> 11) & 0x7; | |
1326 | fpi = (mmxi + tos) % 8; | |
c86c27af | 1327 | |
28fc6740 AC |
1328 | return (FP0_REGNUM + fpi); |
1329 | } | |
1330 | ||
1331 | static void | |
1332 | i386_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, | |
1333 | int regnum, void *buf) | |
1334 | { | |
23a34459 | 1335 | if (i386_mmx_regnum_p (regnum)) |
28fc6740 | 1336 | { |
d9d9c31f | 1337 | char mmx_buf[MAX_REGISTER_SIZE]; |
c86c27af MK |
1338 | int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum); |
1339 | ||
28fc6740 | 1340 | /* Extract (always little endian). */ |
c86c27af | 1341 | regcache_raw_read (regcache, fpnum, mmx_buf); |
f837910f | 1342 | memcpy (buf, mmx_buf, register_size (gdbarch, regnum)); |
28fc6740 AC |
1343 | } |
1344 | else | |
1345 | regcache_raw_read (regcache, regnum, buf); | |
1346 | } | |
1347 | ||
1348 | static void | |
1349 | i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, | |
1350 | int regnum, const void *buf) | |
1351 | { | |
23a34459 | 1352 | if (i386_mmx_regnum_p (regnum)) |
28fc6740 | 1353 | { |
d9d9c31f | 1354 | char mmx_buf[MAX_REGISTER_SIZE]; |
c86c27af MK |
1355 | int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum); |
1356 | ||
28fc6740 AC |
1357 | /* Read ... */ |
1358 | regcache_raw_read (regcache, fpnum, mmx_buf); | |
1359 | /* ... Modify ... (always little endian). */ | |
f837910f | 1360 | memcpy (mmx_buf, buf, register_size (gdbarch, regnum)); |
28fc6740 AC |
1361 | /* ... Write. */ |
1362 | regcache_raw_write (regcache, fpnum, mmx_buf); | |
1363 | } | |
1364 | else | |
1365 | regcache_raw_write (regcache, regnum, buf); | |
1366 | } | |
ff2e87ac AC |
1367 | \f |
1368 | ||
1369 | /* These registers don't have pervasive standard uses. Move them to | |
1370 | i386-tdep.h if necessary. */ | |
1371 | ||
1372 | #define I386_EBX_REGNUM 3 /* %ebx */ | |
1373 | #define I386_ECX_REGNUM 1 /* %ecx */ | |
1374 | #define I386_ESI_REGNUM 6 /* %esi */ | |
1375 | #define I386_EDI_REGNUM 7 /* %edi */ | |
1376 | ||
1377 | /* Return the register number of the register allocated by GCC after | |
1378 | REGNUM, or -1 if there is no such register. */ | |
1379 | ||
1380 | static int | |
1381 | i386_next_regnum (int regnum) | |
1382 | { | |
1383 | /* GCC allocates the registers in the order: | |
1384 | ||
1385 | %eax, %edx, %ecx, %ebx, %esi, %edi, %ebp, %esp, ... | |
1386 | ||
1387 | Since storing a variable in %esp doesn't make any sense we return | |
1388 | -1 for %ebp and for %esp itself. */ | |
1389 | static int next_regnum[] = | |
1390 | { | |
1391 | I386_EDX_REGNUM, /* Slot for %eax. */ | |
1392 | I386_EBX_REGNUM, /* Slot for %ecx. */ | |
1393 | I386_ECX_REGNUM, /* Slot for %edx. */ | |
1394 | I386_ESI_REGNUM, /* Slot for %ebx. */ | |
1395 | -1, -1, /* Slots for %esp and %ebp. */ | |
1396 | I386_EDI_REGNUM, /* Slot for %esi. */ | |
1397 | I386_EBP_REGNUM /* Slot for %edi. */ | |
1398 | }; | |
1399 | ||
de5b9bb9 | 1400 | if (regnum >= 0 && regnum < sizeof (next_regnum) / sizeof (next_regnum[0])) |
ff2e87ac | 1401 | return next_regnum[regnum]; |
28fc6740 | 1402 | |
ff2e87ac AC |
1403 | return -1; |
1404 | } | |
1405 | ||
1406 | /* Return nonzero if a value of type TYPE stored in register REGNUM | |
1407 | needs any special handling. */ | |
d7a0d72c | 1408 | |
3a1e71e3 | 1409 | static int |
ff2e87ac | 1410 | i386_convert_register_p (int regnum, struct type *type) |
d7a0d72c | 1411 | { |
de5b9bb9 MK |
1412 | int len = TYPE_LENGTH (type); |
1413 | ||
ff2e87ac AC |
1414 | /* Values may be spread across multiple registers. Most debugging |
1415 | formats aren't expressive enough to specify the locations, so | |
1416 | some heuristics is involved. Right now we only handle types that | |
de5b9bb9 MK |
1417 | have a length that is a multiple of the word size, since GCC |
1418 | doesn't seem to put any other types into registers. */ | |
1419 | if (len > 4 && len % 4 == 0) | |
1420 | { | |
1421 | int last_regnum = regnum; | |
1422 | ||
1423 | while (len > 4) | |
1424 | { | |
1425 | last_regnum = i386_next_regnum (last_regnum); | |
1426 | len -= 4; | |
1427 | } | |
1428 | ||
1429 | if (last_regnum != -1) | |
1430 | return 1; | |
1431 | } | |
ff2e87ac | 1432 | |
23a34459 | 1433 | return i386_fp_regnum_p (regnum); |
d7a0d72c MK |
1434 | } |
1435 | ||
ff2e87ac AC |
1436 | /* Read a value of type TYPE from register REGNUM in frame FRAME, and |
1437 | return its contents in TO. */ | |
ac27f131 | 1438 | |
3a1e71e3 | 1439 | static void |
ff2e87ac AC |
1440 | i386_register_to_value (struct frame_info *frame, int regnum, |
1441 | struct type *type, void *to) | |
ac27f131 | 1442 | { |
de5b9bb9 MK |
1443 | int len = TYPE_LENGTH (type); |
1444 | char *buf = to; | |
1445 | ||
ff2e87ac AC |
1446 | /* FIXME: kettenis/20030609: What should we do if REGNUM isn't |
1447 | available in FRAME (i.e. if it wasn't saved)? */ | |
3d261580 | 1448 | |
ff2e87ac | 1449 | if (i386_fp_regnum_p (regnum)) |
8d7f6b4a | 1450 | { |
d532c08f MK |
1451 | i387_register_to_value (frame, regnum, type, to); |
1452 | return; | |
8d7f6b4a | 1453 | } |
ff2e87ac | 1454 | |
de5b9bb9 MK |
1455 | /* Read a value spread accross multiple registers. */ |
1456 | ||
1457 | gdb_assert (len > 4 && len % 4 == 0); | |
3d261580 | 1458 | |
de5b9bb9 MK |
1459 | while (len > 0) |
1460 | { | |
1461 | gdb_assert (regnum != -1); | |
1462 | gdb_assert (register_size (current_gdbarch, regnum) == 4); | |
d532c08f | 1463 | |
f837910f | 1464 | get_frame_register (frame, regnum, buf); |
de5b9bb9 MK |
1465 | regnum = i386_next_regnum (regnum); |
1466 | len -= 4; | |
1467 | buf += 4; | |
1468 | } | |
ac27f131 MK |
1469 | } |
1470 | ||
ff2e87ac AC |
1471 | /* Write the contents FROM of a value of type TYPE into register |
1472 | REGNUM in frame FRAME. */ | |
ac27f131 | 1473 | |
3a1e71e3 | 1474 | static void |
ff2e87ac AC |
1475 | i386_value_to_register (struct frame_info *frame, int regnum, |
1476 | struct type *type, const void *from) | |
ac27f131 | 1477 | { |
de5b9bb9 MK |
1478 | int len = TYPE_LENGTH (type); |
1479 | const char *buf = from; | |
1480 | ||
ff2e87ac | 1481 | if (i386_fp_regnum_p (regnum)) |
c6ba6f0d | 1482 | { |
d532c08f MK |
1483 | i387_value_to_register (frame, regnum, type, from); |
1484 | return; | |
1485 | } | |
3d261580 | 1486 | |
de5b9bb9 MK |
1487 | /* Write a value spread accross multiple registers. */ |
1488 | ||
1489 | gdb_assert (len > 4 && len % 4 == 0); | |
ff2e87ac | 1490 | |
de5b9bb9 MK |
1491 | while (len > 0) |
1492 | { | |
1493 | gdb_assert (regnum != -1); | |
1494 | gdb_assert (register_size (current_gdbarch, regnum) == 4); | |
d532c08f | 1495 | |
de5b9bb9 MK |
1496 | put_frame_register (frame, regnum, buf); |
1497 | regnum = i386_next_regnum (regnum); | |
1498 | len -= 4; | |
1499 | buf += 4; | |
1500 | } | |
ac27f131 | 1501 | } |
ff2e87ac AC |
1502 | \f |
1503 | ||
fc338970 | 1504 | |
c906108c | 1505 | #ifdef STATIC_TRANSFORM_NAME |
fc338970 MK |
1506 | /* SunPRO encodes the static variables. This is not related to C++ |
1507 | mangling, it is done for C too. */ | |
c906108c SS |
1508 | |
1509 | char * | |
fba45db2 | 1510 | sunpro_static_transform_name (char *name) |
c906108c SS |
1511 | { |
1512 | char *p; | |
1513 | if (IS_STATIC_TRANSFORM_NAME (name)) | |
1514 | { | |
fc338970 MK |
1515 | /* For file-local statics there will be a period, a bunch of |
1516 | junk (the contents of which match a string given in the | |
c5aa993b JM |
1517 | N_OPT), a period and the name. For function-local statics |
1518 | there will be a bunch of junk (which seems to change the | |
1519 | second character from 'A' to 'B'), a period, the name of the | |
1520 | function, and the name. So just skip everything before the | |
1521 | last period. */ | |
c906108c SS |
1522 | p = strrchr (name, '.'); |
1523 | if (p != NULL) | |
1524 | name = p + 1; | |
1525 | } | |
1526 | return name; | |
1527 | } | |
1528 | #endif /* STATIC_TRANSFORM_NAME */ | |
fc338970 | 1529 | \f |
c906108c | 1530 | |
fc338970 | 1531 | /* Stuff for WIN32 PE style DLL's but is pretty generic really. */ |
c906108c SS |
1532 | |
1533 | CORE_ADDR | |
1cce71eb | 1534 | i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name) |
c906108c | 1535 | { |
fc338970 | 1536 | if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */ |
c906108c | 1537 | { |
c5aa993b | 1538 | unsigned long indirect = read_memory_unsigned_integer (pc + 2, 4); |
c906108c | 1539 | struct minimal_symbol *indsym = |
fc338970 | 1540 | indirect ? lookup_minimal_symbol_by_pc (indirect) : 0; |
645dd519 | 1541 | char *symname = indsym ? SYMBOL_LINKAGE_NAME (indsym) : 0; |
c906108c | 1542 | |
c5aa993b | 1543 | if (symname) |
c906108c | 1544 | { |
c5aa993b JM |
1545 | if (strncmp (symname, "__imp_", 6) == 0 |
1546 | || strncmp (symname, "_imp_", 5) == 0) | |
c906108c SS |
1547 | return name ? 1 : read_memory_unsigned_integer (indirect, 4); |
1548 | } | |
1549 | } | |
fc338970 | 1550 | return 0; /* Not a trampoline. */ |
c906108c | 1551 | } |
fc338970 MK |
1552 | \f |
1553 | ||
8201327c MK |
1554 | /* Return non-zero if PC and NAME show that we are in a signal |
1555 | trampoline. */ | |
1556 | ||
1557 | static int | |
1558 | i386_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
1559 | { | |
1560 | return (name && strcmp ("_sigtramp", name) == 0); | |
1561 | } | |
1562 | \f | |
1563 | ||
fc338970 MK |
1564 | /* We have two flavours of disassembly. The machinery on this page |
1565 | deals with switching between those. */ | |
c906108c SS |
1566 | |
1567 | static int | |
a89aa300 | 1568 | i386_print_insn (bfd_vma pc, struct disassemble_info *info) |
c906108c | 1569 | { |
5e3397bb MK |
1570 | gdb_assert (disassembly_flavor == att_flavor |
1571 | || disassembly_flavor == intel_flavor); | |
1572 | ||
1573 | /* FIXME: kettenis/20020915: Until disassembler_options is properly | |
1574 | constified, cast to prevent a compiler warning. */ | |
1575 | info->disassembler_options = (char *) disassembly_flavor; | |
1576 | info->mach = gdbarch_bfd_arch_info (current_gdbarch)->mach; | |
1577 | ||
1578 | return print_insn_i386 (pc, info); | |
7a292a7a | 1579 | } |
fc338970 | 1580 | \f |
3ce1502b | 1581 | |
8201327c MK |
1582 | /* There are a few i386 architecture variants that differ only |
1583 | slightly from the generic i386 target. For now, we don't give them | |
1584 | their own source file, but include them here. As a consequence, | |
1585 | they'll always be included. */ | |
3ce1502b | 1586 | |
8201327c | 1587 | /* System V Release 4 (SVR4). */ |
3ce1502b | 1588 | |
8201327c MK |
1589 | static int |
1590 | i386_svr4_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
d2a7c97a | 1591 | { |
acd5c798 MK |
1592 | /* UnixWare uses _sigacthandler. The origin of the other symbols is |
1593 | currently unknown. */ | |
8201327c MK |
1594 | return (name && (strcmp ("_sigreturn", name) == 0 |
1595 | || strcmp ("_sigacthandler", name) == 0 | |
1596 | || strcmp ("sigvechandler", name) == 0)); | |
1597 | } | |
d2a7c97a | 1598 | |
acd5c798 MK |
1599 | /* Assuming NEXT_FRAME is for a frame following a SVR4 sigtramp |
1600 | routine, return the address of the associated sigcontext (ucontext) | |
1601 | structure. */ | |
3ce1502b | 1602 | |
3a1e71e3 | 1603 | static CORE_ADDR |
acd5c798 | 1604 | i386_svr4_sigcontext_addr (struct frame_info *next_frame) |
8201327c | 1605 | { |
acd5c798 MK |
1606 | char buf[4]; |
1607 | CORE_ADDR sp; | |
3ce1502b | 1608 | |
acd5c798 MK |
1609 | frame_unwind_register (next_frame, I386_ESP_REGNUM, buf); |
1610 | sp = extract_unsigned_integer (buf, 4); | |
21d0e8a4 | 1611 | |
acd5c798 | 1612 | return read_memory_unsigned_integer (sp + 8, 4); |
8201327c MK |
1613 | } |
1614 | \f | |
3ce1502b | 1615 | |
8201327c | 1616 | /* DJGPP. */ |
d2a7c97a | 1617 | |
8201327c MK |
1618 | static int |
1619 | i386_go32_pc_in_sigtramp (CORE_ADDR pc, char *name) | |
1620 | { | |
1621 | /* DJGPP doesn't have any special frames for signal handlers. */ | |
1622 | return 0; | |
1623 | } | |
1624 | \f | |
d2a7c97a | 1625 | |
8201327c | 1626 | /* Generic ELF. */ |
d2a7c97a | 1627 | |
8201327c MK |
1628 | void |
1629 | i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1630 | { | |
1631 | /* We typically use stabs-in-ELF with the DWARF register numbering. */ | |
1632 | set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1633 | } | |
3ce1502b | 1634 | |
8201327c | 1635 | /* System V Release 4 (SVR4). */ |
3ce1502b | 1636 | |
8201327c MK |
1637 | void |
1638 | i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1639 | { | |
1640 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
3ce1502b | 1641 | |
8201327c MK |
1642 | /* System V Release 4 uses ELF. */ |
1643 | i386_elf_init_abi (info, gdbarch); | |
3ce1502b | 1644 | |
dfe01d39 MK |
1645 | /* System V Release 4 has shared libraries. */ |
1646 | set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section); | |
1647 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); | |
1648 | ||
8201327c | 1649 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_svr4_pc_in_sigtramp); |
21d0e8a4 | 1650 | tdep->sigcontext_addr = i386_svr4_sigcontext_addr; |
acd5c798 MK |
1651 | tdep->sc_pc_offset = 36 + 14 * 4; |
1652 | tdep->sc_sp_offset = 36 + 17 * 4; | |
3ce1502b | 1653 | |
8201327c | 1654 | tdep->jb_pc_offset = 20; |
3ce1502b MK |
1655 | } |
1656 | ||
8201327c | 1657 | /* DJGPP. */ |
3ce1502b | 1658 | |
3a1e71e3 | 1659 | static void |
8201327c | 1660 | i386_go32_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
3ce1502b | 1661 | { |
8201327c | 1662 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
3ce1502b | 1663 | |
8201327c | 1664 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_go32_pc_in_sigtramp); |
3ce1502b | 1665 | |
8201327c | 1666 | tdep->jb_pc_offset = 36; |
3ce1502b MK |
1667 | } |
1668 | ||
8201327c | 1669 | /* NetWare. */ |
3ce1502b | 1670 | |
3a1e71e3 | 1671 | static void |
8201327c | 1672 | i386_nw_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
3ce1502b | 1673 | { |
8201327c | 1674 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
3ce1502b | 1675 | |
8201327c | 1676 | tdep->jb_pc_offset = 24; |
d2a7c97a | 1677 | } |
8201327c | 1678 | \f |
2acceee2 | 1679 | |
38c968cf AC |
1680 | /* i386 register groups. In addition to the normal groups, add "mmx" |
1681 | and "sse". */ | |
1682 | ||
1683 | static struct reggroup *i386_sse_reggroup; | |
1684 | static struct reggroup *i386_mmx_reggroup; | |
1685 | ||
1686 | static void | |
1687 | i386_init_reggroups (void) | |
1688 | { | |
1689 | i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP); | |
1690 | i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP); | |
1691 | } | |
1692 | ||
1693 | static void | |
1694 | i386_add_reggroups (struct gdbarch *gdbarch) | |
1695 | { | |
1696 | reggroup_add (gdbarch, i386_sse_reggroup); | |
1697 | reggroup_add (gdbarch, i386_mmx_reggroup); | |
1698 | reggroup_add (gdbarch, general_reggroup); | |
1699 | reggroup_add (gdbarch, float_reggroup); | |
1700 | reggroup_add (gdbarch, all_reggroup); | |
1701 | reggroup_add (gdbarch, save_reggroup); | |
1702 | reggroup_add (gdbarch, restore_reggroup); | |
1703 | reggroup_add (gdbarch, vector_reggroup); | |
1704 | reggroup_add (gdbarch, system_reggroup); | |
1705 | } | |
1706 | ||
1707 | int | |
1708 | i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
1709 | struct reggroup *group) | |
1710 | { | |
1711 | int sse_regnum_p = (i386_sse_regnum_p (regnum) | |
1712 | || i386_mxcsr_regnum_p (regnum)); | |
1713 | int fp_regnum_p = (i386_fp_regnum_p (regnum) | |
1714 | || i386_fpc_regnum_p (regnum)); | |
1715 | int mmx_regnum_p = (i386_mmx_regnum_p (regnum)); | |
acd5c798 | 1716 | |
38c968cf AC |
1717 | if (group == i386_mmx_reggroup) |
1718 | return mmx_regnum_p; | |
1719 | if (group == i386_sse_reggroup) | |
1720 | return sse_regnum_p; | |
1721 | if (group == vector_reggroup) | |
1722 | return (mmx_regnum_p || sse_regnum_p); | |
1723 | if (group == float_reggroup) | |
1724 | return fp_regnum_p; | |
1725 | if (group == general_reggroup) | |
1726 | return (!fp_regnum_p && !mmx_regnum_p && !sse_regnum_p); | |
acd5c798 | 1727 | |
38c968cf AC |
1728 | return default_register_reggroup_p (gdbarch, regnum, group); |
1729 | } | |
38c968cf | 1730 | \f |
acd5c798 | 1731 | |
f837910f MK |
1732 | /* Get the ARGIth function argument for the current function. */ |
1733 | ||
42c466d7 | 1734 | static CORE_ADDR |
143985b7 AF |
1735 | i386_fetch_pointer_argument (struct frame_info *frame, int argi, |
1736 | struct type *type) | |
1737 | { | |
f837910f MK |
1738 | CORE_ADDR sp = get_frame_register_unsigned (frame, I386_ESP_REGNUM); |
1739 | return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4); | |
143985b7 AF |
1740 | } |
1741 | ||
1742 | \f | |
3a1e71e3 | 1743 | static struct gdbarch * |
a62cc96e AC |
1744 | i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
1745 | { | |
cd3c07fc | 1746 | struct gdbarch_tdep *tdep; |
a62cc96e AC |
1747 | struct gdbarch *gdbarch; |
1748 | ||
4be87837 DJ |
1749 | /* If there is already a candidate, use it. */ |
1750 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1751 | if (arches != NULL) | |
1752 | return arches->gdbarch; | |
a62cc96e AC |
1753 | |
1754 | /* Allocate space for the new architecture. */ | |
1755 | tdep = XMALLOC (struct gdbarch_tdep); | |
1756 | gdbarch = gdbarch_alloc (&info, tdep); | |
1757 | ||
49ed40de KB |
1758 | /* The i386 default settings now include the SSE registers. |
1759 | I386_NUM_XREGS includes mxcsr, and we don't want to count | |
1760 | this as one of the xmm regs -- which is why we subtract one. | |
1761 | ||
1762 | Note: kevinb/2003-07-14: Whatever Mark's concerns are about the | |
1763 | FPU registers in the FIXME below apply to the SSE registers as well. | |
1764 | The only problem that I see is that these registers will show up | |
1765 | in "info all-registers" even on CPUs where they don't exist. IMO, | |
1766 | however, if it's a choice between printing them always (even when | |
1767 | they don't exist) or never showing them to the user (even when they | |
1768 | do exist), I prefer the former over the latter. Ideally, of course, | |
1769 | we'd somehow autodetect that we have them (or not) and display them | |
1770 | when we have them and suppress them when we don't. | |
1771 | ||
356a6b3e MK |
1772 | FIXME: kettenis/20020614: They do include the FPU registers for |
1773 | now, which probably is not quite right. */ | |
49ed40de | 1774 | tdep->num_xmm_regs = I386_NUM_XREGS - 1; |
d2a7c97a | 1775 | |
8201327c MK |
1776 | tdep->jb_pc_offset = -1; |
1777 | tdep->struct_return = pcc_struct_return; | |
8201327c MK |
1778 | tdep->sigtramp_start = 0; |
1779 | tdep->sigtramp_end = 0; | |
21d0e8a4 | 1780 | tdep->sigcontext_addr = NULL; |
a3386186 | 1781 | tdep->sc_reg_offset = NULL; |
8201327c | 1782 | tdep->sc_pc_offset = -1; |
21d0e8a4 | 1783 | tdep->sc_sp_offset = -1; |
8201327c | 1784 | |
896fb97d MK |
1785 | /* The format used for `long double' on almost all i386 targets is |
1786 | the i387 extended floating-point format. In fact, of all targets | |
1787 | in the GCC 2.95 tree, only OSF/1 does it different, and insists | |
1788 | on having a `long double' that's not `long' at all. */ | |
1789 | set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext); | |
21d0e8a4 | 1790 | |
66da5fd8 | 1791 | /* Although the i387 extended floating-point has only 80 significant |
896fb97d MK |
1792 | bits, a `long double' actually takes up 96, probably to enforce |
1793 | alignment. */ | |
1794 | set_gdbarch_long_double_bit (gdbarch, 96); | |
1795 | ||
49ed40de KB |
1796 | /* The default ABI includes general-purpose registers, |
1797 | floating-point registers, and the SSE registers. */ | |
1798 | set_gdbarch_num_regs (gdbarch, I386_SSE_NUM_REGS); | |
acd5c798 MK |
1799 | set_gdbarch_register_name (gdbarch, i386_register_name); |
1800 | set_gdbarch_register_type (gdbarch, i386_register_type); | |
21d0e8a4 | 1801 | |
acd5c798 MK |
1802 | /* Register numbers of various important registers. */ |
1803 | set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */ | |
1804 | set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */ | |
1805 | set_gdbarch_ps_regnum (gdbarch, I386_EFLAGS_REGNUM); /* %eflags */ | |
1806 | set_gdbarch_fp0_regnum (gdbarch, I386_ST0_REGNUM); /* %st(0) */ | |
356a6b3e MK |
1807 | |
1808 | /* Use the "default" register numbering scheme for stabs and COFF. */ | |
1809 | set_gdbarch_stab_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum); | |
1810 | set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_stab_reg_to_regnum); | |
1811 | ||
1812 | /* Use the DWARF register numbering scheme for DWARF and DWARF 2. */ | |
1813 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1814 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_dwarf_reg_to_regnum); | |
1815 | ||
1816 | /* We don't define ECOFF_REG_TO_REGNUM, since ECOFF doesn't seem to | |
1817 | be in use on any of the supported i386 targets. */ | |
1818 | ||
61113f8b MK |
1819 | set_gdbarch_print_float_info (gdbarch, i387_print_float_info); |
1820 | ||
8201327c | 1821 | set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target); |
96297dab | 1822 | |
a62cc96e | 1823 | /* Call dummy code. */ |
acd5c798 | 1824 | set_gdbarch_push_dummy_call (gdbarch, i386_push_dummy_call); |
a62cc96e | 1825 | |
ff2e87ac AC |
1826 | set_gdbarch_convert_register_p (gdbarch, i386_convert_register_p); |
1827 | set_gdbarch_register_to_value (gdbarch, i386_register_to_value); | |
1828 | set_gdbarch_value_to_register (gdbarch, i386_value_to_register); | |
b6197528 | 1829 | |
00f8375e | 1830 | set_gdbarch_extract_return_value (gdbarch, i386_extract_return_value); |
3d7f4f49 | 1831 | set_gdbarch_store_return_value (gdbarch, i386_store_return_value); |
00f8375e | 1832 | set_gdbarch_extract_struct_value_address (gdbarch, |
fc08ec52 | 1833 | i386_extract_struct_value_address); |
8201327c MK |
1834 | set_gdbarch_use_struct_convention (gdbarch, i386_use_struct_convention); |
1835 | ||
93924b6b MK |
1836 | set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue); |
1837 | ||
1838 | /* Stack grows downward. */ | |
1839 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1840 | ||
1841 | set_gdbarch_breakpoint_from_pc (gdbarch, i386_breakpoint_from_pc); | |
1842 | set_gdbarch_decr_pc_after_break (gdbarch, 1); | |
1843 | set_gdbarch_function_start_offset (gdbarch, 0); | |
42fdc8df | 1844 | |
42fdc8df | 1845 | set_gdbarch_frame_args_skip (gdbarch, 8); |
8201327c MK |
1846 | set_gdbarch_pc_in_sigtramp (gdbarch, i386_pc_in_sigtramp); |
1847 | ||
28fc6740 | 1848 | /* Wire in the MMX registers. */ |
0f751ff2 | 1849 | set_gdbarch_num_pseudo_regs (gdbarch, i386_num_mmx_regs); |
28fc6740 AC |
1850 | set_gdbarch_pseudo_register_read (gdbarch, i386_pseudo_register_read); |
1851 | set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write); | |
1852 | ||
5e3397bb MK |
1853 | set_gdbarch_print_insn (gdbarch, i386_print_insn); |
1854 | ||
acd5c798 | 1855 | set_gdbarch_unwind_dummy_id (gdbarch, i386_unwind_dummy_id); |
acd5c798 MK |
1856 | |
1857 | set_gdbarch_unwind_pc (gdbarch, i386_unwind_pc); | |
1858 | ||
38c968cf AC |
1859 | /* Add the i386 register groups. */ |
1860 | i386_add_reggroups (gdbarch); | |
1861 | set_gdbarch_register_reggroup_p (gdbarch, i386_register_reggroup_p); | |
1862 | ||
143985b7 AF |
1863 | /* Helper for function argument information. */ |
1864 | set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument); | |
1865 | ||
6405b0a6 | 1866 | /* Hook in the DWARF CFI frame unwinder. */ |
336d1bba | 1867 | frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer); |
6405b0a6 | 1868 | |
acd5c798 | 1869 | frame_base_set_default (gdbarch, &i386_frame_base); |
6c0e89ed | 1870 | |
3ce1502b | 1871 | /* Hook in ABI-specific overrides, if they have been registered. */ |
4be87837 | 1872 | gdbarch_init_osabi (info, gdbarch); |
3ce1502b | 1873 | |
336d1bba AC |
1874 | frame_unwind_append_sniffer (gdbarch, i386_sigtramp_frame_sniffer); |
1875 | frame_unwind_append_sniffer (gdbarch, i386_frame_sniffer); | |
acd5c798 | 1876 | |
a62cc96e AC |
1877 | return gdbarch; |
1878 | } | |
1879 | ||
8201327c MK |
1880 | static enum gdb_osabi |
1881 | i386_coff_osabi_sniffer (bfd *abfd) | |
1882 | { | |
762c5349 MK |
1883 | if (strcmp (bfd_get_target (abfd), "coff-go32-exe") == 0 |
1884 | || strcmp (bfd_get_target (abfd), "coff-go32") == 0) | |
8201327c MK |
1885 | return GDB_OSABI_GO32; |
1886 | ||
1887 | return GDB_OSABI_UNKNOWN; | |
1888 | } | |
1889 | ||
1890 | static enum gdb_osabi | |
1891 | i386_nlm_osabi_sniffer (bfd *abfd) | |
1892 | { | |
1893 | return GDB_OSABI_NETWARE; | |
1894 | } | |
1895 | \f | |
1896 | ||
28e9e0f0 MK |
1897 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
1898 | void _initialize_i386_tdep (void); | |
1899 | ||
c906108c | 1900 | void |
fba45db2 | 1901 | _initialize_i386_tdep (void) |
c906108c | 1902 | { |
a62cc96e AC |
1903 | register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init); |
1904 | ||
fc338970 | 1905 | /* Add the variable that controls the disassembly flavor. */ |
917317f4 JM |
1906 | { |
1907 | struct cmd_list_element *new_cmd; | |
7a292a7a | 1908 | |
917317f4 JM |
1909 | new_cmd = add_set_enum_cmd ("disassembly-flavor", no_class, |
1910 | valid_flavors, | |
1ed2a135 | 1911 | &disassembly_flavor, |
fc338970 MK |
1912 | "\ |
1913 | Set the disassembly flavor, the valid values are \"att\" and \"intel\", \ | |
c906108c | 1914 | and the default value is \"att\".", |
917317f4 | 1915 | &setlist); |
917317f4 JM |
1916 | add_show_from_set (new_cmd, &showlist); |
1917 | } | |
8201327c MK |
1918 | |
1919 | /* Add the variable that controls the convention for returning | |
1920 | structs. */ | |
1921 | { | |
1922 | struct cmd_list_element *new_cmd; | |
1923 | ||
1924 | new_cmd = add_set_enum_cmd ("struct-convention", no_class, | |
5e3397bb | 1925 | valid_conventions, |
8201327c MK |
1926 | &struct_convention, "\ |
1927 | Set the convention for returning small structs, valid values \ | |
1928 | are \"default\", \"pcc\" and \"reg\", and the default value is \"default\".", | |
1929 | &setlist); | |
1930 | add_show_from_set (new_cmd, &showlist); | |
1931 | } | |
1932 | ||
1933 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour, | |
1934 | i386_coff_osabi_sniffer); | |
1935 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_nlm_flavour, | |
1936 | i386_nlm_osabi_sniffer); | |
1937 | ||
05816f70 | 1938 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4, |
8201327c | 1939 | i386_svr4_init_abi); |
05816f70 | 1940 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_GO32, |
8201327c | 1941 | i386_go32_init_abi); |
05816f70 | 1942 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_NETWARE, |
8201327c | 1943 | i386_nw_init_abi); |
38c968cf AC |
1944 | |
1945 | /* Initialize the i386 specific register groups. */ | |
1946 | i386_init_reggroups (); | |
c906108c | 1947 | } |