Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [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 | |
Andreas Gampe | 705543e | 2017-05-24 13:20:49 -0700 | [diff] [blame] | 19 | #include "android-base/logging.h" |
Andreas Gampe | d126228 | 2016-08-11 18:35:58 -0700 | [diff] [blame] | 20 | #include "base/bit_utils.h" |
David Sehr | 1979c64 | 2018-04-26 14:41:18 -0700 | [diff] [blame] | 21 | #include "base/globals.h" |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 25 | void InstructionSetAbort(InstructionSet isa) { |
| 26 | switch (isa) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 27 | case InstructionSet::kArm: |
| 28 | case InstructionSet::kThumb2: |
| 29 | case InstructionSet::kArm64: |
| 30 | case InstructionSet::kX86: |
| 31 | case InstructionSet::kX86_64: |
| 32 | case InstructionSet::kMips: |
| 33 | case InstructionSet::kMips64: |
| 34 | case InstructionSet::kNone: |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 35 | LOG(FATAL) << "Unsupported instruction set " << isa; |
| 36 | UNREACHABLE(); |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 37 | } |
Andreas Gampe | 705543e | 2017-05-24 13:20:49 -0700 | [diff] [blame] | 38 | LOG(FATAL) << "Unknown ISA " << isa; |
| 39 | UNREACHABLE(); |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | const char* GetInstructionSetString(InstructionSet isa) { |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 43 | switch (isa) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 44 | case InstructionSet::kArm: |
| 45 | case InstructionSet::kThumb2: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 46 | return "arm"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 47 | case InstructionSet::kArm64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 48 | return "arm64"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 49 | case InstructionSet::kX86: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 50 | return "x86"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 51 | case InstructionSet::kX86_64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 52 | return "x86_64"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 53 | case InstructionSet::kMips: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 54 | return "mips"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 55 | case InstructionSet::kMips64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 56 | return "mips64"; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 57 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 58 | return "none"; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 59 | } |
Andreas Gampe | 705543e | 2017-05-24 13:20:49 -0700 | [diff] [blame] | 60 | LOG(FATAL) << "Unknown ISA " << isa; |
| 61 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | InstructionSet GetInstructionSetFromString(const char* isa_str) { |
| 65 | CHECK(isa_str != nullptr); |
| 66 | |
| 67 | if (strcmp("arm", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 68 | return InstructionSet::kArm; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 69 | } else if (strcmp("arm64", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 70 | return InstructionSet::kArm64; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 71 | } else if (strcmp("x86", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 72 | return InstructionSet::kX86; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 73 | } else if (strcmp("x86_64", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 74 | return InstructionSet::kX86_64; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 75 | } else if (strcmp("mips", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 76 | return InstructionSet::kMips; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 77 | } else if (strcmp("mips64", isa_str) == 0) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 78 | return InstructionSet::kMips64; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 81 | return InstructionSet::kNone; |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | size_t GetInstructionSetAlignment(InstructionSet isa) { |
| 85 | switch (isa) { |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 86 | case InstructionSet::kArm: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 87 | // Fall-through. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 88 | case InstructionSet::kThumb2: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 89 | return kArmAlignment; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 90 | case InstructionSet::kArm64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 91 | return kArm64Alignment; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 92 | case InstructionSet::kX86: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 93 | // Fall-through. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 94 | case InstructionSet::kX86_64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 95 | return kX86Alignment; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 96 | case InstructionSet::kMips: |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 97 | // Fall-through. |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 98 | case InstructionSet::kMips64: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 99 | return kMipsAlignment; |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 100 | case InstructionSet::kNone: |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 101 | LOG(FATAL) << "ISA kNone does not have alignment."; |
| 102 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 103 | } |
Andreas Gampe | 705543e | 2017-05-24 13:20:49 -0700 | [diff] [blame] | 104 | LOG(FATAL) << "Unknown ISA " << isa; |
| 105 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Andreas Gampe | a9b2f7b | 2018-11-01 11:10:03 -0700 | [diff] [blame] | 108 | namespace instruction_set_details { |
Andreas Gampe | d126228 | 2016-08-11 18:35:58 -0700 | [diff] [blame] | 109 | |
| 110 | static_assert(IsAligned<kPageSize>(kArmStackOverflowReservedBytes), "ARM gap not page aligned"); |
| 111 | static_assert(IsAligned<kPageSize>(kArm64StackOverflowReservedBytes), "ARM64 gap not page aligned"); |
| 112 | static_assert(IsAligned<kPageSize>(kMipsStackOverflowReservedBytes), "Mips gap not page aligned"); |
| 113 | static_assert(IsAligned<kPageSize>(kMips64StackOverflowReservedBytes), |
| 114 | "Mips64 gap not page aligned"); |
| 115 | static_assert(IsAligned<kPageSize>(kX86StackOverflowReservedBytes), "X86 gap not page aligned"); |
| 116 | static_assert(IsAligned<kPageSize>(kX86_64StackOverflowReservedBytes), |
| 117 | "X86_64 gap not page aligned"); |
| 118 | |
| 119 | #if !defined(ART_FRAME_SIZE_LIMIT) |
| 120 | #error "ART frame size limit missing" |
| 121 | #endif |
| 122 | |
| 123 | // TODO: Should we require an extra page (RoundUp(SIZE) + kPageSize)? |
| 124 | static_assert(ART_FRAME_SIZE_LIMIT < kArmStackOverflowReservedBytes, "Frame size limit too large"); |
| 125 | static_assert(ART_FRAME_SIZE_LIMIT < kArm64StackOverflowReservedBytes, |
| 126 | "Frame size limit too large"); |
| 127 | static_assert(ART_FRAME_SIZE_LIMIT < kMipsStackOverflowReservedBytes, |
| 128 | "Frame size limit too large"); |
| 129 | static_assert(ART_FRAME_SIZE_LIMIT < kMips64StackOverflowReservedBytes, |
| 130 | "Frame size limit too large"); |
| 131 | static_assert(ART_FRAME_SIZE_LIMIT < kX86StackOverflowReservedBytes, |
| 132 | "Frame size limit too large"); |
| 133 | static_assert(ART_FRAME_SIZE_LIMIT < kX86_64StackOverflowReservedBytes, |
| 134 | "Frame size limit too large"); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 135 | |
Andreas Gampe | a9b2f7b | 2018-11-01 11:10:03 -0700 | [diff] [blame] | 136 | NO_RETURN void GetStackOverflowReservedBytesFailure(const char* error_msg) { |
| 137 | LOG(FATAL) << error_msg; |
Andreas Gampe | 705543e | 2017-05-24 13:20:49 -0700 | [diff] [blame] | 138 | UNREACHABLE(); |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Evgeny Astigeevich | bdba2fb | 2018-11-16 14:59:22 +0000 | [diff] [blame] | 141 | } // namespace instruction_set_details |
| 142 | |
Ian Rogers | d582fa4 | 2014-11-05 23:46:43 -0800 | [diff] [blame] | 143 | } // namespace art |