VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-generated-1.h@ 65926

Last change on this file since 65926 was 65926, checked in by vboxsync, 8 years ago

IEM: Started on generating tests from instruction specs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1/* $Id: bs3-cpu-generated-1.h 65926 2017-03-03 11:00:27Z vboxsync $ */
2/** @file
3 * BS3Kit - bs3-cpu-generated-1, common header file.
4 */
5
6/*
7 * Copyright (C) 2007-2016 Oracle Corporation
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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28#ifndef ___bs3_cpu_generated_1_h___
29#define ___bs3_cpu_generated_1_h___
30
31#include <bs3kit.h>
32#include <iprt/assert.h>
33
34
35/**
36 * Operand details.
37 *
38 * Currently simply using the encoding from the reference manuals.
39 */
40typedef enum BS3CG1OP
41{
42 BS3CG1OP_INVALID = 0,
43
44 BS3CG1OP_Eb,
45 BS3CG1OP_Ev,
46
47 BS3CG1OP_Gb,
48 BS3CG1OP_Gv,
49
50 BS3CG1OP_END
51} BS3CG1OP;
52/** Pointer to a const operand enum. */
53typedef const BS3_FAR *PCBS3CG1OP;
54
55
56/**
57 * Instruction encoding format.
58 *
59 * This duplicates some of the info in the operand array, however it makes it
60 * easier to figure out encoding variations.
61 */
62typedef enum BS3CG1ENC
63{
64 BS3CG1ENC_INVALID = 0,
65
66 BS3CG1ENC_FIXED_Iz,
67 BS3CG1ENC_FIXED_FIRST = BS3CG1ENC_FIXED_Iz,
68 BS3CG1ENC_FIXED_Iv,
69
70 BS3CG1ENC_MODRM_Eb_Gb,
71 BS3CG1ENC_MODRM_Ev_Gv,
72
73 BS3CG1ENC_END
74} BS3CG1ENC;
75
76
77/**
78 * Generated instruction info.
79 */
80typedef struct BS3CG1INSTR
81{
82 /** The opcode size. */
83 uint32_t cbOpcode : 2;
84 /** The number of operands. */
85 uint32_t cOperands : 2;
86 /** The length of the mnemonic. */
87 uint32_t cchMnemonic : 3;
88 /** Whether to advance the mnemonic array pointer. */
89 uint32_t fAdvanceMnemonic : 1;
90 /** Offset into g_abBs3Cg1Tests of the first test. */
91 uint32_t offTests : 23;
92 /** BS3CG1ENC values. */
93 uint32_t enmEncoding : 10;
94 /** BS3CG1ENC values. */
95 uint32_t uUnused : 22;
96 /** BS3CG1INSTR_F_XXX. */
97 uint32_t fFlags;
98} BS3CG1INSTR;
99AssertCompileSize(BS3CG1INSTR, 12);
100/** Pointer to a const instruction. */
101typedef BS3CG1INSTR const BS3_FAR *PCBS3CG1INSTR;
102
103
104/** @name BS3CG1INSTR_F_XXX
105 * @{ */
106#define BS3CG1INSTR_F_ UINT32_C(0x00000000)
107/** @} */
108
109
110/**
111 * Test header.
112 */
113typedef struct BS3CG1TESTHDR
114{
115 /** The size of the selector program in bytes.
116 * This is also the offset of the input context modification program. */
117 uint32_t cbSelector : 8;
118 /** The size of the input context modification program in bytes.
119 * This immediately follows the selector program. */
120 uint32_t cbInput : 12;
121 /** The size of the output context modification program in bytes.
122 * This immediately follows the input context modification program. The
123 * program takes the result of the input program as starting point. */
124 uint32_t cbOutput : 11;
125 /** Indicates whether this is the last test or not. */
126 uint32_t fLast : 1;
127} BS3CG1TESTHDR;
128AssertCompileSize(BS3CG1TESTHDR, 4);
129/** Pointer to a const test header. */
130typedef BS3CG1TESTHDR const BS3_FAR *PCBS3CG1TESTHDR;
131
132/** @name Opcode format for the BS3CG1 context modifier.
133 *
134 * Used by both the input and output context programs.
135 *
136 * The most common operations are encoded as a single byte opcode followed by
137 * one or more immediate bytes with data.
138 *
139 * @{ */
140#define BS3CG1_CTXOP_SIZE_MASK UINT8_C(0x07)
141#define BS3CG1_CTXOP_1_BYTE UINT8_C(0x00)
142#define BS3CG1_CTXOP_2_BYTES UINT8_C(0x01)
143#define BS3CG1_CTXOP_4_BYTES UINT8_C(0x02)
144#define BS3CG1_CTXOP_8_BYTES UINT8_C(0x03)
145#define BS3CG1_CTXOP_16_BYTES UINT8_C(0x04)
146#define BS3CG1_CTXOP_32_BYTES UINT8_C(0x05)
147#define BS3CG1_CTXOP_12_BYTES UINT8_C(0x06)
148#define BS3CG1_CTXOP_SIZE_ESC UINT8_C(0x07) /**< Separate byte encoding the value size follows immediately. */
149
150#define BS3CG1_CTXOP_DST_MASK UINT8_C(0x18)
151#define BS3CG1_CTXOP_OP1 UINT8_C(0x00)
152#define BS3CG1_CTXOP_OP2 UINT8_C(0x08)
153#define BS3CG1_CTXOP_EFL UINT8_C(0x10)
154#define BS3CG1_CTXOP_DST_ESC UINT8_C(0x18) /**< Separate byte giving the destination follows after any size byte.*/
155
156#define BS3CG1_CTXOP_SIGN_EXT UINT8_C(0x20) /**< Whether to sign-extend (set) the immediate value. */
157
158#define BS3CG1_CTXOP_OPERATOR_MASK UINT8_C(0xc0)
159#define BS3CG1_CTXOP_ASSIGN UINT8_C(0x00) /**< Simple assignment operator (=) */
160#define BS3CG1_CTXOP_OR UINT8_C(0x40) /**< OR assignment operator (|=). */
161#define BS3CG1_CTXOP_AND UINT8_C(0x80) /**< AND assignment operator (&=). */
162#define BS3CG1_CTXOP_AND_INV UINT8_C(0xc0) /**< AND assignment operator of the inverted value (&~=). */
163/** @} */
164
165/**
166 * Escaped destination values
167 *
168 * These are just uppercased versions of TestInOut.kdFields, where dots are
169 * replaced by underscores.
170 */
171enum BS3CG1DST
172{
173 BS3CG1DST_INVALID = 0,
174 /* Operands. */
175 BS3CG1DST_OP1,
176 BS3CG1DST_OP2,
177 BS3CG1DST_OP3,
178 BS3CG1DST_OP4,
179 /* Flags. */
180 BS3CG1DST_EFL,
181 /* 8-bit GPRs. */
182 BS3CG1DST_AL,
183 BS3CG1DST_CL,
184 BS3CG1DST_DL,
185 BS3CG1DST_BL,
186 BS3CG1DST_AH,
187 BS3CG1DST_CH,
188 BS3CG1DST_DH,
189 BS3CG1DST_BH,
190 BS3CG1DST_R8L,
191 BS3CG1DST_R9L,
192 BS3CG1DST_R10L,
193 BS3CG1DST_R11L,
194 BS3CG1DST_R12L,
195 BS3CG1DST_R13L,
196 BS3CG1DST_R14L,
197 BS3CG1DST_R15L,
198 /* 16-bit GPRs. */
199 BS3CG1DST_AX,
200 BS3CG1DST_DX,
201 BS3CG1DST_CX,
202 BS3CG1DST_BX,
203 BS3CG1DST_SP,
204 BS3CG1DST_BP,
205 BS3CG1DST_SI,
206 BS3CG1DST_DI,
207 BS3CG1DST_R8W,
208 BS3CG1DST_R9W,
209 BS3CG1DST_R10W,
210 BS3CG1DST_R11W,
211 BS3CG1DST_R12W,
212 BS3CG1DST_R13W,
213 BS3CG1DST_R14W,
214 BS3CG1DST_R15W,
215 /* 32-bit GPRs. */
216 BS3CG1DST_EAX,
217 BS3CG1DST_EDX,
218 BS3CG1DST_ECX,
219 BS3CG1DST_EBX,
220 BS3CG1DST_ESP,
221 BS3CG1DST_EBP,
222 BS3CG1DST_ESI,
223 BS3CG1DST_EDI,
224 BS3CG1DST_R8D,
225 BS3CG1DST_R9D,
226 BS3CG1DST_R10D,
227 BS3CG1DST_R11D,
228 BS3CG1DST_R12D,
229 BS3CG1DST_R13D,
230 BS3CG1DST_R14D,
231 BS3CG1DST_R15D,
232 /* 64-bit GPRs. */
233 BS3CG1DST_RAX,
234 BS3CG1DST_RDX,
235 BS3CG1DST_RCX,
236 BS3CG1DST_RBX,
237 BS3CG1DST_RSP,
238 BS3CG1DST_RBP,
239 BS3CG1DST_RSI,
240 BS3CG1DST_RDI,
241 BS3CG1DST_R8,
242 BS3CG1DST_R9,
243 BS3CG1DST_R10,
244 BS3CG1DST_R11,
245 BS3CG1DST_R12,
246 BS3CG1DST_R13,
247 BS3CG1DST_R14,
248 BS3CG1DST_R15,
249 /* 16-bit, 32-bit or 64-bit registers according to operand size. */
250 BS3CG1DST_OZ_RAX,
251 BS3CG1DST_OZ_RDX,
252 BS3CG1DST_OZ_RCX,
253 BS3CG1DST_OZ_RBX,
254 BS3CG1DST_OZ_RSP,
255 BS3CG1DST_OZ_RBP,
256 BS3CG1DST_OZ_RSI,
257 BS3CG1DST_OZ_RDI,
258 BS3CG1DST_OZ_R8,
259 BS3CG1DST_OZ_R9,
260 BS3CG1DST_OZ_R10,
261 BS3CG1DST_OZ_R11,
262 BS3CG1DST_OZ_R12,
263 BS3CG1DST_OZ_R13,
264 BS3CG1DST_OZ_R14,
265 BS3CG1DST_OZ_R15,
266
267 BS3CG1DST_END
268} BS3CG1DST;
269
270/** @name Selector opcode definitions.
271 *
272 * Selector programs are very simple, they are zero or more predicate tests
273 * that are ANDed together. If a predicate test fails, the test is skipped.
274 *
275 * One instruction is encoded as byte, where the first bit indicates what kind
276 * of test and the 7 remaining bits indicates which predicate to check.
277 *
278 * @{ */
279#define BS3CG1SEL_OP_KIND_MASK UINT8_C(0x01) /**< The operator part (put in lower bit to reduce switch value range). */
280#define BS3CG1SEL_OP_IS_TRUE UINT8_C(0x00) /**< Check that the predicate is true. */
281#define BS3CG1SEL_OP_IS_FALSE UINT8_C(0x01) /**< Check that the predicate is false. */
282#define BS3CG1SEL_OP_PRED_SHIFT 1 /**< Shift factor for getting/putting a BS3CG1PRED value into/from a byte. */
283/** @} */
284
285/**
286 * Test selector predicates (values are shifted by BS3CG1SEL_OP_PRED_SHIFT).
287 */
288typedef enum BS3CG1PRED
289{
290 BS3CG1PRED_INVALID = 0,
291
292 /* Operand size. */
293 BS3CG1PRED_SIZE_O16,
294 BS3CG1PRED_SIZE_O32,
295 BS3CG1PRED_SIZE_O64,
296 /* Execution ring. */
297 BS3CG1PRED_RING_0,
298 BS3CG1PRED_RING_1,
299 BS3CG1PRED_RING_2,
300 BS3CG1PRED_RING_3,
301 BS3CG1PRED_RING_0_THRU_2,
302 BS3CG1PRED_RING_1_THRU_3,
303 /* Basic code mode. */
304 BS3CG1PRED_CODE_64BIT,
305 BS3CG1PRED_CODE_32BIT,
306 BS3CG1PRED_CODE_16BIT,
307 /* CPU modes. */
308 BS3CG1PRED_MODE_REAL,
309 BS3CG1PRED_MODE_PROT,
310 BS3CG1PRED_MODE_LONG,
311 BS3CG1PRED_MODE_V86,
312 BS3CG1PRED_MODE_SMM,
313 BS3CG1PRED_MODE_VMX,
314 BS3CG1PRED_MODE_SVM,
315 /* Paging on/off */
316 BS3CG1PRED_PAGING_ON,
317 BS3CG1PRED_PAGING_OFF,
318
319 BS3CG1PRED_END
320} BS3CG1PRED;
321
322
323/** The test instructions (generated). */
324extern const BS3CG1INSTR BS3_FAR_DATA g_aBs3Cg1Instructions[];
325/** The number of test instructions (generated). */
326extern const uint16_t BS3_FAR_DATA g_cBs3Cg1Instructions;
327/** The mnemonics (generated).
328 * Variable length sequence of mnemonics that runs in parallel to
329 * g_aBs3Cg1Instructions. */
330extern const char BS3_FAR_DATA g_achBs3Cg1Mnemonics[];
331/** The opcodes (generated).
332 * Variable length sequence of opcode bytes that runs in parallel to
333 * g_aBs3Cg1Instructions, advancing by BS3CG1INSTR::cbOpcode each time. */
334extern const uint8_t BS3_FAR_DATA g_abBs3Cg1Opcodes[];
335/** The operands (generated).
336 * Variable length sequence of opcode values (BS3CG1OP) that runs in
337 * parallel to g_aBs3Cg1Instructions, advancing by BS3CG1INSTR::cOperands. */
338extern const uint8_t BS3_FAR_DATA g_abBs3Cg1Operands[];
339/** The test data that BS3CG1INSTR.
340 * In order to simplify generating these, we use a byte array. */
341extern const uint8_t BS3_FAR_DATA g_abBs3Cg1Tests[];
342
343
344#endif
345
Note: See TracBrowser for help on using the repository browser.

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