1 | /* $Id: PGMR0.cpp 9686 2008-06-13 13:43:10Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PGM - Page Manager and Monitor, Ring-0.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Header Files *
|
---|
24 | *******************************************************************************/
|
---|
25 | #include <VBox/pgm.h>
|
---|
26 | #include "PGMInternal.h"
|
---|
27 | #include <VBox/vm.h>
|
---|
28 | #include <VBox/log.h>
|
---|
29 | #include <VBox/err.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 |
|
---|
32 | __BEGIN_DECLS
|
---|
33 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_PROT(name)
|
---|
34 | #include "PGMR0Bth.h"
|
---|
35 | #undef PGM_BTH_NAME
|
---|
36 |
|
---|
37 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PROT(name)
|
---|
38 | #include "PGMR0Bth.h"
|
---|
39 | #undef PGM_BTH_NAME
|
---|
40 |
|
---|
41 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_AMD64_PROT(name)
|
---|
42 | #include "PGMR0Bth.h"
|
---|
43 | #undef PGM_BTH_NAME
|
---|
44 |
|
---|
45 | __END_DECLS
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Worker function for PGMR3PhysAllocateHandyPages and pgmPhysEnsureHandyPage.
|
---|
50 | *
|
---|
51 | * @returns The following VBox status codes.
|
---|
52 | * @retval VINF_SUCCESS on success. FF cleared.
|
---|
53 | * @retval VINF_EM_NO_MEMORY if we're out of memory. The FF is set in this case.
|
---|
54 | *
|
---|
55 | * @param pVM The VM handle.
|
---|
56 | *
|
---|
57 | * @remarks Must be called from within the PGM critical section.
|
---|
58 | */
|
---|
59 | PGMR0DECL(int) PGMR0PhysAllocateHandyPages(PVM pVM)
|
---|
60 | {
|
---|
61 | return VERR_NOT_IMPLEMENTED;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * #PF Handler for nested paging.
|
---|
67 | *
|
---|
68 | * @returns VBox status code (appropriate for trap handling and GC return).
|
---|
69 | * @param pVM VM Handle.
|
---|
70 | * @param enmShwPagingMode Paging mode for the nested page tables
|
---|
71 | * @param uErr The trap error code.
|
---|
72 | * @param pRegFrame Trap register frame.
|
---|
73 | * @param pvFault The fault address.
|
---|
74 | */
|
---|
75 | PGMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PVM pVM, PGMMODE enmShwPagingMode, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPHYS pvFault)
|
---|
76 | {
|
---|
77 | int rc;
|
---|
78 |
|
---|
79 | LogFlow(("PGMTrap0eHandler: uErr=%#x pvFault=%VGp eip=%VGv\n", uErr, pvFault, pRegFrame->rip));
|
---|
80 | STAM_PROFILE_START(&pVM->pgm.s.StatGCTrap0e, a);
|
---|
81 | STAM_STATS({ pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution) = NULL; } );
|
---|
82 |
|
---|
83 | /* AMD uses the host's paging mode; Intel's version is on the todo list */
|
---|
84 | Assert(enmShwPagingMode == PGMMODE_32_BIT || enmShwPagingMode == PGMMODE_PAE || enmShwPagingMode == PGMMODE_AMD64);
|
---|
85 |
|
---|
86 | #ifdef VBOX_WITH_STATISTICS
|
---|
87 | /*
|
---|
88 | * Error code stats.
|
---|
89 | */
|
---|
90 | if (uErr & X86_TRAP_PF_US)
|
---|
91 | {
|
---|
92 | if (!(uErr & X86_TRAP_PF_P))
|
---|
93 | {
|
---|
94 | if (uErr & X86_TRAP_PF_RW)
|
---|
95 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNotPresentWrite);
|
---|
96 | else
|
---|
97 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNotPresentRead);
|
---|
98 | }
|
---|
99 | else if (uErr & X86_TRAP_PF_RW)
|
---|
100 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSWrite);
|
---|
101 | else if (uErr & X86_TRAP_PF_RSVD)
|
---|
102 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSReserved);
|
---|
103 | else if (uErr & X86_TRAP_PF_ID)
|
---|
104 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNXE);
|
---|
105 | else
|
---|
106 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSRead);
|
---|
107 | }
|
---|
108 | else
|
---|
109 | { /* Supervisor */
|
---|
110 | if (!(uErr & X86_TRAP_PF_P))
|
---|
111 | {
|
---|
112 | if (uErr & X86_TRAP_PF_RW)
|
---|
113 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVNotPresentWrite);
|
---|
114 | else
|
---|
115 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVNotPresentRead);
|
---|
116 | }
|
---|
117 | else if (uErr & X86_TRAP_PF_RW)
|
---|
118 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVWrite);
|
---|
119 | else if (uErr & X86_TRAP_PF_ID)
|
---|
120 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSNXE);
|
---|
121 | else if (uErr & X86_TRAP_PF_RSVD)
|
---|
122 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVReserved);
|
---|
123 | }
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * Call the worker.
|
---|
128 | *
|
---|
129 | * We pretend the guest is in protected mode without paging, so we can use existing code to build the
|
---|
130 | * nested page tables.
|
---|
131 | */
|
---|
132 | switch(enmShwPagingMode)
|
---|
133 | {
|
---|
134 | case PGMMODE_32_BIT:
|
---|
135 | rc = PGM_BTH_NAME_32BIT_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
136 | break;
|
---|
137 | case PGMMODE_PAE:
|
---|
138 | rc = PGM_BTH_NAME_PAE_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
139 | break;
|
---|
140 | case PGMMODE_AMD64:
|
---|
141 | rc = PGM_BTH_NAME_AMD64_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
142 | break;
|
---|
143 | }
|
---|
144 | if (rc == VINF_PGM_SYNCPAGE_MODIFIED_PDE)
|
---|
145 | rc = VINF_SUCCESS;
|
---|
146 | STAM_STATS({ if (!pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution))
|
---|
147 | pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution) = &pVM->pgm.s.StatTrap0eMisc; });
|
---|
148 | STAM_PROFILE_STOP_EX(&pVM->pgm.s.StatGCTrap0e, pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution), a);
|
---|
149 | return rc;
|
---|
150 | }
|
---|