1 | /*
|
---|
2 | * defines common to all virtual CPUs
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003 Fabrice Bellard
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
22 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
23 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
24 | * a choice of LGPL license versions is made available with the language indicating
|
---|
25 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
26 | * of the LGPL is applied is otherwise unspecified.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef CPU_ALL_H
|
---|
30 | #define CPU_ALL_H
|
---|
31 |
|
---|
32 | #ifdef VBOX
|
---|
33 | # ifndef LOG_GROUP
|
---|
34 | # define LOG_GROUP LOG_GROUP_REM
|
---|
35 | # endif
|
---|
36 | # include <VBox/log.h>
|
---|
37 | # include <VBox/vmm/pgm.h> /* PGM_DYNAMIC_RAM_ALLOC */
|
---|
38 | #endif /* VBOX */
|
---|
39 | #include "qemu-common.h"
|
---|
40 | #include "cpu-common.h"
|
---|
41 |
|
---|
42 | /* some important defines:
|
---|
43 | *
|
---|
44 | * WORDS_ALIGNED : if defined, the host cpu can only make word aligned
|
---|
45 | * memory accesses.
|
---|
46 | *
|
---|
47 | * HOST_WORDS_BIGENDIAN : if defined, the host cpu is big endian and
|
---|
48 | * otherwise little endian.
|
---|
49 | *
|
---|
50 | * (TARGET_WORDS_ALIGNED : same for target cpu (not supported yet))
|
---|
51 | *
|
---|
52 | * TARGET_WORDS_BIGENDIAN : same for target cpu
|
---|
53 | */
|
---|
54 |
|
---|
55 | #include "softfloat.h"
|
---|
56 |
|
---|
57 | #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
|
---|
58 | #define BSWAP_NEEDED
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | #ifdef BSWAP_NEEDED
|
---|
62 |
|
---|
63 | static inline uint16_t tswap16(uint16_t s)
|
---|
64 | {
|
---|
65 | return bswap16(s);
|
---|
66 | }
|
---|
67 |
|
---|
68 | static inline uint32_t tswap32(uint32_t s)
|
---|
69 | {
|
---|
70 | return bswap32(s);
|
---|
71 | }
|
---|
72 |
|
---|
73 | static inline uint64_t tswap64(uint64_t s)
|
---|
74 | {
|
---|
75 | return bswap64(s);
|
---|
76 | }
|
---|
77 |
|
---|
78 | static inline void tswap16s(uint16_t *s)
|
---|
79 | {
|
---|
80 | *s = bswap16(*s);
|
---|
81 | }
|
---|
82 |
|
---|
83 | static inline void tswap32s(uint32_t *s)
|
---|
84 | {
|
---|
85 | *s = bswap32(*s);
|
---|
86 | }
|
---|
87 |
|
---|
88 | static inline void tswap64s(uint64_t *s)
|
---|
89 | {
|
---|
90 | *s = bswap64(*s);
|
---|
91 | }
|
---|
92 |
|
---|
93 | #else
|
---|
94 |
|
---|
95 | static inline uint16_t tswap16(uint16_t s)
|
---|
96 | {
|
---|
97 | return s;
|
---|
98 | }
|
---|
99 |
|
---|
100 | static inline uint32_t tswap32(uint32_t s)
|
---|
101 | {
|
---|
102 | return s;
|
---|
103 | }
|
---|
104 |
|
---|
105 | static inline uint64_t tswap64(uint64_t s)
|
---|
106 | {
|
---|
107 | return s;
|
---|
108 | }
|
---|
109 |
|
---|
110 | static inline void tswap16s(uint16_t *s)
|
---|
111 | {
|
---|
112 | }
|
---|
113 |
|
---|
114 | static inline void tswap32s(uint32_t *s)
|
---|
115 | {
|
---|
116 | }
|
---|
117 |
|
---|
118 | static inline void tswap64s(uint64_t *s)
|
---|
119 | {
|
---|
120 | }
|
---|
121 |
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | #if TARGET_LONG_SIZE == 4
|
---|
125 | #define tswapl(s) tswap32(s)
|
---|
126 | #define tswapls(s) tswap32s((uint32_t *)(s))
|
---|
127 | #define bswaptls(s) bswap32s(s)
|
---|
128 | #else
|
---|
129 | #define tswapl(s) tswap64(s)
|
---|
130 | #define tswapls(s) tswap64s((uint64_t *)(s))
|
---|
131 | #define bswaptls(s) bswap64s(s)
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | typedef union {
|
---|
135 | float32 f;
|
---|
136 | uint32_t l;
|
---|
137 | } CPU_FloatU;
|
---|
138 |
|
---|
139 | /* NOTE: arm FPA is horrible as double 32 bit words are stored in big
|
---|
140 | endian ! */
|
---|
141 | typedef union {
|
---|
142 | float64 d;
|
---|
143 | #if defined(HOST_WORDS_BIGENDIAN) \
|
---|
144 | || (defined(__arm__) && !defined(__VFP_FP__) && !defined(CONFIG_SOFTFLOAT))
|
---|
145 | struct {
|
---|
146 | uint32_t upper;
|
---|
147 | uint32_t lower;
|
---|
148 | } l;
|
---|
149 | #else
|
---|
150 | struct {
|
---|
151 | uint32_t lower;
|
---|
152 | uint32_t upper;
|
---|
153 | } l;
|
---|
154 | #endif
|
---|
155 | uint64_t ll;
|
---|
156 | } CPU_DoubleU;
|
---|
157 |
|
---|
158 | #ifdef TARGET_SPARC
|
---|
159 | typedef union {
|
---|
160 | float128 q;
|
---|
161 | #if defined(HOST_WORDS_BIGENDIAN) \
|
---|
162 | || (defined(__arm__) && !defined(__VFP_FP__) && !defined(CONFIG_SOFTFLOAT))
|
---|
163 | struct {
|
---|
164 | uint32_t upmost;
|
---|
165 | uint32_t upper;
|
---|
166 | uint32_t lower;
|
---|
167 | uint32_t lowest;
|
---|
168 | } l;
|
---|
169 | struct {
|
---|
170 | uint64_t upper;
|
---|
171 | uint64_t lower;
|
---|
172 | } ll;
|
---|
173 | #else
|
---|
174 | struct {
|
---|
175 | uint32_t lowest;
|
---|
176 | uint32_t lower;
|
---|
177 | uint32_t upper;
|
---|
178 | uint32_t upmost;
|
---|
179 | } l;
|
---|
180 | struct {
|
---|
181 | uint64_t lower;
|
---|
182 | uint64_t upper;
|
---|
183 | } ll;
|
---|
184 | #endif
|
---|
185 | } CPU_QuadU;
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | /* CPU memory access without any memory or io remapping */
|
---|
189 |
|
---|
190 | /*
|
---|
191 | * the generic syntax for the memory accesses is:
|
---|
192 | *
|
---|
193 | * load: ld{type}{sign}{size}{endian}_{access_type}(ptr)
|
---|
194 | *
|
---|
195 | * store: st{type}{size}{endian}_{access_type}(ptr, val)
|
---|
196 | *
|
---|
197 | * type is:
|
---|
198 | * (empty): integer access
|
---|
199 | * f : float access
|
---|
200 | *
|
---|
201 | * sign is:
|
---|
202 | * (empty): for floats or 32 bit size
|
---|
203 | * u : unsigned
|
---|
204 | * s : signed
|
---|
205 | *
|
---|
206 | * size is:
|
---|
207 | * b: 8 bits
|
---|
208 | * w: 16 bits
|
---|
209 | * l: 32 bits
|
---|
210 | * q: 64 bits
|
---|
211 | *
|
---|
212 | * endian is:
|
---|
213 | * (empty): target cpu endianness or 8 bit access
|
---|
214 | * r : reversed target cpu endianness (not implemented yet)
|
---|
215 | * be : big endian (not implemented yet)
|
---|
216 | * le : little endian (not implemented yet)
|
---|
217 | *
|
---|
218 | * access_type is:
|
---|
219 | * raw : host memory access
|
---|
220 | * user : user mode access using soft MMU
|
---|
221 | * kernel : kernel mode access using soft MMU
|
---|
222 | */
|
---|
223 |
|
---|
224 | #ifdef VBOX
|
---|
225 | void remAbort(int rc, const char *pszTip) __attribute__((__noreturn__));
|
---|
226 |
|
---|
227 | void remR3PhysRead(RTGCPHYS SrcGCPhys, void *pvDst, unsigned cb);
|
---|
228 | RTCCUINTREG remR3PhysReadU8(RTGCPHYS SrcGCPhys);
|
---|
229 | RTCCINTREG remR3PhysReadS8(RTGCPHYS SrcGCPhys);
|
---|
230 | RTCCUINTREG remR3PhysReadU16(RTGCPHYS SrcGCPhys);
|
---|
231 | RTCCINTREG remR3PhysReadS16(RTGCPHYS SrcGCPhys);
|
---|
232 | RTCCUINTREG remR3PhysReadU32(RTGCPHYS SrcGCPhys);
|
---|
233 | RTCCINTREG remR3PhysReadS32(RTGCPHYS SrcGCPhys);
|
---|
234 | uint64_t remR3PhysReadU64(RTGCPHYS SrcGCPhys);
|
---|
235 | int64_t remR3PhysReadS64(RTGCPHYS SrcGCPhys);
|
---|
236 | void remR3PhysWrite(RTGCPHYS DstGCPhys, const void *pvSrc, unsigned cb);
|
---|
237 | void remR3PhysWriteU8(RTGCPHYS DstGCPhys, uint8_t val);
|
---|
238 | void remR3PhysWriteU16(RTGCPHYS DstGCPhys, uint16_t val);
|
---|
239 | void remR3PhysWriteU32(RTGCPHYS DstGCPhys, uint32_t val);
|
---|
240 | void remR3PhysWriteU64(RTGCPHYS DstGCPhys, uint64_t val);
|
---|
241 |
|
---|
242 | # ifndef REM_PHYS_ADDR_IN_TLB
|
---|
243 | void *remR3TlbGCPhys2Ptr(CPUState *env1, target_ulong physAddr, int fWritable);
|
---|
244 | # endif
|
---|
245 |
|
---|
246 | #endif /* VBOX */
|
---|
247 |
|
---|
248 | #if defined(VBOX) && defined(REM_PHYS_ADDR_IN_TLB)
|
---|
249 |
|
---|
250 | DECLINLINE(uint8_t) ldub_p(const void *ptr)
|
---|
251 | {
|
---|
252 | VBOX_CHECK_ADDR(ptr);
|
---|
253 | return remR3PhysReadU8((uintptr_t)ptr);
|
---|
254 | }
|
---|
255 |
|
---|
256 | DECLINLINE(int8_t) ldsb_p(const void *ptr)
|
---|
257 | {
|
---|
258 | VBOX_CHECK_ADDR(ptr);
|
---|
259 | return remR3PhysReadS8((uintptr_t)ptr);
|
---|
260 | }
|
---|
261 |
|
---|
262 | DECLINLINE(void) stb_p(void *ptr, int v)
|
---|
263 | {
|
---|
264 | VBOX_CHECK_ADDR(ptr);
|
---|
265 | remR3PhysWriteU8((uintptr_t)ptr, v);
|
---|
266 | }
|
---|
267 |
|
---|
268 | DECLINLINE(uint32_t) lduw_le_p(const void *ptr)
|
---|
269 | {
|
---|
270 | VBOX_CHECK_ADDR(ptr);
|
---|
271 | return remR3PhysReadU16((uintptr_t)ptr);
|
---|
272 | }
|
---|
273 |
|
---|
274 | DECLINLINE(int32_t) ldsw_le_p(const void *ptr)
|
---|
275 | {
|
---|
276 | VBOX_CHECK_ADDR(ptr);
|
---|
277 | return remR3PhysReadS16((uintptr_t)ptr);
|
---|
278 | }
|
---|
279 |
|
---|
280 | DECLINLINE(void) stw_le_p(void *ptr, int v)
|
---|
281 | {
|
---|
282 | VBOX_CHECK_ADDR(ptr);
|
---|
283 | remR3PhysWriteU16((uintptr_t)ptr, v);
|
---|
284 | }
|
---|
285 |
|
---|
286 | DECLINLINE(uint32_t) ldl_le_p(const void *ptr)
|
---|
287 | {
|
---|
288 | VBOX_CHECK_ADDR(ptr);
|
---|
289 | return remR3PhysReadU32((uintptr_t)ptr);
|
---|
290 | }
|
---|
291 |
|
---|
292 | DECLINLINE(void) stl_le_p(void *ptr, int v)
|
---|
293 | {
|
---|
294 | VBOX_CHECK_ADDR(ptr);
|
---|
295 | remR3PhysWriteU32((uintptr_t)ptr, v);
|
---|
296 | }
|
---|
297 |
|
---|
298 | DECLINLINE(void) stq_le_p(void *ptr, uint64_t v)
|
---|
299 | {
|
---|
300 | VBOX_CHECK_ADDR(ptr);
|
---|
301 | remR3PhysWriteU64((uintptr_t)ptr, v);
|
---|
302 | }
|
---|
303 |
|
---|
304 | DECLINLINE(uint64_t) ldq_le_p(const void *ptr)
|
---|
305 | {
|
---|
306 | VBOX_CHECK_ADDR(ptr);
|
---|
307 | return remR3PhysReadU64((uintptr_t)ptr);
|
---|
308 | }
|
---|
309 |
|
---|
310 | # undef VBOX_CHECK_ADDR
|
---|
311 |
|
---|
312 | /* float access */
|
---|
313 |
|
---|
314 | DECLINLINE(float32) ldfl_le_p(const void *ptr)
|
---|
315 | {
|
---|
316 | union {
|
---|
317 | float32 f;
|
---|
318 | uint32_t i;
|
---|
319 | } u;
|
---|
320 | u.i = ldl_le_p(ptr);
|
---|
321 | return u.f;
|
---|
322 | }
|
---|
323 |
|
---|
324 | DECLINLINE(void) stfl_le_p(void *ptr, float32 v)
|
---|
325 | {
|
---|
326 | union {
|
---|
327 | float32 f;
|
---|
328 | uint32_t i;
|
---|
329 | } u;
|
---|
330 | u.f = v;
|
---|
331 | stl_le_p(ptr, u.i);
|
---|
332 | }
|
---|
333 |
|
---|
334 | DECLINLINE(float64) ldfq_le_p(const void *ptr)
|
---|
335 | {
|
---|
336 | CPU_DoubleU u;
|
---|
337 | u.l.lower = ldl_le_p(ptr);
|
---|
338 | u.l.upper = ldl_le_p((uint8_t*)ptr + 4);
|
---|
339 | return u.d;
|
---|
340 | }
|
---|
341 |
|
---|
342 | DECLINLINE(void) stfq_le_p(void *ptr, float64 v)
|
---|
343 | {
|
---|
344 | CPU_DoubleU u;
|
---|
345 | u.d = v;
|
---|
346 | stl_le_p(ptr, u.l.lower);
|
---|
347 | stl_le_p((uint8_t*)ptr + 4, u.l.upper);
|
---|
348 | }
|
---|
349 |
|
---|
350 | #else /* !VBOX */
|
---|
351 |
|
---|
352 | static inline int ldub_p(const void *ptr)
|
---|
353 | {
|
---|
354 | return *(uint8_t *)ptr;
|
---|
355 | }
|
---|
356 |
|
---|
357 | static inline int ldsb_p(const void *ptr)
|
---|
358 | {
|
---|
359 | return *(int8_t *)ptr;
|
---|
360 | }
|
---|
361 |
|
---|
362 | static inline void stb_p(void *ptr, int v)
|
---|
363 | {
|
---|
364 | *(uint8_t *)ptr = v;
|
---|
365 | }
|
---|
366 |
|
---|
367 | /* NOTE: on arm, putting 2 in /proc/sys/debug/alignment so that the
|
---|
368 | kernel handles unaligned load/stores may give better results, but
|
---|
369 | it is a system wide setting : bad */
|
---|
370 | #if defined(HOST_WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
|
---|
371 |
|
---|
372 | /* conservative code for little endian unaligned accesses */
|
---|
373 | static inline int lduw_le_p(const void *ptr)
|
---|
374 | {
|
---|
375 | #ifdef _ARCH_PPC
|
---|
376 | int val;
|
---|
377 | __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr));
|
---|
378 | return val;
|
---|
379 | #else
|
---|
380 | const uint8_t *p = ptr;
|
---|
381 | return p[0] | (p[1] << 8);
|
---|
382 | #endif
|
---|
383 | }
|
---|
384 |
|
---|
385 | static inline int ldsw_le_p(const void *ptr)
|
---|
386 | {
|
---|
387 | #ifdef _ARCH_PPC
|
---|
388 | int val;
|
---|
389 | __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr));
|
---|
390 | return (int16_t)val;
|
---|
391 | #else
|
---|
392 | const uint8_t *p = ptr;
|
---|
393 | return (int16_t)(p[0] | (p[1] << 8));
|
---|
394 | #endif
|
---|
395 | }
|
---|
396 |
|
---|
397 | static inline int ldl_le_p(const void *ptr)
|
---|
398 | {
|
---|
399 | #ifdef _ARCH_PPC
|
---|
400 | int val;
|
---|
401 | __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
|
---|
402 | return val;
|
---|
403 | #else
|
---|
404 | const uint8_t *p = ptr;
|
---|
405 | return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
---|
406 | #endif
|
---|
407 | }
|
---|
408 |
|
---|
409 | static inline uint64_t ldq_le_p(const void *ptr)
|
---|
410 | {
|
---|
411 | const uint8_t *p = ptr;
|
---|
412 | uint32_t v1, v2;
|
---|
413 | v1 = ldl_le_p(p);
|
---|
414 | v2 = ldl_le_p(p + 4);
|
---|
415 | return v1 | ((uint64_t)v2 << 32);
|
---|
416 | }
|
---|
417 |
|
---|
418 | static inline void stw_le_p(void *ptr, int v)
|
---|
419 | {
|
---|
420 | #ifdef _ARCH_PPC
|
---|
421 | __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*(uint16_t *)ptr) : "r" (v), "r" (ptr));
|
---|
422 | #else
|
---|
423 | uint8_t *p = ptr;
|
---|
424 | p[0] = v;
|
---|
425 | p[1] = v >> 8;
|
---|
426 | #endif
|
---|
427 | }
|
---|
428 |
|
---|
429 | static inline void stl_le_p(void *ptr, int v)
|
---|
430 | {
|
---|
431 | #ifdef _ARCH_PPC
|
---|
432 | __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*(uint32_t *)ptr) : "r" (v), "r" (ptr));
|
---|
433 | #else
|
---|
434 | uint8_t *p = ptr;
|
---|
435 | p[0] = v;
|
---|
436 | p[1] = v >> 8;
|
---|
437 | p[2] = v >> 16;
|
---|
438 | p[3] = v >> 24;
|
---|
439 | #endif
|
---|
440 | }
|
---|
441 |
|
---|
442 | static inline void stq_le_p(void *ptr, uint64_t v)
|
---|
443 | {
|
---|
444 | uint8_t *p = ptr;
|
---|
445 | stl_le_p(p, (uint32_t)v);
|
---|
446 | stl_le_p(p + 4, v >> 32);
|
---|
447 | }
|
---|
448 |
|
---|
449 | /* float access */
|
---|
450 |
|
---|
451 | static inline float32 ldfl_le_p(const void *ptr)
|
---|
452 | {
|
---|
453 | union {
|
---|
454 | float32 f;
|
---|
455 | uint32_t i;
|
---|
456 | } u;
|
---|
457 | u.i = ldl_le_p(ptr);
|
---|
458 | return u.f;
|
---|
459 | }
|
---|
460 |
|
---|
461 | static inline void stfl_le_p(void *ptr, float32 v)
|
---|
462 | {
|
---|
463 | union {
|
---|
464 | float32 f;
|
---|
465 | uint32_t i;
|
---|
466 | } u;
|
---|
467 | u.f = v;
|
---|
468 | stl_le_p(ptr, u.i);
|
---|
469 | }
|
---|
470 |
|
---|
471 | static inline float64 ldfq_le_p(const void *ptr)
|
---|
472 | {
|
---|
473 | CPU_DoubleU u;
|
---|
474 | u.l.lower = ldl_le_p(ptr);
|
---|
475 | u.l.upper = ldl_le_p(ptr + 4);
|
---|
476 | return u.d;
|
---|
477 | }
|
---|
478 |
|
---|
479 | static inline void stfq_le_p(void *ptr, float64 v)
|
---|
480 | {
|
---|
481 | CPU_DoubleU u;
|
---|
482 | u.d = v;
|
---|
483 | stl_le_p(ptr, u.l.lower);
|
---|
484 | stl_le_p(ptr + 4, u.l.upper);
|
---|
485 | }
|
---|
486 |
|
---|
487 | #else
|
---|
488 |
|
---|
489 | static inline int lduw_le_p(const void *ptr)
|
---|
490 | {
|
---|
491 | return *(uint16_t *)ptr;
|
---|
492 | }
|
---|
493 |
|
---|
494 | static inline int ldsw_le_p(const void *ptr)
|
---|
495 | {
|
---|
496 | return *(int16_t *)ptr;
|
---|
497 | }
|
---|
498 |
|
---|
499 | static inline int ldl_le_p(const void *ptr)
|
---|
500 | {
|
---|
501 | return *(uint32_t *)ptr;
|
---|
502 | }
|
---|
503 |
|
---|
504 | static inline uint64_t ldq_le_p(const void *ptr)
|
---|
505 | {
|
---|
506 | return *(uint64_t *)ptr;
|
---|
507 | }
|
---|
508 |
|
---|
509 | static inline void stw_le_p(void *ptr, int v)
|
---|
510 | {
|
---|
511 | *(uint16_t *)ptr = v;
|
---|
512 | }
|
---|
513 |
|
---|
514 | static inline void stl_le_p(void *ptr, int v)
|
---|
515 | {
|
---|
516 | *(uint32_t *)ptr = v;
|
---|
517 | }
|
---|
518 |
|
---|
519 | static inline void stq_le_p(void *ptr, uint64_t v)
|
---|
520 | {
|
---|
521 | *(uint64_t *)ptr = v;
|
---|
522 | }
|
---|
523 |
|
---|
524 | /* float access */
|
---|
525 |
|
---|
526 | static inline float32 ldfl_le_p(const void *ptr)
|
---|
527 | {
|
---|
528 | return *(float32 *)ptr;
|
---|
529 | }
|
---|
530 |
|
---|
531 | static inline float64 ldfq_le_p(const void *ptr)
|
---|
532 | {
|
---|
533 | return *(float64 *)ptr;
|
---|
534 | }
|
---|
535 |
|
---|
536 | static inline void stfl_le_p(void *ptr, float32 v)
|
---|
537 | {
|
---|
538 | *(float32 *)ptr = v;
|
---|
539 | }
|
---|
540 |
|
---|
541 | static inline void stfq_le_p(void *ptr, float64 v)
|
---|
542 | {
|
---|
543 | *(float64 *)ptr = v;
|
---|
544 | }
|
---|
545 | #endif
|
---|
546 | #endif /* !VBOX */
|
---|
547 |
|
---|
548 | #if !defined(HOST_WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
|
---|
549 |
|
---|
550 | static inline int lduw_be_p(const void *ptr)
|
---|
551 | {
|
---|
552 | #if defined(__i386__)
|
---|
553 | int val;
|
---|
554 | asm volatile ("movzwl %1, %0\n"
|
---|
555 | "xchgb %b0, %h0\n"
|
---|
556 | : "=q" (val)
|
---|
557 | : "m" (*(uint16_t *)ptr));
|
---|
558 | return val;
|
---|
559 | #else
|
---|
560 | const uint8_t *b = ptr;
|
---|
561 | return ((b[0] << 8) | b[1]);
|
---|
562 | #endif
|
---|
563 | }
|
---|
564 |
|
---|
565 | static inline int ldsw_be_p(const void *ptr)
|
---|
566 | {
|
---|
567 | #if defined(__i386__)
|
---|
568 | int val;
|
---|
569 | asm volatile ("movzwl %1, %0\n"
|
---|
570 | "xchgb %b0, %h0\n"
|
---|
571 | : "=q" (val)
|
---|
572 | : "m" (*(uint16_t *)ptr));
|
---|
573 | return (int16_t)val;
|
---|
574 | #else
|
---|
575 | const uint8_t *b = ptr;
|
---|
576 | return (int16_t)((b[0] << 8) | b[1]);
|
---|
577 | #endif
|
---|
578 | }
|
---|
579 |
|
---|
580 | static inline int ldl_be_p(const void *ptr)
|
---|
581 | {
|
---|
582 | #if defined(__i386__) || defined(__x86_64__)
|
---|
583 | int val;
|
---|
584 | asm volatile ("movl %1, %0\n"
|
---|
585 | "bswap %0\n"
|
---|
586 | : "=r" (val)
|
---|
587 | : "m" (*(uint32_t *)ptr));
|
---|
588 | return val;
|
---|
589 | #else
|
---|
590 | const uint8_t *b = ptr;
|
---|
591 | return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
|
---|
592 | #endif
|
---|
593 | }
|
---|
594 |
|
---|
595 | static inline uint64_t ldq_be_p(const void *ptr)
|
---|
596 | {
|
---|
597 | uint32_t a,b;
|
---|
598 | a = ldl_be_p(ptr);
|
---|
599 | b = ldl_be_p((uint8_t *)ptr + 4);
|
---|
600 | return (((uint64_t)a<<32)|b);
|
---|
601 | }
|
---|
602 |
|
---|
603 | static inline void stw_be_p(void *ptr, int v)
|
---|
604 | {
|
---|
605 | #if defined(__i386__)
|
---|
606 | asm volatile ("xchgb %b0, %h0\n"
|
---|
607 | "movw %w0, %1\n"
|
---|
608 | : "=q" (v)
|
---|
609 | : "m" (*(uint16_t *)ptr), "0" (v));
|
---|
610 | #else
|
---|
611 | uint8_t *d = (uint8_t *) ptr;
|
---|
612 | d[0] = v >> 8;
|
---|
613 | d[1] = v;
|
---|
614 | #endif
|
---|
615 | }
|
---|
616 |
|
---|
617 | static inline void stl_be_p(void *ptr, int v)
|
---|
618 | {
|
---|
619 | #if defined(__i386__) || defined(__x86_64__)
|
---|
620 | asm volatile ("bswap %0\n"
|
---|
621 | "movl %0, %1\n"
|
---|
622 | : "=r" (v)
|
---|
623 | : "m" (*(uint32_t *)ptr), "0" (v));
|
---|
624 | #else
|
---|
625 | uint8_t *d = (uint8_t *) ptr;
|
---|
626 | d[0] = v >> 24;
|
---|
627 | d[1] = v >> 16;
|
---|
628 | d[2] = v >> 8;
|
---|
629 | d[3] = v;
|
---|
630 | #endif
|
---|
631 | }
|
---|
632 |
|
---|
633 | static inline void stq_be_p(void *ptr, uint64_t v)
|
---|
634 | {
|
---|
635 | stl_be_p(ptr, v >> 32);
|
---|
636 | stl_be_p((uint8_t *)ptr + 4, v);
|
---|
637 | }
|
---|
638 |
|
---|
639 | /* float access */
|
---|
640 |
|
---|
641 | static inline float32 ldfl_be_p(const void *ptr)
|
---|
642 | {
|
---|
643 | union {
|
---|
644 | float32 f;
|
---|
645 | uint32_t i;
|
---|
646 | } u;
|
---|
647 | u.i = ldl_be_p(ptr);
|
---|
648 | return u.f;
|
---|
649 | }
|
---|
650 |
|
---|
651 | static inline void stfl_be_p(void *ptr, float32 v)
|
---|
652 | {
|
---|
653 | union {
|
---|
654 | float32 f;
|
---|
655 | uint32_t i;
|
---|
656 | } u;
|
---|
657 | u.f = v;
|
---|
658 | stl_be_p(ptr, u.i);
|
---|
659 | }
|
---|
660 |
|
---|
661 | static inline float64 ldfq_be_p(const void *ptr)
|
---|
662 | {
|
---|
663 | CPU_DoubleU u;
|
---|
664 | u.l.upper = ldl_be_p(ptr);
|
---|
665 | u.l.lower = ldl_be_p((uint8_t *)ptr + 4);
|
---|
666 | return u.d;
|
---|
667 | }
|
---|
668 |
|
---|
669 | static inline void stfq_be_p(void *ptr, float64 v)
|
---|
670 | {
|
---|
671 | CPU_DoubleU u;
|
---|
672 | u.d = v;
|
---|
673 | stl_be_p(ptr, u.l.upper);
|
---|
674 | stl_be_p((uint8_t *)ptr + 4, u.l.lower);
|
---|
675 | }
|
---|
676 |
|
---|
677 | #else
|
---|
678 |
|
---|
679 | static inline int lduw_be_p(const void *ptr)
|
---|
680 | {
|
---|
681 | return *(uint16_t *)ptr;
|
---|
682 | }
|
---|
683 |
|
---|
684 | static inline int ldsw_be_p(const void *ptr)
|
---|
685 | {
|
---|
686 | return *(int16_t *)ptr;
|
---|
687 | }
|
---|
688 |
|
---|
689 | static inline int ldl_be_p(const void *ptr)
|
---|
690 | {
|
---|
691 | return *(uint32_t *)ptr;
|
---|
692 | }
|
---|
693 |
|
---|
694 | static inline uint64_t ldq_be_p(const void *ptr)
|
---|
695 | {
|
---|
696 | return *(uint64_t *)ptr;
|
---|
697 | }
|
---|
698 |
|
---|
699 | static inline void stw_be_p(void *ptr, int v)
|
---|
700 | {
|
---|
701 | *(uint16_t *)ptr = v;
|
---|
702 | }
|
---|
703 |
|
---|
704 | static inline void stl_be_p(void *ptr, int v)
|
---|
705 | {
|
---|
706 | *(uint32_t *)ptr = v;
|
---|
707 | }
|
---|
708 |
|
---|
709 | static inline void stq_be_p(void *ptr, uint64_t v)
|
---|
710 | {
|
---|
711 | *(uint64_t *)ptr = v;
|
---|
712 | }
|
---|
713 |
|
---|
714 | /* float access */
|
---|
715 |
|
---|
716 | static inline float32 ldfl_be_p(const void *ptr)
|
---|
717 | {
|
---|
718 | return *(float32 *)ptr;
|
---|
719 | }
|
---|
720 |
|
---|
721 | static inline float64 ldfq_be_p(const void *ptr)
|
---|
722 | {
|
---|
723 | return *(float64 *)ptr;
|
---|
724 | }
|
---|
725 |
|
---|
726 | static inline void stfl_be_p(void *ptr, float32 v)
|
---|
727 | {
|
---|
728 | *(float32 *)ptr = v;
|
---|
729 | }
|
---|
730 |
|
---|
731 | static inline void stfq_be_p(void *ptr, float64 v)
|
---|
732 | {
|
---|
733 | *(float64 *)ptr = v;
|
---|
734 | }
|
---|
735 |
|
---|
736 | #endif
|
---|
737 |
|
---|
738 | /* target CPU memory access functions */
|
---|
739 | #if defined(TARGET_WORDS_BIGENDIAN)
|
---|
740 | #define lduw_p(p) lduw_be_p(p)
|
---|
741 | #define ldsw_p(p) ldsw_be_p(p)
|
---|
742 | #define ldl_p(p) ldl_be_p(p)
|
---|
743 | #define ldq_p(p) ldq_be_p(p)
|
---|
744 | #define ldfl_p(p) ldfl_be_p(p)
|
---|
745 | #define ldfq_p(p) ldfq_be_p(p)
|
---|
746 | #define stw_p(p, v) stw_be_p(p, v)
|
---|
747 | #define stl_p(p, v) stl_be_p(p, v)
|
---|
748 | #define stq_p(p, v) stq_be_p(p, v)
|
---|
749 | #define stfl_p(p, v) stfl_be_p(p, v)
|
---|
750 | #define stfq_p(p, v) stfq_be_p(p, v)
|
---|
751 | #else
|
---|
752 | #define lduw_p(p) lduw_le_p(p)
|
---|
753 | #define ldsw_p(p) ldsw_le_p(p)
|
---|
754 | #define ldl_p(p) ldl_le_p(p)
|
---|
755 | #define ldq_p(p) ldq_le_p(p)
|
---|
756 | #define ldfl_p(p) ldfl_le_p(p)
|
---|
757 | #define ldfq_p(p) ldfq_le_p(p)
|
---|
758 | #define stw_p(p, v) stw_le_p(p, v)
|
---|
759 | #define stl_p(p, v) stl_le_p(p, v)
|
---|
760 | #define stq_p(p, v) stq_le_p(p, v)
|
---|
761 | #define stfl_p(p, v) stfl_le_p(p, v)
|
---|
762 | #define stfq_p(p, v) stfq_le_p(p, v)
|
---|
763 | #endif
|
---|
764 |
|
---|
765 | /* MMU memory access macros */
|
---|
766 |
|
---|
767 | #if defined(CONFIG_USER_ONLY)
|
---|
768 | #include <assert.h>
|
---|
769 | #include "qemu-types.h"
|
---|
770 |
|
---|
771 | /* On some host systems the guest address space is reserved on the host.
|
---|
772 | * This allows the guest address space to be offset to a convenient location.
|
---|
773 | */
|
---|
774 | #if defined(CONFIG_USE_GUEST_BASE)
|
---|
775 | extern unsigned long guest_base;
|
---|
776 | extern int have_guest_base;
|
---|
777 | #define GUEST_BASE guest_base
|
---|
778 | #else
|
---|
779 | #define GUEST_BASE 0ul
|
---|
780 | #endif
|
---|
781 |
|
---|
782 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */
|
---|
783 | #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
|
---|
784 | #define h2g(x) ({ \
|
---|
785 | unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
|
---|
786 | /* Check if given address fits target address space */ \
|
---|
787 | assert(__ret == (abi_ulong)__ret); \
|
---|
788 | (abi_ulong)__ret; \
|
---|
789 | })
|
---|
790 | #define h2g_valid(x) ({ \
|
---|
791 | unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
|
---|
792 | (__guest == (abi_ulong)__guest); \
|
---|
793 | })
|
---|
794 |
|
---|
795 | #define saddr(x) g2h(x)
|
---|
796 | #define laddr(x) g2h(x)
|
---|
797 |
|
---|
798 | #else /* !CONFIG_USER_ONLY */
|
---|
799 | /* NOTE: we use double casts if pointers and target_ulong have
|
---|
800 | different sizes */
|
---|
801 | #define saddr(x) (uint8_t *)(long)(x)
|
---|
802 | #define laddr(x) (uint8_t *)(long)(x)
|
---|
803 | #endif
|
---|
804 |
|
---|
805 | #define ldub_raw(p) ldub_p(laddr((p)))
|
---|
806 | #define ldsb_raw(p) ldsb_p(laddr((p)))
|
---|
807 | #define lduw_raw(p) lduw_p(laddr((p)))
|
---|
808 | #define ldsw_raw(p) ldsw_p(laddr((p)))
|
---|
809 | #define ldl_raw(p) ldl_p(laddr((p)))
|
---|
810 | #define ldq_raw(p) ldq_p(laddr((p)))
|
---|
811 | #define ldfl_raw(p) ldfl_p(laddr((p)))
|
---|
812 | #define ldfq_raw(p) ldfq_p(laddr((p)))
|
---|
813 | #define stb_raw(p, v) stb_p(saddr((p)), v)
|
---|
814 | #define stw_raw(p, v) stw_p(saddr((p)), v)
|
---|
815 | #define stl_raw(p, v) stl_p(saddr((p)), v)
|
---|
816 | #define stq_raw(p, v) stq_p(saddr((p)), v)
|
---|
817 | #define stfl_raw(p, v) stfl_p(saddr((p)), v)
|
---|
818 | #define stfq_raw(p, v) stfq_p(saddr((p)), v)
|
---|
819 |
|
---|
820 |
|
---|
821 | #if defined(CONFIG_USER_ONLY)
|
---|
822 |
|
---|
823 | /* if user mode, no other memory access functions */
|
---|
824 | #define ldub(p) ldub_raw(p)
|
---|
825 | #define ldsb(p) ldsb_raw(p)
|
---|
826 | #define lduw(p) lduw_raw(p)
|
---|
827 | #define ldsw(p) ldsw_raw(p)
|
---|
828 | #define ldl(p) ldl_raw(p)
|
---|
829 | #define ldq(p) ldq_raw(p)
|
---|
830 | #define ldfl(p) ldfl_raw(p)
|
---|
831 | #define ldfq(p) ldfq_raw(p)
|
---|
832 | #define stb(p, v) stb_raw(p, v)
|
---|
833 | #define stw(p, v) stw_raw(p, v)
|
---|
834 | #define stl(p, v) stl_raw(p, v)
|
---|
835 | #define stq(p, v) stq_raw(p, v)
|
---|
836 | #define stfl(p, v) stfl_raw(p, v)
|
---|
837 | #define stfq(p, v) stfq_raw(p, v)
|
---|
838 |
|
---|
839 | #define ldub_code(p) ldub_raw(p)
|
---|
840 | #define ldsb_code(p) ldsb_raw(p)
|
---|
841 | #define lduw_code(p) lduw_raw(p)
|
---|
842 | #define ldsw_code(p) ldsw_raw(p)
|
---|
843 | #define ldl_code(p) ldl_raw(p)
|
---|
844 | #define ldq_code(p) ldq_raw(p)
|
---|
845 |
|
---|
846 | #define ldub_kernel(p) ldub_raw(p)
|
---|
847 | #define ldsb_kernel(p) ldsb_raw(p)
|
---|
848 | #define lduw_kernel(p) lduw_raw(p)
|
---|
849 | #define ldsw_kernel(p) ldsw_raw(p)
|
---|
850 | #define ldl_kernel(p) ldl_raw(p)
|
---|
851 | #define ldq_kernel(p) ldq_raw(p)
|
---|
852 | #define ldfl_kernel(p) ldfl_raw(p)
|
---|
853 | #define ldfq_kernel(p) ldfq_raw(p)
|
---|
854 | #define stb_kernel(p, v) stb_raw(p, v)
|
---|
855 | #define stw_kernel(p, v) stw_raw(p, v)
|
---|
856 | #define stl_kernel(p, v) stl_raw(p, v)
|
---|
857 | #define stq_kernel(p, v) stq_raw(p, v)
|
---|
858 | #define stfl_kernel(p, v) stfl_raw(p, v)
|
---|
859 | #define stfq_kernel(p, vt) stfq_raw(p, v)
|
---|
860 |
|
---|
861 | #endif /* defined(CONFIG_USER_ONLY) */
|
---|
862 |
|
---|
863 | /* page related stuff */
|
---|
864 |
|
---|
865 | #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
|
---|
866 | #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
|
---|
867 | #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
|
---|
868 |
|
---|
869 | /* ??? These should be the larger of unsigned long and target_ulong. */
|
---|
870 | extern unsigned long qemu_real_host_page_size;
|
---|
871 | extern unsigned long qemu_host_page_bits;
|
---|
872 | extern unsigned long qemu_host_page_size;
|
---|
873 | extern unsigned long qemu_host_page_mask;
|
---|
874 |
|
---|
875 | #define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
|
---|
876 |
|
---|
877 | /* same as PROT_xxx */
|
---|
878 | #define PAGE_READ 0x0001
|
---|
879 | #define PAGE_WRITE 0x0002
|
---|
880 | #define PAGE_EXEC 0x0004
|
---|
881 | #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
|
---|
882 | #define PAGE_VALID 0x0008
|
---|
883 | /* original state of the write flag (used when tracking self-modifying
|
---|
884 | code */
|
---|
885 | #define PAGE_WRITE_ORG 0x0010
|
---|
886 | #define PAGE_RESERVED 0x0020
|
---|
887 |
|
---|
888 | void page_dump(FILE *f);
|
---|
889 | int walk_memory_regions(void *,
|
---|
890 | int (*fn)(void *, unsigned long, unsigned long, unsigned long));
|
---|
891 | int page_get_flags(target_ulong address);
|
---|
892 | void page_set_flags(target_ulong start, target_ulong end, int flags);
|
---|
893 | int page_check_range(target_ulong start, target_ulong len, int flags);
|
---|
894 |
|
---|
895 | void cpu_exec_init_all(unsigned long tb_size);
|
---|
896 | CPUState *cpu_copy(CPUState *env);
|
---|
897 | CPUState *qemu_get_cpu(int cpu);
|
---|
898 |
|
---|
899 | void cpu_dump_state(CPUState *env, FILE *f,
|
---|
900 | int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
|
---|
901 | int flags);
|
---|
902 | void cpu_dump_statistics (CPUState *env, FILE *f,
|
---|
903 | int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
|
---|
904 | int flags);
|
---|
905 |
|
---|
906 | void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...)
|
---|
907 | #ifndef VBOX
|
---|
908 | __attribute__ ((__format__ (__printf__, 2, 3)));
|
---|
909 | #else
|
---|
910 | ;
|
---|
911 | #endif
|
---|
912 | extern CPUState *first_cpu;
|
---|
913 | extern CPUState *cpu_single_env;
|
---|
914 | extern int64_t qemu_icount;
|
---|
915 | extern int use_icount;
|
---|
916 |
|
---|
917 | #define CPU_INTERRUPT_HARD 0x02 /* hardware interrupt pending */
|
---|
918 | #define CPU_INTERRUPT_EXITTB 0x04 /* exit the current TB (use for x86 a20 case) */
|
---|
919 | #define CPU_INTERRUPT_TIMER 0x08 /* internal timer exception pending */
|
---|
920 | #define CPU_INTERRUPT_FIQ 0x10 /* Fast interrupt pending. */
|
---|
921 | #define CPU_INTERRUPT_HALT 0x20 /* CPU halt wanted */
|
---|
922 | #define CPU_INTERRUPT_SMI 0x40 /* (x86 only) SMI interrupt pending */
|
---|
923 | #define CPU_INTERRUPT_DEBUG 0x80 /* Debug event occured. */
|
---|
924 | #define CPU_INTERRUPT_VIRQ 0x100 /* virtual interrupt pending. */
|
---|
925 | #define CPU_INTERRUPT_NMI 0x200 /* NMI pending. */
|
---|
926 | #define CPU_INTERRUPT_INIT 0x400 /* INIT pending. */
|
---|
927 | #define CPU_INTERRUPT_SIPI 0x800 /* SIPI pending. */
|
---|
928 | #define CPU_INTERRUPT_MCE 0x1000 /* (x86 only) MCE pending. */
|
---|
929 |
|
---|
930 | #ifdef VBOX
|
---|
931 | /** Executes a single instruction. cpu_exec() will normally return EXCP_SINGLE_INSTR. */
|
---|
932 | # define CPU_INTERRUPT_SINGLE_INSTR 0x02000000
|
---|
933 | /** Executing a CPU_INTERRUPT_SINGLE_INSTR request, quit the cpu_loop. (for exceptions and suchlike) */
|
---|
934 | # define CPU_INTERRUPT_SINGLE_INSTR_IN_FLIGHT 0x04000000
|
---|
935 | /** VM execution was interrupted by VMR3Reset, VMR3Suspend or VMR3PowerOff. */
|
---|
936 | # define CPU_INTERRUPT_RC 0x08000000
|
---|
937 | /** Exit current TB to process an external request. */
|
---|
938 | # define CPU_INTERRUPT_EXTERNAL_EXIT 0x10000000
|
---|
939 | /** Exit current TB to process an external interrupt request. */
|
---|
940 | # define CPU_INTERRUPT_EXTERNAL_HARD 0x20000000
|
---|
941 | /** Exit current TB to process an external timer request. */
|
---|
942 | # define CPU_INTERRUPT_EXTERNAL_TIMER 0x40000000
|
---|
943 | /** Exit current TB to process an external DMA request. */
|
---|
944 | # define CPU_INTERRUPT_EXTERNAL_DMA 0x80000000
|
---|
945 | #endif /* VBOX */
|
---|
946 | void cpu_interrupt(CPUState *s, int mask);
|
---|
947 | void cpu_reset_interrupt(CPUState *env, int mask);
|
---|
948 |
|
---|
949 | void cpu_exit(CPUState *s);
|
---|
950 |
|
---|
951 | int qemu_cpu_has_work(CPUState *env);
|
---|
952 |
|
---|
953 | /* Breakpoint/watchpoint flags */
|
---|
954 | #define BP_MEM_READ 0x01
|
---|
955 | #define BP_MEM_WRITE 0x02
|
---|
956 | #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
|
---|
957 | #define BP_STOP_BEFORE_ACCESS 0x04
|
---|
958 | #define BP_WATCHPOINT_HIT 0x08
|
---|
959 | #define BP_GDB 0x10
|
---|
960 | #define BP_CPU 0x20
|
---|
961 |
|
---|
962 | int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
|
---|
963 | CPUBreakpoint **breakpoint);
|
---|
964 | int cpu_breakpoint_remove(CPUState *env, target_ulong pc, int flags);
|
---|
965 | void cpu_breakpoint_remove_by_ref(CPUState *env, CPUBreakpoint *breakpoint);
|
---|
966 | void cpu_breakpoint_remove_all(CPUState *env, int mask);
|
---|
967 | int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
|
---|
968 | int flags, CPUWatchpoint **watchpoint);
|
---|
969 | int cpu_watchpoint_remove(CPUState *env, target_ulong addr,
|
---|
970 | target_ulong len, int flags);
|
---|
971 | void cpu_watchpoint_remove_by_ref(CPUState *env, CPUWatchpoint *watchpoint);
|
---|
972 | void cpu_watchpoint_remove_all(CPUState *env, int mask);
|
---|
973 |
|
---|
974 | #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
|
---|
975 | #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
|
---|
976 | #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
|
---|
977 |
|
---|
978 | void cpu_single_step(CPUState *env, int enabled);
|
---|
979 | void cpu_reset(CPUState *s);
|
---|
980 |
|
---|
981 | /* Return the physical page corresponding to a virtual one. Use it
|
---|
982 | only for debugging because no protection checks are done. Return -1
|
---|
983 | if no page found. */
|
---|
984 | target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr);
|
---|
985 |
|
---|
986 | #define CPU_LOG_TB_OUT_ASM (1 << 0)
|
---|
987 | #define CPU_LOG_TB_IN_ASM (1 << 1)
|
---|
988 | #define CPU_LOG_TB_OP (1 << 2)
|
---|
989 | #define CPU_LOG_TB_OP_OPT (1 << 3)
|
---|
990 | #define CPU_LOG_INT (1 << 4)
|
---|
991 | #define CPU_LOG_EXEC (1 << 5)
|
---|
992 | #define CPU_LOG_PCALL (1 << 6)
|
---|
993 | #define CPU_LOG_IOPORT (1 << 7)
|
---|
994 | #define CPU_LOG_TB_CPU (1 << 8)
|
---|
995 | #define CPU_LOG_RESET (1 << 9)
|
---|
996 |
|
---|
997 | /* define log items */
|
---|
998 | typedef struct CPULogItem {
|
---|
999 | int mask;
|
---|
1000 | const char *name;
|
---|
1001 | const char *help;
|
---|
1002 | } CPULogItem;
|
---|
1003 |
|
---|
1004 | extern const CPULogItem cpu_log_items[];
|
---|
1005 |
|
---|
1006 | void cpu_set_log(int log_flags);
|
---|
1007 | void cpu_set_log_filename(const char *filename);
|
---|
1008 | int cpu_str_to_log_mask(const char *str);
|
---|
1009 |
|
---|
1010 | /* IO ports API */
|
---|
1011 | #include "ioport.h"
|
---|
1012 |
|
---|
1013 | /* memory API */
|
---|
1014 |
|
---|
1015 | #ifndef VBOX
|
---|
1016 | extern int phys_ram_fd;
|
---|
1017 | extern uint8_t *phys_ram_dirty;
|
---|
1018 | extern ram_addr_t ram_size;
|
---|
1019 | extern ram_addr_t last_ram_offset;
|
---|
1020 | #else /* VBOX */
|
---|
1021 | /** This is required for bounds checking the phys_ram_dirty accesses. */
|
---|
1022 | extern RTGCPHYS phys_ram_dirty_size;
|
---|
1023 | extern uint8_t *phys_ram_dirty;
|
---|
1024 | #endif /* VBOX */
|
---|
1025 |
|
---|
1026 | /* physical memory access */
|
---|
1027 |
|
---|
1028 | /* MMIO pages are identified by a combination of an IO device index and
|
---|
1029 | 3 flags. The ROMD code stores the page ram offset in iotlb entry,
|
---|
1030 | so only a limited number of ids are avaiable. */
|
---|
1031 |
|
---|
1032 | #define IO_MEM_NB_ENTRIES (1 << (TARGET_PAGE_BITS - IO_MEM_SHIFT))
|
---|
1033 |
|
---|
1034 | /* Flags stored in the low bits of the TLB virtual address. These are
|
---|
1035 | defined so that fast path ram access is all zeros. */
|
---|
1036 | /* Zero if TLB entry is valid. */
|
---|
1037 | #define TLB_INVALID_MASK (1 << 3)
|
---|
1038 | /* Set if TLB entry references a clean RAM page. The iotlb entry will
|
---|
1039 | contain the page physical address. */
|
---|
1040 | #define TLB_NOTDIRTY (1 << 4)
|
---|
1041 | /* Set if TLB entry is an IO callback. */
|
---|
1042 | #define TLB_MMIO (1 << 5)
|
---|
1043 |
|
---|
1044 | int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
---|
1045 | uint8_t *buf, int len, int is_write);
|
---|
1046 |
|
---|
1047 | #define VGA_DIRTY_FLAG 0x01
|
---|
1048 | #define CODE_DIRTY_FLAG 0x02
|
---|
1049 | #define MIGRATION_DIRTY_FLAG 0x08
|
---|
1050 |
|
---|
1051 | /* read dirty bit (return 0 or 1) */
|
---|
1052 | static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
|
---|
1053 | {
|
---|
1054 | #ifdef VBOX
|
---|
1055 | if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
|
---|
1056 | {
|
---|
1057 | Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
|
---|
1058 | /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
|
---|
1059 | return 0;
|
---|
1060 | }
|
---|
1061 | #endif /* VBOX */
|
---|
1062 | return phys_ram_dirty[addr >> TARGET_PAGE_BITS] == 0xff;
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | static inline int cpu_physical_memory_get_dirty(ram_addr_t addr,
|
---|
1066 | int dirty_flags)
|
---|
1067 | {
|
---|
1068 | #ifdef VBOX
|
---|
1069 | if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
|
---|
1070 | {
|
---|
1071 | Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
|
---|
1072 | /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
|
---|
1073 | return 0xff & dirty_flags; /** @todo I don't think this is the right thing to return, fix! */
|
---|
1074 | }
|
---|
1075 | #endif /* VBOX */
|
---|
1076 | return phys_ram_dirty[addr >> TARGET_PAGE_BITS] & dirty_flags;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
|
---|
1080 | {
|
---|
1081 | #ifdef VBOX
|
---|
1082 | if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
|
---|
1083 | {
|
---|
1084 | Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
|
---|
1085 | /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
|
---|
1086 | return;
|
---|
1087 | }
|
---|
1088 | #endif /* VBOX */
|
---|
1089 | phys_ram_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
|
---|
1093 | int dirty_flags);
|
---|
1094 | void cpu_tlb_update_dirty(CPUState *env);
|
---|
1095 |
|
---|
1096 | int cpu_physical_memory_set_dirty_tracking(int enable);
|
---|
1097 |
|
---|
1098 | int cpu_physical_memory_get_dirty_tracking(void);
|
---|
1099 |
|
---|
1100 | int cpu_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
|
---|
1101 | target_phys_addr_t end_addr);
|
---|
1102 |
|
---|
1103 | void dump_exec_info(FILE *f,
|
---|
1104 | int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
|
---|
1105 |
|
---|
1106 | /* Coalesced MMIO regions are areas where write operations can be reordered.
|
---|
1107 | * This usually implies that write operations are side-effect free. This allows
|
---|
1108 | * batching which can make a major impact on performance when using
|
---|
1109 | * virtualization.
|
---|
1110 | */
|
---|
1111 | void qemu_register_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
|
---|
1112 |
|
---|
1113 | void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
|
---|
1114 |
|
---|
1115 | /*******************************************/
|
---|
1116 | /* host CPU ticks (if available) */
|
---|
1117 |
|
---|
1118 | #if defined(_ARCH_PPC)
|
---|
1119 |
|
---|
1120 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1121 | {
|
---|
1122 | int64_t retval;
|
---|
1123 | #ifdef _ARCH_PPC64
|
---|
1124 | /* This reads timebase in one 64bit go and includes Cell workaround from:
|
---|
1125 | http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
|
---|
1126 | */
|
---|
1127 | __asm__ __volatile__ (
|
---|
1128 | "mftb %0\n\t"
|
---|
1129 | "cmpwi %0,0\n\t"
|
---|
1130 | "beq- $-8"
|
---|
1131 | : "=r" (retval));
|
---|
1132 | #else
|
---|
1133 | /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
|
---|
1134 | unsigned long junk;
|
---|
1135 | __asm__ __volatile__ (
|
---|
1136 | "mftbu %1\n\t"
|
---|
1137 | "mftb %L0\n\t"
|
---|
1138 | "mftbu %0\n\t"
|
---|
1139 | "cmpw %0,%1\n\t"
|
---|
1140 | "bne $-16"
|
---|
1141 | : "=r" (retval), "=r" (junk));
|
---|
1142 | #endif
|
---|
1143 | return retval;
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | #elif defined(__i386__)
|
---|
1147 |
|
---|
1148 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1149 | {
|
---|
1150 | int64_t val;
|
---|
1151 | asm volatile ("rdtsc" : "=A" (val));
|
---|
1152 | return val;
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | #elif defined(__x86_64__)
|
---|
1156 |
|
---|
1157 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1158 | {
|
---|
1159 | uint32_t low,high;
|
---|
1160 | int64_t val;
|
---|
1161 | asm volatile("rdtsc" : "=a" (low), "=d" (high));
|
---|
1162 | val = high;
|
---|
1163 | val <<= 32;
|
---|
1164 | val |= low;
|
---|
1165 | return val;
|
---|
1166 | }
|
---|
1167 |
|
---|
1168 | #elif defined(__hppa__)
|
---|
1169 |
|
---|
1170 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1171 | {
|
---|
1172 | int val;
|
---|
1173 | asm volatile ("mfctl %%cr16, %0" : "=r"(val));
|
---|
1174 | return val;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | #elif defined(__ia64)
|
---|
1178 |
|
---|
1179 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1180 | {
|
---|
1181 | int64_t val;
|
---|
1182 | asm volatile ("mov %0 = ar.itc" : "=r"(val) :: "memory");
|
---|
1183 | return val;
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | #elif defined(__s390__)
|
---|
1187 |
|
---|
1188 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1189 | {
|
---|
1190 | int64_t val;
|
---|
1191 | asm volatile("stck 0(%1)" : "=m" (val) : "a" (&val) : "cc");
|
---|
1192 | return val;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | #elif defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
|
---|
1196 |
|
---|
1197 | static inline int64_t cpu_get_real_ticks (void)
|
---|
1198 | {
|
---|
1199 | #if defined(_LP64)
|
---|
1200 | uint64_t rval;
|
---|
1201 | asm volatile("rd %%tick,%0" : "=r"(rval));
|
---|
1202 | return rval;
|
---|
1203 | #else
|
---|
1204 | union {
|
---|
1205 | uint64_t i64;
|
---|
1206 | struct {
|
---|
1207 | uint32_t high;
|
---|
1208 | uint32_t low;
|
---|
1209 | } i32;
|
---|
1210 | } rval;
|
---|
1211 | asm volatile("rd %%tick,%1; srlx %1,32,%0"
|
---|
1212 | : "=r"(rval.i32.high), "=r"(rval.i32.low));
|
---|
1213 | return rval.i64;
|
---|
1214 | #endif
|
---|
1215 | }
|
---|
1216 |
|
---|
1217 | #elif defined(__mips__) && \
|
---|
1218 | ((defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__))
|
---|
1219 | /*
|
---|
1220 | * binutils wants to use rdhwr only on mips32r2
|
---|
1221 | * but as linux kernel emulate it, it's fine
|
---|
1222 | * to use it.
|
---|
1223 | *
|
---|
1224 | */
|
---|
1225 | #define MIPS_RDHWR(rd, value) { \
|
---|
1226 | __asm__ __volatile__ ( \
|
---|
1227 | ".set push\n\t" \
|
---|
1228 | ".set mips32r2\n\t" \
|
---|
1229 | "rdhwr %0, "rd"\n\t" \
|
---|
1230 | ".set pop" \
|
---|
1231 | : "=r" (value)); \
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | static inline int64_t cpu_get_real_ticks(void)
|
---|
1235 | {
|
---|
1236 | /* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
|
---|
1237 | uint32_t count;
|
---|
1238 | static uint32_t cyc_per_count = 0;
|
---|
1239 |
|
---|
1240 | if (!cyc_per_count)
|
---|
1241 | MIPS_RDHWR("$3", cyc_per_count);
|
---|
1242 |
|
---|
1243 | MIPS_RDHWR("$2", count);
|
---|
1244 | return (int64_t)(count * cyc_per_count);
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | #else
|
---|
1248 | /* The host CPU doesn't have an easily accessible cycle counter.
|
---|
1249 | Just return a monotonically increasing value. This will be
|
---|
1250 | totally wrong, but hopefully better than nothing. */
|
---|
1251 | static inline int64_t cpu_get_real_ticks (void)
|
---|
1252 | {
|
---|
1253 | static int64_t ticks = 0;
|
---|
1254 | return ticks++;
|
---|
1255 | }
|
---|
1256 | #endif
|
---|
1257 |
|
---|
1258 | /* profiling */
|
---|
1259 | #ifdef CONFIG_PROFILER
|
---|
1260 | static inline int64_t profile_getclock(void)
|
---|
1261 | {
|
---|
1262 | return cpu_get_real_ticks();
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | extern int64_t qemu_time, qemu_time_start;
|
---|
1266 | extern int64_t tlb_flush_time;
|
---|
1267 | extern int64_t dev_time;
|
---|
1268 | #endif
|
---|
1269 |
|
---|
1270 | void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
|
---|
1271 | uint64_t mcg_status, uint64_t addr, uint64_t misc);
|
---|
1272 |
|
---|
1273 | #ifdef VBOX
|
---|
1274 | void tb_invalidate_virt(CPUState *env, uint32_t eip);
|
---|
1275 | #endif /* VBOX */
|
---|
1276 |
|
---|
1277 | #endif /* CPU_ALL_H */
|
---|