Commit | Line | Data |
---|---|---|
748894bf | 1 | /* Target-dependent code for the Motorola 68000 series. |
c6f0559b AC |
2 | |
3 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, | |
4754a64e | 4 | 2001, 2002, 2003, 2004, 2005 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" | |
3f244638 | 24 | #include "dwarf2-frame.h" |
c906108c | 25 | #include "frame.h" |
8de307e0 AS |
26 | #include "frame-base.h" |
27 | #include "frame-unwind.h" | |
f595cb19 | 28 | #include "floatformat.h" |
c906108c SS |
29 | #include "symtab.h" |
30 | #include "gdbcore.h" | |
31 | #include "value.h" | |
32 | #include "gdb_string.h" | |
8de307e0 | 33 | #include "gdb_assert.h" |
7a292a7a | 34 | #include "inferior.h" |
4e052eda | 35 | #include "regcache.h" |
5d3ed2e3 | 36 | #include "arch-utils.h" |
55809acb | 37 | #include "osabi.h" |
a89aa300 | 38 | #include "dis-asm.h" |
32eeb91a AS |
39 | |
40 | #include "m68k-tdep.h" | |
c906108c | 41 | \f |
c5aa993b | 42 | |
89c3b6d3 PDM |
43 | #define P_LINKL_FP 0x480e |
44 | #define P_LINKW_FP 0x4e56 | |
45 | #define P_PEA_FP 0x4856 | |
8de307e0 AS |
46 | #define P_MOVEAL_SP_FP 0x2c4f |
47 | #define P_ADDAW_SP 0xdefc | |
48 | #define P_ADDAL_SP 0xdffc | |
49 | #define P_SUBQW_SP 0x514f | |
50 | #define P_SUBQL_SP 0x518f | |
51 | #define P_LEA_SP_SP 0x4fef | |
52 | #define P_LEA_PC_A5 0x4bfb0170 | |
53 | #define P_FMOVEMX_SP 0xf227 | |
54 | #define P_MOVEL_SP 0x2f00 | |
55 | #define P_MOVEML_SP 0x48e7 | |
89c3b6d3 | 56 | |
103a1597 | 57 | |
103a1597 GS |
58 | #define REGISTER_BYTES_FP (16*4 + 8 + 8*12 + 3*4) |
59 | #define REGISTER_BYTES_NOFP (16*4 + 8) | |
60 | ||
103a1597 | 61 | /* Offset from SP to first arg on stack at first instruction of a function */ |
103a1597 GS |
62 | #define SP_ARG0 (1 * 4) |
63 | ||
103a1597 GS |
64 | #if !defined (BPT_VECTOR) |
65 | #define BPT_VECTOR 0xf | |
66 | #endif | |
67 | ||
f5cf7aa1 | 68 | static const gdb_byte * |
103a1597 GS |
69 | m68k_local_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
70 | { | |
f5cf7aa1 | 71 | static gdb_byte break_insn[] = {0x4e, (0x40 | BPT_VECTOR)}; |
103a1597 GS |
72 | *lenptr = sizeof (break_insn); |
73 | return break_insn; | |
74 | } | |
75 | ||
76 | ||
942dc0e9 | 77 | static int |
5ae5f592 | 78 | m68k_register_bytes_ok (long numbytes) |
942dc0e9 GS |
79 | { |
80 | return ((numbytes == REGISTER_BYTES_FP) | |
81 | || (numbytes == REGISTER_BYTES_NOFP)); | |
82 | } | |
83 | ||
d85fe7f7 AS |
84 | /* Return the GDB type object for the "standard" data type of data in |
85 | register N. This should be int for D0-D7, SR, FPCONTROL and | |
86 | FPSTATUS, long double for FP0-FP7, and void pointer for all others | |
87 | (A0-A7, PC, FPIADDR). Note, for registers which contain | |
88 | addresses return pointer to void, not pointer to char, because we | |
89 | don't want to attempt to print the string after printing the | |
90 | address. */ | |
5d3ed2e3 GS |
91 | |
92 | static struct type * | |
8de307e0 | 93 | m68k_register_type (struct gdbarch *gdbarch, int regnum) |
5d3ed2e3 | 94 | { |
03dac896 AS |
95 | if (regnum >= FP0_REGNUM && regnum <= FP0_REGNUM + 7) |
96 | return builtin_type_m68881_ext; | |
97 | ||
32eeb91a | 98 | if (regnum == M68K_FPI_REGNUM || regnum == PC_REGNUM) |
03dac896 AS |
99 | return builtin_type_void_func_ptr; |
100 | ||
32eeb91a AS |
101 | if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM |
102 | || regnum == PS_REGNUM) | |
03dac896 AS |
103 | return builtin_type_int32; |
104 | ||
32eeb91a | 105 | if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7) |
03dac896 AS |
106 | return builtin_type_void_data_ptr; |
107 | ||
108 | return builtin_type_int32; | |
5d3ed2e3 GS |
109 | } |
110 | ||
111 | /* Function: m68k_register_name | |
112 | Returns the name of the standard m68k register regnum. */ | |
113 | ||
114 | static const char * | |
115 | m68k_register_name (int regnum) | |
116 | { | |
117 | static char *register_names[] = { | |
118 | "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", | |
119 | "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", | |
120 | "ps", "pc", | |
121 | "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7", | |
122 | "fpcontrol", "fpstatus", "fpiaddr", "fpcode", "fpflags" | |
123 | }; | |
124 | ||
125 | if (regnum < 0 || | |
126 | regnum >= sizeof (register_names) / sizeof (register_names[0])) | |
127 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 128 | _("m68k_register_name: illegal register number %d"), regnum); |
5d3ed2e3 GS |
129 | else |
130 | return register_names[regnum]; | |
131 | } | |
e47577ab MK |
132 | \f |
133 | /* Return nonzero if a value of type TYPE stored in register REGNUM | |
134 | needs any special handling. */ | |
135 | ||
136 | static int | |
137 | m68k_convert_register_p (int regnum, struct type *type) | |
138 | { | |
139 | return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7); | |
140 | } | |
141 | ||
142 | /* Read a value of type TYPE from register REGNUM in frame FRAME, and | |
143 | return its contents in TO. */ | |
144 | ||
145 | static void | |
146 | m68k_register_to_value (struct frame_info *frame, int regnum, | |
f5cf7aa1 | 147 | struct type *type, gdb_byte *to) |
e47577ab | 148 | { |
f5cf7aa1 | 149 | gdb_byte from[M68K_MAX_REGISTER_SIZE]; |
e47577ab MK |
150 | |
151 | /* We only support floating-point values. */ | |
152 | if (TYPE_CODE (type) != TYPE_CODE_FLT) | |
153 | { | |
8a3fe4f8 AC |
154 | warning (_("Cannot convert floating-point register value " |
155 | "to non-floating-point type.")); | |
e47577ab MK |
156 | return; |
157 | } | |
158 | ||
159 | /* Convert to TYPE. This should be a no-op if TYPE is equivalent to | |
160 | the extended floating-point format used by the FPU. */ | |
161 | get_frame_register (frame, regnum, from); | |
162 | convert_typed_floating (from, builtin_type_m68881_ext, to, type); | |
163 | } | |
164 | ||
165 | /* Write the contents FROM of a value of type TYPE into register | |
166 | REGNUM in frame FRAME. */ | |
167 | ||
168 | static void | |
169 | m68k_value_to_register (struct frame_info *frame, int regnum, | |
f5cf7aa1 | 170 | struct type *type, const gdb_byte *from) |
e47577ab | 171 | { |
f5cf7aa1 | 172 | gdb_byte to[M68K_MAX_REGISTER_SIZE]; |
e47577ab MK |
173 | |
174 | /* We only support floating-point values. */ | |
175 | if (TYPE_CODE (type) != TYPE_CODE_FLT) | |
176 | { | |
8a3fe4f8 AC |
177 | warning (_("Cannot convert non-floating-point type " |
178 | "to floating-point register value.")); | |
e47577ab MK |
179 | return; |
180 | } | |
181 | ||
182 | /* Convert from TYPE. This should be a no-op if TYPE is equivalent | |
183 | to the extended floating-point format used by the FPU. */ | |
184 | convert_typed_floating (from, type, to, builtin_type_m68881_ext); | |
185 | put_frame_register (frame, regnum, to); | |
186 | } | |
187 | ||
8de307e0 | 188 | \f |
f595cb19 MK |
189 | /* There is a fair number of calling conventions that are in somewhat |
190 | wide use. The 68000/08/10 don't support an FPU, not even as a | |
191 | coprocessor. All function return values are stored in %d0/%d1. | |
192 | Structures are returned in a static buffer, a pointer to which is | |
193 | returned in %d0. This means that functions returning a structure | |
194 | are not re-entrant. To avoid this problem some systems use a | |
195 | convention where the caller passes a pointer to a buffer in %a1 | |
196 | where the return values is to be stored. This convention is the | |
197 | default, and is implemented in the function m68k_return_value. | |
198 | ||
199 | The 68020/030/040/060 do support an FPU, either as a coprocessor | |
200 | (68881/2) or built-in (68040/68060). That's why System V release 4 | |
201 | (SVR4) instroduces a new calling convention specified by the SVR4 | |
202 | psABI. Integer values are returned in %d0/%d1, pointer return | |
203 | values in %a0 and floating values in %fp0. When calling functions | |
204 | returning a structure the caller should pass a pointer to a buffer | |
205 | for the return value in %a0. This convention is implemented in the | |
206 | function m68k_svr4_return_value, and by appropriately setting the | |
207 | struct_value_regnum member of `struct gdbarch_tdep'. | |
208 | ||
209 | GNU/Linux returns values in the same way as SVR4 does, but uses %a1 | |
210 | for passing the structure return value buffer. | |
211 | ||
212 | GCC can also generate code where small structures are returned in | |
213 | %d0/%d1 instead of in memory by using -freg-struct-return. This is | |
214 | the default on NetBSD a.out, OpenBSD and GNU/Linux and several | |
215 | embedded systems. This convention is implemented by setting the | |
216 | struct_return member of `struct gdbarch_tdep' to reg_struct_return. */ | |
217 | ||
218 | /* Read a function return value of TYPE from REGCACHE, and copy that | |
8de307e0 | 219 | into VALBUF. */ |
942dc0e9 GS |
220 | |
221 | static void | |
8de307e0 | 222 | m68k_extract_return_value (struct type *type, struct regcache *regcache, |
f5cf7aa1 | 223 | gdb_byte *valbuf) |
942dc0e9 | 224 | { |
8de307e0 | 225 | int len = TYPE_LENGTH (type); |
f5cf7aa1 | 226 | gdb_byte buf[M68K_MAX_REGISTER_SIZE]; |
942dc0e9 | 227 | |
8de307e0 AS |
228 | if (len <= 4) |
229 | { | |
230 | regcache_raw_read (regcache, M68K_D0_REGNUM, buf); | |
231 | memcpy (valbuf, buf + (4 - len), len); | |
232 | } | |
233 | else if (len <= 8) | |
234 | { | |
235 | regcache_raw_read (regcache, M68K_D0_REGNUM, buf); | |
236 | memcpy (valbuf, buf + (8 - len), len - 4); | |
f5cf7aa1 | 237 | regcache_raw_read (regcache, M68K_D1_REGNUM, valbuf + (len - 4)); |
8de307e0 AS |
238 | } |
239 | else | |
240 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 241 | _("Cannot extract return value of %d bytes long."), len); |
942dc0e9 GS |
242 | } |
243 | ||
942dc0e9 | 244 | static void |
f595cb19 | 245 | m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache, |
f5cf7aa1 | 246 | gdb_byte *valbuf) |
942dc0e9 | 247 | { |
8de307e0 | 248 | int len = TYPE_LENGTH (type); |
f5cf7aa1 | 249 | gdb_byte buf[M68K_MAX_REGISTER_SIZE]; |
942dc0e9 | 250 | |
f595cb19 | 251 | if (TYPE_CODE (type) == TYPE_CODE_FLT) |
8de307e0 | 252 | { |
f595cb19 MK |
253 | regcache_raw_read (regcache, M68K_FP0_REGNUM, buf); |
254 | convert_typed_floating (buf, builtin_type_m68881_ext, valbuf, type); | |
8de307e0 | 255 | } |
f595cb19 MK |
256 | else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4) |
257 | regcache_raw_read (regcache, M68K_A0_REGNUM, valbuf); | |
258 | else | |
259 | m68k_extract_return_value (type, regcache, valbuf); | |
260 | } | |
261 | ||
262 | /* Write a function return value of TYPE from VALBUF into REGCACHE. */ | |
263 | ||
264 | static void | |
265 | m68k_store_return_value (struct type *type, struct regcache *regcache, | |
f5cf7aa1 | 266 | const gdb_byte *valbuf) |
f595cb19 MK |
267 | { |
268 | int len = TYPE_LENGTH (type); | |
942dc0e9 | 269 | |
8de307e0 AS |
270 | if (len <= 4) |
271 | regcache_raw_write_part (regcache, M68K_D0_REGNUM, 4 - len, len, valbuf); | |
272 | else if (len <= 8) | |
273 | { | |
f595cb19 | 274 | regcache_raw_write_part (regcache, M68K_D0_REGNUM, 8 - len, |
8de307e0 | 275 | len - 4, valbuf); |
f5cf7aa1 | 276 | regcache_raw_write (regcache, M68K_D1_REGNUM, valbuf + (len - 4)); |
8de307e0 AS |
277 | } |
278 | else | |
279 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 280 | _("Cannot store return value of %d bytes long."), len); |
8de307e0 | 281 | } |
942dc0e9 | 282 | |
f595cb19 MK |
283 | static void |
284 | m68k_svr4_store_return_value (struct type *type, struct regcache *regcache, | |
f5cf7aa1 | 285 | const gdb_byte *valbuf) |
942dc0e9 | 286 | { |
f595cb19 | 287 | int len = TYPE_LENGTH (type); |
8de307e0 | 288 | |
f595cb19 MK |
289 | if (TYPE_CODE (type) == TYPE_CODE_FLT) |
290 | { | |
f5cf7aa1 | 291 | gdb_byte buf[M68K_MAX_REGISTER_SIZE]; |
f595cb19 MK |
292 | convert_typed_floating (valbuf, type, buf, builtin_type_m68881_ext); |
293 | regcache_raw_write (regcache, M68K_FP0_REGNUM, buf); | |
294 | } | |
295 | else if (TYPE_CODE (type) == TYPE_CODE_PTR && len == 4) | |
296 | { | |
297 | regcache_raw_write (regcache, M68K_A0_REGNUM, valbuf); | |
298 | regcache_raw_write (regcache, M68K_D0_REGNUM, valbuf); | |
299 | } | |
300 | else | |
301 | m68k_store_return_value (type, regcache, valbuf); | |
942dc0e9 GS |
302 | } |
303 | ||
f595cb19 MK |
304 | /* Return non-zero if TYPE, which is assumed to be a structure or |
305 | union type, should be returned in registers for architecture | |
306 | GDBARCH. */ | |
307 | ||
c481dac7 | 308 | static int |
f595cb19 | 309 | m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type) |
c481dac7 | 310 | { |
f595cb19 MK |
311 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
312 | enum type_code code = TYPE_CODE (type); | |
313 | int len = TYPE_LENGTH (type); | |
c481dac7 | 314 | |
f595cb19 MK |
315 | gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION); |
316 | ||
317 | if (tdep->struct_return == pcc_struct_return) | |
318 | return 0; | |
319 | ||
320 | return (len == 1 || len == 2 || len == 4 || len == 8); | |
c481dac7 AS |
321 | } |
322 | ||
f595cb19 MK |
323 | /* Determine, for architecture GDBARCH, how a return value of TYPE |
324 | should be returned. If it is supposed to be returned in registers, | |
325 | and READBUF is non-zero, read the appropriate value from REGCACHE, | |
326 | and copy it into READBUF. If WRITEBUF is non-zero, write the value | |
327 | from WRITEBUF into REGCACHE. */ | |
328 | ||
329 | static enum return_value_convention | |
330 | m68k_return_value (struct gdbarch *gdbarch, struct type *type, | |
f5cf7aa1 MK |
331 | struct regcache *regcache, gdb_byte *readbuf, |
332 | const gdb_byte *writebuf) | |
f595cb19 MK |
333 | { |
334 | enum type_code code = TYPE_CODE (type); | |
335 | ||
1c845060 MK |
336 | /* GCC returns a `long double' in memory too. */ |
337 | if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
338 | && !m68k_reg_struct_return_p (gdbarch, type)) | |
339 | || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12)) | |
340 | { | |
341 | /* The default on m68k is to return structures in static memory. | |
342 | Consequently a function must return the address where we can | |
343 | find the return value. */ | |
f595cb19 | 344 | |
1c845060 MK |
345 | if (readbuf) |
346 | { | |
347 | ULONGEST addr; | |
348 | ||
349 | regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr); | |
350 | read_memory (addr, readbuf, TYPE_LENGTH (type)); | |
351 | } | |
352 | ||
353 | return RETURN_VALUE_ABI_RETURNS_ADDRESS; | |
354 | } | |
f595cb19 MK |
355 | |
356 | if (readbuf) | |
357 | m68k_extract_return_value (type, regcache, readbuf); | |
358 | if (writebuf) | |
359 | m68k_store_return_value (type, regcache, writebuf); | |
360 | ||
361 | return RETURN_VALUE_REGISTER_CONVENTION; | |
362 | } | |
363 | ||
364 | static enum return_value_convention | |
365 | m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *type, | |
f5cf7aa1 MK |
366 | struct regcache *regcache, gdb_byte *readbuf, |
367 | const gdb_byte *writebuf) | |
f595cb19 MK |
368 | { |
369 | enum type_code code = TYPE_CODE (type); | |
370 | ||
371 | if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
372 | && !m68k_reg_struct_return_p (gdbarch, type)) | |
51da707a MK |
373 | { |
374 | /* The System V ABI says that: | |
375 | ||
376 | "A function returning a structure or union also sets %a0 to | |
377 | the value it finds in %a0. Thus when the caller receives | |
378 | control again, the address of the returned object resides in | |
379 | register %a0." | |
380 | ||
381 | So the ABI guarantees that we can always find the return | |
382 | value just after the function has returned. */ | |
383 | ||
384 | if (readbuf) | |
385 | { | |
386 | ULONGEST addr; | |
387 | ||
388 | regcache_raw_read_unsigned (regcache, M68K_A0_REGNUM, &addr); | |
389 | read_memory (addr, readbuf, TYPE_LENGTH (type)); | |
390 | } | |
391 | ||
392 | return RETURN_VALUE_ABI_RETURNS_ADDRESS; | |
393 | } | |
f595cb19 MK |
394 | |
395 | /* This special case is for structures consisting of a single | |
396 | `float' or `double' member. These structures are returned in | |
397 | %fp0. For these structures, we call ourselves recursively, | |
398 | changing TYPE into the type of the first member of the structure. | |
399 | Since that should work for all structures that have only one | |
400 | member, we don't bother to check the member's type here. */ | |
401 | if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1) | |
402 | { | |
403 | type = check_typedef (TYPE_FIELD_TYPE (type, 0)); | |
404 | return m68k_svr4_return_value (gdbarch, type, regcache, | |
405 | readbuf, writebuf); | |
406 | } | |
407 | ||
408 | if (readbuf) | |
409 | m68k_svr4_extract_return_value (type, regcache, readbuf); | |
410 | if (writebuf) | |
411 | m68k_svr4_store_return_value (type, regcache, writebuf); | |
412 | ||
413 | return RETURN_VALUE_REGISTER_CONVENTION; | |
414 | } | |
415 | \f | |
392a587b | 416 | |
8de307e0 | 417 | static CORE_ADDR |
7d9b040b | 418 | m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
8de307e0 AS |
419 | struct regcache *regcache, CORE_ADDR bp_addr, int nargs, |
420 | struct value **args, CORE_ADDR sp, int struct_return, | |
421 | CORE_ADDR struct_addr) | |
7f8e7424 | 422 | { |
f595cb19 | 423 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
f5cf7aa1 | 424 | gdb_byte buf[4]; |
8de307e0 AS |
425 | int i; |
426 | ||
427 | /* Push arguments in reverse order. */ | |
428 | for (i = nargs - 1; i >= 0; i--) | |
429 | { | |
4754a64e | 430 | struct type *value_type = value_enclosing_type (args[i]); |
c481dac7 | 431 | int len = TYPE_LENGTH (value_type); |
8de307e0 | 432 | int container_len = (len + 3) & ~3; |
c481dac7 AS |
433 | int offset; |
434 | ||
435 | /* Non-scalars bigger than 4 bytes are left aligned, others are | |
436 | right aligned. */ | |
437 | if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT | |
438 | || TYPE_CODE (value_type) == TYPE_CODE_UNION | |
439 | || TYPE_CODE (value_type) == TYPE_CODE_ARRAY) | |
440 | && len > 4) | |
441 | offset = 0; | |
442 | else | |
443 | offset = container_len - len; | |
8de307e0 | 444 | sp -= container_len; |
46615f07 | 445 | write_memory (sp + offset, value_contents_all (args[i]), len); |
8de307e0 AS |
446 | } |
447 | ||
c481dac7 | 448 | /* Store struct value address. */ |
8de307e0 AS |
449 | if (struct_return) |
450 | { | |
8de307e0 | 451 | store_unsigned_integer (buf, 4, struct_addr); |
f595cb19 | 452 | regcache_cooked_write (regcache, tdep->struct_value_regnum, buf); |
8de307e0 AS |
453 | } |
454 | ||
455 | /* Store return address. */ | |
456 | sp -= 4; | |
457 | store_unsigned_integer (buf, 4, bp_addr); | |
458 | write_memory (sp, buf, 4); | |
459 | ||
460 | /* Finally, update the stack pointer... */ | |
461 | store_unsigned_integer (buf, 4, sp); | |
462 | regcache_cooked_write (regcache, M68K_SP_REGNUM, buf); | |
463 | ||
464 | /* ...and fake a frame pointer. */ | |
465 | regcache_cooked_write (regcache, M68K_FP_REGNUM, buf); | |
466 | ||
467 | /* DWARF2/GCC uses the stack address *before* the function call as a | |
468 | frame's CFA. */ | |
469 | return sp + 8; | |
7f8e7424 | 470 | } |
8de307e0 AS |
471 | \f |
472 | struct m68k_frame_cache | |
473 | { | |
474 | /* Base address. */ | |
475 | CORE_ADDR base; | |
476 | CORE_ADDR sp_offset; | |
477 | CORE_ADDR pc; | |
7f8e7424 | 478 | |
8de307e0 AS |
479 | /* Saved registers. */ |
480 | CORE_ADDR saved_regs[M68K_NUM_REGS]; | |
481 | CORE_ADDR saved_sp; | |
7f8e7424 | 482 | |
8de307e0 AS |
483 | /* Stack space reserved for local variables. */ |
484 | long locals; | |
485 | }; | |
c906108c | 486 | |
8de307e0 AS |
487 | /* Allocate and initialize a frame cache. */ |
488 | ||
489 | static struct m68k_frame_cache * | |
490 | m68k_alloc_frame_cache (void) | |
c906108c | 491 | { |
8de307e0 AS |
492 | struct m68k_frame_cache *cache; |
493 | int i; | |
c906108c | 494 | |
8de307e0 | 495 | cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache); |
c906108c | 496 | |
8de307e0 AS |
497 | /* Base address. */ |
498 | cache->base = 0; | |
499 | cache->sp_offset = -4; | |
500 | cache->pc = 0; | |
c906108c | 501 | |
8de307e0 AS |
502 | /* Saved registers. We initialize these to -1 since zero is a valid |
503 | offset (that's where %fp is supposed to be stored). */ | |
504 | for (i = 0; i < M68K_NUM_REGS; i++) | |
505 | cache->saved_regs[i] = -1; | |
506 | ||
507 | /* Frameless until proven otherwise. */ | |
508 | cache->locals = -1; | |
509 | ||
510 | return cache; | |
c906108c SS |
511 | } |
512 | ||
8de307e0 AS |
513 | /* Check whether PC points at a code that sets up a new stack frame. |
514 | If so, it updates CACHE and returns the address of the first | |
515 | instruction after the sequence that sets removes the "hidden" | |
516 | argument from the stack or CURRENT_PC, whichever is smaller. | |
517 | Otherwise, return PC. */ | |
c906108c | 518 | |
8de307e0 AS |
519 | static CORE_ADDR |
520 | m68k_analyze_frame_setup (CORE_ADDR pc, CORE_ADDR current_pc, | |
521 | struct m68k_frame_cache *cache) | |
c906108c | 522 | { |
8de307e0 AS |
523 | int op; |
524 | ||
525 | if (pc >= current_pc) | |
526 | return current_pc; | |
c906108c | 527 | |
8de307e0 AS |
528 | op = read_memory_unsigned_integer (pc, 2); |
529 | ||
530 | if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP) | |
c906108c | 531 | { |
8de307e0 AS |
532 | cache->saved_regs[M68K_FP_REGNUM] = 0; |
533 | cache->sp_offset += 4; | |
534 | if (op == P_LINKW_FP) | |
535 | { | |
536 | /* link.w %fp, #-N */ | |
537 | /* link.w %fp, #0; adda.l #-N, %sp */ | |
538 | cache->locals = -read_memory_integer (pc + 2, 2); | |
539 | ||
540 | if (pc + 4 < current_pc && cache->locals == 0) | |
541 | { | |
542 | op = read_memory_unsigned_integer (pc + 4, 2); | |
543 | if (op == P_ADDAL_SP) | |
544 | { | |
545 | cache->locals = read_memory_integer (pc + 6, 4); | |
546 | return pc + 10; | |
547 | } | |
548 | } | |
549 | ||
550 | return pc + 4; | |
551 | } | |
552 | else if (op == P_LINKL_FP) | |
c906108c | 553 | { |
8de307e0 AS |
554 | /* link.l %fp, #-N */ |
555 | cache->locals = -read_memory_integer (pc + 2, 4); | |
556 | return pc + 6; | |
557 | } | |
558 | else | |
559 | { | |
560 | /* pea (%fp); movea.l %sp, %fp */ | |
561 | cache->locals = 0; | |
562 | ||
563 | if (pc + 2 < current_pc) | |
564 | { | |
565 | op = read_memory_unsigned_integer (pc + 2, 2); | |
566 | ||
567 | if (op == P_MOVEAL_SP_FP) | |
568 | { | |
569 | /* move.l %sp, %fp */ | |
570 | return pc + 4; | |
571 | } | |
572 | } | |
573 | ||
574 | return pc + 2; | |
c906108c SS |
575 | } |
576 | } | |
8de307e0 | 577 | else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP) |
c906108c | 578 | { |
8de307e0 AS |
579 | /* subq.[wl] #N,%sp */ |
580 | /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */ | |
581 | cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9; | |
582 | if (pc + 2 < current_pc) | |
c906108c | 583 | { |
8de307e0 AS |
584 | op = read_memory_unsigned_integer (pc + 2, 2); |
585 | if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP) | |
586 | { | |
587 | cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9; | |
588 | return pc + 4; | |
589 | } | |
c906108c | 590 | } |
8de307e0 AS |
591 | return pc + 2; |
592 | } | |
593 | else if (op == P_ADDAW_SP || op == P_LEA_SP_SP) | |
594 | { | |
595 | /* adda.w #-N,%sp */ | |
596 | /* lea (-N,%sp),%sp */ | |
597 | cache->locals = -read_memory_integer (pc + 2, 2); | |
598 | return pc + 4; | |
c906108c | 599 | } |
8de307e0 | 600 | else if (op == P_ADDAL_SP) |
c906108c | 601 | { |
8de307e0 AS |
602 | /* adda.l #-N,%sp */ |
603 | cache->locals = -read_memory_integer (pc + 2, 4); | |
604 | return pc + 6; | |
c906108c | 605 | } |
8de307e0 AS |
606 | |
607 | return pc; | |
c906108c | 608 | } |
c5aa993b | 609 | |
8de307e0 AS |
610 | /* Check whether PC points at code that saves registers on the stack. |
611 | If so, it updates CACHE and returns the address of the first | |
612 | instruction after the register saves or CURRENT_PC, whichever is | |
613 | smaller. Otherwise, return PC. */ | |
c906108c | 614 | |
8de307e0 AS |
615 | static CORE_ADDR |
616 | m68k_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc, | |
617 | struct m68k_frame_cache *cache) | |
618 | { | |
619 | if (cache->locals >= 0) | |
620 | { | |
621 | CORE_ADDR offset; | |
622 | int op; | |
623 | int i, mask, regno; | |
c906108c | 624 | |
8de307e0 AS |
625 | offset = -4 - cache->locals; |
626 | while (pc < current_pc) | |
627 | { | |
628 | op = read_memory_unsigned_integer (pc, 2); | |
629 | if (op == P_FMOVEMX_SP) | |
630 | { | |
631 | /* fmovem.x REGS,-(%sp) */ | |
632 | op = read_memory_unsigned_integer (pc + 2, 2); | |
633 | if ((op & 0xff00) == 0xe000) | |
634 | { | |
635 | mask = op & 0xff; | |
636 | for (i = 0; i < 16; i++, mask >>= 1) | |
637 | { | |
638 | if (mask & 1) | |
639 | { | |
640 | cache->saved_regs[i + M68K_FP0_REGNUM] = offset; | |
641 | offset -= 12; | |
642 | } | |
643 | } | |
644 | pc += 4; | |
645 | } | |
646 | else | |
647 | break; | |
648 | } | |
649 | else if ((op & 0170677) == P_MOVEL_SP) | |
650 | { | |
651 | /* move.l %R,-(%sp) */ | |
652 | regno = ((op & 07000) >> 9) | ((op & 0100) >> 3); | |
653 | cache->saved_regs[regno] = offset; | |
654 | offset -= 4; | |
655 | pc += 2; | |
656 | } | |
657 | else if (op == P_MOVEML_SP) | |
658 | { | |
659 | /* movem.l REGS,-(%sp) */ | |
660 | mask = read_memory_unsigned_integer (pc + 2, 2); | |
661 | for (i = 0; i < 16; i++, mask >>= 1) | |
662 | { | |
663 | if (mask & 1) | |
664 | { | |
665 | cache->saved_regs[15 - i] = offset; | |
666 | offset -= 4; | |
667 | } | |
668 | } | |
669 | pc += 4; | |
670 | } | |
671 | else | |
672 | break; | |
673 | } | |
674 | } | |
675 | ||
676 | return pc; | |
677 | } | |
c906108c | 678 | |
c906108c | 679 | |
8de307e0 AS |
680 | /* Do a full analysis of the prologue at PC and update CACHE |
681 | accordingly. Bail out early if CURRENT_PC is reached. Return the | |
682 | address where the analysis stopped. | |
c906108c | 683 | |
8de307e0 | 684 | We handle all cases that can be generated by gcc. |
c906108c | 685 | |
8de307e0 | 686 | For allocating a stack frame: |
c906108c | 687 | |
8de307e0 AS |
688 | link.w %a6,#-N |
689 | link.l %a6,#-N | |
690 | pea (%fp); move.l %sp,%fp | |
691 | link.w %a6,#0; add.l #-N,%sp | |
692 | subq.l #N,%sp | |
693 | subq.w #N,%sp | |
694 | subq.w #8,%sp; subq.w #N-8,%sp | |
695 | add.w #-N,%sp | |
696 | lea (-N,%sp),%sp | |
697 | add.l #-N,%sp | |
c906108c | 698 | |
8de307e0 | 699 | For saving registers: |
c906108c | 700 | |
8de307e0 AS |
701 | fmovem.x REGS,-(%sp) |
702 | move.l R1,-(%sp) | |
703 | move.l R1,-(%sp); move.l R2,-(%sp) | |
704 | movem.l REGS,-(%sp) | |
c906108c | 705 | |
8de307e0 | 706 | For setting up the PIC register: |
c906108c | 707 | |
8de307e0 | 708 | lea (%pc,N),%a5 |
c906108c | 709 | |
8de307e0 | 710 | */ |
c906108c | 711 | |
eb2e12d7 | 712 | static CORE_ADDR |
8de307e0 AS |
713 | m68k_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc, |
714 | struct m68k_frame_cache *cache) | |
c906108c | 715 | { |
8de307e0 | 716 | unsigned int op; |
c906108c | 717 | |
8de307e0 AS |
718 | pc = m68k_analyze_frame_setup (pc, current_pc, cache); |
719 | pc = m68k_analyze_register_saves (pc, current_pc, cache); | |
720 | if (pc >= current_pc) | |
721 | return current_pc; | |
c906108c | 722 | |
8de307e0 AS |
723 | /* Check for GOT setup. */ |
724 | op = read_memory_unsigned_integer (pc, 4); | |
725 | if (op == P_LEA_PC_A5) | |
c906108c | 726 | { |
8de307e0 AS |
727 | /* lea (%pc,N),%a5 */ |
728 | return pc + 6; | |
c906108c | 729 | } |
8de307e0 AS |
730 | |
731 | return pc; | |
c906108c SS |
732 | } |
733 | ||
8de307e0 | 734 | /* Return PC of first real instruction. */ |
7f8e7424 | 735 | |
8de307e0 AS |
736 | static CORE_ADDR |
737 | m68k_skip_prologue (CORE_ADDR start_pc) | |
c906108c | 738 | { |
8de307e0 AS |
739 | struct m68k_frame_cache cache; |
740 | CORE_ADDR pc; | |
741 | int op; | |
c906108c | 742 | |
8de307e0 AS |
743 | cache.locals = -1; |
744 | pc = m68k_analyze_prologue (start_pc, (CORE_ADDR) -1, &cache); | |
745 | if (cache.locals < 0) | |
746 | return start_pc; | |
747 | return pc; | |
748 | } | |
c906108c | 749 | |
8de307e0 AS |
750 | static CORE_ADDR |
751 | m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
752 | { | |
f5cf7aa1 | 753 | gdb_byte buf[8]; |
7f8e7424 | 754 | |
8de307e0 AS |
755 | frame_unwind_register (next_frame, PC_REGNUM, buf); |
756 | return extract_typed_address (buf, builtin_type_void_func_ptr); | |
757 | } | |
758 | \f | |
759 | /* Normal frames. */ | |
7f8e7424 | 760 | |
8de307e0 AS |
761 | static struct m68k_frame_cache * |
762 | m68k_frame_cache (struct frame_info *next_frame, void **this_cache) | |
763 | { | |
764 | struct m68k_frame_cache *cache; | |
f5cf7aa1 | 765 | gdb_byte buf[4]; |
8de307e0 AS |
766 | int i; |
767 | ||
768 | if (*this_cache) | |
769 | return *this_cache; | |
770 | ||
771 | cache = m68k_alloc_frame_cache (); | |
772 | *this_cache = cache; | |
773 | ||
774 | /* In principle, for normal frames, %fp holds the frame pointer, | |
775 | which holds the base address for the current stack frame. | |
776 | However, for functions that don't need it, the frame pointer is | |
777 | optional. For these "frameless" functions the frame pointer is | |
778 | actually the frame pointer of the calling frame. Signal | |
779 | trampolines are just a special case of a "frameless" function. | |
780 | They (usually) share their frame pointer with the frame that was | |
781 | in progress when the signal occurred. */ | |
782 | ||
783 | frame_unwind_register (next_frame, M68K_FP_REGNUM, buf); | |
784 | cache->base = extract_unsigned_integer (buf, 4); | |
785 | if (cache->base == 0) | |
786 | return cache; | |
787 | ||
788 | /* For normal frames, %pc is stored at 4(%fp). */ | |
789 | cache->saved_regs[M68K_PC_REGNUM] = 4; | |
790 | ||
791 | cache->pc = frame_func_unwind (next_frame); | |
792 | if (cache->pc != 0) | |
793 | m68k_analyze_prologue (cache->pc, frame_pc_unwind (next_frame), cache); | |
794 | ||
795 | if (cache->locals < 0) | |
796 | { | |
797 | /* We didn't find a valid frame, which means that CACHE->base | |
798 | currently holds the frame pointer for our calling frame. If | |
799 | we're at the start of a function, or somewhere half-way its | |
800 | prologue, the function's frame probably hasn't been fully | |
801 | setup yet. Try to reconstruct the base address for the stack | |
802 | frame by looking at the stack pointer. For truly "frameless" | |
803 | functions this might work too. */ | |
804 | ||
805 | frame_unwind_register (next_frame, M68K_SP_REGNUM, buf); | |
806 | cache->base = extract_unsigned_integer (buf, 4) + cache->sp_offset; | |
807 | } | |
7f8e7424 | 808 | |
8de307e0 AS |
809 | /* Now that we have the base address for the stack frame we can |
810 | calculate the value of %sp in the calling frame. */ | |
811 | cache->saved_sp = cache->base + 8; | |
7f8e7424 | 812 | |
8de307e0 AS |
813 | /* Adjust all the saved registers such that they contain addresses |
814 | instead of offsets. */ | |
815 | for (i = 0; i < M68K_NUM_REGS; i++) | |
816 | if (cache->saved_regs[i] != -1) | |
817 | cache->saved_regs[i] += cache->base; | |
c906108c | 818 | |
8de307e0 AS |
819 | return cache; |
820 | } | |
c906108c | 821 | |
8de307e0 AS |
822 | static void |
823 | m68k_frame_this_id (struct frame_info *next_frame, void **this_cache, | |
824 | struct frame_id *this_id) | |
825 | { | |
826 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
c906108c | 827 | |
8de307e0 AS |
828 | /* This marks the outermost frame. */ |
829 | if (cache->base == 0) | |
830 | return; | |
c5aa993b | 831 | |
8de307e0 AS |
832 | /* See the end of m68k_push_dummy_call. */ |
833 | *this_id = frame_id_build (cache->base + 8, cache->pc); | |
834 | } | |
c5aa993b | 835 | |
8de307e0 AS |
836 | static void |
837 | m68k_frame_prev_register (struct frame_info *next_frame, void **this_cache, | |
838 | int regnum, int *optimizedp, | |
839 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
60b04da5 | 840 | int *realnump, gdb_byte *valuep) |
8de307e0 AS |
841 | { |
842 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
843 | ||
844 | gdb_assert (regnum >= 0); | |
845 | ||
846 | if (regnum == M68K_SP_REGNUM && cache->saved_sp) | |
c5aa993b | 847 | { |
8de307e0 AS |
848 | *optimizedp = 0; |
849 | *lvalp = not_lval; | |
850 | *addrp = 0; | |
851 | *realnump = -1; | |
852 | if (valuep) | |
c906108c | 853 | { |
8de307e0 AS |
854 | /* Store the value. */ |
855 | store_unsigned_integer (valuep, 4, cache->saved_sp); | |
89c3b6d3 | 856 | } |
8de307e0 AS |
857 | return; |
858 | } | |
859 | ||
860 | if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1) | |
861 | { | |
862 | *optimizedp = 0; | |
863 | *lvalp = lval_memory; | |
864 | *addrp = cache->saved_regs[regnum]; | |
865 | *realnump = -1; | |
866 | if (valuep) | |
89c3b6d3 | 867 | { |
8de307e0 AS |
868 | /* Read the value in from memory. */ |
869 | read_memory (*addrp, valuep, | |
870 | register_size (current_gdbarch, regnum)); | |
89c3b6d3 | 871 | } |
8de307e0 | 872 | return; |
c906108c | 873 | } |
8de307e0 | 874 | |
00b25ff3 AC |
875 | *optimizedp = 0; |
876 | *lvalp = lval_register; | |
877 | *addrp = 0; | |
878 | *realnump = regnum; | |
879 | if (valuep) | |
880 | frame_unwind_register (next_frame, (*realnump), valuep); | |
8de307e0 AS |
881 | } |
882 | ||
883 | static const struct frame_unwind m68k_frame_unwind = | |
884 | { | |
885 | NORMAL_FRAME, | |
886 | m68k_frame_this_id, | |
887 | m68k_frame_prev_register | |
888 | }; | |
889 | ||
890 | static const struct frame_unwind * | |
336d1bba | 891 | m68k_frame_sniffer (struct frame_info *next_frame) |
8de307e0 AS |
892 | { |
893 | return &m68k_frame_unwind; | |
894 | } | |
895 | \f | |
8de307e0 AS |
896 | static CORE_ADDR |
897 | m68k_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
898 | { | |
899 | struct m68k_frame_cache *cache = m68k_frame_cache (next_frame, this_cache); | |
900 | ||
901 | return cache->base; | |
902 | } | |
903 | ||
904 | static const struct frame_base m68k_frame_base = | |
905 | { | |
906 | &m68k_frame_unwind, | |
907 | m68k_frame_base_address, | |
908 | m68k_frame_base_address, | |
909 | m68k_frame_base_address | |
910 | }; | |
911 | ||
912 | static struct frame_id | |
913 | m68k_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
914 | { | |
f5cf7aa1 | 915 | gdb_byte buf[4]; |
8de307e0 | 916 | CORE_ADDR fp; |
c906108c | 917 | |
8de307e0 AS |
918 | frame_unwind_register (next_frame, M68K_FP_REGNUM, buf); |
919 | fp = extract_unsigned_integer (buf, 4); | |
c906108c | 920 | |
8de307e0 AS |
921 | /* See the end of m68k_push_dummy_call. */ |
922 | return frame_id_build (fp + 8, frame_pc_unwind (next_frame)); | |
923 | } | |
924 | \f | |
c5aa993b | 925 | #ifdef USE_PROC_FS /* Target dependent support for /proc */ |
c906108c SS |
926 | |
927 | #include <sys/procfs.h> | |
928 | ||
c60c0f5f MS |
929 | /* Prototypes for supply_gregset etc. */ |
930 | #include "gregset.h" | |
931 | ||
c906108c | 932 | /* The /proc interface divides the target machine's register set up into |
c5aa993b JM |
933 | two different sets, the general register set (gregset) and the floating |
934 | point register set (fpregset). For each set, there is an ioctl to get | |
935 | the current register set and another ioctl to set the current values. | |
c906108c | 936 | |
c5aa993b JM |
937 | The actual structure passed through the ioctl interface is, of course, |
938 | naturally machine dependent, and is different for each set of registers. | |
939 | For the m68k for example, the general register set is typically defined | |
940 | by: | |
c906108c | 941 | |
c5aa993b | 942 | typedef int gregset_t[18]; |
c906108c | 943 | |
c5aa993b JM |
944 | #define R_D0 0 |
945 | ... | |
946 | #define R_PS 17 | |
c906108c | 947 | |
c5aa993b | 948 | and the floating point set by: |
c906108c | 949 | |
c5aa993b JM |
950 | typedef struct fpregset { |
951 | int f_pcr; | |
952 | int f_psr; | |
953 | int f_fpiaddr; | |
954 | int f_fpregs[8][3]; (8 regs, 96 bits each) | |
955 | } fpregset_t; | |
c906108c | 956 | |
c5aa993b JM |
957 | These routines provide the packing and unpacking of gregset_t and |
958 | fpregset_t formatted data. | |
c906108c SS |
959 | |
960 | */ | |
961 | ||
962 | /* Atari SVR4 has R_SR but not R_PS */ | |
963 | ||
964 | #if !defined (R_PS) && defined (R_SR) | |
965 | #define R_PS R_SR | |
966 | #endif | |
967 | ||
968 | /* Given a pointer to a general register set in /proc format (gregset_t *), | |
c5aa993b JM |
969 | unpack the register contents and supply them as gdb's idea of the current |
970 | register values. */ | |
c906108c SS |
971 | |
972 | void | |
fba45db2 | 973 | supply_gregset (gregset_t *gregsetp) |
c906108c | 974 | { |
52f0bd74 AC |
975 | int regi; |
976 | greg_t *regp = (greg_t *) gregsetp; | |
c906108c | 977 | |
c5aa993b | 978 | for (regi = 0; regi < R_PC; regi++) |
c906108c | 979 | { |
23a6d369 | 980 | regcache_raw_supply (current_regcache, regi, (char *) (regp + regi)); |
c906108c | 981 | } |
23a6d369 AC |
982 | regcache_raw_supply (current_regcache, PS_REGNUM, (char *) (regp + R_PS)); |
983 | regcache_raw_supply (current_regcache, PC_REGNUM, (char *) (regp + R_PC)); | |
c906108c SS |
984 | } |
985 | ||
986 | void | |
fba45db2 | 987 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c | 988 | { |
52f0bd74 AC |
989 | int regi; |
990 | greg_t *regp = (greg_t *) gregsetp; | |
c906108c | 991 | |
c5aa993b | 992 | for (regi = 0; regi < R_PC; regi++) |
c906108c | 993 | { |
8de307e0 | 994 | if (regno == -1 || regno == regi) |
822c9732 | 995 | regcache_raw_collect (current_regcache, regi, regp + regi); |
c906108c | 996 | } |
8de307e0 | 997 | if (regno == -1 || regno == PS_REGNUM) |
822c9732 | 998 | regcache_raw_collect (current_regcache, PS_REGNUM, regp + R_PS); |
8de307e0 | 999 | if (regno == -1 || regno == PC_REGNUM) |
822c9732 | 1000 | regcache_raw_collect (current_regcache, PC_REGNUM, regp + R_PC); |
c906108c SS |
1001 | } |
1002 | ||
1003 | #if defined (FP0_REGNUM) | |
1004 | ||
1005 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
1006 | (fpregset_t *), unpack the register contents and supply them as gdb's |
1007 | idea of the current floating point register values. */ | |
c906108c | 1008 | |
c5aa993b | 1009 | void |
fba45db2 | 1010 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c | 1011 | { |
52f0bd74 | 1012 | int regi; |
c906108c | 1013 | char *from; |
c5aa993b | 1014 | |
32eeb91a | 1015 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c | 1016 | { |
c5aa993b | 1017 | from = (char *) &(fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); |
23a6d369 | 1018 | regcache_raw_supply (current_regcache, regi, from); |
c906108c | 1019 | } |
23a6d369 AC |
1020 | regcache_raw_supply (current_regcache, M68K_FPC_REGNUM, |
1021 | (char *) &(fpregsetp->f_pcr)); | |
1022 | regcache_raw_supply (current_regcache, M68K_FPS_REGNUM, | |
1023 | (char *) &(fpregsetp->f_psr)); | |
1024 | regcache_raw_supply (current_regcache, M68K_FPI_REGNUM, | |
1025 | (char *) &(fpregsetp->f_fpiaddr)); | |
c906108c SS |
1026 | } |
1027 | ||
1028 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
1029 | (fpregset_t *), update the register specified by REGNO from gdb's idea |
1030 | of the current floating point register set. If REGNO is -1, update | |
1031 | them all. */ | |
c906108c SS |
1032 | |
1033 | void | |
fba45db2 | 1034 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
1035 | { |
1036 | int regi; | |
c906108c | 1037 | |
32eeb91a | 1038 | for (regi = FP0_REGNUM; regi < M68K_FPC_REGNUM; regi++) |
c906108c | 1039 | { |
8de307e0 | 1040 | if (regno == -1 || regno == regi) |
822c9732 AC |
1041 | regcache_raw_collect (current_regcache, regi, |
1042 | &fpregsetp->f_fpregs[regi - FP0_REGNUM][0]); | |
c906108c | 1043 | } |
8de307e0 | 1044 | if (regno == -1 || regno == M68K_FPC_REGNUM) |
822c9732 AC |
1045 | regcache_raw_collect (current_regcache, M68K_FPC_REGNUM, |
1046 | &fpregsetp->f_pcr); | |
8de307e0 | 1047 | if (regno == -1 || regno == M68K_FPS_REGNUM) |
822c9732 AC |
1048 | regcache_raw_collect (current_regcache, M68K_FPS_REGNUM, |
1049 | &fpregsetp->f_psr); | |
8de307e0 | 1050 | if (regno == -1 || regno == M68K_FPI_REGNUM) |
822c9732 AC |
1051 | regcache_raw_collect (current_regcache, M68K_FPI_REGNUM, |
1052 | &fpregsetp->f_fpiaddr); | |
c906108c SS |
1053 | } |
1054 | ||
c5aa993b | 1055 | #endif /* defined (FP0_REGNUM) */ |
c906108c | 1056 | |
c5aa993b | 1057 | #endif /* USE_PROC_FS */ |
c906108c | 1058 | |
c906108c SS |
1059 | /* Figure out where the longjmp will land. Slurp the args out of the stack. |
1060 | We expect the first arg to be a pointer to the jmp_buf structure from which | |
1061 | we extract the pc (JB_PC) that we will land at. The pc is copied into PC. | |
1062 | This routine returns true on success. */ | |
1063 | ||
c34d127c | 1064 | static int |
f4281f55 | 1065 | m68k_get_longjmp_target (CORE_ADDR *pc) |
c906108c | 1066 | { |
f5cf7aa1 | 1067 | gdb_byte *buf; |
c906108c | 1068 | CORE_ADDR sp, jb_addr; |
eb2e12d7 AS |
1069 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
1070 | ||
1071 | if (tdep->jb_pc < 0) | |
1072 | { | |
1073 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 1074 | _("m68k_get_longjmp_target: not implemented")); |
eb2e12d7 AS |
1075 | return 0; |
1076 | } | |
c906108c | 1077 | |
35fc8285 | 1078 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c5aa993b | 1079 | sp = read_register (SP_REGNUM); |
c906108c | 1080 | |
b5d78d39 GS |
1081 | if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */ |
1082 | buf, TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
c906108c SS |
1083 | return 0; |
1084 | ||
7c0b4a20 | 1085 | jb_addr = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c | 1086 | |
eb2e12d7 | 1087 | if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf, |
c906108c SS |
1088 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) |
1089 | return 0; | |
1090 | ||
7c0b4a20 | 1091 | *pc = extract_unsigned_integer (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
1092 | return 1; |
1093 | } | |
f595cb19 MK |
1094 | \f |
1095 | ||
1096 | /* System V Release 4 (SVR4). */ | |
1097 | ||
1098 | void | |
1099 | m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1100 | { | |
1101 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1102 | ||
1103 | /* SVR4 uses a different calling convention. */ | |
1104 | set_gdbarch_return_value (gdbarch, m68k_svr4_return_value); | |
1105 | ||
1106 | /* SVR4 uses %a0 instead of %a1. */ | |
1107 | tdep->struct_value_regnum = M68K_A0_REGNUM; | |
1108 | } | |
1109 | \f | |
c906108c | 1110 | |
152d9db6 GS |
1111 | /* Function: m68k_gdbarch_init |
1112 | Initializer function for the m68k gdbarch vector. | |
1113 | Called by gdbarch. Sets up the gdbarch vector(s) for this target. */ | |
1114 | ||
1115 | static struct gdbarch * | |
1116 | m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1117 | { | |
1118 | struct gdbarch_tdep *tdep = NULL; | |
1119 | struct gdbarch *gdbarch; | |
1120 | ||
1121 | /* find a candidate among the list of pre-declared architectures. */ | |
1122 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1123 | if (arches != NULL) | |
1124 | return (arches->gdbarch); | |
1125 | ||
eb2e12d7 AS |
1126 | tdep = xmalloc (sizeof (struct gdbarch_tdep)); |
1127 | gdbarch = gdbarch_alloc (&info, tdep); | |
152d9db6 | 1128 | |
5d3ed2e3 GS |
1129 | set_gdbarch_long_double_format (gdbarch, &floatformat_m68881_ext); |
1130 | set_gdbarch_long_double_bit (gdbarch, 96); | |
1131 | ||
5d3ed2e3 | 1132 | set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue); |
103a1597 | 1133 | set_gdbarch_breakpoint_from_pc (gdbarch, m68k_local_breakpoint_from_pc); |
5d3ed2e3 GS |
1134 | |
1135 | /* Stack grows down. */ | |
1136 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
6300c360 GS |
1137 | |
1138 | set_gdbarch_believe_pcc_promotion (gdbarch, 1); | |
942dc0e9 GS |
1139 | set_gdbarch_decr_pc_after_break (gdbarch, 2); |
1140 | ||
6300c360 | 1141 | set_gdbarch_frame_args_skip (gdbarch, 8); |
942dc0e9 | 1142 | |
8de307e0 | 1143 | set_gdbarch_register_type (gdbarch, m68k_register_type); |
5d3ed2e3 | 1144 | set_gdbarch_register_name (gdbarch, m68k_register_name); |
942dc0e9 GS |
1145 | set_gdbarch_num_regs (gdbarch, 29); |
1146 | set_gdbarch_register_bytes_ok (gdbarch, m68k_register_bytes_ok); | |
32eeb91a | 1147 | set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM); |
32eeb91a AS |
1148 | set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM); |
1149 | set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM); | |
1150 | set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM); | |
e47577ab MK |
1151 | set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p); |
1152 | set_gdbarch_register_to_value (gdbarch, m68k_register_to_value); | |
1153 | set_gdbarch_value_to_register (gdbarch, m68k_value_to_register); | |
a2c6a6d5 | 1154 | |
8de307e0 | 1155 | set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call); |
f595cb19 | 1156 | set_gdbarch_return_value (gdbarch, m68k_return_value); |
6c0e89ed | 1157 | |
650fcc91 AS |
1158 | /* Disassembler. */ |
1159 | set_gdbarch_print_insn (gdbarch, print_insn_m68k); | |
1160 | ||
eb2e12d7 AS |
1161 | #if defined JB_PC && defined JB_ELEMENT_SIZE |
1162 | tdep->jb_pc = JB_PC; | |
1163 | tdep->jb_elt_size = JB_ELEMENT_SIZE; | |
1164 | #else | |
1165 | tdep->jb_pc = -1; | |
1166 | #endif | |
f595cb19 | 1167 | tdep->struct_value_regnum = M68K_A1_REGNUM; |
66894781 | 1168 | tdep->struct_return = reg_struct_return; |
8de307e0 AS |
1169 | |
1170 | /* Frame unwinder. */ | |
1171 | set_gdbarch_unwind_dummy_id (gdbarch, m68k_unwind_dummy_id); | |
1172 | set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc); | |
3f244638 AS |
1173 | |
1174 | /* Hook in the DWARF CFI frame unwinder. */ | |
1175 | frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer); | |
1176 | ||
8de307e0 | 1177 | frame_base_set_default (gdbarch, &m68k_frame_base); |
eb2e12d7 | 1178 | |
55809acb AS |
1179 | /* Hook in ABI-specific overrides, if they have been registered. */ |
1180 | gdbarch_init_osabi (info, gdbarch); | |
1181 | ||
eb2e12d7 AS |
1182 | /* Now we have tuned the configuration, set a few final things, |
1183 | based on what the OS ABI has told us. */ | |
1184 | ||
1185 | if (tdep->jb_pc >= 0) | |
1186 | set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target); | |
1187 | ||
336d1bba | 1188 | frame_unwind_append_sniffer (gdbarch, m68k_frame_sniffer); |
8de307e0 | 1189 | |
152d9db6 GS |
1190 | return gdbarch; |
1191 | } | |
1192 | ||
1193 | ||
1194 | static void | |
1195 | m68k_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
1196 | { | |
eb2e12d7 | 1197 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
152d9db6 | 1198 | |
eb2e12d7 AS |
1199 | if (tdep == NULL) |
1200 | return; | |
152d9db6 | 1201 | } |
2acceee2 | 1202 | |
a78f21af AC |
1203 | extern initialize_file_ftype _initialize_m68k_tdep; /* -Wmissing-prototypes */ |
1204 | ||
c906108c | 1205 | void |
fba45db2 | 1206 | _initialize_m68k_tdep (void) |
c906108c | 1207 | { |
152d9db6 | 1208 | gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep); |
c906108c | 1209 | } |