Sign-extend PC-relative branch target.
authorTaylor R Campbell <campbell@mumble.net>
Mon, 21 Jan 2019 23:37:32 +0000 (23:37 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Wed, 21 Aug 2019 21:34:05 +0000 (21:34 +0000)
src/microcode/cmpintmd/aarch64.c

index 454a3f0394dad1565053081dbf9883831627b27f..711eae798d90582b44225c38ed9a569a7676348c 100644 (file)
@@ -85,12 +85,19 @@ write_cc_entry_offset (cc_entry_offset_t * ceo, insn_t * address)
   return (false);
 }
 
+static long
+sign_extend(long word, unsigned bits)
+{
+  const long magic = (1L << (bits - 1));
+  return ((word ^ magic) - magic);
+}
+
 insn_t *
 cc_return_address_to_entry_address (insn_t * pc)
 {
   insn_t insn = (pc[0]);
   if ((insn & 0xfc000000UL) == 0x14000000UL) /* B */
-    return (pc + (insn & 0x03ffffff));
+    return (pc + (sign_extend ((insn & 0x03ffffff), 26)));
   else
     /* XXX What if it got branch-tensioned?  */
     return (pc);