1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
; $Id: bs3-cpu-basic-2-template.mac $
;; @file
; BS3Kit - bs3-cpu-basic-2 assembly template.
;
;
; Copyright (C) 2007-2019 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) as published by the Free Software
; Foundation, in version 2 as it comes in the "COPYING" file of the
; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
; VirtualBox OSE distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
;*********************************************************************************************************************************
;* Header Files *
;*********************************************************************************************************************************
%include "bs3kit-template-header.mac" ; setup environment
;*********************************************************************************************************************************
;* External Symbols *
;*********************************************************************************************************************************
TMPL_BEGIN_TEXT
;
; Test code snippets containing code which differs between 16-bit, 32-bit
; and 64-bit CPUs modes.
;
%ifdef BS3_INSTANTIATING_CMN
;
; SIDT
;
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_bx_ud2, BS3_PBC_NEAR
sidt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_bx_ud2) == 3)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
sidt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_opsize_bx_ud2
%if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_rexw_bx_ud2, BS3_PBC_NEAR
db X86_OP_REX_W
sidt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_rexw_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_rexw_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_rexw_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
db X86_OP_REX_W
sidt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_rexw_bx_ud2) == 5)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_opsize_rexw_bx_ud2
%endif
%if TMPL_BITS != 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_ss_bx_ud2, BS3_PBC_NEAR
sidt [ss:xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_ss_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_ss_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_ss_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
sidt [ss:xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_ss_bx_ud2) == 5)
BS3_PROC_END_CMN bs3CpuBasic2_sidt_opsize_ss_bx_ud2
%endif
;
; SGDT
;
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_bx_ud2, BS3_PBC_NEAR
sgdt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_bx_ud2) == 3)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_opsize_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
sgdt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_opsize_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_opsize_bx_ud2
%if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_rexw_bx_ud2, BS3_PBC_NEAR
db X86_OP_REX_W
sgdt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_rexw_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_rexw_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_opsize_rexw_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
db X86_OP_REX_W
sgdt [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_opsize_rexw_bx_ud2) == 5)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_opsize_rexw_bx_ud2
%endif
%if TMPL_BITS != 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_ss_bx_ud2, BS3_PBC_NEAR
sgdt [ss:xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_ss_bx_ud2) == 4)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_ss_bx_ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_opsize_ss_bx_ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
sgdt [ss:xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_opsize_ss_bx_ud2) == 5)
BS3_PROC_END_CMN bs3CpuBasic2_sgdt_opsize_ss_bx_ud2
%endif
;
; LIDT
;
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
lidt [xBX]
sidt [BS3_NOT_64BIT(es:) xDI]
lidt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(9,11))
BS3_PROC_END_CMN bs3CpuBasic2_lidt_bx__sidt_es_di__lidt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
lidt [xBX]
sidt [BS3_NOT_64BIT(es:) xDI]
lidt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(10,12))
BS3_PROC_END_CMN bs3CpuBasic2_lidt_opsize_bx__sidt_es_di__lidt_es_si__ud2
%if TMPL_BITS == 16
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
lidt [xBX]
jmp dword BS3_SEL_R0_CS32:.in_32bit wrt FLAT
BS3_SET_BITS 32
.in_32bit:
sidt [es:edi]
lidt [es:esi]
jmp dword BS3_SEL_R0_CS16:.again wrt CGROUP16
BS3_SET_BITS 16
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2) == 27)
BS3_PROC_END_CMN bs3CpuBasic2_lidt_opsize_bx__sidt32_es_di__lidt_es_si__ud2
%endif
%if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_REX_W
lidt [xBX]
sidt [xDI]
lidt [xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2) == 10)
BS3_PROC_END_CMN bs3CpuBasic2_lidt_rexw_bx__sidt_es_di__lidt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
db X86_OP_REX_W
lidt [xBX]
sidt [xDI]
lidt [xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2) == 11)
BS3_PROC_END_CMN bs3CpuBasic2_lidt_opsize_rexw_bx__sidt_es_di__lidt_es_si__ud2
%endif
%if TMPL_BITS != 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
lidt [ss:xBX]
sidt [BS3_NOT_64BIT(es:) xDI]
lidt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2) == 12)
BS3_PROC_END_CMN bs3CpuBasic2_lidt_ss_bx__sidt_es_di__lidt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
lidt [ss:xBX]
sidt [BS3_NOT_64BIT(es:) xDI]
lidt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2) == 13)
BS3_PROC_END_CMN bs3CpuBasic2_lidt_opsize_ss_bx__sidt_es_di__lidt_es_si__ud2
%endif
;
; LGDT
;
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
lgdt [xBX]
sgdt [BS3_NOT_64BIT(es:) xDI]
lgdt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(9,11))
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_bx__sgdt_es_di__lgdt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
lgdt [xBX]
sgdt [BS3_NOT_64BIT(es:) xDI]
lgdt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2) == BS3_IF_64BIT_OTHERWISE(10,12))
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_opsize_bx__sgdt_es_di__lgdt_es_si__ud2
%if TMPL_BITS == 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_REX_W
lgdt [xBX]
sgdt [xDI]
lgdt [xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2) == 10)
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_rexw_bx__sgdt_es_di__lgdt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
db X86_OP_REX_W
lgdt [xBX]
sgdt [xDI]
lgdt [xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2) == 11)
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_opsize_rexw_bx__sgdt_es_di__lgdt_es_si__ud2
%endif
%if TMPL_BITS != 64
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
lgdt [ss:xBX]
sgdt [BS3_NOT_64BIT(es:) xDI]
lgdt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2) == 12)
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_ss_bx__sgdt_es_di__lgdt_es_si__ud2
BS3_PROC_BEGIN_CMN bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2, BS3_PBC_NEAR
db X86_OP_PRF_SIZE_OP
lgdt [ss:xBX]
sgdt [BS3_NOT_64BIT(es:) xDI]
lgdt [BS3_NOT_64BIT(es:) xSI]
.again:
ud2
jmp .again
AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2) == 13)
BS3_PROC_END_CMN bs3CpuBasic2_lgdt_opsize_ss_bx__sgdt_es_di__lgdt_es_si__ud2
%endif
;
; #PF
;
; For testing read access.
BS3_PROC_BEGIN_CMN bs3CpuBasic2_mov_ax_ds_bx__ud2, BS3_PBC_NEAR
mov xAX, [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
BS3_PROC_END_CMN bs3CpuBasic2_mov_ax_ds_bx__ud2
; For testing write access.
BS3_PROC_BEGIN_CMN bs3CpuBasic2_mov_ds_bx_ax__ud2, BS3_PBC_NEAR
mov [xBX], xAX
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
BS3_PROC_END_CMN bs3CpuBasic2_mov_ds_bx_ax__ud2
; For testing read+write access.
BS3_PROC_BEGIN_CMN bs3CpuBasic2_xchg_ds_bx_ax__ud2, BS3_PBC_NEAR
xchg [xBX], xAX
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
BS3_PROC_END_CMN bs3CpuBasic2_xchg_ds_bx_ax__ud2
; Another read+write access test.
BS3_PROC_BEGIN_CMN bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2, BS3_PBC_NEAR
cmpxchg [xBX], xCX
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 3 + (TMPL_BITS == 64))
BS3_PROC_END_CMN bs3CpuBasic2_cmpxchg_ds_bx_cx__ud2
; For testing read access from an aborted instruction: DIV by zero
BS3_PROC_BEGIN_CMN bs3CpuBasic2_div_ds_bx__ud2, BS3_PBC_NEAR
div xPRE [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2 + (TMPL_BITS == 64))
BS3_PROC_END_CMN bs3CpuBasic2_div_ds_bx__ud2
; Two memory operands: push [mem]
BS3_PROC_BEGIN_CMN bs3CpuBasic2_push_ds_bx__ud2, BS3_PBC_NEAR
push xPRE [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2)
BS3_PROC_END_CMN bs3CpuBasic2_push_ds_bx__ud2
; Two memory operands: pop [mem]
BS3_PROC_BEGIN_CMN bs3CpuBasic2_push_ax__pop_ds_bx__ud2, BS3_PBC_NEAR
push xAX
pop xPRE [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 3)
BS3_PROC_END_CMN bs3CpuBasic2_push_ax__pop_ds_bx__ud2
; Two memory operands: call [mem]
BS3_PROC_BEGIN_CMN bs3CpuBasic2_call_ds_bx__ud2, BS3_PBC_NEAR
call xPRE [xBX]
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 2)
BS3_PROC_END_CMN bs3CpuBasic2_call_ds_bx__ud2
; For testing #GP vs #PF write
BS3_PROC_BEGIN_CMN bs3CpuBasic2_insb__ud2, BS3_PBC_NEAR
insb
.again: ud2
jmp .again
AssertCompile(.again - BS3_LAST_LABEL == 1)
BS3_PROC_END_CMN bs3CpuBasic2_insb__ud2
%endif ; BS3_INSTANTIATING_CMN
%include "bs3kit-template-footer.mac" ; reset environment
|