VirtualBox

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

Last change on this file since 1227 was 1209, checked in by vboxsync, 18 years ago

PGMR3ChangeShwPDMappings added

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