Print properly signed displacement in disassembler.

R=titzer@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19667 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ee8cbc4f
......@@ -407,10 +407,11 @@ int DisassemblerIA32::PrintRightOperandHelper(
return 2;
} else if (base == ebp) {
int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2);
AppendToBuffer("[%s*%d+0x%x]",
AppendToBuffer("[%s*%d%s0x%x]",
(this->*register_name)(index),
1 << scale,
disp);
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
return 6;
} else if (index != esp && base != ebp) {
// [base+index*scale]
......@@ -434,23 +435,26 @@ int DisassemblerIA32::PrintRightOperandHelper(
byte sib = *(modrmp + 1);
int scale, index, base;
get_sib(sib, &scale, &index, &base);
int disp =
mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 2) : *(modrmp + 2);
int disp = mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 2)
: *reinterpret_cast<int8_t*>(modrmp + 2);
if (index == base && index == rm /*esp*/ && scale == 0 /*times_1*/) {
AppendToBuffer("[%s+0x%x]", (this->*register_name)(rm), disp);
AppendToBuffer("[%s%s0x%x]",
(this->*register_name)(rm),
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
} else {
AppendToBuffer("[%s+%s*%d+0x%x]",
AppendToBuffer("[%s+%s*%d%s0x%x]",
(this->*register_name)(base),
(this->*register_name)(index),
1 << scale,
disp);
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
}
return mod == 2 ? 6 : 3;
} else {
// No sib.
int disp =
mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 1) :
*reinterpret_cast<int8_t*>(modrmp + 1);
int disp = mod == 2 ? *reinterpret_cast<int32_t*>(modrmp + 1)
: *reinterpret_cast<int8_t*>(modrmp + 1);
AppendToBuffer("[%s%s0x%x]",
(this->*register_name)(rm),
disp < 0 ? "-" : "+",
......
......@@ -485,9 +485,11 @@ int DisassemblerX64::PrintRightOperandHelper(
} else if (base == 5) {
// base == rbp means no base register (when mod == 0).
int32_t disp = *reinterpret_cast<int32_t*>(modrmp + 2);
AppendToBuffer("[%s*%d+0x%x]",
AppendToBuffer("[%s*%d%s0x%x]",
NameOfCPURegister(index),
1 << scale, disp);
1 << scale,
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
return 6;
} else if (index != 4 && base != 5) {
// [base+index*scale]
......@@ -512,38 +514,29 @@ int DisassemblerX64::PrintRightOperandHelper(
int scale, index, base;
get_sib(sib, &scale, &index, &base);
int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 2)
: *reinterpret_cast<char*>(modrmp + 2);
: *reinterpret_cast<int8_t*>(modrmp + 2);
if (index == 4 && (base & 7) == 4 && scale == 0 /*times_1*/) {
if (-disp > 0) {
AppendToBuffer("[%s-0x%x]", NameOfCPURegister(base), -disp);
} else {
AppendToBuffer("[%s+0x%x]", NameOfCPURegister(base), disp);
}
AppendToBuffer("[%s%s0x%x]",
NameOfCPURegister(base),
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
} else {
if (-disp > 0) {
AppendToBuffer("[%s+%s*%d-0x%x]",
NameOfCPURegister(base),
NameOfCPURegister(index),
1 << scale,
-disp);
} else {
AppendToBuffer("[%s+%s*%d+0x%x]",
NameOfCPURegister(base),
NameOfCPURegister(index),
1 << scale,
disp);
}
AppendToBuffer("[%s+%s*%d%s0x%x]",
NameOfCPURegister(base),
NameOfCPURegister(index),
1 << scale,
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
}
return mod == 2 ? 6 : 3;
} else {
// No sib.
int disp = (mod == 2) ? *reinterpret_cast<int32_t*>(modrmp + 1)
: *reinterpret_cast<char*>(modrmp + 1);
if (-disp > 0) {
AppendToBuffer("[%s-0x%x]", NameOfCPURegister(rm), -disp);
} else {
AppendToBuffer("[%s+0x%x]", NameOfCPURegister(rm), disp);
}
: *reinterpret_cast<int8_t*>(modrmp + 1);
AppendToBuffer("[%s%s0x%x]",
NameOfCPURegister(rm),
disp < 0 ? "-" : "+",
disp < 0 ? -disp : disp);
return (mod == 2) ? 5 : 2;
}
break;
......
......@@ -139,6 +139,7 @@
'test-code-stubs.cc',
'test-code-stubs-x64.cc',
'test-cpu-x64.cc',
'test-disasm-x64.cc',
'test-macro-assembler-x64.cc',
'test-log-stack-tracer.cc'
],
......
......@@ -28,13 +28,13 @@
#include <stdlib.h>
#include "v8.h"
#include "stub-cache.h"
#include "debug.h"
#include "disasm.h"
#include "disassembler.h"
#include "macro-assembler.h"
#include "serialize.h"
#include "stub-cache.h"
#include "cctest.h"
using namespace v8::internal;
......@@ -49,7 +49,7 @@ static void DummyStaticFunction(Object* result) {
TEST(DisasmIa320) {
CcTest::InitializeVM();
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
v8::internal::byte buffer[2048];
Assembler assm(isolate, buffer, sizeof buffer);
......@@ -74,12 +74,23 @@ TEST(DisasmIa320) {
__ add(edx, Operand(ebx, 0));
__ add(edx, Operand(ebx, 16));
__ add(edx, Operand(ebx, 1999));
__ add(edx, Operand(ebx, -4));
__ add(edx, Operand(ebx, -1999));
__ add(edx, Operand(esp, 0));
__ add(edx, Operand(esp, 16));
__ add(edx, Operand(esp, 1999));
__ add(edx, Operand(esp, -4));
__ add(edx, Operand(esp, -1999));
__ nop();
__ add(esi, Operand(ecx, times_4, 0));
__ add(esi, Operand(ecx, times_4, 24));
__ add(esi, Operand(ecx, times_4, -4));
__ add(esi, Operand(ecx, times_4, -1999));
__ nop();
__ add(edi, Operand(ebp, ecx, times_4, 0));
__ add(edi, Operand(ebp, ecx, times_4, 12));
__ add(edi, Operand(ebp, ecx, times_4, -8));
__ add(edi, Operand(ebp, ecx, times_4, -3999));
__ add(Operand(ebp, ecx, times_4, 12), Immediate(12));
__ nop();
......
......@@ -34,6 +34,7 @@
#include "disassembler.h"
#include "macro-assembler.h"
#include "serialize.h"
#include "stub-cache.h"
#include "cctest.h"
using namespace v8::internal;
......@@ -48,9 +49,10 @@ static void DummyStaticFunction(Object* result) {
TEST(DisasmX64) {
CcTest::InitializeVM();
v8::HandleScope scope;
Isolate* isolate = CcTest::i_isolate();
HandleScope scope(isolate);
v8::internal::byte buffer[2048];
Assembler assm(CcTest::i_isolate(), buffer, sizeof buffer);
Assembler assm(isolate, buffer, sizeof buffer);
DummyStaticFunction(NULL); // just bloody use it (DELETE; debugging)
// Short immediate instructions
......@@ -68,12 +70,23 @@ TEST(DisasmX64) {
__ addq(rdx, Operand(rbx, 0));
__ addq(rdx, Operand(rbx, 16));
__ addq(rdx, Operand(rbx, 1999));
__ addq(rdx, Operand(rbx, -4));
__ addq(rdx, Operand(rbx, -1999));
__ addq(rdx, Operand(rsp, 0));
__ addq(rdx, Operand(rsp, 16));
__ addq(rdx, Operand(rsp, 1999));
__ addq(rdx, Operand(rsp, -4));
__ addq(rdx, Operand(rsp, -1999));
__ nop();
__ addq(rsi, Operand(rcx, times_4, 0));
__ addq(rsi, Operand(rcx, times_4, 24));
__ addq(rsi, Operand(rcx, times_4, -4));
__ addq(rsi, Operand(rcx, times_4, -1999));
__ nop();
__ addq(rdi, Operand(rbp, rcx, times_4, 0));
__ addq(rdi, Operand(rbp, rcx, times_4, 12));
__ addq(rdi, Operand(rbp, rcx, times_4, -8));
__ addq(rdi, Operand(rbp, rcx, times_4, -3999));
__ addq(Operand(rbp, rcx, times_4, 12), Immediate(12));
__ nop();
......@@ -157,7 +170,8 @@ TEST(DisasmX64) {
__ incq(Operand(rbx, rcx, times_4, 10000));
__ push(Operand(rbx, rcx, times_4, 10000));
__ pop(Operand(rbx, rcx, times_4, 10000));
__ jmp(Operand(rbx, rcx, times_4, 10000));
// TODO(mstarzinger): The following is protected.
// __ jmp(Operand(rbx, rcx, times_4, 10000));
__ lea(rdx, Operand(rbx, rcx, times_4, 10000));
__ or_(rdx, Immediate(12345));
......@@ -233,20 +247,20 @@ TEST(DisasmX64) {
__ call(&L2);
__ nop();
__ bind(&L2);
__ call(Operand(rbx, rcx, times_4, 10000));
// TODO(mstarzinger): The following is protected.
// __ call(Operand(rbx, rcx, times_4, 10000));
__ nop();
Handle<Code> ic(CcTest::i_isolate()->builtins()->builtin(
Builtins::kLoadIC_Initialize));
Handle<Code> ic(LoadIC::initialize_stub(isolate, NOT_CONTEXTUAL));
__ call(ic, RelocInfo::CODE_TARGET);
__ nop();
__ nop();
__ jmp(&L1);
__ jmp(Operand(rbx, rcx, times_4, 10000));
// TODO(mstarzinger): The following is protected.
// __ jmp(Operand(rbx, rcx, times_4, 10000));
#ifdef ENABLE_DEBUGGER_SUPPORT
ExternalReference after_break_target =
ExternalReference(Debug_Address::AfterBreakTarget(),
assm.isolate());
ExternalReference(Debug_Address::AfterBreakTarget(), isolate);
USE(after_break_target);
#endif // ENABLE_DEBUGGER_SUPPORT
__ jmp(ic, RelocInfo::CODE_TARGET);
......@@ -345,9 +359,9 @@ TEST(DisasmX64) {
__ andps(xmm0, xmm1);
__ andps(xmm0, Operand(rbx, rcx, times_4, 10000));
__ orps(xmm0, xmm1);
__ ordps(xmm0, Operand(rbx, rcx, times_4, 10000));
__ orps(xmm0, Operand(rbx, rcx, times_4, 10000));
__ xorps(xmm0, xmm1);
__ xordps(xmm0, Operand(rbx, rcx, times_4, 10000));
__ xorps(xmm0, Operand(rbx, rcx, times_4, 10000));
// Arithmetic operation
__ addps(xmm1, xmm0);
......@@ -355,7 +369,7 @@ TEST(DisasmX64) {
__ subps(xmm1, xmm0);
__ subps(xmm1, Operand(rbx, rcx, times_4, 10000));
__ mulps(xmm1, xmm0);
__ mulps(xmm1, Operand(rbx, ecx, times_4, 10000));
__ mulps(xmm1, Operand(rbx, rcx, times_4, 10000));
__ divps(xmm1, xmm0);
__ divps(xmm1, Operand(rbx, rcx, times_4, 10000));
}
......
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