| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return 1u << VFP3; | 92 return 1u << VFP3; |
| 93 #elif CAN_USE_ARMV7_INSTRUCTIONS | 93 #elif CAN_USE_ARMV7_INSTRUCTIONS |
| 94 return 1u << ARMv7; | 94 return 1u << ARMv7; |
| 95 #else | 95 #else |
| 96 return 0; // Linux runs on anything. | 96 return 0; // Linux runs on anything. |
| 97 #endif | 97 #endif |
| 98 } | 98 } |
| 99 | 99 |
| 100 | 100 |
| 101 #ifdef __arm__ | 101 #ifdef __arm__ |
| 102 bool OS::ArmCpuHasFeature(CpuFeature feature) { | 102 static bool CPUInfoContainsString(const char * search_string) { |
| 103 const char* search_string = NULL; | |
| 104 const char* file_name = "/proc/cpuinfo"; | 103 const char* file_name = "/proc/cpuinfo"; |
| 105 // Simple detection of VFP at runtime for Linux. | |
| 106 // It is based on /proc/cpuinfo, which reveals hardware configuration | |
| 107 // to user-space applications. According to ARM (mid 2009), no similar | |
| 108 // facility is universally available on the ARM architectures, | |
| 109 // so it's up to individual OSes to provide such. | |
| 110 // | |
| 111 // This is written as a straight shot one pass parser | 104 // This is written as a straight shot one pass parser |
| 112 // and not using STL string and ifstream because, | 105 // and not using STL string and ifstream because, |
| 113 // on Linux, it's reading from a (non-mmap-able) | 106 // on Linux, it's reading from a (non-mmap-able) |
| 114 // character special device. | 107 // character special device. |
| 115 switch (feature) { | |
| 116 case VFP3: | |
| 117 search_string = "vfp"; | |
| 118 break; | |
| 119 case ARMv7: | |
| 120 search_string = "ARMv7"; | |
| 121 break; | |
| 122 default: | |
| 123 UNREACHABLE(); | |
| 124 } | |
| 125 | |
| 126 FILE* f = NULL; | 108 FILE* f = NULL; |
| 127 const char* what = search_string; | 109 const char* what = search_string; |
| 128 | 110 |
| 129 if (NULL == (f = fopen(file_name, "r"))) | 111 if (NULL == (f = fopen(file_name, "r"))) |
| 130 return false; | 112 return false; |
| 131 | 113 |
| 132 int k; | 114 int k; |
| 133 while (EOF != (k = fgetc(f))) { | 115 while (EOF != (k = fgetc(f))) { |
| 134 if (k == *what) { | 116 if (k == *what) { |
| 135 ++what; | 117 ++what; |
| 136 while ((*what != '\0') && (*what == fgetc(f))) { | 118 while ((*what != '\0') && (*what == fgetc(f))) { |
| 137 ++what; | 119 ++what; |
| 138 } | 120 } |
| 139 if (*what == '\0') { | 121 if (*what == '\0') { |
| 140 fclose(f); | 122 fclose(f); |
| 141 return true; | 123 return true; |
| 142 } else { | 124 } else { |
| 143 what = search_string; | 125 what = search_string; |
| 144 } | 126 } |
| 145 } | 127 } |
| 146 } | 128 } |
| 147 fclose(f); | 129 fclose(f); |
| 148 | 130 |
| 149 // Did not find string in the proc file. | 131 // Did not find string in the proc file. |
| 150 return false; | 132 return false; |
| 151 } | 133 } |
| 134 |
| 135 bool OS::ArmCpuHasFeature(CpuFeature feature) { |
| 136 const int max_items = 2; |
| 137 const char* search_strings[max_items] = { NULL, NULL }; |
| 138 int search_items = 0; |
| 139 // Simple detection of VFP at runtime for Linux. |
| 140 // It is based on /proc/cpuinfo, which reveals hardware configuration |
| 141 // to user-space applications. According to ARM (mid 2009), no similar |
| 142 // facility is universally available on the ARM architectures, |
| 143 // so it's up to individual OSes to provide such. |
| 144 switch (feature) { |
| 145 case VFP3: |
| 146 search_strings[0] = "vfpv3"; |
| 147 // Some old kernels will report vfp for A8, not vfpv3, so we check for |
| 148 // A8 explicitely. The cpuinfo file report the CPU Part which for Cortex |
| 149 // A8 is 0xc08. |
| 150 search_strings[1] = "0xc08"; |
| 151 search_items = 2; |
| 152 ASSERT(search_items <= max_items); |
| 153 break; |
| 154 case ARMv7: |
| 155 search_strings[0] = "ARMv7" ; |
| 156 search_items = 1; |
| 157 ASSERT(search_items <= max_items); |
| 158 break; |
| 159 default: |
| 160 UNREACHABLE(); |
| 161 } |
| 162 |
| 163 for (int i = 0; i < search_items; ++i) { |
| 164 if (CPUInfoContainsString(search_strings[i])) { |
| 165 return true; |
| 166 } |
| 167 } |
| 168 |
| 169 return false; |
| 170 } |
| 152 #endif // def __arm__ | 171 #endif // def __arm__ |
| 153 | 172 |
| 154 | 173 |
| 155 int OS::ActivationFrameAlignment() { | 174 int OS::ActivationFrameAlignment() { |
| 156 #ifdef V8_TARGET_ARCH_ARM | 175 #ifdef V8_TARGET_ARCH_ARM |
| 157 // On EABI ARM targets this is required for fp correctness in the | 176 // On EABI ARM targets this is required for fp correctness in the |
| 158 // runtime system. | 177 // runtime system. |
| 159 return 8; | 178 return 8; |
| 160 #elif V8_TARGET_ARCH_MIPS | 179 #elif V8_TARGET_ARCH_MIPS |
| 161 return 8; | 180 return 8; |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 } | 910 } |
| 892 | 911 |
| 893 // This sampler is no longer the active sampler. | 912 // This sampler is no longer the active sampler. |
| 894 active_sampler_ = NULL; | 913 active_sampler_ = NULL; |
| 895 } | 914 } |
| 896 | 915 |
| 897 | 916 |
| 898 #endif // ENABLE_LOGGING_AND_PROFILING | 917 #endif // ENABLE_LOGGING_AND_PROFILING |
| 899 | 918 |
| 900 } } // namespace v8::internal | 919 } } // namespace v8::internal |
| OLD | NEW |