VirtualBox

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

Last change on this file since 4172 was 4071, checked in by vboxsync, 18 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.9 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 * @returns The current paging mode.
579 * @param pVM The VM handle.
580 */
581PGMDECL(PGMMODE) PGMGetGuestMode(PVM pVM);
582
583/**
584 * Gets the current shadow paging mode.
585 *
586 * @returns The current paging mode.
587 * @param pVM The VM handle.
588 */
589PGMDECL(PGMMODE) PGMGetShadowMode(PVM pVM);
590
591/**
592 * Get mode name.
593 *
594 * @returns read-only name string.
595 * @param enmMode The mode which name is desired.
596 */
597PGMDECL(const char *) PGMGetModeName(PGMMODE enmMode);
598
599/**
600 * Register a access handler for a physical range.
601 *
602 * @returns VBox status code.
603 * @param pVM VM Handle.
604 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
605 * @param GCPhys Start physical address.
606 * @param GCPhysLast Last physical address. (inclusive)
607 * @param pfnHandlerR3 The R3 handler.
608 * @param pvUserR3 User argument to the R3 handler.
609 * @param pfnHandlerR0 The R0 handler.
610 * @param pvUserR0 User argument to the R0 handler.
611 * @param pfnHandlerGC The GC handler.
612 * @param pvUserGC User argument to the GC handler.
613 * This must be a GC pointer because it will be relocated!
614 * @param pszDesc Pointer to description string. This must not be freed.
615 */
616PGMDECL(int) PGMHandlerPhysicalRegisterEx(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
617 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
618 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
619 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
620 R3PTRTYPE(const char *) pszDesc);
621
622/**
623 * Modify a physical page access handler.
624 *
625 * Modification can only be done to the range it self, not the type or anything else.
626 *
627 * @returns VBox status code.
628 * For all return codes other than VERR_PGM_HANDLER_NOT_FOUND and VINF_SUCCESS the range is deregistered
629 * and a new registration must be performed!
630 * @param pVM VM handle.
631 * @param GCPhysCurrent Current location.
632 * @param GCPhys New location.
633 * @param GCPhysLast New last location.
634 */
635PGMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
636
637/**
638 * Register a physical page access handler.
639 *
640 * @returns VBox status code.
641 * @param pVM VM Handle.
642 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
643 */
644PGMDECL(int) PGMHandlerPhysicalDeregister(PVM pVM, RTGCPHYS GCPhys);
645
646/**
647 * Changes the callbacks associated with a physical access handler.
648 *
649 * @returns VBox status code.
650 * @param pVM VM Handle.
651 * @param GCPhys Start physical address.
652 * @param pfnHandlerR3 The R3 handler.
653 * @param pvUserR3 User argument to the R3 handler.
654 * @param pfnHandlerR0 The R0 handler.
655 * @param pvUserR0 User argument to the R0 handler.
656 * @param pfnHandlerGC The GC handler.
657 * @param pvUserGC User argument to the GC handler.
658 * This must be a GC pointer because it will be relocated!
659 * @param pszDesc Pointer to description string. This must not be freed.
660 */
661PGMDECL(int) PGMHandlerPhysicalChangeCallbacks(PVM pVM, RTGCPHYS GCPhys,
662 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
663 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
664 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
665 R3PTRTYPE(const char *) pszDesc);
666
667/**
668 * Splitts a physical access handler in two.
669 *
670 * @returns VBox status code.
671 * @param pVM VM Handle.
672 * @param GCPhys Start physical address of the handler.
673 * @param GCPhysSplit The split address.
674 */
675PGMDECL(int) PGMHandlerPhysicalSplit(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysSplit);
676
677/**
678 * Joins up two adjacent physical access handlers which has the same callbacks.
679 *
680 * @returns VBox status code.
681 * @param pVM VM Handle.
682 * @param GCPhys1 Start physical address of the first handler.
683 * @param GCPhys2 Start physical address of the second handler.
684 */
685PGMDECL(int) PGMHandlerPhysicalJoin(PVM pVM, RTGCPHYS GCPhys1, RTGCPHYS GCPhys2);
686
687/**
688 * Temporarily turns off the access monitoring of a page within a monitored
689 * physical write/all page access handler region.
690 *
691 * Use this when no further #PFs are required for that page. Be aware that
692 * a page directory sync might reset the flags, and turn on access monitoring
693 * for the page.
694 *
695 * The caller must do required page table modifications.
696 *
697 * @returns VBox status code.
698 * @param pVM VM Handle
699 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
700 * @param GCPhysPage Physical address of the page to turn off access monitoring for.
701 */
702PGMDECL(int) PGMHandlerPhysicalPageTempOff(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
703
704
705/**
706 * Resets any modifications to individual pages in a physical
707 * page access handler region.
708 *
709 * This is used in pair with PGMHandlerPhysicalModify().
710 *
711 * @returns VBox status code.
712 * @param pVM VM Handle
713 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
714 */
715PGMDECL(int) PGMHandlerPhysicalReset(PVM pVM, RTGCPHYS GCPhys);
716
717/**
718 * Turns access monitoring of a page within a monitored
719 * physical write/all page access handler region back on.
720 *
721 * The caller must do required page table modifications.
722 *
723 * @returns VBox status code.
724 * @param pVM VM Handle
725 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
726 * @param GCPhysPage Physical address of the page to turn on access monitoring for.
727 */
728PGMDECL(int) PGMHandlerPhysicalPageReset(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
729
730/**
731 * Checks if a physical range is handled
732 *
733 * @returns boolean.
734 * @param pVM VM Handle
735 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
736 */
737PGMDECL(bool) PGMHandlerPhysicalIsRegistered(PVM pVM, RTGCPHYS GCPhys);
738
739/**
740 * Checks if Address Gate 20 is enabled or not.
741 *
742 * @returns true if enabled.
743 * @returns false if disabled.
744 * @param pVM VM handle.
745 */
746PGMDECL(bool) PGMPhysIsA20Enabled(PVM pVM);
747
748/**
749 * Validates a GC physical address.
750 *
751 * @returns true if valid.
752 * @returns false if invalid.
753 * @param pVM The VM handle.
754 * @param GCPhys The physical address to validate.
755 */
756PGMDECL(bool) PGMPhysIsGCPhysValid(PVM pVM, RTGCPHYS GCPhys);
757
758/**
759 * Checks if a GC physical address is a normal page,
760 * i.e. not ROM, MMIO or reserved.
761 *
762 * @returns true if normal.
763 * @returns false if invalid, ROM, MMIO or reserved page.
764 * @param pVM The VM handle.
765 * @param GCPhys The physical address to check.
766 */
767PGMDECL(bool) PGMPhysIsGCPhysNormal(PVM pVM, RTGCPHYS GCPhys);
768
769/**
770 * Converts a GC physical address to a HC physical address.
771 *
772 * @returns VINF_SUCCESS on success.
773 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
774 * page but has no physical backing.
775 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
776 * GC physical address.
777 * @param pVM The VM handle.
778 * @param GCPhys The GC physical address to convert.
779 * @param pHCPhys Where to store the HC physical address on success.
780 */
781PGMDECL(int) PGMPhysGCPhys2HCPhys(PVM pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys);
782
783/**
784 * Converts a GC physical address to a HC pointer.
785 *
786 * @returns VINF_SUCCESS on success.
787 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
788 * page but has no physical backing.
789 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
790 * GC physical address.
791 * @param pVM The VM handle.
792 * @param GCPhys The GC physical address to convert.
793 * @param cbRange Physical range
794 * @param pHCPtr Where to store the HC pointer on success.
795 */
796PGMDECL(int) PGMPhysGCPhys2HCPtr(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR pHCPtr);
797
798/**
799 * Validates a HC pointer.
800 *
801 * @returns true if valid.
802 * @returns false if invalid.
803 * @param pVM The VM handle.
804 * @param HCPtr The pointer to validate.
805 */
806PGMDECL(bool) PGMPhysIsHCPtrValid(PVM pVM, RTHCPTR HCPtr);
807
808/**
809 * Converts a HC pointer to a GC physical address.
810 *
811 * @returns VINF_SUCCESS on success.
812 * @returns VERR_INVALID_POINTER if the pointer is not within the
813 * GC physical memory.
814 * @param pVM The VM handle.
815 * @param HCPtr The HC pointer to convert.
816 * @param pGCPhys Where to store the GC physical address on success.
817 */
818PGMDECL(int) PGMPhysHCPtr2GCPhys(PVM pVM, RTHCPTR HCPtr, PRTGCPHYS pGCPhys);
819
820/**
821 * Converts a HC pointer to a GC physical address.
822 *
823 * @returns VINF_SUCCESS on success.
824 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
825 * page but has no physical backing.
826 * @returns VERR_INVALID_POINTER if the pointer is not within the
827 * GC physical memory.
828 * @param pVM The VM handle.
829 * @param HCPtr The HC pointer to convert.
830 * @param pHCPhys Where to store the HC physical address on success.
831 */
832PGMDECL(int) PGMPhysHCPtr2HCPhys(PVM pVM, RTHCPTR HCPtr, PRTHCPHYS pHCPhys);
833
834/**
835 * Validates a HC Physical address.
836 *
837 * This is an extremely slow API, don't use it!
838 *
839 * @returns true if valid.
840 * @returns false if invalid.
841 * @param pVM The VM handle.
842 * @param HCPhys The physical address to validate.
843 */
844PGMDECL(bool) PGMPhysIsHCPhysValid(PVM pVM, RTHCPHYS HCPhys);
845
846/**
847 * Converts a HC physical address to a GC physical address.
848 *
849 * This is an extremely slow API, don't use it!
850 *
851 * @returns VINF_SUCCESS on success.
852 * @returns VERR_INVALID_POINTER if the HC physical address is
853 * not within the GC physical memory.
854 * @param pVM The VM handle.
855 * @param HCPhys The HC physical address to convert.
856 * @param pGCPhys Where to store the GC physical address on success.
857 */
858PGMDECL(int) PGMPhysHCPhys2GCPhys(PVM pVM, RTHCPHYS HCPhys, PRTGCPHYS pGCPhys);
859
860/**
861 * Converts a HC physical address to a HC pointer.
862 *
863 * This is an extremely slow API, don't use it!
864 *
865 * @returns VINF_SUCCESS on success.
866 * @returns VERR_INVALID_POINTER if the HC physical address is
867 * not within the GC physical memory.
868 * @param pVM The VM handle.
869 * @param HCPhys The HC physical address to convert.
870 * @param pHCPtr Where to store the HC pointer on success.
871 */
872PGMDECL(int) PGMPhysHCPhys2HCPtr(PVM pVM, RTHCPHYS HCPhys, PRTHCPTR pHCPtr);
873
874/**
875 * Converts a guest pointer to a GC physical address.
876 *
877 * This uses the current CR3/CR0/CR4 of the guest.
878 *
879 * @returns VBox status code.
880 * @param pVM The VM Handle
881 * @param GCPtr The guest pointer to convert.
882 * @param pGCPhys Where to store the HC physical address.
883 */
884PGMDECL(int) PGMPhysGCPtr2GCPhys(PVM pVM, RTGCPTR GCPtr, PRTGCPHYS pGCPhys);
885
886/**
887 * Converts a guest pointer to a HC physical address.
888 *
889 * This uses the current CR3/CR0/CR4 of the guest.
890 *
891 * @returns VBox status code.
892 * @param pVM The VM Handle
893 * @param GCPtr The guest pointer to convert.
894 * @param pHCPhys Where to store the HC physical address.
895 */
896PGMDECL(int) PGMPhysGCPtr2HCPhys(PVM pVM, RTGCPTR GCPtr, PRTHCPHYS pHCPhys);
897
898/**
899 * Converts a guest pointer to a HC pointer.
900 *
901 * This uses the current CR3/CR0/CR4 of the guest.
902 *
903 * @returns VBox status code.
904 * @param pVM The VM Handle
905 * @param GCPtr The guest pointer to convert.
906 * @param pHCPtr Where to store the HC virtual address.
907 */
908PGMDECL(int) PGMPhysGCPtr2HCPtr(PVM pVM, RTGCPTR GCPtr, PRTHCPTR pHCPtr);
909
910/**
911 * Converts a guest virtual address to a HC pointer by specfied CR3 and flags.
912 *
913 * @returns VBox status code.
914 * @param pVM The VM Handle
915 * @param GCPtr The guest pointer to convert.
916 * @param cr3 The guest CR3.
917 * @param fFlags Flags used for interpreting the PD correctly: X86_CR4_PSE and X86_CR4_PAE
918 * @param pHCPtr Where to store the HC pointer.
919 *
920 * @remark This function is used by the REM at a time where PGM could
921 * potentially not be in sync. It could also be used by a
922 * future DBGF API to cpu state independent conversions.
923 */
924PGMDECL(int) PGMPhysGCPtr2HCPtrByGstCR3(PVM pVM, RTGCPTR GCPtr, uint32_t cr3, unsigned fFlags, PRTHCPTR pHCPtr);
925
926/**
927 * Read physical memory.
928 *
929 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
930 * want to ignore those.
931 *
932 * @param pVM VM Handle.
933 * @param GCPhys Physical address start reading from.
934 * @param pvBuf Where to put the read bits.
935 * @param cbRead How many bytes to read.
936 */
937PGMDECL(void) PGMPhysRead(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
938
939/**
940 * Write to physical memory.
941 *
942 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
943 * want to ignore those.
944 *
945 * @param pVM VM Handle.
946 * @param GCPhys Physical address to write to.
947 * @param pvBuf What to write.
948 * @param cbWrite How many bytes to write.
949 */
950PGMDECL(void) PGMPhysWrite(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
951
952
953#ifndef IN_GC /* Only ring 0 & 3. */
954
955/**
956 * Read from guest physical memory by GC physical address, bypassing
957 * MMIO and access handlers.
958 *
959 * @returns VBox status.
960 * @param pVM VM handle.
961 * @param pvDst The destination address.
962 * @param GCPhysSrc The source address (GC physical address).
963 * @param cb The number of bytes to read.
964 */
965PGMDECL(int) PGMPhysReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb);
966
967/**
968 * Write to guest physical memory referenced by GC pointer.
969 * Write memory to GC physical address in guest physical memory.
970 *
971 * This will bypass MMIO and access handlers.
972 *
973 * @returns VBox status.
974 * @param pVM VM handle.
975 * @param GCPhysDst The GC physical address of the destination.
976 * @param pvSrc The source buffer.
977 * @param cb The number of bytes to write.
978 */
979PGMDECL(int) PGMPhysWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb);
980
981/**
982 * Read from guest physical memory referenced by GC pointer.
983 *
984 * This function uses the current CR3/CR0/CR4 of the guest and will
985 * bypass access handlers and not set any accessed bits.
986 *
987 * @returns VBox status.
988 * @param pVM VM handle.
989 * @param pvDst The destination address.
990 * @param GCPtrSrc The source address (GC pointer).
991 * @param cb The number of bytes to read.
992 */
993PGMDECL(int) PGMPhysReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
994
995/**
996 * Write to guest physical memory referenced by GC pointer.
997 *
998 * This function uses the current CR3/CR0/CR4 of the guest and will
999 * bypass access handlers and not set dirty or accessed bits.
1000 *
1001 * @returns VBox status.
1002 * @param pVM VM handle.
1003 * @param GCPtrDst The destination address (GC pointer).
1004 * @param pvSrc The source address.
1005 * @param cb The number of bytes to write.
1006 */
1007PGMDECL(int) PGMPhysWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1008
1009/**
1010 * Write to guest physical memory referenced by GC pointer and update the PTE.
1011 *
1012 * This function uses the current CR3/CR0/CR4 of the guest and will
1013 * bypass access handlers and set any dirty and accessed bits in the PTE.
1014 *
1015 * If you don't want to set the dirty bit, use PGMR3PhysWriteGCPtr().
1016 *
1017 * @returns VBox status.
1018 * @param pVM VM handle.
1019 * @param GCPtrDst The destination address (GC pointer).
1020 * @param pvSrc The source address.
1021 * @param cb The number of bytes to write.
1022 */
1023PGMDECL(int) PGMPhysWriteGCPtrDirty(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1024
1025/**
1026 * Emulation of the invlpg instruction (HC only actually).
1027 *
1028 * @returns VBox status code.
1029 * @param pVM VM handle.
1030 * @param GCPtrPage Page to invalidate.
1031 * @remark ASSUMES the page table entry or page directory is
1032 * valid. Fairly safe, but there could be edge cases!
1033 * @todo Flush page or page directory only if necessary!
1034 */
1035PGMDECL(int) PGMInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1036
1037#endif /* !IN_GC */
1038
1039/**
1040 * Performs a read of guest virtual memory for instruction emulation.
1041 *
1042 * This will check permissions, raise exceptions and update the access bits.
1043 *
1044 * The current implementation will bypass all access handlers. It may later be
1045 * changed to at least respect MMIO.
1046 *
1047 *
1048 * @returns VBox status code suitable to scheduling.
1049 * @retval VINF_SUCCESS if the read was performed successfully.
1050 * @retval VINF_EM_RAW_GUEST_TRAP if an exception was raised but not dispatched yet.
1051 * @retval VINF_TRPM_XCPT_DISPATCHED if an exception was raised and dispatched.
1052 *
1053 * @param pVM The VM handle.
1054 * @param pCtxCore The context core.
1055 * @param pvDst Where to put the bytes we've read.
1056 * @param GCPtrSrc The source address.
1057 * @param cb The number of bytes to read. Not more than a page.
1058 *
1059 * @remark This function will dynamically map physical pages in GC. This may unmap
1060 * mappings done by the caller. Be careful!
1061 */
1062PGMDECL(int) PGMPhysInterpretedRead(PVM pVM, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb);
1063
1064#ifdef VBOX_STRICT
1065/**
1066 * Asserts that the handlers+guest-page-tables == ramrange-flags and
1067 * that the physical addresses associated with virtual handlers are correct.
1068 *
1069 * @returns Number of mismatches.
1070 * @param pVM The VM handle.
1071 */
1072PGMDECL(unsigned) PGMAssertHandlerAndFlagsInSync(PVM pVM);
1073
1074/**
1075 * Asserts that there are no mapping conflicts.
1076 *
1077 * @returns Number of conflicts.
1078 * @param pVM The VM Handle.
1079 */
1080PGMDECL(unsigned) PGMAssertNoMappingConflicts(PVM pVM);
1081
1082/**
1083 * Asserts that everything related to the guest CR3 is correctly shadowed.
1084 *
1085 * This will call PGMAssertNoMappingConflicts() and PGMAssertHandlerAndFlagsInSync(),
1086 * and assert the correctness of the guest CR3 mapping before asserting that the
1087 * shadow page tables is in sync with the guest page tables.
1088 *
1089 * @returns Number of conflicts.
1090 * @param pVM The VM Handle.
1091 * @param cr3 The current guest CR3 register value.
1092 * @param cr4 The current guest CR4 register value.
1093 */
1094PGMDECL(unsigned) PGMAssertCR3(PVM pVM, uint32_t cr3, uint32_t cr4);
1095#endif /* VBOX_STRICT */
1096
1097
1098#ifdef IN_GC
1099
1100/** @defgroup grp_pgm_gc The PGM Guest Context API
1101 * @ingroup grp_pgm
1102 * @{
1103 */
1104
1105/**
1106 * Temporarily maps one guest page specified by 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 * @returns VBox status.
1113 * @param pVM VM handle.
1114 * @param GCPhys GC Physical address of the page.
1115 * @param ppv Where to store the address of the mapping.
1116 */
1117PGMGCDECL(int) PGMGCDynMapGCPage(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1118
1119/**
1120 * Temporarily maps one guest page specified by unaligned GC physical address.
1121 * These pages must have a physical mapping in HC, i.e. they cannot be MMIO pages.
1122 *
1123 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1124 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1125 *
1126 * The caller is aware that only the speicifed page is mapped and that really bad things
1127 * will happen if writing beyond the page!
1128 *
1129 * @returns VBox status.
1130 * @param pVM VM handle.
1131 * @param GCPhys GC Physical address within the page to be mapped.
1132 * @param ppv Where to store the address of the mapping address corresponding to GCPhys.
1133 */
1134PGMGCDECL(int) PGMGCDynMapGCPageEx(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1135
1136/**
1137 * Temporarily maps one host page specified by HC physical address.
1138 *
1139 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1140 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1141 *
1142 * @returns VBox status.
1143 * @param pVM VM handle.
1144 * @param HCPhys HC Physical address of the page.
1145 * @param ppv Where to store the address of the mapping.
1146 */
1147PGMGCDECL(int) PGMGCDynMapHCPage(PVM pVM, RTHCPHYS HCPhys, void **ppv);
1148
1149/**
1150 * Syncs a guest os page table.
1151 *
1152 * @returns VBox status code.
1153 * @param pVM VM handle.
1154 * @param iPD Page directory index.
1155 * @param pPDSrc Source page directory (i.e. Guest OS page directory).
1156 * Assume this is a temporary mapping.
1157 */
1158PGMGCDECL(int) PGMGCSyncPT(PVM pVM, unsigned iPD, PVBOXPD pPDSrc);
1159
1160/**
1161 * Emulation of the invlpg instruction.
1162 *
1163 * @returns VBox status code.
1164 * @param pVM VM handle.
1165 * @param GCPtrPage Page to invalidate.
1166 */
1167PGMGCDECL(int) PGMGCInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1168
1169/** @} */
1170#endif
1171
1172
1173#ifdef IN_RING3
1174/** @defgroup grp_pgm_r3 The PGM Host Context Ring-3 API
1175 * @ingroup grp_pgm
1176 * @{
1177 */
1178/**
1179 * Initiates the paging of VM.
1180 *
1181 * @returns VBox status code.
1182 * @param pVM Pointer to VM structure.
1183 */
1184PGMR3DECL(int) PGMR3Init(PVM pVM);
1185
1186/**
1187 * Init the PGM bits that rely on VMMR0 and MM to be fully initialized.
1188 *
1189 * The dynamic mapping area will also be allocated and initialized at this
1190 * time. We could allocate it during PGMR3Init of course, but the mapping
1191 * wouldn't be allocated at that time preventing us from setting up the
1192 * page table entries with the dummy page.
1193 *
1194 * @returns VBox status code.
1195 * @param pVM VM handle.
1196 */
1197PGMR3DECL(int) PGMR3InitDynMap(PVM pVM);
1198
1199/**
1200 * Ring-3 init finalizing.
1201 *
1202 * @returns VBox status code.
1203 * @param pVM The VM handle.
1204 */
1205PGMR3DECL(int) PGMR3InitFinalize(PVM pVM);
1206
1207/**
1208 * Applies relocations to data and code managed by this
1209 * component. This function will be called at init and
1210 * whenever the VMM need to relocate it self inside the GC.
1211 *
1212 * @param pVM The VM.
1213 * @param offDelta Relocation delta relative to old location.
1214 */
1215PGMR3DECL(void) PGMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
1216
1217/**
1218 * The VM is being reset.
1219 *
1220 * For the PGM component this means that any PD write monitors
1221 * needs to be removed.
1222 *
1223 * @param pVM VM handle.
1224 */
1225PGMR3DECL(void) PGMR3Reset(PVM pVM);
1226
1227/**
1228 * Terminates the PGM.
1229 *
1230 * @returns VBox status code.
1231 * @param pVM Pointer to VM structure.
1232 */
1233PGMR3DECL(int) PGMR3Term(PVM pVM);
1234
1235/**
1236 * Serivce a VMMCALLHOST_PGM_LOCK call.
1237 *
1238 * @returns VBox status code.
1239 * @param pVM The VM handle.
1240 */
1241PDMR3DECL(int) PGMR3LockCall(PVM pVM);
1242
1243/**
1244 * Inform PGM if we want all mappings to be put into the shadow page table. (necessary for e.g. VMX)
1245 *
1246 * @returns VBox status code.
1247 * @param pVM VM handle.
1248 * @param fEnable Enable or disable shadow mappings
1249 */
1250PGMR3DECL(int) PGMR3ChangeShwPDMappings(PVM pVM, bool fEnable);
1251
1252/**
1253 * Allocate missing physical pages for an existing guest RAM range.
1254 *
1255 * @returns VBox status.
1256 * @param pVM The VM handle.
1257 * @param GCPhys GC physical address of the RAM range. (page aligned)
1258 */
1259PGMR3DECL(int) PGM3PhysGrowRange(PVM pVM, RTGCPHYS GCPhys);
1260
1261/**
1262 * Interface MMR3RamRegister(), MMR3RomRegister() and MMIO handler
1263 * registration calls.
1264 *
1265 * It registers the physical memory range with PGM. MM is responsible
1266 * for the toplevel things - allocation and locking - while PGM is taking
1267 * care of all the details and implements the physical address space virtualization.
1268 *
1269 * @returns VBox status.
1270 * @param pVM The VM handle.
1271 * @param pvRam HC virtual address of the RAM range. (page aligned)
1272 * @param GCPhys GC physical address of the RAM range. (page aligned)
1273 * @param cb Size of the RAM range. (page aligned)
1274 * @param fFlags Flags, MM_RAM_*.
1275 * @param paPages Pointer an array of physical page descriptors.
1276 * @param pszDesc Description string.
1277 */
1278PGMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1279
1280/**
1281 * Register a chunk of a the physical memory range with PGM. MM is responsible
1282 * for the toplevel things - allocation and locking - while PGM is taking
1283 * care of all the details and implements the physical address space virtualization.
1284 *
1285 * @returns VBox status.
1286 * @param pVM The VM handle.
1287 * @param pvRam HC virtual address of the RAM range. (page aligned)
1288 * @param GCPhys GC physical address of the RAM range. (page aligned)
1289 * @param cb Size of the RAM range. (page aligned)
1290 * @param fFlags Flags, MM_RAM_*.
1291 * @param paPages Pointer an array of physical page descriptors.
1292 * @param pszDesc Description string.
1293 */
1294PGMR3DECL(int) PGMR3PhysRegisterChunk(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1295
1296/**
1297 * Interface MMIO handler relocation calls.
1298 *
1299 * It relocates an existing physical memory range with PGM.
1300 *
1301 * @returns VBox status.
1302 * @param pVM The VM handle.
1303 * @param GCPhysOld Previous GC physical address of the RAM range. (page aligned)
1304 * @param GCPhysNew New GC physical address of the RAM range. (page aligned)
1305 * @param cb Size of the RAM range. (page aligned)
1306 */
1307PGMR3DECL(int) PGMR3PhysRelocate(PVM pVM, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, size_t cb);
1308
1309/**
1310 * Interface MMR3RomRegister() and MMR3PhysReserve calls to update the
1311 * flags of existing RAM ranges.
1312 *
1313 * @returns VBox status.
1314 * @param pVM The VM handle.
1315 * @param GCPhys GC physical address of the RAM range. (page aligned)
1316 * @param cb Size of the RAM range. (page aligned)
1317 * @param fFlags The Or flags, MM_RAM_* #defines.
1318 * @param fMask The and mask for the flags.
1319 */
1320PGMR3DECL(int) PGMR3PhysSetFlags(PVM pVM, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, unsigned fMask);
1321
1322/**
1323 * Sets the Address Gate 20 state.
1324 *
1325 * @param pVM VM handle.
1326 * @param fEnable True if the gate should be enabled.
1327 * False if the gate should be disabled.
1328 */
1329PGMDECL(void) PGMR3PhysSetA20(PVM pVM, bool fEnable);
1330
1331/**
1332 * Creates a page table based mapping in GC.
1333 *
1334 * @returns VBox status code.
1335 * @param pVM VM Handle.
1336 * @param GCPtr Virtual Address. (Page table aligned!)
1337 * @param cb Size of the range. Must be a 4MB aligned!
1338 * @param pfnRelocate Relocation callback function.
1339 * @param pvUser User argument to the callback.
1340 * @param pszDesc Pointer to description string. This must not be freed.
1341 */
1342PGMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, size_t cb, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc);
1343
1344/**
1345 * Removes a page table based mapping.
1346 *
1347 * @returns VBox status code.
1348 * @param pVM VM Handle.
1349 * @param GCPtr Virtual Address. (Page table aligned!)
1350 */
1351PGMR3DECL(int) PGMR3UnmapPT(PVM pVM, RTGCPTR GCPtr);
1352
1353/**
1354 * Gets the size of the current guest mappings if they were to be
1355 * put next to oneanother.
1356 *
1357 * @returns VBox status code.
1358 * @param pVM The VM.
1359 * @param pcb Where to store the size.
1360 */
1361PGMR3DECL(int) PGMR3MappingsSize(PVM pVM, size_t *pcb);
1362
1363/**
1364 * Fixes the guest context mappings in a range reserved from the Guest OS.
1365 *
1366 * @returns VBox status code.
1367 * @param pVM The VM.
1368 * @param GCPtrBase The address of the reserved range of guest memory.
1369 * @param cb The size of the range starting at GCPtrBase.
1370 */
1371PGMR3DECL(int) PGMR3MappingsFix(PVM pVM, RTGCPTR GCPtrBase, size_t cb);
1372
1373/**
1374 * Unfixes the mappings.
1375 * After calling this function mapping conflict detection will be enabled.
1376 *
1377 * @returns VBox status code.
1378 * @param pVM The VM.
1379 */
1380PGMR3DECL(int) PGMR3MappingsUnfix(PVM pVM);
1381
1382/**
1383 * Map pages into the intermediate context (switcher code).
1384 * These pages are mapped at both the give virtual address and at
1385 * the physical address (for identity mapping).
1386 *
1387 * @returns VBox status code.
1388 * @param pVM The virtual machine.
1389 * @param Addr Intermediate context address of the mapping.
1390 * @param HCPhys Start of the range of physical pages. This must be entriely below 4GB!
1391 * @param cbPages Number of bytes to map.
1392 *
1393 * @remark This API shall not be used to anything but mapping the switcher code.
1394 */
1395PGMR3DECL(int) PGMR3MapIntermediate(PVM pVM, RTUINTPTR Addr, RTHCPHYS HCPhys, unsigned cbPages);
1396
1397/**
1398 * Checks guest PD for conflicts with VMM GC mappings.
1399 *
1400 * @returns true if conflict detected.
1401 * @returns false if not.
1402 * @param pVM The virtual machine.
1403 * @param cr3 Guest context CR3 register.
1404 * @param fRawR0 Whether RawR0 is enabled or not.
1405 */
1406PGMR3DECL(bool) PGMR3MapHasConflicts(PVM pVM, uint32_t cr3, bool fRawR0);
1407
1408/**
1409 * Read memory from the guest mappings.
1410 *
1411 * This will use the page tables associated with the mappings to
1412 * read the memory. This means that not all kind of memory is readable
1413 * since we don't necessarily know how to convert that physical address
1414 * to a HC virtual one.
1415 *
1416 * @returns VBox status.
1417 * @param pVM VM handle.
1418 * @param pvDst The destination address (HC of course).
1419 * @param GCPtrSrc The source address (GC virtual address).
1420 * @param cb Number of bytes to read.
1421 */
1422PGMR3DECL(int) PGMR3MapRead(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
1423
1424/**
1425 * Register a access handler for a physical range.
1426 *
1427 * @returns VBox status code.
1428 * @param pVM VM handle.
1429 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
1430 * @param GCPhys Start physical address.
1431 * @param GCPhysLast Last physical address. (inclusive)
1432 * @param pfnHandlerR3 The R3 handler.
1433 * @param pvUserR3 User argument to the R3 handler.
1434 * @param pszModR0 The R0 handler module. NULL means default R0 module.
1435 * @param pszHandlerR0 The R0 handler symbol name.
1436 * @param pvUserR0 User argument to the R0 handler.
1437 * @param pszModGC The GC handler module. NULL means default GC module.
1438 * @param pszHandlerGC The GC handler symbol name.
1439 * @param pvUserGC User argument to the GC handler.
1440 * This must be a GC pointer because it will be relocated!
1441 * @param pszDesc Pointer to description string. This must not be freed.
1442 */
1443PGMR3DECL(int) PGMR3HandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
1444 PFNPGMR3PHYSHANDLER pfnHandlerR3, void *pvUserR3,
1445 const char *pszModR0, const char *pszHandlerR0, RTR0PTR pvUserR0,
1446 const char *pszModGC, const char *pszHandlerGC, RTGCPTR pvUserGC, const char *pszDesc);
1447
1448/**
1449 * Register an access handler for a virtual range.
1450 *
1451 * @returns VBox status code.
1452 * @param pVM VM handle.
1453 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1454 * @param GCPtr Start address.
1455 * @param GCPtrLast Last address. (inclusive)
1456 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1457 * @param pfnHandlerHC The HC handler.
1458 * @param pfnHandlerGC The GC handler.
1459 * @param pszDesc Pointer to description string. This must not be freed.
1460 */
1461PGMDECL(int) PGMHandlerVirtualRegisterEx(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1462 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1463 PFNPGMHCVIRTHANDLER pfnHandlerHC, RTGCPTR pfnHandlerGC,
1464 HCPTRTYPE(const char *) pszDesc);
1465
1466/**
1467 * Register a access handler for a virtual range.
1468 *
1469 * @returns VBox status code.
1470 * @param pVM VM handle.
1471 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1472 * @param GCPtr Start address.
1473 * @param GCPtrLast Last address. (inclusive)
1474 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1475 * @param pfnHandlerHC The HC handler.
1476 * @param pszHandlerGC The GC handler symbol name.
1477 * @param pszModGC The GC handler module.
1478 * @param pszDesc Pointer to description string. This must not be freed.
1479 */
1480PGMR3DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1481 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1482 PFNPGMHCVIRTHANDLER pfnHandlerHC,
1483 const char *pszHandlerGC, const char *pszModGC, const char *pszDesc);
1484
1485/**
1486 * Modify the page invalidation callback handler for a registered virtual range
1487 * (add more when needed)
1488 *
1489 * @returns VBox status code.
1490 * @param pVM VM handle.
1491 * @param GCPtr Start address.
1492 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1493 */
1494PGMDECL(int) PGMHandlerVirtualChangeInvalidateCallback(PVM pVM, RTGCPTR GCPtr, PFNPGMHCVIRTINVALIDATE pfnInvalidateHC);
1495
1496
1497/**
1498 * Deregister an access handler for a virtual range.
1499 *
1500 * @returns VBox status code.
1501 * @param pVM VM handle.
1502 * @param GCPtr Start address.
1503 */
1504PGMDECL(int) PGMHandlerVirtualDeregister(PVM pVM, RTGCPTR GCPtr);
1505
1506/**
1507 * Grows the shadow page pool.
1508 *
1509 * I.e. adds more pages to it, assuming that hasn't reached cMaxPages yet.
1510 *
1511 * @returns VBox status code.
1512 * @param pVM The VM handle.
1513 */
1514PDMR3DECL(int) PGMR3PoolGrow(PVM pVM);
1515
1516#ifdef ___VBox_dbgf_h /** @todo fix this! */
1517/**
1518 * Dumps a page table hierarchy use only physical addresses and cr4/lm flags.
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, only PAE and PSE is currently used.
1524 * @param fLongMode Set if long mode, false if not long mode.
1525 * @param cMaxDepth Number of levels to dump.
1526 * @param pHlp Pointer to the output functions.
1527 */
1528PGMR3DECL(int) PGMR3DumpHierarchyHC(PVM pVM, uint32_t cr3, uint32_t cr4, bool fLongMode, unsigned cMaxDepth, PCDBGFINFOHLP pHlp);
1529#endif
1530
1531/**
1532 * Dumps a 32-bit guest page directory and page tables.
1533 *
1534 * @returns VBox status code (VINF_SUCCESS).
1535 * @param pVM The VM handle.
1536 * @param cr3 The root of the hierarchy.
1537 * @param cr4 The CR4, PSE is currently used.
1538 * @param PhysSearch Address to search for.
1539 */
1540PGMR3DECL(int) PGMR3DumpHierarchyGC(PVM pVM, uint32_t cr3, uint32_t cr4, RTGCPHYS PhysSearch);
1541
1542/**
1543 * Debug helper - Dumps the supplied page directory.
1544 *
1545 * @internal
1546 */
1547PGMR3DECL(void) PGMR3DumpPD(PVM pVM, PVBOXPD pPD);
1548
1549/**
1550 * Dumps the the PGM mappings..
1551 *
1552 * @param pVM VM handle.
1553 */
1554PGMR3DECL(void) PGMR3DumpMappings(PVM pVM);
1555
1556/** @todo r=bird: s/Byte/U8/ s/Word/U16/ s/Dword/U32/ to match other functions names and returned types. */
1557/**
1558 * Read physical memory. (one byte)
1559 *
1560 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1561 * want to ignore those.
1562 *
1563 * @param pVM VM Handle.
1564 * @param GCPhys Physical address start reading from.
1565 */
1566PGMR3DECL(uint8_t) PGMR3PhysReadByte(PVM pVM, RTGCPHYS GCPhys);
1567
1568/**
1569 * Read physical memory. (one word)
1570 *
1571 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1572 * want to ignore those.
1573 *
1574 * @param pVM VM Handle.
1575 * @param GCPhys Physical address start reading from.
1576 */
1577PGMR3DECL(uint16_t) PGMR3PhysReadWord(PVM pVM, RTGCPHYS GCPhys);
1578
1579/**
1580 * Read physical memory. (one dword)
1581 *
1582 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1583 * want to ignore those.
1584 *
1585 * @param pVM VM Handle.
1586 * @param GCPhys Physical address start reading from.
1587 */
1588PGMR3DECL(uint32_t) PGMR3PhysReadDword(PVM pVM, RTGCPHYS GCPhys);
1589
1590/**
1591 * Write to physical memory. (one byte)
1592 *
1593 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1594 * want to ignore those.
1595 *
1596 * @param pVM VM Handle.
1597 * @param GCPhys Physical address to write to.
1598 * @param val What to write.
1599 */
1600PGMR3DECL(void) PGMR3PhysWriteByte(PVM pVM, RTGCPHYS GCPhys, uint8_t val);
1601
1602/**
1603 * Write to physical memory. (one word)
1604 *
1605 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1606 * want to ignore those.
1607 *
1608 * @param pVM VM Handle.
1609 * @param GCPhys Physical address to write to.
1610 * @param val What to write.
1611 */
1612PGMR3DECL(void) PGMR3PhysWriteWord(PVM pVM, RTGCPHYS GCPhys, uint16_t val);
1613
1614/**
1615 * Write to physical memory. (one dword)
1616 *
1617 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1618 * want to ignore those.
1619 *
1620 * @param pVM VM Handle.
1621 * @param GCPhys Physical address to write to.
1622 * @param val What to write.
1623 */
1624PGMR3DECL(void) PGMR3PhysWriteDword(PVM pVM, RTGCPHYS GCPhys, uint32_t val);
1625
1626/**
1627 * Perform an integrity check on the PGM component.
1628 *
1629 * @returns VINF_SUCCESS if everything is fine.
1630 * @returns VBox error status after asserting on integrity breach.
1631 * @param pVM The VM handle.
1632 */
1633PDMR3DECL(int) PGMR3CheckIntegrity(PVM pVM);
1634
1635/** @} */
1636
1637#endif
1638
1639__END_DECLS
1640
1641/** @} */
1642#endif
1643
Note: See TracBrowser for help on using the repository browser.

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