Commit 2bc5a212 authored by Ilija.Pavlovic's avatar Ilija.Pavlovic Committed by Commit bot

MIPS:

Improved checking target ranges for J and JAL instructions.
Adapted disassembler test for J and JAL instructions.

TEST=cctest/test-disasm-mips[64]
BUG=

Review URL: https://codereview.chromium.org/1237083003

Cr-Commit-Position: refs/heads/master@{#29693}
parent 49e54a02
......@@ -1406,11 +1406,11 @@ void Assembler::j(int32_t target) {
#if DEBUG
// Get pc of delay slot.
uint32_t ipc = reinterpret_cast<uint32_t>(pc_ + 1 * kInstrSize);
bool in_range = (ipc ^ static_cast<uint32_t>(target) >>
(kImm26Bits + kImmFieldShift)) == 0;
bool in_range = ((ipc ^ static_cast<uint32_t>(target)) >>
(kImm26Bits + kImmFieldShift)) == 0;
DCHECK(in_range && ((target & 3) == 0));
#endif
GenInstrJump(J, target >> 2);
GenInstrJump(J, (target >> 2) & kImm26Mask);
}
......@@ -1432,12 +1432,12 @@ void Assembler::jal(int32_t target) {
#ifdef DEBUG
// Get pc of delay slot.
uint32_t ipc = reinterpret_cast<uint32_t>(pc_ + 1 * kInstrSize);
bool in_range = (ipc ^ static_cast<uint32_t>(target) >>
(kImm26Bits + kImmFieldShift)) == 0;
bool in_range = ((ipc ^ static_cast<uint32_t>(target)) >>
(kImm26Bits + kImmFieldShift)) == 0;
DCHECK(in_range && ((target & 3) == 0));
#endif
positions_recorder()->WriteRecordedPositions();
GenInstrJump(JAL, target >> 2);
GenInstrJump(JAL, (target >> 2) & kImm26Mask);
}
......
......@@ -121,16 +121,25 @@ if (failure) { \
int pc_offset = assm.pc_offset(); \
byte *progcounter = &buffer[pc_offset]; \
char str_with_address[100]; \
int instr_index = target >> 2; \
snprintf(str_with_address, sizeof(str_with_address), "%s -> %p", \
compare_string, reinterpret_cast<byte *>( \
((uint32_t)(progcounter + 1) & ~0xfffffff) | \
int instr_index = (target >> 2) & kImm26Mask; \
snprintf( \
str_with_address, sizeof(str_with_address), "%s %p -> %p", \
compare_string, reinterpret_cast<byte *>(target), \
reinterpret_cast<byte *>(((uint32_t)(progcounter + 4) & ~0xfffffff) | \
(instr_index << 2))); \
assm.asm_; \
if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
}
#define GET_PC_REGION(pc_region) \
{ \
int pc_offset = assm.pc_offset(); \
byte *progcounter = &buffer[pc_offset]; \
pc_region = reinterpret_cast<int32_t>(progcounter + 4) & ~0xfffffff; \
}
TEST(Type0) {
SET_UP();
......@@ -466,12 +475,18 @@ TEST(Type0) {
COMPARE_PC_REL_COMPACT(bgtz(a0, 32767), "1c807fff bgtz a0, 32767",
32767);
COMPARE_PC_JUMP(j(0x4), "08000001 j 0x4", 0x4);
COMPARE_PC_JUMP(j(0xffffffc), "0bffffff j 0xffffffc", 0xffffffc);
int32_t pc_region;
GET_PC_REGION(pc_region);
int32_t target = pc_region | 0x4;
COMPARE_PC_JUMP(j(target), "08000001 j ", target);
target = pc_region | 0xffffffc;
COMPARE_PC_JUMP(j(target), "0bffffff j ", target);
COMPARE_PC_JUMP(jal(0x4), "0c000001 jal 0x4", 0x4);
COMPARE_PC_JUMP(jal(0xffffffc), "0fffffff jal 0xffffffc",
0xffffffc);
target = pc_region | 0x4;
COMPARE_PC_JUMP(jal(target), "0c000001 jal ", target);
target = pc_region | 0xffffffc;
COMPARE_PC_JUMP(jal(target), "0fffffff jal ", target);
COMPARE(addiu(a0, a1, 0x0),
"24a40000 addiu a0, a1, 0");
......
......@@ -121,16 +121,25 @@ if (failure) { \
int pc_offset = assm.pc_offset(); \
byte *progcounter = &buffer[pc_offset]; \
char str_with_address[100]; \
int instr_index = target >> 2; \
snprintf(str_with_address, sizeof(str_with_address), "%s -> %p", \
compare_string, reinterpret_cast<byte *>( \
((uint64_t)(progcounter + 1) & ~0xfffffff) | \
int instr_index = (target >> 2) & kImm26Mask; \
snprintf( \
str_with_address, sizeof(str_with_address), "%s %p -> %p", \
compare_string, reinterpret_cast<byte *>(target), \
reinterpret_cast<byte *>(((uint64_t)(progcounter + 1) & ~0xfffffff) | \
(instr_index << 2))); \
assm.asm_; \
if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
}
#define GET_PC_REGION(pc_region) \
{ \
int pc_offset = assm.pc_offset(); \
byte *progcounter = &buffer[pc_offset]; \
pc_region = reinterpret_cast<int64_t>(progcounter + 4) & ~0xfffffff; \
}
TEST(Type0) {
SET_UP();
......@@ -1114,12 +1123,18 @@ TEST(Type3) {
COMPARE_PC_REL_COMPACT(bgtz(a0, 32767), "1c807fff bgtz a0, 32767",
32767);
COMPARE_PC_JUMP(j(0x4), "08000001 j 0x4", 0x4);
COMPARE_PC_JUMP(j(0xffffffc), "0bffffff j 0xffffffc", 0xffffffc);
int64_t pc_region;
GET_PC_REGION(pc_region);
int64_t target = pc_region | 0x4;
COMPARE_PC_JUMP(j(target), "08000001 j ", target);
target = pc_region | 0xffffffc;
COMPARE_PC_JUMP(j(target), "0bffffff j ", target);
COMPARE_PC_JUMP(jal(0x4), "0c000001 jal 0x4", 0x4);
COMPARE_PC_JUMP(jal(0xffffffc), "0fffffff jal 0xffffffc",
0xffffffc);
target = pc_region | 0x4;
COMPARE_PC_JUMP(jal(target), "0c000001 jal ", target);
target = pc_region | 0xffffffc;
COMPARE_PC_JUMP(jal(target), "0fffffff jal ", target);
VERIFY_RUN();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment