blob: 5ab461bc730ddc5739644746286f5ac0ecc14a86 [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) {
Andreas Gampe57b34292015-01-14 15:45:59 -080060 return kMips64;
Ian Rogersd582fa42014-11-05 23:46:43 -080061 }
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:
Andreas Gampe57b34292015-01-14 15:45:59 -080079 // Fall-through.
80 case kMips64:
Ian Rogersd582fa42014-11-05 23:46:43 -080081 return kMipsAlignment;
82 case kNone:
83 LOG(FATAL) << "ISA kNone does not have alignment.";
84 UNREACHABLE();
85 default:
86 LOG(FATAL) << "Unknown ISA " << isa;
87 UNREACHABLE();
88 }
89}
90
91static constexpr size_t kDefaultStackOverflowReservedBytes = 16 * KB;
92static constexpr size_t kMipsStackOverflowReservedBytes = kDefaultStackOverflowReservedBytes;
Andreas Gampe57b34292015-01-14 15:45:59 -080093static constexpr size_t kMips64StackOverflowReservedBytes = kDefaultStackOverflowReservedBytes;
Ian Rogersd582fa42014-11-05 23:46:43 -080094
95static constexpr size_t kArmStackOverflowReservedBytes = 8 * KB;
96static constexpr size_t kArm64StackOverflowReservedBytes = 8 * KB;
97static constexpr size_t kX86StackOverflowReservedBytes = 8 * KB;
98static constexpr size_t kX86_64StackOverflowReservedBytes = 8 * KB;
99
100size_t GetStackOverflowReservedBytes(InstructionSet isa) {
101 switch (isa) {
102 case kArm: // Intentional fall-through.
103 case kThumb2:
104 return kArmStackOverflowReservedBytes;
105
106 case kArm64:
107 return kArm64StackOverflowReservedBytes;
108
109 case kMips:
110 return kMipsStackOverflowReservedBytes;
111
Andreas Gampe57b34292015-01-14 15:45:59 -0800112 case kMips64:
113 return kMips64StackOverflowReservedBytes;
114
Ian Rogersd582fa42014-11-05 23:46:43 -0800115 case kX86:
116 return kX86StackOverflowReservedBytes;
117
118 case kX86_64:
119 return kX86_64StackOverflowReservedBytes;
120
121 case kNone:
122 LOG(FATAL) << "kNone has no stack overflow size";
123 UNREACHABLE();
124
125 default:
126 LOG(FATAL) << "Unknown instruction set" << isa;
127 UNREACHABLE();
128 }
129}
130
131} // namespace art