VirtualBox

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

Last change on this file since 6532 was 6532, checked in by vboxsync, 17 years ago

Cleaned out the PGM_DYNAMIC_RAM_ALLOC tests to avoid unnecessary mess with VBOX_WITH_NEW_PHYS_CODE.

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