• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "android-base/logging.h"
20 #include "base/bit_utils.h"
21 #include "base/globals.h"
22 
23 namespace art {
24 
InstructionSetAbort(InstructionSet isa)25 void InstructionSetAbort(InstructionSet isa) {
26   switch (isa) {
27     case InstructionSet::kArm:
28     case InstructionSet::kThumb2:
29     case InstructionSet::kArm64:
30     case InstructionSet::kX86:
31     case InstructionSet::kX86_64:
32     case InstructionSet::kNone:
33       LOG(FATAL) << "Unsupported instruction set " << isa;
34       UNREACHABLE();
35   }
36   LOG(FATAL) << "Unknown ISA " << isa;
37   UNREACHABLE();
38 }
39 
GetInstructionSetString(InstructionSet isa)40 const char* GetInstructionSetString(InstructionSet isa) {
41   switch (isa) {
42     case InstructionSet::kArm:
43     case InstructionSet::kThumb2:
44       return "arm";
45     case InstructionSet::kArm64:
46       return "arm64";
47     case InstructionSet::kX86:
48       return "x86";
49     case InstructionSet::kX86_64:
50       return "x86_64";
51     case InstructionSet::kNone:
52       return "none";
53   }
54   LOG(FATAL) << "Unknown ISA " << isa;
55   UNREACHABLE();
56 }
57 
GetInstructionSetFromString(const char * isa_str)58 InstructionSet GetInstructionSetFromString(const char* isa_str) {
59   CHECK(isa_str != nullptr);
60 
61   if (strcmp("arm", isa_str) == 0) {
62     return InstructionSet::kArm;
63   } else if (strcmp("arm64", isa_str) == 0) {
64     return InstructionSet::kArm64;
65   } else if (strcmp("x86", isa_str) == 0) {
66     return InstructionSet::kX86;
67   } else if (strcmp("x86_64", isa_str) == 0) {
68     return InstructionSet::kX86_64;
69   }
70 
71   return InstructionSet::kNone;
72 }
73 
GetInstructionSetAlignment(InstructionSet isa)74 size_t GetInstructionSetAlignment(InstructionSet isa) {
75   switch (isa) {
76     case InstructionSet::kArm:
77       // Fall-through.
78     case InstructionSet::kThumb2:
79       return kArmAlignment;
80     case InstructionSet::kArm64:
81       return kArm64Alignment;
82     case InstructionSet::kX86:
83       // Fall-through.
84     case InstructionSet::kX86_64:
85       return kX86Alignment;
86     case InstructionSet::kNone:
87       LOG(FATAL) << "ISA kNone does not have alignment.";
88       UNREACHABLE();
89   }
90   LOG(FATAL) << "Unknown ISA " << isa;
91   UNREACHABLE();
92 }
93 
94 namespace instruction_set_details {
95 
96 static_assert(IsAligned<kPageSize>(kArmStackOverflowReservedBytes), "ARM gap not page aligned");
97 static_assert(IsAligned<kPageSize>(kArm64StackOverflowReservedBytes), "ARM64 gap not page aligned");
98 static_assert(IsAligned<kPageSize>(kX86StackOverflowReservedBytes), "X86 gap not page aligned");
99 static_assert(IsAligned<kPageSize>(kX86_64StackOverflowReservedBytes),
100               "X86_64 gap not page aligned");
101 
102 #if !defined(ART_FRAME_SIZE_LIMIT)
103 #error "ART frame size limit missing"
104 #endif
105 
106 // TODO: Should we require an extra page (RoundUp(SIZE) + kPageSize)?
107 static_assert(ART_FRAME_SIZE_LIMIT < kArmStackOverflowReservedBytes, "Frame size limit too large");
108 static_assert(ART_FRAME_SIZE_LIMIT < kArm64StackOverflowReservedBytes,
109               "Frame size limit too large");
110 static_assert(ART_FRAME_SIZE_LIMIT < kX86StackOverflowReservedBytes,
111               "Frame size limit too large");
112 static_assert(ART_FRAME_SIZE_LIMIT < kX86_64StackOverflowReservedBytes,
113               "Frame size limit too large");
114 
GetStackOverflowReservedBytesFailure(const char * error_msg)115 NO_RETURN void GetStackOverflowReservedBytesFailure(const char* error_msg) {
116   LOG(FATAL) << error_msg;
117   UNREACHABLE();
118 }
119 
120 }  // namespace instruction_set_details
121 
122 }  // namespace art
123