1 | /* $Id: PGMPhys.h 5999 2007-12-07 15:05:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PGM - Page Manager and Monitor, Physical Memory Addressing.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Read physical memory. (one byte/word/dword)
|
---|
21 | *
|
---|
22 | * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
|
---|
23 | * want to ignore those.
|
---|
24 | *
|
---|
25 | * @param pVM VM Handle.
|
---|
26 | * @param GCPhys Physical address start reading from.
|
---|
27 | */
|
---|
28 | PGMDECL(PGMPHYS_DATATYPE) PGMPHYSFN_READNAME(PVM pVM, RTGCPHYS GCPhys)
|
---|
29 | {
|
---|
30 | uint32_t iCacheIndex;
|
---|
31 |
|
---|
32 | Assert(VM_IS_EMT(pVM));
|
---|
33 |
|
---|
34 | #ifdef PGM_PHYSMEMACCESS_CACHING
|
---|
35 | if (pVM->pgm.s.fPhysCacheFlushPending)
|
---|
36 | {
|
---|
37 | pVM->pgm.s.pgmphysreadcache.aEntries = 0; /* flush cache; physical or virtual handlers have changed */
|
---|
38 | pVM->pgm.s.pgmphyswritecache.aEntries = 0; /* flush cache; physical or virtual handlers have changed */
|
---|
39 | pVM->pgm.s.fPhysCacheFlushPending = false;
|
---|
40 | }
|
---|
41 | else
|
---|
42 | if ( ASMBitTest(&pVM->pgm.s.pgmphysreadcache.aEntries, (iCacheIndex = ((GCPhys >> PAGE_SHIFT) & PGM_MAX_PHYSCACHE_ENTRIES_MASK)))
|
---|
43 | && pVM->pgm.s.pgmphysreadcache.Entry[iCacheIndex].GCPhys == PAGE_ADDRESS(GCPhys) /** @todo r=bird: wrong macro. You don't want an uintptr_t! */
|
---|
44 | #if PGMPHYS_DATASIZE != 1
|
---|
45 | && PAGE_ADDRESS(GCPhys) == PAGE_ADDRESS(GCPhys + sizeof(PGMPHYS_DATATYPE) - 1) /** (GCPhys & PAGE_OFFSET_MASK) <= PAGE_SIZE - sizeof(PGMPHYS_DATATYPE) */
|
---|
46 | #endif
|
---|
47 | )
|
---|
48 | {
|
---|
49 | RTGCPHYS off = GCPhys - pVM->pgm.s.pgmphysreadcache.Entry[iCacheIndex].GCPhys;
|
---|
50 | return *(PGMPHYS_DATATYPE *)(pVM->pgm.s.pgmphysreadcache.Entry[iCacheIndex].pbHC + off);
|
---|
51 | }
|
---|
52 | #endif /* PGM_PHYSMEMACCESS_CACHING */
|
---|
53 | PGMPHYS_DATATYPE val;
|
---|
54 |
|
---|
55 | PGMPhysRead(pVM, GCPhys, &val, sizeof(val));
|
---|
56 | return val;
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Write to physical memory. (one byte/word/dword)
|
---|
62 | *
|
---|
63 | * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
|
---|
64 | * want to ignore those.
|
---|
65 | *
|
---|
66 | * @param pVM VM Handle.
|
---|
67 | * @param GCPhys Physical address to write to.
|
---|
68 | * @param val What to write.
|
---|
69 | */
|
---|
70 | PGMDECL(void) PGMPHYSFN_WRITENAME(PVM pVM, RTGCPHYS GCPhys, PGMPHYS_DATATYPE val)
|
---|
71 | {
|
---|
72 | uint32_t iCacheIndex;
|
---|
73 |
|
---|
74 | Assert(VM_IS_EMT(pVM));
|
---|
75 |
|
---|
76 | #ifdef PGM_PHYSMEMACCESS_CACHING
|
---|
77 | if (pVM->pgm.s.fPhysCacheFlushPending)
|
---|
78 | {
|
---|
79 | pVM->pgm.s.pgmphysreadcache.aEntries = 0; /* flush cache; physical or virtual handlers have changed */
|
---|
80 | pVM->pgm.s.pgmphyswritecache.aEntries = 0; /* flush cache; physical or virtual handlers have changed */
|
---|
81 | pVM->pgm.s.fPhysCacheFlushPending = false;
|
---|
82 | }
|
---|
83 | else
|
---|
84 | if ( ASMBitTest(&pVM->pgm.s.pgmphyswritecache.aEntries, (iCacheIndex = ((GCPhys >> PAGE_SHIFT) & PGM_MAX_PHYSCACHE_ENTRIES_MASK)))
|
---|
85 | && pVM->pgm.s.pgmphyswritecache.Entry[iCacheIndex].GCPhys == PAGE_ADDRESS(GCPhys)
|
---|
86 | #if PGMPHYS_DATASIZE != 1
|
---|
87 | && PAGE_ADDRESS(GCPhys) == PAGE_ADDRESS(GCPhys + sizeof(val) - 1)
|
---|
88 | #endif
|
---|
89 | )
|
---|
90 | {
|
---|
91 | RTGCPHYS off = GCPhys - pVM->pgm.s.pgmphyswritecache.Entry[iCacheIndex].GCPhys;
|
---|
92 | *(PGMPHYS_DATATYPE *)(pVM->pgm.s.pgmphyswritecache.Entry[iCacheIndex].pbHC + off) = val;
|
---|
93 | return;
|
---|
94 | }
|
---|
95 | #endif /* PGM_PHYSMEMACCESS_CACHING */
|
---|
96 | return PGMPhysWrite(pVM, GCPhys, &val, sizeof(val));
|
---|
97 | }
|
---|
98 |
|
---|
99 | #undef PGMPHYSFN_READNAME
|
---|
100 | #undef PGMPHYSFN_WRITENAME
|
---|
101 | #undef PGMPHYS_DATATYPE
|
---|
102 | #undef PGMPHYS_DATASIZE
|
---|
103 |
|
---|