# HG changeset patch # User Michael Pavone # Date 1419651401 28800 # Node ID 8c7b63f9fab810da055a80652b4e216b9aa40dcd # Parent 452ad0b42afa80cf0e608d5c8807d0f633517803 Fix reg-indirect mode for RBP/R13 diff -r 452ad0b42afa -r 8c7b63f9fab8 gen_x86.c --- a/gen_x86.c Fri Dec 26 15:46:53 2014 -0800 +++ b/gen_x86.c Fri Dec 26 19:36:41 2014 -0800 @@ -322,10 +322,17 @@ opcode |= BIT_SIZE; } *(out++) = opcode | dir; - *(out++) = MODE_REG_INDIRECT | base | (reg << 3); - if (base == RSP) { - //add SIB byte, with no index and RSP as base - *(out++) = (RSP << 3) | RSP; + if (base == RBP) { + //add a dummy 8-bit displacement since MODE_REG_INDIRECT with + //an R/M field of RBP selects RIP, relative addressing + *(out++) = MODE_REG_DISPLACE8 | base | (reg << 3); + *(out++) = 0; + } else { + *(out++) = MODE_REG_INDIRECT | base | (reg << 3); + if (base == RSP) { + //add SIB byte, with no index and RSP as base + *(out++) = (RSP << 3) | RSP; + } } code->cur = out; }