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