]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 years ago[Morello] Enable DWARF unwinding with C registers
Luis Machado [Wed, 9 Sep 2020 16:09:47 +0000 (13:09 -0300)] 
[Morello] Enable DWARF unwinding with C registers

Adjust unwinding functions to cope with the presence of C registers.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_prologue_prev_register): Handle the PCC and
CSP registers. Remove the LSB.
(aarch64_dwarf2_prev_register): Handle CSP, PCC and remove the LSB
from CLR.
(aarch64_dwarf2_frame_init_reg): Handle PCC and CSP.
(aarch64_dwarf_reg_to_regnum): Handle C registers.

2 years ago[Morello] Add 'C' augmentation character support
Luis Machado [Thu, 8 Oct 2020 17:06:35 +0000 (14:06 -0300)] 
[Morello] Add 'C' augmentation character support

Handle the Morello 'C' augmentation character. It is not used yet, but it
is acknowledged.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* dwarf2/frame.c (struct dwarf2_cie) <pure_cap>: New field.
(decode_frame_entry_1): Handle the 'C' augmentation character.

2 years ago[General/Morello] Fetch and display register capability tags correctly
Luis Machado [Thu, 8 Oct 2020 09:14:37 +0000 (06:14 -0300)] 
[General/Morello] Fetch and display register capability tags correctly

This patch teaches GDB how to print the capability tag from registers.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_register_has_tag, aarch64_register_tag): New
functions.
(aarch64_gdbarch_init): Register hooks.
* arch-utils.c (default_register_has_tag, default_register_tag): New
functions.
* arch-utils.h (default_register_has_tag, default_register_tag): New
prototypes.
* gdbarch.c: Regenerate.
* gdbarch.h: Likewise.
* gdbarch.sh (register_has_tag, register_tag): New gdbarch hooks.
* regcache.c (readable_regcache::cooked_read_value): Fetch the tag
metadata from registers.
* valprint.c (generic_value_print_capability): Display register tags.
* value.c (struct value) <tagged, tag>: New fields.
(value_contents_copy_raw): Handle tags.
(value_tagged, set_value_tagged, value_tag, set_value_tag): New
functions.
(value_copy): Handle tags.
* value.h (value_tagged, set_value_tagged, value_tag)
(set_value_tag): New prototypes.

2 years ago[Morello] Record mapping symbols and mark C64 function symbols as special
Luis Machado [Thu, 1 Oct 2020 18:59:23 +0000 (15:59 -0300)] 
[Morello] Record mapping symbols and mark C64 function symbols as special

This patch teaches GDB about AArch64 mapping symbols and special minimal
symbols.

FIXME-Morello: This is currently not actively used, but will be used to detect
capability mode functions later.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c: Include elf-bfd.h.
(MSYMBOL_SET_SPECIAL, MSYMBOL_IS_SPECIAL): New constants.
(aarch64_mapping_symbol): New struct.
(aarch64_mapping_symbol_vec): New typedef.
(aarch64_per_bfd): New struct.
(aarch64_bfd_data_key): New static global.
(aarch64_elf_make_msymbol_special, +aarch64_record_special_symbol): New
function.
(aarch64_gdbarch_init): Register hooks.

2 years ago[Morello] Add static ABI detection based on the __cap_relocs section
Luis Machado [Thu, 1 Oct 2020 15:15:39 +0000 (12:15 -0300)] 
[Morello] Add static ABI detection based on the __cap_relocs section

This patch attempts to detect if we are loading a capability-enabled symbol
file or not, so we can set the proper hooks.

FIXME-Morello: This still needs formalization in the ABI document.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_bfd_has_capabilities): New function.
(aarch64_gdbarch_init): Do static ABI check.

2 years ago[Morello] Add register aliases for Morello (cfp, clr, c31, cip0 and cip1)
Luis Machado [Thu, 1 Oct 2020 04:38:35 +0000 (01:38 -0300)] 
[Morello] Add register aliases for Morello (cfp, clr, c31, cip0 and cip1)

This patch adds cfp, clr, c31, cip0 and cip1, aliased to c29, c30, c31, c16 and
c17.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_morello_register_aliases): New static global.
(aarch64_gdbarch_init): Initialize alias registers.

2 years ago[Morello] Disable displaced stepping for Morello
Luis Machado [Mon, 28 Sep 2020 19:32:03 +0000 (16:32 -0300)] 
[Morello] Disable displaced stepping for Morello

Morello can't support displaced stepping at the moment given it has no API
to write capabilities, which is needed when GDB needs to adjust the X and C
registers during a displaced stepping operation.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-linux-tdep.c (aarch64_linux_init_abi): Only set displaced
stepping hooks for non-Morello targets.

2 years ago[Morello] Fix displaced stepping LSB adjustment and add debugging output
Luis Machado [Mon, 28 Sep 2020 14:06:30 +0000 (11:06 -0300)] 
[Morello] Fix displaced stepping LSB adjustment and add debugging output

This patch fixes cases where the LSB of a pure cap function isn't cleared when
we use it for address arithmetic. Also adds debugging output.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_displaced_step_data) <gdbarch>: New field.
(aarch64_displaced_step_b): Add debugging output.
(aarch64_displaced_step_copy_insn): Initialize the gdbarch member.
(aarch64_pointer_to_address, aarch64_address_to_pointer)
(aarch64_integer_to_address): Add debugging output.
* arch/aarch64-insn.c (aarch64_decode_b, aarch64_decode_bcond)
(aarch64_decode_cb, aarch64_decode_tb)
(aarch64_decode_ldr_literal): Refactor and add debugging output.
* infrun.c (displaced_step_prepare_throw): Clear LSB bits.

2 years ago[Morello] Add support for Morello sigreturn/sigcontext frame
Luis Machado [Thu, 24 Sep 2020 18:09:24 +0000 (15:09 -0300)] 
[Morello] Add support for Morello sigreturn/sigcontext frame

This patch teaches GDB how to interpret the Morello sigcontext
structure in a sigreturn frame and allows GDB to read back the
correct values of the registers.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-linux-tdep.c: Include arch/aarch64-insn.h.
(AARCH64_MORELLO_MAGIC, AARCH64_MORELLO_SIGCONTEXT_SIZE)
(AARCH64_MORELLO_SIGCONTEXT_C0_OFFSET): New constants.
(aarch64_linux_sigframe_init): Update to handle Morello
sigreturn/sigcontext frames.

2 years ago[Morello] Mask the LSB from cap mode addresses
Luis Machado [Tue, 15 Sep 2020 17:16:30 +0000 (14:16 -0300)] 
[Morello] Mask the LSB from cap mode addresses

This patch removes the LSB from capability mode addresses. This is a bit set
to indicate that a given function deals with capabilities.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_addr_bits_remove): New function.
(aarch64_gdbarch_init): Register hook.

2 years ago[General] Accept capabilities as a type of pointer
Luis Machado [Thu, 10 Sep 2020 20:33:06 +0000 (17:33 -0300)] 
[General] Accept capabilities as a type of pointer

This makes GDB happy when trying to convert to/from capabilities from
long types.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* findvar.c (extract_typed_address): Handle capabilities.
(store_typed_address): Likewise.
* value.c (unpack_long): Likewise.
(pack_long): Likewise.

2 years ago[General] Add capability casts to scalar types
Luis Machado [Wed, 9 Sep 2020 21:30:10 +0000 (18:30 -0300)] 
[General] Add capability casts to scalar types

Add support for casting capabilities to scalar types. We basically truncate
the capability to the size of the target type.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* valops.c (value_cast): Cast from capability to scalar types.

2 years ago[Morello] Add support for capability/pointer/integer conversions
Luis Machado [Wed, 9 Sep 2020 20:20:15 +0000 (17:20 -0300)] 
[Morello] Add support for capability/pointer/integer conversions

Enable hooks to allow custom conversions of capability/pointer/integer values.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c: Include inferior.h.
(aarch64_pointer_to_address, aarch64_address_to_pointer)
(aarch64_integer_to_address): New functions.
(aarch64_gdbarch_init): Register hooks.

2 years ago[Morello] Add capability fault codes and report fault information
Luis Machado [Thu, 3 Sep 2020 17:20:46 +0000 (14:20 -0300)] 
[Morello] Add capability fault codes and report fault information

Report capability faults with additional information, like tag, bounds,
sealed permissions and access faults.

gdb/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-linux-tdep.c: Include value.h.
(aarch64_linux_report_signal_info): New function.
(aarch64_linux_init_abi): Register hook for reporting signal
information.
* arch/aarch64-cap-linux.h (SEGV_CAPTAGERR, SEGV_CAPSEALEDERR)
(SEGV_CAPBOUNDSERR, SEGV_CAPPERMERR, SEGV_CAPSTORETAGERR): New
constants.

2 years ago[Morello] Add set/show ABI command for AArch64
Luis Machado [Fri, 17 Jul 2020 20:40:44 +0000 (17:40 -0300)] 
[Morello] Add set/show ABI command for AArch64

Add a new command for developers to set and show the AArch64 ABI GDB is
using at the moment.

We define 2 ABI's: AAPCS64 and AAPCS64-cap.

Each of these ABI's should impact the architecture setup in different ways.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (set_aarch64_cmdlist, show_aarch64_cmdlist,
aarch64_abi_strings, aarch64_current_abi_global)
(aarch64_current_abi_string): New static globals.
(aarch64_update_current_architecture, aarch64_set_abi)
(aarch64_show_abi): New functions.
(aarch64_gdbarch_init): Handle ABI identification.
(_initialize_aarch64_tdep): Add new ABI commands.
* aarch64-tdep.h (aarch64_abi_kind): New enum.
(struct gdbarch_tdep) <abi>: New field.

2 years ago[General] More capability type handling (merge with others)
Luis Machado [Thu, 2 Jul 2020 19:31:11 +0000 (16:31 -0300)] 
[General] More capability type handling (merge with others)

Teach more parts of GDB how to handle capabilities properly, add a function
to print capabilities in their natural format and initialize capability types
properly.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* c-typeprint.c (c_type_print_varspec_prefix)
(c_type_print_varspec_suffix): Handle capability type.
* dwarf2/read.c (read_base_type): Call init_capability_type for
capabilities.
* gdbtypes.c (init_capability_type): New function.
(type_align): Handle capability type.
(recursive_dump_type): Likewise.
(arch_capability_type): New function.
(gdbtypes_post_init): Call arch_capability_type for capability
types.
* gdbtypes.h (init_capability_type, arch_capability_type):  New
prototypes.
* valprint.c: Include gdbsupport/capability.h.
(generic_value_print_capability): New function.
(generic_value_print): Handle capability types.

2 years ago[Morello] Capability address_class support and testcase
Luis Machado [Wed, 6 May 2020 16:41:48 +0000 (13:41 -0300)] 
[Morello] Capability address_class support and testcase

Handle the new address class type for Morello, which modifies regular
pointers and makes them 16 bytes in size.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_address_class_type_flags)
(aarch64_address_class_type_flags_to_name)
(aarch64_address_class_name_to_type_flags): New functions.
(aarch64_gdbarch_init): Register address class hooks.

gdb/testsuite/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdb.dwarf2/dw2-capability.exp: New test.

2 years ago[Morello] Add capability register set support
Luis Machado [Thu, 5 Mar 2020 17:02:22 +0000 (14:02 -0300)] 
[Morello] Add capability register set support

This patch adds capability register set support to both GDB and GDBserver,
allowing the use of ptrace.

gdb/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-linux-nat.c: Include arch/aarch64-cap-linux.h.
(fetch_cregs_from_thread)
(store_cregs_to_thread): New functions.
(aarch64_linux_nat_target::fetch_registers): Modify to check for
capability registers.
* aarch64-linux-tdep.c: Include arch/aarch64-cap-linux.h.
* aarch64-tdep.c (aarch64_cannot_store_register): Check for capability
registers.
(aarch64_gdbarch_init): Also save the last capability register number.
* aarch64-tdep.h (struct gdbarch_tdep) <cap_reg_last>: New field.
* arch/aarch64-cap-linux.h (AARCH64_LINUX_CREGS_SIZE,
AARCH64_MORELLO_REGS_NUM, AARCH64_C_REGS_NUM): New constants.
* arch/aarch64.c: Remove FIXME comment.
* nat/aarch64-linux.h (user_morello_state): New struct.

gdbserver/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* linux-aarch64-low.c: arch/aarch64-cap-linux.h.
(aarch64_store_cregset): New function.
(aarch64_regsets): Add capability register set.
(aarch64_sve_regsets): Likewise.

include/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* elf/common.h (NT_ARM_MORELLO): Define.

2 years ago[Morello] Generate target descriptions based on runtime capability feature checks
Luis Machado [Thu, 26 Mar 2020 14:58:01 +0000 (11:58 -0300)] 
[Morello] Generate target descriptions based on runtime capability feature checks

This patch adds code to do runtime checks for Morello, so GDB can pick the
correct target description and register set.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-linux-nat.c (aarch64_linux_nat_target::read_description):
Check for HWCAP2_MORELLO.
* aarch64-linux-tdep.c (aarch64_linux_core_read_description): Likewise.
* aarch64-tdep.c (tdesc_aarch64_list): Add one more dimension.
(aarch64_read_description): New parameter capability_p, use it to
generate the proper target description.
(aarch64_gdbarch_init): Update invocation of aarch64_read_description.
* aarch64-tdep.h (aarch64_read_description): New parameter capability_p.
* arch/aarch64.c (aarch64_create_target_description): New parameter
capability_p. Use it.
* arch/aarch64.h (aarch64_create_target_description): New parameter
capability_p.

gdbserver/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* linux-aarch64-ipa.cc (get_ipa_tdesc): Update.
* linux-aarch64-low.cc (aarch64_target::low_arch_setup): Check for
HWCAP2_MORELLO and use it.
* linux-aarch64-tdesc.cc (tdesc_aarch64_list): Add one more dimension.
(aarch64_linux_read_description): New parameter capability_p. Use it.
* linux-aarch64-tdesc.h (aarch64_linux_read_description): New parameter
capability_p.

2 years ago[Morello] Add Morello target description XML and registers
Luis Machado [Thu, 12 Mar 2020 19:37:28 +0000 (16:37 -0300)] 
[Morello] Add Morello target description XML and registers

This patch adds a Morello register description XML and code to detect and use
said registers.

gdb/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_c_register_names): New static array.
(aarch64_gdbarch_init): Check for capability
XML feature and add registers to the target.
* aarch64-tdep.h (struct gdbarch_tdep) <cap_reg_base>: New field.
<has_capability>: New method.
* arch/aarch64.c: Include features/aarch64-capability.c.
(aarch64_create_target_description): Invoke
create_feature_aarch64_capability.
* features/Makefile (FEATURE_XMLFILES): Add aarch64-capability.xml
* features/aarch64-capability.xml: New file.
* features/aarch64-capability.c: Generate.

2 years ago[Morello] Add feature check constant for capabilities
Luis Machado [Thu, 5 Mar 2020 11:57:44 +0000 (08:57 -0300)] 
[Morello] Add feature check constant for capabilities

This patch adds a Morello feature check constant HWCAP2_MORELLO,
as defined in the Linux Kernel.

Dependencies: glibc and Kernel.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* Makefile.in (HFILES_NO_SRCDIR): Add arch/aarch64-cap-linux.h.
* arch/aarch64-cap-linux.h: New header file.

2 years ago[Morello] Add new DWARF defines for capabilities
Luis Machado [Thu, 5 Mar 2020 20:13:25 +0000 (17:13 -0300)] 
[Morello] Add new DWARF defines for capabilities

This patch adds some new definitions required for Morello.

* DWARF base types: DW_ATE_CHERI_signed_intcap and DW_ATE_CHERI_unsigned_intcap.

* DWARF address class: DW_ADDR_capability

* DWARF register numbering

It also adds support for handling DW_ATE_CHERI_signed_intcap and
DW_ATE_CHERI_unsigned_intcap on binutils and GDB.

binutils/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* dwarf.c (get_type_signedness): Handles capabilities.
(read_and_display_attr_value): Likewise.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.h (AARCH64_DWARF_C0, AARCH64_DWARF_CSP)
(AARCH64_DWARF_PCC, AARCH64_DWARF_DDC)
(AARCH64_DWARF_RESERVED_1, AARCH64_DWARF_RESERVED_2)
(C_REGISTER_SIZE): New defines.
* dwarf2/read.c (read_base_type): Handle capabilities.

include/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* dwarf2.def (DW_ATE_CHERI_signed_intcap)
(DW_ATE_CHERI_unsigned_intcap): New defines.
* dwarf2.h (DW_ADDR_capability): New define.

2 years ago[General] Add target description support for capability types
Luis Machado [Thu, 26 Mar 2020 14:01:39 +0000 (11:01 -0300)] 
[General] Add target description support for capability types

Add new capability types so target descriptions can use them. Then it gets
translated to the underlying type GDB uses.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* target-descriptions.c (make_gdb_type): Handle new capability
types.

gdbsupport/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* tdesc.cc (tdesc_predefined_types): Add new capability types.
* tdesc.h (tdesc_type_kind) <TDESC_TYPE_CODE_CAPABILITY>
<TDESC_TYPE_DATA_CAPABILITY, TDESC_TYPE_INTCAP>
<TDESC_TYPE_UINTCAP>: New fields.

2 years ago[General] gdbarch update to include code_capability_bit, data_capability_bit etc
Luis Machado [Fri, 27 Mar 2020 14:33:55 +0000 (11:33 -0300)] 
[General] gdbarch update to include code_capability_bit, data_capability_bit etc

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdb/gdbarch.c: Regenerate.
* gdb/gdbarch.h: Regenerate.
* gdb/gdbarch.sh (code_capability_bit)
(data_capability_bit, capability_bit, dwarf2_capability_size): New
methods.
* gdb/gdbtypes.c (gdbtypes_post_init): Initialize data address
capability to a pointer to intcap_t.

2 years ago[General] Add support for capability types and modifier in GDB
Luis Machado [Wed, 6 May 2020 21:25:15 +0000 (18:25 -0300)] 
[General] Add support for capability types and modifier in GDB

This commit adds support for the __intcap_t and __uintcap_t types
in GDB. It also adds support for the __capability pointer modifier.

FIXME-Morello: The __intcap_t and __uintcap_t builtin types and the
capability data/function pointers still need to be properly defined.

A new testcase exercises the capability types and sizes.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdb/c-exp.y (CAPABILITY, INTCAP_KEYWORD, UINTCAP_KEYWORD): New
tokens.
Handle new tokens.
* gdb/c-lang.c (c_primitive_types) <c_primitive_type_intcap_t>
<c_primitive_type_uintcap_t>: New fields.
(c_language_arch_info): Handle intcap/uintcap.
(cplus_primitive_types) <cplus_primitive_type_intcap_t>
<cplus_primitive_type_uintcap_t>: New fields.
(cplus_language::language_arch_info): Handle intcap/uintcap.
* gdb/c-typeprint.c (c_type_print_modifier): Handle the __capability
modifier.
* gdb/gdbtypes.c (make_capability_type): New function.
(make_unqualified_type): Handle capabilities.
(recursive_dump_type): Likewise.
(gdbtypes_post_init): Initialize capability builtins.
* gdb/gdbtypes.h (TYPE_INSTANCE_FLAG_CAPABILITY): New flag.
(TYPE_CAPABILITY): New define.
(struct type) <m_instance_flags>: New field.
(struct builtin_type) <builtin_intcap_t, builtin_uintcap_t>: New
fields.
(make_capability_type): New prototype.
* gdb/type-stack.c (type_stack::insert)
(type_stack::follow_type_instance_flags)
(type_stack::follow_types): Handle capability modifier.
* gdb/type-stack.h (enum type_pieces) <tp_capability>: New field.

gdb/testsuite/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdb.arch/aarch64-morello-captypes.c: New file.
* gdb.arch/aarch64-morello-captypes.exp: New file.

2 years ago[General] Add new builtin types to support capabilities
Luis Machado [Thu, 12 Mar 2020 16:59:45 +0000 (13:59 -0300)] 
[General] Add new builtin types to support capabilities

This patch adds some required builtin types so GDB can properly support
capabilities.

We need a data capability and a code capability. Those are not expected to
yield valid conversions between themselves.

gdb/ChangeLog

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdbtypes.h (enum type_code) <TYPE_CODE_CAPABILITY>: New enum.
(struct builtin_type) <builtin_data_addr_capability>
<builtin_code_addr_capability>: New fields.

2 years ago[Morello] Initial capability data structure support + Unit testing
Luis Machado [Wed, 1 Apr 2020 19:38:42 +0000 (16:38 -0300)] 
[Morello] Initial capability data structure support + Unit testing

This patch adds capability data structures and related functions. These are
Morello-specific, so the encodings only make sense for this particular
Architecture. The capability is restricted to 128 bits, but could be expanded
to hold other variations while keeping the capability class structure.

Unit tests were also included to validate the decoding/encoding functions. The
output is matched against auto-generated values based on a reference
implementation.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdb/aarch64-tdep.c: Include gdbsupport/capability.h.
(aarch64_capability_decoding_test): New function.
(_initialize_aarch64_tdep): Register capability tests.

gdbsupport/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* gdbsupport/Makefile.am: Regenerate.
* gdbsupport/Makefile.in: Adjust to include gdbsupport/capability.*.
* gdbsupport/capability.cc: New file.
* gdbsupport/capability.h: New file.

2 years ago[Morello] TLS Descriptor support
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:11 +0000 (09:18 +0530)] 
[Morello] TLS Descriptor support

This change adds basic support for TLS descriptors.  Relaxation of
TLSDESC_GD to other relocations is limited to TLS_LE, other cases end
up retaining TLSDESC_GD.

There is one key difference from A64 for TLSDESC_GD -> LE transition
and that is in the case of static non-pie binaries.  Morello
TLSDESC_GD relocations are relaxed to LE for static non-pie binaries
since it ought to be safe to do so and it aligns with llvm behaviour.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (IS_AARCH64_TLSDESC_RELOC): Add Morello
relocations.
(elfNN_aarch64_tlsdesc_small_plt_c64_entry): New Morello
tlsdesc PLT entry.
(elfNN_aarch64_howto_table): Add TLSDESC_ADR_PAGE20,
TLSDESC_LD128_LO12, TLSDESC_CALL, TLSDESC relocations for
Morello.
(aarch64_tls_transition_without_check): Add INFO and
MORELLO_RELOC arguments.  Add morello TLSDESC relocations.
(aarch64_reloc_got_type, elfNN_aarch64_final_link_relocate,
elfNN_aarch64_tls_relax, elfNN_aarch64_check_relocs,
aarch64_can_relax_tls): Add morello TLSDESC relocations.
(aarch64_tls_transition): Add transitions for morello TLSDESC
relocations.
(elfNN_aarch64_tls_relax): Add relaxations for morello
TLSDESC.
(elfNN_aarch64_relocate_section): Emit dynamic relocation for
Morello static relocations.
(elfNN_aarch64_allocate_dynrelocs): Allocate dynamic
relocation space for Morello TLSDESC.
(elfNN_aarch64_finish_dynamic_sections): Emit Morello tlsdesc
PLT entry.
* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend,
_bfd_aarch64_elf_resolve_relocation): Add Morello relocations.
* reloc.c: Add Morello relocations.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (s_tlsdesccall): Emit Morello
TLSDESC_CALL in C64 code.
(reloc_table): Add Morello relocation.
(md_apply_fix): Emit Morello TLSDESC_LD128_LO12 in C64 code.
(aarch64_force_relocation): Add Morello TLSDESC relocations.
* testsuite/gas/aarch64/morello-tlsdesc-c64.d: New file.
* testsuite/gas/aarch64/morello-tlsdesc.d: New file.
* testsuite/gas/aarch64/morello-tlsdesc.s: New file.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h: New Morello TLSDESC relocations.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/morello-tlsdesc.s: New file.
* testsuite/ld-aarch64/morello-tlsdesc.d: New test.
* testsuite/ld-aarch64/morello-tlsdesc-static.d: New test.
* testsuite/ld-aarch64/morello-tlsdesc-staticpie.d: New test.
* testsuite/ld-aarch64/aarch64-elf.exp: Add them.

2 years ago[Morello] Pad section alignment to account for capability range format
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:11 +0000 (09:18 +0530)] 
[Morello] Pad section alignment to account for capability range format

The capability format has limitations on the alignment and length of
capability bounds and are subject to rounding.  Add alignment and
padding at the boundaries of such long (typically >16M) sections so
that any capabilities referencing these sections do not end up
overlapping into neighbouring sections.

There are two cases where this is in use.  The first and most
important due to the current implementation is the range for PCC,
which needs to span all executable sections and all PLT and GOT
sections.  The other case is for linker and ldscript defined symbols
that may be used in dynamic relocations.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elf_aarch64_link_hash_table): New member.
(section_start_symbol, c64_valid_cap_range, exponent): Move
up.
(sec_change_queue): New structure.
(queue_section_padding, record_section_change,
elfNN_c64_resize_sections): New functions.
(bfd_elfNN_aarch64_init_maps): Add info argument.  Adjust
callers.
* elfxx-aarch64.h (bfd_elf64_aarch64_init_maps,
bfd_elf32_aarch64_init_maps): Add info argument.
(elf64_c64_resize_sections, elf32_c64_resize_sections): New
function declarations.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* emultempl/aarch64elf.em (elf64_c64_pad_section): New
function.
(gld${EMULATION_NAME}_after_allocation): Resize C64 sections.
* ldlang.c (lang_add_newdot): New function.
* ldlang.h (lang_add_newdot): New function declaration.
* testsuite/ld-aarch64/aarch64-elf.exp: Add new test.
* testsuite/ld-aarch64/morello-sec-round.d: New file.
* testsuite/ld-aarch64/morello-sec-round.ld: New file.
* testsuite/ld-aarch64/morello-sec-round.s: New file.

2 years ago[Morello] Capability support for exception headers
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:11 +0000 (09:18 +0530)] 
[Morello] Capability support for exception headers

- Identify and mark C64 frames
- Identify C64 registers including DDC.
- Identify 'purecap' argument to .cfi_startproc for C64 frames
- Emit 'C' in augmentation string for C64 frames
- Recognise the 'C' in the CIE augmentation string when parsing
  exception headers

Difference from LLVM: The llvm assembler only uses purecap to add C to
the augmentation string.  The GNU assembler on the other hand uses
-march and validates that purecap is passed to .cfi_startproc only for
-morello+c64.  This means that for code compiled for A64, if llvm sees
`.cfi_startproc purecap`, it sets 'C' whereas the GNU assembler flags
an error.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf-bfd.h (elf_backend_data): New callback
elf_backend_eh_frame_augmentation_char.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Use it.
* elfnn-aarch64.c (elf64_aarch64_eh_frame_augmentation_char):
New function.
(elf_backend_eh_frame_augmentation_char): New macro.

* elfxx-target.h [!elf_backend_eh_frame_augmentation_char]:
Set elf_backend_eh_frame_augmentation_char to NULL.
(elfNN_bed): Initialise
elf_backend_eh_frame_augmentation_char.

binutils/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* dwarf.c (dwarf_regnames_aarch64): Add capability registers.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (REG_DW_CSP, REG_DW_CLR): New macros.
(s_aarch64_cfi_b_key_frame): Adjust for new entry_extras
struct.
(tc_aarch64_frame_initial_instructions): Adjust for C64.
(tc_aarch64_fde_entry_init_extra,
tc_aarch64_cfi_startproc_exp): New functions.
(tc_aarch64_regname_to_dw2regnum): Support capability
registers.
* config/tc-aarch64.h (fde_entry): Forward declaration.
(eh_entry_extras): New struct.
(tc_fde_entry_extras, tc_cie_entry_extras): Use it.
(tc_fde_entry_init_extra): Set to
tc_aarch64_fde_entry_init_extra.
(tc_output_cie_extra): Emit 'C' for C64.
(tc_cie_fde_equivalent_extra): Adjust for C64.
(tc_cie_entry_init_extra): Likewise.
(tc_cfi_startproc_exp): New macro.
(tc_aarch64_cfi_startproc_exp,
tc_aarch64_fde_entry_init_extra): New function declarations.
* dw2gencfi.c (tc_cfi_startproc_exp): New macro.
(dot_cfi_startproc): Use it.
* testsuite/gas/aarch64/morello-eh.d: New test.
* testsuite/gas/aarch64/morello-eh.s: New test.

2 years ago[Morello] Add interworking and range extension veneers
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:10 +0000 (09:18 +0530)] 
[Morello] Add interworking and range extension veneers

Add veneers to branch from A64 to C64 and vice versa and for range
extension from C64 to C64.  The veneers are named as
__foo_a64c64_veneer, __foo_c64a64_veneer or simply __foo_veneer
(where foo is the target function) based on whether the branch is from
A64 to C64, the other way around or for extended range.

A64 to C64 needs an additional BX since the ADRP in the veneer does
not generate a valid capability without the switch using BX.  As a
result, the addendum LSB is no longer important for A64 -> C64 switch,
but we keep it anyway so that we can use the same veneer for long
range C64 to C64 branches.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (STUB_ENTRY_NAME): Add format specifier for
veneer type.
(C64_MAX_ADRP_IMM, C64_MIN_ADRP_IMM): New macros.
(aarch64_branch_reloc_p, c64_valid_for_adrp_p,
aarch64_interwork_stub): New functions.
(aarch64_c64_branch_stub, c64_aarch64_branch_stub): New stubs.
(elf_aarch64_stub_type): New members.
(aarch64_type_of_stub): Support C64 stubs.
(aarch64_lookup_stub_type_suffix): New function.
(elfNN_aarch64_stub_name): Use it.
(elfNN_aarch64_get_stub_entry): Add stub_type argument.
Adjust callers.  Support C64 stubs.
(aarch64_build_one_stub): Likewise.
(aarch64_size_one_stub): Likewise.
(elfNN_aarch64_size_stubs): Likewise.
(elfNN_aarch64_build_stubs): Save and return error if stub
building failed.
(elfNN_aarch64_final_link_relocate): Emit stubs based on
whether source and target of a branch are different.
(aarch64_map_one_stub): Emit mapping symbol for C64 stubs.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/aarch64-elf.exp: Add test.
* testsuite/ld-aarch64/morello-stubs-static.d: New file.
* testsuite/ld-aarch64/morello-stubs.d: New file.
* testsuite/ld-aarch64/morello-stubs.ld: New file.
* testsuite/ld-aarch64/morello-stubs.s: New file.

The jump targets have limited range (i.e. limited by ADRP range) and
hence cannot be used for very long jumps.  The linker will throw an
error for such out of range jumps.

2 years ago[Morello] Implement branch relocations
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:10 +0000 (09:18 +0530)] 
[Morello] Implement branch relocations

This implements the following static relocations:

- R_MORELLO_CALL26, R_MORELLO_JUMP26
- R_MORELLO_TSTBR14, R_MORELLO_CONDBR19

and the following dynamic relocations:

- R_MORELLO_JUMP_SLOT and R_MORELLO_IRELATIVE

Some notes on the implementation:

- The linker selects morello PLT stubs when it finds at least one
  static relocation that needs a capability GOT slot.

- It is assumed that C64 is not compatible with BTI/PAC, so the latter
  gets overridden.  To allow this, the call to setup_plt_values is
  delayed to take into account htab->c64_plt.

- If the caller is A64, the assembler emits R_AARCH64_JUMP_SLOT,
  otherwise it emits R_MORELLO_JUMP_SLOT.

- The PLT stub is A64-compatible, in that it should do the right thing
  when the execution state is A64.

- If the slots are 16-bytes (this happens when there is at least one
  Morello relocation on the GOT), the references in .plt.got and in
  .got are always capabilities; the dynamic linker will take care of
  that.  For PLT, the default trampoline is a capability.  This is
  true for A64 as well as C64.

- At present it is assumed that there is no interworking between A64
  and C64 functions.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_c64_small_plt0_entry,
elfNN_c64_small_plt_entry): New variables.
(elfNN_aarch64_howto_table): Add relocations.
(setup_plt_values): Choose C64 PLT when appropriate.
(bfd_elfNN_aarch64_set_options): Defer setup_plt_values
call...
(elfNN_aarch64_link_setup_gnu_properties) ... from here as
well...
(elfNN_aarch64_size_dynamic_sections): ... to here.
(elfNN_aarch64_final_link_relocate,
elfNN_aarch64_check_relocs, elfNN_aarch64_reloc_type_class):
Support new relocations.
(map_symbol_type): New member AARCH64_MAP_C64.
(elfNN_aarch64_output_arch_local_syms): Use it.
(aarch64_update_c64_plt_entry): New function.
(elfNN_aarch64_create_small_pltn_entry): Use it.
(elfNN_aarch64_init_small_plt0_entry): Emit C64 PLT when
appropriate.
* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend,
_bfd_aarch64_elf_resolve_relocation): Add new relocations.
* libbfd.h (bfd_reloc_code_real_names): Likewise.
* reloc.c: New relocations BFD_RELOC_MORELLO_TSTBR14,
BFD_RELOC_MORELLO_BRANCH19, BFD_RELOC_MORELLO_JUMP26,
BFD_RELOC_MORELLO_CALL26, BFD_RELOC_MORELLO_JUMP_SLOT and
BFD_RELOC_MORELLO_IRELATIVE.
* bfd-in2.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Choose C64 branch
relocations when appropriate.
(md_apply_fix, aarch64_force_relocation,
aarch64_fix_adjustable): Support C64 branch relocations.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h: New relocations R_MORELLO_TSTBR14,
R_MORELLO_CONDBR19, R_MORELLO_JUMP26, R_MORELLO_CALL26,
R_MORELLO_JUMP_SLOT and R_MORELLO_IRELATIVE.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/aarch64-elf.exp: Add new tests.
* testsuite/ld-aarch64/c64-ifunc-2-local.d: New file.
* testsuite/ld-aarch64/c64-ifunc-2.d: New file.
* testsuite/ld-aarch64/c64-ifunc-3a.d: New file.
* testsuite/ld-aarch64/c64-ifunc-3b.d: New file.
* testsuite/ld-aarch64/c64-ifunc-4.d: New file.
* testsuite/ld-aarch64/c64-ifunc-4a.d: New file.
* testsuite/ld-aarch64/ifunc-2-local.s: Support capabilities.
* testsuite/ld-aarch64/ifunc-2.s: Likewise.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-dis.c (get_sym_code_type): Fix C64 PLT disassembly.

2 years ago[Morello] Linker tests for capability data relocations
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:10 +0000 (09:18 +0530)] 
[Morello] Linker tests for capability data relocations

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d: New test.
* testsuite/ld-aarch64/emit-relocs-morello-2.d: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello-2.s: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello-3.d: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello-3.s: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello-a64c.d: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello.d: Likewise.
* testsuite/ld-aarch64/emit-relocs-morello.s: Likewise.
* testsuite/ld-aarch64/aarch64-elf.exp: Add new tests.

2 years ago[Morello] Add symbol markers for reloc section for static binaries
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:10 +0000 (09:18 +0530)] 
[Morello] Add symbol markers for reloc section for static binaries

Add symbols __cap_dynrelocs_start and __cap_dynrelocs_end to mark the
start and end of the .rela.dyn section when building a static
executable without PIE.  This allows the runtime startup to traverse
the section and initialise capabilities without having to read the ELF
headers.

All relocations must be of type R_C64_RELATIVE and have the following
properties:

- Frag contains the base of the capability to be initialised
- Frag + 8 has the size and permissions encoded into 56 and 8 bits
  respectively
- Addend is the offset from the capability base

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Emit
relative C64 relocations for static binaries early.
(aarch64_elf_init_got_section): Add capability relocations to
SRELCAPS for non-PIE static binaries.
(elfNN_aarch64_allocate_dynrelocs): Likewise.
(elfNN_aarch64_always_size_sections): Emit
__cap_dynrelocs_start and __cap_dynrelocs_end.

2 years ago[Morello] GOT Relocations
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:10 +0000 (09:18 +0530)] 
[Morello] GOT Relocations

- Implement R_MORELLO_LD128_GOT_LO12_NC and emit the correct
  relocation based on the target register size.
- Add R_MORELLO_GLOB_DAT and R_MORELLO_RELATIVE dynamic relocations for GOT
  entries
- Add support for capabilities in GOT

GOT slots for capabilities need to be 16 byte to accommodate
capabilities.  For this purpose, we delay initialising size and
alignment of the GOT sections until we have walked all relocs in
check_relocs.  If we encounter capability relocations during the walk,
set the GOT entry size and alignment to account for capabilities or
leave it pointer sized otherwise.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (GOT_ENTRY_SIZE): Adjust for C64
relocations.  Adjust callers.
(GOT_RESERVED_HEADER_SLOTS, GOT_CAP): New macros.
(elfNN_aarch64_howto_table): Add R_MORELLO_LD128_GOT_LO12_NC
and R_MORELLO_GLOB_DAT.
(elf_aarch64_link_hash_table): New member c64_rel.
(bfd_elfNN_aarch64_set_options): Initialise it.
(cap_meta, c64_get_capsize): New functions.
(aarch64_reloc_got_type): Use GOT_CAP.
(elfNN_aarch64_final_link_relocate): Add
R_MORELLO_LD128_GOT_LO12_NC and R_MORELLO_GLOB_DAT.
(aarch64_elf_create_got_section): Move section initialisation
into a...
(aarch64_elf_init_got_section): ... New function.
(elfNN_aarch64_size_dynamic_sections): Call it.
(elfNN_aarch64_check_relocs): Add R_MORELLO_LD128_GOT_LO12_NC
and R_MORELLO_GLOB_DAT.
(elfNN_aarch64_finish_dynamic_symbol): Emit C64 relocations
when appropriate.
(elfNN_aarch64_got_elt_size): New function.
(elfNN_aarch64_got_header_size): Return GOT entry size based
on c64_rel.
(elf_backend_got_elt_size): New macro.
* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend,
_bfd_aarch64_elf_resolve_relocation): Add
BFD_RELOC_MORELLO_LD128_GOT_LO12_NC.
* libbfd.h (bfd_reloc_code_real_names): Add
BFD_RELOC_MORELLO_GLOB_DAT and
BFD_RELOC_MORELLO_LD128_GOT_LO12_NC.
* reloc.c: Likewise.
* bfd-in2.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Emit C64 relocations
for got_lo12.  Move old relocation checks from...
(md_apply_fix): ... here.
* testsuite/gas/aarch64/morello-ldst-reloc.d: Add tests.
* testsuite/gas/aarch64/morello-ldst-reloc.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h: New relocations R_MORELLO_LD128_GOT_LO12_NC
and R_MORELLO_GLOB_DAT.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/emit-relocs-morello-1.d: New file.
* testsuite/ld-aarch64/emit-relocs-morello-1.s: New test file.
* testsuite/ld-aarch64/aarch64-elf.exp: Add it to test runner.

2 years ago[Morello] Expand GOT entry sizes for C64
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:09 +0000 (09:18 +0530)] 
[Morello] Expand GOT entry sizes for C64

Expand GOT slots based on whether we are emitting C64 relocations.
This patch only has infrastructure changes, i.e. it only makes
got_header_size a function and adjusts across architectures.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>
    Tamar Christina  <tamar.christina@arm.com>

* elf-bfd.h (elf_backend_data): Make got_header_size a
function.  Add callbacks to all targets that use it.
* elflink.c (_bfd_elf_create_got_section,
bfd_elf_gc_common_finalize_got_offsets,
_bfd_elf_common_section): Adjust got_header_size usage.

2 years ago[Morello] Allow lo12 relocations for alternate base ld/st
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:09 +0000 (09:18 +0530)] 
[Morello] Allow lo12 relocations for alternate base ld/st

This brings feature parity between the regular, Morello and alternate
base load/store instructions.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfxx-aarch64.c (reencode_ldst_pos_imm): Support loads and
stores with alternate base.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (ldst_lo12_determine_real_reloc_type):
Support alternate base loads and stores.
(parse_operands): Support relocations for alternate base
address operands.
* testsuite/gas/aarch64/morello-ldst-reloc.d: New file.
* testsuite/gas/aarch64/morello-ldst-reloc.s: New file.

2 years ago[Morello] Capability data relocations
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:09 +0000 (09:18 +0530)] 
[Morello] Capability data relocations

Introduce three new relocations disguised as two relocations to
support capabilities.

R_MORELLO_CAPINIT is emitted as a static relocation by the assembler
and as a dynamic relocation by the linker; it's a one on one free!

The R_MORELLO_CAPINIT static relocation is emitted by the assembler to
provide capability information to the static linker.  The static
linker may do one of two things:

- For local symbols that can be resolved at link time, the static
  linker sets up frag and emits a R_MORELLO_RELATIVE dynamic
  relocation that the dynamic linker can resolve in a manner similar
  to R_AARCH64_RELATIVE.  The dynamic linker will have all of the
  information it needs (i.e. permissions, size and relative address)
  to set up the capability without needing to peek into the symbol
  table.

- For dynamic symbols, the static linker emits a R_MORELLO_CAPINIT
  with the reference of the dynamic symbol it refers to.  The dynamic
  linker is then responsible for resolving the symbol at runtime and
  setting up the capability based on the properties of the symbol it
  is able to deduce.

Linker and Linker script defined symbols
----------------------------------------

For symbols defined by the linker or in linker scripts, capability
size and permissions are based on the section the symbol belongs to.

For linker defined symbols (i.e. _DYNAMIC or _GLOBAL_OFFSET_TABLE_)
this is straightforward since the linker puts them in the correct
section and at the start.

For symbols defined in the linker script, if they are anywhere but the
end of the output script definition, their range becomes the point at
which they are defined, up to the end of the output section.  For
symbols defined at the end of the output section, the symbols are
defined with a zero size unless their name is of the form __start_.*
or __.*_start, indicating a start of the section that follows it.  In
this case, the symbols are given the range and permission of the
output section following it.

Ideally, the last case (i.e. the heuristic looking for the name)
should be strictly for compatibility and should eventually be fixed in
the linker script to put the symbol into the output section it intends
to track.  It may be a useful enhancement to add a warning to that
effect.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_aarch64_howto_table,
elfNN_aarch64_final_link_relocate, elfNN_aarch64_check_relocs,
elfNN_aarch64_relocate_section): Add R_MORELLO_CAPINIT and
R_MORELLO_RELATIVE.
(elf_aarch64_link_hash_table): New member srelcaps.
(c64_valid_cap_range, exponent, cap_meta,
section_start_symbol, c64_fixup_frag): New functions.
* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend,
_bfd_aarch64_elf_resolve_relocation): Add
BFD_RELOC_MORELLO_CAPINIT and BFD_RELOC_MORELLO_RELATIVE.
* libbfd.h (bfd_reloc_code_real_names): Likewise.
* reloc.c: Likewise.
* bfd-in2.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (s_aarch64_capinit): New function.
(md_pseudo_table): Use it.
(md_apply_fix): Add BFD_RELOC_MORELLO_CAPINIT.
(aarch64_fix_adjustable): Return FALSE for capabilities.
* testsuite/gas/aarch64/morello-capinit.d: New test file.
* testsuite/gas/aarch64/morello-capinit.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h (R_MORELLO_CAPINIT, R_MORELLO_RELATIVE): New
relocations.

ld/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/ld-aarch64/aarch64-elf.exp: Add test.
* testsuite/ld-aarch64/morello-capinit.d: New file.
* testsuite/ld-aarch64/morello-capinit.ld: New file.
* testsuite/ld-aarch64/morello-capinit.s: New file.

2 years ago[Morello] Add Morello relocations for ADRP
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:09 +0000 (09:18 +0530)] 
[Morello] Add Morello relocations for ADRP

New relocations R_MORELLO_ADR_PREL_PG_HI20,
R_MORELLO_ADR_PREL_PG_HI20_NC and R_MORELLO_ADR_GOT_PAGE

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* reloc.c: Add MORELLO_ADR_HI20_PCREL,
MORELLO_ADR_HI20_NC_PCREL and MORELLO_ADR_GOT_PAGE.
* elfnn-aarch64.c (elfNN_aarch64_howto_table): Likewise.
(aarch64_reloc_got_type): Add MORELLO_ADR_GOT_PAGE.
(_bfd_aarch64_erratum_843419_branch_to_stub): Add C64 argument
to _bfd_aarch64_reencode_adr_imm.
(elfNN_aarch64_final_link_relocate,
elfNN_aarch64_check_relocs): Add MORELLO_ADR_GOT_PAGE,
MORELLO_ADR_HI20_PCREL and MORELLO_ADR_HI20_NC_PCREL.
* elfxx-aarch64.c (_bfd_aarch64_reencode_adr_imm): Add C64
argument.
(_bfd_aarch64_elf_put_addend): Adjust callers.
* elfxx-aarch64.h (_bfd_aarch64_reencode_adr_imm): Add C64
argument.
* libbfd.h (bfd_reloc_code_real_names): Add
MORELLO_ADR_GOT_PAGE, MORELLO_ADR_HI20_PCREL and
MORELLO_ADR_HI20_NC_PCREL.
* bfd-in2.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (reloc_table_entry): Add c64_adrp_type
field.
(reloc_table): Adjust.
(parse_adrp): Adjust users.
(md_apply_fix): Add MORELLO_ADR_GOT_PAGE,
MORELLO_ADR_HI20_PCREL and MORELLO_ADR_HI20_NC_PCREL.
* testsuite/gas/aarch64/morello_insn-c64.d: Adjust test.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h: Add R_MORELLO_ADR_PREL_PG_HI20,
R_MORELLO_ADR_PREL_PG_HI20_NC and R_MORELLO_ADR_GOT_PAGE.

2 years ago[Morello] Make DC, IC capability aware in C64.
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:09 +0000 (09:18 +0530)] 
[Morello] Make DC, IC capability aware in C64.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (process_omitted_operand,
parse_operands): Add Cat_SYS.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): New operand Cat_SYS.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-opc.c (operand_general_constraint_met_p): Expect
capability registers for cache operations in C64.
(aarch64_print_operand): Print register arguments for cache
instructions correctly.
* aarch64-tbl.h (aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Add Morello system registers
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] Add Morello system registers

Implement MRS/MSR for capability registers.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_sys_reg): New opcode argument.
(parse_operands): Adjust callers.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* include/opcode/aarch64.h
(aarch64_sys_reg_capreg_supported_p): New function.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_sysreg): Adjust for morello
MRS/MSR.
* aarch64-dis.c (aarch64_ext_sysreg): Likewise.
* aarch64-opc.c (fields): New field a64c_op0.
(operand_general_constraint_met_p): Add SYSREG operand
validation.
(aarch64_print_operand): Print Morello MRS/MSR operands
correctly.
(SR_MORELLO): New macro.
(aarch64_sys_regs): Use it.  Add Morello system registers.
(aarch64_sys_reg_capreg_supported_p): New function.
* aarch64-opc.h (aarch64_field_kind): New field FLD_a64c_op0.
* aarch64-tbl.h (QL2_SRC_CA, QL2_DST_CA): New macros.
(aarch64_opcode_table): New instructions.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] ADR, ADRP and ADRDP
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] ADR, ADRP and ADRDP

The opcodes for these instructions overlap with their A64 equivalents;
in fact they're the same with one bit reduced in the immediate.  Use
mapping symbols to determine the correct disassembly.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add A64C_ADDR_ADRDP.
Support 20-bit offset for capability variants.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add A64C_ADDR_ADRDP.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-dis.c (aarch64_ext_regno): Reject A64 ADR when in
C64.
(aarch64_ext_imm): Select ADRDP in C64.
* aarch64-opc.c (fields): Add a64c_immhi field.
(validate_adr_reg_for_feature): New function.
(operand_general_constraint_met_p): Use it.
(aarch64_print_operand): Add A64C_ADDR_ADRDP.
* aarch64-opc.h (aarch64_field_kind): FLD_a64c_immhi.
* aarch64-tbl.h (aarch64_opcode_table): Add new instructions.
(AARCH64_OPERANDS): Add new operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Implement LDUR/STUR fallback for LDR/STR in altbase mode
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] Implement LDUR/STUR fallback for LDR/STR in altbase mode

Give the ops saner names instead of _2, _3, etc.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operand): Reuse ADDR_UIMM12 code
in CAPADDR_UIMM9.
(try_to_encode_as_unscaled_ldst, fix_insn): Add support for
altbase loads and stores.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_op): Add members for altbase LDUR
and STUR.  Rename existing LDUR ops.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-tbl.h (aarch64_opcode_table): Change OP of LDUR/STUR
instructions.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] altbase: Remaining LD/ST
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] altbase: Remaining LD/ST

LDRB, LDRH, LDRSB, LDRSH, STRB, STRH, LDURB, LDURH, STURB, STURH,
LDURSB, LDURSH, LDURSW.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.c (F_NOSHIFT): New flag.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_addr_uimm): Shift only if
F_NOSHIFT is not set.
* aarch64-tbl.h (QL2_B_ADDR, QL2_X_ADDR, QL2_H_ADDR): New
macro.
(aarch64_opcode_table): New instructions.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] altbase: LDUR/STUR
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] altbase: LDUR/STUR

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add Rsz2, Fsz, St and
CAPADDR_SIMM9.
(try_to_encode_as_unscaled_ldst): Add unscaled altbase loads.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add sz2, Fsz, St and
CAPADDR_SIMM9.
(aarch64_op): Add OP_STR_POS_3, OP_LDR_POS_3, OP_STR_POS_4,
OP_LDR_POS_4, OP_LDUR_3, OP_STUR_3, OP_LDUR_4, OP_STUR_4.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_fregsz): New function.
(aarch64_ins_addr_simm): Add ldst_altbase to assert.
* aarch64-asm.h (ins_fregsz): New function declaration.
* aarch64-dis.c (aarch64_ext_fregsz): New function.
(aarch64_ext_addr_simm): Disable writeback for ldst_altbase.
* aarch64-dis.h (ext_fregsz): New function declaration.
* aarch64-opc.c (fields): Add altbase_sf2 and altbase_sf3.
(operand_general_constraint_met_p): Add CAPADDR_SIMM9.
(aarch64_print_operand): Add CAPADDR_SIMM9, Rsz2, Fsz, St.
* aarch64-opc.h (aarch64_field_kind): Add FLD_altbase_sf2, FLD_altbase_sf3.
* aarch64-tbl.h (aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] altbase: LDR/STR
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:08 +0000 (09:18 +0530)] 
[Morello] altbase: LDR/STR

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add Rsz,
CAPADDR_REGOFF, CAPADDR_UIMM9.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.c (aarch64.opnd): add Rsz, CAPADDR_REGOFF,
CAPADDR_UIMM9.
(aarch64_insn_class): Add ldst_altbase.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_regsz): New function.
(aarch64_ins_ft): Support altbase loads.
(aarch64_ins_addr_uimm12): Rename to aarch64_ins_addr_uimm.
* aarch64-asm.h: (ins_regsz): New function declaration.
(ins_addr_uimm12): Rename to ins_addr_uimm.
* aarch64-dis.c (aarch64_ext_regsz): New function.
(aarch64_ext_ft): Support altbase loads.
(aarch64_ext_addr_uimm12): Rename to aarch64_ext_addr_uimm.
* aarch64-dis.h: (ext_regsz): New function declaration.
(dis_addr_uimm12): Rename to dis_addr_uimm.
* aarch64-opc.c (fields): Add altbase_sf.
(operand_general_constraint_met_p): Check constraints for
ldst_altbase, CAPADDR_REGOFF, CAPADDR_UIMM9.
(aarch64_print_operand): Print Rsz, CAPADDR_REGOFF,
CAPADDR_UIMM9.
* aarch64-opc.h (aarch64_field_kind): Add FLD_altbase_sf.
* aarch64-tbl.h (QL2_A64C_R_CAPADDR, QL2_A64C_FP_CAPADDR): New
macro.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Loads and stores with alternate base
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:07 +0000 (09:18 +0530)] 
[Morello] Loads and stores with alternate base

These are loads that use a capability base register in A64 and 64-bit
integer register in C64.

This patch implements LDAR, LDARB, STLR and STLRB.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add Wt.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add Wt.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-opc.c (get_altbase_reg_name): New function.
(aarch64_print_operand): Use it.  Add Wt.
* aarch64-tbl.h (QL2_A64C_W_CAPADDR): New macro.
(aarch64_opcode_table): Add instructions.
(AARCH64_OPERANDS): New operand.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] All remaining load and store instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:07 +0000 (09:18 +0530)] 
[Morello] All remaining load and store instructions

- LDR/STR immediate, indexed and register offset
- LDUR/STUR
- LDTR/STTR

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands, fix_insn): Add
A64C_ADDR_SIMM9.
(try_to_encode_as_unscaled_ldst): Add capability loads.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add A64C_ADDR_SIMM9.
(aarch64_op): Add OP_STR_POS_2, OP_LDR_POS_2, OP_LDUR_2,
OP_STUR_2.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_addr_simm): Support scaling.
* aarch64-dis.c (aarch64_ext_addr_simm): Likewise.
* aarch64-opc.c (operand_general_constraint_met_p,
aarch64_print_operand): Add A64C_ADDR_SIMM9.
* aarch64-tbl.h (aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] LDR immediate
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:07 +0000 (09:18 +0530)] 
[Morello] LDR immediate

The 17-bit signed offset needs to be 16-byte aligned, but the
PCC-relative address resolution rounds down the final address to the
16-byte boundary.  Due to this, disassembly of the instruction will
show as if it is loading from the middle of an object.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_aarch64_howto_table): Add
LD_PREL_LO17.
(elfNN_aarch64_final_link_relocate,
elfNN_aarch64_check_relocs): Likewise.
* elfxx-aarch64.c (reencode_ld_lit_ofs_17): New function.
(_bfd_aarch64_elf_put_addend,
_bfd_aarch64_elf_resolve_relocation): Add LD_PREL_LO17.
* libbfd.h (bfd_reloc_code_real_names): Add
BFD_RELOC_MORELLO_LD_LO17_PCREL.
* reloc.c: Add BFD_RELOC_AARCH64_LD_LO17_PCREL.
* bfd-in2.h: Regenerate.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (encode_ld_lit_ofs_17): New function.
(parse_operands, programmer_friendly_fixup, md_apply_fix): Add
ADDR_PCREL17.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h: New relocation R_MORELLO_LD_PREL_LO17.
* opcode/aarch64.h (aarch64_opnd): Add ADDR_PCREL17.
(aarch64_op): Add OP_LDR_LIT_2.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.
* aarch64-opc.c (fields): Add imm17.
(operand_general_constraint_met_p, aarch64_print_operand): Add
ADDR_PCREL17.
* aarch64-opc.h (aarch64_field_kind): Add FLD_imm17.
* aarch64-tbl.h (QL2_A64C_CA_PCREL): New macro.
(aarch64_opcode_table): New instruction.
(AARCH64_OPERANDS): New operand.

2 years ago[Morello] Load and store instructions.
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:07 +0000 (09:18 +0530)] 
[Morello] Load and store instructions.

- LDAPR, LDAR, LDXP, LDAXP, LDXR, LDAXR, LDCT, LDNP, LDP.
- STXR, STLXR, STLR, STXP, STLXP, STCT, STNP, STP.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands, fix_insn): Add
A64C_ADDR_SIMM7.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add A64C_ADDR_SIMM7.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.
* aarch64-opc.c (fields): Add a64c_index2.
(operand_general_constraint_met_p, aarch64_print_operand): Add
A64C_ADDR_SIMM7.
* aarch64-opc.h (aarch64_field_kind): Add FLD_a64c_index2.
* aarch64-tbl.h (QL2_A64C_CA_ADDR, QL2_A64C_X_ADDR,
QL3_A64C_W_CA_ADDR, QL4_A64C_W_CA_CA_ADDR): New macros.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.

2 years ago[Morello] Load and branch instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:07 +0000 (09:18 +0530)] 
[Morello] Load and branch instructions

- BR, BLR
- LDPBR, LDPBLR

This branch instructions take an address as their target operand.  The
important distinction between the address register usage between these
instructions and other load and store instructions is that these
instructions do not support 64-bit registers as addresses.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (aarch64_addr_reg_parse): Add capability
registers.
(parse_address_main): Support capability address operands.
(parse_cap_address): New function.
(parse_operands): Add CAPADDR_SIMPLE and CAPADDR_SIMM7.
* testsuite/gas/aarch64/morello_ldst-c64.d: Add tests.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add CAPADDR_SIMPLE and
CAPADDR_SIMM7.
(aarch64_insn_class): Add br_capaddr.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_addr_simple): Fix comment.
(aarch64_ins_addr_simm): Support capability address operands.
* aarch64-dis.c (aarch64_ext_addr_simple): Fix comment.
(aarch64_ext_addr_simm): Support capability address operands.
* aarch64-opc.c (fields): Add capaddr_simm7.
(operand_general_constraint_met_p): Add CAPADDR_SIMM7.
(aarch64_print_operand): Add CAPADDR_SIMM7 and CAPADDR_SIMPLE.
* aarch64-opc.h (aarch64_field_kind): Add FLD_capaddr_simm7.
* aarch64-tbl.h (QL1_A64C_CAPADDR, QL2_A64C_CA_CAPADDR): New
macros.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Capability sealing and unsealing instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:06 +0000 (09:18 +0530)] 
[Morello] Capability sealing and unsealing instructions

- SEAL, UNSEAL

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add FORM.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/aarch64.h (aarch64_operand_class): Add FORM.
(aarch64_opnd): Likewise.
(aarch64_form): New struct.
(aarch64_forms): New array.
(get_form_from_value, get_form_from_str): New functions.
(aarch64_opnd_info): New member FORM.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_form): New function.
* aarch64-asm.h (ins_form): New function declaration.
* aarch64-dis.c (aarch64_ext_form): New function.
* aarch64-dis.h (ext_form): New function declaraion.
* aarch64-opc.c (fields): New field form.
(aarch64_forms): Initialise array.
(get_form_from_value, get_form_from_str): New functions.
(aarch64_print_operand): Add FORM.
* aarch64-opc.h (aarch64_field_kind): Add FLD_form.
* aarch64-tbl.h (aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Capability construction and modification instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:06 +0000 (09:18 +0530)] 
[Morello] Capability construction and modification instructions

SCBNDS, SCBNDSE, SCFLGS, SCOFF, SCTAG, SCVALUE.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add IMM6_EXT.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* include/aarch64.h (aarch64_opnd): Add IMM6_EXT.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_aimm): Fix comment.
* aarch64-dis.c (aarch64_ext_a64c_imm6): New function.
* aarch64-dis.h (ext_a64c_imm6): New function.
* aarch64-opc.c (fields): New field a64c_shift.
(operand_general_constraint_met_p, aarch64_print_operand): Add
IMM6_EXT.
* aarch64-opc.h (aarch64_field_kind): Add new field.
* aarch64-tbl.h (aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] CLRTAG, CLRPERM
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:06 +0000 (09:18 +0530)] 
[Morello] CLRTAG, CLRPERM

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_perms): New function.
(parse_operands): Add PERM.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_operand_class): Add PERM.
(aarch64_opnd): Add PERM.
(get_perm_bit): New function.
(aarch64_opnd_info): New member perm.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_ins_perm): New function.
* aarch64-asm.h (ins_perm): New function.
* aarch64-dis.c (aarch64_ext_perm): New function.
* aarch64-dis.h (ext_perm): New function.
* aarch64-opc.c (fields): New field perm.
(get_perm_str, get_perm_bit): New functions.
(aarch64_print_operand): Add PERM.
* aarch64-opc.h (aarch64_field_kind): Add perm.
* aarch64-tbl.h (QL_I2SAMEQ): New macro.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Miscellaneous Morello Instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:06 +0000 (09:18 +0530)] 
[Morello] Miscellaneous Morello Instructions

All these instructions use existing operands and fields, so clubbed
together for simplicity.

- ALIGND, ALIGNU
- BUILD, CFHI
- CHKEQ, CHKSS, CHKSLD, CHKTGD, CHKSSU.
- CPYTYPE, CPYVALUE
- CSEAL
- CTHI, CVT, CVTD, CVTDZ, CVTP, CVTPZ, CVTZ.
- EORFLGS, ORRFLGS
- GCBASE, GCFLGS, GCLEN, GCLIM, GCOFF, GCPERM, GCSEAL, GCTAG, GCTYPE,
  GCVALUE.
- RET, RETR, RETS.
- RRLEN, RRMASK
- SUBS, CMP
- CAS, CASA, CASAL, CASL
- SWP, SWPA, SWPAL, SWPL
- CSEL

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.
* testsuite/gas/aarch64/morello_ldst-c64.d: New file.
* testsuite/gas/aarch64/morello_ldst.d: Likewise.
* testsuite/gas/aarch64/morello_ldst.s: Likewise.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-tbl.h (QL2_A64C_X_CA, QL2_A64C_CA_X, QL2_A64C_X_X,
QL3_A64C_X_CA_CA, QL3_A64C_CA_CA_ADDR, QL4_A64C_CSEL): New
macros.
(aarch64_opcode_table): New instructions.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Branch and return instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:06 +0000 (09:18 +0530)] 
[Morello] Branch and return instructions

- BLR, BLRR, BLRS, BR, BRR, BRS, BX.
- RET, RETR, RETS.

Disassembly note: RET with capability is always disassembled with the
register name even if it is the default register, i.e. C30.  This is
to make it visually simpler to differentiate between the A64 and
Morello RET instructions.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (process_omitted_operand): Identify Can.
(parse_operands): Add CST_REG, Cam_SP
and A64C_IMMV4.
* testsuite/gas/aarch64/morello_insn.s: Add tests.
* testsuite/gas/aarch64/morello_insn.d: Likewise.
* testsuite/gas/aarch64/morello_insn-c64.d: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add CST_REG, Cam_SP
and A64C_IMMV4.
(aarch64_insn_class): Add br_sealed.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-dis.c (aarch64_ext_a64c_immv): New function.
(aarch64_ext_regno): Set PRESENT flag for A64 RET.
* aarch64-dis.h (aarch64_ext_a64c_immv): New function.
* aarch64-opc.c (operand_general_constraint_met_p): Add
A64C_IMMV4.  Remove ATTRIBUTE_UNUSED.  Reject A64 RET without
operand when in C64.
(aarch64_match_operands_constraint): Remove ATTRIBUTE_UNUSED.
(aarch64_print_operand): Add A64C_IMMV4, Cam_SP and CST_REG.
* aarch64-tbl.h (QL1_A64C_CA, QL3_A64C_CA_CA_CA): New macros.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): New operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Add BICFLGS
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[Morello] Add BICFLGS

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add A64C_IMM8.
* testsuite/gas/aarch64/morello_insn.d: Add tests.
* testsuite/gas/aarch64/morello_insn-c64.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): Add A64C_IMM8.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-opc.c (fields): Add a64c_imm8.
(aarch64_print_operand): Add A64C_IMM8.
* aarch64-opc.h (aarch64_field_kind): Add a64c_imm8.
* aarch64-tbl.h (QL3_A64C_CA_CA_X): New macro.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): Add A64C_IMM8.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] ADD and SUB instructions
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[Morello] ADD and SUB instructions

Implement ADD (immediate), SUB (immediate) and ADD (extended
register).

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands, fix_insn): Add
A64C_AIMM and A64C_Rm_EXT.
* testsuite/gas/aarch64/morello_insn.d: Add tests.
* testsuite/gas/aarch64/morello_insn-c64.d: Add tests.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64 (aarch64_opnd): Add A64C_AIMM and
A64C_Rm_EXT.
(aarch64_op): Add OP_A64C_ADD.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-dis.c (aarch64_ext_regno, aarch64_ext_reg_extended):
Identify capability register class.
(do_ext_aimm): New function.
(arch64_ext_aimm): Call it.
(aarch64_ext_a64c_aimm): New function.
* aarch64-dis.h (ext_a64c_aimm): New function.
* aarch64-opc.c (fields): Add a64c_shift_ai field.
(operand_general_constraint_met_p, aarch64_print_operand): Add
A64C_AIMM and A64C_Rm_EXT.
* aarch64-opc.h (aarch64_field_kind): Add a64c_shift_ai.
* aarch64-tbl.h (QL3_A64C_CA_CA_NIL, QL3_A64C_CA_CA_R): New
macro.
(aarch64_opcode_table): New instructions.
(AARCH64_OPERANDS): Add new operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Add MOV and CPY instructions for capabilities
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[Morello] Add MOV and CPY instructions for capabilities

MOV is an alias of CPY in all cases except when moving CZR into a
capability register (e.g. mov c0, czr), in which case it is treated
as an alias of mov x0, xzr.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (parse_operands): Add capability
register operands.
* testsuite/gas/aarch64/morello_insn.d: Add tests.
* testsuite/gas/aarch64/morello_insn-c64.d: Likewise.
* testsuite/gas/aarch64/morello_insn.s: Likewise.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opnd): New capability operands.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (do_special_encoding): Recognise capability
registers.
* aarch64-opc.c (aarch64_opnd_qualifiers): Capability operand
qualifiers.
(aarch64_print_operand): Support capability operands.
* aarch64-opc.h (select_operand_for_sf_field_coding):
Recognise capability registers.
* aarch64-tbl.h (QL2_A64C_CA_CA): New macro.
(aarch64_opcode_table): Add mov and cpy.
(AARCH64_OPERANDS): Add capability register operands.
* aarch64-asm-2.c: Regenerate.
* aarch64-dis-2.c: Regenerate.
* aarch64-opc-2.c: Regenerate.

2 years ago[Morello] Identify branch source and target using mapping symbols
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[Morello] Identify branch source and target using mapping symbols

Initialise section map data so that it can be used to identify C64
branch targets.  This is a reliable way (as long as mapping symbols
are correctly placed!) to identify branch source and target types in
cases where the target type is not STT_FUNC.  STT_FUNC targets can
already be identified using the LSB in the symbol table.

Use cases where the branch relocations are used (such as
elfNN_aarch64_size_stubs) have been adjusted to use the symbol cache
instead of reading the symbol table all over again.  In addition to
being faster, it will also allow identification of the relocation
targets using the st_target_internal set earlier by check_relocs.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf-bfd.h (bfd_elf_section_data): New member
is_target_section_data.
* elfnn-aarch64.c (_aarch64_elf_section_data): New member
sorted.
(elf_aarch64_section_data_get, c64_value_p): New functions.
(elf_aarch64_compare_mapping): Move function up in the file.
(elf_aarch64_obj_tdata): New member secmaps_initialised.
(bfd_elfNN_aarch64_init_maps, bfd_elfNN_aarch64_set_options):
Use it.
(elfNN_aarch64_size_stubs): Use symbol cache.
(elfNN_aarch64_check_relocs): Call
bfd_elfNN_aarch64_init_maps.  Mark C64 symbols in relocations
in the symbol cache.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (FIXUP_F_C64): New macro.
(output_inst, parse_operands): Use it.
(aarch64_force_relocation, aarch64_fix_adjustable): Defer
relocation of branches with different source and targets to
the linker.
* config/tc-aarch64.h (aarch64_fix): New member c64.

2 years ago[AArch64] Remove section caches for section data
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[AArch64] Remove section caches for section data

The cache is not used anymore and is unnecessarily allocated and
freed.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (section_list,
sections_with_aarch64_elf_section_data,
record_section_with_aarch64_elf_section_data,
find_aarch64_elf_section_entry,
unrecord_section_with_aarch64_elf_section_data,
unrecord_section_via_map_over_sections,
bfd_elfNN_close_and_cleanup, bfd_elfNN_bfd_free_cached_info):
Remove.  Adjust all users.

2 years ago[Morello] Set LSB for c64 symbols in object code
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:05 +0000 (09:18 +0530)] 
[Morello] Set LSB for c64 symbols in object code

The Morello processor takes the LSB of the PCC (i.e. the capability
equivalent of PC) as a hint to set PE state to C64 when set and A64
otherwise.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Set LSB for C64 symbols.
(elfNN_aarch64_output_map_sym, elfNN_aarch64_output_stub_sym):
Initialise st_target_internal.
(aarch64_elfNN_swap_symbol_in, aarch64_elfNN_swap_symbol_out):
New functions.
(elfNN_aarch64_size_info): Add them as callbacks.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c: Include cpu-aarch64.h.
(IS_C64): New macro.
(make_mapping_symbol, aarch64_frob_label): Set LSB of C64
symbol.
(aarch64_adjust_symtab): Mark all C64 functions.
(parse_operands): Set LSB when target of ADR is a function.
(aarch64_fix_adjustable): New function.
* config/tc-aarch64.h (AARCH64_SET_FLAG, AARCH64_RESET_FLAG,
AARCH64_FLAG_C64, AARCH64_IS_C64, AARCH64_SET_C64): New
macros.
(aarch64_fix_adjustable): New function.
(tc_fix_adjustable): Use it.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* elf/aarch64.h (aarch64_st_branch_type): New enum.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-dis.c: Include elf/aarch64.h.
(get_sym_code_type): Identify C64 functions.

2 years ago[Morello] Add mapping symbol to identify C64 code sections
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:04 +0000 (09:18 +0530)] 
[Morello] Add mapping symbol to identify C64 code sections

Add a mapping symbol $c at the beginning of every C64 code section to
allow the disassembler to identify C64 code sections.  This will allow
the disassembler to print the correct base address registers and also
choose the correct disassembly in cases where the opcodes for A64 and
C64 instructions are aliased.

To aid correct disassembly of instructions, pass CPU variant to
various helpers in libopcodes so that they can use that information to
choose between A64 and C64 disassembly.

bfd/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* cpu-aarch64.c (bfd_is_aarch64_special_symbol_name): Add
capability mapping symbol.
* elfnn-aarch64.c (elfNN_aarch64_output_map_sym,
is_aarch64_mapping_symbol): Likewise.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.h (mstate): Add MAP_C64.
* config/tc-aarch64.c (make_mapping_symbol): Add capability
mapping symbol.
(MAP_CUR_INSN): New macro.
(mapping_state, s_aarch64_inst, md_assemble,
aarch64_handle_align, aarch64_init_frag): Use it.
(output_operand_error_record, do_encode,
try_to_encode_as_unscaled_ldst, fix_mov_imm_insn, fix_insn):
Pass CPU_VARIANT to AARCH64_OPCODE_ENCODE.
* doc/c-aarch64.texi: Document $c.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (aarch64_opcode_encode): Add cpu variant
argument.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-asm.c (aarch64_opcode_encode): Add CPU variant
argument.
* aarch64-dis.c (map_type): Add MAP_C64.
(MAYBE_C64): New macro.
(determine_disassembling_preference, print_operands): Use it.
(aarch64_symbol_is_valid): Test for $c.
(get_sym_code_type): Recognise MAP_C64.
(select_aarch64_variant): Clear AARCH64_FEATURE_C64.
(determine_disassembling_preference, aarch64_opcode_decode):
Adjust calls to aarch64_match_operands_constraint.
* aarch64-opc.c (get_altbase_reg_name, get_base_reg_name): New
functions.
(aarch64_print_operand): Use them.
(aarch64_match_operands_constraint): Likewise.
* aarch64-opc.h (aarch64_match_operands_constraint): Add CPU
variant argument.

2 years ago[AArch64] Initial commit for Morello architecture
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:04 +0000 (09:18 +0530)] 
[AArch64] Initial commit for Morello architecture

The Morello architecture implements support for 129 bit capabilities
to replace traditional pointers to reference memory.  A 129 bit
capability has a 64-bit virtual address in its lowest bits and the
next 64 bits have various access control metadata such as bounds
within which the virtual address can be, permissions and other
metadata for protection.  The top 129th bit is stored out of band and
it indicates if the capability is valid.

Capability registers extends the 64-bit register file and are
similarly numberd c0 to c30.  The stack capability register is csp and
it aliases with sp.  One may access the lower 64 bits of the
capability registers by using the 64-bit register names, i.e. x0-x30
and sp.  The Arm Architecture Reference Manual Supplement Morello for
A-profile Architecture has more details on the register layout.

To ensure backward compatibiility, processors implementing the Morello
architecture can run in two states, the standard A64 and a new state
called C64.  In A64 state, base addresses of memory access
instructions are treated as pointers and traditional aarch64
applications should run out of the box in this state.  In C64 state,
base address registers are expected to be valid capabilities.

There are additional load and store instructions that allow using
capabilities as address registers in A64 mode (and 64-bit registers in
C64 mode).  These are called alternate base loads and stores.

The following new -march flags are implemented:

- a64c: This is the base feature flag to implement instruction
  extensions for Morello that are distinct from its base A64 support.
  Address registers are assumed to be 64-bit except for alternate base
  loads and stores; they are assumed to be capability registers.

- morello: This enables instructions that are allowed on the Morello
  architecture in A64.  This includes armv8.2-a, a64c and other
  extensions that are considered part of the Morello architecture.

- c64: This enables instructions that are allowed on the Morello
  architecture in C64 state.  Address registers are assumed to be
  capabilities except for alternate base loads and stores; they are
  assumed to be 64-bit registers.

To assemble code that is intended to run in A64 state on Morello,
build with -march=morello and for C64 state, build with
-march=morello+c64.

This patch implements bare support for registers and the -march flags.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (AARCH64_REG_TYPES,
get_reg_expected_msg, aarch64_addr_reg_parse, parse_address,
reg_names): Add capability registers.
(parse_operands): Identify capability register based address.
(aarch64_archs): Add morello.
(aarch64_features): Add a64c and c64.
* doc/c-aarch64.texi: Document -march flags.
* testsuite/gas/aarch64/morello_insn.d: New file
* testsuite/gas/aarch64/morello_insn-c64.d: New file
* testsuite/gas/aarch64/morello_insn.s: New file.

include/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* opcode/aarch64.h (AARCH64_FEATURE_A64C,
AARCH64_FEATURE_C64): New feature macros.
(AARCH64_ARCH_MORELLO): New architecture macro.
(aarch64_operand_class): Add AARCH64_OPND_CLASS_CAP_REG.
(aarch64_opnd): New capability operands.
(aarch64_opnd_qualifier): New capability qualifier.
(aarch64_insn_class): Add a64c instruction class.

opcodes/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* aarch64-opc.c (fields): New capability register fields.
(aarch64_opnd_qualifiers): Capability operand qualifiers.
(int_reg): Add capability register bank.
(get_int_reg_name): Adjust for capability registers.
(get_cap_reg_name): New function.
(aarch64_print_operand): Support printing capability operands.
* aarch64-opc.h (aarch64_field_kind): Add capability operand
fields.
(OPD_F_MAYBE_CSP): New macro.
(operand_maybe_cap_stack_pointer): New function.
* aarch64-tbl.h (QL2_A64C_CA_CA, A64C, A64C_INSN): New macros.
(aarch64_feature_a64c): New feature set.

2 years ago[AArch64] Prefer error messages from opcodes enabled in CPU_VARIANT
Siddhesh Poyarekar [Fri, 11 Sep 2020 03:48:04 +0000 (09:18 +0530)] 
[AArch64] Prefer error messages from opcodes enabled in CPU_VARIANT

Printing error messages from opcodes that would otherwise not be used
due to not being enabled is pointless when there are other
alternatives.  Prefer error messages from enabled opcodes instead.

A more ideal fix would to sort error messages earlier when deciding
which KIND to return.  That is, other fatal errors of a less serious
KIND from an enabled opcode should get priority over a more serious
KIND of a disabled opcode.

gas/ChangeLog:

2020-10-20  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

* config/tc-aarch64.c (output_operand_error_report): Account
for CPU_VARIANT in error messages.
* testsuite/gas/aarch64/illegal-sve2.l: Adjust.
* testsuite/gas/aarch64/verbose-error.l: Adjust.

2 years agogdb/hurd: pass memory_tagged as false to find_memory_region_ftype
Enze Li [Sun, 24 Jul 2022 03:20:46 +0000 (11:20 +0800)] 
gdb/hurd: pass memory_tagged as false to find_memory_region_ftype

I tried building GDB on GNU/Hurd, and ran into this error:

  CXX    gnu-nat.o
gnu-nat.c: In member function â€˜virtual int gnu_nat_target::find_memory_regions(find_memory_region_ftype, void*)’:
gnu-nat.c:2620:21: error: too few arguments to function
 2620 |             (*func) (last_region_address,
      |             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
 2621 |                      last_region_end - last_region_address,
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2622 |                      last_protection & VM_PROT_READ,
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2623 |                      last_protection & VM_PROT_WRITE,
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2624 |                      last_protection & VM_PROT_EXECUTE,
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2625 |                      1, /* MODIFIED is unknown, pass it as true.  */
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2626 |                      data);
      |                      ~~~~~
gnu-nat.c:2635:13: error: too few arguments to function
 2635 |     (*func) (last_region_address, last_region_end - last_region_address,
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2636 |              last_protection & VM_PROT_READ,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2637 |              last_protection & VM_PROT_WRITE,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2638 |              last_protection & VM_PROT_EXECUTE,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2639 |              1, /* MODIFIED is unknown, pass it as true.  */
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2640 |              data);
      |              ~~~~~
make[2]: *** [Makefile:1926: gnu-nat.o] Error 1

This is because in this commit:

  commit 68cffbbd4406b4efe1aa6e18460b1d7ca02549f1
  Date:   Thu Mar 31 11:42:35 2022 +0100

      [AArch64] MTE corefile support

Added a new argument to find_memory_region_ftype, but did not pass it to
the function in gnu-nat.c.  Fix this by passing memory_tagged as false.

As Luis pointed out, similar bugs may also appear on FreeBSD and NetBSD,
and I have reproduced them on both systems.  This patch fixes them
incidentally.

Tested by rebuilding on GNU/Hurd, FreeBSD/amd64 and NetBSD/amd64.

2 years ago[AArch64] MTE corefile support
Luis Machado [Thu, 31 Mar 2022 10:42:35 +0000 (11:42 +0100)] 
[AArch64] MTE corefile support

Teach GDB how to dump memory tags for AArch64 when using the gcore command
and how to read memory tag data back from a core file generated by GDB
(via gcore) or by the Linux kernel.

The format is documented in the Linux Kernel documentation [1].

Each tagged memory range (listed in /proc/<pid>/smaps) gets dumped to its
own PT_AARCH64_MEMTAG_MTE segment. A section named ".memtag" is created for each
of those segments when reading the core file back.

To save a little bit of space, given MTE tags only take 4 bits, the memory tags
are stored packed as 2 tags per byte.

When reading the data back, the tags are unpacked.

I've added a new testcase to exercise the feature.

Build-tested with --enable-targets=all and regression tested on aarch64-linux
Ubuntu 20.04.

[1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support)

2 years agoFix include guard naming for arch/aarch64-mte-linux.h
Luis Machado [Mon, 4 Jul 2022 09:43:25 +0000 (10:43 +0100)] 
Fix include guard naming for arch/aarch64-mte-linux.h

It should be ARCH_AARCH64_MTE_LINUX_H as opposed to ARCH_AARCH64_LINUX_H.

2 years ago[AArch64] Support AArch64 MTE memory tag dumps in core files
Luis Machado [Tue, 28 Jun 2022 11:57:34 +0000 (12:57 +0100)] 
[AArch64] Support AArch64 MTE memory tag dumps in core files

The Linux kernel can dump memory tag segments to a core file, one segment
per mapped range. The format and documentation can be found in the Linux
kernel tree [1].

The following patch adjusts bfd and binutils so they can handle this new
segment type and display it accordingly. It also adds code required so GDB
can properly read/dump core file data containing memory tags.

Upon reading, each segment that contains memory tags gets mapped to a
section named "memtag". These sections will be used by GDB to lookup the tag
data. There can be multiple such sections with the same name, and they are not
numbered to simplify GDB's handling and lookup.

There is another patch for GDB that enables both reading
and dumping of memory tag segments.

Tested on aarch64-linux Ubuntu 20.04.

[1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support)

2 years agofbsd-nat: Correct the return type of the have_regset method.
John Baldwin [Tue, 2 Aug 2022 21:54:28 +0000 (14:54 -0700)] 
fbsd-nat: Correct the return type of the have_regset method.

During the development of 40c23d880386d6e8202567eaa2a6b041feb1a652,
the return value of fbsd_nat_target::have_regset was changed from a
simple boolean to returning the size of the register set.  The
comments and callers were all updated for this change, but the actual
return type was accidentally left as a bool.  This change fixes the
return type to be a size_t.

Current callers of this only checked the value against 0 and thus
still worked correctly.

3 years agoTweak the std::hash<> specialization for aarch64_features.
John Baldwin [Mon, 23 May 2022 18:02:55 +0000 (11:02 -0700)] 
Tweak the std::hash<> specialization for aarch64_features.

Move the specialization into an explicit std namespace to workaround a
bug in older compilers.  GCC 6.4.1 at least fails to compile the previous
version with the following error:

gdb/arch/aarch64.h:48:13: error: specialization of 'template<class _Tp> struct std::hash' in different namespace [-fpermissive]

  struct std::hash<aarch64_features>

(cherry picked from commit e8123c847f61c7458200b349615c47e9df17a0ed)

3 years agoUse aarch64_features to describe register features in target descriptions.
John Baldwin [Wed, 18 May 2022 20:32:04 +0000 (13:32 -0700)] 
Use aarch64_features to describe register features in target descriptions.

Replace the sve bool member of aarch64_features with a vq member that
holds the vector quotient.  It is zero if SVE is not present.

Add std::hash<> specialization and operator== so that aarch64_features
can be used as a key with std::unordered_map<>.

Change the various functions that create or lookup aarch64 target
descriptions to accept a const aarch64_features object rather than a
growing number of arguments.

Replace the multi-dimension tdesc_aarch64_list arrays used to cache
target descriptions with unordered_maps indexed by aarch64_feature.

(cherry picked from commit 0ee6b1c511c0e2a6793568692d2e5418cd6bc10d)

3 years agogdbserver: Fix build after adding tls feature to arm tdesc.
John Baldwin [Wed, 4 May 2022 04:38:12 +0000 (21:38 -0700)] 
gdbserver: Fix build after adding tls feature to arm tdesc.

(cherry picked from commit 24ef0d41ac9632ff85d3781e5852371e39661558)

3 years agoRead the tpidr register from NT_ARM_TLS on Linux.
John Baldwin [Tue, 3 May 2022 23:05:11 +0000 (16:05 -0700)] 
Read the tpidr register from NT_ARM_TLS on Linux.

(cherry picked from commit 3b4b3e438d2cbf685133df5425931a2355192045)

3 years agogdbserver: Read the tpidr register from NT_ARM_TLS on Linux.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
gdbserver: Read the tpidr register from NT_ARM_TLS on Linux.

(cherry picked from commit 9c27bc99e4e1c4fbf51dc8f6186f0fdd5994a38b)

3 years agoRead the tpidr register from NT_ARM_TLS core dump notes on Linux Aarch64.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Read the tpidr register from NT_ARM_TLS core dump notes on Linux Aarch64.

(cherry picked from commit 224151d7748ef13df82878067266cfaa9861e360)

3 years agoaarch64-fbsd-nat: Move definition of debug_regs_probed under HAVE_DBREG.
John Baldwin [Thu, 26 May 2022 21:14:46 +0000 (14:14 -0700)] 
aarch64-fbsd-nat: Move definition of debug_regs_probed under HAVE_DBREG.

This fixes the build on older FreeBSD systems without support for
hardware breakpoints/watchpoints.

(cherry picked from commit b2fdd31b03ef01a9a790ecb5d0dc0fea209b49ec)

3 years agoFetch the NT_ARM_TLS register set for native FreeBSD/Aarch64 processes.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Fetch the NT_ARM_TLS register set for native FreeBSD/Aarch64 processes.

This permits resolving TLS variables.

(cherry picked from commit b7fe5463cf0dd6d7701d0be5ae129a9d4ecd28bc)

3 years agoSupport TLS variables on FreeBSD/Aarch64.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Support TLS variables on FreeBSD/Aarch64.

Derive the pointer to the DTV array from the tpidr register.

(cherry picked from commit f9fbb7636a5b67abae41a35f02ae70f58523d375)

3 years agoRead the tpidr register from NT_ARM_TLS core dump notes on FreeBSD/Aarch64.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Read the tpidr register from NT_ARM_TLS core dump notes on FreeBSD/Aarch64.

(cherry picked from commit 0a765c1a8e9c59f4cd0cdaf986291f957fe6ee90)

3 years agoAdd an aarch64-tls feature which includes the tpidr register.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Add an aarch64-tls feature which includes the tpidr register.

(cherry picked from commit 414d5848bb2766ea7cef162c6ef5862ddb4dfe0f)

3 years agoFetch the NT_ARM_TLS register set for native FreeBSD/arm processes.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Fetch the NT_ARM_TLS register set for native FreeBSD/arm processes.

This permits resolving TLS variables.

(cherry picked from commit 684943d213b461a6a84ae67a9b8fcae5a28f007d)

3 years agoSupport TLS variables on FreeBSD/arm.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Support TLS variables on FreeBSD/arm.

Derive the pointer to the DTV array from the tpidruro register.

(cherry picked from commit 2e686a74dc4782caeef75f76174909ab7ad358f8)

3 years agoRead the tpidruro register from NT_ARM_TLS core dump notes on FreeBSD/arm.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Read the tpidruro register from NT_ARM_TLS core dump notes on FreeBSD/arm.

(cherry picked from commit 099fbce0accf209677e041fd9dc10bcb4a5eb578)

3 years agoAdd an arm-tls feature which includes the tpidruro register from CP15.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
Add an arm-tls feature which includes the tpidruro register from CP15.

(cherry picked from commit 92d48a1e4eac54db11f1a110328672394fce2853)

3 years agofbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET.
John Baldwin [Tue, 3 May 2022 23:05:10 +0000 (16:05 -0700)] 
fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET.

FreeBSD's kernel has recently added PT_GETREGSET and PT_SETREGSET
operations to fetch a register set named by an ELF note type.  These
helper routines provide helpers to check for a register set's
existence, fetch registers for a register set, and store registers to
a register set.

(cherry picked from commit 40c23d880386d6e8202567eaa2a6b041feb1a652)

3 years agoCreate pseudo sections for NT_ARM_TLS notes on FreeBSD.
John Baldwin [Wed, 27 Apr 2022 15:06:39 +0000 (08:06 -0700)] 
Create pseudo sections for NT_ARM_TLS notes on FreeBSD.

bfd/ChangeLog:

* elf.c (elfcore_grok_freebsd_note): Handle NT_ARM_TLS notes.

(cherry picked from commit 8e6afe4013fd57f92eec4659439bc6e44b0446f8)

3 years agoRemove unused variable.
John Baldwin [Fri, 1 Apr 2022 22:21:09 +0000 (15:21 -0700)] 
Remove unused variable.

(cherry picked from commit 3181aed81c92d091f5313df5dee27a9376dc1cce)

3 years agoUse I386_GSBASE_REGNUM in i386fbsd_get_thread_local_address.
John Baldwin [Fri, 1 Apr 2022 20:16:46 +0000 (13:16 -0700)] 
Use I386_GSBASE_REGNUM in i386fbsd_get_thread_local_address.

32-bit x86 arches always the I386_*BASE_REGNUM values.  Only code that
needs to support both 64-bit and 32-bit arches needs to use
tdep->fsbase_regnum to compute a segment base register number.

(cherry picked from commit c13566fdd5725d4c337a2741be02c12c4f430022)

3 years agoFreeBSD/x86: Read segment base registers from NT_X86_SEGBASES.
John Baldwin [Fri, 1 Apr 2022 20:16:46 +0000 (13:16 -0700)] 
FreeBSD/x86: Read segment base registers from NT_X86_SEGBASES.

FreeBSD kernels recently grew a new register core dump note containing
the base addresses of the %fs and %gs segments (corresponding to the
%fsbase and %gsbase registers).  Parse this note to permit inspecting
TLS variables in core dumps.  Native processes already supported TLS
via older ptrace() operations.

(cherry picked from commit f3215e1526d762f005fdf86abac81da514c74e50)

3 years agoUse pseudosections for NT_FREEBSD_X86_SEGBASES core dump notes.
John Baldwin [Fri, 1 Apr 2022 20:16:46 +0000 (13:16 -0700)] 
Use pseudosections for NT_FREEBSD_X86_SEGBASES core dump notes.

This includes adding pseudosections when reading a core dump as well
as support for writing out a core dump note from a pseudosection.

bfd/ChangeLog:

* elf-bfd.h (elfcore_write_x86_segbases): New.
* elf.c (elfcore_grok_freebsd_note): Add pseudosections for
NT_FREEBSD_X86_SEGBASES register notes.
(elfcore_write_x86_segbases): New.
(elfcore_write_register_note): Write NT_FREEBSD_X86_SEGBASES
register notes.

(cherry picked from commit b5c2367c3ac5f696221d9c24f470498abdb83257)

3 years agoRecognize FreeBSD core dump note for x86 segment base registers.
John Baldwin [Fri, 1 Apr 2022 20:16:46 +0000 (13:16 -0700)] 
Recognize FreeBSD core dump note for x86 segment base registers.

This core dump note contains the value of the base address of the %fs
and %gs segments for both i386 and amd64 core dumps.  It is primarily
useful in resolving the address of TLS variables in core dumps.

binutils/ChangeLog:

* readelf.c (get_freebsd_elfcore_note_type): Handle
NT_FREEBSD_X86_SEGBASES.

include/ChangeLog:

* elf/common.h (NT_FREEBSD_X86_SEGBASES): Define.

(cherry picked from commit a171378aa472fab0407dc1f99e8e7782286719ed)

3 years agoelfcore_grok_freebsd_note: Remove checks of note->namesz.
John Baldwin [Fri, 1 Apr 2022 20:16:46 +0000 (13:16 -0700)] 
elfcore_grok_freebsd_note: Remove checks of note->namesz.

This function is only called if the note name is "FreeBSD", so
checking the name size is unnecessary.

bfd/ChangeLog:

* elf.c (elfcore_grok_freebsd_note): Remove checks for namesz.

(cherry picked from commit e330d4c033eab2e0e7206a29d6c11a9a59fd205b)

3 years agoAdd support for hardware breakpoints/watchpoints on FreeBSD/Aarch64.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
Add support for hardware breakpoints/watchpoints on FreeBSD/Aarch64.

This shares aarch64-nat.c and nat/aarch64-hw-point.c with the Linux
native target.  Since FreeBSD writes all of the debug registers in one
ptrace op, use an unordered_set<> to track the "dirty" state for
threads rather than bitmasks of modified registers.

(cherry picked from commit 065a00b3a461463cca766ac6bb33e3be436397bd)

3 years agofbsd-nat: Add a low_prepare_to_resume virtual method.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add a low_prepare_to_resume virtual method.

This method can be overridden by architecture-specific targets to
perform additional work before a thread is resumed.

(cherry picked from commit a3627b54280ba306766f2689fb35442f24c4c313)

3 years agofbsd-nat: Add a low_delete_thread virtual method.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add a low_delete_thread virtual method.

This method can be overridden by architecture-specific targets to
perform additional work when a thread is deleted.

Note that this method is only invoked on systems supporting LWP
events, but the pending use case (aarch64 debug registers) is not
supported on older kernels that do not support LWP events.

(cherry picked from commit 983b1119bc315c9182e3aba898ca8099e54da49e)

3 years agofbsd-nat: Add helper routine to fetch siginfo_t for a ptid.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
fbsd-nat: Add helper routine to fetch siginfo_t for a ptid.

(cherry picked from commit 6719bc690e2829c50d3d3bb22ede1324e5baa12a)

3 years agoaarch64: Add an aarch64_nat_target mixin class.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
aarch64: Add an aarch64_nat_target mixin class.

This class includes platform-independent target methods for hardware
breakpoints and watchpoints using routines from
nat/aarch64-hw-point.c.

stopped_data_address is not platform-independent since the FAR
register holding the address for a breakpoint hit must be fetched in a
platform-specific manner.  However, aarch64_stopped_data_address is
provided as a helper routine which performs platform-independent
validation given the value of the FAR register.

For tracking the per-process debug register mirror state, use an
unordered_map indexed by pid as recently adopted in x86-nat.c rather
than a manual linked-list.

(cherry picked from commit 1570c37c340bb9df2db2c30b437d6c30e1d75459)

3 years agonat: Split out platform-independent aarch64 debug register support.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
nat: Split out platform-independent aarch64 debug register support.

Move non-Linux-specific support for hardware break/watchpoints from
nat/aarch64-linux-hw-point.c to nat/aarch64-hw-point.c.  Changes
beyond a simple split of the code are:

- aarch64_linux_region_ok_for_watchpoint and
  aarch64_linux_any_set_debug_regs_state renamed to drop linux_ as
  they are not platform specific.

- Platforms must implement the aarch64_notify_debug_reg_change
  function which is invoked from the platform-independent code when a
  debug register changes for a given debug register state.  This does
  not use the indirection of a 'low' structure as is done for x86.

- The handling for kernel_supports_any_contiguous_range is not
  pristine.  For non-Linux it is simply defined to true.  Some uses of
  this could perhaps be implemented as new 'low' routines for the
  various places that check it instead?

- Pass down ptid into aarch64_handle_breakpoint and
  aarch64_handle_watchpoint rather than using current_lwp_ptid which
  is only defined on Linux.  In addition, pass the ptid on to
  aarch64_notify_debug_reg_change instead of the unused state
  argument.

(cherry picked from commit 4bd817e71eefd659f51ec75bfb13109c486e8311)

3 years agox86-fbsd-nat: Copy debug register state on fork.
John Baldwin [Tue, 22 Mar 2022 19:05:43 +0000 (12:05 -0700)] 
x86-fbsd-nat: Copy debug register state on fork.

Use the FreeBSD native target low_new_fork hook to copy the
per-process debug state from the parent to the child on fork.

(cherry picked from commit 041a4212d37de6172b3428613c9f9f52ab950c6c)