VirtualBox

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

最後變更 在這個檔案從18661是 18661,由 vboxsync 提交於 16 年 前

src/recompiler: Clean out the VBOX_WITH_NEW_PHYS_CODE #ifdefs.

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

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