+2020-12-04 Luis Machado <luis.machado@linaro.org>
+
+ * aarch64-tdep.c (submask, bit, bits): Remove.
+ * arch/aarch64-insn.c (extract_signed_bitfield): Remove.
+ (aarch64_decode_adr, aarch64_decode_b aarch64_decode_bcond)
+ (aarch64_decode_cb, aarch64_decode_tb)
+ (aarch64_decode_ldr_literal): Use sbits to extract a signed
+ immediate.
+ * arch/aarch64-insn.h (submask, bits, bit, sbits): New macros.
+
2020-12-04 Tom de Vries <tdevries@suse.de>
PR tdep/27007
/* Toggle this file's internal debugging dump. */
bool aarch64_debug = false;
-/* Extract a signed value from a bit field within an instruction
- encoding.
-
- INSN is the instruction opcode.
-
- WIDTH specifies the width of the bit field to extract (in bits).
-
- OFFSET specifies the least significant bit of the field where bits
- are numbered zero counting from least to most significant. */
-
-static int32_t
-extract_signed_bitfield (uint32_t insn, unsigned width, unsigned offset)
-{
- unsigned shift_l = sizeof (int32_t) * 8 - (offset + width);
- unsigned shift_r = sizeof (int32_t) * 8 - width;
-
- return ((int32_t) insn << shift_l) >> shift_r;
-}
-
/* Determine if specified bits within an instruction opcode matches a
specific pattern.
if (decode_masked_match (insn, 0x1f000000, 0x10000000))
{
uint32_t immlo = (insn >> 29) & 0x3;
- int32_t immhi = extract_signed_bitfield (insn, 19, 5) << 2;
+ int32_t immhi = sbits (insn, 5, 23) * 4;
*is_adrp = (insn >> 31) & 0x1;
*rd = (insn >> 0) & 0x1f;
if (decode_masked_match (insn, 0x7c000000, 0x14000000))
{
*is_bl = (insn >> 31) & 0x1;
- *offset = extract_signed_bitfield (insn, 26, 0) << 2;
+ *offset = sbits (insn, 0, 25) * 4;
if (aarch64_debug)
{
if (decode_masked_match (insn, 0xff000010, 0x54000000))
{
*cond = (insn >> 0) & 0xf;
- *offset = extract_signed_bitfield (insn, 19, 5) << 2;
+ *offset = sbits (insn, 5, 23) * 4;
if (aarch64_debug)
{
*rn = (insn >> 0) & 0x1f;
*is64 = (insn >> 31) & 0x1;
*is_cbnz = (insn >> 24) & 0x1;
- *offset = extract_signed_bitfield (insn, 19, 5) << 2;
+ *offset = sbits (insn, 5, 23) * 4;
if (aarch64_debug)
{
*rt = (insn >> 0) & 0x1f;
*is_tbnz = (insn >> 24) & 0x1;
*bit = ((insn >> (31 - 4)) & 0x20) | ((insn >> 19) & 0x1f);
- *imm = extract_signed_bitfield (insn, 14, 5) << 2;
+ *imm = sbits (insn, 5, 18) * 4;
if (aarch64_debug)
{
*is64 = (insn >> 30) & 0x1;
*rt = (insn >> 0) & 0x1f;
- *offset = extract_signed_bitfield (insn, 19, 5) << 2;
+ *offset = sbits (insn, 5, 23) * 4;
if (aarch64_debug)
debug_printf ("decode: %s 0x%x %s %s%u, #?\n",
extern bool aarch64_debug;
+/* Support routines for instruction parsing. */
+
+/* Create a mask of X bits. */
+#define submask(x) ((1L << ((x) + 1)) - 1)
+
+/* Extract the bitfield from OBJ starting at bit ST and ending at bit FN. */
+#define bits(obj,st,fn) (((obj) >> (st)) & submask ((fn) - (st)))
+
+/* Extract bit ST from OBJ. */
+#define bit(obj,st) (((obj) >> (st)) & 1)
+
+/* Extract the signed bitfield from OBJ starting at bit ST and ending at
+ bit FN. The result is sign-extended. */
+#define sbits(obj,st,fn) \
+ ((long) (bits(obj,st,fn) | ((long) bit(obj,fn) * ~ submask (fn - st))))
+
/* List of opcodes that we need for building the jump pad and relocating
an instruction. */