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