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