1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #if V8_TARGET_ARCH_MIPS
6 
7 #include "src/mips/constants-mips.h"
8 
9 namespace v8 {
10 namespace internal {
11 
12 
13 // -----------------------------------------------------------------------------
14 // Registers.
15 
16 
17 // These register names are defined in a way to match the native disassembler
18 // formatting. See for example the command "objdump -d <binary file>".
19 const char* Registers::names_[kNumSimuRegisters] = {
20   "zero_reg",
21   "at",
22   "v0", "v1",
23   "a0", "a1", "a2", "a3",
24   "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
25   "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
26   "t8", "t9",
27   "k0", "k1",
28   "gp",
29   "sp",
30   "fp",
31   "ra",
32   "LO", "HI",
33   "pc"
34 };
35 
36 
37 // List of alias names which can be used when referring to MIPS registers.
38 const Registers::RegisterAlias Registers::aliases_[] = {
39   {0, "zero"},
40   {23, "cp"},
41   {30, "s8"},
42   {30, "s8_fp"},
43   {kInvalidRegister, NULL}
44 };
45 
46 
47 const char* Registers::Name(int reg) {
48   const char* result;
49   if ((0 <= reg) && (reg < kNumSimuRegisters)) {
50     result = names_[reg];
51   } else {
52     result = "noreg";
53   }
54   return result;
55 }
56 
57 
58 int Registers::Number(const char* name) {
59   // Look through the canonical names.
60   for (int i = 0; i < kNumSimuRegisters; i++) {
61     if (strcmp(names_[i], name) == 0) {
62       return i;
63     }
64   }
65 
66   // Look through the alias names.
67   int i = 0;
68   while (aliases_[i].reg != kInvalidRegister) {
69     if (strcmp(aliases_[i].name, name) == 0) {
70       return aliases_[i].reg;
71     }
72     i++;
73   }
74 
75   // No register with the reguested name found.
76   return kInvalidRegister;
77 }
78 
79 
80 const char* FPURegisters::names_[kNumFPURegisters] = {
81   "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
82   "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21",
83   "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
84 };
85 
86 
87 // List of alias names which can be used when referring to MIPS registers.
88 const FPURegisters::RegisterAlias FPURegisters::aliases_[] = {
89   {kInvalidRegister, NULL}
90 };
91 
92 
93 const char* FPURegisters::Name(int creg) {
94   const char* result;
95   if ((0 <= creg) && (creg < kNumFPURegisters)) {
96     result = names_[creg];
97   } else {
98     result = "nocreg";
99   }
100   return result;
101 }
102 
103 
104 int FPURegisters::Number(const char* name) {
105   // Look through the canonical names.
106   for (int i = 0; i < kNumFPURegisters; i++) {
107     if (strcmp(names_[i], name) == 0) {
108       return i;
109     }
110   }
111 
112   // Look through the alias names.
113   int i = 0;
114   while (aliases_[i].creg != kInvalidRegister) {
115     if (strcmp(aliases_[i].name, name) == 0) {
116       return aliases_[i].creg;
117     }
118     i++;
119   }
120 
121   // No Cregister with the reguested name found.
122   return kInvalidFPURegister;
123 }
124 
125 
126 }  // namespace internal
127 }  // namespace v8
128 
129 #endif  // V8_TARGET_ARCH_MIPS
130