Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 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 | namespace art { |
| 20 | |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 21 | const char* GetInstructionSetString(const InstructionSet isa) { |
| 22 | switch (isa) { |
| 23 | case kArm: |
| 24 | case kThumb2: |
| 25 | return "arm"; |
| 26 | case kArm64: |
| 27 | return "arm64"; |
| 28 | case kX86: |
| 29 | return "x86"; |
| 30 | case kX86_64: |
| 31 | return "x86_64"; |
| 32 | case kMips: |
| 33 | return "mips"; |
| 34 | case kNone: |
| 35 | return "none"; |
| 36 | default: |
| 37 | LOG(FATAL) << "Unknown ISA " << isa; |
| 38 | return nullptr; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | InstructionSet GetInstructionSetFromString(const char* isa_str) { |
| 43 | CHECK(isa_str != nullptr); |
| 44 | |
Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 45 | if (strcmp("arm", isa_str) == 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 46 | return kArm; |
Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 47 | } else if (strcmp("arm64", isa_str) == 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 48 | return kArm64; |
Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 49 | } else if (strcmp("x86", isa_str) == 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 50 | return kX86; |
Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 51 | } else if (strcmp("x86_64", isa_str) == 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 52 | return kX86_64; |
Andreas Gampe | 20c8930 | 2014-08-19 17:28:06 -0700 | [diff] [blame] | 53 | } else if (strcmp("mips", isa_str) == 0) { |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 54 | return kMips; |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Narayan Kamath | 11d9f06 | 2014-04-23 20:24:57 +0100 | [diff] [blame] | 57 | return kNone; |
| 58 | } |
| 59 | |
Andreas Gampe | af13ad9 | 2014-04-11 12:07:48 -0700 | [diff] [blame] | 60 | size_t GetInstructionSetAlignment(InstructionSet isa) { |
| 61 | switch (isa) { |
| 62 | case kArm: |
| 63 | // Fall-through. |
| 64 | case kThumb2: |
| 65 | return kArmAlignment; |
| 66 | case kArm64: |
| 67 | return kArm64Alignment; |
| 68 | case kX86: |
| 69 | // Fall-through. |
| 70 | case kX86_64: |
| 71 | return kX86Alignment; |
| 72 | case kMips: |
| 73 | return kMipsAlignment; |
| 74 | case kNone: |
| 75 | LOG(FATAL) << "ISA kNone does not have alignment."; |
| 76 | return 0; |
| 77 | default: |
| 78 | LOG(FATAL) << "Unknown ISA " << isa; |
| 79 | return 0; |
| 80 | } |
| 81 | } |
| 82 | |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 83 | |
| 84 | static constexpr size_t kDefaultStackOverflowReservedBytes = 16 * KB; |
| 85 | static constexpr size_t kMipsStackOverflowReservedBytes = kDefaultStackOverflowReservedBytes; |
| 86 | |
Dave Allison | 648d711 | 2014-07-25 16:15:27 -0700 | [diff] [blame] | 87 | static constexpr size_t kArmStackOverflowReservedBytes = 8 * KB; |
| 88 | static constexpr size_t kArm64StackOverflowReservedBytes = 8 * KB; |
| 89 | static constexpr size_t kX86StackOverflowReservedBytes = 8 * KB; |
| 90 | static constexpr size_t kX86_64StackOverflowReservedBytes = 8 * KB; |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 91 | |
| 92 | size_t GetStackOverflowReservedBytes(InstructionSet isa) { |
| 93 | switch (isa) { |
| 94 | case kArm: // Intentional fall-through. |
| 95 | case kThumb2: |
| 96 | return kArmStackOverflowReservedBytes; |
| 97 | |
| 98 | case kArm64: |
| 99 | return kArm64StackOverflowReservedBytes; |
| 100 | |
| 101 | case kMips: |
| 102 | return kMipsStackOverflowReservedBytes; |
| 103 | |
| 104 | case kX86: |
| 105 | return kX86StackOverflowReservedBytes; |
| 106 | |
| 107 | case kX86_64: |
| 108 | return kX86_64StackOverflowReservedBytes; |
| 109 | |
| 110 | case kNone: |
| 111 | LOG(FATAL) << "kNone has no stack overflow size"; |
| 112 | return 0; |
| 113 | |
| 114 | default: |
| 115 | LOG(FATAL) << "Unknown instruction set" << isa; |
| 116 | return 0; |
| 117 | } |
| 118 | } |
| 119 | |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 120 | std::string InstructionSetFeatures::GetFeatureString() const { |
| 121 | std::string result; |
| 122 | if ((mask_ & kHwDiv) != 0) { |
| 123 | result += "div"; |
| 124 | } |
| 125 | if (result.size() == 0) { |
| 126 | result = "none"; |
| 127 | } |
| 128 | return result; |
| 129 | } |
| 130 | |
| 131 | } // namespace art |