OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // CPU specific code for arm independent of OS goes here. | 5 // CPU specific code for arm independent of OS goes here. |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #if V8_TARGET_ARCH_ARM64 | 9 #if V8_TARGET_ARCH_ARM64 |
10 | 10 |
11 #include "arm64/cpu-arm64.h" | 11 #include "arm64/cpu-arm64.h" |
12 #include "arm64/utils-arm64.h" | 12 #include "arm64/utils-arm64.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 #ifdef DEBUG | 17 #ifdef DEBUG |
18 bool CpuFeatures::initialized_ = false; | 18 bool CpuFeatures::initialized_ = false; |
19 #endif | 19 #endif |
20 unsigned CpuFeatures::supported_ = 0; | 20 unsigned CpuFeatures::supported_ = 0; |
21 unsigned CpuFeatures::found_by_runtime_probing_only_ = 0; | |
22 unsigned CpuFeatures::cross_compile_ = 0; | 21 unsigned CpuFeatures::cross_compile_ = 0; |
23 | 22 |
24 // Initialise to smallest possible cache size. | 23 |
25 unsigned CpuFeatures::dcache_line_size_ = 1; | 24 class CacheLineSizes { |
26 unsigned CpuFeatures::icache_line_size_ = 1; | 25 public: |
26 CacheLineSizes() { | |
27 #ifdef USE_SIMULATOR | |
28 cache_type_register_ = 0; | |
29 #else | |
30 // Copy the content of the cache type register to a core register. | |
31 __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT | |
32 : [ctr] "=r" (cache_type_register_)); | |
33 #endif | |
34 }; | |
35 | |
36 uint32_t icache_line_size() const { return ExtractCacheLineSize(0); } | |
37 uint32_t dcache_line_size() const { return ExtractCacheLineSize(16); } | |
38 | |
39 private: | |
40 uint32_t ExtractCacheLineSize(int cache_line_size_shift) const { | |
41 // The cache type register holds the size of the caches as a power of two. | |
42 return 1 << ((cache_type_register_ >> cache_line_size_shift) & 0xf); | |
Rodolph Perfetta
2014/05/02 13:12:07
Argh, the original code was wrong (my bad), the si
Sven Panne
2014/05/05 07:57:33
So the "1 << ..." should be replaced by a "4 << ..
| |
43 } | |
44 | |
45 uint32_t cache_type_register_; | |
46 }; | |
27 | 47 |
28 | 48 |
29 void CPU::FlushICache(void* address, size_t length) { | 49 void CPU::FlushICache(void* address, size_t length) { |
30 if (length == 0) { | 50 if (length == 0) return; |
31 return; | |
32 } | |
33 | 51 |
34 #ifdef USE_SIMULATOR | 52 #ifdef USE_SIMULATOR |
35 // TODO(all): consider doing some cache simulation to ensure every address | 53 // TODO(all): consider doing some cache simulation to ensure every address |
36 // run has been synced. | 54 // run has been synced. |
37 USE(address); | 55 USE(address); |
38 USE(length); | 56 USE(length); |
39 #else | 57 #else |
40 // The code below assumes user space cache operations are allowed. The goal | 58 // The code below assumes user space cache operations are allowed. The goal |
41 // of this routine is to make sure the code generated is visible to the I | 59 // of this routine is to make sure the code generated is visible to the I |
42 // side of the CPU. | 60 // side of the CPU. |
43 | 61 |
44 uintptr_t start = reinterpret_cast<uintptr_t>(address); | 62 uintptr_t start = reinterpret_cast<uintptr_t>(address); |
45 // Sizes will be used to generate a mask big enough to cover a pointer. | 63 // Sizes will be used to generate a mask big enough to cover a pointer. |
46 uintptr_t dsize = static_cast<uintptr_t>(CpuFeatures::dcache_line_size()); | 64 CacheLineSizes sizes; |
47 uintptr_t isize = static_cast<uintptr_t>(CpuFeatures::icache_line_size()); | 65 uintptr_t dsize = sizes.dcache_line_size(); |
66 uintptr_t isize = sizes.icache_line_size(); | |
48 // Cache line sizes are always a power of 2. | 67 // Cache line sizes are always a power of 2. |
49 ASSERT(CountSetBits(dsize, 64) == 1); | 68 ASSERT(CountSetBits(dsize, 64) == 1); |
50 ASSERT(CountSetBits(isize, 64) == 1); | 69 ASSERT(CountSetBits(isize, 64) == 1); |
51 uintptr_t dstart = start & ~(dsize - 1); | 70 uintptr_t dstart = start & ~(dsize - 1); |
52 uintptr_t istart = start & ~(isize - 1); | 71 uintptr_t istart = start & ~(isize - 1); |
53 uintptr_t end = start + length; | 72 uintptr_t end = start + length; |
54 | 73 |
55 __asm__ __volatile__ ( // NOLINT | 74 __asm__ __volatile__ ( // NOLINT |
56 // Clean every line of the D cache containing the target data. | 75 // Clean every line of the D cache containing the target data. |
57 "0: \n\t" | 76 "0: \n\t" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 [end] "r" (end) | 119 [end] "r" (end) |
101 // This code does not write to memory but without the dependency gcc might | 120 // This code does not write to memory but without the dependency gcc might |
102 // move this code before the code is generated. | 121 // move this code before the code is generated. |
103 : "cc", "memory" | 122 : "cc", "memory" |
104 ); // NOLINT | 123 ); // NOLINT |
105 #endif | 124 #endif |
106 } | 125 } |
107 | 126 |
108 | 127 |
109 void CpuFeatures::Probe(bool serializer_enabled) { | 128 void CpuFeatures::Probe(bool serializer_enabled) { |
110 // Compute I and D cache line size. The cache type register holds | |
111 // information about the caches. | |
112 uint32_t cache_type_register = GetCacheType(); | |
113 | |
114 static const int kDCacheLineSizeShift = 16; | |
115 static const int kICacheLineSizeShift = 0; | |
116 static const uint32_t kDCacheLineSizeMask = 0xf << kDCacheLineSizeShift; | |
117 static const uint32_t kICacheLineSizeMask = 0xf << kICacheLineSizeShift; | |
118 | |
119 // The cache type register holds the size of the I and D caches as a power of | |
120 // two. | |
121 uint32_t dcache_line_size_power_of_two = | |
122 (cache_type_register & kDCacheLineSizeMask) >> kDCacheLineSizeShift; | |
123 uint32_t icache_line_size_power_of_two = | |
124 (cache_type_register & kICacheLineSizeMask) >> kICacheLineSizeShift; | |
125 | |
126 dcache_line_size_ = 1 << dcache_line_size_power_of_two; | |
127 icache_line_size_ = 1 << icache_line_size_power_of_two; | |
128 | |
129 // AArch64 has no configuration options, no further probing is required. | 129 // AArch64 has no configuration options, no further probing is required. |
130 supported_ = 0; | 130 supported_ = 0; |
131 | 131 |
132 #ifdef DEBUG | 132 #ifdef DEBUG |
133 initialized_ = true; | 133 initialized_ = true; |
134 #endif | 134 #endif |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 unsigned CpuFeatures::dcache_line_size() { | |
139 ASSERT(initialized_); | |
140 return dcache_line_size_; | |
141 } | |
142 | |
143 | |
144 unsigned CpuFeatures::icache_line_size() { | |
145 ASSERT(initialized_); | |
146 return icache_line_size_; | |
147 } | |
148 | |
149 | |
150 uint32_t CpuFeatures::GetCacheType() { | |
151 #ifdef USE_SIMULATOR | |
152 // This will lead to a cache with 1 byte long lines, which is fine since the | |
153 // simulator will not need this information. | |
154 return 0; | |
155 #else | |
156 uint32_t cache_type_register; | |
157 // Copy the content of the cache type register to a core register. | |
158 __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT | |
159 : [ctr] "=r" (cache_type_register)); | |
160 return cache_type_register; | |
161 #endif | |
162 } | |
163 | |
164 } } // namespace v8::internal | 138 } } // namespace v8::internal |
165 | 139 |
166 #endif // V8_TARGET_ARCH_ARM64 | 140 #endif // V8_TARGET_ARCH_ARM64 |
OLD | NEW |