/* Target-dependent code for the Motorola 68000 series.
- Copyright (C) 1990-2020 Free Software Foundation, Inc.
+ Copyright (C) 1990-2023 Free Software Foundation, Inc.
This file is part of GDB.
static struct type *
m68k_ps_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (!tdep->m68k_ps_type)
{
static struct type *
m68881_ext_type (struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (!tdep->m68881_ext_type)
- tdep->m68881_ext_type
- = arch_float_type (gdbarch, -1, "builtin_type_m68881_ext",
- floatformats_m68881_ext);
+ {
+ type_allocator alloc (gdbarch);
+ tdep->m68881_ext_type
+ = init_float_type (alloc, -1, "builtin_type_m68881_ext",
+ floatformats_m68881_ext);
+ }
return tdep->m68881_ext_type;
}
static struct type *
m68k_register_type (struct gdbarch *gdbarch, int regnum)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (tdep->fpregs_present)
{
static const char *
m68k_register_name (struct gdbarch *gdbarch, int regnum)
{
- if (regnum < 0 || regnum >= ARRAY_SIZE (m68k_register_names))
- internal_error (__FILE__, __LINE__,
- _("m68k_register_name: illegal register number %d"),
- regnum);
- else if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
- && gdbarch_tdep (gdbarch)->fpregs_present == 0)
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+
+ gdb_static_assert (ARRAY_SIZE (m68k_register_names) == M68K_NUM_REGS);
+ if (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FPI_REGNUM
+ && tdep->fpregs_present == 0)
return "";
else
return m68k_register_names[regnum];
m68k_convert_register_p (struct gdbarch *gdbarch,
int regnum, struct type *type)
{
- if (!gdbarch_tdep (gdbarch)->fpregs_present)
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+
+ if (!tdep->fpregs_present)
return 0;
return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
/* We only support floating-point values. */
return its contents in TO. */
static int
-m68k_register_to_value (struct frame_info *frame, int regnum,
+m68k_register_to_value (frame_info_ptr frame, int regnum,
struct type *type, gdb_byte *to,
int *optimizedp, int *unavailablep)
{
/* Convert to TYPE. */
if (!get_frame_register_bytes (frame, regnum, 0,
- register_size (gdbarch, regnum),
- from, optimizedp, unavailablep))
+ gdb::make_array_view (from,
+ register_size (gdbarch,
+ regnum)),
+ optimizedp, unavailablep))
return 0;
target_float_convert (from, fpreg_type, to, type);
REGNUM in frame FRAME. */
static void
-m68k_value_to_register (struct frame_info *frame, int regnum,
+m68k_value_to_register (frame_info_ptr frame, int regnum,
struct type *type, const gdb_byte *from)
{
gdb_byte to[M68K_MAX_REGISTER_SIZE];
m68k_extract_return_value (struct type *type, struct regcache *regcache,
gdb_byte *valbuf)
{
- int len = TYPE_LENGTH (type);
+ int len = type->length ();
gdb_byte buf[M68K_MAX_REGISTER_SIZE];
if (type->code () == TYPE_CODE_PTR && len == 4)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
regcache->raw_read (tdep->pointer_result_regnum, valbuf);
}
else if (len <= 4)
regcache->raw_read (M68K_D1_REGNUM, valbuf + (len - 4));
}
else
- internal_error (__FILE__, __LINE__,
- _("Cannot extract return value of %d bytes long."), len);
+ internal_error (_("Cannot extract return value of %d bytes long."), len);
}
static void
{
gdb_byte buf[M68K_MAX_REGISTER_SIZE];
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (tdep->float_return && type->code () == TYPE_CODE_FLT)
{
m68k_store_return_value (struct type *type, struct regcache *regcache,
const gdb_byte *valbuf)
{
- int len = TYPE_LENGTH (type);
+ int len = type->length ();
if (type->code () == TYPE_CODE_PTR && len == 4)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
regcache->raw_write (tdep->pointer_result_regnum, valbuf);
/* gdb historically also set D0 in the SVR4 case. */
if (tdep->pointer_result_regnum != M68K_D0_REGNUM)
regcache->raw_write (M68K_D1_REGNUM, valbuf + (len - 4));
}
else
- internal_error (__FILE__, __LINE__,
- _("Cannot store return value of %d bytes long."), len);
+ internal_error (_("Cannot store return value of %d bytes long."), len);
}
static void
const gdb_byte *valbuf)
{
struct gdbarch *gdbarch = regcache->arch ();
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (tdep->float_return && type->code () == TYPE_CODE_FLT)
{
static int
m68k_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
enum type_code code = type->code ();
- int len = TYPE_LENGTH (type);
+ int len = type->length ();
gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
|| code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY);
const bool is_vector = code == TYPE_CODE_ARRAY && type->is_vector ();
if (is_vector
- && check_typedef (TYPE_TARGET_TYPE (type))->code () == TYPE_CODE_FLT)
+ && check_typedef (type->target_type ())->code () == TYPE_CODE_FLT)
return 0;
/* According to m68k_return_in_memory in the m68k GCC back-end,
if (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
|| code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
&& !m68k_reg_struct_return_p (gdbarch, type))
- || (code == TYPE_CODE_FLT && TYPE_LENGTH (type) == 12))
+ || (code == TYPE_CODE_FLT && type->length () == 12))
{
/* The default on m68k is to return structures in static memory.
- Consequently a function must return the address where we can
- find the return value. */
+ Consequently a function must return the address where we can
+ find the return value. */
if (readbuf)
{
ULONGEST addr;
regcache_raw_read_unsigned (regcache, M68K_D0_REGNUM, &addr);
- read_memory (addr, readbuf, TYPE_LENGTH (type));
+ read_memory (addr, readbuf, type->length ());
}
return RETURN_VALUE_ABI_RETURNS_ADDRESS;
gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = type->code ();
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
/* Aggregates with a single member are always returned like their
sole element. */
|| code == TYPE_CODE_COMPLEX || code == TYPE_CODE_ARRAY)
&& !m68k_reg_struct_return_p (gdbarch, type))
/* GCC may return a `long double' in memory too. */
- || (!gdbarch_tdep (gdbarch)->float_return
+ || (!tdep->float_return
&& code == TYPE_CODE_FLT
- && TYPE_LENGTH (type) == 12))
+ && type->length () == 12))
{
/* The System V ABI says that:
if (readbuf)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
ULONGEST addr;
regcache_raw_read_unsigned (regcache, tdep->pointer_result_regnum,
&addr);
- read_memory (addr, readbuf, TYPE_LENGTH (type));
+ read_memory (addr, readbuf, type->length ());
}
return RETURN_VALUE_ABI_RETURNS_ADDRESS;
function_call_return_method return_method,
CORE_ADDR struct_addr)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
gdb_byte buf[4];
int i;
/* Push arguments in reverse order. */
for (i = nargs - 1; i >= 0; i--)
{
- struct type *value_type = value_enclosing_type (args[i]);
- int len = TYPE_LENGTH (value_type);
+ struct type *value_type = args[i]->enclosing_type ();
+ int len = value_type->length ();
int container_len = (len + 3) & ~3;
int offset;
else
offset = container_len - len;
sp -= container_len;
- write_memory (sp + offset, value_contents_all (args[i]), len);
+ write_memory (sp + offset, args[i]->contents_all ().data (), len);
}
/* Store struct value address. */
static int
m68k_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
{
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
+
if (num < 8)
/* d0..7 */
return (num - 0) + M68K_D0_REGNUM;
else if (num < 16)
/* a0..7 */
return (num - 8) + M68K_A0_REGNUM;
- else if (num < 24 && gdbarch_tdep (gdbarch)->fpregs_present)
+ else if (num < 24 && tdep->fpregs_present)
/* fp0..7 */
return (num - 16) + M68K_FP0_REGNUM;
else if (num == 25)
struct m68k_frame_cache *cache)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (cache->locals >= 0)
{
{
op = read_memory_unsigned_integer (pc, 2, byte_order);
if (op == P_FMOVEMX_SP
- && gdbarch_tdep (gdbarch)->fpregs_present)
+ && tdep->fpregs_present)
{
/* fmovem.x REGS,-(%sp) */
op = read_memory_unsigned_integer (pc + 2, 2, byte_order);
}
static CORE_ADDR
-m68k_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
+m68k_unwind_pc (struct gdbarch *gdbarch, frame_info_ptr next_frame)
{
gdb_byte buf[8];
/* Normal frames. */
static struct m68k_frame_cache *
-m68k_frame_cache (struct frame_info *this_frame, void **this_cache)
+m68k_frame_cache (frame_info_ptr this_frame, void **this_cache)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
}
static void
-m68k_frame_this_id (struct frame_info *this_frame, void **this_cache,
+m68k_frame_this_id (frame_info_ptr this_frame, void **this_cache,
struct frame_id *this_id)
{
struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
}
static struct value *
-m68k_frame_prev_register (struct frame_info *this_frame, void **this_cache,
+m68k_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
int regnum)
{
struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
static const struct frame_unwind m68k_frame_unwind =
{
+ "m68k prologue",
NORMAL_FRAME,
default_frame_unwind_stop_reason,
m68k_frame_this_id,
};
\f
static CORE_ADDR
-m68k_frame_base_address (struct frame_info *this_frame, void **this_cache)
+m68k_frame_base_address (frame_info_ptr this_frame, void **this_cache)
{
struct m68k_frame_cache *cache = m68k_frame_cache (this_frame, this_cache);
};
static struct frame_id
-m68k_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
+m68k_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame)
{
CORE_ADDR fp;
This routine returns true on success. */
static int
-m68k_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
+m68k_get_longjmp_target (frame_info_ptr frame, CORE_ADDR *pc)
{
gdb_byte *buf;
CORE_ADDR sp, jb_addr;
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
if (tdep->jb_pc < 0)
{
- internal_error (__FILE__, __LINE__,
- _("m68k_get_longjmp_target: not implemented"));
+ internal_error (_("m68k_get_longjmp_target: not implemented"));
return 0;
}
void
m68k_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
/* SVR4 uses a different calling convention. */
set_gdbarch_return_value (gdbarch, m68k_svr4_return_value);
static void
m68k_embedded_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
m68k_svr4_init_abi (info, gdbarch);
tdep->pointer_result_regnum = M68K_D0_REGNUM;
static struct gdbarch *
m68k_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
- struct gdbarch_tdep *tdep = NULL;
- struct gdbarch *gdbarch;
struct gdbarch_list *best_arch;
- struct tdesc_arch_data *tdesc_data = NULL;
+ tdesc_arch_data_up tdesc_data;
int i;
enum m68k_flavour flavour = m68k_no_flavour;
int has_fp = 1;
valid_p = 1;
for (i = 0; i <= M68K_PC_REGNUM; i++)
- valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
+ valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
m68k_register_names[i]);
if (!valid_p)
- {
- tdesc_data_cleanup (tdesc_data);
- return NULL;
- }
+ return NULL;
feature = tdesc_find_feature (info.target_desc,
"org.gnu.gdb.coldfire.fp");
{
valid_p = 1;
for (i = M68K_FP0_REGNUM; i <= M68K_FPI_REGNUM; i++)
- valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
+ valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
m68k_register_names[i]);
if (!valid_p)
- {
- tdesc_data_cleanup (tdesc_data);
- return NULL;
- }
+ return NULL;
}
else
has_fp = 0;
best_arch != NULL;
best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
{
- if (flavour != gdbarch_tdep (best_arch->gdbarch)->flavour)
+ m68k_gdbarch_tdep *tdep
+ = gdbarch_tdep<m68k_gdbarch_tdep> (best_arch->gdbarch);
+
+ if (flavour != tdep->flavour)
continue;
- if (has_fp != gdbarch_tdep (best_arch->gdbarch)->fpregs_present)
+ if (has_fp != tdep->fpregs_present)
continue;
- if (float_return != gdbarch_tdep (best_arch->gdbarch)->float_return)
+ if (float_return != tdep->float_return)
continue;
break;
}
if (best_arch != NULL)
- {
- if (tdesc_data != NULL)
- tdesc_data_cleanup (tdesc_data);
- return best_arch->gdbarch;
- }
+ return best_arch->gdbarch;
+
+ gdbarch *gdbarch
+ = gdbarch_alloc (&info, gdbarch_tdep_up (new m68k_gdbarch_tdep));
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
- tdep = XCNEW (struct gdbarch_tdep);
- gdbarch = gdbarch_alloc (&info, tdep);
tdep->fpregs_present = has_fp;
tdep->float_return = float_return;
tdep->flavour = flavour;
frame_unwind_append_unwinder (gdbarch, &m68k_frame_unwind);
- if (tdesc_data)
- tdesc_use_registers (gdbarch, info.target_desc, tdesc_data);
+ if (tdesc_data != nullptr)
+ tdesc_use_registers (gdbarch, info.target_desc, std::move (tdesc_data));
return gdbarch;
}
static void
m68k_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
{
- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ m68k_gdbarch_tdep *tdep = gdbarch_tdep<m68k_gdbarch_tdep> (gdbarch);
if (tdep == NULL)
return;