root / cpu-all.h @ 00dbbb03
History | View | Annotate | Download (27.6 kB)
1 | 5a9fdfec | bellard | /*
|
---|---|---|---|
2 | 5a9fdfec | bellard | * defines common to all virtual CPUs
|
3 | 5fafdf24 | ths | *
|
4 | 5a9fdfec | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 5a9fdfec | bellard | *
|
6 | 5a9fdfec | bellard | * This library is free software; you can redistribute it and/or
|
7 | 5a9fdfec | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 5a9fdfec | bellard | * License as published by the Free Software Foundation; either
|
9 | 5a9fdfec | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 5a9fdfec | bellard | *
|
11 | 5a9fdfec | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 5a9fdfec | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 5a9fdfec | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 5a9fdfec | bellard | * Lesser General Public License for more details.
|
15 | 5a9fdfec | bellard | *
|
16 | 5a9fdfec | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 5a9fdfec | bellard | * License along with this library; if not, write to the Free Software
|
18 | 5a9fdfec | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 5a9fdfec | bellard | */
|
20 | 5a9fdfec | bellard | #ifndef CPU_ALL_H
|
21 | 5a9fdfec | bellard | #define CPU_ALL_H
|
22 | 5a9fdfec | bellard | |
23 | f54b3f92 | aurel32 | #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__)
|
24 | 0ac4bd56 | bellard | #define WORDS_ALIGNED
|
25 | 0ac4bd56 | bellard | #endif
|
26 | 0ac4bd56 | bellard | |
27 | 5fafdf24 | ths | /* some important defines:
|
28 | 5fafdf24 | ths | *
|
29 | 0ac4bd56 | bellard | * WORDS_ALIGNED : if defined, the host cpu can only make word aligned
|
30 | 0ac4bd56 | bellard | * memory accesses.
|
31 | 5fafdf24 | ths | *
|
32 | 0ac4bd56 | bellard | * WORDS_BIGENDIAN : if defined, the host cpu is big endian and
|
33 | 0ac4bd56 | bellard | * otherwise little endian.
|
34 | 5fafdf24 | ths | *
|
35 | 0ac4bd56 | bellard | * (TARGET_WORDS_ALIGNED : same for target cpu (not supported yet))
|
36 | 5fafdf24 | ths | *
|
37 | 0ac4bd56 | bellard | * TARGET_WORDS_BIGENDIAN : same for target cpu
|
38 | 0ac4bd56 | bellard | */
|
39 | 0ac4bd56 | bellard | |
40 | f193c797 | bellard | #include "bswap.h" |
41 | 939ef593 | aurel32 | #include "softfloat.h" |
42 | f193c797 | bellard | |
43 | f193c797 | bellard | #if defined(WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
|
44 | f193c797 | bellard | #define BSWAP_NEEDED
|
45 | f193c797 | bellard | #endif
|
46 | f193c797 | bellard | |
47 | f193c797 | bellard | #ifdef BSWAP_NEEDED
|
48 | f193c797 | bellard | |
49 | f193c797 | bellard | static inline uint16_t tswap16(uint16_t s) |
50 | f193c797 | bellard | { |
51 | f193c797 | bellard | return bswap16(s);
|
52 | f193c797 | bellard | } |
53 | f193c797 | bellard | |
54 | f193c797 | bellard | static inline uint32_t tswap32(uint32_t s) |
55 | f193c797 | bellard | { |
56 | f193c797 | bellard | return bswap32(s);
|
57 | f193c797 | bellard | } |
58 | f193c797 | bellard | |
59 | f193c797 | bellard | static inline uint64_t tswap64(uint64_t s) |
60 | f193c797 | bellard | { |
61 | f193c797 | bellard | return bswap64(s);
|
62 | f193c797 | bellard | } |
63 | f193c797 | bellard | |
64 | f193c797 | bellard | static inline void tswap16s(uint16_t *s) |
65 | f193c797 | bellard | { |
66 | f193c797 | bellard | *s = bswap16(*s); |
67 | f193c797 | bellard | } |
68 | f193c797 | bellard | |
69 | f193c797 | bellard | static inline void tswap32s(uint32_t *s) |
70 | f193c797 | bellard | { |
71 | f193c797 | bellard | *s = bswap32(*s); |
72 | f193c797 | bellard | } |
73 | f193c797 | bellard | |
74 | f193c797 | bellard | static inline void tswap64s(uint64_t *s) |
75 | f193c797 | bellard | { |
76 | f193c797 | bellard | *s = bswap64(*s); |
77 | f193c797 | bellard | } |
78 | f193c797 | bellard | |
79 | f193c797 | bellard | #else
|
80 | f193c797 | bellard | |
81 | f193c797 | bellard | static inline uint16_t tswap16(uint16_t s) |
82 | f193c797 | bellard | { |
83 | f193c797 | bellard | return s;
|
84 | f193c797 | bellard | } |
85 | f193c797 | bellard | |
86 | f193c797 | bellard | static inline uint32_t tswap32(uint32_t s) |
87 | f193c797 | bellard | { |
88 | f193c797 | bellard | return s;
|
89 | f193c797 | bellard | } |
90 | f193c797 | bellard | |
91 | f193c797 | bellard | static inline uint64_t tswap64(uint64_t s) |
92 | f193c797 | bellard | { |
93 | f193c797 | bellard | return s;
|
94 | f193c797 | bellard | } |
95 | f193c797 | bellard | |
96 | f193c797 | bellard | static inline void tswap16s(uint16_t *s) |
97 | f193c797 | bellard | { |
98 | f193c797 | bellard | } |
99 | f193c797 | bellard | |
100 | f193c797 | bellard | static inline void tswap32s(uint32_t *s) |
101 | f193c797 | bellard | { |
102 | f193c797 | bellard | } |
103 | f193c797 | bellard | |
104 | f193c797 | bellard | static inline void tswap64s(uint64_t *s) |
105 | f193c797 | bellard | { |
106 | f193c797 | bellard | } |
107 | f193c797 | bellard | |
108 | f193c797 | bellard | #endif
|
109 | f193c797 | bellard | |
110 | f193c797 | bellard | #if TARGET_LONG_SIZE == 4 |
111 | f193c797 | bellard | #define tswapl(s) tswap32(s)
|
112 | f193c797 | bellard | #define tswapls(s) tswap32s((uint32_t *)(s))
|
113 | 0a962c02 | bellard | #define bswaptls(s) bswap32s(s)
|
114 | f193c797 | bellard | #else
|
115 | f193c797 | bellard | #define tswapl(s) tswap64(s)
|
116 | f193c797 | bellard | #define tswapls(s) tswap64s((uint64_t *)(s))
|
117 | 0a962c02 | bellard | #define bswaptls(s) bswap64s(s)
|
118 | f193c797 | bellard | #endif
|
119 | f193c797 | bellard | |
120 | 0ca9d380 | aurel32 | typedef union { |
121 | 0ca9d380 | aurel32 | float32 f; |
122 | 0ca9d380 | aurel32 | uint32_t l; |
123 | 0ca9d380 | aurel32 | } CPU_FloatU; |
124 | 0ca9d380 | aurel32 | |
125 | 832ed0fa | bellard | /* NOTE: arm FPA is horrible as double 32 bit words are stored in big
|
126 | 832ed0fa | bellard | endian ! */
|
127 | 0ac4bd56 | bellard | typedef union { |
128 | 53cd6637 | bellard | float64 d; |
129 | 9d60cac0 | bellard | #if defined(WORDS_BIGENDIAN) \
|
130 | 9d60cac0 | bellard | || (defined(__arm__) && !defined(__VFP_FP__) && !defined(CONFIG_SOFTFLOAT)) |
131 | 0ac4bd56 | bellard | struct {
|
132 | 0ac4bd56 | bellard | uint32_t upper; |
133 | 832ed0fa | bellard | uint32_t lower; |
134 | 0ac4bd56 | bellard | } l; |
135 | 0ac4bd56 | bellard | #else
|
136 | 0ac4bd56 | bellard | struct {
|
137 | 0ac4bd56 | bellard | uint32_t lower; |
138 | 832ed0fa | bellard | uint32_t upper; |
139 | 0ac4bd56 | bellard | } l; |
140 | 0ac4bd56 | bellard | #endif
|
141 | 0ac4bd56 | bellard | uint64_t ll; |
142 | 0ac4bd56 | bellard | } CPU_DoubleU; |
143 | 0ac4bd56 | bellard | |
144 | 1f587329 | blueswir1 | #ifdef TARGET_SPARC
|
145 | 1f587329 | blueswir1 | typedef union { |
146 | 1f587329 | blueswir1 | float128 q; |
147 | 1f587329 | blueswir1 | #if defined(WORDS_BIGENDIAN) \
|
148 | 1f587329 | blueswir1 | || (defined(__arm__) && !defined(__VFP_FP__) && !defined(CONFIG_SOFTFLOAT)) |
149 | 1f587329 | blueswir1 | struct {
|
150 | 1f587329 | blueswir1 | uint32_t upmost; |
151 | 1f587329 | blueswir1 | uint32_t upper; |
152 | 1f587329 | blueswir1 | uint32_t lower; |
153 | 1f587329 | blueswir1 | uint32_t lowest; |
154 | 1f587329 | blueswir1 | } l; |
155 | 1f587329 | blueswir1 | struct {
|
156 | 1f587329 | blueswir1 | uint64_t upper; |
157 | 1f587329 | blueswir1 | uint64_t lower; |
158 | 1f587329 | blueswir1 | } ll; |
159 | 1f587329 | blueswir1 | #else
|
160 | 1f587329 | blueswir1 | struct {
|
161 | 1f587329 | blueswir1 | uint32_t lowest; |
162 | 1f587329 | blueswir1 | uint32_t lower; |
163 | 1f587329 | blueswir1 | uint32_t upper; |
164 | 1f587329 | blueswir1 | uint32_t upmost; |
165 | 1f587329 | blueswir1 | } l; |
166 | 1f587329 | blueswir1 | struct {
|
167 | 1f587329 | blueswir1 | uint64_t lower; |
168 | 1f587329 | blueswir1 | uint64_t upper; |
169 | 1f587329 | blueswir1 | } ll; |
170 | 1f587329 | blueswir1 | #endif
|
171 | 1f587329 | blueswir1 | } CPU_QuadU; |
172 | 1f587329 | blueswir1 | #endif
|
173 | 1f587329 | blueswir1 | |
174 | 61382a50 | bellard | /* CPU memory access without any memory or io remapping */
|
175 | 61382a50 | bellard | |
176 | 83d73968 | bellard | /*
|
177 | 83d73968 | bellard | * the generic syntax for the memory accesses is:
|
178 | 83d73968 | bellard | *
|
179 | 83d73968 | bellard | * load: ld{type}{sign}{size}{endian}_{access_type}(ptr)
|
180 | 83d73968 | bellard | *
|
181 | 83d73968 | bellard | * store: st{type}{size}{endian}_{access_type}(ptr, val)
|
182 | 83d73968 | bellard | *
|
183 | 83d73968 | bellard | * type is:
|
184 | 83d73968 | bellard | * (empty): integer access
|
185 | 83d73968 | bellard | * f : float access
|
186 | 5fafdf24 | ths | *
|
187 | 83d73968 | bellard | * sign is:
|
188 | 83d73968 | bellard | * (empty): for floats or 32 bit size
|
189 | 83d73968 | bellard | * u : unsigned
|
190 | 83d73968 | bellard | * s : signed
|
191 | 83d73968 | bellard | *
|
192 | 83d73968 | bellard | * size is:
|
193 | 83d73968 | bellard | * b: 8 bits
|
194 | 83d73968 | bellard | * w: 16 bits
|
195 | 83d73968 | bellard | * l: 32 bits
|
196 | 83d73968 | bellard | * q: 64 bits
|
197 | 5fafdf24 | ths | *
|
198 | 83d73968 | bellard | * endian is:
|
199 | 83d73968 | bellard | * (empty): target cpu endianness or 8 bit access
|
200 | 83d73968 | bellard | * r : reversed target cpu endianness (not implemented yet)
|
201 | 83d73968 | bellard | * be : big endian (not implemented yet)
|
202 | 83d73968 | bellard | * le : little endian (not implemented yet)
|
203 | 83d73968 | bellard | *
|
204 | 83d73968 | bellard | * access_type is:
|
205 | 83d73968 | bellard | * raw : host memory access
|
206 | 83d73968 | bellard | * user : user mode access using soft MMU
|
207 | 83d73968 | bellard | * kernel : kernel mode access using soft MMU
|
208 | 83d73968 | bellard | */
|
209 | c27004ec | bellard | static inline int ldub_p(void *ptr) |
210 | 5a9fdfec | bellard | { |
211 | 5a9fdfec | bellard | return *(uint8_t *)ptr;
|
212 | 5a9fdfec | bellard | } |
213 | 5a9fdfec | bellard | |
214 | c27004ec | bellard | static inline int ldsb_p(void *ptr) |
215 | 5a9fdfec | bellard | { |
216 | 5a9fdfec | bellard | return *(int8_t *)ptr;
|
217 | 5a9fdfec | bellard | } |
218 | 5a9fdfec | bellard | |
219 | c27004ec | bellard | static inline void stb_p(void *ptr, int v) |
220 | 5a9fdfec | bellard | { |
221 | 5a9fdfec | bellard | *(uint8_t *)ptr = v; |
222 | 5a9fdfec | bellard | } |
223 | 5a9fdfec | bellard | |
224 | 5a9fdfec | bellard | /* NOTE: on arm, putting 2 in /proc/sys/debug/alignment so that the
|
225 | 5a9fdfec | bellard | kernel handles unaligned load/stores may give better results, but
|
226 | 5a9fdfec | bellard | it is a system wide setting : bad */
|
227 | 2df3b95d | bellard | #if defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
|
228 | 5a9fdfec | bellard | |
229 | 5a9fdfec | bellard | /* conservative code for little endian unaligned accesses */
|
230 | 2df3b95d | bellard | static inline int lduw_le_p(void *ptr) |
231 | 5a9fdfec | bellard | { |
232 | 5a9fdfec | bellard | #ifdef __powerpc__
|
233 | 5a9fdfec | bellard | int val;
|
234 | 5a9fdfec | bellard | __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr)); |
235 | 5a9fdfec | bellard | return val;
|
236 | 8384dd67 | blueswir1 | #elif defined(__sparc__)
|
237 | 8384dd67 | blueswir1 | #ifndef ASI_PRIMARY_LITTLE
|
238 | 8384dd67 | blueswir1 | #define ASI_PRIMARY_LITTLE 0x88 |
239 | 8384dd67 | blueswir1 | #endif
|
240 | 8384dd67 | blueswir1 | |
241 | 8384dd67 | blueswir1 | int val;
|
242 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("lduha [%1] %2, %0" : "=r" (val) : "r" (ptr), |
243 | 8384dd67 | blueswir1 | "i" (ASI_PRIMARY_LITTLE));
|
244 | 8384dd67 | blueswir1 | return val;
|
245 | 5a9fdfec | bellard | #else
|
246 | 5a9fdfec | bellard | uint8_t *p = ptr; |
247 | 5a9fdfec | bellard | return p[0] | (p[1] << 8); |
248 | 5a9fdfec | bellard | #endif
|
249 | 5a9fdfec | bellard | } |
250 | 5a9fdfec | bellard | |
251 | 2df3b95d | bellard | static inline int ldsw_le_p(void *ptr) |
252 | 5a9fdfec | bellard | { |
253 | 5a9fdfec | bellard | #ifdef __powerpc__
|
254 | 5a9fdfec | bellard | int val;
|
255 | 5a9fdfec | bellard | __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr)); |
256 | 5a9fdfec | bellard | return (int16_t)val;
|
257 | 8384dd67 | blueswir1 | #elif defined(__sparc__)
|
258 | 8384dd67 | blueswir1 | int val;
|
259 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("ldsha [%1] %2, %0" : "=r" (val) : "r" (ptr), |
260 | 8384dd67 | blueswir1 | "i" (ASI_PRIMARY_LITTLE));
|
261 | 8384dd67 | blueswir1 | return val;
|
262 | 5a9fdfec | bellard | #else
|
263 | 5a9fdfec | bellard | uint8_t *p = ptr; |
264 | 5a9fdfec | bellard | return (int16_t)(p[0] | (p[1] << 8)); |
265 | 5a9fdfec | bellard | #endif
|
266 | 5a9fdfec | bellard | } |
267 | 5a9fdfec | bellard | |
268 | 2df3b95d | bellard | static inline int ldl_le_p(void *ptr) |
269 | 5a9fdfec | bellard | { |
270 | 5a9fdfec | bellard | #ifdef __powerpc__
|
271 | 5a9fdfec | bellard | int val;
|
272 | 5a9fdfec | bellard | __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr)); |
273 | 5a9fdfec | bellard | return val;
|
274 | 8384dd67 | blueswir1 | #elif defined(__sparc__)
|
275 | 8384dd67 | blueswir1 | int val;
|
276 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("lduwa [%1] %2, %0" : "=r" (val) : "r" (ptr), |
277 | 8384dd67 | blueswir1 | "i" (ASI_PRIMARY_LITTLE));
|
278 | 8384dd67 | blueswir1 | return val;
|
279 | 5a9fdfec | bellard | #else
|
280 | 5a9fdfec | bellard | uint8_t *p = ptr; |
281 | 5a9fdfec | bellard | return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); |
282 | 5a9fdfec | bellard | #endif
|
283 | 5a9fdfec | bellard | } |
284 | 5a9fdfec | bellard | |
285 | 2df3b95d | bellard | static inline uint64_t ldq_le_p(void *ptr) |
286 | 5a9fdfec | bellard | { |
287 | 8384dd67 | blueswir1 | #if defined(__sparc__)
|
288 | 8384dd67 | blueswir1 | uint64_t val; |
289 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("ldxa [%1] %2, %0" : "=r" (val) : "r" (ptr), |
290 | 8384dd67 | blueswir1 | "i" (ASI_PRIMARY_LITTLE));
|
291 | 8384dd67 | blueswir1 | return val;
|
292 | 8384dd67 | blueswir1 | #else
|
293 | 5a9fdfec | bellard | uint8_t *p = ptr; |
294 | 5a9fdfec | bellard | uint32_t v1, v2; |
295 | f0aca822 | bellard | v1 = ldl_le_p(p); |
296 | f0aca822 | bellard | v2 = ldl_le_p(p + 4);
|
297 | 5a9fdfec | bellard | return v1 | ((uint64_t)v2 << 32); |
298 | 8384dd67 | blueswir1 | #endif
|
299 | 5a9fdfec | bellard | } |
300 | 5a9fdfec | bellard | |
301 | 2df3b95d | bellard | static inline void stw_le_p(void *ptr, int v) |
302 | 5a9fdfec | bellard | { |
303 | 5a9fdfec | bellard | #ifdef __powerpc__
|
304 | 5a9fdfec | bellard | __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*(uint16_t *)ptr) : "r" (v), "r" (ptr)); |
305 | 8384dd67 | blueswir1 | #elif defined(__sparc__)
|
306 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("stha %1, [%2] %3" : "=m" (*(uint16_t *)ptr) : "r" (v), |
307 | 8384dd67 | blueswir1 | "r" (ptr), "i" (ASI_PRIMARY_LITTLE)); |
308 | 5a9fdfec | bellard | #else
|
309 | 5a9fdfec | bellard | uint8_t *p = ptr; |
310 | 5a9fdfec | bellard | p[0] = v;
|
311 | 5a9fdfec | bellard | p[1] = v >> 8; |
312 | 5a9fdfec | bellard | #endif
|
313 | 5a9fdfec | bellard | } |
314 | 5a9fdfec | bellard | |
315 | 2df3b95d | bellard | static inline void stl_le_p(void *ptr, int v) |
316 | 5a9fdfec | bellard | { |
317 | 5a9fdfec | bellard | #ifdef __powerpc__
|
318 | 5a9fdfec | bellard | __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*(uint32_t *)ptr) : "r" (v), "r" (ptr)); |
319 | 8384dd67 | blueswir1 | #elif defined(__sparc__)
|
320 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("stwa %1, [%2] %3" : "=m" (*(uint32_t *)ptr) : "r" (v), |
321 | 8384dd67 | blueswir1 | "r" (ptr), "i" (ASI_PRIMARY_LITTLE)); |
322 | 5a9fdfec | bellard | #else
|
323 | 5a9fdfec | bellard | uint8_t *p = ptr; |
324 | 5a9fdfec | bellard | p[0] = v;
|
325 | 5a9fdfec | bellard | p[1] = v >> 8; |
326 | 5a9fdfec | bellard | p[2] = v >> 16; |
327 | 5a9fdfec | bellard | p[3] = v >> 24; |
328 | 5a9fdfec | bellard | #endif
|
329 | 5a9fdfec | bellard | } |
330 | 5a9fdfec | bellard | |
331 | 2df3b95d | bellard | static inline void stq_le_p(void *ptr, uint64_t v) |
332 | 5a9fdfec | bellard | { |
333 | 8384dd67 | blueswir1 | #if defined(__sparc__)
|
334 | 8384dd67 | blueswir1 | __asm__ __volatile__ ("stxa %1, [%2] %3" : "=m" (*(uint64_t *)ptr) : "r" (v), |
335 | 8384dd67 | blueswir1 | "r" (ptr), "i" (ASI_PRIMARY_LITTLE)); |
336 | 8384dd67 | blueswir1 | #undef ASI_PRIMARY_LITTLE
|
337 | 8384dd67 | blueswir1 | #else
|
338 | 5a9fdfec | bellard | uint8_t *p = ptr; |
339 | f0aca822 | bellard | stl_le_p(p, (uint32_t)v); |
340 | f0aca822 | bellard | stl_le_p(p + 4, v >> 32); |
341 | 8384dd67 | blueswir1 | #endif
|
342 | 5a9fdfec | bellard | } |
343 | 5a9fdfec | bellard | |
344 | 5a9fdfec | bellard | /* float access */
|
345 | 5a9fdfec | bellard | |
346 | 2df3b95d | bellard | static inline float32 ldfl_le_p(void *ptr) |
347 | 5a9fdfec | bellard | { |
348 | 5a9fdfec | bellard | union {
|
349 | 53cd6637 | bellard | float32 f; |
350 | 5a9fdfec | bellard | uint32_t i; |
351 | 5a9fdfec | bellard | } u; |
352 | 2df3b95d | bellard | u.i = ldl_le_p(ptr); |
353 | 5a9fdfec | bellard | return u.f;
|
354 | 5a9fdfec | bellard | } |
355 | 5a9fdfec | bellard | |
356 | 2df3b95d | bellard | static inline void stfl_le_p(void *ptr, float32 v) |
357 | 5a9fdfec | bellard | { |
358 | 5a9fdfec | bellard | union {
|
359 | 53cd6637 | bellard | float32 f; |
360 | 5a9fdfec | bellard | uint32_t i; |
361 | 5a9fdfec | bellard | } u; |
362 | 5a9fdfec | bellard | u.f = v; |
363 | 2df3b95d | bellard | stl_le_p(ptr, u.i); |
364 | 5a9fdfec | bellard | } |
365 | 5a9fdfec | bellard | |
366 | 2df3b95d | bellard | static inline float64 ldfq_le_p(void *ptr) |
367 | 5a9fdfec | bellard | { |
368 | 0ac4bd56 | bellard | CPU_DoubleU u; |
369 | 2df3b95d | bellard | u.l.lower = ldl_le_p(ptr); |
370 | 2df3b95d | bellard | u.l.upper = ldl_le_p(ptr + 4);
|
371 | 5a9fdfec | bellard | return u.d;
|
372 | 5a9fdfec | bellard | } |
373 | 5a9fdfec | bellard | |
374 | 2df3b95d | bellard | static inline void stfq_le_p(void *ptr, float64 v) |
375 | 5a9fdfec | bellard | { |
376 | 0ac4bd56 | bellard | CPU_DoubleU u; |
377 | 5a9fdfec | bellard | u.d = v; |
378 | 2df3b95d | bellard | stl_le_p(ptr, u.l.lower); |
379 | 2df3b95d | bellard | stl_le_p(ptr + 4, u.l.upper);
|
380 | 5a9fdfec | bellard | } |
381 | 5a9fdfec | bellard | |
382 | 2df3b95d | bellard | #else
|
383 | 2df3b95d | bellard | |
384 | 2df3b95d | bellard | static inline int lduw_le_p(void *ptr) |
385 | 2df3b95d | bellard | { |
386 | 2df3b95d | bellard | return *(uint16_t *)ptr;
|
387 | 2df3b95d | bellard | } |
388 | 2df3b95d | bellard | |
389 | 2df3b95d | bellard | static inline int ldsw_le_p(void *ptr) |
390 | 2df3b95d | bellard | { |
391 | 2df3b95d | bellard | return *(int16_t *)ptr;
|
392 | 2df3b95d | bellard | } |
393 | 93ac68bc | bellard | |
394 | 2df3b95d | bellard | static inline int ldl_le_p(void *ptr) |
395 | 2df3b95d | bellard | { |
396 | 2df3b95d | bellard | return *(uint32_t *)ptr;
|
397 | 2df3b95d | bellard | } |
398 | 2df3b95d | bellard | |
399 | 2df3b95d | bellard | static inline uint64_t ldq_le_p(void *ptr) |
400 | 2df3b95d | bellard | { |
401 | 2df3b95d | bellard | return *(uint64_t *)ptr;
|
402 | 2df3b95d | bellard | } |
403 | 2df3b95d | bellard | |
404 | 2df3b95d | bellard | static inline void stw_le_p(void *ptr, int v) |
405 | 2df3b95d | bellard | { |
406 | 2df3b95d | bellard | *(uint16_t *)ptr = v; |
407 | 2df3b95d | bellard | } |
408 | 2df3b95d | bellard | |
409 | 2df3b95d | bellard | static inline void stl_le_p(void *ptr, int v) |
410 | 2df3b95d | bellard | { |
411 | 2df3b95d | bellard | *(uint32_t *)ptr = v; |
412 | 2df3b95d | bellard | } |
413 | 2df3b95d | bellard | |
414 | 2df3b95d | bellard | static inline void stq_le_p(void *ptr, uint64_t v) |
415 | 2df3b95d | bellard | { |
416 | 2df3b95d | bellard | *(uint64_t *)ptr = v; |
417 | 2df3b95d | bellard | } |
418 | 2df3b95d | bellard | |
419 | 2df3b95d | bellard | /* float access */
|
420 | 2df3b95d | bellard | |
421 | 2df3b95d | bellard | static inline float32 ldfl_le_p(void *ptr) |
422 | 2df3b95d | bellard | { |
423 | 2df3b95d | bellard | return *(float32 *)ptr;
|
424 | 2df3b95d | bellard | } |
425 | 2df3b95d | bellard | |
426 | 2df3b95d | bellard | static inline float64 ldfq_le_p(void *ptr) |
427 | 2df3b95d | bellard | { |
428 | 2df3b95d | bellard | return *(float64 *)ptr;
|
429 | 2df3b95d | bellard | } |
430 | 2df3b95d | bellard | |
431 | 2df3b95d | bellard | static inline void stfl_le_p(void *ptr, float32 v) |
432 | 2df3b95d | bellard | { |
433 | 2df3b95d | bellard | *(float32 *)ptr = v; |
434 | 2df3b95d | bellard | } |
435 | 2df3b95d | bellard | |
436 | 2df3b95d | bellard | static inline void stfq_le_p(void *ptr, float64 v) |
437 | 2df3b95d | bellard | { |
438 | 2df3b95d | bellard | *(float64 *)ptr = v; |
439 | 2df3b95d | bellard | } |
440 | 2df3b95d | bellard | #endif
|
441 | 2df3b95d | bellard | |
442 | 2df3b95d | bellard | #if !defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
|
443 | 2df3b95d | bellard | |
444 | 2df3b95d | bellard | static inline int lduw_be_p(void *ptr) |
445 | 93ac68bc | bellard | { |
446 | 83d73968 | bellard | #if defined(__i386__)
|
447 | 83d73968 | bellard | int val;
|
448 | 83d73968 | bellard | asm volatile ("movzwl %1, %0\n" |
449 | 83d73968 | bellard | "xchgb %b0, %h0\n"
|
450 | 83d73968 | bellard | : "=q" (val)
|
451 | 83d73968 | bellard | : "m" (*(uint16_t *)ptr));
|
452 | 83d73968 | bellard | return val;
|
453 | 83d73968 | bellard | #else
|
454 | 93ac68bc | bellard | uint8_t *b = (uint8_t *) ptr; |
455 | 83d73968 | bellard | return ((b[0] << 8) | b[1]); |
456 | 83d73968 | bellard | #endif
|
457 | 93ac68bc | bellard | } |
458 | 93ac68bc | bellard | |
459 | 2df3b95d | bellard | static inline int ldsw_be_p(void *ptr) |
460 | 93ac68bc | bellard | { |
461 | 83d73968 | bellard | #if defined(__i386__)
|
462 | 83d73968 | bellard | int val;
|
463 | 83d73968 | bellard | asm volatile ("movzwl %1, %0\n" |
464 | 83d73968 | bellard | "xchgb %b0, %h0\n"
|
465 | 83d73968 | bellard | : "=q" (val)
|
466 | 83d73968 | bellard | : "m" (*(uint16_t *)ptr));
|
467 | 83d73968 | bellard | return (int16_t)val;
|
468 | 83d73968 | bellard | #else
|
469 | 83d73968 | bellard | uint8_t *b = (uint8_t *) ptr; |
470 | 83d73968 | bellard | return (int16_t)((b[0] << 8) | b[1]); |
471 | 83d73968 | bellard | #endif
|
472 | 93ac68bc | bellard | } |
473 | 93ac68bc | bellard | |
474 | 2df3b95d | bellard | static inline int ldl_be_p(void *ptr) |
475 | 93ac68bc | bellard | { |
476 | 4f2ac237 | bellard | #if defined(__i386__) || defined(__x86_64__)
|
477 | 83d73968 | bellard | int val;
|
478 | 83d73968 | bellard | asm volatile ("movl %1, %0\n" |
479 | 83d73968 | bellard | "bswap %0\n"
|
480 | 83d73968 | bellard | : "=r" (val)
|
481 | 83d73968 | bellard | : "m" (*(uint32_t *)ptr));
|
482 | 83d73968 | bellard | return val;
|
483 | 83d73968 | bellard | #else
|
484 | 93ac68bc | bellard | uint8_t *b = (uint8_t *) ptr; |
485 | 83d73968 | bellard | return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; |
486 | 83d73968 | bellard | #endif
|
487 | 93ac68bc | bellard | } |
488 | 93ac68bc | bellard | |
489 | 2df3b95d | bellard | static inline uint64_t ldq_be_p(void *ptr) |
490 | 93ac68bc | bellard | { |
491 | 93ac68bc | bellard | uint32_t a,b; |
492 | 2df3b95d | bellard | a = ldl_be_p(ptr); |
493 | 4d7a0880 | blueswir1 | b = ldl_be_p((uint8_t *)ptr + 4);
|
494 | 93ac68bc | bellard | return (((uint64_t)a<<32)|b); |
495 | 93ac68bc | bellard | } |
496 | 93ac68bc | bellard | |
497 | 2df3b95d | bellard | static inline void stw_be_p(void *ptr, int v) |
498 | 93ac68bc | bellard | { |
499 | 83d73968 | bellard | #if defined(__i386__)
|
500 | 83d73968 | bellard | asm volatile ("xchgb %b0, %h0\n" |
501 | 83d73968 | bellard | "movw %w0, %1\n"
|
502 | 83d73968 | bellard | : "=q" (v)
|
503 | 83d73968 | bellard | : "m" (*(uint16_t *)ptr), "0" (v)); |
504 | 83d73968 | bellard | #else
|
505 | 93ac68bc | bellard | uint8_t *d = (uint8_t *) ptr; |
506 | 93ac68bc | bellard | d[0] = v >> 8; |
507 | 93ac68bc | bellard | d[1] = v;
|
508 | 83d73968 | bellard | #endif
|
509 | 93ac68bc | bellard | } |
510 | 93ac68bc | bellard | |
511 | 2df3b95d | bellard | static inline void stl_be_p(void *ptr, int v) |
512 | 93ac68bc | bellard | { |
513 | 4f2ac237 | bellard | #if defined(__i386__) || defined(__x86_64__)
|
514 | 83d73968 | bellard | asm volatile ("bswap %0\n" |
515 | 83d73968 | bellard | "movl %0, %1\n"
|
516 | 83d73968 | bellard | : "=r" (v)
|
517 | 83d73968 | bellard | : "m" (*(uint32_t *)ptr), "0" (v)); |
518 | 83d73968 | bellard | #else
|
519 | 93ac68bc | bellard | uint8_t *d = (uint8_t *) ptr; |
520 | 93ac68bc | bellard | d[0] = v >> 24; |
521 | 93ac68bc | bellard | d[1] = v >> 16; |
522 | 93ac68bc | bellard | d[2] = v >> 8; |
523 | 93ac68bc | bellard | d[3] = v;
|
524 | 83d73968 | bellard | #endif
|
525 | 93ac68bc | bellard | } |
526 | 93ac68bc | bellard | |
527 | 2df3b95d | bellard | static inline void stq_be_p(void *ptr, uint64_t v) |
528 | 93ac68bc | bellard | { |
529 | 2df3b95d | bellard | stl_be_p(ptr, v >> 32);
|
530 | 4d7a0880 | blueswir1 | stl_be_p((uint8_t *)ptr + 4, v);
|
531 | 0ac4bd56 | bellard | } |
532 | 0ac4bd56 | bellard | |
533 | 0ac4bd56 | bellard | /* float access */
|
534 | 0ac4bd56 | bellard | |
535 | 2df3b95d | bellard | static inline float32 ldfl_be_p(void *ptr) |
536 | 0ac4bd56 | bellard | { |
537 | 0ac4bd56 | bellard | union {
|
538 | 53cd6637 | bellard | float32 f; |
539 | 0ac4bd56 | bellard | uint32_t i; |
540 | 0ac4bd56 | bellard | } u; |
541 | 2df3b95d | bellard | u.i = ldl_be_p(ptr); |
542 | 0ac4bd56 | bellard | return u.f;
|
543 | 0ac4bd56 | bellard | } |
544 | 0ac4bd56 | bellard | |
545 | 2df3b95d | bellard | static inline void stfl_be_p(void *ptr, float32 v) |
546 | 0ac4bd56 | bellard | { |
547 | 0ac4bd56 | bellard | union {
|
548 | 53cd6637 | bellard | float32 f; |
549 | 0ac4bd56 | bellard | uint32_t i; |
550 | 0ac4bd56 | bellard | } u; |
551 | 0ac4bd56 | bellard | u.f = v; |
552 | 2df3b95d | bellard | stl_be_p(ptr, u.i); |
553 | 0ac4bd56 | bellard | } |
554 | 0ac4bd56 | bellard | |
555 | 2df3b95d | bellard | static inline float64 ldfq_be_p(void *ptr) |
556 | 0ac4bd56 | bellard | { |
557 | 0ac4bd56 | bellard | CPU_DoubleU u; |
558 | 2df3b95d | bellard | u.l.upper = ldl_be_p(ptr); |
559 | 4d7a0880 | blueswir1 | u.l.lower = ldl_be_p((uint8_t *)ptr + 4);
|
560 | 0ac4bd56 | bellard | return u.d;
|
561 | 0ac4bd56 | bellard | } |
562 | 0ac4bd56 | bellard | |
563 | 2df3b95d | bellard | static inline void stfq_be_p(void *ptr, float64 v) |
564 | 0ac4bd56 | bellard | { |
565 | 0ac4bd56 | bellard | CPU_DoubleU u; |
566 | 0ac4bd56 | bellard | u.d = v; |
567 | 2df3b95d | bellard | stl_be_p(ptr, u.l.upper); |
568 | 4d7a0880 | blueswir1 | stl_be_p((uint8_t *)ptr + 4, u.l.lower);
|
569 | 93ac68bc | bellard | } |
570 | 93ac68bc | bellard | |
571 | 5a9fdfec | bellard | #else
|
572 | 5a9fdfec | bellard | |
573 | 2df3b95d | bellard | static inline int lduw_be_p(void *ptr) |
574 | 5a9fdfec | bellard | { |
575 | 5a9fdfec | bellard | return *(uint16_t *)ptr;
|
576 | 5a9fdfec | bellard | } |
577 | 5a9fdfec | bellard | |
578 | 2df3b95d | bellard | static inline int ldsw_be_p(void *ptr) |
579 | 5a9fdfec | bellard | { |
580 | 5a9fdfec | bellard | return *(int16_t *)ptr;
|
581 | 5a9fdfec | bellard | } |
582 | 5a9fdfec | bellard | |
583 | 2df3b95d | bellard | static inline int ldl_be_p(void *ptr) |
584 | 5a9fdfec | bellard | { |
585 | 5a9fdfec | bellard | return *(uint32_t *)ptr;
|
586 | 5a9fdfec | bellard | } |
587 | 5a9fdfec | bellard | |
588 | 2df3b95d | bellard | static inline uint64_t ldq_be_p(void *ptr) |
589 | 5a9fdfec | bellard | { |
590 | 5a9fdfec | bellard | return *(uint64_t *)ptr;
|
591 | 5a9fdfec | bellard | } |
592 | 5a9fdfec | bellard | |
593 | 2df3b95d | bellard | static inline void stw_be_p(void *ptr, int v) |
594 | 5a9fdfec | bellard | { |
595 | 5a9fdfec | bellard | *(uint16_t *)ptr = v; |
596 | 5a9fdfec | bellard | } |
597 | 5a9fdfec | bellard | |
598 | 2df3b95d | bellard | static inline void stl_be_p(void *ptr, int v) |
599 | 5a9fdfec | bellard | { |
600 | 5a9fdfec | bellard | *(uint32_t *)ptr = v; |
601 | 5a9fdfec | bellard | } |
602 | 5a9fdfec | bellard | |
603 | 2df3b95d | bellard | static inline void stq_be_p(void *ptr, uint64_t v) |
604 | 5a9fdfec | bellard | { |
605 | 5a9fdfec | bellard | *(uint64_t *)ptr = v; |
606 | 5a9fdfec | bellard | } |
607 | 5a9fdfec | bellard | |
608 | 5a9fdfec | bellard | /* float access */
|
609 | 5a9fdfec | bellard | |
610 | 2df3b95d | bellard | static inline float32 ldfl_be_p(void *ptr) |
611 | 5a9fdfec | bellard | { |
612 | 53cd6637 | bellard | return *(float32 *)ptr;
|
613 | 5a9fdfec | bellard | } |
614 | 5a9fdfec | bellard | |
615 | 2df3b95d | bellard | static inline float64 ldfq_be_p(void *ptr) |
616 | 5a9fdfec | bellard | { |
617 | 53cd6637 | bellard | return *(float64 *)ptr;
|
618 | 5a9fdfec | bellard | } |
619 | 5a9fdfec | bellard | |
620 | 2df3b95d | bellard | static inline void stfl_be_p(void *ptr, float32 v) |
621 | 5a9fdfec | bellard | { |
622 | 53cd6637 | bellard | *(float32 *)ptr = v; |
623 | 5a9fdfec | bellard | } |
624 | 5a9fdfec | bellard | |
625 | 2df3b95d | bellard | static inline void stfq_be_p(void *ptr, float64 v) |
626 | 5a9fdfec | bellard | { |
627 | 53cd6637 | bellard | *(float64 *)ptr = v; |
628 | 5a9fdfec | bellard | } |
629 | 2df3b95d | bellard | |
630 | 2df3b95d | bellard | #endif
|
631 | 2df3b95d | bellard | |
632 | 2df3b95d | bellard | /* target CPU memory access functions */
|
633 | 2df3b95d | bellard | #if defined(TARGET_WORDS_BIGENDIAN)
|
634 | 2df3b95d | bellard | #define lduw_p(p) lduw_be_p(p)
|
635 | 2df3b95d | bellard | #define ldsw_p(p) ldsw_be_p(p)
|
636 | 2df3b95d | bellard | #define ldl_p(p) ldl_be_p(p)
|
637 | 2df3b95d | bellard | #define ldq_p(p) ldq_be_p(p)
|
638 | 2df3b95d | bellard | #define ldfl_p(p) ldfl_be_p(p)
|
639 | 2df3b95d | bellard | #define ldfq_p(p) ldfq_be_p(p)
|
640 | 2df3b95d | bellard | #define stw_p(p, v) stw_be_p(p, v)
|
641 | 2df3b95d | bellard | #define stl_p(p, v) stl_be_p(p, v)
|
642 | 2df3b95d | bellard | #define stq_p(p, v) stq_be_p(p, v)
|
643 | 2df3b95d | bellard | #define stfl_p(p, v) stfl_be_p(p, v)
|
644 | 2df3b95d | bellard | #define stfq_p(p, v) stfq_be_p(p, v)
|
645 | 2df3b95d | bellard | #else
|
646 | 2df3b95d | bellard | #define lduw_p(p) lduw_le_p(p)
|
647 | 2df3b95d | bellard | #define ldsw_p(p) ldsw_le_p(p)
|
648 | 2df3b95d | bellard | #define ldl_p(p) ldl_le_p(p)
|
649 | 2df3b95d | bellard | #define ldq_p(p) ldq_le_p(p)
|
650 | 2df3b95d | bellard | #define ldfl_p(p) ldfl_le_p(p)
|
651 | 2df3b95d | bellard | #define ldfq_p(p) ldfq_le_p(p)
|
652 | 2df3b95d | bellard | #define stw_p(p, v) stw_le_p(p, v)
|
653 | 2df3b95d | bellard | #define stl_p(p, v) stl_le_p(p, v)
|
654 | 2df3b95d | bellard | #define stq_p(p, v) stq_le_p(p, v)
|
655 | 2df3b95d | bellard | #define stfl_p(p, v) stfl_le_p(p, v)
|
656 | 2df3b95d | bellard | #define stfq_p(p, v) stfq_le_p(p, v)
|
657 | 5a9fdfec | bellard | #endif
|
658 | 5a9fdfec | bellard | |
659 | 61382a50 | bellard | /* MMU memory access macros */
|
660 | 61382a50 | bellard | |
661 | 53a5960a | pbrook | #if defined(CONFIG_USER_ONLY)
|
662 | 53a5960a | pbrook | /* On some host systems the guest address space is reserved on the host.
|
663 | 53a5960a | pbrook | * This allows the guest address space to be offset to a convenient location.
|
664 | 53a5960a | pbrook | */
|
665 | 53a5960a | pbrook | //#define GUEST_BASE 0x20000000
|
666 | 53a5960a | pbrook | #define GUEST_BASE 0 |
667 | 53a5960a | pbrook | |
668 | 53a5960a | pbrook | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */
|
669 | 53a5960a | pbrook | #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) |
670 | 706b0a15 | ths | #define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE)) |
671 | 53a5960a | pbrook | |
672 | 53a5960a | pbrook | #define saddr(x) g2h(x)
|
673 | 53a5960a | pbrook | #define laddr(x) g2h(x)
|
674 | 53a5960a | pbrook | |
675 | 53a5960a | pbrook | #else /* !CONFIG_USER_ONLY */ |
676 | c27004ec | bellard | /* NOTE: we use double casts if pointers and target_ulong have
|
677 | c27004ec | bellard | different sizes */
|
678 | 53a5960a | pbrook | #define saddr(x) (uint8_t *)(long)(x) |
679 | 53a5960a | pbrook | #define laddr(x) (uint8_t *)(long)(x) |
680 | 53a5960a | pbrook | #endif
|
681 | 53a5960a | pbrook | |
682 | 53a5960a | pbrook | #define ldub_raw(p) ldub_p(laddr((p)))
|
683 | 53a5960a | pbrook | #define ldsb_raw(p) ldsb_p(laddr((p)))
|
684 | 53a5960a | pbrook | #define lduw_raw(p) lduw_p(laddr((p)))
|
685 | 53a5960a | pbrook | #define ldsw_raw(p) ldsw_p(laddr((p)))
|
686 | 53a5960a | pbrook | #define ldl_raw(p) ldl_p(laddr((p)))
|
687 | 53a5960a | pbrook | #define ldq_raw(p) ldq_p(laddr((p)))
|
688 | 53a5960a | pbrook | #define ldfl_raw(p) ldfl_p(laddr((p)))
|
689 | 53a5960a | pbrook | #define ldfq_raw(p) ldfq_p(laddr((p)))
|
690 | 53a5960a | pbrook | #define stb_raw(p, v) stb_p(saddr((p)), v)
|
691 | 53a5960a | pbrook | #define stw_raw(p, v) stw_p(saddr((p)), v)
|
692 | 53a5960a | pbrook | #define stl_raw(p, v) stl_p(saddr((p)), v)
|
693 | 53a5960a | pbrook | #define stq_raw(p, v) stq_p(saddr((p)), v)
|
694 | 53a5960a | pbrook | #define stfl_raw(p, v) stfl_p(saddr((p)), v)
|
695 | 53a5960a | pbrook | #define stfq_raw(p, v) stfq_p(saddr((p)), v)
|
696 | c27004ec | bellard | |
697 | c27004ec | bellard | |
698 | 5fafdf24 | ths | #if defined(CONFIG_USER_ONLY)
|
699 | 61382a50 | bellard | |
700 | 61382a50 | bellard | /* if user mode, no other memory access functions */
|
701 | 61382a50 | bellard | #define ldub(p) ldub_raw(p)
|
702 | 61382a50 | bellard | #define ldsb(p) ldsb_raw(p)
|
703 | 61382a50 | bellard | #define lduw(p) lduw_raw(p)
|
704 | 61382a50 | bellard | #define ldsw(p) ldsw_raw(p)
|
705 | 61382a50 | bellard | #define ldl(p) ldl_raw(p)
|
706 | 61382a50 | bellard | #define ldq(p) ldq_raw(p)
|
707 | 61382a50 | bellard | #define ldfl(p) ldfl_raw(p)
|
708 | 61382a50 | bellard | #define ldfq(p) ldfq_raw(p)
|
709 | 61382a50 | bellard | #define stb(p, v) stb_raw(p, v)
|
710 | 61382a50 | bellard | #define stw(p, v) stw_raw(p, v)
|
711 | 61382a50 | bellard | #define stl(p, v) stl_raw(p, v)
|
712 | 61382a50 | bellard | #define stq(p, v) stq_raw(p, v)
|
713 | 61382a50 | bellard | #define stfl(p, v) stfl_raw(p, v)
|
714 | 61382a50 | bellard | #define stfq(p, v) stfq_raw(p, v)
|
715 | 61382a50 | bellard | |
716 | 61382a50 | bellard | #define ldub_code(p) ldub_raw(p)
|
717 | 61382a50 | bellard | #define ldsb_code(p) ldsb_raw(p)
|
718 | 61382a50 | bellard | #define lduw_code(p) lduw_raw(p)
|
719 | 61382a50 | bellard | #define ldsw_code(p) ldsw_raw(p)
|
720 | 61382a50 | bellard | #define ldl_code(p) ldl_raw(p)
|
721 | bc98a7ef | j_mayer | #define ldq_code(p) ldq_raw(p)
|
722 | 61382a50 | bellard | |
723 | 61382a50 | bellard | #define ldub_kernel(p) ldub_raw(p)
|
724 | 61382a50 | bellard | #define ldsb_kernel(p) ldsb_raw(p)
|
725 | 61382a50 | bellard | #define lduw_kernel(p) lduw_raw(p)
|
726 | 61382a50 | bellard | #define ldsw_kernel(p) ldsw_raw(p)
|
727 | 61382a50 | bellard | #define ldl_kernel(p) ldl_raw(p)
|
728 | bc98a7ef | j_mayer | #define ldq_kernel(p) ldq_raw(p)
|
729 | 0ac4bd56 | bellard | #define ldfl_kernel(p) ldfl_raw(p)
|
730 | 0ac4bd56 | bellard | #define ldfq_kernel(p) ldfq_raw(p)
|
731 | 61382a50 | bellard | #define stb_kernel(p, v) stb_raw(p, v)
|
732 | 61382a50 | bellard | #define stw_kernel(p, v) stw_raw(p, v)
|
733 | 61382a50 | bellard | #define stl_kernel(p, v) stl_raw(p, v)
|
734 | 61382a50 | bellard | #define stq_kernel(p, v) stq_raw(p, v)
|
735 | 0ac4bd56 | bellard | #define stfl_kernel(p, v) stfl_raw(p, v)
|
736 | 0ac4bd56 | bellard | #define stfq_kernel(p, vt) stfq_raw(p, v)
|
737 | 61382a50 | bellard | |
738 | 61382a50 | bellard | #endif /* defined(CONFIG_USER_ONLY) */ |
739 | 61382a50 | bellard | |
740 | 5a9fdfec | bellard | /* page related stuff */
|
741 | 5a9fdfec | bellard | |
742 | 03875444 | aurel32 | #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS) |
743 | 5a9fdfec | bellard | #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1) |
744 | 5a9fdfec | bellard | #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK) |
745 | 5a9fdfec | bellard | |
746 | 53a5960a | pbrook | /* ??? These should be the larger of unsigned long and target_ulong. */
|
747 | 83fb7adf | bellard | extern unsigned long qemu_real_host_page_size; |
748 | 83fb7adf | bellard | extern unsigned long qemu_host_page_bits; |
749 | 83fb7adf | bellard | extern unsigned long qemu_host_page_size; |
750 | 83fb7adf | bellard | extern unsigned long qemu_host_page_mask; |
751 | 5a9fdfec | bellard | |
752 | 83fb7adf | bellard | #define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask) |
753 | 5a9fdfec | bellard | |
754 | 5a9fdfec | bellard | /* same as PROT_xxx */
|
755 | 5a9fdfec | bellard | #define PAGE_READ 0x0001 |
756 | 5a9fdfec | bellard | #define PAGE_WRITE 0x0002 |
757 | 5a9fdfec | bellard | #define PAGE_EXEC 0x0004 |
758 | 5a9fdfec | bellard | #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
|
759 | 5a9fdfec | bellard | #define PAGE_VALID 0x0008 |
760 | 5a9fdfec | bellard | /* original state of the write flag (used when tracking self-modifying
|
761 | 5a9fdfec | bellard | code */
|
762 | 5fafdf24 | ths | #define PAGE_WRITE_ORG 0x0010 |
763 | 50a9569b | balrog | #define PAGE_RESERVED 0x0020 |
764 | 5a9fdfec | bellard | |
765 | 5a9fdfec | bellard | void page_dump(FILE *f);
|
766 | 53a5960a | pbrook | int page_get_flags(target_ulong address);
|
767 | 53a5960a | pbrook | void page_set_flags(target_ulong start, target_ulong end, int flags); |
768 | 3d97b40b | ths | int page_check_range(target_ulong start, target_ulong len, int flags); |
769 | 5a9fdfec | bellard | |
770 | 26a5f13b | bellard | void cpu_exec_init_all(unsigned long tb_size); |
771 | c5be9f08 | ths | CPUState *cpu_copy(CPUState *env); |
772 | c5be9f08 | ths | |
773 | 5fafdf24 | ths | void cpu_dump_state(CPUState *env, FILE *f,
|
774 | 7fe48483 | bellard | int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
775 | 7fe48483 | bellard | int flags);
|
776 | 76a66253 | j_mayer | void cpu_dump_statistics (CPUState *env, FILE *f,
|
777 | 76a66253 | j_mayer | int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
778 | 76a66253 | j_mayer | int flags);
|
779 | 7fe48483 | bellard | |
780 | a90b7318 | balrog | void cpu_abort(CPUState *env, const char *fmt, ...) |
781 | c3d2689d | balrog | __attribute__ ((__format__ (__printf__, 2, 3))) |
782 | c3d2689d | balrog | __attribute__ ((__noreturn__)); |
783 | f0aca822 | bellard | extern CPUState *first_cpu;
|
784 | e2f22898 | bellard | extern CPUState *cpu_single_env;
|
785 | 2e70f6ef | pbrook | extern int64_t qemu_icount;
|
786 | 2e70f6ef | pbrook | extern int use_icount; |
787 | 5a9fdfec | bellard | |
788 | 9acbed06 | bellard | #define CPU_INTERRUPT_EXIT 0x01 /* wants exit from main loop */ |
789 | 9acbed06 | bellard | #define CPU_INTERRUPT_HARD 0x02 /* hardware interrupt pending */ |
790 | 9acbed06 | bellard | #define CPU_INTERRUPT_EXITTB 0x04 /* exit the current TB (use for x86 a20 case) */ |
791 | ef792f9d | bellard | #define CPU_INTERRUPT_TIMER 0x08 /* internal timer exception pending */ |
792 | 98699967 | bellard | #define CPU_INTERRUPT_FIQ 0x10 /* Fast interrupt pending. */ |
793 | ba3c64fb | bellard | #define CPU_INTERRUPT_HALT 0x20 /* CPU halt wanted */ |
794 | 3b21e03e | bellard | #define CPU_INTERRUPT_SMI 0x40 /* (x86 only) SMI interrupt pending */ |
795 | 6658ffb8 | pbrook | #define CPU_INTERRUPT_DEBUG 0x80 /* Debug event occured. */ |
796 | 0573fbfc | ths | #define CPU_INTERRUPT_VIRQ 0x100 /* virtual interrupt pending. */ |
797 | 474ea849 | aurel32 | #define CPU_INTERRUPT_NMI 0x200 /* NMI pending. */ |
798 | 98699967 | bellard | |
799 | 4690764b | bellard | void cpu_interrupt(CPUState *s, int mask); |
800 | b54ad049 | bellard | void cpu_reset_interrupt(CPUState *env, int mask); |
801 | 68a79315 | bellard | |
802 | 0f459d16 | pbrook | int cpu_watchpoint_insert(CPUState *env, target_ulong addr, int type); |
803 | 6658ffb8 | pbrook | int cpu_watchpoint_remove(CPUState *env, target_ulong addr);
|
804 | 7d03f82f | edgar_igl | void cpu_watchpoint_remove_all(CPUState *env);
|
805 | 2e12669a | bellard | int cpu_breakpoint_insert(CPUState *env, target_ulong pc);
|
806 | 2e12669a | bellard | int cpu_breakpoint_remove(CPUState *env, target_ulong pc);
|
807 | 7d03f82f | edgar_igl | void cpu_breakpoint_remove_all(CPUState *env);
|
808 | 60897d36 | edgar_igl | |
809 | 60897d36 | edgar_igl | #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */ |
810 | 60897d36 | edgar_igl | #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */ |
811 | 60897d36 | edgar_igl | #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */ |
812 | 60897d36 | edgar_igl | |
813 | c33a346e | bellard | void cpu_single_step(CPUState *env, int enabled); |
814 | d95dc32d | bellard | void cpu_reset(CPUState *s);
|
815 | 4c3a88a2 | bellard | |
816 | 13eb76e0 | bellard | /* Return the physical page corresponding to a virtual one. Use it
|
817 | 13eb76e0 | bellard | only for debugging because no protection checks are done. Return -1
|
818 | 13eb76e0 | bellard | if no page found. */
|
819 | 9b3c35e0 | j_mayer | target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr); |
820 | 13eb76e0 | bellard | |
821 | 5fafdf24 | ths | #define CPU_LOG_TB_OUT_ASM (1 << 0) |
822 | 9fddaa0c | bellard | #define CPU_LOG_TB_IN_ASM (1 << 1) |
823 | f193c797 | bellard | #define CPU_LOG_TB_OP (1 << 2) |
824 | f193c797 | bellard | #define CPU_LOG_TB_OP_OPT (1 << 3) |
825 | f193c797 | bellard | #define CPU_LOG_INT (1 << 4) |
826 | f193c797 | bellard | #define CPU_LOG_EXEC (1 << 5) |
827 | f193c797 | bellard | #define CPU_LOG_PCALL (1 << 6) |
828 | fd872598 | bellard | #define CPU_LOG_IOPORT (1 << 7) |
829 | 9fddaa0c | bellard | #define CPU_LOG_TB_CPU (1 << 8) |
830 | f193c797 | bellard | |
831 | f193c797 | bellard | /* define log items */
|
832 | f193c797 | bellard | typedef struct CPULogItem { |
833 | f193c797 | bellard | int mask;
|
834 | f193c797 | bellard | const char *name; |
835 | f193c797 | bellard | const char *help; |
836 | f193c797 | bellard | } CPULogItem; |
837 | f193c797 | bellard | |
838 | f193c797 | bellard | extern CPULogItem cpu_log_items[];
|
839 | f193c797 | bellard | |
840 | 34865134 | bellard | void cpu_set_log(int log_flags); |
841 | 34865134 | bellard | void cpu_set_log_filename(const char *filename); |
842 | f193c797 | bellard | int cpu_str_to_log_mask(const char *str); |
843 | 34865134 | bellard | |
844 | 09683d35 | bellard | /* IO ports API */
|
845 | 09683d35 | bellard | |
846 | 09683d35 | bellard | /* NOTE: as these functions may be even used when there is an isa
|
847 | 09683d35 | bellard | brige on non x86 targets, we always defined them */
|
848 | 09683d35 | bellard | #ifndef NO_CPU_IO_DEFS
|
849 | 09683d35 | bellard | void cpu_outb(CPUState *env, int addr, int val); |
850 | 09683d35 | bellard | void cpu_outw(CPUState *env, int addr, int val); |
851 | 09683d35 | bellard | void cpu_outl(CPUState *env, int addr, int val); |
852 | 09683d35 | bellard | int cpu_inb(CPUState *env, int addr); |
853 | 09683d35 | bellard | int cpu_inw(CPUState *env, int addr); |
854 | 09683d35 | bellard | int cpu_inl(CPUState *env, int addr); |
855 | 09683d35 | bellard | #endif
|
856 | 09683d35 | bellard | |
857 | 00f82b8a | aurel32 | /* address in the RAM (different from a physical address) */
|
858 | 00f82b8a | aurel32 | #ifdef USE_KQEMU
|
859 | 00f82b8a | aurel32 | typedef uint32_t ram_addr_t;
|
860 | 00f82b8a | aurel32 | #else
|
861 | 00f82b8a | aurel32 | typedef unsigned long ram_addr_t; |
862 | 00f82b8a | aurel32 | #endif
|
863 | 00f82b8a | aurel32 | |
864 | 33417e70 | bellard | /* memory API */
|
865 | 33417e70 | bellard | |
866 | 00f82b8a | aurel32 | extern ram_addr_t phys_ram_size;
|
867 | edf75d59 | bellard | extern int phys_ram_fd; |
868 | edf75d59 | bellard | extern uint8_t *phys_ram_base;
|
869 | 1ccde1cb | bellard | extern uint8_t *phys_ram_dirty;
|
870 | 00f82b8a | aurel32 | extern ram_addr_t ram_size;
|
871 | edf75d59 | bellard | |
872 | edf75d59 | bellard | /* physical memory access */
|
873 | 0f459d16 | pbrook | |
874 | 0f459d16 | pbrook | /* MMIO pages are identified by a combination of an IO device index and
|
875 | 0f459d16 | pbrook | 3 flags. The ROMD code stores the page ram offset in iotlb entry,
|
876 | 0f459d16 | pbrook | so only a limited number of ids are avaiable. */
|
877 | 0f459d16 | pbrook | |
878 | 0f459d16 | pbrook | #define IO_MEM_SHIFT 3 |
879 | 98699967 | bellard | #define IO_MEM_NB_ENTRIES (1 << (TARGET_PAGE_BITS - IO_MEM_SHIFT)) |
880 | edf75d59 | bellard | |
881 | edf75d59 | bellard | #define IO_MEM_RAM (0 << IO_MEM_SHIFT) /* hardcoded offset */ |
882 | edf75d59 | bellard | #define IO_MEM_ROM (1 << IO_MEM_SHIFT) /* hardcoded offset */ |
883 | edf75d59 | bellard | #define IO_MEM_UNASSIGNED (2 << IO_MEM_SHIFT) |
884 | 0f459d16 | pbrook | #define IO_MEM_NOTDIRTY (3 << IO_MEM_SHIFT) |
885 | 0f459d16 | pbrook | |
886 | 0f459d16 | pbrook | /* Acts like a ROM when read and like a device when written. */
|
887 | 2a4188a3 | bellard | #define IO_MEM_ROMD (1) |
888 | db7b5426 | blueswir1 | #define IO_MEM_SUBPAGE (2) |
889 | 4254fab8 | blueswir1 | #define IO_MEM_SUBWIDTH (4) |
890 | edf75d59 | bellard | |
891 | 0f459d16 | pbrook | /* Flags stored in the low bits of the TLB virtual address. These are
|
892 | 0f459d16 | pbrook | defined so that fast path ram access is all zeros. */
|
893 | 0f459d16 | pbrook | /* Zero if TLB entry is valid. */
|
894 | 0f459d16 | pbrook | #define TLB_INVALID_MASK (1 << 3) |
895 | 0f459d16 | pbrook | /* Set if TLB entry references a clean RAM page. The iotlb entry will
|
896 | 0f459d16 | pbrook | contain the page physical address. */
|
897 | 0f459d16 | pbrook | #define TLB_NOTDIRTY (1 << 4) |
898 | 0f459d16 | pbrook | /* Set if TLB entry is an IO callback. */
|
899 | 0f459d16 | pbrook | #define TLB_MMIO (1 << 5) |
900 | 0f459d16 | pbrook | |
901 | 7727994d | bellard | typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value); |
902 | 7727994d | bellard | typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr); |
903 | 33417e70 | bellard | |
904 | 5fafdf24 | ths | void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
905 | 00f82b8a | aurel32 | ram_addr_t size, |
906 | 00f82b8a | aurel32 | ram_addr_t phys_offset); |
907 | 00f82b8a | aurel32 | ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); |
908 | 00f82b8a | aurel32 | ram_addr_t qemu_ram_alloc(ram_addr_t); |
909 | e9a1ab19 | bellard | void qemu_ram_free(ram_addr_t addr);
|
910 | 33417e70 | bellard | int cpu_register_io_memory(int io_index, |
911 | 33417e70 | bellard | CPUReadMemoryFunc **mem_read, |
912 | 7727994d | bellard | CPUWriteMemoryFunc **mem_write, |
913 | 7727994d | bellard | void *opaque);
|
914 | 8926b517 | bellard | CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index);
|
915 | 8926b517 | bellard | CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index);
|
916 | 33417e70 | bellard | |
917 | 2e12669a | bellard | void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
918 | 13eb76e0 | bellard | int len, int is_write); |
919 | 5fafdf24 | ths | static inline void cpu_physical_memory_read(target_phys_addr_t addr, |
920 | 2e12669a | bellard | uint8_t *buf, int len)
|
921 | 8b1f24b0 | bellard | { |
922 | 8b1f24b0 | bellard | cpu_physical_memory_rw(addr, buf, len, 0);
|
923 | 8b1f24b0 | bellard | } |
924 | 5fafdf24 | ths | static inline void cpu_physical_memory_write(target_phys_addr_t addr, |
925 | 2e12669a | bellard | const uint8_t *buf, int len) |
926 | 8b1f24b0 | bellard | { |
927 | 8b1f24b0 | bellard | cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
|
928 | 8b1f24b0 | bellard | } |
929 | aab33094 | bellard | uint32_t ldub_phys(target_phys_addr_t addr); |
930 | aab33094 | bellard | uint32_t lduw_phys(target_phys_addr_t addr); |
931 | 8df1cd07 | bellard | uint32_t ldl_phys(target_phys_addr_t addr); |
932 | aab33094 | bellard | uint64_t ldq_phys(target_phys_addr_t addr); |
933 | 8df1cd07 | bellard | void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
|
934 | bc98a7ef | j_mayer | void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);
|
935 | aab33094 | bellard | void stb_phys(target_phys_addr_t addr, uint32_t val);
|
936 | aab33094 | bellard | void stw_phys(target_phys_addr_t addr, uint32_t val);
|
937 | 8df1cd07 | bellard | void stl_phys(target_phys_addr_t addr, uint32_t val);
|
938 | aab33094 | bellard | void stq_phys(target_phys_addr_t addr, uint64_t val);
|
939 | 8b1f24b0 | bellard | |
940 | 5fafdf24 | ths | void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
941 | d0ecd2aa | bellard | const uint8_t *buf, int len); |
942 | 5fafdf24 | ths | int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
943 | 8b1f24b0 | bellard | uint8_t *buf, int len, int is_write); |
944 | 13eb76e0 | bellard | |
945 | 04c504cc | bellard | #define VGA_DIRTY_FLAG 0x01 |
946 | 04c504cc | bellard | #define CODE_DIRTY_FLAG 0x02 |
947 | 0a962c02 | bellard | |
948 | 1ccde1cb | bellard | /* read dirty bit (return 0 or 1) */
|
949 | 04c504cc | bellard | static inline int cpu_physical_memory_is_dirty(ram_addr_t addr) |
950 | 1ccde1cb | bellard | { |
951 | 0a962c02 | bellard | return phys_ram_dirty[addr >> TARGET_PAGE_BITS] == 0xff; |
952 | 0a962c02 | bellard | } |
953 | 0a962c02 | bellard | |
954 | 5fafdf24 | ths | static inline int cpu_physical_memory_get_dirty(ram_addr_t addr, |
955 | 0a962c02 | bellard | int dirty_flags)
|
956 | 0a962c02 | bellard | { |
957 | 0a962c02 | bellard | return phys_ram_dirty[addr >> TARGET_PAGE_BITS] & dirty_flags;
|
958 | 1ccde1cb | bellard | } |
959 | 1ccde1cb | bellard | |
960 | 04c504cc | bellard | static inline void cpu_physical_memory_set_dirty(ram_addr_t addr) |
961 | 1ccde1cb | bellard | { |
962 | 0a962c02 | bellard | phys_ram_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
|
963 | 1ccde1cb | bellard | } |
964 | 1ccde1cb | bellard | |
965 | 04c504cc | bellard | void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
|
966 | 0a962c02 | bellard | int dirty_flags);
|
967 | 04c504cc | bellard | void cpu_tlb_update_dirty(CPUState *env);
|
968 | 1ccde1cb | bellard | |
969 | e3db7226 | bellard | void dump_exec_info(FILE *f,
|
970 | e3db7226 | bellard | int (*cpu_fprintf)(FILE *f, const char *fmt, ...)); |
971 | e3db7226 | bellard | |
972 | effedbc9 | bellard | /*******************************************/
|
973 | effedbc9 | bellard | /* host CPU ticks (if available) */
|
974 | effedbc9 | bellard | |
975 | effedbc9 | bellard | #if defined(__powerpc__)
|
976 | effedbc9 | bellard | |
977 | 5fafdf24 | ths | static inline uint32_t get_tbl(void) |
978 | effedbc9 | bellard | { |
979 | effedbc9 | bellard | uint32_t tbl; |
980 | effedbc9 | bellard | asm volatile("mftb %0" : "=r" (tbl)); |
981 | effedbc9 | bellard | return tbl;
|
982 | effedbc9 | bellard | } |
983 | effedbc9 | bellard | |
984 | 5fafdf24 | ths | static inline uint32_t get_tbu(void) |
985 | effedbc9 | bellard | { |
986 | effedbc9 | bellard | uint32_t tbl; |
987 | effedbc9 | bellard | asm volatile("mftbu %0" : "=r" (tbl)); |
988 | effedbc9 | bellard | return tbl;
|
989 | effedbc9 | bellard | } |
990 | effedbc9 | bellard | |
991 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks(void) |
992 | effedbc9 | bellard | { |
993 | effedbc9 | bellard | uint32_t l, h, h1; |
994 | effedbc9 | bellard | /* NOTE: we test if wrapping has occurred */
|
995 | effedbc9 | bellard | do {
|
996 | effedbc9 | bellard | h = get_tbu(); |
997 | effedbc9 | bellard | l = get_tbl(); |
998 | effedbc9 | bellard | h1 = get_tbu(); |
999 | effedbc9 | bellard | } while (h != h1);
|
1000 | effedbc9 | bellard | return ((int64_t)h << 32) | l; |
1001 | effedbc9 | bellard | } |
1002 | effedbc9 | bellard | |
1003 | effedbc9 | bellard | #elif defined(__i386__)
|
1004 | effedbc9 | bellard | |
1005 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks(void) |
1006 | 5f1ce948 | bellard | { |
1007 | 5f1ce948 | bellard | int64_t val; |
1008 | 5f1ce948 | bellard | asm volatile ("rdtsc" : "=A" (val)); |
1009 | 5f1ce948 | bellard | return val;
|
1010 | 5f1ce948 | bellard | } |
1011 | 5f1ce948 | bellard | |
1012 | effedbc9 | bellard | #elif defined(__x86_64__)
|
1013 | effedbc9 | bellard | |
1014 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks(void) |
1015 | effedbc9 | bellard | { |
1016 | effedbc9 | bellard | uint32_t low,high; |
1017 | effedbc9 | bellard | int64_t val; |
1018 | effedbc9 | bellard | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
1019 | effedbc9 | bellard | val = high; |
1020 | effedbc9 | bellard | val <<= 32;
|
1021 | effedbc9 | bellard | val |= low; |
1022 | effedbc9 | bellard | return val;
|
1023 | effedbc9 | bellard | } |
1024 | effedbc9 | bellard | |
1025 | f54b3f92 | aurel32 | #elif defined(__hppa__)
|
1026 | f54b3f92 | aurel32 | |
1027 | f54b3f92 | aurel32 | static inline int64_t cpu_get_real_ticks(void) |
1028 | f54b3f92 | aurel32 | { |
1029 | f54b3f92 | aurel32 | int val;
|
1030 | f54b3f92 | aurel32 | asm volatile ("mfctl %%cr16, %0" : "=r"(val)); |
1031 | f54b3f92 | aurel32 | return val;
|
1032 | f54b3f92 | aurel32 | } |
1033 | f54b3f92 | aurel32 | |
1034 | effedbc9 | bellard | #elif defined(__ia64)
|
1035 | effedbc9 | bellard | |
1036 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks(void) |
1037 | effedbc9 | bellard | { |
1038 | effedbc9 | bellard | int64_t val; |
1039 | effedbc9 | bellard | asm volatile ("mov %0 = ar.itc" : "=r"(val) :: "memory"); |
1040 | effedbc9 | bellard | return val;
|
1041 | effedbc9 | bellard | } |
1042 | effedbc9 | bellard | |
1043 | effedbc9 | bellard | #elif defined(__s390__)
|
1044 | effedbc9 | bellard | |
1045 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks(void) |
1046 | effedbc9 | bellard | { |
1047 | effedbc9 | bellard | int64_t val; |
1048 | effedbc9 | bellard | asm volatile("stck 0(%1)" : "=m" (val) : "a" (&val) : "cc"); |
1049 | effedbc9 | bellard | return val;
|
1050 | effedbc9 | bellard | } |
1051 | effedbc9 | bellard | |
1052 | 3142255c | blueswir1 | #elif defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
|
1053 | effedbc9 | bellard | |
1054 | effedbc9 | bellard | static inline int64_t cpu_get_real_ticks (void) |
1055 | effedbc9 | bellard | { |
1056 | effedbc9 | bellard | #if defined(_LP64)
|
1057 | effedbc9 | bellard | uint64_t rval; |
1058 | effedbc9 | bellard | asm volatile("rd %%tick,%0" : "=r"(rval)); |
1059 | effedbc9 | bellard | return rval;
|
1060 | effedbc9 | bellard | #else
|
1061 | effedbc9 | bellard | union {
|
1062 | effedbc9 | bellard | uint64_t i64; |
1063 | effedbc9 | bellard | struct {
|
1064 | effedbc9 | bellard | uint32_t high; |
1065 | effedbc9 | bellard | uint32_t low; |
1066 | effedbc9 | bellard | } i32; |
1067 | effedbc9 | bellard | } rval; |
1068 | effedbc9 | bellard | asm volatile("rd %%tick,%1; srlx %1,32,%0" |
1069 | effedbc9 | bellard | : "=r"(rval.i32.high), "=r"(rval.i32.low)); |
1070 | effedbc9 | bellard | return rval.i64;
|
1071 | effedbc9 | bellard | #endif
|
1072 | effedbc9 | bellard | } |
1073 | c4b89d18 | ths | |
1074 | c4b89d18 | ths | #elif defined(__mips__)
|
1075 | c4b89d18 | ths | |
1076 | c4b89d18 | ths | static inline int64_t cpu_get_real_ticks(void) |
1077 | c4b89d18 | ths | { |
1078 | c4b89d18 | ths | #if __mips_isa_rev >= 2 |
1079 | c4b89d18 | ths | uint32_t count; |
1080 | c4b89d18 | ths | static uint32_t cyc_per_count = 0; |
1081 | c4b89d18 | ths | |
1082 | c4b89d18 | ths | if (!cyc_per_count)
|
1083 | c4b89d18 | ths | __asm__ __volatile__("rdhwr %0, $3" : "=r" (cyc_per_count)); |
1084 | c4b89d18 | ths | |
1085 | c4b89d18 | ths | __asm__ __volatile__("rdhwr %1, $2" : "=r" (count)); |
1086 | c4b89d18 | ths | return (int64_t)(count * cyc_per_count);
|
1087 | c4b89d18 | ths | #else
|
1088 | c4b89d18 | ths | /* FIXME */
|
1089 | c4b89d18 | ths | static int64_t ticks = 0; |
1090 | c4b89d18 | ths | return ticks++;
|
1091 | c4b89d18 | ths | #endif
|
1092 | c4b89d18 | ths | } |
1093 | c4b89d18 | ths | |
1094 | 46152182 | pbrook | #else
|
1095 | 46152182 | pbrook | /* The host CPU doesn't have an easily accessible cycle counter.
|
1096 | 85028e4d | ths | Just return a monotonically increasing value. This will be
|
1097 | 85028e4d | ths | totally wrong, but hopefully better than nothing. */
|
1098 | 46152182 | pbrook | static inline int64_t cpu_get_real_ticks (void) |
1099 | 46152182 | pbrook | { |
1100 | 46152182 | pbrook | static int64_t ticks = 0; |
1101 | 46152182 | pbrook | return ticks++;
|
1102 | 46152182 | pbrook | } |
1103 | effedbc9 | bellard | #endif
|
1104 | effedbc9 | bellard | |
1105 | effedbc9 | bellard | /* profiling */
|
1106 | effedbc9 | bellard | #ifdef CONFIG_PROFILER
|
1107 | effedbc9 | bellard | static inline int64_t profile_getclock(void) |
1108 | effedbc9 | bellard | { |
1109 | effedbc9 | bellard | return cpu_get_real_ticks();
|
1110 | effedbc9 | bellard | } |
1111 | effedbc9 | bellard | |
1112 | 5f1ce948 | bellard | extern int64_t kqemu_time, kqemu_time_start;
|
1113 | 5f1ce948 | bellard | extern int64_t qemu_time, qemu_time_start;
|
1114 | 5f1ce948 | bellard | extern int64_t tlb_flush_time;
|
1115 | 5f1ce948 | bellard | extern int64_t kqemu_exec_count;
|
1116 | 5f1ce948 | bellard | extern int64_t dev_time;
|
1117 | 5f1ce948 | bellard | extern int64_t kqemu_ret_int_count;
|
1118 | 5f1ce948 | bellard | extern int64_t kqemu_ret_excp_count;
|
1119 | 5f1ce948 | bellard | extern int64_t kqemu_ret_intr_count;
|
1120 | 5f1ce948 | bellard | #endif
|
1121 | 5f1ce948 | bellard | |
1122 | 5a9fdfec | bellard | #endif /* CPU_ALL_H */ |