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
|
; $Id: bootsector2-cpu-hidden-regs-1-template.mac $
;; @file
; bootsector2 hidden CPU registers - multi mode 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.
;
%include "bootsector2-template-header.mac"
;;
; Helper for reporting several register values at in a sequence.
;
BEGINPROC TMPL_NM(TestValueRegSZZ)
push sAX
push sBX
mov xBX, xAX
.next:
mov xAX, xBX
call TMPL_NM_CMN(TestValueReg)
.inner_next:
inc xBX
cmp byte [xBX], 0
jne .inner_next
inc xBX
cmp byte [xBX], 0
je .done
jmp .next
.done
pop sBX
pop sAX
ret
ENDPROC TMPL_NM(TestValueRegSZZ)
;;
; Tests various LDTR values
;
BEGINPROC TMPL_NM(doLdtrTests)
push sAX
; The inital LDT.
mov sAX, .szLdtrInitial
call TMPL_NM(TestValueRegSZZ)
; Load our LDT
mov eax, BS2_SEL_LDT
lldt ax
mov sAX, .szLdtrValid
call TMPL_NM(TestValueRegSZZ)
; NULL LDTR.
xor eax, eax
lldt ax
mov sAX, .szLdtr0
call TMPL_NM(TestValueRegSZZ)
; NULL(1) LDTR.
mov eax, 1
lldt ax
mov sAX, .szLdtr1
call TMPL_NM(TestValueRegSZZ)
; NULL(2) LDTR.
mov eax, 2
lldt ax
mov sAX, .szLdtr2
call TMPL_NM(TestValueRegSZZ)
; NULL(3) LDTR.
mov eax, 3
lldt ax
mov sAX, .szLdtr3
call TMPL_NM(TestValueRegSZZ)
.done
pop sAX
ret
.szLdtrInitial:
db 'LDTR(Initial) sel:ldtr', 0
db 'LDTR(Initial) base:ldtr_base', 0
db 'LDTR(Initial) limit:ldtr_lim', 0
db 'LDTR(Initial) attr:ldtr_attr', 0
db 0
.szLdtrValid:
db 'LDTR(Valid) sel:ldtr', 0
db 'LDTR(Valid) base:ldtr_base', 0
db 'LDTR(Valid) limit:ldtr_lim', 0
db 'LDTR(Valid) attr:ldtr_attr', 0
db 0
.szLdtr0:
db 'LDTR(0) sel:ldtr', 0
db 'LDTR(0) base:ldtr_base', 0
db 'LDTR(0) limit:ldtr_lim', 0
db 'LDTR(0) attr:ldtr_attr', 0
db 0
.szLdtr1:
db 'LDTR(1) sel:ldtr', 0
db 'LDTR(1) base:ldtr_base', 0
db 'LDTR(1) limit:ldtr_lim', 0
db 'LDTR(1) attr:ldtr_attr', 0
db 0
.szLdtr2:
db 'LDTR(2) sel:ldtr', 0
db 'LDTR(2) base:ldtr_base', 0
db 'LDTR(2) limit:ldtr_lim', 0
db 'LDTR(2) attr:ldtr_attr', 0
db 0
.szLdtr3:
db 'LDTR(3) sel:ldtr', 0
db 'LDTR(3) base:ldtr_base', 0
db 'LDTR(3) limit:ldtr_lim', 0
db 'LDTR(3) attr:ldtr_attr', 0
db 0
ENDPROC TMPL_NM(doLdtrTests)
;;
; Tests various LDTR values
;
BEGINPROC TMPL_NM(doTrTests)
push sAX
; Initial TR values.
mov sAX, .szTrInitial
call TMPL_NM(TestValueRegSZZ)
jmp .next1
.szTrInitial:
db 'TR(Initial) sel:tr', 0
db 'TR(Initial) base:tr_base', 0
db 'TR(Initial) limit:tr_lim', 0
db 'TR(Initial) attr:tr_attr', 0
db 0
.next1:
; Our TR.
%ifdef TMPL_CMN_LM
mov ax, BS2_SEL_TSS64
ltr ax
mov sAX, .szTrTss64
call TMPL_NM(TestValueRegSZZ)
jmp .next2
.szTrTss64:
db 'TR(64) sel:tr', 0
db 'TR(64) base:tr_base', 0
db 'TR(64) limit:tr_lim', 0
db 'TR(64) attr:tr_attr', 0
db 0
%elifdef TMPL_PP32
mov ax, BS2_SEL_TSS32
ltr ax
mov sAX, .szTrTss32
call TMPL_NM(TestValueRegSZZ)
jmp .next2
.szTrTss32:
db 'TR(32) sel:tr', 0
db 'TR(32) base:tr_base', 0
db 'TR(32) limit:tr_lim', 0
db 'TR(32) attr:tr_attr', 0
db 0
;%elifdef TMPL_PP16
; mov ax, BS2_SEL_TSS16
; mov sAX, .szTrTss16
; call TMPL_NM(TestValueRegSZZ)
%endif
.next2:
; Note! Loading 0 into TR is not possible, unlike with LDTR.
.done
pop sAX
ret
ENDPROC TMPL_NM(doTrTests)
;;
; Test loading of NULL selectors.
;
BEGINPROC TMPL_NM(doNullSelTests)
push sAX
push xBX
push gs
mov ax, ss
mov gs, ax
mov sAX, .szGsSs
call TMPL_NM(TestValueRegSZZ)
xor eax, eax
mov gs, ax
mov sAX, .szGs0
call TMPL_NM(TestValueRegSZZ)
mov ax, 3
mov gs, ax
mov sAX, .szGs3
call TMPL_NM(TestValueRegSZZ)
%ifdef TMPL_64BIT
pushf
cli
mov bx, ss
mov ax, 0
mov ss, ax
mov sAX, .szSs0
call TMPL_NM(TestValueRegSZZ)
mov ss, bx
popf
call TMPL_NM_CMN(Bs2ToRing2)
mov bx, ss
mov ax, 2
mov ss, ax
mov sAX, .szSs1Ring2
call TMPL_NM(TestValueRegSZZ)
mov ss, bx
test byte [g_fCpuAmd], 1
jz .not_amd
mov ax, 3
mov ss, ax
mov sAX, .szSs3Ring2
call TMPL_NM(TestValueRegSZZ)
.not_amd:
call TMPL_NM_CMN(Bs2ToRing0)
%endif
pop gs
pop xBX
pop sAX
ret
.szGsSs:
db 'GS(ss) sel:gs', 0
db 'GS(ss) base:gs_base', 0
db 'GS(ss) limit:gs_lim', 0
db 'GS(ss) attr:gs_attr', 0
db 0
.szGs0:
db 'GS(0) sel:gs', 0
db 'GS(0) base:gs_base', 0
db 'GS(0) limit:gs_lim', 0
db 'GS(0) attr:gs_attr', 0
db 0
.szGs3:
db 'GS(3) sel:gs', 0
db 'GS(3) base:gs_base', 0
db 'GS(3) limit:gs_lim', 0
db 'GS(3) attr:gs_attr', 0
db 0
%ifdef TMPL_64BIT
.szSs0:
db 'SS(0) sel:ss', 0
db 'SS(0) base:ss_base', 0
db 'SS(0) limit:ss_lim', 0
db 'SS(0) attr:ss_attr', 0
db 0
.szSs1Ring2
db 'ring-2 SS(2) sel:ss', 0
db 'ring-2 SS(2) base:ss_base', 0
db 'ring-2 SS(2) limit:ss_lim', 0
db 'ring-2 SS(2) attr:ss_attr', 0
db 0
.szSs3Ring2
db 'ring-2 SS(3) sel:ss', 0
db 'ring-2 SS(3) base:ss_base', 0
db 'ring-2 SS(3) limit:ss_lim', 0
db 'ring-2 SS(3) attr:ss_attr', 0
db 0
%endif
ENDPROC TMPL_NM(doNullSelTests)
BEGINPROC TMPL_NM(doTestsWorker)
push sAX
mov xAX, .s_szSubTest
call TMPL_NM_CMN(TestSub)
call TMPL_NM(doLdtrTests)
call TMPL_NM(doTrTests)
call TMPL_NM(doNullSelTests)
.done
pop sAX
ret
.s_szSubTest:
db TMPL_MODE_STR, 0
ENDPROC TMPL_NM(doTestsWorker)
;;
; Do the tests for this mode.
;
; @uses nothing
;
BEGINCODELOW
BITS 16
BEGINPROC TMPL_NM(doTests_rm)
call TMPL_NM(Bs2IsModeSupported_rm)
jz .done
call TMPL_NM(Bs2EnterMode_rm)
BITS TMPL_BITS
call TMPL_NM(doTestsWorker)
call TMPL_NM(Bs2ExitMode)
BITS 16
.done:
ret
ENDPROC TMPL_NM(doTests_rm)
TMPL_BEGINCODE
BITS TMPL_BITS
%include "bootsector2-template-footer.mac"
|