VirtualBox

source: vbox/trunk/src/recompiler/cpu-all.h@ 37270

Last change on this file since 37270 was 36175, checked in by vboxsync, 14 years ago

rem: Synced up to v0.11.1 (35bfc7324e2e6946c4113ada5db30553a1a7c40b) from git://git.savannah.nongnu.org/qemu.git.

  • Property svn:eol-style set to native
File size: 31.5 KB
Line 
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 * 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(WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
58#define BSWAP_NEEDED
59#endif
60
61#ifdef BSWAP_NEEDED
62
63static inline uint16_t tswap16(uint16_t s)
64{
65 return bswap16(s);
66}
67
68static inline uint32_t tswap32(uint32_t s)
69{
70 return bswap32(s);
71}
72
73static inline uint64_t tswap64(uint64_t s)
74{
75 return bswap64(s);
76}
77
78static inline void tswap16s(uint16_t *s)
79{
80 *s = bswap16(*s);
81}
82
83static inline void tswap32s(uint32_t *s)
84{
85 *s = bswap32(*s);
86}
87
88static inline void tswap64s(uint64_t *s)
89{
90 *s = bswap64(*s);
91}
92
93#else
94
95static inline uint16_t tswap16(uint16_t s)
96{
97 return s;
98}
99
100static inline uint32_t tswap32(uint32_t s)
101{
102 return s;
103}
104
105static inline uint64_t tswap64(uint64_t s)
106{
107 return s;
108}
109
110static inline void tswap16s(uint16_t *s)
111{
112}
113
114static inline void tswap32s(uint32_t *s)
115{
116}
117
118static 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
134typedef 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 ! */
141typedef union {
142 float64 d;
143#if defined(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
159typedef union {
160 float128 q;
161#if defined(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
225void remAbort(int rc, const char *pszTip) __attribute__((__noreturn__));
226
227void remR3PhysRead(RTGCPHYS SrcGCPhys, void *pvDst, unsigned cb);
228RTCCUINTREG remR3PhysReadU8(RTGCPHYS SrcGCPhys);
229RTCCINTREG remR3PhysReadS8(RTGCPHYS SrcGCPhys);
230RTCCUINTREG remR3PhysReadU16(RTGCPHYS SrcGCPhys);
231RTCCINTREG remR3PhysReadS16(RTGCPHYS SrcGCPhys);
232RTCCUINTREG remR3PhysReadU32(RTGCPHYS SrcGCPhys);
233RTCCINTREG remR3PhysReadS32(RTGCPHYS SrcGCPhys);
234uint64_t remR3PhysReadU64(RTGCPHYS SrcGCPhys);
235int64_t remR3PhysReadS64(RTGCPHYS SrcGCPhys);
236void remR3PhysWrite(RTGCPHYS DstGCPhys, const void *pvSrc, unsigned cb);
237void remR3PhysWriteU8(RTGCPHYS DstGCPhys, uint8_t val);
238void remR3PhysWriteU16(RTGCPHYS DstGCPhys, uint16_t val);
239void remR3PhysWriteU32(RTGCPHYS DstGCPhys, uint32_t val);
240void remR3PhysWriteU64(RTGCPHYS DstGCPhys, uint64_t val);
241
242#ifndef REM_PHYS_ADDR_IN_TLB
243void *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
250DECLINLINE(uint8_t) ldub_p(const void *ptr)
251{
252 VBOX_CHECK_ADDR(ptr);
253 return remR3PhysReadU8((uintptr_t)ptr);
254}
255
256DECLINLINE(int8_t) ldsb_p(const void *ptr)
257{
258 VBOX_CHECK_ADDR(ptr);
259 return remR3PhysReadS8((uintptr_t)ptr);
260}
261
262DECLINLINE(void) stb_p(void *ptr, int v)
263{
264 VBOX_CHECK_ADDR(ptr);
265 remR3PhysWriteU8((uintptr_t)ptr, v);
266}
267
268DECLINLINE(uint32_t) lduw_le_p(const void *ptr)
269{
270 VBOX_CHECK_ADDR(ptr);
271 return remR3PhysReadU16((uintptr_t)ptr);
272}
273
274DECLINLINE(int32_t) ldsw_le_p(const void *ptr)
275{
276 VBOX_CHECK_ADDR(ptr);
277 return remR3PhysReadS16((uintptr_t)ptr);
278}
279
280DECLINLINE(void) stw_le_p(void *ptr, int v)
281{
282 VBOX_CHECK_ADDR(ptr);
283 remR3PhysWriteU16((uintptr_t)ptr, v);
284}
285
286DECLINLINE(uint32_t) ldl_le_p(const void *ptr)
287{
288 VBOX_CHECK_ADDR(ptr);
289 return remR3PhysReadU32((uintptr_t)ptr);
290}
291
292DECLINLINE(void) stl_le_p(void *ptr, int v)
293{
294 VBOX_CHECK_ADDR(ptr);
295 remR3PhysWriteU32((uintptr_t)ptr, v);
296}
297
298DECLINLINE(void) stq_le_p(void *ptr, uint64_t v)
299{
300 VBOX_CHECK_ADDR(ptr);
301 remR3PhysWriteU64((uintptr_t)ptr, v);
302}
303
304DECLINLINE(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
314DECLINLINE(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
324DECLINLINE(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
334DECLINLINE(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
342DECLINLINE(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
352static inline int ldub_p(const void *ptr)
353{
354 return *(uint8_t *)ptr;
355}
356
357static inline int ldsb_p(const void *ptr)
358{
359 return *(int8_t *)ptr;
360}
361
362static 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(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
371
372/* conservative code for little endian unaligned accesses */
373static 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
385static 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
397static 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
409static 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
418static 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
429static 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
442static 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
451static 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
461static 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
471static 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
479static 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
489static inline int lduw_le_p(const void *ptr)
490{
491 return *(uint16_t *)ptr;
492}
493
494static inline int ldsw_le_p(const void *ptr)
495{
496 return *(int16_t *)ptr;
497}
498
499static inline int ldl_le_p(const void *ptr)
500{
501 return *(uint32_t *)ptr;
502}
503
504static inline uint64_t ldq_le_p(const void *ptr)
505{
506 return *(uint64_t *)ptr;
507}
508
509static inline void stw_le_p(void *ptr, int v)
510{
511 *(uint16_t *)ptr = v;
512}
513
514static inline void stl_le_p(void *ptr, int v)
515{
516 *(uint32_t *)ptr = v;
517}
518
519static inline void stq_le_p(void *ptr, uint64_t v)
520{
521 *(uint64_t *)ptr = v;
522}
523
524/* float access */
525
526static inline float32 ldfl_le_p(const void *ptr)
527{
528 return *(float32 *)ptr;
529}
530
531static inline float64 ldfq_le_p(const void *ptr)
532{
533 return *(float64 *)ptr;
534}
535
536static inline void stfl_le_p(void *ptr, float32 v)
537{
538 *(float32 *)ptr = v;
539}
540
541static inline void stfq_le_p(void *ptr, float64 v)
542{
543 *(float64 *)ptr = v;
544}
545#endif
546#endif /* !VBOX */
547
548#if !defined(WORDS_BIGENDIAN) || defined(WORDS_ALIGNED)
549
550static 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
565static 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
580static 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
595static 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
603static 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
617static 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
633static 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
641static 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
651static 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
661static 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
669static 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
679static inline int lduw_be_p(const void *ptr)
680{
681 return *(uint16_t *)ptr;
682}
683
684static inline int ldsw_be_p(const void *ptr)
685{
686 return *(int16_t *)ptr;
687}
688
689static inline int ldl_be_p(const void *ptr)
690{
691 return *(uint32_t *)ptr;
692}
693
694static inline uint64_t ldq_be_p(const void *ptr)
695{
696 return *(uint64_t *)ptr;
697}
698
699static inline void stw_be_p(void *ptr, int v)
700{
701 *(uint16_t *)ptr = v;
702}
703
704static inline void stl_be_p(void *ptr, int v)
705{
706 *(uint32_t *)ptr = v;
707}
708
709static inline void stq_be_p(void *ptr, uint64_t v)
710{
711 *(uint64_t *)ptr = v;
712}
713
714/* float access */
715
716static inline float32 ldfl_be_p(const void *ptr)
717{
718 return *(float32 *)ptr;
719}
720
721static inline float64 ldfq_be_p(const void *ptr)
722{
723 return *(float64 *)ptr;
724}
725
726static inline void stfl_be_p(void *ptr, float32 v)
727{
728 *(float32 *)ptr = v;
729}
730
731static 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//#define GUEST_BASE 0x20000000
775#define GUEST_BASE 0
776
777/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
778#define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
779#define h2g(x) ({ \
780 unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
781 /* Check if given address fits target address space */ \
782 assert(__ret == (abi_ulong)__ret); \
783 (abi_ulong)__ret; \
784})
785#define h2g_valid(x) ({ \
786 unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
787 (__guest == (abi_ulong)__guest); \
788})
789
790#define saddr(x) g2h(x)
791#define laddr(x) g2h(x)
792
793#else /* !CONFIG_USER_ONLY */
794/* NOTE: we use double casts if pointers and target_ulong have
795 different sizes */
796#define saddr(x) (uint8_t *)(long)(x)
797#define laddr(x) (uint8_t *)(long)(x)
798#endif
799
800#define ldub_raw(p) ldub_p(laddr((p)))
801#define ldsb_raw(p) ldsb_p(laddr((p)))
802#define lduw_raw(p) lduw_p(laddr((p)))
803#define ldsw_raw(p) ldsw_p(laddr((p)))
804#define ldl_raw(p) ldl_p(laddr((p)))
805#define ldq_raw(p) ldq_p(laddr((p)))
806#define ldfl_raw(p) ldfl_p(laddr((p)))
807#define ldfq_raw(p) ldfq_p(laddr((p)))
808#define stb_raw(p, v) stb_p(saddr((p)), v)
809#define stw_raw(p, v) stw_p(saddr((p)), v)
810#define stl_raw(p, v) stl_p(saddr((p)), v)
811#define stq_raw(p, v) stq_p(saddr((p)), v)
812#define stfl_raw(p, v) stfl_p(saddr((p)), v)
813#define stfq_raw(p, v) stfq_p(saddr((p)), v)
814
815
816#if defined(CONFIG_USER_ONLY)
817
818/* if user mode, no other memory access functions */
819#define ldub(p) ldub_raw(p)
820#define ldsb(p) ldsb_raw(p)
821#define lduw(p) lduw_raw(p)
822#define ldsw(p) ldsw_raw(p)
823#define ldl(p) ldl_raw(p)
824#define ldq(p) ldq_raw(p)
825#define ldfl(p) ldfl_raw(p)
826#define ldfq(p) ldfq_raw(p)
827#define stb(p, v) stb_raw(p, v)
828#define stw(p, v) stw_raw(p, v)
829#define stl(p, v) stl_raw(p, v)
830#define stq(p, v) stq_raw(p, v)
831#define stfl(p, v) stfl_raw(p, v)
832#define stfq(p, v) stfq_raw(p, v)
833
834#define ldub_code(p) ldub_raw(p)
835#define ldsb_code(p) ldsb_raw(p)
836#define lduw_code(p) lduw_raw(p)
837#define ldsw_code(p) ldsw_raw(p)
838#define ldl_code(p) ldl_raw(p)
839#define ldq_code(p) ldq_raw(p)
840
841#define ldub_kernel(p) ldub_raw(p)
842#define ldsb_kernel(p) ldsb_raw(p)
843#define lduw_kernel(p) lduw_raw(p)
844#define ldsw_kernel(p) ldsw_raw(p)
845#define ldl_kernel(p) ldl_raw(p)
846#define ldq_kernel(p) ldq_raw(p)
847#define ldfl_kernel(p) ldfl_raw(p)
848#define ldfq_kernel(p) ldfq_raw(p)
849#define stb_kernel(p, v) stb_raw(p, v)
850#define stw_kernel(p, v) stw_raw(p, v)
851#define stl_kernel(p, v) stl_raw(p, v)
852#define stq_kernel(p, v) stq_raw(p, v)
853#define stfl_kernel(p, v) stfl_raw(p, v)
854#define stfq_kernel(p, vt) stfq_raw(p, v)
855
856#endif /* defined(CONFIG_USER_ONLY) */
857
858/* page related stuff */
859
860#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
861#define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
862#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
863
864/* ??? These should be the larger of unsigned long and target_ulong. */
865extern unsigned long qemu_real_host_page_size;
866extern unsigned long qemu_host_page_bits;
867extern unsigned long qemu_host_page_size;
868extern unsigned long qemu_host_page_mask;
869
870#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
871
872/* same as PROT_xxx */
873#define PAGE_READ 0x0001
874#define PAGE_WRITE 0x0002
875#define PAGE_EXEC 0x0004
876#define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
877#define PAGE_VALID 0x0008
878/* original state of the write flag (used when tracking self-modifying
879 code */
880#define PAGE_WRITE_ORG 0x0010
881#define PAGE_RESERVED 0x0020
882
883void page_dump(FILE *f);
884int walk_memory_regions(void *,
885 int (*fn)(void *, unsigned long, unsigned long, unsigned long));
886int page_get_flags(target_ulong address);
887void page_set_flags(target_ulong start, target_ulong end, int flags);
888int page_check_range(target_ulong start, target_ulong len, int flags);
889
890void cpu_exec_init_all(unsigned long tb_size);
891CPUState *cpu_copy(CPUState *env);
892CPUState *qemu_get_cpu(int cpu);
893
894void cpu_dump_state(CPUState *env, FILE *f,
895 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
896 int flags);
897void cpu_dump_statistics (CPUState *env, FILE *f,
898 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
899 int flags);
900
901void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...)
902#ifndef VBOX
903 __attribute__ ((__format__ (__printf__, 2, 3)));
904#else
905 ;
906#endif
907extern CPUState *first_cpu;
908extern CPUState *cpu_single_env;
909extern int64_t qemu_icount;
910extern int use_icount;
911
912#define CPU_INTERRUPT_HARD 0x02 /* hardware interrupt pending */
913#define CPU_INTERRUPT_EXITTB 0x04 /* exit the current TB (use for x86 a20 case) */
914#define CPU_INTERRUPT_TIMER 0x08 /* internal timer exception pending */
915#define CPU_INTERRUPT_FIQ 0x10 /* Fast interrupt pending. */
916#define CPU_INTERRUPT_HALT 0x20 /* CPU halt wanted */
917#define CPU_INTERRUPT_SMI 0x40 /* (x86 only) SMI interrupt pending */
918#define CPU_INTERRUPT_DEBUG 0x80 /* Debug event occured. */
919#define CPU_INTERRUPT_VIRQ 0x100 /* virtual interrupt pending. */
920#define CPU_INTERRUPT_NMI 0x200 /* NMI pending. */
921#define CPU_INTERRUPT_INIT 0x400 /* INIT pending. */
922#define CPU_INTERRUPT_SIPI 0x800 /* SIPI pending. */
923#define CPU_INTERRUPT_MCE 0x1000 /* (x86 only) MCE pending. */
924
925#ifdef VBOX
926/** Executes a single instruction. cpu_exec() will normally return EXCP_SINGLE_INSTR. */
927# define CPU_INTERRUPT_SINGLE_INSTR 0x02000000
928/** Executing a CPU_INTERRUPT_SINGLE_INSTR request, quit the cpu_loop. (for exceptions and suchlike) */
929# define CPU_INTERRUPT_SINGLE_INSTR_IN_FLIGHT 0x04000000
930/** VM execution was interrupted by VMR3Reset, VMR3Suspend or VMR3PowerOff. */
931# define CPU_INTERRUPT_RC 0x08000000
932/** Exit current TB to process an external request. */
933# define CPU_INTERRUPT_EXTERNAL_EXIT 0x10000000
934/** Exit current TB to process an external interrupt request. */
935# define CPU_INTERRUPT_EXTERNAL_HARD 0x20000000
936/** Exit current TB to process an external timer request. */
937# define CPU_INTERRUPT_EXTERNAL_TIMER 0x40000000
938/** Exit current TB to process an external DMA request. */
939# define CPU_INTERRUPT_EXTERNAL_DMA 0x80000000
940#endif /* VBOX */
941void cpu_interrupt(CPUState *s, int mask);
942void cpu_reset_interrupt(CPUState *env, int mask);
943
944void cpu_exit(CPUState *s);
945
946int qemu_cpu_has_work(CPUState *env);
947
948/* Breakpoint/watchpoint flags */
949#define BP_MEM_READ 0x01
950#define BP_MEM_WRITE 0x02
951#define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
952#define BP_STOP_BEFORE_ACCESS 0x04
953#define BP_WATCHPOINT_HIT 0x08
954#define BP_GDB 0x10
955#define BP_CPU 0x20
956
957int cpu_breakpoint_insert(CPUState *env, target_ulong pc, int flags,
958 CPUBreakpoint **breakpoint);
959int cpu_breakpoint_remove(CPUState *env, target_ulong pc, int flags);
960void cpu_breakpoint_remove_by_ref(CPUState *env, CPUBreakpoint *breakpoint);
961void cpu_breakpoint_remove_all(CPUState *env, int mask);
962int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
963 int flags, CPUWatchpoint **watchpoint);
964int cpu_watchpoint_remove(CPUState *env, target_ulong addr,
965 target_ulong len, int flags);
966void cpu_watchpoint_remove_by_ref(CPUState *env, CPUWatchpoint *watchpoint);
967void cpu_watchpoint_remove_all(CPUState *env, int mask);
968
969#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
970#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
971#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
972
973void cpu_single_step(CPUState *env, int enabled);
974void cpu_reset(CPUState *s);
975
976/* Return the physical page corresponding to a virtual one. Use it
977 only for debugging because no protection checks are done. Return -1
978 if no page found. */
979target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr);
980
981#define CPU_LOG_TB_OUT_ASM (1 << 0)
982#define CPU_LOG_TB_IN_ASM (1 << 1)
983#define CPU_LOG_TB_OP (1 << 2)
984#define CPU_LOG_TB_OP_OPT (1 << 3)
985#define CPU_LOG_INT (1 << 4)
986#define CPU_LOG_EXEC (1 << 5)
987#define CPU_LOG_PCALL (1 << 6)
988#define CPU_LOG_IOPORT (1 << 7)
989#define CPU_LOG_TB_CPU (1 << 8)
990#define CPU_LOG_RESET (1 << 9)
991
992/* define log items */
993typedef struct CPULogItem {
994 int mask;
995 const char *name;
996 const char *help;
997} CPULogItem;
998
999extern const CPULogItem cpu_log_items[];
1000
1001void cpu_set_log(int log_flags);
1002void cpu_set_log_filename(const char *filename);
1003int cpu_str_to_log_mask(const char *str);
1004
1005/* IO ports API */
1006#include "ioport.h"
1007
1008/* memory API */
1009
1010#ifndef VBOX
1011extern int phys_ram_fd;
1012extern uint8_t *phys_ram_dirty;
1013extern ram_addr_t ram_size;
1014extern ram_addr_t last_ram_offset;
1015#else /* VBOX */
1016/** This is required for bounds checking the phys_ram_dirty accesses. */
1017extern RTGCPHYS phys_ram_dirty_size;
1018extern uint8_t *phys_ram_dirty;
1019#endif /* VBOX */
1020
1021/* physical memory access */
1022
1023/* MMIO pages are identified by a combination of an IO device index and
1024 3 flags. The ROMD code stores the page ram offset in iotlb entry,
1025 so only a limited number of ids are avaiable. */
1026
1027#define IO_MEM_NB_ENTRIES (1 << (TARGET_PAGE_BITS - IO_MEM_SHIFT))
1028
1029/* Flags stored in the low bits of the TLB virtual address. These are
1030 defined so that fast path ram access is all zeros. */
1031/* Zero if TLB entry is valid. */
1032#define TLB_INVALID_MASK (1 << 3)
1033/* Set if TLB entry references a clean RAM page. The iotlb entry will
1034 contain the page physical address. */
1035#define TLB_NOTDIRTY (1 << 4)
1036/* Set if TLB entry is an IO callback. */
1037#define TLB_MMIO (1 << 5)
1038
1039int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
1040 uint8_t *buf, int len, int is_write);
1041
1042#define VGA_DIRTY_FLAG 0x01
1043#define CODE_DIRTY_FLAG 0x02
1044#define KQEMU_DIRTY_FLAG 0x04
1045#define MIGRATION_DIRTY_FLAG 0x08
1046
1047/* read dirty bit (return 0 or 1) */
1048static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
1049{
1050#ifdef VBOX
1051 if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
1052 {
1053 Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
1054 /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
1055 return 0;
1056 }
1057#endif /* VBOX */
1058 return phys_ram_dirty[addr >> TARGET_PAGE_BITS] == 0xff;
1059}
1060
1061static inline int cpu_physical_memory_get_dirty(ram_addr_t addr,
1062 int dirty_flags)
1063{
1064#ifdef VBOX
1065 if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
1066 {
1067 Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
1068 /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
1069 return 0xff & dirty_flags; /** @todo I don't think this is the right thing to return, fix! */
1070 }
1071#endif /* VBOX */
1072 return phys_ram_dirty[addr >> TARGET_PAGE_BITS] & dirty_flags;
1073}
1074
1075static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
1076{
1077#ifdef VBOX
1078 if (RT_UNLIKELY((addr >> TARGET_PAGE_BITS) >= phys_ram_dirty_size))
1079 {
1080 Log(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));
1081 /*AssertMsgFailed(("cpu_physical_memory_is_dirty: %RGp\n", (RTGCPHYS)addr));*/
1082 return;
1083 }
1084#endif /* VBOX */
1085 phys_ram_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
1086}
1087
1088void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
1089 int dirty_flags);
1090void cpu_tlb_update_dirty(CPUState *env);
1091
1092int cpu_physical_memory_set_dirty_tracking(int enable);
1093
1094int cpu_physical_memory_get_dirty_tracking(void);
1095
1096int cpu_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
1097 target_phys_addr_t end_addr);
1098
1099void dump_exec_info(FILE *f,
1100 int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
1101
1102/* Coalesced MMIO regions are areas where write operations can be reordered.
1103 * This usually implies that write operations are side-effect free. This allows
1104 * batching which can make a major impact on performance when using
1105 * virtualization.
1106 */
1107void qemu_register_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
1108
1109void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size);
1110
1111/*******************************************/
1112/* host CPU ticks (if available) */
1113
1114#if defined(_ARCH_PPC)
1115
1116static inline int64_t cpu_get_real_ticks(void)
1117{
1118 int64_t retval;
1119#ifdef _ARCH_PPC64
1120 /* This reads timebase in one 64bit go and includes Cell workaround from:
1121 http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
1122 */
1123 __asm__ __volatile__ (
1124 "mftb %0\n\t"
1125 "cmpwi %0,0\n\t"
1126 "beq- $-8"
1127 : "=r" (retval));
1128#else
1129 /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
1130 unsigned long junk;
1131 __asm__ __volatile__ (
1132 "mftbu %1\n\t"
1133 "mftb %L0\n\t"
1134 "mftbu %0\n\t"
1135 "cmpw %0,%1\n\t"
1136 "bne $-16"
1137 : "=r" (retval), "=r" (junk));
1138#endif
1139 return retval;
1140}
1141
1142#elif defined(__i386__)
1143
1144static inline int64_t cpu_get_real_ticks(void)
1145{
1146 int64_t val;
1147 asm volatile ("rdtsc" : "=A" (val));
1148 return val;
1149}
1150
1151#elif defined(__x86_64__)
1152
1153static inline int64_t cpu_get_real_ticks(void)
1154{
1155 uint32_t low,high;
1156 int64_t val;
1157 asm volatile("rdtsc" : "=a" (low), "=d" (high));
1158 val = high;
1159 val <<= 32;
1160 val |= low;
1161 return val;
1162}
1163
1164#elif defined(__hppa__)
1165
1166static inline int64_t cpu_get_real_ticks(void)
1167{
1168 int val;
1169 asm volatile ("mfctl %%cr16, %0" : "=r"(val));
1170 return val;
1171}
1172
1173#elif defined(__ia64)
1174
1175static inline int64_t cpu_get_real_ticks(void)
1176{
1177 int64_t val;
1178 asm volatile ("mov %0 = ar.itc" : "=r"(val) :: "memory");
1179 return val;
1180}
1181
1182#elif defined(__s390__)
1183
1184static inline int64_t cpu_get_real_ticks(void)
1185{
1186 int64_t val;
1187 asm volatile("stck 0(%1)" : "=m" (val) : "a" (&val) : "cc");
1188 return val;
1189}
1190
1191#elif defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
1192
1193static inline int64_t cpu_get_real_ticks (void)
1194{
1195#if defined(_LP64)
1196 uint64_t rval;
1197 asm volatile("rd %%tick,%0" : "=r"(rval));
1198 return rval;
1199#else
1200 union {
1201 uint64_t i64;
1202 struct {
1203 uint32_t high;
1204 uint32_t low;
1205 } i32;
1206 } rval;
1207 asm volatile("rd %%tick,%1; srlx %1,32,%0"
1208 : "=r"(rval.i32.high), "=r"(rval.i32.low));
1209 return rval.i64;
1210#endif
1211}
1212
1213#elif defined(__mips__)
1214
1215static inline int64_t cpu_get_real_ticks(void)
1216{
1217#if __mips_isa_rev >= 2
1218 uint32_t count;
1219 static uint32_t cyc_per_count = 0;
1220
1221 if (!cyc_per_count)
1222 __asm__ __volatile__("rdhwr %0, $3" : "=r" (cyc_per_count));
1223
1224 __asm__ __volatile__("rdhwr %1, $2" : "=r" (count));
1225 return (int64_t)(count * cyc_per_count);
1226#else
1227 /* FIXME */
1228 static int64_t ticks = 0;
1229 return ticks++;
1230#endif
1231}
1232
1233#else
1234/* The host CPU doesn't have an easily accessible cycle counter.
1235 Just return a monotonically increasing value. This will be
1236 totally wrong, but hopefully better than nothing. */
1237static inline int64_t cpu_get_real_ticks (void)
1238{
1239 static int64_t ticks = 0;
1240 return ticks++;
1241}
1242#endif
1243
1244/* profiling */
1245#ifdef CONFIG_PROFILER
1246static inline int64_t profile_getclock(void)
1247{
1248 return cpu_get_real_ticks();
1249}
1250
1251extern int64_t kqemu_time, kqemu_time_start;
1252extern int64_t qemu_time, qemu_time_start;
1253extern int64_t tlb_flush_time;
1254extern int64_t kqemu_exec_count;
1255extern int64_t dev_time;
1256extern int64_t kqemu_ret_int_count;
1257extern int64_t kqemu_ret_excp_count;
1258extern int64_t kqemu_ret_intr_count;
1259#endif
1260
1261void cpu_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
1262 uint64_t mcg_status, uint64_t addr, uint64_t misc);
1263
1264#ifdef VBOX
1265void tb_invalidate_virt(CPUState *env, uint32_t eip);
1266#endif /* VBOX */
1267
1268#endif /* CPU_ALL_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette