Home | History | Annotate | Download | only in arm
      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 defined(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   memcpy(&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).
     91 // Note that "sN:sM" is the same as "dN/2"
     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 };
    102 
    103 
    104 const char* VFPRegisters::Name(int reg, bool is_double) {
    105   ASSERT((0 <= reg) && (reg < kNumVFPRegisters));
    106   return names_[reg + (is_double ? kNumVFPSingleRegisters : 0)];
    107 }
    108 
    109 
    110 int VFPRegisters::Number(const char* name, bool* is_double) {
    111   for (int i = 0; i < kNumVFPRegisters; i++) {
    112     if (strcmp(names_[i], name) == 0) {
    113       if (i < kNumVFPSingleRegisters) {
    114         *is_double = false;
    115         return i;
    116       } else {
    117         *is_double = true;
    118         return i - kNumVFPSingleRegisters;
    119       }
    120     }
    121   }
    122 
    123   // No register with the requested name found.
    124   return kNoRegister;
    125 }
    126 
    127 
    128 int Registers::Number(const char* name) {
    129   // Look through the canonical names.
    130   for (int i = 0; i < kNumRegisters; i++) {
    131     if (strcmp(names_[i], name) == 0) {
    132       return i;
    133     }
    134   }
    135 
    136   // Look through the alias names.
    137   int i = 0;
    138   while (aliases_[i].reg != kNoRegister) {
    139     if (strcmp(aliases_[i].name, name) == 0) {
    140       return aliases_[i].reg;
    141     }
    142     i++;
    143   }
    144 
    145   // No register with the requested name found.
    146   return kNoRegister;
    147 }
    148 
    149 
    150 } }  // namespace v8::internal
    151 
    152 #endif  // V8_TARGET_ARCH_ARM
    153