Remove path name from test case
[binutils-gdb.git] / gdb / m68k-tdep.c
1 /* Target-dependent code for the Motorola 68000 series.
2
3 Copyright (C) 1990-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "dwarf2/frame.h"
22 #include "frame.h"
23 #include "frame-base.h"
24 #include "frame-unwind.h"
25 #include "gdbtypes.h"
26 #include "symtab.h"
27 #include "gdbcore.h"
28 #include "value.h"
29 #include "inferior.h"
30 #include "regcache.h"
31 #include "arch-utils.h"
32 #include "osabi.h"
33 #include "dis-asm.h"
34 #include "target-descriptions.h"
35 #include "floatformat.h"
36 #include "target-float.h"
37 #include "elf-bfd.h"
38 #include "elf/m68k.h"
39
40 #include "m68k-tdep.h"
41 \f
42
43 #define P_LINKL_FP 0x480e
44 #define P_LINKW_FP 0x4e56
45 #define P_PEA_FP 0x4856
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
56
57 /* Offset from SP to first arg on stack at first instruction of a function. */
58 #define SP_ARG0 (1 * 4)
59
60 #if !defined (BPT_VECTOR)
61 #define BPT_VECTOR 0xf
62 #endif
63
64 constexpr gdb_byte m68k_break_insn[] = {0x4e, (0x40 | BPT_VECTOR)};
65
66 typedef BP_MANIPULATION (m68k_break_insn) m68k_breakpoint;
67 \f
68
69 /* Construct types for ISA-specific registers. */
70 static struct type *
71 m68k_ps_type (struct gdbarch *gdbarch)
72 {
73 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
74
75 if (!tdep->m68k_ps_type)
76 {
77 struct type *type;
78
79 type = arch_flags_type (gdbarch, "builtin_type_m68k_ps", 32);
80 append_flags_type_flag (type, 0, "C");
81 append_flags_type_flag (type, 1, "V");
82 append_flags_type_flag (type, 2, "Z");
83 append_flags_type_flag (type, 3, "N");
84 append_flags_type_flag (type, 4, "X");
85 append_flags_type_flag (type, 8, "I0");
86 append_flags_type_flag (type, 9, "I1");
87 append_flags_type_flag (type, 10, "I2");
88 append_flags_type_flag (type, 12, "M");
89 append_flags_type_flag (type, 13, "S");
90 append_flags_type_flag (type, 14, "T0");
91 append_flags_type_flag (type, 15, "T1");
92
93 tdep->m68k_ps_type = type;
94 }
95
96 return tdep->m68k_ps_type;
97 }
98
99 static struct type *
100 m68881_ext_type (struct gdbarch *gdbarch)
101 {
102 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
103
104 if (!tdep->m68881_ext_type)
105 {
106 type_allocator alloc (gdbarch);
107 tdep->m68881_ext_type
108 = init_float_type (alloc, -1, "builtin_type_m68881_ext",
109 floatformats_m68881_ext);
110 }
111
112 return tdep->m68881_ext_type;
113 }
114
115 /* Return the GDB type object for the "standard" data type of data in
116 register N. This should be int for D0-D7, SR, FPCONTROL and
117 FPSTATUS, long double for FP0-FP7, and void pointer for all others
118 (A0-A7, PC, FPIADDR). Note, for registers which contain
119 addresses return pointer to void, not pointer to char, because we
120 don't want to attempt to print the string after printing the
121 address. */
122
123 static struct type *
124 m68k_register_type (struct gdbarch *gdbarch, int regnum)
125 {
126 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
127
128 if (tdep->fpregs_present)
129 {
130 if (regnum >= gdbarch_fp0_regnum (gdbarch)
131 && regnum <= gdbarch_fp0_regnum (gdbarch) + 7)
132 {
133 if (tdep->flavour == m68k_coldfire_flavour)
134 return builtin_type (gdbarch)->builtin_double;
135 else
136 return m68881_ext_type (gdbarch);
137 }
138
139 if (regnum == M68K_FPI_REGNUM)
140 return builtin_type (gdbarch)->builtin_func_ptr;
141
142 if (regnum == M68K_FPC_REGNUM || regnum == M68K_FPS_REGNUM)
143 return builtin_type (gdbarch)->builtin_int32;
144 }
145 else
146 {
147 if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM)
148 return builtin_type (gdbarch)->builtin_int0;
149 }
150
151 if (regnum == gdbarch_pc_regnum (gdbarch))
152 return builtin_type (gdbarch)->builtin_func_ptr;
153
154 if (regnum >= M68K_A0_REGNUM && regnum <= M68K_A0_REGNUM + 7)
155 return builtin_type (gdbarch)->builtin_data_ptr;
156
157 if (regnum == M68K_PS_REGNUM)
158 return m68k_ps_type (gdbarch);
159
160 return builtin_type (gdbarch)->builtin_int32;
161 }
162
163 static const char * const m68k_register_names[] = {
164 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
165 "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp",
166 "ps", "pc",
167 "fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
168 "fpcontrol", "fpstatus", "fpiaddr"
169 };
170
171 /* Function: m68k_register_name
172 Returns the name of the standard m68k register regnum. */
173
174 static const char *
175 m68k_register_name (struct gdbarch *gdbarch, int regnum)
176 {
177 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
178
179 gdb_static_assert (ARRAY_SIZE (m68k_register_names) == M68K_NUM_REGS);
180 if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
181 && tdep->fpregs_present == 0)
182 return "";
183 else
184 return m68k_register_names[regnum];
185 }
186 \f
187 /* Return nonzero if a value of type TYPE stored in register REGNUM
188 needs any special handling. */
189
190 static int
191 m68k_convert_register_p (struct gdbarch *gdbarch,
192 int regnum, struct type *type)
193 {
194 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
195
196 if (!tdep->fpregs_present)
197 return 0;
198 return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
199 /* We only support floating-point values. */
200 && type->code () == TYPE_CODE_FLT
201 && type != register_type (gdbarch, M68K_FP0_REGNUM));
202 }
203
204 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
205 return its contents in TO. */
206
207 static int
208 m68k_register_to_value (frame_info_ptr frame, int regnum,
209 struct type *type, gdb_byte *to,
210 int *optimizedp, int *unavailablep)
211 {
212 struct gdbarch *gdbarch = get_frame_arch (frame);
213 gdb_byte from[M68K_MAX_REGISTER_SIZE];
214 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
215
216 gdb_assert (type->code () == TYPE_CODE_FLT);
217
218 /* Convert to TYPE. */
219 if (!get_frame_register_bytes (frame, regnum, 0,
220 gdb::make_array_view (from,
221 register_size (gdbarch,
222 regnum)),
223 optimizedp, unavailablep))
224 return 0;
225
226 target_float_convert (from, fpreg_type, to, type);
227 *optimizedp = *unavailablep = 0;
228 return 1;
229 }
230
231 /* Write the contents FROM of a value of type TYPE into register
232 REGNUM in frame FRAME. */
233
234 static void
235 m68k_value_to_register (frame_info_ptr frame, int regnum,
236 struct type *type, const gdb_byte *from)
237 {
238 gdb_byte to[M68K_MAX_REGISTER_SIZE];
239 struct type *fpreg_type = register_type (get_frame_arch (frame),
240 M68K_FP0_REGNUM);
241
242 /* We only support floating-point values. */
243 if (type->code () != TYPE_CODE_FLT)
244 {
245 warning (_("Cannot convert non-floating-point type "
246 "to floating-point register value."));
247 return;
248 }
249
250 /* Convert from TYPE. */
251 target_float_convert (from, type, to, fpreg_type);
252 put_frame_register (frame, regnum, to);
253 }
254
255 \f
256 /* There is a fair number of calling conventions that are in somewhat
257 wide use. The 68000/08/10 don't support an FPU, not even as a
258 coprocessor. All function return values are stored in %d0/%d1.
259 Structures are returned in a static buffer, a pointer to which is
260 returned in %d0. This means that functions returning a structure
261 are not re-entrant. To avoid this problem some systems use a
262 convention where the caller passes a pointer to a buffer in %a1
263 where the return values is to be stored. This convention is the
264 default, and is implemented in the function m68k_return_value.
265
266 The 68020/030/040/060 do support an FPU, either as a coprocessor
267 (68881/2) or built-in (68040/68060). That's why System V release 4
268 (SVR4) introduces a new calling convention specified by the SVR4
269 psABI. Integer values are returned in %d0/%d1, pointer return
270 values in %a0 and floating values in %fp0. When calling functions
271 returning a structure the caller should pass a pointer to a buffer
272 for the return value in %a0. This convention is implemented in the
273 function m68k_svr4_return_value, and by appropriately setting the
274 struct_value_regnum member of `struct gdbarch_tdep'.
275
276 GNU/Linux returns values in the same way as SVR4 does, but uses %a1
277 for passing the structure return value buffer.
278
279 GCC can also generate code where small structures are returned in
280 %d0/%d1 instead of in memory by using -freg-struct-return. This is
281 the default on NetBSD a.out, OpenBSD and GNU/Linux and several
282 embedded systems. This convention is implemented by setting the
283 struct_return member of `struct gdbarch_tdep' to reg_struct_return.
284
285 GCC also has an "embedded" ABI. This works like the SVR4 ABI,
286 except that pointers are returned in %D0. This is implemented by
287 setting the pointer_result_regnum member of `struct gdbarch_tdep'
288 as appropriate. */
289
290 /* Read a function return value of TYPE from REGCACHE, and copy that
291 into VALBUF. */
292
293 static void
294 m68k_extract_return_value (struct type *type, struct regcache *regcache,
295 gdb_byte *valbuf)
296 {
297 int len = type->length ();
298 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
299
300 if (type->code () == TYPE_CODE_PTR && len == 4)
301 {
302 struct gdbarch *gdbarch = regcache->arch ();
303 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
304 regcache->raw_read (tdep->pointer_result_regnum, valbuf);
305 }
306 else if (len <= 4)
307 {
308 regcache->raw_read (M68K_D0_REGNUM, buf);
309 memcpy (valbuf, buf + (4 - len), len);
310 }
311 else if (len <= 8)
312 {
313 regcache->raw_read (M68K_D0_REGNUM, buf);
314 memcpy (valbuf, buf + (8 - len), len - 4);
315 regcache->raw_read (M68K_D1_REGNUM, valbuf + (len - 4));
316 }
317 else
318 internal_error (_("Cannot extract return value of %d bytes long."), len);
319 }
320
321 static void
322 m68k_svr4_extract_return_value (struct type *type, struct regcache *regcache,
323 gdb_byte *valbuf)
324 {
325 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
326 struct gdbarch *gdbarch = regcache->arch ();
327 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
328
329 if (tdep->float_return && type->code () == TYPE_CODE_FLT)
330 {
331 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
332 regcache->raw_read (M68K_FP0_REGNUM, buf);
333 target_float_convert (buf, fpreg_type, valbuf, type);
334 }
335 else
336 m68k_extract_return_value (type, regcache, valbuf);
337 }
338
339 /* Write a function return value of TYPE from VALBUF into REGCACHE. */
340
341 static void
342 m68k_store_return_value (struct type *type, struct regcache *regcache,
343 const gdb_byte *valbuf)
344 {
345 int len = type->length ();
346
347 if (type->code () == TYPE_CODE_PTR && len == 4)
348 {
349 struct gdbarch *gdbarch = regcache->arch ();
350 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
351 regcache->raw_write (tdep->pointer_result_regnum, valbuf);
352 /* gdb historically also set D0 in the SVR4 case. */
353 if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
354 regcache->raw_write (M68K_D0_REGNUM, valbuf);
355 }
356 else if (len <= 4)
357 regcache->raw_write_part (M68K_D0_REGNUM, 4 - len, len, valbuf);
358 else if (len <= 8)
359 {
360 regcache->raw_write_part (M68K_D0_REGNUM, 8 - len, len - 4, valbuf);
361 regcache->raw_write (M68K_D1_REGNUM, valbuf + (len - 4));
362 }
363 else
364 internal_error (_("Cannot store return value of %d bytes long."), len);
365 }
366
367 static void
368 m68k_svr4_store_return_value (struct type *type, struct regcache *regcache,
369 const gdb_byte *valbuf)
370 {
371 struct gdbarch *gdbarch = regcache->arch ();
372 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
373
374 if (tdep->float_return && type->code () == TYPE_CODE_FLT)
375 {
376 struct type *fpreg_type = register_type (gdbarch, M68K_FP0_REGNUM);
377 gdb_byte buf[M68K_MAX_REGISTER_SIZE];
378 target_float_convert (valbuf, type, buf, fpreg_type);
379 regcache->raw_write (M68K_FP0_REGNUM, buf);
380 }
381 else
382 m68k_store_return_value (type, regcache, valbuf);
383 }
384
385 /* Return non-zero if TYPE, which is assumed to be a structure, union or
386 complex type, should be returned in registers for architecture
387 GDBARCH. */
388
389 static int
390 m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
391 {
392 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
393 enum type_code code = type->code ();
394 int len = type->length ();
395
396 gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
397 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY);
398
399 if (tdep->struct_return == pcc_struct_return)
400 return 0;
401
402 const bool is_vector = code == TYPE_CODE_ARRAY && type->is_vector ();
403
404 if (is_vector
405 && check_typedef (type->target_type ())->code () == TYPE_CODE_FLT)
406 return 0;
407
408 /* According to m68k_return_in_memory in the m68k GCC back-end,
409 strange things happen for small aggregate types. Aggregate types
410 with only one component are always returned like the type of the
411 component. Aggregate types whose size is 2, 4, or 8 are returned
412 in registers if their natural alignment is at least 16 bits.
413
414 We reject vectors here, as experimentally this gives the correct
415 answer. */
416 if (!is_vector && (len == 2 || len == 4 || len == 8))
417 return type_align (type) >= 2;
418
419 return (len == 1 || len == 2 || len == 4 || len == 8);
420 }
421
422 /* Determine, for architecture GDBARCH, how a return value of TYPE
423 should be returned. If it is supposed to be returned in registers,
424 and READBUF is non-zero, read the appropriate value from REGCACHE,
425 and copy it into READBUF. If WRITEBUF is non-zero, write the value
426 from WRITEBUF into REGCACHE. */
427
428 static enum return_value_convention
429 m68k_return_value (struct gdbarch *gdbarch, struct value *function,
430 struct type *type, struct regcache *regcache,
431 gdb_byte *readbuf, const gdb_byte *writebuf)
432 {
433 enum type_code code = type->code ();
434
435 /* GCC returns a `long double' in memory too. */
436 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
437 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
438 && !m68k_reg_struct_return_p (gdbarch, type))
439 || (code == TYPE_CODE_FLT && type->length () == 12))
440 {
441 /* The default on m68k is to return structures in static memory.
442 Consequently a function must return the address where we can
443 find the return value. */
444
445 if (readbuf)
446 {
447 ULONGEST addr;
448
449 regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
450 read_memory (addr, readbuf, type->length ());
451 }
452
453 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
454 }
455
456 if (readbuf)
457 m68k_extract_return_value (type, regcache, readbuf);
458 if (writebuf)
459 m68k_store_return_value (type, regcache, writebuf);
460
461 return RETURN_VALUE_REGISTER_CONVENTION;
462 }
463
464 static enum return_value_convention
465 m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
466 struct type *type, struct regcache *regcache,
467 gdb_byte *readbuf, const gdb_byte *writebuf)
468 {
469 enum type_code code = type->code ();
470 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
471
472 /* Aggregates with a single member are always returned like their
473 sole element. */
474 if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
475 && type->num_fields () == 1)
476 {
477 type = check_typedef (type->field (0).type ());
478 return m68k_svr4_return_value (gdbarch, function, type, regcache,
479 readbuf, writebuf);
480 }
481
482 if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
483 || code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
484 && !m68k_reg_struct_return_p (gdbarch, type))
485 /* GCC may return a `long double' in memory too. */
486 || (!tdep->float_return
487 && code == TYPE_CODE_FLT
488 && type->length () == 12))
489 {
490 /* The System V ABI says that:
491
492 "A function returning a structure or union also sets %a0 to
493 the value it finds in %a0. Thus when the caller receives
494 control again, the address of the returned object resides in
495 register %a0."
496
497 So the ABI guarantees that we can always find the return
498 value just after the function has returned.
499
500 However, GCC also implements the "embedded" ABI. That ABI
501 does not preserve %a0 across calls, but does write the value
502 back to %d0. */
503
504 if (readbuf)
505 {
506 ULONGEST addr;
507
508 regcache_raw_read_unsigned (regcache, tdep->pointer_result_regnum,
509 &addr);
510 read_memory (addr, readbuf, type->length ());
511 }
512
513 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
514 }
515
516 if (readbuf)
517 m68k_svr4_extract_return_value (type, regcache, readbuf);
518 if (writebuf)
519 m68k_svr4_store_return_value (type, regcache, writebuf);
520
521 return RETURN_VALUE_REGISTER_CONVENTION;
522 }
523 \f
524
525 /* Always align the frame to a 4-byte boundary. This is required on
526 coldfire and harmless on the rest. */
527
528 static CORE_ADDR
529 m68k_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
530 {
531 /* Align the stack to four bytes. */
532 return sp & ~3;
533 }
534
535 static CORE_ADDR
536 m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
537 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
538 struct value **args, CORE_ADDR sp,
539 function_call_return_method return_method,
540 CORE_ADDR struct_addr)
541 {
542 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
543 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
544 gdb_byte buf[4];
545 int i;
546
547 /* Push arguments in reverse order. */
548 for (i = nargs - 1; i >= 0; i--)
549 {
550 struct type *value_type = args[i]->enclosing_type ();
551 int len = value_type->length ();
552 int container_len = (len + 3) & ~3;
553 int offset;
554
555 /* Non-scalars bigger than 4 bytes are left aligned, others are
556 right aligned. */
557 if ((value_type->code () == TYPE_CODE_STRUCT
558 || value_type->code () == TYPE_CODE_UNION
559 || value_type->code () == TYPE_CODE_ARRAY)
560 && len > 4)
561 offset = 0;
562 else
563 offset = container_len - len;
564 sp -= container_len;
565 write_memory (sp + offset, args[i]->contents_all ().data (), len);
566 }
567
568 /* Store struct value address. */
569 if (return_method == return_method_struct)
570 {
571 store_unsigned_integer (buf, 4, byte_order, struct_addr);
572 regcache->cooked_write (tdep->struct_value_regnum, buf);
573 }
574
575 /* Store return address. */
576 sp -= 4;
577 store_unsigned_integer (buf, 4, byte_order, bp_addr);
578 write_memory (sp, buf, 4);
579
580 /* Finally, update the stack pointer... */
581 store_unsigned_integer (buf, 4, byte_order, sp);
582 regcache->cooked_write (M68K_SP_REGNUM, buf);
583
584 /* ...and fake a frame pointer. */
585 regcache->cooked_write (M68K_FP_REGNUM, buf);
586
587 /* DWARF2/GCC uses the stack address *before* the function call as a
588 frame's CFA. */
589 return sp + 8;
590 }
591
592 /* Convert a dwarf or dwarf2 regnumber to a GDB regnum. */
593
594 static int
595 m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
596 {
597 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
598
599 if (num < 8)
600 /* d0..7 */
601 return (num - 0) + M68K_D0_REGNUM;
602 else if (num < 16)
603 /* a0..7 */
604 return (num - 8) + M68K_A0_REGNUM;
605 else if (num < 24 && tdep->fpregs_present)
606 /* fp0..7 */
607 return (num - 16) + M68K_FP0_REGNUM;
608 else if (num == 25)
609 /* pc */
610 return M68K_PC_REGNUM;
611 else
612 return -1;
613 }
614
615 \f
616 struct m68k_frame_cache
617 {
618 /* Base address. */
619 CORE_ADDR base;
620 CORE_ADDR sp_offset;
621 CORE_ADDR pc;
622
623 /* Saved registers. */
624 CORE_ADDR saved_regs[M68K_NUM_REGS];
625 CORE_ADDR saved_sp;
626
627 /* Stack space reserved for local variables. */
628 long locals;
629 };
630
631 /* Allocate and initialize a frame cache. */
632
633 static struct m68k_frame_cache *
634 m68k_alloc_frame_cache (void)
635 {
636 struct m68k_frame_cache *cache;
637 int i;
638
639 cache = FRAME_OBSTACK_ZALLOC (struct m68k_frame_cache);
640
641 /* Base address. */
642 cache->base = 0;
643 cache->sp_offset = -4;
644 cache->pc = 0;
645
646 /* Saved registers. We initialize these to -1 since zero is a valid
647 offset (that's where %fp is supposed to be stored). */
648 for (i = 0; i < M68K_NUM_REGS; i++)
649 cache->saved_regs[i] = -1;
650
651 /* Frameless until proven otherwise. */
652 cache->locals = -1;
653
654 return cache;
655 }
656
657 /* Check whether PC points at a code that sets up a new stack frame.
658 If so, it updates CACHE and returns the address of the first
659 instruction after the sequence that sets removes the "hidden"
660 argument from the stack or CURRENT_PC, whichever is smaller.
661 Otherwise, return PC. */
662
663 static CORE_ADDR
664 m68k_analyze_frame_setup (struct gdbarch *gdbarch,
665 CORE_ADDR pc, CORE_ADDR current_pc,
666 struct m68k_frame_cache *cache)
667 {
668 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
669 int op;
670
671 if (pc >= current_pc)
672 return current_pc;
673
674 op = read_memory_unsigned_integer (pc, 2, byte_order);
675
676 if (op == P_LINKW_FP || op == P_LINKL_FP || op == P_PEA_FP)
677 {
678 cache->saved_regs[M68K_FP_REGNUM] = 0;
679 cache->sp_offset += 4;
680 if (op == P_LINKW_FP)
681 {
682 /* link.w %fp, #-N */
683 /* link.w %fp, #0; adda.l #-N, %sp */
684 cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
685
686 if (pc + 4 < current_pc && cache->locals == 0)
687 {
688 op = read_memory_unsigned_integer (pc + 4, 2, byte_order);
689 if (op == P_ADDAL_SP)
690 {
691 cache->locals = read_memory_integer (pc + 6, 4, byte_order);
692 return pc + 10;
693 }
694 }
695
696 return pc + 4;
697 }
698 else if (op == P_LINKL_FP)
699 {
700 /* link.l %fp, #-N */
701 cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
702 return pc + 6;
703 }
704 else
705 {
706 /* pea (%fp); movea.l %sp, %fp */
707 cache->locals = 0;
708
709 if (pc + 2 < current_pc)
710 {
711 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
712
713 if (op == P_MOVEAL_SP_FP)
714 {
715 /* move.l %sp, %fp */
716 return pc + 4;
717 }
718 }
719
720 return pc + 2;
721 }
722 }
723 else if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
724 {
725 /* subq.[wl] #N,%sp */
726 /* subq.[wl] #8,%sp; subq.[wl] #N,%sp */
727 cache->locals = (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
728 if (pc + 2 < current_pc)
729 {
730 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
731 if ((op & 0170777) == P_SUBQW_SP || (op & 0170777) == P_SUBQL_SP)
732 {
733 cache->locals += (op & 07000) == 0 ? 8 : (op & 07000) >> 9;
734 return pc + 4;
735 }
736 }
737 return pc + 2;
738 }
739 else if (op == P_ADDAW_SP || op == P_LEA_SP_SP)
740 {
741 /* adda.w #-N,%sp */
742 /* lea (-N,%sp),%sp */
743 cache->locals = -read_memory_integer (pc + 2, 2, byte_order);
744 return pc + 4;
745 }
746 else if (op == P_ADDAL_SP)
747 {
748 /* adda.l #-N,%sp */
749 cache->locals = -read_memory_integer (pc + 2, 4, byte_order);
750 return pc + 6;
751 }
752
753 return pc;
754 }
755
756 /* Check whether PC points at code that saves registers on the stack.
757 If so, it updates CACHE and returns the address of the first
758 instruction after the register saves or CURRENT_PC, whichever is
759 smaller. Otherwise, return PC. */
760
761 static CORE_ADDR
762 m68k_analyze_register_saves (struct gdbarch *gdbarch, CORE_ADDR pc,
763 CORE_ADDR current_pc,
764 struct m68k_frame_cache *cache)
765 {
766 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
767 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
768
769 if (cache->locals >= 0)
770 {
771 CORE_ADDR offset;
772 int op;
773 int i, mask, regno;
774
775 offset = -4 - cache->locals;
776 while (pc < current_pc)
777 {
778 op = read_memory_unsigned_integer (pc, 2, byte_order);
779 if (op == P_FMOVEMX_SP
780 && tdep->fpregs_present)
781 {
782 /* fmovem.x REGS,-(%sp) */
783 op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
784 if ((op & 0xff00) == 0xe000)
785 {
786 mask = op & 0xff;
787 for (i = 0; i < 16; i++, mask >>= 1)
788 {
789 if (mask & 1)
790 {
791 cache->saved_regs[i + M68K_FP0_REGNUM] = offset;
792 offset -= 12;
793 }
794 }
795 pc += 4;
796 }
797 else
798 break;
799 }
800 else if ((op & 0177760) == P_MOVEL_SP)
801 {
802 /* move.l %R,-(%sp) */
803 regno = op & 017;
804 cache->saved_regs[regno] = offset;
805 offset -= 4;
806 pc += 2;
807 }
808 else if (op == P_MOVEML_SP)
809 {
810 /* movem.l REGS,-(%sp) */
811 mask = read_memory_unsigned_integer (pc + 2, 2, byte_order);
812 for (i = 0; i < 16; i++, mask >>= 1)
813 {
814 if (mask & 1)
815 {
816 cache->saved_regs[15 - i] = offset;
817 offset -= 4;
818 }
819 }
820 pc += 4;
821 }
822 else
823 break;
824 }
825 }
826
827 return pc;
828 }
829
830
831 /* Do a full analysis of the prologue at PC and update CACHE
832 accordingly. Bail out early if CURRENT_PC is reached. Return the
833 address where the analysis stopped.
834
835 We handle all cases that can be generated by gcc.
836
837 For allocating a stack frame:
838
839 link.w %a6,#-N
840 link.l %a6,#-N
841 pea (%fp); move.l %sp,%fp
842 link.w %a6,#0; add.l #-N,%sp
843 subq.l #N,%sp
844 subq.w #N,%sp
845 subq.w #8,%sp; subq.w #N-8,%sp
846 add.w #-N,%sp
847 lea (-N,%sp),%sp
848 add.l #-N,%sp
849
850 For saving registers:
851
852 fmovem.x REGS,-(%sp)
853 move.l R1,-(%sp)
854 move.l R1,-(%sp); move.l R2,-(%sp)
855 movem.l REGS,-(%sp)
856
857 For setting up the PIC register:
858
859 lea (%pc,N),%a5
860
861 */
862
863 static CORE_ADDR
864 m68k_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
865 CORE_ADDR current_pc, struct m68k_frame_cache *cache)
866 {
867 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
868 unsigned int op;
869
870 pc = m68k_analyze_frame_setup (gdbarch, pc, current_pc, cache);
871 pc = m68k_analyze_register_saves (gdbarch, pc, current_pc, cache);
872 if (pc >= current_pc)
873 return current_pc;
874
875 /* Check for GOT setup. */
876 op = read_memory_unsigned_integer (pc, 4, byte_order);
877 if (op == P_LEA_PC_A5)
878 {
879 /* lea (%pc,N),%a5 */
880 return pc + 8;
881 }
882
883 return pc;
884 }
885
886 /* Return PC of first real instruction. */
887
888 static CORE_ADDR
889 m68k_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
890 {
891 struct m68k_frame_cache cache;
892 CORE_ADDR pc;
893
894 cache.locals = -1;
895 pc = m68k_analyze_prologue (gdbarch, start_pc, (CORE_ADDR) -1, &cache);
896 if (cache.locals < 0)
897 return start_pc;
898 return pc;
899 }
900
901 static CORE_ADDR
902 m68k_unwind_pc (struct gdbarch *gdbarch, frame_info_ptr next_frame)
903 {
904 gdb_byte buf[8];
905
906 frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
907 return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
908 }
909 \f
910 /* Normal frames. */
911
912 static struct m68k_frame_cache *
913 m68k_frame_cache (frame_info_ptr this_frame, void **this_cache)
914 {
915 struct gdbarch *gdbarch = get_frame_arch (this_frame);
916 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
917 struct m68k_frame_cache *cache;
918 gdb_byte buf[4];
919 int i;
920
921 if (*this_cache)
922 return (struct m68k_frame_cache *) *this_cache;
923
924 cache = m68k_alloc_frame_cache ();
925 *this_cache = cache;
926
927 /* In principle, for normal frames, %fp holds the frame pointer,
928 which holds the base address for the current stack frame.
929 However, for functions that don't need it, the frame pointer is
930 optional. For these "frameless" functions the frame pointer is
931 actually the frame pointer of the calling frame. Signal
932 trampolines are just a special case of a "frameless" function.
933 They (usually) share their frame pointer with the frame that was
934 in progress when the signal occurred. */
935
936 get_frame_register (this_frame, M68K_FP_REGNUM, buf);
937 cache->base = extract_unsigned_integer (buf, 4, byte_order);
938 if (cache->base == 0)
939 return cache;
940
941 /* For normal frames, %pc is stored at 4(%fp). */
942 cache->saved_regs[M68K_PC_REGNUM] = 4;
943
944 cache->pc = get_frame_func (this_frame);
945 if (cache->pc != 0)
946 m68k_analyze_prologue (get_frame_arch (this_frame), cache->pc,
947 get_frame_pc (this_frame), cache);
948
949 if (cache->locals < 0)
950 {
951 /* We didn't find a valid frame, which means that CACHE->base
952 currently holds the frame pointer for our calling frame. If
953 we're at the start of a function, or somewhere half-way its
954 prologue, the function's frame probably hasn't been fully
955 setup yet. Try to reconstruct the base address for the stack
956 frame by looking at the stack pointer. For truly "frameless"
957 functions this might work too. */
958
959 get_frame_register (this_frame, M68K_SP_REGNUM, buf);
960 cache->base = extract_unsigned_integer (buf, 4, byte_order)
961 + cache->sp_offset;
962 }
963
964 /* Now that we have the base address for the stack frame we can
965 calculate the value of %sp in the calling frame. */
966 cache->saved_sp = cache->base + 8;
967
968 /* Adjust all the saved registers such that they contain addresses
969 instead of offsets. */
970 for (i = 0; i < M68K_NUM_REGS; i++)
971 if (cache->saved_regs[i] != -1)
972 cache->saved_regs[i] += cache->base;
973
974 return cache;
975 }
976
977 static void
978 m68k_frame_this_id (frame_info_ptr this_frame, void **this_cache,
979 struct frame_id *this_id)
980 {
981 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
982
983 /* This marks the outermost frame. */
984 if (cache->base == 0)
985 return;
986
987 /* See the end of m68k_push_dummy_call. */
988 *this_id = frame_id_build (cache->base + 8, cache->pc);
989 }
990
991 static struct value *
992 m68k_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
993 int regnum)
994 {
995 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
996
997 gdb_assert (regnum >= 0);
998
999 if (regnum == M68K_SP_REGNUM && cache->saved_sp)
1000 return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
1001
1002 if (regnum < M68K_NUM_REGS && cache->saved_regs[regnum] != -1)
1003 return frame_unwind_got_memory (this_frame, regnum,
1004 cache->saved_regs[regnum]);
1005
1006 return frame_unwind_got_register (this_frame, regnum, regnum);
1007 }
1008
1009 static const struct frame_unwind m68k_frame_unwind =
1010 {
1011 "m68k prologue",
1012 NORMAL_FRAME,
1013 default_frame_unwind_stop_reason,
1014 m68k_frame_this_id,
1015 m68k_frame_prev_register,
1016 NULL,
1017 default_frame_sniffer
1018 };
1019 \f
1020 static CORE_ADDR
1021 m68k_frame_base_address (frame_info_ptr this_frame, void **this_cache)
1022 {
1023 struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
1024
1025 return cache->base;
1026 }
1027
1028 static const struct frame_base m68k_frame_base =
1029 {
1030 &m68k_frame_unwind,
1031 m68k_frame_base_address,
1032 m68k_frame_base_address,
1033 m68k_frame_base_address
1034 };
1035
1036 static struct frame_id
1037 m68k_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame)
1038 {
1039 CORE_ADDR fp;
1040
1041 fp = get_frame_register_unsigned (this_frame, M68K_FP_REGNUM);
1042
1043 /* See the end of m68k_push_dummy_call. */
1044 return frame_id_build (fp + 8, get_frame_pc (this_frame));
1045 }
1046 \f
1047
1048 /* Figure out where the longjmp will land. Slurp the args out of the stack.
1049 We expect the first arg to be a pointer to the jmp_buf structure from which
1050 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
1051 This routine returns true on success. */
1052
1053 static int
1054 m68k_get_longjmp_target (frame_info_ptr frame, CORE_ADDR *pc)
1055 {
1056 gdb_byte *buf;
1057 CORE_ADDR sp, jb_addr;
1058 struct gdbarch *gdbarch = get_frame_arch (frame);
1059 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
1060 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1061
1062 if (tdep->jb_pc < 0)
1063 {
1064 internal_error (_("m68k_get_longjmp_target: not implemented"));
1065 return 0;
1066 }
1067
1068 buf = (gdb_byte *) alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
1069 sp = get_frame_register_unsigned (frame, gdbarch_sp_regnum (gdbarch));
1070
1071 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack. */
1072 buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
1073 return 0;
1074
1075 jb_addr = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
1076 / TARGET_CHAR_BIT, byte_order);
1077
1078 if (target_read_memory (jb_addr + tdep->jb_pc * tdep->jb_elt_size, buf,
1079 gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT),
1080 byte_order)
1081 return 0;
1082
1083 *pc = extract_unsigned_integer (buf, gdbarch_ptr_bit (gdbarch)
1084 / TARGET_CHAR_BIT, byte_order);
1085 return 1;
1086 }
1087 \f
1088
1089 /* This is the implementation of gdbarch method
1090 return_in_first_hidden_param_p. */
1091
1092 static int
1093 m68k_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
1094 struct type *type)
1095 {
1096 return 0;
1097 }
1098
1099 /* System V Release 4 (SVR4). */
1100
1101 void
1102 m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1103 {
1104 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
1105
1106 /* SVR4 uses a different calling convention. */
1107 set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
1108
1109 /* SVR4 uses %a0 instead of %a1. */
1110 tdep->struct_value_regnum = M68K_A0_REGNUM;
1111
1112 /* SVR4 returns pointers in %a0. */
1113 tdep->pointer_result_regnum = M68K_A0_REGNUM;
1114 }
1115
1116 /* GCC's m68k "embedded" ABI. This is like the SVR4 ABI, but pointer
1117 values are returned in %d0, not %a0. */
1118
1119 static void
1120 m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1121 {
1122 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
1123
1124 m68k_svr4_init_abi (info, gdbarch);
1125 tdep->pointer_result_regnum = M68K_D0_REGNUM;
1126 }
1127
1128 \f
1129
1130 /* Function: m68k_gdbarch_init
1131 Initializer function for the m68k gdbarch vector.
1132 Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
1133
1134 static struct gdbarch *
1135 m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1136 {
1137 struct gdbarch_list *best_arch;
1138 tdesc_arch_data_up tdesc_data;
1139 int i;
1140 enum m68k_flavour flavour = m68k_no_flavour;
1141 int has_fp = 1;
1142 const struct floatformat **long_double_format = floatformats_m68881_ext;
1143
1144 /* Check any target description for validity. */
1145 if (tdesc_has_registers (info.target_desc))
1146 {
1147 const struct tdesc_feature *feature;
1148 int valid_p;
1149
1150 feature = tdesc_find_feature (info.target_desc,
1151 "org.gnu.gdb.m68k.core");
1152
1153 if (feature == NULL)
1154 {
1155 feature = tdesc_find_feature (info.target_desc,
1156 "org.gnu.gdb.coldfire.core");
1157 if (feature != NULL)
1158 flavour = m68k_coldfire_flavour;
1159 }
1160
1161 if (feature == NULL)
1162 {
1163 feature = tdesc_find_feature (info.target_desc,
1164 "org.gnu.gdb.fido.core");
1165 if (feature != NULL)
1166 flavour = m68k_fido_flavour;
1167 }
1168
1169 if (feature == NULL)
1170 return NULL;
1171
1172 tdesc_data = tdesc_data_alloc ();
1173
1174 valid_p = 1;
1175 for (i = 0; i <= M68K_PC_REGNUM; i++)
1176 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
1177 m68k_register_names[i]);
1178
1179 if (!valid_p)
1180 return NULL;
1181
1182 feature = tdesc_find_feature (info.target_desc,
1183 "org.gnu.gdb.coldfire.fp");
1184 if (feature != NULL)
1185 {
1186 valid_p = 1;
1187 for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
1188 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
1189 m68k_register_names[i]);
1190 if (!valid_p)
1191 return NULL;
1192 }
1193 else
1194 has_fp = 0;
1195 }
1196
1197 /* The mechanism for returning floating values from function
1198 and the type of long double depend on whether we're
1199 on ColdFire or standard m68k. */
1200
1201 if (info.bfd_arch_info && info.bfd_arch_info->mach != 0)
1202 {
1203 const bfd_arch_info_type *coldfire_arch =
1204 bfd_lookup_arch (bfd_arch_m68k, bfd_mach_mcf_isa_a_nodiv);
1205
1206 if (coldfire_arch
1207 && ((*info.bfd_arch_info->compatible)
1208 (info.bfd_arch_info, coldfire_arch)))
1209 flavour = m68k_coldfire_flavour;
1210 }
1211
1212 /* Try to figure out if the arch uses floating registers to return
1213 floating point values from functions. On ColdFire, floating
1214 point values are returned in D0. */
1215 int float_return = 0;
1216 if (has_fp && flavour != m68k_coldfire_flavour)
1217 float_return = 1;
1218 #ifdef HAVE_ELF
1219 if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
1220 {
1221 int fp_abi = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
1222 Tag_GNU_M68K_ABI_FP);
1223 if (fp_abi == 1)
1224 float_return = 1;
1225 else if (fp_abi == 2)
1226 float_return = 0;
1227 }
1228 #endif /* HAVE_ELF */
1229
1230 /* If there is already a candidate, use it. */
1231 for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
1232 best_arch != NULL;
1233 best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
1234 {
1235 m68k_gdbarch_tdep *tdep
1236 = gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
1237
1238 if (flavour != tdep->flavour)
1239 continue;
1240
1241 if (has_fp != tdep->fpregs_present)
1242 continue;
1243
1244 if (float_return != tdep->float_return)
1245 continue;
1246
1247 break;
1248 }
1249
1250 if (best_arch != NULL)
1251 return best_arch->gdbarch;
1252
1253 gdbarch *gdbarch
1254 = gdbarch_alloc (&info, gdbarch_tdep_up (new m68k_gdbarch_tdep));
1255 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
1256
1257 tdep->fpregs_present = has_fp;
1258 tdep->float_return = float_return;
1259 tdep->flavour = flavour;
1260
1261 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1262 long_double_format = floatformats_ieee_double;
1263 set_gdbarch_long_double_format (gdbarch, long_double_format);
1264 set_gdbarch_long_double_bit (gdbarch, long_double_format[0]->totalsize);
1265
1266 set_gdbarch_skip_prologue (gdbarch, m68k_skip_prologue);
1267 set_gdbarch_breakpoint_kind_from_pc (gdbarch, m68k_breakpoint::kind_from_pc);
1268 set_gdbarch_sw_breakpoint_from_kind (gdbarch, m68k_breakpoint::bp_from_kind);
1269
1270 /* Stack grows down. */
1271 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1272 set_gdbarch_frame_align (gdbarch, m68k_frame_align);
1273
1274 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
1275 if (flavour == m68k_coldfire_flavour || flavour == m68k_fido_flavour)
1276 set_gdbarch_decr_pc_after_break (gdbarch, 2);
1277
1278 set_gdbarch_frame_args_skip (gdbarch, 8);
1279 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, m68k_dwarf_reg_to_regnum);
1280
1281 set_gdbarch_register_type (gdbarch, m68k_register_type);
1282 set_gdbarch_register_name (gdbarch, m68k_register_name);
1283 set_gdbarch_num_regs (gdbarch, M68K_NUM_REGS);
1284 set_gdbarch_sp_regnum (gdbarch, M68K_SP_REGNUM);
1285 set_gdbarch_pc_regnum (gdbarch, M68K_PC_REGNUM);
1286 set_gdbarch_ps_regnum (gdbarch, M68K_PS_REGNUM);
1287 set_gdbarch_convert_register_p (gdbarch, m68k_convert_register_p);
1288 set_gdbarch_register_to_value (gdbarch, m68k_register_to_value);
1289 set_gdbarch_value_to_register (gdbarch, m68k_value_to_register);
1290
1291 if (has_fp)
1292 set_gdbarch_fp0_regnum (gdbarch, M68K_FP0_REGNUM);
1293
1294 /* Function call & return. */
1295 set_gdbarch_push_dummy_call (gdbarch, m68k_push_dummy_call);
1296 set_gdbarch_return_value (gdbarch, m68k_return_value);
1297 set_gdbarch_return_in_first_hidden_param_p (gdbarch,
1298 m68k_return_in_first_hidden_param_p);
1299
1300 #if defined JB_PC && defined JB_ELEMENT_SIZE
1301 tdep->jb_pc = JB_PC;
1302 tdep->jb_elt_size = JB_ELEMENT_SIZE;
1303 #else
1304 tdep->jb_pc = -1;
1305 #endif
1306 tdep->pointer_result_regnum = M68K_D0_REGNUM;
1307 tdep->struct_value_regnum = M68K_A1_REGNUM;
1308 tdep->struct_return = reg_struct_return;
1309
1310 /* Frame unwinder. */
1311 set_gdbarch_dummy_id (gdbarch, m68k_dummy_id);
1312 set_gdbarch_unwind_pc (gdbarch, m68k_unwind_pc);
1313
1314 /* Hook in the DWARF CFI frame unwinder. */
1315 dwarf2_append_unwinders (gdbarch);
1316
1317 frame_base_set_default (gdbarch, &m68k_frame_base);
1318
1319 /* Hook in ABI-specific overrides, if they have been registered. */
1320 gdbarch_init_osabi (info, gdbarch);
1321
1322 /* Now we have tuned the configuration, set a few final things,
1323 based on what the OS ABI has told us. */
1324
1325 if (tdep->jb_pc >= 0)
1326 set_gdbarch_get_longjmp_target (gdbarch, m68k_get_longjmp_target);
1327
1328 frame_unwind_append_unwinder (gdbarch, &m68k_frame_unwind);
1329
1330 if (tdesc_data != nullptr)
1331 tdesc_use_registers (gdbarch, info.target_desc, std::move (tdesc_data));
1332
1333 return gdbarch;
1334 }
1335
1336
1337 static void
1338 m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
1339 {
1340 m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
1341
1342 if (tdep == NULL)
1343 return;
1344 }
1345
1346 /* OSABI sniffer for m68k. */
1347
1348 static enum gdb_osabi
1349 m68k_osabi_sniffer (bfd *abfd)
1350 {
1351 unsigned int elfosabi = elf_elfheader (abfd)->e_ident[EI_OSABI];
1352
1353 if (elfosabi == ELFOSABI_NONE)
1354 return GDB_OSABI_SVR4;
1355
1356 return GDB_OSABI_UNKNOWN;
1357 }
1358
1359 void _initialize_m68k_tdep ();
1360 void
1361 _initialize_m68k_tdep ()
1362 {
1363 gdbarch_register (bfd_arch_m68k, m68k_gdbarch_init, m68k_dump_tdep);
1364
1365 gdbarch_register_osabi_sniffer (bfd_arch_m68k, bfd_target_elf_flavour,
1366 m68k_osabi_sniffer);
1367 gdbarch_register_osabi (bfd_arch_m68k, 0, GDB_OSABI_SVR4,
1368 m68k_embedded_init_abi);
1369 }