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