Skip to content

Commit 56e4ea2

Browse files
committed
[mips] Fix decoding of microMIPS JALX instruction
microMIPS jump and link exchange instruction stores a target in a 26-bits field. Despite other microMIPS JAL instructions these bits are target address shifted right 2 bits [1]. The patch fixes the JALX instruction decoding and uses 2-bit shift. [1] MIPS Architecture for Programmers Volume II-B: The microMIPS32 Instruction Set Differential Revision: https://reviews.llvm.org/D67320 llvm-svn: 371428
1 parent d2a9516 commit 56e4ea2

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

lld/test/ELF/mips-micro-cross-calls.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
# REG-NEXT: 20034: 08 00 80 11 j 131140 <bar>
2323

2424
# MICRO: micro:
25-
# MICRO-NEXT: 20010: f0 00 80 00 jalx 65536
25+
# MICRO-NEXT: 20010: f0 00 80 00 jalx 131072 <__start>
2626
# MICRO-NEXT: 20014: 00 00 00 00 nop
27-
# MICRO-NEXT: 20018: f0 00 80 0c jalx 65560
27+
# MICRO-NEXT: 20018: f0 00 80 0c jalx 131120 <__LA25Thunk_bar>
2828

2929
# MICRO: __microLA25Thunk_foo:
3030
# MICRO-NEXT: 20020: 41 b9 00 02 lui $25, 2

llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ static DecodeStatus DecodeJumpTargetMM(MCInst &Inst,
267267
uint64_t Address,
268268
const void *Decoder);
269269

270+
// DecodeJumpTargetXMM - Decode microMIPS jump and link exchange target,
271+
// which is shifted left by 2 bit.
272+
static DecodeStatus DecodeJumpTargetXMM(MCInst &Inst,
273+
unsigned Insn,
274+
uint64_t Address,
275+
const void *Decoder);
276+
270277
static DecodeStatus DecodeMem(MCInst &Inst,
271278
unsigned Insn,
272279
uint64_t Address,
@@ -2291,6 +2298,15 @@ static DecodeStatus DecodeJumpTargetMM(MCInst &Inst,
22912298
return MCDisassembler::Success;
22922299
}
22932300

2301+
static DecodeStatus DecodeJumpTargetXMM(MCInst &Inst,
2302+
unsigned Insn,
2303+
uint64_t Address,
2304+
const void *Decoder) {
2305+
unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2;
2306+
Inst.addOperand(MCOperand::createImm(JumpOffset));
2307+
return MCDisassembler::Success;
2308+
}
2309+
22942310
static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst,
22952311
unsigned Value,
22962312
uint64_t Address,

llvm/lib/Target/Mips/MicroMipsInstrInfo.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,17 +955,18 @@ let DecoderNamespace = "MicroMips" in {
955955
EXT_FM_MM<0x0c>, ISA_MICROMIPS32_NOT_MIPS32R6;
956956

957957
/// Jump Instructions
958-
let DecoderMethod = "DecodeJumpTargetMM" in
958+
let DecoderMethod = "DecodeJumpTargetMM" in {
959959
def J_MM : MMRel, JumpFJ<jmptarget_mm, "j", br, bb, "j">,
960960
J_FM_MM<0x35>, AdditionalRequires<[RelocNotPIC]>,
961961
IsBranch, ISA_MICROMIPS32_NOT_MIPS32R6;
962-
963-
let DecoderMethod = "DecodeJumpTargetMM" in {
964962
def JAL_MM : MMRel, JumpLink<"jal", calltarget_mm>, J_FM_MM<0x3d>,
965963
ISA_MICROMIPS32_NOT_MIPS32R6;
964+
}
965+
966+
let DecoderMethod = "DecodeJumpTargetXMM" in
966967
def JALX_MM : MMRel, JumpLink<"jalx", calltarget>, J_FM_MM<0x3c>,
967968
ISA_MICROMIPS32_NOT_MIPS32R6;
968-
}
969+
969970
def JR_MM : MMRel, IndirectBranch<"jr", GPR32Opnd>, JR_FM_MM<0x3c>,
970971
ISA_MICROMIPS32_NOT_MIPS32R6;
971972
def JALR_MM : JumpLinkReg<"jalr", GPR32Opnd>, JALR_FM_MM<0x03c>,

llvm/test/MC/Disassembler/Mips/micromips32r3/valid-el.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
0x00 0xd4 0x98 0x02 # CHECK: j 1328
138138
0x00 0xf4 0x98 0x02 # CHECK: jal 1328
139139
0xe6 0x03 0x3c 0x0f # CHECK: jalr $ra, $6
140+
0x10 0xf0 0x34 0x00 # CHECK: jalx 4194512
140141
0x07 0x00 0x3c 0x0f # CHECK: jr $7
141142
0xc9 0x94 0x9a 0x02 # CHECK: beq $9, $6, 1336
142143
0x46 0x40 0x9a 0x02 # CHECK: bgez $6, 1336

llvm/test/MC/Disassembler/Mips/micromips32r3/valid.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
0xd4 0x00 0x02 0x98 # CHECK: j 1328
138138
0xf4 0x00 0x02 0x98 # CHECK: jal 1328
139139
0x03 0xe6 0x0f 0x3c # CHECK: jalr $ra, $6
140+
0xf0 0x10 0x00 0x34 # CHECK: jalx 4194512
140141
0x00 0x07 0x0f 0x3c # CHECK: jr $7
141142
0x94 0xc9 0x02 0x9a # CHECK: beq $9, $6, 1336
142143
0x40 0x46 0x02 0x9a # CHECK: bgez $6, 1336

0 commit comments

Comments
 (0)