1 | /* $Id: TRPMR0.cpp 14515 2008-11-24 12:33:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * TRPM - The Trap Monitor - HC Ring 0
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_TRPM
|
---|
27 | #include <VBox/trpm.h>
|
---|
28 | #include "TRPMInternal.h"
|
---|
29 | #include <VBox/vm.h>
|
---|
30 | #include <VBox/err.h>
|
---|
31 | #include <VBox/log.h>
|
---|
32 | #include <iprt/assert.h>
|
---|
33 | #include <iprt/asm.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Dispatches an interrupt that arrived while we were in the guest context.
|
---|
38 | *
|
---|
39 | * @param pVM The VM handle.
|
---|
40 | * @remark Must be called with interrupts disabled.
|
---|
41 | */
|
---|
42 | VMMR0DECL(void) TRPMR0DispatchHostInterrupt(PVM pVM)
|
---|
43 | {
|
---|
44 | RTUINT uActiveVector = pVM->trpm.s.uActiveVector;
|
---|
45 | pVM->trpm.s.uActiveVector = ~0;
|
---|
46 | AssertMsgReturnVoid(uActiveVector < 256, ("uActiveVector=%#x is invalid! (More assertions to come, please enjoy!)\n", uActiveVector));
|
---|
47 |
|
---|
48 | #ifdef VBOX_WITH_HYBIRD_32BIT_KERNEL
|
---|
49 | /*
|
---|
50 | * Check if we're in long mode or not.
|
---|
51 | */
|
---|
52 | if ( (ASMCpuId_EDX(0x80000001) & X86_CPUID_AMD_FEATURE_EDX_LONG_MODE)
|
---|
53 | && (ASMRdMsr(MSR_K6_EFER) & MSR_K6_EFER_LMA))
|
---|
54 | {
|
---|
55 | trpmR0DispatchHostInterruptSimple(uActiveVector);
|
---|
56 | return;
|
---|
57 | }
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Get the handler pointer (16:32 ptr) / (16:48 ptr).
|
---|
62 | */
|
---|
63 | RTIDTR Idtr;
|
---|
64 | ASMGetIDTR(&Idtr);
|
---|
65 | #if HC_ARCH_BITS == 32
|
---|
66 | PVBOXIDTE pIdte = &((PVBOXIDTE)Idtr.pIdt)[uActiveVector];
|
---|
67 | #else
|
---|
68 | PVBOXIDTE pIdte = &((PVBOXIDTE)Idtr.pIdt)[uActiveVector * 2];
|
---|
69 | #endif
|
---|
70 | AssertMsgReturnVoid(pIdte->Gen.u1Present, ("The IDT entry (%d) is not present!\n", uActiveVector));
|
---|
71 | AssertMsgReturnVoid( pIdte->Gen.u3Type1 == VBOX_IDTE_TYPE1
|
---|
72 | || pIdte->Gen.u5Type2 == VBOX_IDTE_TYPE2_INT_32,
|
---|
73 | ("The IDT entry (%d) is not 32-bit int gate! type1=%#x type2=%#x\n",
|
---|
74 | uActiveVector, pIdte->Gen.u3Type1, pIdte->Gen.u5Type2));
|
---|
75 | #if HC_ARCH_BITS == 32
|
---|
76 | RTFAR32 pfnHandler;
|
---|
77 | pfnHandler.off = VBOXIDTE_OFFSET(*pIdte);
|
---|
78 | pfnHandler.sel = pIdte->Gen.u16SegSel;
|
---|
79 |
|
---|
80 | const RTR0UINTREG uRSP = ~(RTR0UINTREG)0;
|
---|
81 |
|
---|
82 | #else /* 64-bit: */
|
---|
83 | RTFAR64 pfnHandler;
|
---|
84 | pfnHandler.off = VBOXIDTE_OFFSET(*pIdte);
|
---|
85 | pfnHandler.off |= (uint64_t)(*(uint32_t *)(pIdte + 1)) << 32; //cleanup!
|
---|
86 | pfnHandler.sel = pIdte->Gen.u16SegSel;
|
---|
87 |
|
---|
88 | RTR0UINTREG uRSP = ~(RTR0UINTREG)0;
|
---|
89 | if (pIdte->au32[1] & 0x7 /*IST*/)
|
---|
90 | {
|
---|
91 | trpmR0DispatchHostInterruptSimple(uActiveVector);
|
---|
92 | return;
|
---|
93 | }
|
---|
94 |
|
---|
95 | #endif
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Dispatch it.
|
---|
99 | */
|
---|
100 | trpmR0DispatchHostInterrupt(pfnHandler.off, pfnHandler.sel, uRSP);
|
---|
101 | }
|
---|
102 |
|
---|