1 | /* $Id: PGMR0.cpp 10471 2008-07-10 13:45:02Z 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 | #define LOG_GROUP LOG_GROUP_PGM
|
---|
26 | #include <VBox/pgm.h>
|
---|
27 | #include "PGMInternal.h"
|
---|
28 | #include <VBox/vm.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 | #include <VBox/err.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 | __BEGIN_DECLS
|
---|
34 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_PROT(name)
|
---|
35 | #include "PGMR0Bth.h"
|
---|
36 | #undef PGM_BTH_NAME
|
---|
37 |
|
---|
38 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PROT(name)
|
---|
39 | #include "PGMR0Bth.h"
|
---|
40 | #undef PGM_BTH_NAME
|
---|
41 |
|
---|
42 | #define PGM_BTH_NAME(name) PGM_BTH_NAME_AMD64_PROT(name)
|
---|
43 | #include "PGMR0Bth.h"
|
---|
44 | #undef PGM_BTH_NAME
|
---|
45 |
|
---|
46 | __END_DECLS
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Worker function for PGMR3PhysAllocateHandyPages and pgmPhysEnsureHandyPage.
|
---|
51 | *
|
---|
52 | * @returns The following VBox status codes.
|
---|
53 | * @retval VINF_SUCCESS on success. FF cleared.
|
---|
54 | * @retval VINF_EM_NO_MEMORY if we're out of memory. The FF is set in this case.
|
---|
55 | *
|
---|
56 | * @param pVM The VM handle.
|
---|
57 | *
|
---|
58 | * @remarks Must be called from within the PGM critical section.
|
---|
59 | */
|
---|
60 | PGMR0DECL(int) PGMR0PhysAllocateHandyPages(PVM pVM)
|
---|
61 | {
|
---|
62 | return VERR_NOT_IMPLEMENTED;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * #PF Handler for nested paging.
|
---|
68 | *
|
---|
69 | * @returns VBox status code (appropriate for trap handling and GC return).
|
---|
70 | * @param pVM VM Handle.
|
---|
71 | * @param enmShwPagingMode Paging mode for the nested page tables
|
---|
72 | * @param uErr The trap error code.
|
---|
73 | * @param pRegFrame Trap register frame.
|
---|
74 | * @param pvFault The fault address.
|
---|
75 | */
|
---|
76 | PGMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PVM pVM, PGMMODE enmShwPagingMode, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPHYS pvFault)
|
---|
77 | {
|
---|
78 | int rc;
|
---|
79 |
|
---|
80 | LogFlow(("PGMTrap0eHandler: uErr=%#x pvFault=%VGp eip=%VGv\n", uErr, pvFault, pRegFrame->rip));
|
---|
81 | STAM_PROFILE_START(&pVM->pgm.s.StatGCTrap0e, a);
|
---|
82 | STAM_STATS({ pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution) = NULL; } );
|
---|
83 |
|
---|
84 | /* AMD uses the host's paging mode; Intel's version is on the todo list */
|
---|
85 | AssertMsg(enmShwPagingMode == PGMMODE_32_BIT || enmShwPagingMode == PGMMODE_PAE || enmShwPagingMode == PGMMODE_PAE_NX || enmShwPagingMode == PGMMODE_AMD64 || enmShwPagingMode == PGMMODE_AMD64_NX, ("enmShwPagingMode=%d\n", enmShwPagingMode));
|
---|
86 |
|
---|
87 | #ifdef VBOX_WITH_STATISTICS
|
---|
88 | /*
|
---|
89 | * Error code stats.
|
---|
90 | */
|
---|
91 | if (uErr & X86_TRAP_PF_US)
|
---|
92 | {
|
---|
93 | if (!(uErr & X86_TRAP_PF_P))
|
---|
94 | {
|
---|
95 | if (uErr & X86_TRAP_PF_RW)
|
---|
96 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNotPresentWrite);
|
---|
97 | else
|
---|
98 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNotPresentRead);
|
---|
99 | }
|
---|
100 | else if (uErr & X86_TRAP_PF_RW)
|
---|
101 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSWrite);
|
---|
102 | else if (uErr & X86_TRAP_PF_RSVD)
|
---|
103 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSReserved);
|
---|
104 | else if (uErr & X86_TRAP_PF_ID)
|
---|
105 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSNXE);
|
---|
106 | else
|
---|
107 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eUSRead);
|
---|
108 | }
|
---|
109 | else
|
---|
110 | { /* Supervisor */
|
---|
111 | if (!(uErr & X86_TRAP_PF_P))
|
---|
112 | {
|
---|
113 | if (uErr & X86_TRAP_PF_RW)
|
---|
114 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVNotPresentWrite);
|
---|
115 | else
|
---|
116 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVNotPresentRead);
|
---|
117 | }
|
---|
118 | else if (uErr & X86_TRAP_PF_RW)
|
---|
119 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVWrite);
|
---|
120 | else if (uErr & X86_TRAP_PF_ID)
|
---|
121 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSNXE);
|
---|
122 | else if (uErr & X86_TRAP_PF_RSVD)
|
---|
123 | STAM_COUNTER_INC(&pVM->pgm.s.StatGCTrap0eSVReserved);
|
---|
124 | }
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * Call the worker.
|
---|
129 | *
|
---|
130 | * We pretend the guest is in protected mode without paging, so we can use existing code to build the
|
---|
131 | * nested page tables.
|
---|
132 | */
|
---|
133 | switch(enmShwPagingMode)
|
---|
134 | {
|
---|
135 | case PGMMODE_32_BIT:
|
---|
136 | rc = PGM_BTH_NAME_32BIT_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
137 | break;
|
---|
138 | case PGMMODE_PAE:
|
---|
139 | case PGMMODE_PAE_NX:
|
---|
140 | rc = PGM_BTH_NAME_PAE_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
141 | break;
|
---|
142 | case PGMMODE_AMD64:
|
---|
143 | case PGMMODE_AMD64_NX:
|
---|
144 | rc = PGM_BTH_NAME_AMD64_PROT(Trap0eHandler)(pVM, uErr, pRegFrame, pvFault);
|
---|
145 | break;
|
---|
146 | default:
|
---|
147 | AssertFailed();
|
---|
148 | rc = VERR_INVALID_PARAMETER;
|
---|
149 | break;
|
---|
150 | }
|
---|
151 | if (rc == VINF_PGM_SYNCPAGE_MODIFIED_PDE)
|
---|
152 | rc = VINF_SUCCESS;
|
---|
153 | STAM_STATS({ if (!pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution))
|
---|
154 | pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution) = &pVM->pgm.s.StatTrap0eMisc; });
|
---|
155 | STAM_PROFILE_STOP_EX(&pVM->pgm.s.StatGCTrap0e, pVM->pgm.s.CTXSUFF(pStatTrap0eAttribution), a);
|
---|
156 | return rc;
|
---|
157 | }
|
---|