tstInstrEmul.cpp revision 230bd8589bba39933ac5ec21482d6186d675e604
366N/A/* $Id$ */
366N/A/** @file
366N/A * Micro Testcase, checking emulation of certain instructions
366N/A */
943N/A
366N/A/*
366N/A * Copyright (C) 2006-2007 Oracle Corporation
919N/A *
919N/A * This file is part of VirtualBox Open Source Edition (OSE), as
919N/A * available from http://www.virtualbox.org. This file is free software;
919N/A * you can redistribute it and/or modify it under the terms of the GNU
919N/A * General Public License (GPL) as published by the Free Software
919N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
919N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
919N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
919N/A */
919N/A
919N/A/*******************************************************************************
919N/A* Header Files *
919N/A*******************************************************************************/
919N/A#include <stdio.h>
919N/A#include <VBox/vmm/vm.h>
919N/A#include <VBox/err.h>
919N/A#include <VBox/vmm/em.h>
366N/A
366N/A#include <VBox/log.h>
366N/A#include <iprt/assert.h>
366N/A#include <iprt/initterm.h>
493N/A#include <iprt/stream.h>
366N/A#include <iprt/string.h>
366N/A#include <iprt/semaphore.h>
493N/A
366N/A
911N/Aint main(int argc, char **argv)
911N/A{
911N/A int rcRet = 0; /* error count. */
911N/A
366N/A RTR3InitExe(argc, &argv, 0);
366N/A RTPrintf("tstInstrEmul: TESTING...\n");
366N/A
366N/A uint32_t eax, edx, ebx, ecx, eflags;
366N/A uint64_t val;
366N/A
970N/A val = UINT64_C(0xffffffffffff);
970N/A eax = 0xffffffff;
970N/A edx = 0xffff;
970N/A ebx = 0x1;
970N/A ecx = 0x2;
970N/A eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
366N/A if ( !(eflags & X86_EFL_ZF)
366N/A || val != UINT64_C(0x200000001))
493N/A {
969N/A RTPrintf("tstInstrEmul: FAILURE - Lock cmpxchg8b failed the equal case! (val=%x%x)\n", val);
366N/A return 1;
965N/A }
965N/A val = UINT64_C(0x123456789);
366N/A eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
366N/A if ( (eflags & X86_EFL_ZF)
366N/A || eax != 0x23456789
366N/A || edx != 0x1)
366N/A {
493N/A RTPrintf("tstInstrEmul: FAILURE - Lock cmpxchg8b failed the non-equal case! (val=%x%x)\n", val);
366N/A return 1;
970N/A }
970N/A RTPrintf("tstInstrEmul: Testing lock cmpxchg instruction emulation - SUCCESS\n");
970N/A
366N/A val = UINT64_C(0xffffffffffff);
eax = 0xffffffff;
edx = 0xffff;
ebx = 0x1;
ecx = 0x2;
eflags = EMEmulateCmpXchg8b(&val, &eax, &edx, ebx, ecx);
if ( !(eflags & X86_EFL_ZF)
|| val != UINT64_C(0x200000001))
{
RTPrintf("tstInstrEmul: FAILURE - Cmpxchg8b failed the equal case! (val=%x%x)\n", val);
return 1;
}
val = UINT64_C(0x123456789);
eflags = EMEmulateCmpXchg8b(&val, &eax, &edx, ebx, ecx);
if ( (eflags & X86_EFL_ZF)
|| eax != 0x23456789
|| edx != 0x1)
{
RTPrintf("tstInstrEmul: FAILURE - Cmpxchg8b failed the non-equal case! (val=%x%x)\n", val);
return 1;
}
RTPrintf("tstInstrEmul: Testing cmpxchg instruction emulation - SUCCESS\n");
/*
* Summary.
*/
if (!rcRet)
RTPrintf("tstInstrEmul: SUCCESS\n");
else
RTPrintf("tstInstrEmul: FAILURE - %d errors\n", rcRet);
return rcRet ? 1 : 0;
}