blob: 92fa727674613e1fa9390a061cd5950a7f06f311 [file] [log] [blame]
Ian Rogersd582fa42014-11-05 23:46:43 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "instruction_set.h"
18
19#include "globals.h"
20
21namespace art {
22
23const char* GetInstructionSetString(const InstructionSet isa) {
24 switch (isa) {
25 case kArm:
26 case kThumb2:
27 return "arm";
28 case kArm64:
29 return "arm64";
30 case kX86:
31 return "x86";
32 case kX86_64:
33 return "x86_64";
34 case kMips:
35 return "mips";
36 case kMips64:
37 return "mips64";
38 case kNone:
39 return "none";
40 default:
41 LOG(FATAL) << "Unknown ISA " << isa;
42 UNREACHABLE();
43 }
44}
45
46InstructionSet GetInstructionSetFromString(const char* isa_str) {
47 CHECK(isa_str != nullptr);
48
49 if (strcmp("arm", isa_str) == 0) {
50 return kArm;
51 } else if (strcmp("arm64", isa_str) == 0) {
52 return kArm64;
53 } else if (strcmp("x86", isa_str) == 0) {
54 return kX86;
55 } else if (strcmp("x86_64", isa_str) == 0) {
56 return kX86_64;
57 } else if (strcmp("mips", isa_str) == 0) {
58 return kMips;
59 } else if (strcmp("mips64", isa_str) == 0) {
60 return kMips;
61 }
62
63 return kNone;
64}
65
66size_t GetInstructionSetAlignment(InstructionSet isa) {
67 switch (isa) {
68 case kArm:
69 // Fall-through.
70 case kThumb2:
71 return kArmAlignment;
72 case kArm64:
73 return kArm64Alignment;
74 case kX86:
75 // Fall-through.
76 case kX86_64:
77 return kX86Alignment;
78 case kMips:
79 return kMipsAlignment;
80 case kNone:
81 LOG(FATAL) << "ISA kNone does not have alignment.";
82 UNREACHABLE();
83 default:
84 LOG(FATAL) << "Unknown ISA " << isa;
85 UNREACHABLE();
86 }
87}
88
89static constexpr size_t kDefaultStackOverflowReservedBytes = 16 * KB;
90static constexpr size_t kMipsStackOverflowReservedBytes = kDefaultStackOverflowReservedBytes;
91
92static constexpr size_t kArmStackOverflowReservedBytes = 8 * KB;
93static constexpr size_t kArm64StackOverflowReservedBytes = 8 * KB;
94static constexpr size_t kX86StackOverflowReservedBytes = 8 * KB;
95static constexpr size_t kX86_64StackOverflowReservedBytes = 8 * KB;
96
97size_t GetStackOverflowReservedBytes(InstructionSet isa) {
98 switch (isa) {
99 case kArm: // Intentional fall-through.
100 case kThumb2:
101 return kArmStackOverflowReservedBytes;
102
103 case kArm64:
104 return kArm64StackOverflowReservedBytes;
105
106 case kMips:
107 return kMipsStackOverflowReservedBytes;
108
109 case kX86:
110 return kX86StackOverflowReservedBytes;
111
112 case kX86_64:
113 return kX86_64StackOverflowReservedBytes;
114
115 case kNone:
116 LOG(FATAL) << "kNone has no stack overflow size";
117 UNREACHABLE();
118
119 default:
120 LOG(FATAL) << "Unknown instruction set" << isa;
121 UNREACHABLE();
122 }
123}
124
125} // namespace art