VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstX86-1A.asm@ 36768

Last change on this file since 36768 was 36768, checked in by vboxsync, 14 years ago

IEM: Initial commit, work in progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1; $Id: tstX86-1A.asm 36768 2011-04-20 18:33:29Z vboxsync $
2;; @file
3; X86 instruction set testcase #1.
4;
5
6;
7; Copyright (C) 2011 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
18
19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20; Header Files ;
21;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22%include "iprt/asmdefs.mac"
23%include "VBox/x86.mac"
24
25;; @todo Move this to a header?
26struc TRAPINFO
27 .uTrapPC RTCCPTR_RES 1
28 .uResumePC RTCCPTR_RES 1
29 .u8TrapNo resb 1
30 .cbInstr resb 1
31 .au8Padding resb (RTCCPTR_CB*2 - 2)
32endstruc
33
34
35;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36; Global Variables ;
37;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38BEGINDATA
39extern NAME(g_pbEfPage)
40
41g_szAlpha:
42 db "abcdefghijklmnopqrstuvwxyz", 0
43g_szAlpha_end:
44%define g_cchAlpha (g_szAlpha_end - g_szAlpha)
45 db 0, 0, 0,
46
47;;
48; The last global data item. We build this as we write the code.
49GLOBALNAME g_aTrapInfo
50
51
52;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53; Defined Constants And Macros ;
54;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55%define X86_XCPT_GP 13
56%define X86_XCPT_PF 14
57
58;;
59; Macro for recording a trapping instruction (simple).
60;
61; @param 1 The trap number.
62; @param 2+ The instruction which should trap.
63%macro ShouldTrap 2+
64..trap:
65 %2
66..trap_end:
67 mov eax, __LINE__
68 jmp .failed
69BEGINDATA
70..trapinfo: istruc TRAPINFO
71 at TRAPINFO.uTrapPC, RTCCPTR_DEF ..trap
72 at TRAPINFO.uResumePC, RTCCPTR_DEF ..resume
73 at TRAPINFO.u8TrapNo, db %1
74 at TRAPINFO.cbInstr, db (..trap_end - ..trap)
75iend
76BEGINCODE
77..resume:
78%endmacro
79
80
81
82BEGINCODE
83
84;;
85; Loads all general registers except xBP and xSP with unique values.
86;
87x861_LoadUniqueRegValues:
88%ifdef RT_ARCH_AMD64
89 mov rax, 00000000000000000h
90 mov rcx, 01111111111111111h
91 mov rdx, 02222222222222222h
92 mov rbx, 03333333333333333h
93 mov rsi, 06666666666666666h
94 mov rdi, 07777777777777777h
95 mov r8, 08888888888888888h
96 mov r9, 09999999999999999h
97 mov r10, 0aaaaaaaaaaaaaaaah
98 mov r11, 0bbbbbbbbbbbbbbbbh
99 mov r12, 0cccccccccccccccch
100 mov r13, 0ddddddddddddddddh
101 mov r14, 0eeeeeeeeeeeeeeeeh
102 mov r15, 0ffffffffffffffffh
103%else
104 mov eax, 000000000h
105 mov ecx, 011111111h
106 mov edx, 022222222h
107 mov ebx, 033333333h
108 mov esi, 066666666h
109 mov edi, 077777777h
110%endif
111 ret
112; end x861_LoadUniqueRegValues
113
114
115;;
116; Clears all general registers except xBP and xSP.
117;
118x861_ClearRegisters:
119 xor eax, eax
120 xor ebx, ebx
121 xor ecx, ecx
122 xor edx, edx
123 xor esi, esi
124 xor edi, edi
125%ifdef RT_ARCH_AMD64
126 xor r8, r8
127 xor r9, r9
128 xor r10, r10
129 xor r11, r11
130 xor r12, r12
131 xor r13, r13
132 xor r14, r14
133 xor r15, r15
134%endif
135 ret
136; x861_ClearRegisters
137
138
139BEGINPROC x861_Test1
140 push xBP
141 mov xBP, xSP
142 pushf
143 push xBX
144 push xCX
145 push xDX
146 push xSI
147 push xDI
148%ifdef RT_ARCH_AMD64
149 push r8
150 push r9
151 push r10
152 push r11
153 push r12
154 push r13
155 push r14
156 push r15
157%endif
158
159 ;
160 ; Odd push behavior
161 ;
162%ifdef RT_ARCH_X86
163 ; upper word of a 'push cs' is cleared.
164 mov eax, __LINE__
165 mov dword [esp - 4], 0f0f0f0fh
166 push cs
167 pop ecx
168 mov bx, cs
169 and ebx, 0000ffffh
170 cmp ecx, ebx
171 jne .failed
172
173 ; upper word of a 'push ds' is cleared.
174 mov eax, __LINE__
175 mov dword [esp - 4], 0f0f0f0fh
176 push ds
177 pop ecx
178 mov bx, ds
179 and ebx, 0000ffffh
180 cmp ecx, ebx
181 jne .failed
182
183 ; upper word of a 'push es' is cleared.
184 mov eax, __LINE__
185 mov dword [esp - 4], 0f0f0f0fh
186 push es
187 pop ecx
188 mov bx, es
189 and ebx, 0000ffffh
190 cmp ecx, ebx
191 jne .failed
192%endif ; RT_ARCH_X86
193
194 ; The upper part of a 'push fs' is cleared.
195 mov eax, __LINE__
196 xor ecx, ecx
197 not xCX
198 push xCX
199 pop xCX
200 push fs
201 pop xCX
202 mov bx, fs
203 and ebx, 0000ffffh
204 cmp xCX, xBX
205 jne .failed
206
207 ; The upper part of a 'push gs' is cleared.
208 mov eax, __LINE__
209 xor ecx, ecx
210 not xCX
211 push xCX
212 pop xCX
213 push gs
214 pop xCX
215 mov bx, gs
216 and ebx, 0000ffffh
217 cmp xCX, xBX
218 jne .failed
219
220%ifdef RT_ARCH_AMD64
221 ; REX.B works with 'push r64'.
222 call x861_LoadUniqueRegValues
223 mov eax, __LINE__
224 push rcx
225 pop rdx
226 cmp rdx, rcx
227 jne .failed
228
229 call x861_LoadUniqueRegValues
230 mov eax, __LINE__
231 db 041h ; REX.B
232 push rcx
233 pop rdx
234 cmp rdx, r9
235 jne .failed
236
237 call x861_LoadUniqueRegValues
238 mov eax, __LINE__
239 db 042h ; REX.X
240 push rcx
241 pop rdx
242 cmp rdx, rcx
243 jne .failed
244
245 call x861_LoadUniqueRegValues
246 mov eax, __LINE__
247 db 044h ; REX.R
248 push rcx
249 pop rdx
250 cmp rdx, rcx
251 jne .failed
252
253 call x861_LoadUniqueRegValues
254 mov eax, __LINE__
255 db 048h ; REX.W
256 push rcx
257 pop rdx
258 cmp rdx, rcx
259 jne .failed
260
261 call x861_LoadUniqueRegValues
262 mov eax, __LINE__
263 db 04fh ; REX.*
264 push rcx
265 pop rdx
266 cmp rdx, r9
267 jne .failed
268%endif
269
270 ;
271 ; Zero extening when moving from a segreg as well as memory access sizes.
272 ;
273 call x861_LoadUniqueRegValues
274 mov eax, __LINE__
275 mov ecx, ds
276 shr xCX, 16
277 cmp xCX, 0
278 jnz .failed
279
280%ifdef RT_ARCH_AMD64
281 call x861_LoadUniqueRegValues
282 mov eax, __LINE__
283 mov rcx, ds
284 shr rcx, 16
285 cmp rcx, 0
286 jnz .failed
287%endif
288
289 call x861_LoadUniqueRegValues
290 mov eax, __LINE__
291 mov xDX, xCX
292 mov cx, ds
293 shr xCX, 16
294 shr xDX, 16
295 cmp xCX, xDX
296 jnz .failed
297
298 ; Loading is always a word access.
299 mov eax, __LINE__
300 mov xDI, [NAME(g_pbEfPage)]
301 lea xDI, [xDI + 0x1000 - 2]
302 mov xDX, es
303 mov [xDI], dx
304 mov es, [xDI] ; should not crash
305
306 ; Saving is always a word access.
307 mov eax, __LINE__
308 mov xDI, [NAME(g_pbEfPage)]
309 mov dword [xDI + 0x1000 - 4], -1
310 mov [xDI + 0x1000 - 2], ss ; Should not crash.
311 mov bx, ss
312 mov cx, [xDI + 0x1000 - 2]
313 cmp cx, bx
314 jne .failed
315
316%ifdef RT_ARCH_AMD64
317 ; Check that the rex.R and rex.W bits don't have any influence over a memory write.
318 call x861_ClearRegisters
319 mov eax, __LINE__
320 mov xDI, [NAME(g_pbEfPage)]
321 mov dword [xDI + 0x1000 - 4], -1
322 db 04ah
323 mov [xDI + 0x1000 - 2], ss ; Should not crash.
324 mov bx, ss
325 mov cx, [xDI + 0x1000 - 2]
326 cmp cx, bx
327 jne .failed
328%endif
329
330
331 ;
332 ; Check what happens when both string prefixes are used.
333 ;
334 cld
335 mov dx, ds
336 mov es, dx
337
338 ; check that repne scasb (al=0) behaves like expected.
339 mov xDI, g_szAlpha
340 xor eax, eax ; find the end
341 mov ecx, g_cchAlpha + 1
342 repne scasb
343 cmp ecx, 1
344 mov eax, __LINE__
345 jne .failed
346
347 ; check that repe scasb (al=0) behaves like expected.
348 mov xDI, g_szAlpha
349 xor eax, eax ; find the end
350 mov ecx, g_cchAlpha + 1
351 repe scasb
352 cmp ecx, g_cchAlpha
353 mov eax, __LINE__
354 jne .failed
355
356 ; repne is last, it wins.
357 mov xDI, g_szAlpha
358 xor eax, eax ; find the end
359 mov ecx, g_cchAlpha + 1
360 db 0f3h ; repe - ignored
361 db 0f2h ; repne
362 scasb
363 cmp ecx, 1
364 mov eax, __LINE__
365 jne .failed
366
367 ; repe is last, it wins.
368 mov xDI, g_szAlpha
369 xor eax, eax ; find the end
370 mov ecx, g_cchAlpha + 1
371 db 0f2h ; repne - ignored
372 db 0f3h ; repe
373 scasb
374 cmp ecx, g_cchAlpha
375 mov eax, __LINE__
376 jne .failed
377
378 ;
379 ; Check if stosb works with both prefixes.
380 ;
381 cld
382 mov dx, ds
383 mov es, dx
384 mov xDI, [NAME(g_pbEfPage)]
385 xor eax, eax
386 mov ecx, 01000h
387 rep stosb
388
389 mov xDI, [NAME(g_pbEfPage)]
390 mov ecx, 4
391 mov eax, 0ffh
392 db 0f2h ; repne
393 stosb
394 mov eax, __LINE__
395 cmp ecx, 0
396 jne .failed
397 mov eax, __LINE__
398 mov xDI, [NAME(g_pbEfPage)]
399 cmp dword [xDI], 0ffffffffh
400 jne .failed
401 cmp dword [xDI+4], 0
402 jne .failed
403
404 mov xDI, [NAME(g_pbEfPage)]
405 mov ecx, 4
406 mov eax, 0feh
407 db 0f3h ; repe
408 stosb
409 mov eax, __LINE__
410 cmp ecx, 0
411 jne .failed
412 mov eax, __LINE__
413 mov xDI, [NAME(g_pbEfPage)]
414 cmp dword [xDI], 0fefefefeh
415 jne .failed
416 cmp dword [xDI+4], 0
417 jne .failed
418
419 ;
420 ; String operations shouldn't crash because of an invalid address if rCX is 0.
421 ;
422 mov eax, __LINE__
423 cld
424 mov dx, ds
425 mov es, dx
426 mov xDI, [NAME(g_pbEfPage)]
427 xor xCX, xCX
428 rep stosb ; no trap
429
430 ;
431 ; INS/OUTS will trap in ring-3 even when rCX is 0. (ASSUMES IOPL < 3)
432 ;
433 mov eax, __LINE__
434 cld
435 mov dx, ss
436 mov ss, dx
437 mov xDI, xSP
438 xor xCX, xCX
439 ShouldTrap X86_XCPT_GP, rep insb
440
441
442
443.success:
444 xor eax, eax
445.return:
446%ifdef RT_ARCH_AMD64
447 pop r15
448 pop r14
449 pop r13
450 pop r12
451 pop r11
452 pop r10
453 pop r9
454 pop r8
455%endif
456 pop xDI
457 pop xSI
458 pop xDX
459 pop xCX
460 pop xBX
461 popf
462 leave
463 ret
464
465.failed2:
466 mov eax, -1
467.failed:
468 jmp .return
469ENDPROC x861_Test1
470
471
472;;
473; Terminate the trap info array with a NIL entry.
474BEGINDATA
475GLOBALNAME g_aTrapInfoEnd
476istruc TRAPINFO
477 at TRAPINFO.uTrapPC, RTCCPTR_DEF 0
478 at TRAPINFO.uResumePC, RTCCPTR_DEF 0
479 at TRAPINFO.u8TrapNo, db 0
480 at TRAPINFO.cbInstr, db 0
481iend
482
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