1// Copyright 2009 the V8 project authors. All rights reserved. 2// Redistribution and use in source and binary forms, with or without 3// modification, are permitted provided that the following conditions are 4// met: 5// 6// * Redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer. 8// * Redistributions in binary form must reproduce the above 9// copyright notice, this list of conditions and the following 10// disclaimer in the documentation and/or other materials provided 11// with the distribution. 12// * Neither the name of Google Inc. nor the names of its 13// contributors may be used to endorse or promote products derived 14// from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28#include "v8.h" 29 30#include "constants-arm.h" 31 32 33namespace assembler { 34namespace arm { 35 36namespace v8i = v8::internal; 37 38 39// These register names are defined in a way to match the native disassembler 40// formatting. See for example the command "objdump -d <binary file>". 41const char* Registers::names_[kNumRegisters] = { 42 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 43 "r8", "r9", "r10", "fp", "ip", "sp", "lr", "pc", 44}; 45 46 47// List of alias names which can be used when referring to ARM registers. 48const Registers::RegisterAlias Registers::aliases_[] = { 49 {10, "sl"}, 50 {11, "r11"}, 51 {12, "r12"}, 52 {13, "r13"}, 53 {14, "r14"}, 54 {15, "r15"}, 55 {kNoRegister, NULL} 56}; 57 58 59const char* Registers::Name(int reg) { 60 const char* result; 61 if ((0 <= reg) && (reg < kNumRegisters)) { 62 result = names_[reg]; 63 } else { 64 result = "noreg"; 65 } 66 return result; 67} 68 69 70// Support for VFP registers s0 to s31 (d0 to d15). 71// Note that "sN:sM" is the same as "dN/2" 72// These register names are defined in a way to match the native disassembler 73// formatting. See for example the command "objdump -d <binary file>". 74const char* VFPRegisters::names_[kNumVFPRegisters] = { 75 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", 76 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", 77 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", 78 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", 79 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", 80 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15" 81}; 82 83 84const char* VFPRegisters::Name(int reg) { 85 ASSERT((0 <= reg) && (reg < kNumVFPRegisters)); 86 return names_[reg]; 87} 88 89 90int Registers::Number(const char* name) { 91 // Look through the canonical names. 92 for (int i = 0; i < kNumRegisters; i++) { 93 if (strcmp(names_[i], name) == 0) { 94 return i; 95 } 96 } 97 98 // Look through the alias names. 99 int i = 0; 100 while (aliases_[i].reg != kNoRegister) { 101 if (strcmp(aliases_[i].name, name) == 0) { 102 return aliases_[i].reg; 103 } 104 i++; 105 } 106 107 // No register with the reguested name found. 108 return kNoRegister; 109} 110 111 112} } // namespace assembler::arm 113