VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/IEMAllN8vePython.py@ 101369

最後變更 在這個檔案從101369是 101369,由 vboxsync 提交於 18 月 前

Main/Global.cpp: Move the macros for compose the x64/x86/arm64/arm32 guest OS IDs to the VirtualBox API header so the GUI and others can make use of them as well. bugref:10384

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 14.0 KB
 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: IEMAllN8vePython.py 101369 2023-10-06 01:22:15Z vboxsync $
4# pylint: disable=invalid-name
5
6"""
7Native recompiler side-kick for IEMAllThrdPython.py.
8
9Analyzes the each threaded function variant to see if we can we're able to
10recompile it, then provides modifies MC block code for doing so.
11"""
12
13from __future__ import print_function;
14
15__copyright__ = \
16"""
17Copyright (C) 2023 Oracle and/or its affiliates.
18
19This file is part of VirtualBox base platform packages, as
20available from https://www.alldomusa.eu.org.
21
22This program is free software; you can redistribute it and/or
23modify it under the terms of the GNU General Public License
24as published by the Free Software Foundation, in version 3 of the
25License.
26
27This program is distributed in the hope that it will be useful, but
28WITHOUT ANY WARRANTY; without even the implied warranty of
29MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30General Public License for more details.
31
32You should have received a copy of the GNU General Public License
33along with this program; if not, see <https://www.gnu.org/licenses>.
34
35SPDX-License-Identifier: GPL-3.0-only
36"""
37__version__ = "$Revision: 101369 $"
38
39# Standard python imports:
40#import sys;
41
42# Out python imports:
43import IEMAllInstPython as iai;
44
45
46## Supplememnts g_dMcStmtParsers.
47g_dMcStmtThreaded = {
48 'IEM_MC_DEFER_TO_CIMPL_0_RET_THREADED': (None, True, True, ),
49 'IEM_MC_DEFER_TO_CIMPL_1_RET_THREADED': (None, True, True, ),
50 'IEM_MC_DEFER_TO_CIMPL_2_RET_THREADED': (None, True, True, ),
51 'IEM_MC_DEFER_TO_CIMPL_3_RET_THREADED': (None, True, True, ),
52
53 'IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC16': (None, True, False, ),
54 'IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC32': (None, True, True, ),
55 'IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC64': (None, True, False, ),
56
57 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_16_ADDR32': (None, False, False, ),
58 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_16_PRE386': (None, False, False, ),
59 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_16': (None, False, False, ),
60 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_32_ADDR16': (None, False, False, ),
61 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_32_FLAT': (None, False, False, ),
62 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_32': (None, False, False, ),
63 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_64_ADDR32': (None, False, False, ),
64 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_64_FSGS': (None, False, False, ),
65 'IEM_MC_CALC_RM_EFF_ADDR_THREADED_64': (None, False, False, ),
66
67 'IEM_MC_CALL_CIMPL_1_THREADED': (None, True, False, ),
68 'IEM_MC_CALL_CIMPL_2_THREADED': (None, True, False, ),
69 'IEM_MC_CALL_CIMPL_3_THREADED': (None, True, False, ),
70 'IEM_MC_CALL_CIMPL_4_THREADED': (None, True, False, ),
71 'IEM_MC_CALL_CIMPL_5_THREADED': (None, True, False, ),
72
73 'IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC16': (None, True, False, ),
74 'IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC32': (None, True, False, ),
75 'IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC64': (None, True, False, ),
76 'IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC16': (None, True, False, ),
77 'IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC32': (None, True, False, ),
78 'IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC64': (None, True, False, ),
79 'IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC32': (None, True, False, ),
80 'IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC64': (None, True, False, ),
81
82 'IEM_MC_STORE_GREG_U8_THREADED': (None, True, False, ),
83 'IEM_MC_STORE_GREG_U8_CONST_THREADED': (None, True, False, ),
84 'IEM_MC_FETCH_GREG_U8_THREADED': (None, False, False, ),
85 'IEM_MC_FETCH_GREG_U8_SX_U16_THREADED': (None, False, False, ),
86 'IEM_MC_FETCH_GREG_U8_SX_U32_THREADED': (None, False, False, ),
87 'IEM_MC_FETCH_GREG_U8_SX_U64_THREADED': (None, False, False, ),
88 'IEM_MC_FETCH_GREG_U8_ZX_U16_THREADED': (None, False, False, ),
89 'IEM_MC_FETCH_GREG_U8_ZX_U32_THREADED': (None, False, False, ),
90 'IEM_MC_FETCH_GREG_U8_ZX_U64_THREADED': (None, False, False, ),
91 'IEM_MC_REF_GREG_U8_THREADED': (None, True, False, ),
92
93 # Flat Mem:
94 'IEM_MC_FETCH_MEM16_FLAT_U8': (None, True, False, ),
95 'IEM_MC_FETCH_MEM32_FLAT_U8': (None, True, False, ),
96 'IEM_MC_FETCH_MEM_FLAT_D80': (None, True, False, ),
97 'IEM_MC_FETCH_MEM_FLAT_I16': (None, True, False, ),
98 'IEM_MC_FETCH_MEM_FLAT_I32': (None, True, False, ),
99 'IEM_MC_FETCH_MEM_FLAT_I64': (None, True, False, ),
100 'IEM_MC_FETCH_MEM_FLAT_R32': (None, True, False, ),
101 'IEM_MC_FETCH_MEM_FLAT_R64': (None, True, False, ),
102 'IEM_MC_FETCH_MEM_FLAT_R80': (None, True, False, ),
103 'IEM_MC_FETCH_MEM_FLAT_U128_ALIGN_SSE': (None, True, False, ),
104 'IEM_MC_FETCH_MEM_FLAT_U128_NO_AC': (None, True, False, ),
105 'IEM_MC_FETCH_MEM_FLAT_U128': (None, True, False, ),
106 'IEM_MC_FETCH_MEM_FLAT_U16_DISP': (None, True, False, ),
107 'IEM_MC_FETCH_MEM_FLAT_U16_SX_U32': (None, True, False, ),
108 'IEM_MC_FETCH_MEM_FLAT_U16_SX_U64': (None, True, False, ),
109 'IEM_MC_FETCH_MEM_FLAT_U16': (None, True, False, ),
110 'IEM_MC_FETCH_MEM_FLAT_U16_ZX_U32': (None, True, False, ),
111 'IEM_MC_FETCH_MEM_FLAT_U16_ZX_U64': (None, True, False, ),
112 'IEM_MC_FETCH_MEM_FLAT_U256_ALIGN_AVX': (None, True, False, ),
113 'IEM_MC_FETCH_MEM_FLAT_U256_NO_AC': (None, True, False, ),
114 'IEM_MC_FETCH_MEM_FLAT_U256': (None, True, False, ),
115 'IEM_MC_FETCH_MEM_FLAT_U32_DISP': (None, True, False, ),
116 'IEM_MC_FETCH_MEM_FLAT_U32_SX_U64': (None, True, False, ),
117 'IEM_MC_FETCH_MEM_FLAT_U32': (None, True, False, ),
118 'IEM_MC_FETCH_MEM_FLAT_U32_ZX_U64': (None, True, False, ),
119 'IEM_MC_FETCH_MEM_FLAT_U64': (None, True, False, ),
120 'IEM_MC_FETCH_MEM_FLAT_U8_SX_U16': (None, True, False, ),
121 'IEM_MC_FETCH_MEM_FLAT_U8_SX_U32': (None, True, False, ),
122 'IEM_MC_FETCH_MEM_FLAT_U8_SX_U64': (None, True, False, ),
123 'IEM_MC_FETCH_MEM_FLAT_U8': (None, True, False, ),
124 'IEM_MC_FETCH_MEM_FLAT_U8_ZX_U16': (None, True, False, ),
125 'IEM_MC_FETCH_MEM_FLAT_U8_ZX_U32': (None, True, False, ),
126 'IEM_MC_FETCH_MEM_FLAT_U8_ZX_U64': (None, True, False, ),
127 'IEM_MC_FETCH_MEM_FLAT_XMM_ALIGN_SSE': (None, True, False, ),
128 'IEM_MC_FETCH_MEM_FLAT_XMM_U32': (None, True, False, ),
129 'IEM_MC_FETCH_MEM_FLAT_XMM_U64': (None, True, False, ),
130 'IEM_MC_MEM_FLAT_MAP_EX': (None, True, False, ),
131 'IEM_MC_MEM_FLAT_MAP': (None, True, False, ),
132 'IEM_MC_MEM_FLAT_MAP_U16_RO': (None, True, False, ),
133 'IEM_MC_MEM_FLAT_MAP_U16_RW': (None, True, False, ),
134 'IEM_MC_MEM_FLAT_MAP_U32_RO': (None, True, False, ),
135 'IEM_MC_MEM_FLAT_MAP_U32_RW': (None, True, False, ),
136 'IEM_MC_MEM_FLAT_MAP_U64_RO': (None, True, False, ),
137 'IEM_MC_MEM_FLAT_MAP_U64_RW': (None, True, False, ),
138 'IEM_MC_MEM_FLAT_MAP_U8_RO': (None, True, False, ),
139 'IEM_MC_MEM_FLAT_MAP_U8_RW': (None, True, False, ),
140 'IEM_MC_STORE_MEM_FLAT_U128_ALIGN_SSE': (None, True, False, ),
141 'IEM_MC_STORE_MEM_FLAT_U128': (None, True, False, ),
142 'IEM_MC_STORE_MEM_FLAT_U16': (None, True, False, ),
143 'IEM_MC_STORE_MEM_FLAT_U256_ALIGN_AVX': (None, True, False, ),
144 'IEM_MC_STORE_MEM_FLAT_U256': (None, True, False, ),
145 'IEM_MC_STORE_MEM_FLAT_U32': (None, True, False, ),
146 'IEM_MC_STORE_MEM_FLAT_U64': (None, True, False, ),
147 'IEM_MC_STORE_MEM_FLAT_U8_CONST': (None, True, False, ),
148 'IEM_MC_STORE_MEM_FLAT_U8': (None, True, False, ),
149
150 # Flat Stack:
151 'IEM_MC_FLAT64_PUSH_U16': (None, True, False, ),
152 'IEM_MC_FLAT64_PUSH_U64': (None, True, False, ),
153 'IEM_MC_FLAT64_PUSH_U16': (None, True, False, ),
154 'IEM_MC_FLAT64_PUSH_U64': (None, True, False, ),
155 'IEM_MC_FLAT64_POP_U16': (None, True, False, ),
156 'IEM_MC_FLAT64_POP_U64': (None, True, False, ),
157 'IEM_MC_FLAT64_POP_U16': (None, True, False, ),
158 'IEM_MC_FLAT64_POP_U64': (None, True, False, ),
159 'IEM_MC_FLAT64_PUSH_U16': (None, True, False, ),
160 'IEM_MC_FLAT64_PUSH_U64': (None, True, False, ),
161 'IEM_MC_FLAT64_PUSH_U16': (None, True, False, ),
162 'IEM_MC_FLAT64_PUSH_U64': (None, True, False, ),
163 'IEM_MC_FLAT32_PUSH_U16': (None, True, False, ),
164 'IEM_MC_FLAT64_PUSH_U16': (None, True, False, ),
165 'IEM_MC_FLAT32_PUSH_U32': (None, True, False, ),
166 'IEM_MC_FLAT64_PUSH_U64': (None, True, False, ),
167};
168
169class NativeRecompFunctionVariation(object):
170 """
171 Class that deals with transforming a threaded function variation into a
172 native recompiler function.
173
174 This base class doesn't do any transforming and just renders the same
175 code as for the threaded function.
176 """
177
178 def __init__(self, oVariation, sHostArch):
179 self.oVariation = oVariation # type: ThreadedFunctionVariation
180 self.sHostArch = sHostArch;
181
182 def isRecompilable(self):
183 """
184 Predicate that returns whether the variant can be recompiled natively
185 (for the selected host architecture).
186 """
187 return True;
188
189 def renderCode(self, cchIndent):
190 """
191 Returns the native recompiler function body for this threaded variant.
192 """
193 aoStmts = self.oVariation.aoStmtsForThreadedFunction # type: list(McStmt)
194 return iai.McStmt.renderCodeForList(aoStmts, cchIndent);
195
196 @staticmethod
197 def checkStatements(aoStmts, sHostArch):
198 """
199 Checks that all the given statements are supported by the native recompiler.
200 """
201 _ = sHostArch;
202 for oStmt in aoStmts: # type: McStmt
203 if not oStmt.isCppStmt():
204 aInfo = iai.g_dMcStmtParsers.get(oStmt.sName);
205 if not aInfo:
206 aInfo = g_dMcStmtThreaded.get(oStmt.sName);
207 if not aInfo:
208 raise Exception('Unknown statement: %s' % (oStmt.sName, ));
209 if aInfo[2] is False:
210 return False;
211 if aInfo[2] is not True:
212 if isinstance(aInfo[2], str):
213 if aInfo[2] != sHostArch:
214 return False;
215 elif sHostArch not in aInfo[2]:
216 return False;
217 #elif not self.fDecode:
218
219 if isinstance(oStmt, iai.McStmtCond):
220 if not NativeRecompFunctionVariation.checkStatements(oStmt.aoIfBranch, sHostArch):
221 return False;
222 if not NativeRecompFunctionVariation.checkStatements(oStmt.aoElseBranch, sHostArch):
223 return False;
224 return True;
225
226
227
228def analyzeVariantForNativeRecomp(oVariation,
229 sHostArch): # type: (ThreadedFunctionVariation, str) -> NativeRecompFunctionVariation
230 """
231 This function analyzes the threaded function variant and returns an
232 NativeRecompFunctionVariation instance for it, unless it's not
233 possible to recompile at present.
234
235 Returns NativeRecompFunctionVariation or None.
236 """
237
238 #
239 # Analyze the statements.
240 #
241 aoStmts = oVariation.aoStmtsForThreadedFunction # type: list(McStmt)
242 if NativeRecompFunctionVariation.checkStatements(aoStmts, sHostArch):
243 return NativeRecompFunctionVariation(oVariation, sHostArch);
244
245 # The simplest case are the IEM_MC_DEFER_TO_CIMPL_*_RET_THREADED ones, just pass them thru:
246 #if ( len(aoStmts) == 1
247 # and aoStmts[0].sName.startswith('IEM_MC_DEFER_TO_CIMPL_')
248 # and aoStmts[0].sName.endswith('_RET_THREADED')):
249 # return NativeRecompFunctionVariation(oVariation, sHostArch);
250
251
252 # g_dMcStmtParsers
253
254
255 return None;
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette