217a9d
diff -rup binutils.orig/gas/config/tc-aarch64.c binutils-2.30/gas/config/tc-aarch64.c
217a9d
--- binutils.orig/gas/config/tc-aarch64.c	2022-04-05 10:30:32.735881142 +0100
217a9d
+++ binutils-2.30/gas/config/tc-aarch64.c	2022-04-05 10:31:28.198694747 +0100
217a9d
@@ -8553,6 +8553,8 @@ static const struct aarch64_option_cpu_v
217a9d
   {"sha3",		AARCH64_FEATURE (AARCH64_FEATURE_SHA2
217a9d
 					 | AARCH64_FEATURE_SHA3, 0),
217a9d
 			AARCH64_ARCH_NONE},
217a9d
+  {"rng",               AARCH64_FEATURE (AARCH64_FEATURE_RNG, 0),
217a9d
+                        AARCH64_ARCH_NONE},
217a9d
   {NULL,		AARCH64_ARCH_NONE, AARCH64_ARCH_NONE},
217a9d
 };
217a9d
 
217a9d
diff -rup binutils.orig/gas/doc/c-aarch64.texi binutils-2.30/gas/doc/c-aarch64.texi
217a9d
--- binutils.orig/gas/doc/c-aarch64.texi	2022-04-05 10:30:32.735881142 +0100
217a9d
+++ binutils-2.30/gas/doc/c-aarch64.texi	2022-04-05 10:32:35.814423321 +0100
217a9d
@@ -179,6 +179,8 @@ automatically cause those extensions to
217a9d
 @item @code{fp16fml} @tab ARMv8.2-A @tab ARMv8.4-A or later
217a9d
  @tab Enable ARMv8.2 16-bit floating-point multiplication variant support.
217a9d
  This implies @code{fp16}.
217a9d
+@item @code{rng} @tab ARMv8.5-A @tab No
217a9d
+ @tab Enable ARMv8.5-A random number instructions.
217a9d
 @end multitable
217a9d
 
217a9d
 @node AArch64 Syntax
217a9d
Only in binutils-2.30/gas/testsuite/gas/aarch64: rng-1.d
217a9d
Only in binutils-2.30/gas/testsuite/gas/aarch64: rng-1.s
217a9d
diff -rup binutils.orig/include/opcode/aarch64.h binutils-2.30/include/opcode/aarch64.h
217a9d
--- binutils.orig/include/opcode/aarch64.h	2022-04-05 10:30:33.256879707 +0100
217a9d
+++ binutils-2.30/include/opcode/aarch64.h	2022-04-05 10:42:30.241087320 +0100
217a9d
@@ -62,6 +62,7 @@ typedef uint32_t aarch64_insn;
217a9d
 #define AARCH64_FEATURE_COMPNUM	0x40000000	/* Complex # instructions.  */
217a9d
 #define AARCH64_FEATURE_DOTPROD 0x080000000     /* Dot Product instructions.  */
217a9d
 #define AARCH64_FEATURE_F16_FML	0x1000000000ULL	/* v8.2 FP16FML ins.  */
217a9d
+#define AARCH64_FEATURE_RNG     0x80000000000ULL /* Random Number instructions.  */
217a9d
 
217a9d
 /* Architectures are the sum of the base and extensions.  */
217a9d
 #define AARCH64_ARCH_V8		AARCH64_FEATURE (AARCH64_FEATURE_V8, \
217a9d
diff -rup binutils.orig/opcodes/aarch64-opc.c binutils-2.30/opcodes/aarch64-opc.c
217a9d
--- binutils.orig/opcodes/aarch64-opc.c	2022-04-05 10:30:33.019880360 +0100
217a9d
+++ binutils-2.30/opcodes/aarch64-opc.c	2022-04-05 10:58:07.179526356 +0100
217a9d
@@ -3823,6 +3823,8 @@ const aarch64_sys_reg aarch64_sys_regs [
217a9d
   { "contextidr_el1",   CPENC(3,0,C13,C0,1),	0 },
217a9d
   { "contextidr_el2",	CPENC (3, 4, C13, C0, 1), F_ARCHEXT },
217a9d
   { "contextidr_el12",	CPENC (3, 5, C13, C0, 1), F_ARCHEXT },
217a9d
+  { "rndr",             CPENC(3,3,C2,C4,0),       F_ARCHEXT }, /* RO */
217a9d
+  { "rndrrs",           CPENC(3,3,C2,C4,1),       F_ARCHEXT }, /* RO */
217a9d
   { "tpidr_el0",        CPENC(3,3,C13,C0,2),	0 },
217a9d
   { "tpidrro_el0",      CPENC(3,3,C13,C0,3),	0 }, /* RO */
217a9d
   { "tpidr_el1",        CPENC(3,0,C13,C0,4),	0 },
217a9d
@@ -4254,6 +4256,13 @@ aarch64_sys_reg_supported_p (const aarch
217a9d
       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_4))
217a9d
     return FALSE;
217a9d
 
217a9d
+  /* Random Number Instructions.  For now they are available
217a9d
+     (and optional) only with ARMv8.5-A.  */
217a9d
+  if ((   reg->value == CPENC (3, 3, C2, C4, 0)
217a9d
+       || reg->value == CPENC (3, 3, C2, C4, 1))
217a9d
+      && !(AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_RNG)))
217a9d
+    return FALSE;
217a9d
+
217a9d
   return TRUE;
217a9d
 }
217a9d
 
217a9d
--- /dev/null	2022-04-05 09:32:54.900867346 +0100
217a9d
+++ binutils-2.30/gas/testsuite/gas/aarch64/rng-1.s	2022-04-05 10:36:04.921589937 +0100
217a9d
@@ -0,0 +1,3 @@
217a9d
+	.arch armv8.4-a+rng
217a9d
+	mrs x5, rndr
217a9d
+	mrs x6, rndrrs
217a9d
--- /dev/null	2022-04-05 09:32:54.900867346 +0100
217a9d
+++ binutils-2.30/gas/testsuite/gas/aarch64/rng-1.d	2022-04-05 10:35:48.937653638 +0100
217a9d
@@ -0,0 +1,10 @@
217a9d
+#source: rng-1.s
217a9d
+#objdump: -dr
217a9d
+
217a9d
+.*:     file format .*
217a9d
+
217a9d
+Disassembly of section \.text:
217a9d
+
217a9d
+0+ <.*>:
217a9d
+.*:	d53b2405 	mrs	x5, rndr
217a9d
+.*:	d53b2426 	mrs	x6, rndrrs