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