mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
0747795c08
This changes all includes to use the form "common/filename.h" rather than just "filename.h". This was written by a script. gdb/ChangeLog 2019-01-25 Tom Tromey <tom@tromey.com> * xtensa-linux-nat.c: Fix common/ includes. * xml-support.h: Fix common/ includes. * xml-support.c: Fix common/ includes. * x86-linux-nat.c: Fix common/ includes. * windows-nat.c: Fix common/ includes. * varobj.h: Fix common/ includes. * varobj.c: Fix common/ includes. * value.c: Fix common/ includes. * valops.c: Fix common/ includes. * utils.c: Fix common/ includes. * unittests/xml-utils-selftests.c: Fix common/ includes. * unittests/utils-selftests.c: Fix common/ includes. * unittests/unpack-selftests.c: Fix common/ includes. * unittests/tracepoint-selftests.c: Fix common/ includes. * unittests/style-selftests.c: Fix common/ includes. * unittests/string_view-selftests.c: Fix common/ includes. * unittests/scoped_restore-selftests.c: Fix common/ includes. * unittests/scoped_mmap-selftests.c: Fix common/ includes. * unittests/scoped_fd-selftests.c: Fix common/ includes. * unittests/rsp-low-selftests.c: Fix common/ includes. * unittests/parse-connection-spec-selftests.c: Fix common/ includes. * unittests/optional-selftests.c: Fix common/ includes. * unittests/offset-type-selftests.c: Fix common/ includes. * unittests/observable-selftests.c: Fix common/ includes. * unittests/mkdir-recursive-selftests.c: Fix common/ includes. * unittests/memrange-selftests.c: Fix common/ includes. * unittests/memory-map-selftests.c: Fix common/ includes. * unittests/lookup_name_info-selftests.c: Fix common/ includes. * unittests/function-view-selftests.c: Fix common/ includes. * unittests/environ-selftests.c: Fix common/ includes. * unittests/copy_bitwise-selftests.c: Fix common/ includes. * unittests/common-utils-selftests.c: Fix common/ includes. * unittests/cli-utils-selftests.c: Fix common/ includes. * unittests/array-view-selftests.c: Fix common/ includes. * ui-file.c: Fix common/ includes. * tui/tui-io.c: Fix common/ includes. * tracepoint.h: Fix common/ includes. * tracepoint.c: Fix common/ includes. * tracefile-tfile.c: Fix common/ includes. * top.h: Fix common/ includes. * top.c: Fix common/ includes. * thread.c: Fix common/ includes. * target/waitstatus.h: Fix common/ includes. * target/waitstatus.c: Fix common/ includes. * target.h: Fix common/ includes. * target.c: Fix common/ includes. * target-memory.c: Fix common/ includes. * target-descriptions.c: Fix common/ includes. * symtab.h: Fix common/ includes. * symfile.c: Fix common/ includes. * stap-probe.c: Fix common/ includes. * spu-linux-nat.c: Fix common/ includes. * sparc-nat.c: Fix common/ includes. * source.c: Fix common/ includes. * solib.c: Fix common/ includes. * solib-target.c: Fix common/ includes. * ser-unix.c: Fix common/ includes. * ser-tcp.c: Fix common/ includes. * ser-pipe.c: Fix common/ includes. * ser-base.c: Fix common/ includes. * selftest-arch.c: Fix common/ includes. * s12z-tdep.c: Fix common/ includes. * rust-exp.y: Fix common/ includes. * rs6000-aix-tdep.c: Fix common/ includes. * riscv-tdep.c: Fix common/ includes. * remote.c: Fix common/ includes. * remote-notif.h: Fix common/ includes. * remote-fileio.h: Fix common/ includes. * remote-fileio.c: Fix common/ includes. * regcache.h: Fix common/ includes. * regcache.c: Fix common/ includes. * record-btrace.c: Fix common/ includes. * python/python.c: Fix common/ includes. * python/py-type.c: Fix common/ includes. * python/py-inferior.c: Fix common/ includes. * progspace.h: Fix common/ includes. * producer.c: Fix common/ includes. * procfs.c: Fix common/ includes. * proc-api.c: Fix common/ includes. * printcmd.c: Fix common/ includes. * ppc-linux-nat.c: Fix common/ includes. * parser-defs.h: Fix common/ includes. * osdata.c: Fix common/ includes. * obsd-nat.c: Fix common/ includes. * nat/x86-linux.c: Fix common/ includes. * nat/x86-linux-dregs.c: Fix common/ includes. * nat/x86-dregs.h: Fix common/ includes. * nat/x86-dregs.c: Fix common/ includes. * nat/ppc-linux.c: Fix common/ includes. * nat/mips-linux-watch.h: Fix common/ includes. * nat/mips-linux-watch.c: Fix common/ includes. * nat/linux-waitpid.c: Fix common/ includes. * nat/linux-ptrace.h: Fix common/ includes. * nat/linux-ptrace.c: Fix common/ includes. * nat/linux-procfs.c: Fix common/ includes. * nat/linux-personality.c: Fix common/ includes. * nat/linux-osdata.c: Fix common/ includes. * nat/linux-namespaces.c: Fix common/ includes. * nat/linux-btrace.h: Fix common/ includes. * nat/linux-btrace.c: Fix common/ includes. * nat/fork-inferior.c: Fix common/ includes. * nat/amd64-linux-siginfo.c: Fix common/ includes. * nat/aarch64-sve-linux-ptrace.c: Fix common/ includes. * nat/aarch64-linux.c: Fix common/ includes. * nat/aarch64-linux-hw-point.h: Fix common/ includes. * nat/aarch64-linux-hw-point.c: Fix common/ includes. * namespace.h: Fix common/ includes. * mips-linux-tdep.c: Fix common/ includes. * minsyms.c: Fix common/ includes. * mi/mi-parse.h: Fix common/ includes. * mi/mi-main.c: Fix common/ includes. * mi/mi-cmd-env.c: Fix common/ includes. * memrange.h: Fix common/ includes. * memattr.c: Fix common/ includes. * maint.h: Fix common/ includes. * maint.c: Fix common/ includes. * main.c: Fix common/ includes. * machoread.c: Fix common/ includes. * location.c: Fix common/ includes. * linux-thread-db.c: Fix common/ includes. * linux-nat.c: Fix common/ includes. * linux-fork.c: Fix common/ includes. * inline-frame.c: Fix common/ includes. * infrun.c: Fix common/ includes. * inflow.c: Fix common/ includes. * inferior.h: Fix common/ includes. * inferior.c: Fix common/ includes. * infcmd.c: Fix common/ includes. * inf-ptrace.c: Fix common/ includes. * inf-child.c: Fix common/ includes. * ia64-linux-nat.c: Fix common/ includes. * i387-tdep.c: Fix common/ includes. * i386-tdep.c: Fix common/ includes. * i386-linux-tdep.c: Fix common/ includes. * i386-linux-nat.c: Fix common/ includes. * i386-go32-tdep.c: Fix common/ includes. * i386-fbsd-tdep.c: Fix common/ includes. * i386-fbsd-nat.c: Fix common/ includes. * guile/scm-type.c: Fix common/ includes. * guile/guile.c: Fix common/ includes. * go32-nat.c: Fix common/ includes. * gnu-nat.c: Fix common/ includes. * gdbthread.h: Fix common/ includes. * gdbarch-selftests.c: Fix common/ includes. * gdb_usleep.c: Fix common/ includes. * gdb_select.h: Fix common/ includes. * gdb_bfd.c: Fix common/ includes. * gcore.c: Fix common/ includes. * fork-child.c: Fix common/ includes. * findvar.c: Fix common/ includes. * fbsd-nat.c: Fix common/ includes. * event-top.c: Fix common/ includes. * event-loop.c: Fix common/ includes. * dwarf2read.c: Fix common/ includes. * dwarf2loc.c: Fix common/ includes. * dwarf2-frame.c: Fix common/ includes. * dwarf-index-cache.c: Fix common/ includes. * dtrace-probe.c: Fix common/ includes. * disasm-selftests.c: Fix common/ includes. * defs.h: Fix common/ includes. * csky-tdep.c: Fix common/ includes. * cp-valprint.c: Fix common/ includes. * cp-support.h: Fix common/ includes. * cp-support.c: Fix common/ includes. * corelow.c: Fix common/ includes. * completer.h: Fix common/ includes. * completer.c: Fix common/ includes. * compile/compile.c: Fix common/ includes. * compile/compile-loc2c.c: Fix common/ includes. * compile/compile-cplus-types.c: Fix common/ includes. * compile/compile-cplus-symbols.c: Fix common/ includes. * command.h: Fix common/ includes. * cli/cli-dump.c: Fix common/ includes. * cli/cli-cmds.c: Fix common/ includes. * charset.c: Fix common/ includes. * build-id.c: Fix common/ includes. * btrace.h: Fix common/ includes. * btrace.c: Fix common/ includes. * breakpoint.h: Fix common/ includes. * breakpoint.c: Fix common/ includes. * ax.h: (enum agent_op): Fix common/ includes. * ax-general.c (struct aop_map): Fix common/ includes. * ax-gdb.c: Fix common/ includes. * auxv.c: Fix common/ includes. * auto-load.c: Fix common/ includes. * arm-tdep.c: Fix common/ includes. * arch/riscv.c: Fix common/ includes. * arch/ppc-linux-common.c: Fix common/ includes. * arch/i386.c: Fix common/ includes. * arch/arm.c: Fix common/ includes. * arch/arm-linux.c: Fix common/ includes. * arch/arm-get-next-pcs.c: Fix common/ includes. * arch/amd64.c: Fix common/ includes. * arch/aarch64.c: Fix common/ includes. * arch/aarch64-insn.c: Fix common/ includes. * arch-utils.c: Fix common/ includes. * amd64-windows-tdep.c: Fix common/ includes. * amd64-tdep.c: Fix common/ includes. * amd64-sol2-tdep.c: Fix common/ includes. * amd64-obsd-tdep.c: Fix common/ includes. * amd64-nbsd-tdep.c: Fix common/ includes. * amd64-linux-tdep.c: Fix common/ includes. * amd64-linux-nat.c: Fix common/ includes. * amd64-fbsd-tdep.c: Fix common/ includes. * amd64-fbsd-nat.c: Fix common/ includes. * amd64-dicos-tdep.c: Fix common/ includes. * amd64-darwin-tdep.c: Fix common/ includes. * agent.c: Fix common/ includes. * ada-lang.h: Fix common/ includes. * ada-lang.c: Fix common/ includes. * aarch64-tdep.c: Fix common/ includes. gdb/gdbserver/ChangeLog 2019-01-25 Tom Tromey <tom@tromey.com> * win32-low.c: Fix common/ includes. * win32-i386-low.c: Fix common/ includes. * tracepoint.c: Fix common/ includes. * thread-db.c: Fix common/ includes. * target.h: Fix common/ includes. * symbol.c: Fix common/ includes. * spu-low.c: Fix common/ includes. * server.h: Fix common/ includes. * server.c: Fix common/ includes. * remote-utils.c: Fix common/ includes. * regcache.h: Fix common/ includes. * regcache.c: Fix common/ includes. * nto-x86-low.c: Fix common/ includes. * notif.h: Fix common/ includes. * mem-break.h: Fix common/ includes. * lynx-low.c: Fix common/ includes. * lynx-i386-low.c: Fix common/ includes. * linux-x86-tdesc-selftest.c: Fix common/ includes. * linux-x86-low.c: Fix common/ includes. * linux-low.c: Fix common/ includes. * inferiors.h: Fix common/ includes. * i387-fp.c: Fix common/ includes. * hostio.c: Fix common/ includes. * hostio-errno.c: Fix common/ includes. * gdbthread.h: Fix common/ includes. * gdbreplay.c: Fix common/ includes. * fork-child.c: Fix common/ includes. * event-loop.c: Fix common/ includes. * ax.c: (enum gdb_agent_op): Fix common/ includes.
603 lines
18 KiB
C
603 lines
18 KiB
C
/* Target-dependent code for the S12Z, for the GDB.
|
||
Copyright (C) 2018-2019 Free Software Foundation, Inc.
|
||
|
||
This file is part of GDB.
|
||
|
||
This program is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||
|
||
/* Much of this file is shamelessly copied from or1k-tdep.c and others. */
|
||
|
||
#include "defs.h"
|
||
|
||
#include "arch-utils.h"
|
||
#include "dwarf2-frame.h"
|
||
#include "common/errors.h"
|
||
#include "frame-unwind.h"
|
||
#include "gdbcore.h"
|
||
#include "gdbcmd.h"
|
||
#include "inferior.h"
|
||
#include "opcode/s12z.h"
|
||
#include "trad-frame.h"
|
||
#include "remote.h"
|
||
|
||
/* Two of the registers included in S12Z_N_REGISTERS are
|
||
the CCH and CCL "registers" which are just views into
|
||
the CCW register. */
|
||
#define N_PHYSICAL_REGISTERS (S12Z_N_REGISTERS - 2)
|
||
|
||
|
||
/* A permutation of all the physical registers. Indexing this array
|
||
with an integer from gdb's internal representation will return the
|
||
register enum. */
|
||
static const int reg_perm[N_PHYSICAL_REGISTERS] =
|
||
{
|
||
REG_D0,
|
||
REG_D1,
|
||
REG_D2,
|
||
REG_D3,
|
||
REG_D4,
|
||
REG_D5,
|
||
REG_D6,
|
||
REG_D7,
|
||
REG_X,
|
||
REG_Y,
|
||
REG_S,
|
||
REG_P,
|
||
REG_CCW
|
||
};
|
||
|
||
/* The inverse of the above permutation. Indexing this
|
||
array with a register enum (e.g. REG_D2) will return the register
|
||
number in gdb's internal representation. */
|
||
static const int inv_reg_perm[N_PHYSICAL_REGISTERS] =
|
||
{
|
||
2, 3, 4, 5, /* d2, d3, d4, d5 */
|
||
0, 1, /* d0, d1 */
|
||
6, 7, /* d6, d7 */
|
||
8, 9, 10, 11, 12 /* x, y, s, p, ccw */
|
||
};
|
||
|
||
/* Return the name of the register REGNUM. */
|
||
static const char *
|
||
s12z_register_name (struct gdbarch *gdbarch, int regnum)
|
||
{
|
||
/* Registers is declared in opcodes/s12z.h. */
|
||
return registers[reg_perm[regnum]].name;
|
||
}
|
||
|
||
static CORE_ADDR
|
||
s12z_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
|
||
{
|
||
CORE_ADDR start_pc = 0;
|
||
|
||
if (find_pc_partial_function (pc, NULL, &start_pc, NULL))
|
||
{
|
||
CORE_ADDR prologue_end = skip_prologue_using_sal (gdbarch, pc);
|
||
|
||
if (prologue_end != 0)
|
||
return prologue_end;
|
||
}
|
||
|
||
warning (_("%s Failed to find end of prologue PC = %08x\n"),
|
||
__FUNCTION__, (unsigned int) pc);
|
||
|
||
return pc;
|
||
}
|
||
|
||
/* Implement the unwind_pc gdbarch method. */
|
||
static CORE_ADDR
|
||
s12z_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
|
||
{
|
||
return frame_unwind_register_unsigned (next_frame, REG_P);
|
||
}
|
||
|
||
/* Implement the unwind_sp gdbarch method. */
|
||
static CORE_ADDR
|
||
s12z_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
|
||
{
|
||
return frame_unwind_register_unsigned (next_frame, REG_S);
|
||
}
|
||
|
||
static struct type *
|
||
s12z_register_type (struct gdbarch *gdbarch, int reg_nr)
|
||
{
|
||
switch (registers[reg_perm[reg_nr]].bytes)
|
||
{
|
||
case 1:
|
||
return builtin_type (gdbarch)->builtin_uint8;
|
||
case 2:
|
||
return builtin_type (gdbarch)->builtin_uint16;
|
||
case 3:
|
||
return builtin_type (gdbarch)->builtin_uint24;
|
||
case 4:
|
||
return builtin_type (gdbarch)->builtin_uint32;
|
||
default:
|
||
return builtin_type (gdbarch)->builtin_uint32;
|
||
}
|
||
return builtin_type (gdbarch)->builtin_int0;
|
||
}
|
||
|
||
|
||
static int
|
||
s12z_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int num)
|
||
{
|
||
switch (num)
|
||
{
|
||
case 15: return REG_S;
|
||
case 7: return REG_X;
|
||
case 8: return REG_Y;
|
||
case 42: return REG_D0;
|
||
case 43: return REG_D1;
|
||
case 44: return REG_D2;
|
||
case 45: return REG_D3;
|
||
case 46: return REG_D4;
|
||
case 47: return REG_D5;
|
||
case 48: return REG_D6;
|
||
case 49: return REG_D7;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
|
||
/* Support functions for frame handling. */
|
||
|
||
/* Copy of gdb_buffered_insn_length_fprintf from disasm.c. */
|
||
|
||
static int ATTRIBUTE_PRINTF (2, 3)
|
||
s12z_fprintf_disasm (void *stream, const char *format, ...)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
struct disassemble_info
|
||
s12z_disassemble_info (struct gdbarch *gdbarch)
|
||
{
|
||
struct disassemble_info di;
|
||
init_disassemble_info (&di, &null_stream, s12z_fprintf_disasm);
|
||
di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
|
||
di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
|
||
di.endian = gdbarch_byte_order (gdbarch);
|
||
di.read_memory_func = [](bfd_vma memaddr, gdb_byte *myaddr,
|
||
unsigned int len, struct disassemble_info *info)
|
||
{
|
||
return target_read_code (memaddr, myaddr, len);
|
||
};
|
||
return di;
|
||
}
|
||
|
||
/* Initialize a prologue cache. */
|
||
|
||
static struct trad_frame_cache *
|
||
s12z_frame_cache (struct frame_info *this_frame, void **prologue_cache)
|
||
{
|
||
struct trad_frame_cache *info;
|
||
|
||
CORE_ADDR this_sp;
|
||
CORE_ADDR this_sp_for_id;
|
||
|
||
CORE_ADDR start_addr;
|
||
CORE_ADDR end_addr;
|
||
|
||
/* Nothing to do if we already have this info. */
|
||
if (NULL != *prologue_cache)
|
||
return (struct trad_frame_cache *) *prologue_cache;
|
||
|
||
/* Get a new prologue cache and populate it with default values. */
|
||
info = trad_frame_cache_zalloc (this_frame);
|
||
*prologue_cache = info;
|
||
|
||
/* Find the start address of this function (which is a normal frame, even
|
||
if the next frame is the sentinel frame) and the end of its prologue. */
|
||
CORE_ADDR this_pc = get_frame_pc (this_frame);
|
||
struct gdbarch *gdbarch = get_frame_arch (this_frame);
|
||
find_pc_partial_function (this_pc, NULL, &start_addr, NULL);
|
||
|
||
/* Get the stack pointer if we have one (if there's no process executing
|
||
yet we won't have a frame. */
|
||
this_sp = (NULL == this_frame) ? 0 :
|
||
get_frame_register_unsigned (this_frame, REG_S);
|
||
|
||
/* Return early if GDB couldn't find the function. */
|
||
if (start_addr == 0)
|
||
{
|
||
warning (_("Couldn't find function including address %s SP is %s\n"),
|
||
paddress (gdbarch, this_pc),
|
||
paddress (gdbarch, this_sp));
|
||
|
||
/* JPB: 28-Apr-11. This is a temporary patch, to get round GDB
|
||
crashing right at the beginning. Build the frame ID as best we
|
||
can. */
|
||
trad_frame_set_id (info, frame_id_build (this_sp, this_pc));
|
||
|
||
return info;
|
||
}
|
||
|
||
/* The default frame base of this frame (for ID purposes only - frame
|
||
base is an overloaded term) is its stack pointer. For now we use the
|
||
value of the SP register in this frame. However if the PC is in the
|
||
prologue of this frame, before the SP has been set up, then the value
|
||
will actually be that of the prev frame, and we'll need to adjust it
|
||
later. */
|
||
trad_frame_set_this_base (info, this_sp);
|
||
this_sp_for_id = this_sp;
|
||
|
||
/* We should only examine code that is in the prologue. This is all code
|
||
up to (but not including) end_addr. We should only populate the cache
|
||
while the address is up to (but not including) the PC or end_addr,
|
||
whichever is first. */
|
||
end_addr = s12z_skip_prologue (gdbarch, start_addr);
|
||
|
||
/* All the following analysis only occurs if we are in the prologue and
|
||
have executed the code. Check we have a sane prologue size, and if
|
||
zero we are frameless and can give up here. */
|
||
if (end_addr < start_addr)
|
||
error (_("end addr %s is less than start addr %s"),
|
||
paddress (gdbarch, end_addr), paddress (gdbarch, start_addr));
|
||
|
||
CORE_ADDR addr = start_addr; /* Where we have got to? */
|
||
int frame_size = 0;
|
||
int saved_frame_size = 0;
|
||
while (this_pc > addr)
|
||
{
|
||
struct disassemble_info di = s12z_disassemble_info (gdbarch);
|
||
|
||
/* No instruction can be more than 11 bytes long, I think. */
|
||
gdb_byte buf[11];
|
||
|
||
int nb = print_insn_s12z (addr, &di);
|
||
gdb_assert (nb <= 11);
|
||
|
||
if (0 != target_read_code (addr, buf, nb))
|
||
memory_error (TARGET_XFER_E_IO, addr);
|
||
|
||
if (buf[0] == 0x05) /* RTS */
|
||
{
|
||
frame_size = saved_frame_size;
|
||
}
|
||
/* Conditional Branches. If any of these are encountered, then
|
||
it is likely that a RTS will terminate it. So we need to save
|
||
the frame size so it can be restored. */
|
||
else if ( (buf[0] == 0x02) /* BRSET */
|
||
|| (buf[0] == 0x0B) /* DBcc / TBcc */
|
||
|| (buf[0] == 0x03)) /* BRCLR */
|
||
{
|
||
saved_frame_size = frame_size;
|
||
}
|
||
else if (buf[0] == 0x04) /* PUL/ PSH .. */
|
||
{
|
||
bool pull = buf[1] & 0x80;
|
||
int stack_adjustment = 0;
|
||
if (buf[1] & 0x40)
|
||
{
|
||
if (buf[1] & 0x01) stack_adjustment += 3; /* Y */
|
||
if (buf[1] & 0x02) stack_adjustment += 3; /* X */
|
||
if (buf[1] & 0x04) stack_adjustment += 4; /* D7 */
|
||
if (buf[1] & 0x08) stack_adjustment += 4; /* D6 */
|
||
if (buf[1] & 0x10) stack_adjustment += 2; /* D5 */
|
||
if (buf[1] & 0x20) stack_adjustment += 2; /* D4 */
|
||
}
|
||
else
|
||
{
|
||
if (buf[1] & 0x01) stack_adjustment += 2; /* D3 */
|
||
if (buf[1] & 0x02) stack_adjustment += 2; /* D2 */
|
||
if (buf[1] & 0x04) stack_adjustment += 1; /* D1 */
|
||
if (buf[1] & 0x08) stack_adjustment += 1; /* D0 */
|
||
if (buf[1] & 0x10) stack_adjustment += 1; /* CCL */
|
||
if (buf[1] & 0x20) stack_adjustment += 1; /* CCH */
|
||
}
|
||
|
||
if (!pull)
|
||
stack_adjustment = -stack_adjustment;
|
||
frame_size -= stack_adjustment;
|
||
}
|
||
else if (buf[0] == 0x0a) /* LEA S, (xxx, S) */
|
||
{
|
||
if (0x06 == (buf[1] >> 4))
|
||
{
|
||
int simm = (signed char) (buf[1] & 0x0F);
|
||
frame_size -= simm;
|
||
}
|
||
}
|
||
else if (buf[0] == 0x1a) /* LEA S, (S, xxxx) */
|
||
{
|
||
int simm = (signed char) buf[1];
|
||
frame_size -= simm;
|
||
}
|
||
addr += nb;
|
||
}
|
||
|
||
/* If the PC has not actually got to this point, then the frame
|
||
base will be wrong, and we adjust it. */
|
||
if (this_pc < addr)
|
||
{
|
||
/* Only do if executing. */
|
||
if (0 != this_sp)
|
||
{
|
||
this_sp_for_id = this_sp - frame_size;
|
||
trad_frame_set_this_base (info, this_sp_for_id);
|
||
}
|
||
trad_frame_set_reg_value (info, REG_S, this_sp + 3);
|
||
trad_frame_set_reg_addr (info, REG_P, this_sp);
|
||
}
|
||
else
|
||
{
|
||
gdb_assert (this_sp == this_sp_for_id);
|
||
/* The stack pointer of the prev frame is frame_size greater
|
||
than the stack pointer of this frame plus one address
|
||
size (caused by the JSR or BSR). */
|
||
trad_frame_set_reg_value (info, REG_S,
|
||
this_sp + frame_size + 3);
|
||
trad_frame_set_reg_addr (info, REG_P, this_sp + frame_size);
|
||
}
|
||
|
||
|
||
/* Build the frame ID. */
|
||
trad_frame_set_id (info, frame_id_build (this_sp_for_id, start_addr));
|
||
|
||
return info;
|
||
}
|
||
|
||
/* Implement the this_id function for the stub unwinder. */
|
||
static void
|
||
s12z_frame_this_id (struct frame_info *this_frame,
|
||
void **prologue_cache, struct frame_id *this_id)
|
||
{
|
||
struct trad_frame_cache *info = s12z_frame_cache (this_frame,
|
||
prologue_cache);
|
||
|
||
trad_frame_get_id (info, this_id);
|
||
}
|
||
|
||
|
||
/* Implement the prev_register function for the stub unwinder. */
|
||
static struct value *
|
||
s12z_frame_prev_register (struct frame_info *this_frame,
|
||
void **prologue_cache, int regnum)
|
||
{
|
||
struct trad_frame_cache *info = s12z_frame_cache (this_frame,
|
||
prologue_cache);
|
||
|
||
return trad_frame_get_register (info, this_frame, regnum);
|
||
}
|
||
|
||
/* Data structures for the normal prologue-analysis-based unwinder. */
|
||
static const struct frame_unwind s12z_frame_unwind = {
|
||
NORMAL_FRAME,
|
||
default_frame_unwind_stop_reason,
|
||
s12z_frame_this_id,
|
||
s12z_frame_prev_register,
|
||
NULL,
|
||
default_frame_sniffer,
|
||
NULL,
|
||
};
|
||
|
||
|
||
constexpr gdb_byte s12z_break_insn[] = {0x00};
|
||
|
||
typedef BP_MANIPULATION (s12z_break_insn) s12z_breakpoint;
|
||
|
||
struct gdbarch_tdep
|
||
{
|
||
};
|
||
|
||
/* A vector of human readable characters representing the
|
||
bits in the CCW register. Unused bits are represented as '-'.
|
||
Lowest significant bit comes first. */
|
||
static const char ccw_bits[] =
|
||
{
|
||
'C', /* Carry */
|
||
'V', /* Two's Complement Overflow */
|
||
'Z', /* Zero */
|
||
'N', /* Negative */
|
||
'I', /* Interrupt */
|
||
'-',
|
||
'X', /* Non-Maskable Interrupt */
|
||
'S', /* STOP Disable */
|
||
'0', /* Interrupt priority level */
|
||
'0', /* ditto */
|
||
'0', /* ditto */
|
||
'-',
|
||
'-',
|
||
'-',
|
||
'-',
|
||
'U' /* User/Supervisor State. */
|
||
};
|
||
|
||
/* Print a human readable representation of the CCW register.
|
||
For example: "u----000SX-Inzvc" corresponds to the value
|
||
0xD0. */
|
||
static void
|
||
s12z_print_ccw_info (struct gdbarch *gdbarch,
|
||
struct ui_file *file,
|
||
struct frame_info *frame,
|
||
int reg)
|
||
{
|
||
struct value *v = value_of_register (reg, frame);
|
||
const char *name = gdbarch_register_name (gdbarch, reg);
|
||
uint32_t ccw = value_as_long (v);
|
||
fputs_filtered (name, file);
|
||
size_t len = strlen (name);
|
||
const int stop_1 = 15;
|
||
const int stop_2 = 17;
|
||
for (int i = 0; i < stop_1 - len; ++i)
|
||
fputc_filtered (' ', file);
|
||
fprintf_filtered (file, "0x%04x", ccw);
|
||
for (int i = 0; i < stop_2 - len; ++i)
|
||
fputc_filtered (' ', file);
|
||
for (int b = 15; b >= 0; --b)
|
||
{
|
||
if (ccw & (0x1u << b))
|
||
{
|
||
if (ccw_bits[b] == 0)
|
||
fputc_filtered ('1', file);
|
||
else
|
||
fputc_filtered (ccw_bits[b], file);
|
||
}
|
||
else
|
||
fputc_filtered (tolower (ccw_bits[b]), file);
|
||
}
|
||
fputc_filtered ('\n', file);
|
||
}
|
||
|
||
static void
|
||
s12z_print_registers_info (struct gdbarch *gdbarch,
|
||
struct ui_file *file,
|
||
struct frame_info *frame,
|
||
int regnum, int print_all)
|
||
{
|
||
const int numregs = (gdbarch_num_regs (gdbarch)
|
||
+ gdbarch_num_pseudo_regs (gdbarch));
|
||
|
||
if (regnum == -1)
|
||
{
|
||
for (int reg = 0; reg < numregs; reg++)
|
||
{
|
||
if (REG_CCW == reg_perm[reg])
|
||
{
|
||
s12z_print_ccw_info (gdbarch, file, frame, reg);
|
||
continue;
|
||
}
|
||
default_print_registers_info (gdbarch, file, frame, reg, print_all);
|
||
}
|
||
}
|
||
else if (REG_CCW == reg_perm[regnum])
|
||
s12z_print_ccw_info (gdbarch, file, frame, regnum);
|
||
else
|
||
default_print_registers_info (gdbarch, file, frame, regnum, print_all);
|
||
}
|
||
|
||
|
||
|
||
|
||
static void
|
||
s12z_extract_return_value (struct type *type, struct regcache *regcache,
|
||
void *valbuf)
|
||
{
|
||
int reg = -1;
|
||
|
||
switch (TYPE_LENGTH (type))
|
||
{
|
||
case 0: /* Nothing to do */
|
||
return;
|
||
|
||
case 1:
|
||
reg = REG_D0;
|
||
break;
|
||
|
||
case 2:
|
||
reg = REG_D2;
|
||
break;
|
||
|
||
case 3:
|
||
reg = REG_X;
|
||
break;
|
||
|
||
case 4:
|
||
reg = REG_D6;
|
||
break;
|
||
|
||
default:
|
||
error (_("bad size for return value"));
|
||
return;
|
||
}
|
||
|
||
regcache->cooked_read (inv_reg_perm[reg], (gdb_byte *) valbuf);
|
||
}
|
||
|
||
static enum return_value_convention
|
||
s12z_return_value (struct gdbarch *gdbarch, struct value *function,
|
||
struct type *type, struct regcache *regcache,
|
||
gdb_byte *readbuf, const gdb_byte *writebuf)
|
||
{
|
||
if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|
||
|| TYPE_CODE (type) == TYPE_CODE_UNION
|
||
|| TYPE_CODE (type) == TYPE_CODE_ARRAY
|
||
|| TYPE_LENGTH (type) > 4)
|
||
return RETURN_VALUE_STRUCT_CONVENTION;
|
||
|
||
if (readbuf)
|
||
s12z_extract_return_value (type, regcache, readbuf);
|
||
|
||
return RETURN_VALUE_REGISTER_CONVENTION;
|
||
}
|
||
|
||
|
||
static void
|
||
show_bdccsr_command (const char *args, int from_tty)
|
||
{
|
||
struct string_file output;
|
||
target_rcmd ("bdccsr", &output);
|
||
|
||
printf_unfiltered ("The current BDCCSR value is %s\n", output.string().c_str());
|
||
}
|
||
|
||
static struct gdbarch *
|
||
s12z_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
|
||
{
|
||
struct gdbarch_tdep *tdep = XNEW (struct gdbarch_tdep);
|
||
struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
|
||
|
||
add_cmd ("bdccsr", class_support, show_bdccsr_command,
|
||
_("Show the current value of the microcontroller's BDCCSR."),
|
||
&maintenanceinfolist);
|
||
|
||
/* Target data types. */
|
||
set_gdbarch_short_bit (gdbarch, 16);
|
||
set_gdbarch_int_bit (gdbarch, 16);
|
||
set_gdbarch_long_bit (gdbarch, 32);
|
||
set_gdbarch_long_long_bit (gdbarch, 32);
|
||
set_gdbarch_ptr_bit (gdbarch, 24);
|
||
set_gdbarch_addr_bit (gdbarch, 24);
|
||
set_gdbarch_char_signed (gdbarch, 0);
|
||
|
||
set_gdbarch_ps_regnum (gdbarch, REG_CCW);
|
||
set_gdbarch_pc_regnum (gdbarch, REG_P);
|
||
set_gdbarch_sp_regnum (gdbarch, REG_S);
|
||
|
||
|
||
set_gdbarch_print_registers_info (gdbarch, s12z_print_registers_info);
|
||
|
||
set_gdbarch_breakpoint_kind_from_pc (gdbarch,
|
||
s12z_breakpoint::kind_from_pc);
|
||
set_gdbarch_sw_breakpoint_from_kind (gdbarch,
|
||
s12z_breakpoint::bp_from_kind);
|
||
|
||
set_gdbarch_num_regs (gdbarch, N_PHYSICAL_REGISTERS);
|
||
set_gdbarch_register_name (gdbarch, s12z_register_name);
|
||
set_gdbarch_skip_prologue (gdbarch, s12z_skip_prologue);
|
||
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
|
||
set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s12z_dwarf_reg_to_regnum);
|
||
|
||
set_gdbarch_register_type (gdbarch, s12z_register_type);
|
||
|
||
/* Functions to access frame data. */
|
||
set_gdbarch_unwind_pc (gdbarch, s12z_unwind_pc);
|
||
set_gdbarch_unwind_sp (gdbarch, s12z_unwind_sp);
|
||
|
||
frame_unwind_append_unwinder (gdbarch, &s12z_frame_unwind);
|
||
/* Currently, the only known producer for this archtecture, produces buggy
|
||
dwarf CFI. So don't append a dwarf unwinder until the situation is
|
||
better understood. */
|
||
|
||
set_gdbarch_return_value (gdbarch, s12z_return_value);
|
||
|
||
return gdbarch;
|
||
}
|
||
|
||
void
|
||
_initialize_s12z_tdep (void)
|
||
{
|
||
gdbarch_register (bfd_arch_s12z, s12z_gdbarch_init, NULL);
|
||
}
|