VirtualBox

source: vbox/trunk/include/VBox/pgm.h@ 4675

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

Moved some of the odd address conversion routines to PGMR3Dbg just to get them out of the way.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.5 KB
Line 
1/** @file
2 * PGM - Page Monitor/Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___VBox_pgm_h
18#define ___VBox_pgm_h
19
20#include <VBox/cdefs.h>
21#include <VBox/types.h>
22#include <VBox/sup.h>
23#include <VBox/cpum.h>
24#include <VBox/vmapi.h>
25
26__BEGIN_DECLS
27
28/** @defgroup grp_pgm The Page Monitor/Manager API
29 * @{
30 */
31
32/** Enable dynamic allocation of guest physical RAM. */
33#define PGM_DYNAMIC_RAM_ALLOC
34
35/** Chunk size for dynamically allocated physical memory. */
36#define PGM_DYNAMIC_CHUNK_SIZE (1*1024*1024)
37/** Shift GC physical address by 20 bits to get the offset into the pvHCChunkHC array. */
38#define PGM_DYNAMIC_CHUNK_SHIFT 20
39/** Dynamic chunk offset mask. */
40#define PGM_DYNAMIC_CHUNK_OFFSET_MASK 0xfffff
41/** Dynamic chunk base mask. */
42#define PGM_DYNAMIC_CHUNK_BASE_MASK (~(RTGCPHYS)PGM_DYNAMIC_CHUNK_OFFSET_MASK)
43
44
45/** Page flags used for PGMHyperSetPageFlags
46 * @deprecated
47 * @{ */
48#define PGMPAGE_READ 1
49#define PGMPAGE_WRITE 2
50#define PGMPAGE_USER 4
51#define PGMPAGE_SYSTEM 8
52#define PGMPAGE_NOTPRESENT 16
53/** @} */
54
55
56/**
57 * FNPGMRELOCATE callback mode.
58 */
59typedef enum PGMRELOCATECALL
60{
61 /** The callback is for checking if the suggested address is suitable. */
62 PGMRELOCATECALL_SUGGEST = 1,
63 /** The callback is for executing the relocation. */
64 PGMRELOCATECALL_RELOCATE
65} PGMRELOCATECALL;
66
67
68/**
69 * Callback function which will be called when PGM is trying to find
70 * a new location for the mapping.
71 *
72 * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
73 * In 1) the callback should say if it objects to a suggested new location. If it
74 * accepts the new location, it is called again for doing it's relocation.
75 *
76 *
77 * @returns true if the location is ok.
78 * @returns false if another location should be found.
79 * @param GCPtrOld The old virtual address.
80 * @param GCPtrNew The new virtual address.
81 * @param enmMode Used to indicate the callback mode.
82 * @param pvUser User argument.
83 * @remark The return value is no a failure indicator, it's an acceptance
84 * indicator. Relocation can not fail!
85 */
86typedef DECLCALLBACK(bool) FNPGMRELOCATE(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
87/** Pointer to a relocation callback function. */
88typedef FNPGMRELOCATE *PFNPGMRELOCATE;
89
90
91/**
92 * Physical page access handler type.
93 */
94typedef enum PGMPHYSHANDLERTYPE
95{
96 /** MMIO range. Pages are not present, all access is done in interpreter or recompiler. */
97 PGMPHYSHANDLERTYPE_MMIO = 1,
98 /** Handle all normal page faults for a physical page range. */
99 PGMPHYSHANDLERTYPE_PHYSICAL,
100 /** Handler all write access to a physical page range. */
101 PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
102 /** Handler all access to a physical page range. */
103 PGMPHYSHANDLERTYPE_PHYSICAL_ALL
104
105} PGMPHYSHANDLERTYPE;
106
107/**
108 * \#PF Handler callback for physical access handler ranges (MMIO among others) in GC.
109 *
110 * @returns VBox status code (appropriate for GC return).
111 * @param pVM VM Handle.
112 * @param uErrorCode CPU Error code.
113 * @param pRegFrame Trap register frame.
114 * NULL on DMA and other non CPU access.
115 * @param pvFault The fault address (cr2).
116 * @param GCPhysFault The GC physical address corresponding to pvFault.
117 * @param pvUser User argument.
118 */
119typedef DECLCALLBACK(int) FNPGMGCPHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
120/** Pointer to PGM access callback. */
121typedef FNPGMGCPHYSHANDLER *PFNPGMGCPHYSHANDLER;
122
123/**
124 * \#PF Handler callback for physical access handler ranges (MMIO among others) in R0.
125 *
126 * @returns VBox status code (appropriate for GC return).
127 * @param pVM VM Handle.
128 * @param uErrorCode CPU Error code.
129 * @param pRegFrame Trap register frame.
130 * NULL on DMA and other non CPU access.
131 * @param pvFault The fault address (cr2).
132 * @param GCPhysFault The GC physical address corresponding to pvFault.
133 * @param pvUser User argument.
134 */
135typedef DECLCALLBACK(int) FNPGMR0PHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
136/** Pointer to PGM access callback. */
137typedef FNPGMR0PHYSHANDLER *PFNPGMR0PHYSHANDLER;
138
139/**
140 * Guest Access type
141 */
142typedef enum PGMACCESSTYPE
143{
144 /** Read access. */
145 PGMACCESSTYPE_READ = 1,
146 /** Write access. */
147 PGMACCESSTYPE_WRITE
148} PGMACCESSTYPE;
149
150/**
151 * \#PF Handler callback for physical access handler ranges (MMIO among others) in HC.
152 *
153 * The handler can not raise any faults, it's mainly for monitoring write access
154 * to certain pages.
155 *
156 * @returns VINF_SUCCESS if the handler have carried out the operation.
157 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
158 * @param pVM VM Handle.
159 * @param GCPhys The physical address the guest is writing to.
160 * @param pvPhys The HC mapping of that address.
161 * @param pvBuf What the guest is reading/writing.
162 * @param cbBuf How much it's reading/writing.
163 * @param enmAccessType The access type.
164 * @param pvUser User argument.
165 */
166typedef DECLCALLBACK(int) FNPGMR3PHYSHANDLER(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
167/** Pointer to PGM access callback. */
168typedef FNPGMR3PHYSHANDLER *PFNPGMR3PHYSHANDLER;
169
170
171/**
172 * Virtual access handler type.
173 */
174typedef enum PGMVIRTHANDLERTYPE
175{
176 /** Natural traps only. */
177 PGMVIRTHANDLERTYPE_NORMAL = 1,
178 /** Write access handled. */
179 PGMVIRTHANDLERTYPE_WRITE,
180 /** All access handled. */
181 PGMVIRTHANDLERTYPE_ALL,
182 /** By eip - Natural traps only. */
183 PGMVIRTHANDLERTYPE_EIP,
184 /** Hypervisor write access handled.
185 * This is used to catch the guest trying to write to LDT, TSS and any other
186 * system structure which the brain dead intel guys let unprivilegde code find. */
187 PGMVIRTHANDLERTYPE_HYPERVISOR
188
189} PGMVIRTHANDLERTYPE;
190
191/**
192 * \#PF Handler callback for virtual access handler ranges.
193 *
194 * Important to realize that a physical page in a range can have aliases, and
195 * for ALL and WRITE handlers these will also trigger.
196 *
197 * @returns VBox status code (appropriate for GC return).
198 * @param pVM VM Handle.
199 * @param uErrorCode CPU Error code.
200 * @param pRegFrame Trap register frame.
201 * @param pvFault The fault address (cr2).
202 * @param pvRange The base address of the handled virtual range.
203 * @param offRange The offset of the access into this range.
204 * (If it's a EIP range this's the EIP, if not it's pvFault.)
205 */
206typedef DECLCALLBACK(int) FNPGMGCVIRTHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
207/** Pointer to PGM access callback. */
208typedef FNPGMGCVIRTHANDLER *PFNPGMGCVIRTHANDLER;
209
210/**
211 * \#PF Handler callback for virtual access handler ranges.
212 *
213 * Important to realize that a physical page in a range can have aliases, and
214 * for ALL and WRITE handlers these will also trigger.
215 *
216 * @returns VINF_SUCCESS if the handler have carried out the operation.
217 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
218 * @param pVM VM Handle.
219 * @param GCPtr The virtual address the guest is writing to. (not correct if it's an alias!)
220 * @param pvPtr The HC mapping of that address.
221 * @param pvBuf What the guest is reading/writing.
222 * @param cbBuf How much it's reading/writing.
223 * @param enmAccessType The access type.
224 * @param pvUser User argument.
225 */
226typedef DECLCALLBACK(int) FNPGMHCVIRTHANDLER(PVM pVM, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
227/** Pointer to PGM access callback. */
228typedef FNPGMHCVIRTHANDLER *PFNPGMHCVIRTHANDLER;
229
230
231/**
232 * \#PF Handler callback for invalidation of virtual access handler ranges.
233 *
234 * @param pVM VM Handle.
235 * @param GCPtr The virtual address the guest has changed.
236 */
237typedef DECLCALLBACK(int) FNPGMHCVIRTINVALIDATE(PVM pVM, RTGCPTR GCPtr);
238/** Pointer to PGM invalidation callback. */
239typedef FNPGMHCVIRTINVALIDATE *PFNPGMHCVIRTINVALIDATE;
240
241/**
242 * Paging mode.
243 */
244typedef enum PGMMODE
245{
246 /** The usual invalid value. */
247 PGMMODE_INVALID = 0,
248 /** Real mode. */
249 PGMMODE_REAL,
250 /** Protected mode, no paging. */
251 PGMMODE_PROTECTED,
252 /** 32-bit paging. */
253 PGMMODE_32_BIT,
254 /** PAE paging. */
255 PGMMODE_PAE,
256 /** PAE paging with NX enabled. */
257 PGMMODE_PAE_NX,
258 /** 64-bit AMD paging (long mode). */
259 PGMMODE_AMD64,
260 /** 64-bit AMD paging (long mode) with NX enabled. */
261 PGMMODE_AMD64_NX,
262 /** The max number of modes */
263 PGMMODE_MAX,
264 /** 32bit hackishness. */
265 PGMMODE_32BIT_HACK = 0x7fffffff
266} PGMMODE;
267
268
269/**
270 * Gets the current CR3 register value for the shadow memory context.
271 * @returns CR3 value.
272 * @param pVM The VM handle.
273 */
274PGMDECL(uint32_t) PGMGetHyperCR3(PVM pVM);
275
276/**
277 * Gets the CR3 register value for the 32-Bit shadow memory context.
278 * @returns CR3 value.
279 * @param pVM The VM handle.
280 */
281PGMDECL(uint32_t) PGMGetHyper32BitCR3(PVM pVM);
282
283/**
284 * Gets the CR3 register value for the PAE shadow memory context.
285 * @returns CR3 value.
286 * @param pVM The VM handle.
287 */
288PGMDECL(uint32_t) PGMGetHyperPaeCR3(PVM pVM);
289
290/**
291 * Gets the CR3 register value for the AMD64 shadow memory context.
292 * @returns CR3 value.
293 * @param pVM The VM handle.
294 */
295PGMDECL(uint32_t) PGMGetHyperAmd64CR3(PVM pVM);
296
297/**
298 * Gets the current CR3 register value for the HC intermediate memory context.
299 * @returns CR3 value.
300 * @param pVM The VM handle.
301 */
302PGMDECL(uint32_t) PGMGetInterHCCR3(PVM pVM);
303
304/**
305 * Gets the current CR3 register value for the GC intermediate memory context.
306 * @returns CR3 value.
307 * @param pVM The VM handle.
308 */
309PGMDECL(uint32_t) PGMGetInterGCCR3(PVM pVM);
310
311/**
312 * Gets the CR3 register value for the 32-Bit intermediate memory context.
313 * @returns CR3 value.
314 * @param pVM The VM handle.
315 */
316PGMDECL(uint32_t) PGMGetInter32BitCR3(PVM pVM);
317
318/**
319 * Gets the CR3 register value for the PAE intermediate memory context.
320 * @returns CR3 value.
321 * @param pVM The VM handle.
322 */
323PGMDECL(uint32_t) PGMGetInterPaeCR3(PVM pVM);
324
325/**
326 * Gets the CR3 register value for the AMD64 intermediate memory context.
327 * @returns CR3 value.
328 * @param pVM The VM handle.
329 */
330PGMDECL(uint32_t) PGMGetInterAmd64CR3(PVM pVM);
331
332/**
333 * \#PF Handler.
334 *
335 * @returns VBox status code (appropriate for GC return).
336 * @param pVM VM Handle.
337 * @param uErr The trap error code.
338 * @param pRegFrame Trap register frame.
339 * @param pvFault The fault address.
340 */
341PGMDECL(int) PGMTrap0eHandler(PVM pVM, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
342
343/**
344 * Prefetch a page/set of pages.
345 *
346 * Typically used to sync commonly used pages before entering raw mode
347 * after a CR3 reload.
348 *
349 * @returns VBox status code suitable for scheduling.
350 * @retval VINF_SUCCESS on success.
351 * @retval VINF_PGM_SYNC_CR3 if we're out of shadow pages or something like that.
352 * @param pVM VM handle.
353 * @param GCPtrPage Page to prefetch.
354 */
355PGMDECL(int) PGMPrefetchPage(PVM pVM, RTGCPTR GCPtrPage);
356
357/**
358 * Verifies a range of pages for read or write access.
359 *
360 * Supports handling of pages marked for dirty bit tracking and CSAM.
361 *
362 * @returns VBox status code.
363 * @param pVM VM handle.
364 * @param Addr Guest virtual address to check.
365 * @param cbSize Access size.
366 * @param fAccess Access type (r/w, user/supervisor (X86_PTE_*).
367 */
368PGMDECL(int) PGMVerifyAccess(PVM pVM, RTGCUINTPTR Addr, uint32_t cbSize, uint32_t fAccess);
369
370/**
371 * Verifies a range of pages for read or write access
372 *
373 * Only checks the guest's page tables
374 *
375 * @returns VBox status code.
376 * @param pVM VM handle.
377 * @param Addr Guest virtual address to check
378 * @param cbSize Access size
379 * @param fAccess Access type (r/w, user/supervisor (X86_PTE_*))
380 */
381PGMDECL(int) PGMIsValidAccess(PVM pVM, RTGCUINTPTR Addr, uint32_t cbSize, uint32_t fAccess);
382
383/**
384 * Executes an instruction using the interpreter.
385 *
386 * @returns VBox status code (appropriate for trap handling and GC return).
387 * @param pVM VM handle.
388 * @param pRegFrame Register frame.
389 * @param pvFault Fault address.
390 */
391PGMDECL(int) PGMInterpretInstruction(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
392
393/**
394 * Maps a range of physical pages at a given virtual address
395 * in the guest context.
396 *
397 * The GC virtual address range must be within an existing mapping.
398 *
399 * @returns VBox status code.
400 * @param pVM The virtual machine.
401 * @param GCPtr Where to map the page(s). Must be page aligned.
402 * @param HCPhys Start of the range of physical pages. Must be page aligned.
403 * @param cbPages Number of bytes to map. Must be page aligned.
404 * @param fFlags Page flags (X86_PTE_*).
405 */
406PGMDECL(int) PGMMap(PVM pVM, RTGCUINTPTR GCPtr, RTHCPHYS HCPhys, uint32_t cbPages, unsigned fFlags);
407
408/**
409 * Sets (replaces) the page flags for a range of pages in a mapping.
410 *
411 * The pages must be mapped pages, it's not possible to change the flags of
412 * Guest OS pages.
413 *
414 * @returns VBox status.
415 * @param pVM VM handle.
416 * @param GCPtr Virtual address of the first page in the range.
417 * @param cb Size (in bytes) of the range to apply the modification to.
418 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
419 */
420PGMDECL(int) PGMMapSetPage(PVM pVM, RTGCPTR GCPtr, uint64_t cb, uint64_t fFlags);
421
422/**
423 * Modify page flags for a range of pages in a mapping.
424 *
425 * The existing flags are ANDed with the fMask and ORed with the fFlags.
426 *
427 * @returns VBox status code.
428 * @param pVM VM handle.
429 * @param GCPtr Virtual address of the first page in the range.
430 * @param cb Size (in bytes) of the range to apply the modification to.
431 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
432 * @param fMask The AND mask - page flags X86_PTE_*.
433 * Be very CAREFUL when ~'ing constants which could be 32-bit!
434 */
435PGMDECL(int) PGMMapModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
436
437/**
438 * Gets effective page information (from the VMM page directory).
439 *
440 * @returns VBox status.
441 * @param pVM VM Handle.
442 * @param GCPtr Guest Context virtual address of the page.
443 * @param pfFlags Where to store the flags. These are X86_PTE_*.
444 * @param pHCPhys Where to store the HC physical address of the page.
445 * This is page aligned.
446 * @remark You should use PGMMapGetPage() for pages in a mapping.
447 */
448PGMDECL(int) PGMShwGetPage(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
449
450/**
451 * Sets (replaces) the page flags for a range of pages in the shadow context.
452 *
453 * @returns VBox status.
454 * @param pVM VM handle.
455 * @param GCPtr The address of the first page.
456 * @param cb The size of the range in bytes.
457 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
458 * @remark You must use PGMMapSetPage() for pages in a mapping.
459 */
460PGMDECL(int) PGMShwSetPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags);
461
462/**
463 * Modify page flags for a range of pages in the shadow context.
464 *
465 * The existing flags are ANDed with the fMask and ORed with the fFlags.
466 *
467 * @returns VBox status code.
468 * @param pVM VM handle.
469 * @param GCPtr Virtual address of the first page in the range.
470 * @param cb Size (in bytes) of the range to apply the modification to.
471 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
472 * @param fMask The AND mask - page flags X86_PTE_*.
473 * Be very CAREFUL when ~'ing constants which could be 32-bit!
474 * @remark You must use PGMMapModifyPage() for pages in a mapping.
475 */
476PGMDECL(int) PGMShwModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
477
478/**
479 * Gets effective Guest OS page information.
480 *
481 * When GCPtr is in a big page, the function will return as if it was a normal
482 * 4KB page. If the need for distinguishing between big and normal page becomes
483 * necessary at a later point, a PGMGstGetPageEx() will be created for that
484 * purpose.
485 *
486 * @returns VBox status.
487 * @param pVM VM Handle.
488 * @param GCPtr Guest Context virtual address of the page.
489 * @param pfFlags Where to store the flags. These are X86_PTE_*, even for big pages.
490 * @param pGCPhys Where to store the GC physical address of the page.
491 * This is page aligned. The fact that the
492 */
493PGMDECL(int) PGMGstGetPage(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
494
495/**
496 * Checks if the page is present.
497 *
498 * @returns true if the page is present.
499 * @returns false if the page is not present.
500 * @param pVM The VM handle.
501 * @param GCPtr Address within the page.
502 */
503PGMDECL(bool) PGMGstIsPagePresent(PVM pVM, RTGCPTR GCPtr);
504
505/**
506 * Sets (replaces) the page flags for a range of pages in the guest's tables.
507 *
508 * @returns VBox status.
509 * @param pVM VM handle.
510 * @param GCPtr The address of the first page.
511 * @param cb The size of the range in bytes.
512 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
513 */
514PGMDECL(int) PGMGstSetPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags);
515
516/**
517 * Modify page flags for a range of pages in the guest's tables
518 *
519 * The existing flags are ANDed with the fMask and ORed with the fFlags.
520 *
521 * @returns VBox status code.
522 * @param pVM VM handle.
523 * @param GCPtr Virtual address of the first page in the range.
524 * @param cb Size (in bytes) of the range to apply the modification to.
525 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
526 * @param fMask The AND mask - page flags X86_PTE_*, excluding the page mask of course.
527 * Be very CAREFUL when ~'ing constants which could be 32-bit!
528 */
529PGMDECL(int) PGMGstModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
530
531/**
532 * Performs and schedules necessary updates following a CR3 load or reload.
533 *
534 * This will normally involve mapping the guest PD or nPDPTR
535 *
536 * @returns VBox status code.
537 * @retval VINF_PGM_SYNC_CR3 if monitoring requires a CR3 sync. This can
538 * safely be ignored and overridden since the FF will be set too then.
539 * @param pVM VM handle.
540 * @param cr3 The new cr3.
541 * @param fGlobal Indicates whether this is a global flush or not.
542 */
543PGMDECL(int) PGMFlushTLB(PVM pVM, uint32_t cr3, bool fGlobal);
544
545/**
546 * Synchronize the paging structures.
547 *
548 * This function is called in response to the VM_FF_PGM_SYNC_CR3 and
549 * VM_FF_PGM_SYNC_CR3_NONGLOBAL. Those two force action flags are set
550 * in several places, most importantly whenever the CR3 is loaded.
551 *
552 * @returns VBox status code.
553 * @param pVM The virtual machine.
554 * @param cr0 Guest context CR0 register
555 * @param cr3 Guest context CR3 register
556 * @param cr4 Guest context CR4 register
557 * @param fGlobal Including global page directories or not
558 */
559PGMDECL(int) PGMSyncCR3(PVM pVM, uint32_t cr0, uint32_t cr3, uint32_t cr4, bool fGlobal);
560
561/**
562 * Called whenever CR0 or CR4 in a way which may change
563 * the paging mode.
564 *
565 * @returns VBox status code fit for scheduling in GC and R0.
566 * @retval VINF_SUCCESS if the was no change, or it was successfully dealt with.
567 * @retval VINF_PGM_CHANGE_MODE if we're in GC or R0 and the mode changes.
568 * @param pVM VM handle.
569 * @param cr0 The new cr0.
570 * @param cr4 The new cr4.
571 * @param efer The new extended feature enable register.
572 */
573PGMDECL(int) PGMChangeMode(PVM pVM, uint32_t cr0, uint32_t cr4, uint64_t efer);
574
575/**
576 * Gets the current guest paging mode.
577 *
578 * If you just need the CPU mode (real/protected/long), use CPUMGetGuestMode().
579 *
580 * @returns The current paging mode.
581 * @param pVM The VM handle.
582 */
583PGMDECL(PGMMODE) PGMGetGuestMode(PVM pVM);
584
585/**
586 * Gets the current shadow paging mode.
587 *
588 * @returns The current paging mode.
589 * @param pVM The VM handle.
590 */
591PGMDECL(PGMMODE) PGMGetShadowMode(PVM pVM);
592
593/**
594 * Get mode name.
595 *
596 * @returns read-only name string.
597 * @param enmMode The mode which name is desired.
598 */
599PGMDECL(const char *) PGMGetModeName(PGMMODE enmMode);
600
601/**
602 * Register a access handler for a physical range.
603 *
604 * @returns VBox status code.
605 * @param pVM VM Handle.
606 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
607 * @param GCPhys Start physical address.
608 * @param GCPhysLast Last physical address. (inclusive)
609 * @param pfnHandlerR3 The R3 handler.
610 * @param pvUserR3 User argument to the R3 handler.
611 * @param pfnHandlerR0 The R0 handler.
612 * @param pvUserR0 User argument to the R0 handler.
613 * @param pfnHandlerGC The GC handler.
614 * @param pvUserGC User argument to the GC handler.
615 * This must be a GC pointer because it will be relocated!
616 * @param pszDesc Pointer to description string. This must not be freed.
617 */
618PGMDECL(int) PGMHandlerPhysicalRegisterEx(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
619 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
620 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
621 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
622 R3PTRTYPE(const char *) pszDesc);
623
624/**
625 * Modify a physical page access handler.
626 *
627 * Modification can only be done to the range it self, not the type or anything else.
628 *
629 * @returns VBox status code.
630 * For all return codes other than VERR_PGM_HANDLER_NOT_FOUND and VINF_SUCCESS the range is deregistered
631 * and a new registration must be performed!
632 * @param pVM VM handle.
633 * @param GCPhysCurrent Current location.
634 * @param GCPhys New location.
635 * @param GCPhysLast New last location.
636 */
637PGMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
638
639/**
640 * Register a physical page access handler.
641 *
642 * @returns VBox status code.
643 * @param pVM VM Handle.
644 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
645 */
646PGMDECL(int) PGMHandlerPhysicalDeregister(PVM pVM, RTGCPHYS GCPhys);
647
648/**
649 * Changes the callbacks associated with a physical access handler.
650 *
651 * @returns VBox status code.
652 * @param pVM VM Handle.
653 * @param GCPhys Start physical address.
654 * @param pfnHandlerR3 The R3 handler.
655 * @param pvUserR3 User argument to the R3 handler.
656 * @param pfnHandlerR0 The R0 handler.
657 * @param pvUserR0 User argument to the R0 handler.
658 * @param pfnHandlerGC The GC handler.
659 * @param pvUserGC User argument to the GC handler.
660 * This must be a GC pointer because it will be relocated!
661 * @param pszDesc Pointer to description string. This must not be freed.
662 */
663PGMDECL(int) PGMHandlerPhysicalChangeCallbacks(PVM pVM, RTGCPHYS GCPhys,
664 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
665 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
666 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
667 R3PTRTYPE(const char *) pszDesc);
668
669/**
670 * Splitts a physical access handler in two.
671 *
672 * @returns VBox status code.
673 * @param pVM VM Handle.
674 * @param GCPhys Start physical address of the handler.
675 * @param GCPhysSplit The split address.
676 */
677PGMDECL(int) PGMHandlerPhysicalSplit(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysSplit);
678
679/**
680 * Joins up two adjacent physical access handlers which has the same callbacks.
681 *
682 * @returns VBox status code.
683 * @param pVM VM Handle.
684 * @param GCPhys1 Start physical address of the first handler.
685 * @param GCPhys2 Start physical address of the second handler.
686 */
687PGMDECL(int) PGMHandlerPhysicalJoin(PVM pVM, RTGCPHYS GCPhys1, RTGCPHYS GCPhys2);
688
689/**
690 * Temporarily turns off the access monitoring of a page within a monitored
691 * physical write/all page access handler region.
692 *
693 * Use this when no further #PFs are required for that page. Be aware that
694 * a page directory sync might reset the flags, and turn on access monitoring
695 * for the page.
696 *
697 * The caller must do required page table modifications.
698 *
699 * @returns VBox status code.
700 * @param pVM VM Handle
701 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
702 * @param GCPhysPage Physical address of the page to turn off access monitoring for.
703 */
704PGMDECL(int) PGMHandlerPhysicalPageTempOff(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
705
706
707/**
708 * Resets any modifications to individual pages in a physical
709 * page access handler region.
710 *
711 * This is used in pair with PGMHandlerPhysicalModify().
712 *
713 * @returns VBox status code.
714 * @param pVM VM Handle
715 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
716 */
717PGMDECL(int) PGMHandlerPhysicalReset(PVM pVM, RTGCPHYS GCPhys);
718
719/**
720 * Turns access monitoring of a page within a monitored
721 * physical write/all page access handler region back on.
722 *
723 * The caller must do required page table modifications.
724 *
725 * @returns VBox status code.
726 * @param pVM VM Handle
727 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
728 * @param GCPhysPage Physical address of the page to turn on access monitoring for.
729 */
730PGMDECL(int) PGMHandlerPhysicalPageReset(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
731
732/**
733 * Checks if a physical range is handled
734 *
735 * @returns boolean.
736 * @param pVM VM Handle
737 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
738 */
739PGMDECL(bool) PGMHandlerPhysicalIsRegistered(PVM pVM, RTGCPHYS GCPhys);
740
741/**
742 * Checks if Address Gate 20 is enabled or not.
743 *
744 * @returns true if enabled.
745 * @returns false if disabled.
746 * @param pVM VM handle.
747 */
748PGMDECL(bool) PGMPhysIsA20Enabled(PVM pVM);
749
750/**
751 * Validates a GC physical address.
752 *
753 * @returns true if valid.
754 * @returns false if invalid.
755 * @param pVM The VM handle.
756 * @param GCPhys The physical address to validate.
757 */
758PGMDECL(bool) PGMPhysIsGCPhysValid(PVM pVM, RTGCPHYS GCPhys);
759
760/**
761 * Checks if a GC physical address is a normal page,
762 * i.e. not ROM, MMIO or reserved.
763 *
764 * @returns true if normal.
765 * @returns false if invalid, ROM, MMIO or reserved page.
766 * @param pVM The VM handle.
767 * @param GCPhys The physical address to check.
768 */
769PGMDECL(bool) PGMPhysIsGCPhysNormal(PVM pVM, RTGCPHYS GCPhys);
770
771/**
772 * Converts a GC physical address to a HC physical address.
773 *
774 * @returns VINF_SUCCESS on success.
775 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
776 * page but has no physical backing.
777 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
778 * GC physical address.
779 * @param pVM The VM handle.
780 * @param GCPhys The GC physical address to convert.
781 * @param pHCPhys Where to store the HC physical address on success.
782 */
783PGMDECL(int) PGMPhysGCPhys2HCPhys(PVM pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys);
784
785/**
786 * Requests the mapping of a guest page into the current context.
787 *
788 * This API should only be used for very short term, as it will consume
789 * scarse resources (R0 and GC) in the mapping cache. When you're done
790 * with the page, call PGMPhysGCPhys2CCPtrRelease() ASAP to release it.
791 *
792 * @returns VBox status code.
793 * @retval VINF_SUCCESS on success.
794 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
795 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
796 *
797 * @param pVM The VM handle.
798 * @param GCPhys The guest physical address of the page that should be mapped.
799 * @param ppv Where to store the address corresponding to GCPhys.
800 *
801 * @remark Avoid calling this API from within critical sections (other than
802 * the PGM one) because of the deadlock risk.
803 */
804PGMDECL(int) PGMPhysGCPhys2CCPtr(PVM pVM, RTGCPHYS GCPhys, void **ppv);
805
806/**
807 * Release the mapping of a guest page.
808 *
809 * This is the counterpart to the PGMPhysGCPhys2CCPtr.
810 *
811 * @param pVM The VM handle.
812 * @param GCPhys The address that was mapped using PGMPhysGCPhys2CCPtr.
813 * @param pv The address that PGMPhysGCPhys2CCPtr returned.
814 */
815PGMDECL(void) PGMPhysGCPhys2CCPtrRelease(PVM pVM, RTGCPHYS GCPhys, void *pv);
816
817/**
818 * Converts a GC physical address to a HC pointer.
819 *
820 * @returns VINF_SUCCESS on success.
821 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
822 * page but has no physical backing.
823 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
824 * GC physical address.
825 * @param pVM The VM handle.
826 * @param GCPhys The GC physical address to convert.
827 * @param cbRange Physical range
828 * @param pHCPtr Where to store the HC pointer on success.
829 */
830PGMDECL(int) PGMPhysGCPhys2HCPtr(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR pHCPtr);
831
832/**
833 * Converts a guest pointer to a GC physical address.
834 *
835 * This uses the current CR3/CR0/CR4 of the guest.
836 *
837 * @returns VBox status code.
838 * @param pVM The VM Handle
839 * @param GCPtr The guest pointer to convert.
840 * @param pGCPhys Where to store the HC physical address.
841 */
842PGMDECL(int) PGMPhysGCPtr2GCPhys(PVM pVM, RTGCPTR GCPtr, PRTGCPHYS pGCPhys);
843
844/**
845 * Converts a guest pointer to a HC physical address.
846 *
847 * This uses the current CR3/CR0/CR4 of the guest.
848 *
849 * @returns VBox status code.
850 * @param pVM The VM Handle
851 * @param GCPtr The guest pointer to convert.
852 * @param pHCPhys Where to store the HC physical address.
853 */
854PGMDECL(int) PGMPhysGCPtr2HCPhys(PVM pVM, RTGCPTR GCPtr, PRTHCPHYS pHCPhys);
855
856/**
857 * Converts a guest pointer to a HC pointer.
858 *
859 * This uses the current CR3/CR0/CR4 of the guest.
860 *
861 * @returns VBox status code.
862 * @param pVM The VM Handle
863 * @param GCPtr The guest pointer to convert.
864 * @param pHCPtr Where to store the HC virtual address.
865 */
866PGMDECL(int) PGMPhysGCPtr2HCPtr(PVM pVM, RTGCPTR GCPtr, PRTHCPTR pHCPtr);
867
868/**
869 * Converts a guest virtual address to a HC pointer by specfied CR3 and flags.
870 *
871 * @returns VBox status code.
872 * @param pVM The VM Handle
873 * @param GCPtr The guest pointer to convert.
874 * @param cr3 The guest CR3.
875 * @param fFlags Flags used for interpreting the PD correctly: X86_CR4_PSE and X86_CR4_PAE
876 * @param pHCPtr Where to store the HC pointer.
877 *
878 * @remark This function is used by the REM at a time where PGM could
879 * potentially not be in sync. It could also be used by a
880 * future DBGF API to cpu state independent conversions.
881 */
882PGMDECL(int) PGMPhysGCPtr2HCPtrByGstCR3(PVM pVM, RTGCPTR GCPtr, uint32_t cr3, unsigned fFlags, PRTHCPTR pHCPtr);
883
884/**
885 * Read physical memory.
886 *
887 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
888 * want to ignore those.
889 *
890 * @param pVM VM Handle.
891 * @param GCPhys Physical address start reading from.
892 * @param pvBuf Where to put the read bits.
893 * @param cbRead How many bytes to read.
894 */
895PGMDECL(void) PGMPhysRead(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
896
897/**
898 * Write to physical memory.
899 *
900 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
901 * want to ignore those.
902 *
903 * @param pVM VM Handle.
904 * @param GCPhys Physical address to write to.
905 * @param pvBuf What to write.
906 * @param cbWrite How many bytes to write.
907 */
908PGMDECL(void) PGMPhysWrite(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
909
910
911#ifndef IN_GC /* Only ring 0 & 3. */
912
913/**
914 * Read from guest physical memory by GC physical address, bypassing
915 * MMIO and access handlers.
916 *
917 * @returns VBox status.
918 * @param pVM VM handle.
919 * @param pvDst The destination address.
920 * @param GCPhysSrc The source address (GC physical address).
921 * @param cb The number of bytes to read.
922 */
923PGMDECL(int) PGMPhysReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb);
924
925/**
926 * Write to guest physical memory referenced by GC pointer.
927 * Write memory to GC physical address in guest physical memory.
928 *
929 * This will bypass MMIO and access handlers.
930 *
931 * @returns VBox status.
932 * @param pVM VM handle.
933 * @param GCPhysDst The GC physical address of the destination.
934 * @param pvSrc The source buffer.
935 * @param cb The number of bytes to write.
936 */
937PGMDECL(int) PGMPhysWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb);
938
939/**
940 * Read from guest physical memory referenced by GC pointer.
941 *
942 * This function uses the current CR3/CR0/CR4 of the guest and will
943 * bypass access handlers and not set any accessed bits.
944 *
945 * @returns VBox status.
946 * @param pVM VM handle.
947 * @param pvDst The destination address.
948 * @param GCPtrSrc The source address (GC pointer).
949 * @param cb The number of bytes to read.
950 */
951PGMDECL(int) PGMPhysReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
952
953/**
954 * Write to guest physical memory referenced by GC pointer.
955 *
956 * This function uses the current CR3/CR0/CR4 of the guest and will
957 * bypass access handlers and not set dirty or accessed bits.
958 *
959 * @returns VBox status.
960 * @param pVM VM handle.
961 * @param GCPtrDst The destination address (GC pointer).
962 * @param pvSrc The source address.
963 * @param cb The number of bytes to write.
964 */
965PGMDECL(int) PGMPhysWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
966
967/**
968 * Read from guest physical memory referenced by GC pointer.
969 *
970 * This function uses the current CR3/CR0/CR4 of the guest and will
971 * respect access handlers and set accessed bits.
972 *
973 * @returns VBox status.
974 * @param pVM VM handle.
975 * @param pvDst The destination address.
976 * @param GCPtrSrc The source address (GC pointer).
977 * @param cb The number of bytes to read.
978 */
979PGMDECL(int) PGMPhysReadGCPtrSafe(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
980
981/**
982 * Write to guest physical memory referenced by GC pointer.
983 *
984 * This function uses the current CR3/CR0/CR4 of the guest and will
985 * respect access handlers and set dirty and accessed bits.
986 *
987 * @returns VBox status.
988 * @param pVM VM handle.
989 * @param GCPtrDst The destination address (GC pointer).
990 * @param pvSrc The source address.
991 * @param cb The number of bytes to write.
992 */
993PGMDECL(int) PGMPhysWriteGCPtrSafe(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
994
995/**
996 * Write to guest physical memory referenced by GC pointer and update the PTE.
997 *
998 * This function uses the current CR3/CR0/CR4 of the guest and will
999 * bypass access handlers and set any dirty and accessed bits in the PTE.
1000 *
1001 * If you don't want to set the dirty bit, use PGMR3PhysWriteGCPtr().
1002 *
1003 * @returns VBox status.
1004 * @param pVM VM handle.
1005 * @param GCPtrDst The destination address (GC pointer).
1006 * @param pvSrc The source address.
1007 * @param cb The number of bytes to write.
1008 */
1009PGMDECL(int) PGMPhysWriteGCPtrDirty(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1010
1011/**
1012 * Emulation of the invlpg instruction (HC only actually).
1013 *
1014 * @returns VBox status code.
1015 * @param pVM VM handle.
1016 * @param GCPtrPage Page to invalidate.
1017 * @remark ASSUMES the page table entry or page directory is
1018 * valid. Fairly safe, but there could be edge cases!
1019 * @todo Flush page or page directory only if necessary!
1020 */
1021PGMDECL(int) PGMInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1022
1023#endif /* !IN_GC */
1024
1025/**
1026 * Performs a read of guest virtual memory for instruction emulation.
1027 *
1028 * This will check permissions, raise exceptions and update the access bits.
1029 *
1030 * The current implementation will bypass all access handlers. It may later be
1031 * changed to at least respect MMIO.
1032 *
1033 *
1034 * @returns VBox status code suitable to scheduling.
1035 * @retval VINF_SUCCESS if the read was performed successfully.
1036 * @retval VINF_EM_RAW_GUEST_TRAP if an exception was raised but not dispatched yet.
1037 * @retval VINF_TRPM_XCPT_DISPATCHED if an exception was raised and dispatched.
1038 *
1039 * @param pVM The VM handle.
1040 * @param pCtxCore The context core.
1041 * @param pvDst Where to put the bytes we've read.
1042 * @param GCPtrSrc The source address.
1043 * @param cb The number of bytes to read. Not more than a page.
1044 *
1045 * @remark This function will dynamically map physical pages in GC. This may unmap
1046 * mappings done by the caller. Be careful!
1047 */
1048PGMDECL(int) PGMPhysInterpretedRead(PVM pVM, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb);
1049
1050#ifdef VBOX_STRICT
1051/**
1052 * Asserts that the handlers+guest-page-tables == ramrange-flags and
1053 * that the physical addresses associated with virtual handlers are correct.
1054 *
1055 * @returns Number of mismatches.
1056 * @param pVM The VM handle.
1057 */
1058PGMDECL(unsigned) PGMAssertHandlerAndFlagsInSync(PVM pVM);
1059
1060/**
1061 * Asserts that there are no mapping conflicts.
1062 *
1063 * @returns Number of conflicts.
1064 * @param pVM The VM Handle.
1065 */
1066PGMDECL(unsigned) PGMAssertNoMappingConflicts(PVM pVM);
1067
1068/**
1069 * Asserts that everything related to the guest CR3 is correctly shadowed.
1070 *
1071 * This will call PGMAssertNoMappingConflicts() and PGMAssertHandlerAndFlagsInSync(),
1072 * and assert the correctness of the guest CR3 mapping before asserting that the
1073 * shadow page tables is in sync with the guest page tables.
1074 *
1075 * @returns Number of conflicts.
1076 * @param pVM The VM Handle.
1077 * @param cr3 The current guest CR3 register value.
1078 * @param cr4 The current guest CR4 register value.
1079 */
1080PGMDECL(unsigned) PGMAssertCR3(PVM pVM, uint32_t cr3, uint32_t cr4);
1081#endif /* VBOX_STRICT */
1082
1083
1084#ifdef IN_GC
1085
1086/** @defgroup grp_pgm_gc The PGM Guest Context API
1087 * @ingroup grp_pgm
1088 * @{
1089 */
1090
1091/**
1092 * Temporarily maps one guest page specified by GC physical address.
1093 * These pages must have a physical mapping in HC, i.e. they cannot be MMIO pages.
1094 *
1095 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1096 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1097 *
1098 * @returns VBox status.
1099 * @param pVM VM handle.
1100 * @param GCPhys GC Physical address of the page.
1101 * @param ppv Where to store the address of the mapping.
1102 */
1103PGMGCDECL(int) PGMGCDynMapGCPage(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1104
1105/**
1106 * Temporarily maps one guest page specified by unaligned GC physical address.
1107 * These pages must have a physical mapping in HC, i.e. they cannot be MMIO pages.
1108 *
1109 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1110 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1111 *
1112 * The caller is aware that only the speicifed page is mapped and that really bad things
1113 * will happen if writing beyond the page!
1114 *
1115 * @returns VBox status.
1116 * @param pVM VM handle.
1117 * @param GCPhys GC Physical address within the page to be mapped.
1118 * @param ppv Where to store the address of the mapping address corresponding to GCPhys.
1119 */
1120PGMGCDECL(int) PGMGCDynMapGCPageEx(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1121
1122/**
1123 * Temporarily maps one host page specified by HC physical address.
1124 *
1125 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1126 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1127 *
1128 * @returns VBox status.
1129 * @param pVM VM handle.
1130 * @param HCPhys HC Physical address of the page.
1131 * @param ppv Where to store the address of the mapping.
1132 */
1133PGMGCDECL(int) PGMGCDynMapHCPage(PVM pVM, RTHCPHYS HCPhys, void **ppv);
1134
1135/**
1136 * Syncs a guest os page table.
1137 *
1138 * @returns VBox status code.
1139 * @param pVM VM handle.
1140 * @param iPD Page directory index.
1141 * @param pPDSrc Source page directory (i.e. Guest OS page directory).
1142 * Assume this is a temporary mapping.
1143 */
1144PGMGCDECL(int) PGMGCSyncPT(PVM pVM, unsigned iPD, PVBOXPD pPDSrc);
1145
1146/**
1147 * Emulation of the invlpg instruction.
1148 *
1149 * @returns VBox status code.
1150 * @param pVM VM handle.
1151 * @param GCPtrPage Page to invalidate.
1152 */
1153PGMGCDECL(int) PGMGCInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1154
1155/** @} */
1156#endif
1157
1158
1159#ifdef IN_RING3
1160/** @defgroup grp_pgm_r3 The PGM Host Context Ring-3 API
1161 * @ingroup grp_pgm
1162 * @{
1163 */
1164/**
1165 * Initiates the paging of VM.
1166 *
1167 * @returns VBox status code.
1168 * @param pVM Pointer to VM structure.
1169 */
1170PGMR3DECL(int) PGMR3Init(PVM pVM);
1171
1172/**
1173 * Init the PGM bits that rely on VMMR0 and MM to be fully initialized.
1174 *
1175 * The dynamic mapping area will also be allocated and initialized at this
1176 * time. We could allocate it during PGMR3Init of course, but the mapping
1177 * wouldn't be allocated at that time preventing us from setting up the
1178 * page table entries with the dummy page.
1179 *
1180 * @returns VBox status code.
1181 * @param pVM VM handle.
1182 */
1183PGMR3DECL(int) PGMR3InitDynMap(PVM pVM);
1184
1185/**
1186 * Ring-3 init finalizing.
1187 *
1188 * @returns VBox status code.
1189 * @param pVM The VM handle.
1190 */
1191PGMR3DECL(int) PGMR3InitFinalize(PVM pVM);
1192
1193/**
1194 * Applies relocations to data and code managed by this
1195 * component. This function will be called at init and
1196 * whenever the VMM need to relocate it self inside the GC.
1197 *
1198 * @param pVM The VM.
1199 * @param offDelta Relocation delta relative to old location.
1200 */
1201PGMR3DECL(void) PGMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
1202
1203/**
1204 * The VM is being reset.
1205 *
1206 * For the PGM component this means that any PD write monitors
1207 * needs to be removed.
1208 *
1209 * @param pVM VM handle.
1210 */
1211PGMR3DECL(void) PGMR3Reset(PVM pVM);
1212
1213/**
1214 * Terminates the PGM.
1215 *
1216 * @returns VBox status code.
1217 * @param pVM Pointer to VM structure.
1218 */
1219PGMR3DECL(int) PGMR3Term(PVM pVM);
1220
1221/**
1222 * Serivce a VMMCALLHOST_PGM_LOCK call.
1223 *
1224 * @returns VBox status code.
1225 * @param pVM The VM handle.
1226 */
1227PDMR3DECL(int) PGMR3LockCall(PVM pVM);
1228
1229/**
1230 * Inform PGM if we want all mappings to be put into the shadow page table. (necessary for e.g. VMX)
1231 *
1232 * @returns VBox status code.
1233 * @param pVM VM handle.
1234 * @param fEnable Enable or disable shadow mappings
1235 */
1236PGMR3DECL(int) PGMR3ChangeShwPDMappings(PVM pVM, bool fEnable);
1237
1238/**
1239 * Allocate missing physical pages for an existing guest RAM range.
1240 *
1241 * @returns VBox status.
1242 * @param pVM The VM handle.
1243 * @param GCPhys GC physical address of the RAM range. (page aligned)
1244 */
1245PGMR3DECL(int) PGM3PhysGrowRange(PVM pVM, RTGCPHYS GCPhys);
1246
1247/**
1248 * Interface that the MMR3RamRegister(), MMR3RomRegister() and MMIO handler
1249 * registration APIs calls to inform PGM about memory registrations.
1250 *
1251 * It registers the physical memory range with PGM. MM is responsible
1252 * for the toplevel things - allocation and locking - while PGM is taking
1253 * care of all the details and implements the physical address space virtualization.
1254 *
1255 * @returns VBox status.
1256 * @param pVM The VM handle.
1257 * @param pvRam HC virtual address of the RAM range. (page aligned)
1258 * @param GCPhys GC physical address of the RAM range. (page aligned)
1259 * @param cb Size of the RAM range. (page aligned)
1260 * @param fFlags Flags, MM_RAM_*.
1261 * @param paPages Pointer an array of physical page descriptors.
1262 * @param pszDesc Description string.
1263 */
1264PGMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1265
1266/**
1267 * Register a chunk of a the physical memory range with PGM. MM is responsible
1268 * for the toplevel things - allocation and locking - while PGM is taking
1269 * care of all the details and implements the physical address space virtualization.
1270 *
1271 * @returns VBox status.
1272 * @param pVM The VM handle.
1273 * @param pvRam HC virtual address of the RAM range. (page aligned)
1274 * @param GCPhys GC physical address of the RAM range. (page aligned)
1275 * @param cb Size of the RAM range. (page aligned)
1276 * @param fFlags Flags, MM_RAM_*.
1277 * @param paPages Pointer an array of physical page descriptors.
1278 * @param pszDesc Description string.
1279 */
1280PGMR3DECL(int) PGMR3PhysRegisterChunk(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1281
1282/**
1283 * Interface MMIO handler relocation calls.
1284 *
1285 * It relocates an existing physical memory range with PGM.
1286 *
1287 * @returns VBox status.
1288 * @param pVM The VM handle.
1289 * @param GCPhysOld Previous GC physical address of the RAM range. (page aligned)
1290 * @param GCPhysNew New GC physical address of the RAM range. (page aligned)
1291 * @param cb Size of the RAM range. (page aligned)
1292 */
1293PGMR3DECL(int) PGMR3PhysRelocate(PVM pVM, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, size_t cb);
1294
1295/**
1296 * Interface MMR3RomRegister() and MMR3PhysReserve calls to update the
1297 * flags of existing RAM ranges.
1298 *
1299 * @returns VBox status.
1300 * @param pVM The VM handle.
1301 * @param GCPhys GC physical address of the RAM range. (page aligned)
1302 * @param cb Size of the RAM range. (page aligned)
1303 * @param fFlags The Or flags, MM_RAM_* #defines.
1304 * @param fMask The and mask for the flags.
1305 */
1306PGMR3DECL(int) PGMR3PhysSetFlags(PVM pVM, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, unsigned fMask);
1307
1308/**
1309 * Sets the Address Gate 20 state.
1310 *
1311 * @param pVM VM handle.
1312 * @param fEnable True if the gate should be enabled.
1313 * False if the gate should be disabled.
1314 */
1315PGMDECL(void) PGMR3PhysSetA20(PVM pVM, bool fEnable);
1316
1317/**
1318 * Creates a page table based mapping in GC.
1319 *
1320 * @returns VBox status code.
1321 * @param pVM VM Handle.
1322 * @param GCPtr Virtual Address. (Page table aligned!)
1323 * @param cb Size of the range. Must be a 4MB aligned!
1324 * @param pfnRelocate Relocation callback function.
1325 * @param pvUser User argument to the callback.
1326 * @param pszDesc Pointer to description string. This must not be freed.
1327 */
1328PGMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, size_t cb, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc);
1329
1330/**
1331 * Removes a page table based mapping.
1332 *
1333 * @returns VBox status code.
1334 * @param pVM VM Handle.
1335 * @param GCPtr Virtual Address. (Page table aligned!)
1336 */
1337PGMR3DECL(int) PGMR3UnmapPT(PVM pVM, RTGCPTR GCPtr);
1338
1339/**
1340 * Gets the size of the current guest mappings if they were to be
1341 * put next to oneanother.
1342 *
1343 * @returns VBox status code.
1344 * @param pVM The VM.
1345 * @param pcb Where to store the size.
1346 */
1347PGMR3DECL(int) PGMR3MappingsSize(PVM pVM, size_t *pcb);
1348
1349/**
1350 * Fixes the guest context mappings in a range reserved from the Guest OS.
1351 *
1352 * @returns VBox status code.
1353 * @param pVM The VM.
1354 * @param GCPtrBase The address of the reserved range of guest memory.
1355 * @param cb The size of the range starting at GCPtrBase.
1356 */
1357PGMR3DECL(int) PGMR3MappingsFix(PVM pVM, RTGCPTR GCPtrBase, size_t cb);
1358
1359/**
1360 * Unfixes the mappings.
1361 * After calling this function mapping conflict detection will be enabled.
1362 *
1363 * @returns VBox status code.
1364 * @param pVM The VM.
1365 */
1366PGMR3DECL(int) PGMR3MappingsUnfix(PVM pVM);
1367
1368/**
1369 * Map pages into the intermediate context (switcher code).
1370 * These pages are mapped at both the give virtual address and at
1371 * the physical address (for identity mapping).
1372 *
1373 * @returns VBox status code.
1374 * @param pVM The virtual machine.
1375 * @param Addr Intermediate context address of the mapping.
1376 * @param HCPhys Start of the range of physical pages. This must be entriely below 4GB!
1377 * @param cbPages Number of bytes to map.
1378 *
1379 * @remark This API shall not be used to anything but mapping the switcher code.
1380 */
1381PGMR3DECL(int) PGMR3MapIntermediate(PVM pVM, RTUINTPTR Addr, RTHCPHYS HCPhys, unsigned cbPages);
1382
1383/**
1384 * Checks guest PD for conflicts with VMM GC mappings.
1385 *
1386 * @returns true if conflict detected.
1387 * @returns false if not.
1388 * @param pVM The virtual machine.
1389 * @param cr3 Guest context CR3 register.
1390 * @param fRawR0 Whether RawR0 is enabled or not.
1391 */
1392PGMR3DECL(bool) PGMR3MapHasConflicts(PVM pVM, uint32_t cr3, bool fRawR0);
1393
1394/**
1395 * Read memory from the guest mappings.
1396 *
1397 * This will use the page tables associated with the mappings to
1398 * read the memory. This means that not all kind of memory is readable
1399 * since we don't necessarily know how to convert that physical address
1400 * to a HC virtual one.
1401 *
1402 * @returns VBox status.
1403 * @param pVM VM handle.
1404 * @param pvDst The destination address (HC of course).
1405 * @param GCPtrSrc The source address (GC virtual address).
1406 * @param cb Number of bytes to read.
1407 */
1408PGMR3DECL(int) PGMR3MapRead(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
1409
1410/**
1411 * Register a access handler for a physical range.
1412 *
1413 * @returns VBox status code.
1414 * @param pVM VM handle.
1415 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
1416 * @param GCPhys Start physical address.
1417 * @param GCPhysLast Last physical address. (inclusive)
1418 * @param pfnHandlerR3 The R3 handler.
1419 * @param pvUserR3 User argument to the R3 handler.
1420 * @param pszModR0 The R0 handler module. NULL means default R0 module.
1421 * @param pszHandlerR0 The R0 handler symbol name.
1422 * @param pvUserR0 User argument to the R0 handler.
1423 * @param pszModGC The GC handler module. NULL means default GC module.
1424 * @param pszHandlerGC The GC handler symbol name.
1425 * @param pvUserGC User argument to the GC handler.
1426 * This must be a GC pointer because it will be relocated!
1427 * @param pszDesc Pointer to description string. This must not be freed.
1428 */
1429PGMR3DECL(int) PGMR3HandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
1430 PFNPGMR3PHYSHANDLER pfnHandlerR3, void *pvUserR3,
1431 const char *pszModR0, const char *pszHandlerR0, RTR0PTR pvUserR0,
1432 const char *pszModGC, const char *pszHandlerGC, RTGCPTR pvUserGC, const char *pszDesc);
1433
1434/**
1435 * Register an access handler for a virtual range.
1436 *
1437 * @returns VBox status code.
1438 * @param pVM VM handle.
1439 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1440 * @param GCPtr Start address.
1441 * @param GCPtrLast Last address. (inclusive)
1442 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1443 * @param pfnHandlerHC The HC handler.
1444 * @param pfnHandlerGC The GC handler.
1445 * @param pszDesc Pointer to description string. This must not be freed.
1446 */
1447PGMDECL(int) PGMHandlerVirtualRegisterEx(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1448 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1449 PFNPGMHCVIRTHANDLER pfnHandlerHC, RTGCPTR pfnHandlerGC,
1450 HCPTRTYPE(const char *) pszDesc);
1451
1452/**
1453 * Register a access handler for a virtual range.
1454 *
1455 * @returns VBox status code.
1456 * @param pVM VM handle.
1457 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1458 * @param GCPtr Start address.
1459 * @param GCPtrLast Last address. (inclusive)
1460 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1461 * @param pfnHandlerHC The HC handler.
1462 * @param pszHandlerGC The GC handler symbol name.
1463 * @param pszModGC The GC handler module.
1464 * @param pszDesc Pointer to description string. This must not be freed.
1465 */
1466PGMR3DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1467 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1468 PFNPGMHCVIRTHANDLER pfnHandlerHC,
1469 const char *pszHandlerGC, const char *pszModGC, const char *pszDesc);
1470
1471/**
1472 * Modify the page invalidation callback handler for a registered virtual range
1473 * (add more when needed)
1474 *
1475 * @returns VBox status code.
1476 * @param pVM VM handle.
1477 * @param GCPtr Start address.
1478 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1479 */
1480PGMDECL(int) PGMHandlerVirtualChangeInvalidateCallback(PVM pVM, RTGCPTR GCPtr, PFNPGMHCVIRTINVALIDATE pfnInvalidateHC);
1481
1482
1483/**
1484 * Deregister an access handler for a virtual range.
1485 *
1486 * @returns VBox status code.
1487 * @param pVM VM handle.
1488 * @param GCPtr Start address.
1489 */
1490PGMDECL(int) PGMHandlerVirtualDeregister(PVM pVM, RTGCPTR GCPtr);
1491
1492/**
1493 * Grows the shadow page pool.
1494 *
1495 * I.e. adds more pages to it, assuming that hasn't reached cMaxPages yet.
1496 *
1497 * @returns VBox status code.
1498 * @param pVM The VM handle.
1499 */
1500PDMR3DECL(int) PGMR3PoolGrow(PVM pVM);
1501
1502#ifdef ___VBox_dbgf_h /** @todo fix this! */
1503/**
1504 * Dumps a page table hierarchy use only physical addresses and cr4/lm flags.
1505 *
1506 * @returns VBox status code (VINF_SUCCESS).
1507 * @param pVM The VM handle.
1508 * @param cr3 The root of the hierarchy.
1509 * @param cr4 The cr4, only PAE and PSE is currently used.
1510 * @param fLongMode Set if long mode, false if not long mode.
1511 * @param cMaxDepth Number of levels to dump.
1512 * @param pHlp Pointer to the output functions.
1513 */
1514PGMR3DECL(int) PGMR3DumpHierarchyHC(PVM pVM, uint32_t cr3, uint32_t cr4, bool fLongMode, unsigned cMaxDepth, PCDBGFINFOHLP pHlp);
1515#endif
1516
1517/**
1518 * Dumps a 32-bit guest page directory and page tables.
1519 *
1520 * @returns VBox status code (VINF_SUCCESS).
1521 * @param pVM The VM handle.
1522 * @param cr3 The root of the hierarchy.
1523 * @param cr4 The CR4, PSE is currently used.
1524 * @param PhysSearch Address to search for.
1525 */
1526PGMR3DECL(int) PGMR3DumpHierarchyGC(PVM pVM, uint32_t cr3, uint32_t cr4, RTGCPHYS PhysSearch);
1527
1528/**
1529 * Debug helper - Dumps the supplied page directory.
1530 *
1531 * @internal
1532 */
1533PGMR3DECL(void) PGMR3DumpPD(PVM pVM, PVBOXPD pPD);
1534
1535/**
1536 * Dumps the the PGM mappings..
1537 *
1538 * @param pVM VM handle.
1539 */
1540PGMR3DECL(void) PGMR3DumpMappings(PVM pVM);
1541
1542/** @todo r=bird: s/Byte/U8/ s/Word/U16/ s/Dword/U32/ to match other functions names and returned types. */
1543/**
1544 * Read physical memory. (one byte)
1545 *
1546 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1547 * want to ignore those.
1548 *
1549 * @param pVM VM Handle.
1550 * @param GCPhys Physical address start reading from.
1551 */
1552PGMR3DECL(uint8_t) PGMR3PhysReadByte(PVM pVM, RTGCPHYS GCPhys);
1553
1554/**
1555 * Read physical memory. (one word)
1556 *
1557 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1558 * want to ignore those.
1559 *
1560 * @param pVM VM Handle.
1561 * @param GCPhys Physical address start reading from.
1562 */
1563PGMR3DECL(uint16_t) PGMR3PhysReadWord(PVM pVM, RTGCPHYS GCPhys);
1564
1565/**
1566 * Read physical memory. (one dword)
1567 *
1568 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1569 * want to ignore those.
1570 *
1571 * @param pVM VM Handle.
1572 * @param GCPhys Physical address start reading from.
1573 */
1574PGMR3DECL(uint32_t) PGMR3PhysReadDword(PVM pVM, RTGCPHYS GCPhys);
1575
1576/**
1577 * Write to physical memory. (one byte)
1578 *
1579 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1580 * want to ignore those.
1581 *
1582 * @param pVM VM Handle.
1583 * @param GCPhys Physical address to write to.
1584 * @param val What to write.
1585 */
1586PGMR3DECL(void) PGMR3PhysWriteByte(PVM pVM, RTGCPHYS GCPhys, uint8_t val);
1587
1588/**
1589 * Write to physical memory. (one word)
1590 *
1591 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1592 * want to ignore those.
1593 *
1594 * @param pVM VM Handle.
1595 * @param GCPhys Physical address to write to.
1596 * @param val What to write.
1597 */
1598PGMR3DECL(void) PGMR3PhysWriteWord(PVM pVM, RTGCPHYS GCPhys, uint16_t val);
1599
1600/**
1601 * Write to physical memory. (one dword)
1602 *
1603 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1604 * want to ignore those.
1605 *
1606 * @param pVM VM Handle.
1607 * @param GCPhys Physical address to write to.
1608 * @param val What to write.
1609 */
1610PGMR3DECL(void) PGMR3PhysWriteDword(PVM pVM, RTGCPHYS GCPhys, uint32_t val);
1611
1612/**
1613 * Perform an integrity check on the PGM component.
1614 *
1615 * @returns VINF_SUCCESS if everything is fine.
1616 * @returns VBox error status after asserting on integrity breach.
1617 * @param pVM The VM handle.
1618 */
1619PDMR3DECL(int) PGMR3CheckIntegrity(PVM pVM);
1620
1621/**
1622 * Converts a HC pointer to a GC physical address.
1623 *
1624 * Only for the debugger.
1625 *
1626 * @returns VBox status code.
1627 * @retval VINF_SUCCESS on success, *pGCPhys is set.
1628 * @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
1629 *
1630 * @param pVM The VM handle.
1631 * @param HCPtr The HC pointer to convert.
1632 * @param pGCPhys Where to store the GC physical address on success.
1633 */
1634PGMR3DECL(int) PGMR3DbgHCPtr2GCPhys(PVM pVM, RTHCPTR HCPtr, PRTGCPHYS pGCPhys);
1635
1636/**
1637 * Converts a HC pointer to a GC physical address.
1638 *
1639 * @returns VBox status code.
1640 * @retval VINF_SUCCESS on success, *pHCPhys is set.
1641 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical page but has no physical backing.
1642 * @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
1643 *
1644 * @param pVM The VM handle.
1645 * @param HCPtr The HC pointer to convert.
1646 * @param pHCPhys Where to store the HC physical address on success.
1647 */
1648PGMR3DECL(int) PGMR3DbgHCPtr2HCPhys(PVM pVM, RTHCPTR HCPtr, PRTHCPHYS pHCPhys);
1649
1650/**
1651 * Converts a HC physical address to a GC physical address.
1652 *
1653 * Only for the debugger.
1654 *
1655 * @returns VBox status code
1656 * @retval VINF_SUCCESS on success, *pGCPhys is set.
1657 * @retval VERR_INVALID_POINTER if the HC physical address is not within the GC physical memory.
1658 *
1659 * @param pVM The VM handle.
1660 * @param HCPhys The HC physical address to convert.
1661 * @param pGCPhys Where to store the GC physical address on success.
1662 */
1663PGMR3DECL(int) PGMR3DbgHCPhys2GCPhys(PVM pVM, RTHCPHYS HCPhys, PRTGCPHYS pGCPhys);
1664
1665/** @} */
1666
1667#endif /* IN_RING3 */
1668
1669__END_DECLS
1670
1671/** @} */
1672#endif
1673
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