2019-10-18 08:48:08 +08:00
|
|
|
/* Target dependent code for ARC architecture, for GDB.
|
2016-08-13 01:02:20 +08:00
|
|
|
|
2024-01-12 23:30:44 +08:00
|
|
|
Copyright 2005-2024 Free Software Foundation, Inc.
|
2016-08-13 01:02:20 +08:00
|
|
|
Contributed by Synopsys 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/>. */
|
|
|
|
|
|
|
|
#ifndef ARC_TDEP_H
|
|
|
|
#define ARC_TDEP_H
|
|
|
|
|
|
|
|
/* Need disassemble_info. */
|
|
|
|
#include "dis-asm.h"
|
2020-08-04 02:41:42 +08:00
|
|
|
#include "gdbarch.h"
|
2017-10-26 02:51:54 +08:00
|
|
|
#include "arch/arc.h"
|
2016-08-13 01:02:20 +08:00
|
|
|
|
2017-02-10 19:11:46 +08:00
|
|
|
/* To simplify GDB code this enum assumes that internal regnums should be same
|
|
|
|
as architectural register numbers, i.e. PCL regnum is 63. This allows to
|
|
|
|
use internal GDB regnums as architectural numbers when dealing with
|
|
|
|
instruction encodings, for example when analyzing what are the registers
|
|
|
|
saved in function prologue. */
|
|
|
|
|
2016-08-13 01:02:20 +08:00
|
|
|
enum arc_regnum
|
|
|
|
{
|
|
|
|
/* Core registers. */
|
|
|
|
ARC_R0_REGNUM = 0,
|
|
|
|
ARC_R1_REGNUM = 1,
|
|
|
|
ARC_R4_REGNUM = 4,
|
|
|
|
ARC_R7_REGNUM = 7,
|
|
|
|
ARC_R9_REGNUM = 9,
|
|
|
|
ARC_R13_REGNUM = 13,
|
|
|
|
ARC_R16_REGNUM = 16,
|
|
|
|
ARC_R25_REGNUM = 25,
|
|
|
|
/* Global data pointer. */
|
|
|
|
ARC_GP_REGNUM,
|
|
|
|
/* Frame pointer. */
|
|
|
|
ARC_FP_REGNUM,
|
|
|
|
/* Stack pointer. */
|
|
|
|
ARC_SP_REGNUM,
|
|
|
|
/* Return address from interrupt. */
|
|
|
|
ARC_ILINK_REGNUM,
|
|
|
|
ARC_R30_REGNUM,
|
|
|
|
/* Return address from function. */
|
|
|
|
ARC_BLINK_REGNUM,
|
2020-07-09 23:43:13 +08:00
|
|
|
/* Accumulator registers. */
|
|
|
|
ARC_R58_REGNUM = 58,
|
|
|
|
ARC_R59_REGNUM,
|
2016-08-13 01:02:20 +08:00
|
|
|
/* Zero-delay loop counter. */
|
|
|
|
ARC_LP_COUNT_REGNUM = 60,
|
2017-02-10 19:11:46 +08:00
|
|
|
/* Reserved register number. There should never be a register with such
|
|
|
|
number, this name is needed only for a sanity check in
|
|
|
|
arc_cannot_(fetch|store)_register. */
|
|
|
|
ARC_RESERVED_REGNUM,
|
|
|
|
/* Long-immediate value. This is not a physical register - if instruction
|
|
|
|
has register 62 as an operand, then this operand is a literal value
|
|
|
|
stored in the instruction memory right after the instruction itself.
|
|
|
|
This value is required in this enumeration as an architectural number
|
|
|
|
for instruction analysis. */
|
|
|
|
ARC_LIMM_REGNUM,
|
2016-08-13 01:02:20 +08:00
|
|
|
/* Program counter, aligned to 4-bytes, read-only. */
|
|
|
|
ARC_PCL_REGNUM,
|
|
|
|
ARC_LAST_CORE_REGNUM = ARC_PCL_REGNUM,
|
2020-07-09 23:43:13 +08:00
|
|
|
|
2016-08-13 01:02:20 +08:00
|
|
|
/* AUX registers. */
|
|
|
|
/* Actual program counter. */
|
|
|
|
ARC_PC_REGNUM,
|
|
|
|
ARC_FIRST_AUX_REGNUM = ARC_PC_REGNUM,
|
|
|
|
/* Status register. */
|
|
|
|
ARC_STATUS32_REGNUM,
|
2020-07-09 23:43:13 +08:00
|
|
|
/* Zero-delay loop start instruction. */
|
|
|
|
ARC_LP_START_REGNUM,
|
|
|
|
/* Zero-delay loop next-after-last instruction. */
|
|
|
|
ARC_LP_END_REGNUM,
|
|
|
|
/* Branch target address. */
|
|
|
|
ARC_BTA_REGNUM,
|
2017-01-30 23:32:10 +08:00
|
|
|
/* Exception return address. */
|
|
|
|
ARC_ERET_REGNUM,
|
|
|
|
ARC_LAST_AUX_REGNUM = ARC_ERET_REGNUM,
|
2020-07-09 23:43:13 +08:00
|
|
|
ARC_LAST_REGNUM = ARC_LAST_AUX_REGNUM,
|
2016-08-13 01:02:20 +08:00
|
|
|
|
|
|
|
/* Additional ABI constants. */
|
|
|
|
ARC_FIRST_ARG_REGNUM = ARC_R0_REGNUM,
|
|
|
|
ARC_LAST_ARG_REGNUM = ARC_R7_REGNUM,
|
|
|
|
ARC_FIRST_CALLEE_SAVED_REGNUM = ARC_R13_REGNUM,
|
|
|
|
ARC_LAST_CALLEE_SAVED_REGNUM = ARC_R25_REGNUM,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Number of bytes in ARC register. All ARC registers are considered 32-bit.
|
|
|
|
Those registers, which are actually shorter has zero-on-read for extra bits.
|
|
|
|
Longer registers are represented as pairs of 32-bit registers. */
|
|
|
|
#define ARC_REGISTER_SIZE 4
|
|
|
|
|
2016-07-07 01:36:49 +08:00
|
|
|
/* STATUS32 register: hardware loops disabled bit. */
|
|
|
|
#define ARC_STATUS32_L_MASK (1 << 12)
|
|
|
|
/* STATUS32 register: current instruction is a delay slot. */
|
|
|
|
#define ARC_STATUS32_DE_MASK (1 << 6)
|
|
|
|
|
2017-01-30 23:32:10 +08:00
|
|
|
/* Special value for register offset arrays. */
|
|
|
|
#define ARC_OFFSET_NO_REGISTER (-1)
|
|
|
|
|
2022-01-03 02:46:15 +08:00
|
|
|
#define arc_print(fmt, args...) gdb_printf (gdb_stdlog, fmt, ##args)
|
2016-08-13 01:02:20 +08:00
|
|
|
|
2021-01-14 03:32:23 +08:00
|
|
|
extern bool arc_debug;
|
2016-08-13 01:02:20 +08:00
|
|
|
|
2021-01-14 03:32:39 +08:00
|
|
|
/* Print an "arc" debug statement. */
|
|
|
|
|
|
|
|
#define arc_debug_printf(fmt, ...) \
|
|
|
|
debug_prefixed_printf_cond (arc_debug, "arc", fmt, ##__VA_ARGS__)
|
|
|
|
|
2016-10-12 19:36:44 +08:00
|
|
|
/* Target-dependent information. */
|
|
|
|
|
2022-07-25 19:07:11 +08:00
|
|
|
struct arc_gdbarch_tdep : gdbarch_tdep_base
|
2016-10-12 19:36:44 +08:00
|
|
|
{
|
2016-10-12 19:36:44 +08:00
|
|
|
/* Offset to PC value in jump buffer. If this is negative, longjmp
|
|
|
|
support will be disabled. */
|
gdb: fix gdbarch_tdep ODR violation
I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.
To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class. The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.
These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor. In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object). But that's not necessary right now.
It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.
Most changes are fairly straightforward, mostly needing to add some
casts all over the place. There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep. I did my
best to adapt it, but I can't test those changes.
Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b
2021-11-16 00:29:39 +08:00
|
|
|
int jb_pc = 0;
|
2020-07-09 23:44:01 +08:00
|
|
|
|
|
|
|
/* Whether target has hardware (aka zero-delay) loops. */
|
gdb: fix gdbarch_tdep ODR violation
I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.
To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class. The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.
These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor. In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object). But that's not necessary right now.
It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.
Most changes are fairly straightforward, mostly needing to add some
casts all over the place. There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep. I did my
best to adapt it, but I can't test those changes.
Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b
2021-11-16 00:29:39 +08:00
|
|
|
bool has_hw_loops = false;
|
2016-08-23 00:39:46 +08:00
|
|
|
|
|
|
|
/* Detect sigtramp. */
|
gdb: pass frames as `const frame_info_ptr &`
We currently pass frames to function by value, as `frame_info_ptr`.
This is somewhat expensive:
- the size of `frame_info_ptr` is 64 bytes, which is a bit big to pass
by value
- the constructors and destructor link/unlink the object in the global
`frame_info_ptr::frame_list` list. This is an `intrusive_list`, so
it's not so bad: it's just assigning a few points, there's no memory
allocation as if it was `std::list`, but still it's useless to do
that over and over.
As suggested by Tom Tromey, change many function signatures to accept
`const frame_info_ptr &` instead of `frame_info_ptr`.
Some functions reassign their `frame_info_ptr` parameter, like:
void
the_func (frame_info_ptr frame)
{
for (; frame != nullptr; frame = get_prev_frame (frame))
{
...
}
}
I wondered what to do about them, do I leave them as-is or change them
(and need to introduce a separate local variable that can be
re-assigned). I opted for the later for consistency. It might not be
clear why some functions take `const frame_info_ptr &` while others take
`frame_info_ptr`. Also, if a function took a `frame_info_ptr` because
it did re-assign its parameter, I doubt that we would think to change it
to `const frame_info_ptr &` should the implementation change such that
it doesn't need to take `frame_info_ptr` anymore. It seems better to
have a simple rule and apply it everywhere.
Change-Id: I59d10addef687d157f82ccf4d54f5dde9a963fd0
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-20 02:07:47 +08:00
|
|
|
bool (*is_sigtramp) (const frame_info_ptr &) = nullptr;
|
2016-08-23 00:39:46 +08:00
|
|
|
|
|
|
|
/* Get address of sigcontext for sigtramp. */
|
gdb: pass frames as `const frame_info_ptr &`
We currently pass frames to function by value, as `frame_info_ptr`.
This is somewhat expensive:
- the size of `frame_info_ptr` is 64 bytes, which is a bit big to pass
by value
- the constructors and destructor link/unlink the object in the global
`frame_info_ptr::frame_list` list. This is an `intrusive_list`, so
it's not so bad: it's just assigning a few points, there's no memory
allocation as if it was `std::list`, but still it's useless to do
that over and over.
As suggested by Tom Tromey, change many function signatures to accept
`const frame_info_ptr &` instead of `frame_info_ptr`.
Some functions reassign their `frame_info_ptr` parameter, like:
void
the_func (frame_info_ptr frame)
{
for (; frame != nullptr; frame = get_prev_frame (frame))
{
...
}
}
I wondered what to do about them, do I leave them as-is or change them
(and need to introduce a separate local variable that can be
re-assigned). I opted for the later for consistency. It might not be
clear why some functions take `const frame_info_ptr &` while others take
`frame_info_ptr`. Also, if a function took a `frame_info_ptr` because
it did re-assign its parameter, I doubt that we would think to change it
to `const frame_info_ptr &` should the implementation change such that
it doesn't need to take `frame_info_ptr` anymore. It seems better to
have a simple rule and apply it everywhere.
Change-Id: I59d10addef687d157f82ccf4d54f5dde9a963fd0
Approved-By: Andrew Burgess <aburgess@redhat.com>
2024-02-20 02:07:47 +08:00
|
|
|
CORE_ADDR (*sigcontext_addr) (const frame_info_ptr &) = nullptr;
|
2016-08-23 00:39:46 +08:00
|
|
|
|
|
|
|
/* Offset of registers in `struct sigcontext'. */
|
gdb: fix gdbarch_tdep ODR violation
I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.
To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class. The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.
These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor. In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object). But that's not necessary right now.
It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.
Most changes are fairly straightforward, mostly needing to add some
casts all over the place. There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep. I did my
best to adapt it, but I can't test those changes.
Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b
2021-11-16 00:29:39 +08:00
|
|
|
const int *sc_reg_offset = nullptr;
|
2016-08-23 00:39:46 +08:00
|
|
|
|
|
|
|
/* Number of registers in sc_reg_offsets. Most likely a ARC_LAST_REGNUM,
|
|
|
|
but in theory it could be less, so it is kept separate. */
|
gdb: fix gdbarch_tdep ODR violation
I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.
To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class. The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.
These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor. In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object). But that's not necessary right now.
It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.
Most changes are fairly straightforward, mostly needing to add some
casts all over the place. There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep. I did my
best to adapt it, but I can't test those changes.
Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b
2021-11-16 00:29:39 +08:00
|
|
|
int sc_num_regs = 0;
|
2016-10-12 19:36:44 +08:00
|
|
|
};
|
|
|
|
|
2016-08-13 01:02:20 +08:00
|
|
|
/* Utility functions used by other ARC-specific modules. */
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
arc_mach_is_arc600 (struct gdbarch *gdbarch)
|
|
|
|
{
|
|
|
|
return (gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_arc_arc600
|
|
|
|
|| gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_arc_arc601);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
arc_mach_is_arc700 (struct gdbarch *gdbarch)
|
|
|
|
{
|
|
|
|
return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_arc_arc700;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
arc_mach_is_arcv2 (struct gdbarch *gdbarch)
|
|
|
|
{
|
|
|
|
return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_arc_arcv2;
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:12:14 +08:00
|
|
|
/* ARC EM and ARC HS are unique BFD arches, however they share the same machine
|
|
|
|
number as "ARCv2". */
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
arc_arch_is_hs (const struct bfd_arch_info* arch)
|
|
|
|
{
|
|
|
|
return startswith (arch->printable_name, "HS");
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
arc_arch_is_em (const struct bfd_arch_info* arch)
|
|
|
|
{
|
|
|
|
return startswith (arch->printable_name, "EM");
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:12:06 +08:00
|
|
|
/* Function to access ARC disassembler. Underlying opcodes disassembler will
|
|
|
|
print an instruction into stream specified in the INFO, so if it is
|
|
|
|
undesired, then this stream should be set to some invisible stream, but it
|
|
|
|
can't be set to an actual NULL value - that would cause a crash. */
|
|
|
|
int arc_delayed_print_insn (bfd_vma addr, struct disassemble_info *info);
|
|
|
|
|
|
|
|
/* Get branch/jump target address for the INSN. Note that this function
|
|
|
|
returns branch target and doesn't evaluate if this branch is taken or not.
|
|
|
|
For the indirect jumps value depends in register state, hence can change.
|
|
|
|
It is an error to call this function for a non-branch instruction. */
|
|
|
|
|
|
|
|
CORE_ADDR arc_insn_get_branch_target (const struct arc_instruction &insn);
|
|
|
|
|
|
|
|
/* Get address of next instruction after INSN, assuming linear execution (no
|
|
|
|
taken branches). If instruction has a delay slot, then returned value will
|
|
|
|
point at the instruction in delay slot. That is - "address of instruction +
|
|
|
|
instruction length with LIMM". */
|
|
|
|
|
|
|
|
CORE_ADDR arc_insn_get_linear_next_pc (const struct arc_instruction &insn);
|
|
|
|
|
2017-01-30 23:32:10 +08:00
|
|
|
/* Create an arc_arch_features instance from the provided data. */
|
|
|
|
|
|
|
|
arc_arch_features arc_arch_features_create (const bfd *abfd,
|
|
|
|
const unsigned long mach);
|
|
|
|
|
2016-08-13 01:02:20 +08:00
|
|
|
#endif /* ARC_TDEP_H */
|