aarch64: Add base support for Armv8-R
authorAlex Coplan <alex.coplan@arm.com>
Tue, 8 Sep 2020 13:13:45 +0000 (14:13 +0100)
committerAlex Coplan <alex.coplan@arm.com>
Tue, 8 Sep 2020 13:14:11 +0000 (14:14 +0100)
This patch adds the basic infrastructure needed to support Armv8-R in
AArch64 binutils: new command-line flags, new feature bits, a new BFD
architecture, and support for differentiating between architecture
variants in the disassembler.

The new command-line options added by this patch are -march=armv8-r in
GAS and -m aarch64:armv8-r in objdump.

The disassembler support is necessary since Armv8-R AArch64 introduces a
system register (VSCTLR_EL2) which shares an encoding with a different
system register (TTBR0_EL2) in Armv8-A. This also allows us to use the
correct preferred disassembly for the new DFB alias introduced in
Armv8-R.

bfd/ChangeLog:

2020-09-08  Alex Coplan  <alex.coplan@arm.com>

* archures.c (bfd_mach_aarch64_8R): New.
* bfd-in2.h: Regenerate.
* cpu-aarch64.c (bfd_aarch64_arch_v8_r): New.
(bfd_aarch64_arch_ilp32): Update tail pointer.

gas/ChangeLog:

2020-09-08  Alex Coplan  <alex.coplan@arm.com>

* config/tc-aarch64.c (aarch64_archs): Add armv8-r.
* doc/c-aarch64.texi: Document -march=armv8-r.

include/ChangeLog:

2020-09-08  Alex Coplan  <alex.coplan@arm.com>

* opcode/aarch64.h (AARCH64_FEATURE_V8_A): New.
(AARCH64_FEATURE_V8_R): New.
(AARCH64_ARCH_V8): Include new A-profile feature bit.
(AARCH64_ARCH_V8_R): New.

opcodes/ChangeLog:

2020-09-08  Alex Coplan  <alex.coplan@arm.com>

* aarch64-dis.c (arch_variant): New.
(determine_disassembling_preference): Disassemble according to
arch variant.
(select_aarch64_variant): New.
(print_insn_aarch64): Set feature set.

bfd/ChangeLog
bfd/archures.c
bfd/bfd-in2.h
bfd/cpu-aarch64.c
gas/ChangeLog
gas/config/tc-aarch64.c
gas/doc/c-aarch64.texi
include/ChangeLog
include/opcode/aarch64.h
opcodes/ChangeLog
opcodes/aarch64-dis.c

index 4faa8f235112de1c0e624f331c4d7e1fca3b77e4..0ae5d3047c2a6d9a2eabfda5d16707cdd900d649 100644 (file)
@@ -1,3 +1,10 @@
+2020-09-08  Alex Coplan  <alex.coplan@arm.com>
+
+       * archures.c (bfd_mach_aarch64_8R): New.
+       * bfd-in2.h: Regenerate.
+       * cpu-aarch64.c (bfd_aarch64_arch_v8_r): New.
+       (bfd_aarch64_arch_ilp32): Update tail pointer.
+
 2020-09-08  Alan Modra  <amodra@gmail.com>
 
        PR 13250
index 969fa20873997a2c641c9cbd10d23d50b8319f0d..50698648d6a0c154329d00a9040137b3e8c66bab 100644 (file)
@@ -530,6 +530,7 @@ DESCRIPTION
 .#define bfd_mach_tilegx32     2
 .  bfd_arch_aarch64,   {* AArch64.  *}
 .#define bfd_mach_aarch64 0
+.#define bfd_mach_aarch64_8R   1
 .#define bfd_mach_aarch64_ilp32        32
 .  bfd_arch_nios2,     {* Nios II.  *}
 .#define bfd_mach_nios2                0
index 3c85b073013872dc2023e0f7b647b30eebd8dd83..2202cab43938e352a3b6ab85dddab1ca4be67776 100644 (file)
@@ -1930,6 +1930,7 @@ enum bfd_architecture
 #define bfd_mach_tilegx32      2
   bfd_arch_aarch64,   /* AArch64.  */
 #define bfd_mach_aarch64 0
+#define bfd_mach_aarch64_8R    1
 #define bfd_mach_aarch64_ilp32 32
   bfd_arch_nios2,     /* Nios II.  */
 #define bfd_mach_nios2         0
index b3df3faad9e2e4b9bbc05dfd3ec7104b2ac20d35..8d9b420a425c3806ee3b50bd47d20650397fbf1c 100644 (file)
@@ -107,8 +107,12 @@ scan (const struct bfd_arch_info *info, const char *string)
     "aarch64", PRINT, 4, DEFAULT, compatible, scan,            \
       bfd_arch_default_fill, NEXT, 0 }
 
+static const bfd_arch_info_type bfd_aarch64_arch_v8_r =
+  N (bfd_mach_aarch64_8R, "aarch64:armv8-r", 64, FALSE, NULL);
+
 static const bfd_arch_info_type bfd_aarch64_arch_ilp32 =
-  N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", 32, FALSE, NULL);
+  N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", 32, FALSE,
+     &bfd_aarch64_arch_v8_r);
 
 const bfd_arch_info_type bfd_aarch64_arch =
   N (0, "aarch64", 64, TRUE, &bfd_aarch64_arch_ilp32);
index 117f7e00a0c3eade450a26dd088df169f2caeca9..1c5929d90abdc25f1b879cbfda3473adcd46e51a 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-08  Alex Coplan  <alex.coplan@arm.com>
+
+       * config/tc-aarch64.c (aarch64_archs): Add armv8-r.
+       * doc/c-aarch64.texi: Document -march=armv8-r.
+
 2020-09-07  Mark Wielaard  <mark@klomp.org>
 
        * dwarf2dbg.c (add_line_strp): New function.
index db5edcb3dc3bde1349163ea70786b1d3c15ddd07..effa976980aa030d14a4dd6a08e2501c12a085f0 100644 (file)
@@ -8997,6 +8997,7 @@ static const struct aarch64_arch_option_table aarch64_archs[] = {
   {"armv8.4-a", AARCH64_ARCH_V8_4},
   {"armv8.5-a", AARCH64_ARCH_V8_5},
   {"armv8.6-a", AARCH64_ARCH_V8_6},
+  {"armv8-r",  AARCH64_ARCH_V8_R},
   {NULL, AARCH64_ARCH_NONE}
 };
 
index 86b6efc52bd42a1a4964f3270087ae87316263e1..89725a7e2f8abdbd6162f3d618627017dfd454c3 100644 (file)
@@ -100,7 +100,7 @@ issue an error message if an attempt is made to assemble an
 instruction which will not execute on the target architecture.  The
 following architecture names are recognized: @code{armv8-a},
 @code{armv8.1-a}, @code{armv8.2-a}, @code{armv8.3-a}, @code{armv8.4-a}
-@code{armv8.5-a}, and @code{armv8.6-a}.
+@code{armv8.5-a}, @code{armv8.6-a}, and @code{armv8-r}.
 
 If both @option{-mcpu} and @option{-march} are specified, the
 assembler will use the setting for @option{-mcpu}.  If neither are
index 62d88221a9cb2f404d2c98e0c9206040bc07f2ea..10a3c7d4ca5fb99e7e9252254e383dd6d83f79ac 100644 (file)
@@ -1,3 +1,10 @@
+2020-09-08  Alex Coplan  <alex.coplan@arm.com>
+
+       * opcode/aarch64.h (AARCH64_FEATURE_V8_A): New.
+       (AARCH64_FEATURE_V8_R): New.
+       (AARCH64_ARCH_V8): Include new A-profile feature bit.
+       (AARCH64_ARCH_V8_R): New.
+
 2020-09-02  Alan Modra  <amodra@gmail.com>
 
        * opcode/v850.h (struct v850_operand <insert>): Make param op an
index 5122ea85658f9f747ca6d6e0dd31fc2005b2d6eb..85f4fb5961ede7350564920a26ee652c4390500e 100644 (file)
@@ -40,6 +40,7 @@ typedef uint32_t aarch64_insn;
 #define AARCH64_FEATURE_V8          (1ULL << 0) /* All processors.  */
 #define AARCH64_FEATURE_V8_6        (1ULL << 1) /* ARMv8.6 processors.  */
 #define AARCH64_FEATURE_BFLOAT16     (1ULL << 2) /* Bfloat16 insns.  */
+#define AARCH64_FEATURE_V8_A        (1ULL << 3) /* Armv8-A processors.  */
 #define AARCH64_FEATURE_SVE2        (1ULL << 4) /* SVE2 instructions.  */
 #define AARCH64_FEATURE_V8_2        (1ULL << 5) /* ARMv8.2 processors.  */
 #define AARCH64_FEATURE_V8_3        (1ULL << 6) /* ARMv8.3 processors.  */
@@ -48,6 +49,7 @@ typedef uint32_t aarch64_insn;
 #define AARCH64_FEATURE_SVE2_SM4     (1ULL << 9)
 #define AARCH64_FEATURE_SVE2_SHA3    (1ULL << 10)
 #define AARCH64_FEATURE_V8_4        (1ULL << 11) /* ARMv8.4 processors.  */
+#define AARCH64_FEATURE_V8_R        (1ULL << 12) /* Armv8-R processors.  */
 #define AARCH64_FEATURE_FP          (1ULL << 17) /* FP instructions.  */
 #define AARCH64_FEATURE_SIMD        (1ULL << 18) /* SIMD instructions.  */
 #define AARCH64_FEATURE_CRC         (1ULL << 19) /* CRC instructions.  */
@@ -90,7 +92,8 @@ typedef uint32_t aarch64_insn;
 
 /* Architectures are the sum of the base and extensions.  */
 #define AARCH64_ARCH_V8                AARCH64_FEATURE (AARCH64_FEATURE_V8, \
-                                                AARCH64_FEATURE_FP  \
+                                                AARCH64_FEATURE_V8_A \
+                                                | AARCH64_FEATURE_FP  \
                                                 | AARCH64_FEATURE_SIMD)
 #define AARCH64_ARCH_V8_1      AARCH64_FEATURE (AARCH64_ARCH_V8, \
                                                 AARCH64_FEATURE_CRC    \
@@ -125,6 +128,9 @@ typedef uint32_t aarch64_insn;
                                                 AARCH64_FEATURE_V8_6   \
                                                 | AARCH64_FEATURE_BFLOAT16 \
                                                 | AARCH64_FEATURE_I8MM)
+#define AARCH64_ARCH_V8_R      (AARCH64_FEATURE (AARCH64_ARCH_V8_4,    \
+                                                AARCH64_FEATURE_V8_R)  \
+                             & ~(AARCH64_FEATURE_V8_A | AARCH64_FEATURE_LOR))
 
 #define AARCH64_ARCH_NONE      AARCH64_FEATURE (0, 0)
 #define AARCH64_ANY            AARCH64_FEATURE (-1, 0) /* Any basic core.  */
index 7740c888608e8fbfda014ad6c1f5a230165b7270..bbba2553020b7892894df19c36577e0f033be81e 100644 (file)
@@ -1,3 +1,11 @@
+2020-09-08  Alex Coplan  <alex.coplan@arm.com>
+
+       * aarch64-dis.c (arch_variant): New.
+       (determine_disassembling_preference): Disassemble according to
+       arch variant.
+       (select_aarch64_variant): New.
+       (print_insn_aarch64): Set feature set.
+
 2020-09-02  Alan Modra  <amodra@gmail.com>
 
        * v850-opc.c (insert_i5div1, insert_i5div2, insert_i5div3),
index 326fabb71687d18d911e1de0ac4b7495b01d832f..9d23b3154a2ab1978e837b856c911f92a17fd2e5 100644 (file)
@@ -35,6 +35,7 @@ enum map_type
   MAP_DATA
 };
 
+static aarch64_feature_set arch_variant; /* See select_aarch64_variant.  */
 static enum map_type last_type;
 static int last_mapping_sym = -1;
 static bfd_vma last_stop_offset = 0;
@@ -2690,6 +2691,13 @@ determine_disassembling_preference (struct aarch64_inst *inst,
          DEBUG_TRACE ("skip %s as base opcode not match", alias->name);
          continue;
        }
+
+      if (!AARCH64_CPU_HAS_FEATURE (arch_variant, *alias->avariant))
+       {
+         DEBUG_TRACE ("skip %s: we're missing features", alias->name);
+         continue;
+       }
+
       /* No need to do any complicated transformation on operands, if the alias
         opcode does not have any operand.  */
       if (aarch64_num_of_operands (alias) == 0 && alias->opcode == inst->value)
@@ -3360,6 +3368,24 @@ get_sym_code_type (struct disassemble_info *info, int n,
   return FALSE;
 }
 
+/* Set the feature bits in arch_variant in order to get the correct disassembly
+   for the chosen architecture variant.
+
+   Currently we only restrict disassembly for Armv8-R and otherwise enable all
+   non-R-profile features.  */
+static void
+select_aarch64_variant (unsigned mach)
+{
+  switch (mach)
+    {
+    case bfd_mach_aarch64_8R:
+      arch_variant = AARCH64_ARCH_V8_R;
+      break;
+    default:
+      arch_variant = AARCH64_ANY & ~(AARCH64_FEATURE_V8_R);
+    }
+}
+
 /* Entry-point of the AArch64 disassembler.  */
 
 int
@@ -3374,6 +3400,7 @@ print_insn_aarch64 (bfd_vma pc,
   unsigned int size = 4;
   unsigned long        data;
   aarch64_operand_error errors;
+  static bfd_boolean set_features;
 
   if (info->disassembler_options)
     {
@@ -3385,6 +3412,12 @@ print_insn_aarch64 (bfd_vma pc,
       info->disassembler_options = NULL;
     }
 
+  if (!set_features)
+    {
+      select_aarch64_variant (info->mach);
+      set_features = TRUE;
+    }
+
   /* Aarch64 instructions are always little-endian */
   info->endian_code = BFD_ENDIAN_LITTLE;