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