1
/* $Id: CPUMGC.cpp $ */
3
* CPUM - Guest Context Code.
7
* Copyright (C) 2006-2007 Oracle Corporation
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.
19
/*******************************************************************************
21
*******************************************************************************/
22
#define LOG_GROUP LOG_GROUP_CPUM
23
#include <VBox/cpum.h>
25
#include <VBox/trpm.h>
26
#include "CPUMInternal.h"
29
#include <iprt/assert.h>
33
/*******************************************************************************
34
* Internal Functions *
35
*******************************************************************************/
36
RT_C_DECLS_BEGIN /* addressed from asm (not called so no DECLASM). */
37
DECLCALLBACK(int) cpumGCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser);
42
* Deal with traps occuring during segment loading and IRET
43
* when resuming guest context.
45
* @returns VBox status code.
46
* @param pVM The VM handle.
47
* @param pRegFrame The register frame.
48
* @param uUser User argument. In this case a combination of the
49
* CPUM_HANDLER_* \#defines.
51
DECLCALLBACK(int) cpumGCHandleNPAndGP(PVM pVM, PCPUMCTXCORE pRegFrame, uintptr_t uUser)
53
Log(("********************************************************\n"));
54
Log(("cpumGCHandleNPAndGP: eip=%RX32 uUser=%#x\n", pRegFrame->eip, uUser));
55
Log(("********************************************************\n"));
57
PVMCPU pVCpu = VMMGetCpu0(pVM);
60
* Update the guest cpu state.
62
if (uUser & CPUM_HANDLER_CTXCORE_IN_EBP)
64
PCPUMCTXCORE pGstCtxCore = (PCPUMCTXCORE)CPUMGetGuestCtxCore(pVCpu);
65
PCCPUMCTXCORE pGstCtxCoreSrc = (PCPUMCTXCORE)pRegFrame->ebp;
66
*pGstCtxCore = *pGstCtxCoreSrc;
70
* Take action based on what's happended.
72
switch (uUser & CPUM_HANDLER_TYPEMASK)
75
// if (!pVM->cpum.s.Guest.ldtr)
78
// pRegFrame->eip += 6; /* mov gs, [edx + CPUM.Guest.gs] */
79
// return VINF_SUCCESS;
84
TRPMGCHyperReturnToHost(pVM, VINF_EM_RAW_STALE_SELECTOR);
87
/* Make sure we restore the guest context from the interrupt stack frame. */
88
case CPUM_HANDLER_IRET:
90
PCPUMCTXCORE pGstCtxCore = (PCPUMCTXCORE)CPUMGetGuestCtxCore(pVCpu);
91
uint32_t *pEsp = (uint32_t *)pRegFrame->esp;
93
/* Sync general purpose registers */
94
*pGstCtxCore = *pRegFrame;
96
pGstCtxCore->eip = *pEsp++;
97
pGstCtxCore->cs = (RTSEL)*pEsp++;
98
pGstCtxCore->eflags.u32 = *pEsp++;
99
pGstCtxCore->esp = *pEsp++;
100
pGstCtxCore->ss = (RTSEL)*pEsp++;
101
if (pGstCtxCore->eflags.Bits.u1VM)
103
pGstCtxCore->es = (RTSEL)*pEsp++;
104
pGstCtxCore->ds = (RTSEL)*pEsp++;
105
pGstCtxCore->fs = (RTSEL)*pEsp++;
106
pGstCtxCore->gs = (RTSEL)*pEsp++;
109
TRPMGCHyperReturnToHost(pVM, VINF_EM_RAW_IRET_TRAP);
113
return VERR_TRPM_DONT_PANIC;