From 4c03e84542a03bf1eb8ebdfd4decd92ffb1d4e72 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 21 Jan 2019 23:37:32 +0000 Subject: [PATCH] Sign-extend PC-relative branch target. --- src/microcode/cmpintmd/aarch64.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/microcode/cmpintmd/aarch64.c b/src/microcode/cmpintmd/aarch64.c index 454a3f039..711eae798 100644 --- a/src/microcode/cmpintmd/aarch64.c +++ b/src/microcode/cmpintmd/aarch64.c @@ -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); -- 2.25.1