Skip to content

Commit 5517af8

Browse files
author
Victor Do Nascimento
committed
aarch64: Apply narrowing of allowed immediate values for SYSP
While CRn and CRm fields in the SYSP instruction are 4-bit wide and are thus able to accommodate values in the range 0-15, the specifications for the SYSP instructions limit their ranges to 8-9 for CRm and 0-7 in the case of CRn. This led to the need to signal in some way to the operand parser that a given operand is under special restrictions regarding its use. This is done via the new `F_OPD_NARROW' flag, indicating a narrowing in the range of operand values for fields in the instruction tagged with the flag. The flag is then used in `parse_operands' when the instruction is assembled, but needs not be taken into consideration during disassembly.
1 parent 3521a28 commit 5517af8

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

gas/config/tc-aarch64.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6474,6 +6474,7 @@ parse_operands (char *str, const aarch64_opcode *opcode)
64746474
int i;
64756475
char *backtrack_pos = 0;
64766476
const enum aarch64_opnd *operands = opcode->operands;
6477+
const uint64_t flags = opcode->flags;
64776478
aarch64_reg_type imm_reg_type;
64786479

64796480
clear_error ();
@@ -6822,7 +6823,22 @@ parse_operands (char *str, const aarch64_opcode *opcode)
68226823
goto failure;
68236824

68246825
po_imm_nc_or_fail ();
6825-
if (val > 15)
6826+
if (flags & F_OPD_NARROW)
6827+
{
6828+
if ((operands[i] == AARCH64_OPND_CRn)
6829+
&& (val < 8 || val > 9))
6830+
{
6831+
set_fatal_syntax_error (_(N_ ("C8 - C9 expected")));
6832+
goto failure;
6833+
}
6834+
else if ((operands[i] == AARCH64_OPND_CRm)
6835+
&& (val > 7))
6836+
{
6837+
set_fatal_syntax_error (_(N_ ("C0 - C7 expected")));
6838+
goto failure;
6839+
}
6840+
}
6841+
else if (val > 15)
68266842
{
68276843
set_fatal_syntax_error (_(N_ ("C0 - C15 expected")));
68286844
goto failure;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#name: Out-of-bounds SYSP operand tests
2+
#source: illegal-sys128.s
3+
#error_output: illegal-sys128.l

gas/testsuite/gas/aarch64/sysp.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#objdump: -dr
2+
3+
.*
4+
5+
6+
Disassembly of section \.text:
7+
8+
0+ <\.text>:
9+
[^:]*: d5488000 sysp #0, C8, C0, #0, x0, x1
10+
[^:]*: d54e97fa sysp #6, C9, C7, #7, x26, x27

gas/testsuite/gas/aarch64/sysp.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.arch armv9.4-a+d128
2+
3+
sysp #0, C8, C0, #0, x0, x1
4+
sysp #6, C9, C7, #7, x26, x27

include/opcode/aarch64.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,12 @@ extern const aarch64_opcode aarch64_opcode_table[];
12241224
to be optional, then we also implicitly specify (N+1)th operand to also be
12251225
optional. */
12261226
#define F_OPD_PAIR_OPT (1ULL << 32)
1227-
/* Next bit is 33. */
1227+
/* This instruction does not allow the full range of values that the
1228+
width of fields in the assembler instruction would theoretically
1229+
allow. This impacts the constraintts on assembly but yelds no
1230+
impact on disassembly. */
1231+
#define F_OPD_NARROW (1ULL << 33)
1232+
/* Next bit is 34. */
12281233

12291234
/* Instruction constraints. */
12301235
/* This instruction has a predication constraint on the instruction at PC+4. */

opcodes/aarch64-tbl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4201,7 +4201,7 @@ const struct aarch64_opcode aarch64_opcode_table[] =
42014201
GCS_INSN ("gcssttr", 0xd91f1c00, 0xfffffc00, OP2 (Rt, Rn_SP), QL_I2SAMEX, 0),
42024202
CORE_INSN ("gcsb", 0xd503227f, 0xffffffff, ic_system, 0, OP1 (BARRIER_GCSB), {}, F_ALIAS),
42034203
CORE_INSN ("sys", 0xd5080000, 0xfff80000, ic_system, 0, OP5 (UIMM3_OP1, CRn, CRm, UIMM3_OP2, Rt), QL_SYS, F_HAS_ALIAS | F_OPD4_OPT | F_DEFAULT (0x1F)),
4204-
D128_INSN ("sysp", 0xd5480000, 0xfff80000, OP6 (UIMM3_OP1, CRn, CRm, UIMM3_OP2, Rt, PAIRREG_OR_XZR), QL_SYSP, F_HAS_ALIAS | F_OPD4_OPT | F_OPD_PAIR_OPT | F_DEFAULT (0x1f)),
4204+
D128_INSN ("sysp", 0xd5480000, 0xfff80000, OP6 (UIMM3_OP1, CRn, CRm, UIMM3_OP2, Rt, PAIRREG_OR_XZR), QL_SYSP, F_HAS_ALIAS | F_OPD_NARROW | F_OPD4_OPT | F_OPD_PAIR_OPT | F_DEFAULT (0x1f)),
42054205
CORE_INSN ("at", 0xd5080000, 0xfff80000, ic_system, 0, OP2 (SYSREG_AT, Rt), QL_SRC_X, F_ALIAS),
42064206
CORE_INSN ("dc", 0xd5080000, 0xfff80000, ic_system, 0, OP2 (SYSREG_DC, Rt), QL_SRC_X, F_ALIAS),
42074207
CORE_INSN ("ic", 0xd5080000, 0xfff80000, ic_system, 0, OP2 (SYSREG_IC, Rt_SYS), QL_SRC_X, F_ALIAS | F_OPD1_OPT | F_DEFAULT (0x1F)),

0 commit comments

Comments
 (0)