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, nullptr}};
44 
Name(int reg)45 const char* Registers::Name(int reg) {
46   const char* result;
47   if ((0 <= reg) && (reg < kNumSimuRegisters)) {
48     result = names_[reg];
49   } else {
50     result = "noreg";
51   }
52   return result;
53 }
54 
55 
Number(const char * name)56 int Registers::Number(const char* name) {
57   // Look through the canonical names.
58   for (int i = 0; i < kNumSimuRegisters; i++) {
59     if (strcmp(names_[i], name) == 0) {
60       return i;
61     }
62   }
63 
64   // Look through the alias names.
65   int i = 0;
66   while (aliases_[i].reg != kInvalidRegister) {
67     if (strcmp(aliases_[i].name, name) == 0) {
68       return aliases_[i].reg;
69     }
70     i++;
71   }
72 
73   // No register with the reguested name found.
74   return kInvalidRegister;
75 }
76 
77 
78 const char* FPURegisters::names_[kNumFPURegisters] = {
79   "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11",
80   "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21",
81   "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
82 };
83 
84 
85 // List of alias names which can be used when referring to MIPS registers.
86 const FPURegisters::RegisterAlias FPURegisters::aliases_[] = {
87     {kInvalidRegister, nullptr}};
88 
Name(int creg)89 const char* FPURegisters::Name(int creg) {
90   const char* result;
91   if ((0 <= creg) && (creg < kNumFPURegisters)) {
92     result = names_[creg];
93   } else {
94     result = "nocreg";
95   }
96   return result;
97 }
98 
99 
Number(const char * name)100 int FPURegisters::Number(const char* name) {
101   // Look through the canonical names.
102   for (int i = 0; i < kNumFPURegisters; i++) {
103     if (strcmp(names_[i], name) == 0) {
104       return i;
105     }
106   }
107 
108   // Look through the alias names.
109   int i = 0;
110   while (aliases_[i].creg != kInvalidRegister) {
111     if (strcmp(aliases_[i].name, name) == 0) {
112       return aliases_[i].creg;
113     }
114     i++;
115   }
116 
117   // No Cregister with the reguested name found.
118   return kInvalidFPURegister;
119 }
120 
121 const char* MSARegisters::names_[kNumMSARegisters] = {
122     "w0",  "w1",  "w2",  "w3",  "w4",  "w5",  "w6",  "w7",  "w8",  "w9",  "w10",
123     "w11", "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21",
124     "w22", "w23", "w24", "w25", "w26", "w27", "w28", "w29", "w30", "w31"};
125 
126 const MSARegisters::RegisterAlias MSARegisters::aliases_[] = {
127     {kInvalidRegister, nullptr}};
128 
Name(int creg)129 const char* MSARegisters::Name(int creg) {
130   const char* result;
131   if ((0 <= creg) && (creg < kNumMSARegisters)) {
132     result = names_[creg];
133   } else {
134     result = "nocreg";
135   }
136   return result;
137 }
138 
Number(const char * name)139 int MSARegisters::Number(const char* name) {
140   // Look through the canonical names.
141   for (int i = 0; i < kNumMSARegisters; i++) {
142     if (strcmp(names_[i], name) == 0) {
143       return i;
144     }
145   }
146 
147   // Look through the alias names.
148   int i = 0;
149   while (aliases_[i].creg != kInvalidRegister) {
150     if (strcmp(aliases_[i].name, name) == 0) {
151       return aliases_[i].creg;
152     }
153     i++;
154   }
155 
156   // No Cregister with the reguested name found.
157   return kInvalidMSARegister;
158 }
159 
160 }  // namespace internal
161 }  // namespace v8
162 
163 #endif  // V8_TARGET_ARCH_MIPS
164