VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstInstrEmul.cpp@ 13561

Last change on this file since 13561 was 13561, checked in by vboxsync, 16 years ago

Emulate (lock) cmpxchg8b in ring 0 & 3. Added testcase for instruction emulation.

File size: 2.8 KB
Line 
1/* $Id: tstMicro.cpp 37408 2008-10-03 22:22:37Z bird $ */
2/** @file
3 * Micro Testcase, checking emulation of certain instructions
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <stdio.h>
26#include <VBox/vm.h>
27#include <VBox/err.h>
28#include <VBox/em.h>
29
30#include <VBox/log.h>
31#include <iprt/assert.h>
32#include <iprt/runtime.h>
33#include <iprt/stream.h>
34#include <iprt/string.h>
35#include <iprt/semaphore.h>
36
37
38int main(int argc, char **argv)
39{
40 int rcRet = 0; /* error count. */
41
42 uint32_t eax, edx, ebx, ecx, eflags;
43 uint64_t val;
44
45 val = UINT64_C(0xffffffffffff);
46 eax = 0xffffffff;
47 edx = 0xffff;
48 ebx = 0x1;
49 ecx = 0x2;
50 eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
51 if ( !(eflags & X86_EFL_ZF)
52 || val != UINT64_C(0x200000001))
53 {
54 printf("Lock cmpxchg8b failed the equal case! (val=%x%x)\n", val);
55 return -1;
56 }
57 eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
58 if (eflags & X86_EFL_ZF)
59 {
60 printf("Lock cmpxchg8b failed the non-equal case! (val=%x%x)\n", val);
61 return -1;
62 }
63 printf("Testing lock cmpxchg instruction emulation - SUCCESS\n");
64
65 val = UINT64_C(0xffffffffffff);
66 eax = 0xffffffff;
67 edx = 0xffff;
68 ebx = 0x1;
69 ecx = 0x2;
70 eflags = EMEmulateCmpXchg8b(&val, &eax, &edx, ebx, ecx);
71 if ( !(eflags & X86_EFL_ZF)
72 || val != UINT64_C(0x200000001))
73 {
74 printf("Cmpxchg8b failed the equal case! (val=%x%x)\n", val);
75 return -1;
76 }
77 eflags = EMEmulateCmpXchg8b(&val, &eax, &edx, ebx, ecx);
78 if (eflags & X86_EFL_ZF)
79 {
80 printf("Cmpxchg8b failed the non-equal case! (val=%x%x)\n", val);
81 return -1;
82 }
83 printf("Testing cmpxchg instruction emulation - SUCCESS\n");
84
85 return rcRet;
86}
Note: See TracBrowser for help on using the repository browser.

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