Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: src/a64/cpu-a64.cc

Issue 144963003: A64: add missing files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/a64/cpu-a64.h ('k') | src/a64/debug-a64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // CPU specific code for arm independent of OS goes here.
29 #ifdef __arm__
30 #include <sys/syscall.h> // For cache flushing.
31 #endif
32
33 #include "v8.h"
34
35 #if defined(V8_TARGET_ARCH_A64)
36
37 #include "a64/cpu-a64.h"
38 #include "a64/utils-a64.h"
39
40 namespace v8 {
41 namespace internal {
42
43 #ifdef DEBUG
44 bool CpuFeatures::initialized_ = false;
45 #endif
46 unsigned CpuFeatures::supported_ = 0;
47
48
49 // Initialise to smallest possible cache size.
50 unsigned CpuFeatures::dcache_line_size_ = 1;
51 unsigned CpuFeatures::icache_line_size_ = 1;
52
53
54 void CPU::SetUp() {
55 CpuFeatures::Probe();
56 }
57
58
59 bool CPU::SupportsCrankshaft() {
60 return true;
61 }
62
63 void CPU::FlushICache(void* address, size_t length) {
64 if (length == 0) {
65 return;
66 }
67
68 #ifdef USE_SIMULATOR
69 // TODO(all): consider doing some cache simulation to ensure every address
70 // run has been synced.
71 USE(address);
72 USE(length);
73 #else
74 // The code below assumes user space cache operations are allowed. The goal
75 // of this routine is to make sure the code generated is visible to the I
76 // side of the CPU.
77
78 uintptr_t start = reinterpret_cast<uintptr_t>(address);
79 // Sizes will be used to generate a mask big enough to cover a pointer.
80 uintptr_t dsize = static_cast<uintptr_t>(CpuFeatures::dcache_line_size());
81 uintptr_t isize = static_cast<uintptr_t>(CpuFeatures::icache_line_size());
82 // Cache line sizes are always a power of 2.
83 ASSERT(CountSetBits(dsize, 64) == 1);
84 ASSERT(CountSetBits(isize, 64) == 1);
85 uintptr_t dstart = start & ~(dsize - 1);
86 uintptr_t istart = start & ~(isize - 1);
87 uintptr_t end = start + length;
88
89 __asm__ __volatile__ ( // NOLINT
90 // Clean every line of the D cache containing the target data.
91 "0: \n\t"
92 // dc : Data Cache maintenance
93 // c : Clean
94 // va : by (Virtual) Address
95 // u : to the point of Unification
96 // The point of unification for a processor is the point by which the
97 // instruction and data caches are guaranteed to see the same copy of a
98 // memory location. See ARM DDI 0406B page B2-12 for more information.
99 "dc cvau, %[dline] \n\t"
100 "add %[dline], %[dline], %[dsize] \n\t"
101 "cmp %[dline], %[end] \n\t"
102 "b.lt 0b \n\t"
103 // Barrier to make sure the effect of the code above is visible to the rest
104 // of the world.
105 // dsb : Data Synchronisation Barrier
106 // ish : Inner SHareable domain
107 // The point of unification for an Inner Shareable shareability domain is
108 // the point by which the instruction and data caches of all the processors
109 // in that Inner Shareable shareability domain are guaranteed to see the
110 // same copy of a memory location. See ARM DDI 0406B page B2-12 for more
111 // information.
112 "dsb ish \n\t"
113 // Invalidate every line of the I cache containing the target data.
114 "1: \n\t"
115 // ic : instruction cache maintenance
116 // i : invalidate
117 // va : by address
118 // u : to the point of unification
119 "ic ivau, %[iline] \n\t"
120 "add %[iline], %[iline], %[isize] \n\t"
121 "cmp %[iline], %[end] \n\t"
122 "b.lt 1b \n\t"
123 // Barrier to make sure the effect of the code above is visible to the rest
124 // of the world.
125 "dsb ish \n\t"
126 // Barrier to ensure any prefetching which happened before this code is
127 // discarded.
128 // isb : Instruction Synchronisation Barrier
129 "isb \n\t"
130 : [dline] "+r" (dstart),
131 [iline] "+r" (istart)
132 : [dsize] "r" (dsize),
133 [isize] "r" (isize),
134 [end] "r" (end)
135 // This code does not write to memory but without the dependency gcc might
136 // move this code before the code is generated.
137 : "cc", "memory"
138 ); // NOLINT
139 #endif
140 }
141
142
143 void CPU::DebugBreak() {
144 #if defined(USE_SIMULATOR)
145 asm volatile("int $3");
146 #else
147 asm volatile("hlt 0");
148 #endif
149 }
150
151
152 void CpuFeatures::Probe() {
153 // Compute I and D cache line size. The cache type register holds
154 // information about the caches.
155 uint32_t cache_type_register = GetCacheType();
156
157 static const int kDCacheLineSizeShift = 16;
158 static const int kICacheLineSizeShift = 0;
159 static const uint32_t kDCacheLineSizeMask = 0xf << kDCacheLineSizeShift;
160 static const uint32_t kICacheLineSizeMask = 0xf << kICacheLineSizeShift;
161
162 // The cache type register holds the size of the I and D caches as a power of
163 // two.
164 uint32_t dcache_line_size_power_of_two =
165 (cache_type_register & kDCacheLineSizeMask) >> kDCacheLineSizeShift;
166 uint32_t icache_line_size_power_of_two =
167 (cache_type_register & kICacheLineSizeMask) >> kICacheLineSizeShift;
168
169 dcache_line_size_ = 1 << dcache_line_size_power_of_two;
170 icache_line_size_ = 1 << icache_line_size_power_of_two;
171
172 // AArch64 has no configuration options, no further probing is required.
173 supported_ = 0;
174
175 #ifdef DEBUG
176 initialized_ = true;
177 #endif
178 }
179
180
181 unsigned CpuFeatures::dcache_line_size() {
182 ASSERT(initialized_);
183 return dcache_line_size_;
184 }
185
186
187 unsigned CpuFeatures::icache_line_size() {
188 ASSERT(initialized_);
189 return icache_line_size_;
190 }
191
192
193 uint32_t CpuFeatures::GetCacheType() {
194 #ifdef USE_SIMULATOR
195 // This will lead to a cache with 1 byte long lines, which is fine since the
196 // simulator will not need this information.
197 return 0;
198 #else
199 uint32_t cache_type_register;
200 // Copy the content of the cache type register to a core register.
201 __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT
202 : [ctr] "=r" (cache_type_register));
203 return cache_type_register;
204 #endif
205 }
206
207 } } // namespace v8::internal
208
209 #endif // V8_TARGET_ARCH_A64
OLDNEW
« no previous file with comments | « src/a64/cpu-a64.h ('k') | src/a64/debug-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698