1 | /* $Id: IEMOpHlp.h 108261 2025-02-17 15:51:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IEM - Interpreted Execution Manager - Opcode Helpers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.alldomusa.eu.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VMM_INCLUDED_SRC_include_IEMOpHlp_h
|
---|
29 | #define VMM_INCLUDED_SRC_include_IEMOpHlp_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /** @name Common opcode decoders.
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Complains about a stub.
|
---|
40 | *
|
---|
41 | * Providing two versions of this macro, one for daily use and one for use when
|
---|
42 | * working on IEM.
|
---|
43 | */
|
---|
44 | #define IEMOP_BITCH_ABOUT_STUB() Log(("Stub: %s (line %d)\n", __FUNCTION__, __LINE__));
|
---|
45 |
|
---|
46 | /** Stubs an opcode. */
|
---|
47 | #define FNIEMOP_STUB(a_Name) \
|
---|
48 | FNIEMOP_DEF(a_Name) \
|
---|
49 | { \
|
---|
50 | RT_NOREF_PV(pVCpu); \
|
---|
51 | IEMOP_BITCH_ABOUT_STUB(); \
|
---|
52 | return VERR_IEM_INSTR_NOT_IMPLEMENTED; \
|
---|
53 | } \
|
---|
54 | typedef int ignore_semicolon
|
---|
55 |
|
---|
56 | /** Stubs an opcode. */
|
---|
57 | #define FNIEMOP_STUB_1(a_Name, a_Type0, a_Name0) \
|
---|
58 | FNIEMOP_DEF_1(a_Name, a_Type0, a_Name0) \
|
---|
59 | { \
|
---|
60 | RT_NOREF_PV(pVCpu); \
|
---|
61 | RT_NOREF_PV(a_Name0); \
|
---|
62 | IEMOP_BITCH_ABOUT_STUB(); \
|
---|
63 | return VERR_IEM_INSTR_NOT_IMPLEMENTED; \
|
---|
64 | } \
|
---|
65 | typedef int ignore_semicolon
|
---|
66 |
|
---|
67 | /** Stubs an opcode which currently should raise \#UD. */
|
---|
68 | #define FNIEMOP_UD_STUB(a_Name) \
|
---|
69 | FNIEMOP_DEF(a_Name) \
|
---|
70 | { \
|
---|
71 | Log(("Unsupported instruction %Rfn\n", __FUNCTION__)); \
|
---|
72 | IEMOP_RAISE_INVALID_OPCODE_RET(); \
|
---|
73 | } \
|
---|
74 | typedef int ignore_semicolon
|
---|
75 |
|
---|
76 | /** Stubs an opcode which currently should raise \#UD. */
|
---|
77 | #define FNIEMOP_UD_STUB_1(a_Name, a_Type0, a_Name0) \
|
---|
78 | FNIEMOP_DEF_1(a_Name, a_Type0, a_Name0) \
|
---|
79 | { \
|
---|
80 | RT_NOREF_PV(pVCpu); \
|
---|
81 | RT_NOREF_PV(a_Name0); \
|
---|
82 | Log(("Unsupported instruction %Rfn\n", __FUNCTION__)); \
|
---|
83 | IEMOP_RAISE_INVALID_OPCODE_RET(); \
|
---|
84 | } \
|
---|
85 | typedef int ignore_semicolon
|
---|
86 |
|
---|
87 | /** @} */
|
---|
88 |
|
---|
89 |
|
---|
90 | /** @name Opcode Debug Helpers.
|
---|
91 | * @{
|
---|
92 | */
|
---|
93 | #ifdef VBOX_WITH_STATISTICS
|
---|
94 | # ifdef IN_RING3
|
---|
95 | # define IEMOP_INC_STATS(a_Stats) do { pVCpu->iem.s.StatsR3.a_Stats += 1; } while (0)
|
---|
96 | # else
|
---|
97 | # define IEMOP_INC_STATS(a_Stats) do { pVCpu->iem.s.StatsRZ.a_Stats += 1; } while (0)
|
---|
98 | # endif
|
---|
99 | #else
|
---|
100 | # define IEMOP_INC_STATS(a_Stats) do { } while (0)
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /** @} */
|
---|
104 |
|
---|
105 |
|
---|
106 | /** @name Opcode Helpers.
|
---|
107 | * @{
|
---|
108 | */
|
---|
109 |
|
---|
110 | #ifdef IN_RING3
|
---|
111 | # define IEMOP_HLP_MIN_CPU(a_uMinCpu, a_fOnlyIf) \
|
---|
112 | do { \
|
---|
113 | if (IEM_GET_TARGET_CPU(pVCpu) >= (a_uMinCpu) || !(a_fOnlyIf)) { } \
|
---|
114 | else \
|
---|
115 | { \
|
---|
116 | (void)DBGFSTOP(pVCpu->CTX_SUFF(pVM)); \
|
---|
117 | IEMOP_RAISE_INVALID_OPCODE_RET(); \
|
---|
118 | } \
|
---|
119 | } while (0)
|
---|
120 | #else
|
---|
121 | # define IEMOP_HLP_MIN_CPU(a_uMinCpu, a_fOnlyIf) \
|
---|
122 | do { \
|
---|
123 | if (IEM_GET_TARGET_CPU(pVCpu) >= (a_uMinCpu) || !(a_fOnlyIf)) { } \
|
---|
124 | else IEMOP_RAISE_INVALID_OPCODE_RET(); \
|
---|
125 | } while (0)
|
---|
126 | #endif
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Check for a CPUMFEATURES member to be true, raise \#UD if clear.
|
---|
131 | */
|
---|
132 | #define IEMOP_HLP_RAISE_UD_IF_MISSING_GUEST_FEATURE(pVCpu, a_fFeature) \
|
---|
133 | do \
|
---|
134 | { \
|
---|
135 | if (IEM_GET_GUEST_CPU_FEATURES(pVCpu)->a_fFeature) \
|
---|
136 | { /* likely */ } \
|
---|
137 | else \
|
---|
138 | IEMOP_RAISE_INVALID_OPCODE_RET(); \
|
---|
139 | } while (0)
|
---|
140 |
|
---|
141 | /** @} */
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * Include the target specific header.
|
---|
145 | */
|
---|
146 | #ifdef VBOX_VMM_TARGET_X86
|
---|
147 | # include "VMMAll/target-x86/IEMOpHlp-x86.h"
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | #endif /* !VMM_INCLUDED_SRC_include_IEMOpHlp_h */
|
---|