[PATCH 06/28] aarch64: Fix incorrect opcode masks

Alice Carlotti alice.carlotti@arm.com
Wed Nov 4 18:42:42 GMT 2026


The masks for ldp/stp (offset) and stllrh were too lax.  Fixing them
does not change decode behaviour, because earlier opcode table entries
have priority, and these extra encodings are already decoded as
ldnp/stnp and stllrb respectively.


diff --git a/opcodes/aarch64-dis-2.c b/opcodes/aarch64-dis-2.c
index b1d1b92b5e27ab3c3416e49fc0c1c3dfd7cd3871..2930749291ffca977b9dbfb7f7dcec9ad99f49db 100644
--- a/opcodes/aarch64-dis-2.c
+++ b/opcodes/aarch64-dis-2.c
@@ -8086,13 +8086,13 @@ aarch64_opcode_lookup_1 (uint32_t word)
                     {
                       if (((word >> 23) & 0x1) == 0)
                         {
-                          if (((word >> 29) & 0x1) == 0)
+                          if (((word >> 24) & 0x1) == 0)
                             {
-                              if (((word >> 15) & 0x1) == 0)
+                              if (((word >> 29) & 0x1) == 0)
                                 {
-                                  if (((word >> 21) & 0x1) == 0)
+                                  if (((word >> 15) & 0x1) == 0)
                                     {
-                                      if (((word >> 24) & 0x1) == 0)
+                                      if (((word >> 21) & 0x1) == 0)
                                         {
                                           if (((word >> 31) & 0x1) == 0)
                                             {
@@ -8121,35 +8121,25 @@ aarch64_opcode_lookup_1 (uint32_t word)
                                         }
                                       else
                                         {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             xx001001000xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_89007c00_sttxr_Rs_Rt_ADDR_SIMPLE;
+                                          if (((word >> 31) & 0x1) == 0)
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 0x001000001xxxxx0xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_08207c00_casp_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
+                                            }
+                                          else
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 1x001000001xxxxx0xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_88200000_stxp_Rs_Rt_Rt2_ADDR_SIMPLE;
+                                            }
                                         }
                                     }
                                   else
                                     {
-                                      if (((word >> 31) & 0x1) == 0)
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             0x00100x001xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_08207c00_casp_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
-                                        }
-                                      else
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             1x00100x001xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_88200000_stxp_Rs_Rt_Rt2_ADDR_SIMPLE;
-                                        }
-                                    }
-                                }
-                              else
-                                {
-                                  if (((word >> 21) & 0x1) == 0)
-                                    {
-                                      if (((word >> 24) & 0x1) == 0)
+                                      if (((word >> 21) & 0x1) == 0)
                                         {
                                           if (((word >> 31) & 0x1) == 0)
                                             {
@@ -8178,48 +8168,68 @@ aarch64_opcode_lookup_1 (uint32_t word)
                                         }
                                       else
                                         {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             xx001001000xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_8900fc00_stltxr_Rs_Rt_ADDR_SIMPLE;
+                                          if (((word >> 31) & 0x1) == 0)
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 0x001000001xxxxx1xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_0820fc00_caspl_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
+                                            }
+                                          else
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 1x001000001xxxxx1xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_88208000_stlxp_Rs_Rt_Rt2_ADDR_SIMPLE;
+                                            }
                                         }
                                     }
+                                }
+                              else
+                                {
+                                  if (((word >> 30) & 0x1) == 0)
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         x010100000xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_28000000_stnp_Rt_Rt2_ADDR_SIMM7;
+                                    }
                                   else
                                     {
-                                      if (((word >> 31) & 0x1) == 0)
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             0x00100x001xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_0820fc00_caspl_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
-                                        }
-                                      else
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             1x00100x001xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_88208000_stlxp_Rs_Rt_Rt2_ADDR_SIMPLE;
-                                        }
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         x110100000xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_e8000000_sttnp_Rt_Rt2_ADDR_SIMM7;
                                     }
                                 }
                             }
                           else
                             {
-                              if (((word >> 30) & 0x1) == 0)
+                              if (((word >> 29) & 0x1) == 0)
                                 {
-                                  /* 33222222222211111111110000000000
-                                     10987654321098765432109876543210
-                                     x010100x00xxxxxxxxxxxxxxxxxxxxxx.  */
-                                  return A64_OPID_28000000_stnp_Rt_Rt2_ADDR_SIMM7;
+                                  if (((word >> 15) & 0x1) == 0)
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         xx00100100xxxxxx0xxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_89007c00_sttxr_Rs_Rt_ADDR_SIMPLE;
+                                    }
+                                  else
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         xx00100100xxxxxx1xxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_8900fc00_stltxr_Rs_Rt_ADDR_SIMPLE;
+                                    }
                                 }
                               else
                                 {
-                                  if (((word >> 24) & 0x1) == 0)
+                                  if (((word >> 30) & 0x1) == 0)
                                     {
                                       /* 33222222222211111111110000000000
                                          10987654321098765432109876543210
-                                         x110100000xxxxxxxxxxxxxxxxxxxxxx.  */
-                                      return A64_OPID_e8000000_sttnp_Rt_Rt2_ADDR_SIMM7;
+                                         x010100100xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_29000000_stp_Rt_Rt2_ADDR_SIMM7;
                                     }
                                   else
                                     {
@@ -8253,10 +8263,20 @@ aarch64_opcode_lookup_1 (uint32_t word)
                                         {
                                           if (((word >> 31) & 0x1) == 0)
                                             {
-                                              /* 33222222222211111111110000000000
-                                                 10987654321098765432109876543210
-                                                 0x001000100xxxxx0xxxxxxxxxxxxxxx.  */
-                                              return A64_OPID_089f7c00_stllrb_Rt_ADDR_SIMPLE;
+                                              if (((word >> 30) & 0x1) == 0)
+                                                {
+                                                  /* 33222222222211111111110000000000
+                                                     10987654321098765432109876543210
+                                                     00001000100xxxxx0xxxxxxxxxxxxxxx.  */
+                                                  return A64_OPID_089f7c00_stllrb_Rt_ADDR_SIMPLE;
+                                                }
+                                              else
+                                                {
+                                                  /* 33222222222211111111110000000000
+                                                     10987654321098765432109876543210
+                                                     01001000100xxxxx0xxxxxxxxxxxxxxx.  */
+                                                  return A64_OPID_489f7c00_stllrh_Rt_ADDR_SIMPLE;
+                                                }
                                             }
                                           else
                                             {
@@ -8423,13 +8443,13 @@ aarch64_opcode_lookup_1 (uint32_t word)
                     {
                       if (((word >> 23) & 0x1) == 0)
                         {
-                          if (((word >> 29) & 0x1) == 0)
+                          if (((word >> 24) & 0x1) == 0)
                             {
-                              if (((word >> 15) & 0x1) == 0)
+                              if (((word >> 29) & 0x1) == 0)
                                 {
-                                  if (((word >> 21) & 0x1) == 0)
+                                  if (((word >> 15) & 0x1) == 0)
                                     {
-                                      if (((word >> 24) & 0x1) == 0)
+                                      if (((word >> 21) & 0x1) == 0)
                                         {
                                           if (((word >> 31) & 0x1) == 0)
                                             {
@@ -8458,35 +8478,25 @@ aarch64_opcode_lookup_1 (uint32_t word)
                                         }
                                       else
                                         {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             xx001001010xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_895f7c00_ldtxr_Rt_ADDR_SIMPLE;
+                                          if (((word >> 31) & 0x1) == 0)
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 0x001000011xxxxx0xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_08607c00_caspa_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
+                                            }
+                                          else
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 1x001000011xxxxx0xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_887f0000_ldxp_Rt_Rt2_ADDR_SIMPLE;
+                                            }
                                         }
                                     }
                                   else
                                     {
-                                      if (((word >> 31) & 0x1) == 0)
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             0x00100x011xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_08607c00_caspa_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
-                                        }
-                                      else
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             1x00100x011xxxxx0xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_887f0000_ldxp_Rt_Rt2_ADDR_SIMPLE;
-                                        }
-                                    }
-                                }
-                              else
-                                {
-                                  if (((word >> 21) & 0x1) == 0)
-                                    {
-                                      if (((word >> 24) & 0x1) == 0)
+                                      if (((word >> 21) & 0x1) == 0)
                                         {
                                           if (((word >> 31) & 0x1) == 0)
                                             {
@@ -8515,48 +8525,68 @@ aarch64_opcode_lookup_1 (uint32_t word)
                                         }
                                       else
                                         {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             xx001001010xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_895ffc00_ldatxr_Rt_ADDR_SIMPLE;
+                                          if (((word >> 31) & 0x1) == 0)
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 0x001000011xxxxx1xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_0860fc00_caspal_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
+                                            }
+                                          else
+                                            {
+                                              /* 33222222222211111111110000000000
+                                                 10987654321098765432109876543210
+                                                 1x001000011xxxxx1xxxxxxxxxxxxxxx.  */
+                                              return A64_OPID_887f8000_ldaxp_Rt_Rt2_ADDR_SIMPLE;
+                                            }
                                         }
                                     }
+                                }
+                              else
+                                {
+                                  if (((word >> 30) & 0x1) == 0)
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         x010100001xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_28400000_ldnp_Rt_Rt2_ADDR_SIMM7;
+                                    }
                                   else
                                     {
-                                      if (((word >> 31) & 0x1) == 0)
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             0x00100x011xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_0860fc00_caspal_Rs_PAIRREG_Rt_PAIRREG_ADDR_SIMPLE;
-                                        }
-                                      else
-                                        {
-                                          /* 33222222222211111111110000000000
-                                             10987654321098765432109876543210
-                                             1x00100x011xxxxx1xxxxxxxxxxxxxxx.  */
-                                          return A64_OPID_887f8000_ldaxp_Rt_Rt2_ADDR_SIMPLE;
-                                        }
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         x110100001xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_e8400000_ldtnp_Rt_Rt2_ADDR_SIMM7;
                                     }
                                 }
                             }
                           else
                             {
-                              if (((word >> 30) & 0x1) == 0)
+                              if (((word >> 29) & 0x1) == 0)
                                 {
-                                  /* 33222222222211111111110000000000
-                                     10987654321098765432109876543210
-                                     x010100x01xxxxxxxxxxxxxxxxxxxxxx.  */
-                                  return A64_OPID_28400000_ldnp_Rt_Rt2_ADDR_SIMM7;
+                                  if (((word >> 15) & 0x1) == 0)
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         xx00100101xxxxxx0xxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_895f7c00_ldtxr_Rt_ADDR_SIMPLE;
+                                    }
+                                  else
+                                    {
+                                      /* 33222222222211111111110000000000
+                                         10987654321098765432109876543210
+                                         xx00100101xxxxxx1xxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_895ffc00_ldatxr_Rt_ADDR_SIMPLE;
+                                    }
                                 }
                               else
                                 {
-                                  if (((word >> 24) & 0x1) == 0)
+                                  if (((word >> 30) & 0x1) == 0)
                                     {
                                       /* 33222222222211111111110000000000
                                          10987654321098765432109876543210
-                                         x110100001xxxxxxxxxxxxxxxxxxxxxx.  */
-                                      return A64_OPID_e8400000_ldtnp_Rt_Rt2_ADDR_SIMM7;
+                                         x010100101xxxxxxxxxxxxxxxxxxxxxx.  */
+                                      return A64_OPID_29400000_ldp_Rt_Rt2_ADDR_SIMM7;
                                     }
                                   else
                                     {
@@ -35850,21 +35880,6 @@ aarch64_find_next_opcode (const aarch64_opcode *opcode)
       break;
     case A64_OPID_c121e400_fmul_SME_Zdnx4_SME_Znx4_SME_Zmx4:
       return NULL;
-    case A64_OPID_28000000_stnp_Rt_Rt2_ADDR_SIMM7:
-      value = A64_OPID_29000000_stp_Rt_Rt2_ADDR_SIMM7;
-      break;
-    case A64_OPID_29000000_stp_Rt_Rt2_ADDR_SIMM7:
-      return NULL;
-    case A64_OPID_089f7c00_stllrb_Rt_ADDR_SIMPLE:
-      value = A64_OPID_489f7c00_stllrh_Rt_ADDR_SIMPLE;
-      break;
-    case A64_OPID_489f7c00_stllrh_Rt_ADDR_SIMPLE:
-      return NULL;
-    case A64_OPID_28400000_ldnp_Rt_Rt2_ADDR_SIMM7:
-      value = A64_OPID_29400000_ldp_Rt_Rt2_ADDR_SIMM7;
-      break;
-    case A64_OPID_29400000_ldp_Rt_Rt2_ADDR_SIMM7:
-      return NULL;
     case A64_OPID_f8a00800_prfm_PRFOP_ADDR_REGOFF:
       value = A64_OPID_f8a04818_rprfm_RPRFMOP_Rm_SIMD_ADDR_SIMPLE;
       break;
diff --git a/opcodes/aarch64-tbl.h b/opcodes/aarch64-tbl.h
index 0bd63922703c82e2c5c1e22cba49320f37d69cbf..93eb7c12f43bfac272fdd111cd9d4e18f900ae65 100644
--- a/opcodes/aarch64-tbl.h
+++ b/opcodes/aarch64-tbl.h
@@ -4848,7 +4848,7 @@ const struct aarch64_opcode aarch64_opcode_table[] =
   _LOR_INSN ("ldlarh", 0x48df7c00, 0xffe08000, ldstexcl, OP2 (Rt, ADDR_SIMPLE), QL_W1_LDST_EXC, 0),
   _LOR_INSN ("stllr",  0x889f7c00, 0xbfe08000, ldstexcl, OP2 (Rt, ADDR_SIMPLE), QL_R1NIL,       F_GPRSIZE_IN_Q),
   _LOR_INSN ("stllrb", 0x089f7c00, 0xffe08000, ldstexcl, OP2 (Rt, ADDR_SIMPLE), QL_W1_LDST_EXC, 0),
-  _LOR_INSN ("stllrh", 0x489f7c00, 0xbfe08000, ldstexcl, OP2 (Rt, ADDR_SIMPLE), QL_W1_LDST_EXC, 0),
+  _LOR_INSN ("stllrh", 0x489f7c00, 0xffe08000, ldstexcl, OP2 (Rt, ADDR_SIMPLE), QL_W1_LDST_EXC, 0),
   /* Load acquire and store release pair.  */
   _LSCP_INSN ("ldap", 0xd9405800, 0xffe0fc00, ldstpair_off, OP3 (Rt, Rs, ADDR_SIMPLE), QL_X2NIL, F_LDST_LOAD),
   _LSCP_INSN ("ldapp", 0xd9407800, 0xffe0fc00, ldstpair_off, OP3 (Rt, Rs, ADDR_SIMPLE), QL_X2NIL, F_LDST_LOAD),
@@ -4859,8 +4859,8 @@ const struct aarch64_opcode aarch64_opcode_table[] =
   CORE_INSN ("stnp", 0x2c000000, 0x3fc00000, ldstnapair_offs, 0, OP3 (Ft, Ft2, ADDR_SIMM7), QL_LDST_PAIR_FP, F_LDST_STORE),
   CORE_INSN ("ldnp", 0x2c400000, 0x3fc00000, ldstnapair_offs, 0, OP3 (Ft, Ft2, ADDR_SIMM7), QL_LDST_PAIR_FP, F_LDST_LOAD),
   /* Load/store register pair (offset).  */
-  CORE_INSN ("stp", 0x29000000, 0x7ec00000, ldstpair_off, 0, OP3 (Rt, Rt2, ADDR_SIMM7), QL_LDST_PAIR_R, F_LDST_STORE | F_SF),
-  CORE_INSN ("ldp", 0x29400000, 0x7ec00000, ldstpair_off, 0, OP3 (Rt, Rt2, ADDR_SIMM7), QL_LDST_PAIR_R, F_LDST_LOAD | F_SF),
+  CORE_INSN ("stp", 0x29000000, 0x7fc00000, ldstpair_off, 0, OP3 (Rt, Rt2, ADDR_SIMM7), QL_LDST_PAIR_R, F_LDST_STORE | F_SF),
+  CORE_INSN ("ldp", 0x29400000, 0x7fc00000, ldstpair_off, 0, OP3 (Rt, Rt2, ADDR_SIMM7), QL_LDST_PAIR_R, F_LDST_LOAD | F_SF),
   CORE_INSN ("stp", 0x2d000000, 0x3fc00000, ldstpair_off, 0, OP3 (Ft, Ft2, ADDR_SIMM7), QL_LDST_PAIR_FP, F_LDST_STORE | 0),
   CORE_INSN ("ldp", 0x2d400000, 0x3fc00000, ldstpair_off, 0, OP3 (Ft, Ft2, ADDR_SIMM7), QL_LDST_PAIR_FP, F_LDST_LOAD),
   {"ldpsw", 0x69400000, 0xffc00000, ldstpair_off, 0, CORE, OP3 (Rt, Rt2, ADDR_SIMM7), QL_LDST_PAIR_X32, F_SUBCLASS_OTHER, 0, 0, VERIFIER (ldpsw)},


More information about the Binutils mailing list