summaryrefslogtreecommitdiff
path: root/src/VBox/VMM/testcase/tstInstrEmul.cpp
blob: 3173c48ca551e3d3ca5220ac72d159b7b8fee6fc (plain)
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
/* $Id: tstInstrEmul.cpp $ */
/** @file
 * Micro Testcase, checking emulation of certain instructions
 */

/*
 * Copyright (C) 2006-2014 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.
 */

/*******************************************************************************
*   Header Files                                                               *
*******************************************************************************/
#include <stdio.h>
#include <VBox/vmm/vm.h>
#include <VBox/err.h>
#include <VBox/vmm/em.h>

#include <VBox/log.h>
#include <iprt/assert.h>
#include <iprt/initterm.h>
#include <iprt/stream.h>
#include <iprt/string.h>
#include <iprt/semaphore.h>


int main(int argc, char **argv)
{
    int     rcRet = 0;                  /* error count. */

    RTR3InitExe(argc, &argv, 0);
    RTPrintf("tstInstrEmul: TESTING...\n");

    uint32_t eax, edx, ebx, ecx, eflags;
    uint64_t val;

    val = UINT64_C(0xffffffffffff);
    eax = 0xffffffff;
    edx = 0xffff;
    ebx = 0x1;
    ecx = 0x2;
    eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
    if (    !(eflags & X86_EFL_ZF)
        ||  val != UINT64_C(0x200000001))
    {
        RTPrintf("tstInstrEmul: FAILURE - Lock cmpxchg8b failed the equal case! (val=%RX64)\n", val);
        return 1;
    }
    val = UINT64_C(0x123456789);
    eflags = EMEmulateLockCmpXchg8b(&val, &eax, &edx, ebx, ecx);
    if (    (eflags & X86_EFL_ZF)
        ||  eax != 0x23456789
        ||  edx != 0x1)
    {
        RTPrintf("tstInstrEmul: FAILURE - Lock cmpxchg8b failed the non-equal case! (val=%RX64)\n", val);
        return 1;
    }
    RTPrintf("tstInstrEmul: Testing lock cmpxchg instruction emulation - SUCCESS\n");

    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=%RX64)\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=%RX64)\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;
}