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 #if V8_TARGET_ARCH_ARM 31 32 #include "constants-arm.h" 33 34 35 namespace v8 { 36 namespace internal { 37 38 double Instruction::DoubleImmedVmov() const { 39 // Reconstruct a double from the immediate encoded in the vmov instruction. 40 // 41 // instruction: [xxxxxxxx,xxxxabcd,xxxxxxxx,xxxxefgh] 42 // double: [aBbbbbbb,bbcdefgh,00000000,00000000, 43 // 00000000,00000000,00000000,00000000] 44 // 45 // where B = ~b. Only the high 16 bits are affected. 46 uint64_t high16; 47 high16 = (Bits(17, 16) << 4) | Bits(3, 0); // xxxxxxxx,xxcdefgh. 48 high16 |= (0xff * Bit(18)) << 6; // xxbbbbbb,bbxxxxxx. 49 high16 |= (Bit(18) ^ 1) << 14; // xBxxxxxx,xxxxxxxx. 50 high16 |= Bit(19) << 15; // axxxxxxx,xxxxxxxx. 51 52 uint64_t imm = high16 << 48; 53 double d; 54 OS::MemCopy(&d, &imm, 8); 55 return d; 56 } 57 58 59 // These register names are defined in a way to match the native disassembler 60 // formatting. See for example the command "objdump -d <binary file>". 61 const char* Registers::names_[kNumRegisters] = { 62 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 63 "r8", "r9", "r10", "fp", "ip", "sp", "lr", "pc", 64 }; 65 66 67 // List of alias names which can be used when referring to ARM registers. 68 const Registers::RegisterAlias Registers::aliases_[] = { 69 {10, "sl"}, 70 {11, "r11"}, 71 {12, "r12"}, 72 {13, "r13"}, 73 {14, "r14"}, 74 {15, "r15"}, 75 {kNoRegister, NULL} 76 }; 77 78 79 const char* Registers::Name(int reg) { 80 const char* result; 81 if ((0 <= reg) && (reg < kNumRegisters)) { 82 result = names_[reg]; 83 } else { 84 result = "noreg"; 85 } 86 return result; 87 } 88 89 90 // Support for VFP registers s0 to s31 (d0 to d15) and d16-d31. 91 // Note that "sN:sM" is the same as "dN/2" up to d15. 92 // These register names are defined in a way to match the native disassembler 93 // formatting. See for example the command "objdump -d <binary file>". 94 const char* VFPRegisters::names_[kNumVFPRegisters] = { 95 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", 96 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", 97 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23", 98 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31", 99 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", 100 "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15", 101 "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23", 102 "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31" 103 }; 104 105 106 const char* VFPRegisters::Name(int reg, bool is_double) { 107 ASSERT((0 <= reg) && (reg < kNumVFPRegisters)); 108 return names_[reg + (is_double ? kNumVFPSingleRegisters : 0)]; 109 } 110 111 112 int VFPRegisters::Number(const char* name, bool* is_double) { 113 for (int i = 0; i < kNumVFPRegisters; i++) { 114 if (strcmp(names_[i], name) == 0) { 115 if (i < kNumVFPSingleRegisters) { 116 *is_double = false; 117 return i; 118 } else { 119 *is_double = true; 120 return i - kNumVFPSingleRegisters; 121 } 122 } 123 } 124 125 // No register with the requested name found. 126 return kNoRegister; 127 } 128 129 130 int Registers::Number(const char* name) { 131 // Look through the canonical names. 132 for (int i = 0; i < kNumRegisters; i++) { 133 if (strcmp(names_[i], name) == 0) { 134 return i; 135 } 136 } 137 138 // Look through the alias names. 139 int i = 0; 140 while (aliases_[i].reg != kNoRegister) { 141 if (strcmp(aliases_[i].name, name) == 0) { 142 return aliases_[i].reg; 143 } 144 i++; 145 } 146 147 // No register with the requested name found. 148 return kNoRegister; 149 } 150 151 152 } } // namespace v8::internal 153 154 #endif // V8_TARGET_ARCH_ARM 155