Commit 3546e91b authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Refactor the register to name mapping in the ARM simulator.

Review URL: http://codereview.chromium.org/195024

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2847 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 07e6f6f6
......@@ -56,9 +56,9 @@ SOURCES = {
],
'arch:arm': [
'arm/assembler-arm.cc', 'arm/builtins-arm.cc', 'arm/cfg-arm.cc',
'arm/codegen-arm.cc', 'arm/cpu-arm.cc', 'arm/disasm-arm.cc',
'arm/debug-arm.cc', 'arm/frames-arm.cc', 'arm/ic-arm.cc',
'arm/jump-target-arm.cc', 'arm/macro-assembler-arm.cc',
'arm/codegen-arm.cc', 'arm/constants-arm.cc', 'arm/cpu-arm.cc',
'arm/disasm-arm.cc', 'arm/debug-arm.cc', 'arm/frames-arm.cc',
'arm/ic-arm.cc', 'arm/jump-target-arm.cc', 'arm/macro-assembler-arm.cc',
'arm/regexp-macro-assembler-arm.cc',
'arm/register-allocator-arm.cc', 'arm/stub-cache-arm.cc',
'arm/virtual-frame-arm.cc'
......
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "v8.h"
#include "constants-arm.h"
namespace assembler {
namespace arm {
namespace v8i = v8::internal;
// These register names are defined in a way to match the native disassembler
// formatting. See for example the command "objdump -d <binary file>".
const char* Registers::names_[kNumRegisters] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "fp", "ip", "sp", "lr", "pc",
};
// List of alias names which can be used when referring to ARM registers.
const Registers::RegisterAlias Registers::aliases_[] = {
{10, "sl"},
{11, "r11"},
{12, "r12"},
{13, "r13"},
{14, "r14"},
{15, "r15"},
{kNoRegister, NULL}
};
const char* Registers::Name(int reg) {
const char* result;
if ((0 <= reg) && (reg < kNumRegisters)) {
result = names_[reg];
} else {
result = "noreg";
}
return result;
}
int Registers::Number(const char* name) {
// Look through the canonical names.
for (int i = 0; i < kNumRegisters; i++) {
if (strcmp(names_[i], name) == 0) {
return i;
}
}
// Look through the alias names.
int i = 0;
while (aliases_[i].reg != kNoRegister) {
if (strcmp(aliases_[i].name, name) == 0) {
return aliases_[i].reg;
}
i++;
}
// No register with the reguested name found.
return kNoRegister;
}
} } // namespace assembler::arm
......@@ -52,6 +52,13 @@
namespace assembler {
namespace arm {
// Number of registers in normal ARM mode.
static const int kNumRegisters = 16;
// PC is register 15.
static const int kPCRegister = 15;
static const int kNoRegister = -1;
// Defines constants and accessor classes to assemble, disassemble and
// simulate ARM instructions.
//
......@@ -269,6 +276,27 @@ class Instr {
};
// Helper functions for converting between register numbers and names.
class Registers {
public:
// Return the name of the register.
static const char* Name(int reg);
// Lookup the register number for the name provided.
static int Number(const char* name);
struct RegisterAlias {
int reg;
const char *name;
};
private:
static const char* names_[kNumRegisters];
static const RegisterAlias aliases_[];
};
} } // namespace assembler::arm
#endif // V8_ARM_CONSTANTS_ARM_H_
......@@ -57,6 +57,7 @@
#include "v8.h"
#include "constants-arm.h"
#include "disasm.h"
#include "macro-assembler.h"
#include "platform.h"
......@@ -898,16 +899,6 @@ namespace disasm {
namespace v8i = v8::internal;
static const int kMaxRegisters = 16;
// These register names are defined in a way to match the native disassembler
// formatting. See for example the command "objdump -d <binary file>".
static const char* reg_names[kMaxRegisters] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "fp", "ip", "sp", "lr", "pc",
};
const char* NameConverter::NameOfAddress(byte* addr) const {
static v8::internal::EmbeddedVector<char, 32> tmp_buffer;
v8::internal::OS::SNPrintF(tmp_buffer, "%p", addr);
......@@ -921,13 +912,7 @@ const char* NameConverter::NameOfConstant(byte* addr) const {
const char* NameConverter::NameOfCPURegister(int reg) const {
const char* result;
if ((0 <= reg) && (reg < kMaxRegisters)) {
result = reg_names[reg];
} else {
result = "noreg";
}
return result;
return assembler::arm::Registers::Name(reg);
}
......
......@@ -70,6 +70,7 @@ class Debugger {
Simulator* sim_;
int32_t GetRegisterValue(int regnum);
bool GetValue(const char* desc, int32_t* value);
// Set or delete a breakpoint. Returns true if successful.
......@@ -132,43 +133,19 @@ void Debugger::Stop(Instr* instr) {
#endif
// The order of these are important, see the handling of the 'print all'
// debugger command.
static const char* reg_names[] = { "r0", "r1", "r2", "r3",
"r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11",
"r12", "r13", "r14", "r15",
"pc", "lr", "sp", "ip",
"fp", "sl", ""};
static int reg_nums[] = { 0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
15, 14, 13, 12,
11, 10};
static int RegNameToRegNum(const char* name) {
int reg = 0;
while (*reg_names[reg] != 0) {
if (strcmp(reg_names[reg], name) == 0) {
return reg_nums[reg];
}
reg++;
int32_t Debugger::GetRegisterValue(int regnum) {
if (regnum == kPCRegister) {
return sim_->get_pc();
} else {
return sim_->get_register(regnum);
}
return -1;
}
bool Debugger::GetValue(const char* desc, int32_t* value) {
int regnum = RegNameToRegNum(desc);
if (regnum >= 0) {
if (regnum == 15) {
*value = sim_->get_pc();
} else {
*value = sim_->get_register(regnum);
}
int regnum = Registers::Number(desc);
if (regnum != kNoRegister) {
*value = GetRegisterValue(regnum);
return true;
} else {
return SScanF(desc, "%i", value) == 1;
......@@ -273,17 +250,9 @@ void Debugger::Debug() {
if (args == 2) {
int32_t value;
if (strcmp(arg1, "all") == 0) {
for (int i = 0; i <= 15; i++) {
if (GetValue(reg_names[i], &value)) {
if (i <= 10) {
PrintF("%3s: 0x%08x %d\n", reg_names[i], value, value);
} else {
PrintF("%3s: 0x%08x %d\n",
reg_names[15 + 16 - i],
value,
value);
}
}
for (int i = 0; i < kNumRegisters; i++) {
value = GetRegisterValue(i);
PrintF("%3s: 0x%08x %10d\n", Registers::Name(i), value, value);
}
} else {
if (GetValue(arg1, &value)) {
......@@ -301,7 +270,6 @@ void Debugger::Debug() {
int32_t value;
if (GetValue(arg1, &value)) {
Object* obj = reinterpret_cast<Object*>(value);
USE(obj);
PrintF("%s: \n", arg1);
#ifdef DEBUG
obj->PrintLn();
......
......@@ -312,6 +312,10 @@
RelativePath="..\..\src\compiler.h"
>
</File>
<File
RelativePath="..\..\src\arm\constants-arm.cc"
>
</File>
<File
RelativePath="..\..\src\arm\constants-arm.h"
>
......
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