1 | /* $Id: PATMPatch.h 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PATMPatch - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #ifndef ___PATMPATCH_H
|
---|
18 | #define ___PATMPATCH_H
|
---|
19 |
|
---|
20 | int patmPatchAddReloc32(PVM pVM, PPATCHINFO pPatch, uint8_t *pRelocHC, uint32_t uType, RTGCPTR pSource = 0, RTGCPTR pDest = 0);
|
---|
21 | int patmPatchAddJump(PVM pVM, PPATCHINFO pPatch, uint8_t *pJumpHC, uint32_t offset, RTGCPTR pTargetGC, uint32_t opcode);
|
---|
22 |
|
---|
23 | int patmPatchGenCpuid(PVM pVM, PPATCHINFO pPatch, RTGCPTR pCurInstrGC);
|
---|
24 | int patmPatchGenSxDT(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTGCPTR pCurInstrGC);
|
---|
25 | int patmPatchGenSldtStr(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTGCPTR pCurInstrGC);
|
---|
26 | int patmPatchGenMovControl(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu);
|
---|
27 | int patmPatchGenMovDebug(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu);
|
---|
28 | int patmPatchGenMovFromSS(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTGCPTR pCurInstrGC);
|
---|
29 | int patmPatchGenRelJump(PVM pVM, PPATCHINFO pPatch, GCPTRTYPE(uint8_t *) pTargetGC, uint32_t opcode, bool fSizeOverride);
|
---|
30 | int patmPatchGenLoop(PVM pVM, PPATCHINFO pPatch, GCPTRTYPE(uint8_t *) pTargetGC, uint32_t opcode, bool fSizeOverride);
|
---|
31 | int patmPatchGenPushf(PVM pVM, PPATCHINFO pPatch, bool fSizeOverride);
|
---|
32 | int patmPatchGenPopf(PVM pVM, PPATCHINFO pPatch, GCPTRTYPE(uint8_t *) pReturnAddrGC, bool fSizeOverride, bool fGenJumpBack);
|
---|
33 | int patmPatchGenSti(PVM pVM, PPATCHINFO pPatch, RTGCPTR pCurInstrGC, RTGCPTR pNextInstrGC);
|
---|
34 |
|
---|
35 | int patmPatchGenCli(PVM pVM, PPATCHINFO pPatch);
|
---|
36 | int patmPatchGenIret(PVM pVM, PPATCHINFO pPatch, RTGCPTR pCurInstrGC, bool fSizeOverride);
|
---|
37 | int patmPatchGenDuplicate(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, GCPTRTYPE(uint8_t *) pCurInstrGC);
|
---|
38 | int patmPatchGenPushCS(PVM pVM, PPATCHINFO pPatch);
|
---|
39 |
|
---|
40 | int patmPatchGenStats(PVM pVM, PPATCHINFO pPatch, RTGCPTR pInstrGC);
|
---|
41 |
|
---|
42 | int patmPatchGenCall(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTGCPTR pInstrGC, RTGCPTR pTargetGC, bool fIndirect);
|
---|
43 | int patmPatchGenRet(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, GCPTRTYPE(uint8_t *) pCurInstrGC);
|
---|
44 |
|
---|
45 | int patmPatchGenPatchJump(PVM pVM, PPATCHINFO pPatch, RTGCPTR pCurInstrGC, GCPTRTYPE(uint8_t *) pPatchAddrGC, bool fAddLookupRecord = true);
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Generate indirect jump to unknown destination
|
---|
49 | *
|
---|
50 | * @returns VBox status code.
|
---|
51 | * @param pVM The VM to operate on.
|
---|
52 | * @param pPatch Patch record
|
---|
53 | * @param pCpu Disassembly state
|
---|
54 | * @param pCurInstrGC Current instruction address
|
---|
55 | */
|
---|
56 | int patmPatchGenJump(PVM pVM, PPATCHINFO pPatch, DISCPUSTATE *pCpu, RTGCPTR pCurInstrGC);
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Generate a trap handler entrypoint
|
---|
60 | *
|
---|
61 | * @returns VBox status code.
|
---|
62 | * @param pVM The VM to operate on.
|
---|
63 | * @param pPatch Patch record
|
---|
64 | * @param pTrapHandlerGC IDT handler address
|
---|
65 | */
|
---|
66 | int patmPatchGenTrapEntry(PVM pVM, PPATCHINFO pPatch, RTGCPTR pTrapHandlerGC);
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Generate an interrupt handler entrypoint
|
---|
70 | *
|
---|
71 | * @returns VBox status code.
|
---|
72 | * @param pVM The VM to operate on.
|
---|
73 | * @param pPatch Patch record
|
---|
74 | * @param pIntHandlerGC IDT handler address
|
---|
75 | */
|
---|
76 | int patmPatchGenIntEntry(PVM pVM, PPATCHINFO pPatch, RTGCPTR pIntHandlerGC);
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Generate the jump from guest to patch code
|
---|
80 | *
|
---|
81 | * @returns VBox status code.
|
---|
82 | * @param pVM The VM to operate on.
|
---|
83 | * @param pPatch Patch record
|
---|
84 | * @param pTargetGC Guest target jump
|
---|
85 | * @param fClearInhibitIRQs Clear inhibit irq flag
|
---|
86 | */
|
---|
87 | int patmPatchGenJumpToGuest(PVM pVM, PPATCHINFO pPatch, GCPTRTYPE(uint8_t *) pReturnAddrGC, bool fClearInhibitIRQs = false);
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Generate illegal instruction (int 3)
|
---|
91 | *
|
---|
92 | * @returns VBox status code.
|
---|
93 | * @param pVM The VM to operate on.
|
---|
94 | * @param pPatch Patch structure
|
---|
95 | *
|
---|
96 | */
|
---|
97 | int patmPatchGenIllegalInstr(PVM pVM, PPATCHINFO pPatch);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Set PATM interrupt flag
|
---|
101 | *
|
---|
102 | * @returns VBox status code.
|
---|
103 | * @param pVM The VM to operate on.
|
---|
104 | * @param pPatch Patch structure
|
---|
105 | * @param pInstrGC Corresponding guest instruction
|
---|
106 | *
|
---|
107 | */
|
---|
108 | int patmPatchGenSetPIF(PVM pVM, PPATCHINFO pPatch, RTGCPTR pInstrGC);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Clear PATM interrupt flag
|
---|
112 | *
|
---|
113 | * @returns VBox status code.
|
---|
114 | * @param pVM The VM to operate on.
|
---|
115 | * @param pPatch Patch structure
|
---|
116 | * @param pInstrGC Corresponding guest instruction
|
---|
117 | *
|
---|
118 | */
|
---|
119 | int patmPatchGenClearPIF(PVM pVM, PPATCHINFO pPatch, RTGCPTR pInstrGC);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Clear PATM inhibit irq flag
|
---|
123 | *
|
---|
124 | * @returns VBox status code.
|
---|
125 | * @param pVM The VM to operate on.
|
---|
126 | * @param pPatch Patch structure
|
---|
127 | * @param pNextInstrGC Next guest instruction
|
---|
128 | */
|
---|
129 | int patmPatchGenClearInhibitIRQ(PVM pVM, PPATCHINFO pPatch, RTGCPTR pNextInstrGC);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Check virtual IF flag and jump back to original guest code if set
|
---|
133 | *
|
---|
134 | * @returns VBox status code.
|
---|
135 | * @param pVM The VM to operate on.
|
---|
136 | * @param pPatch Patch structure
|
---|
137 | * @param pCurInstrGC Guest context pointer to the current instruction
|
---|
138 | *
|
---|
139 | */
|
---|
140 | int patmPatchGenCheckIF(PVM pVM, PPATCHINFO pPatch, RTGCPTR pCurInstrGC);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Generate all global patm functions
|
---|
144 | *
|
---|
145 | * @returns VBox status code.
|
---|
146 | * @param pVM The VM to operate on.
|
---|
147 | * @param pPatch Patch structure
|
---|
148 | *
|
---|
149 | */
|
---|
150 | int patmPatchGenGlobalFunctions(PVM pVM, PPATCHINFO pPatch);
|
---|
151 |
|
---|
152 | #endif
|
---|