tstDisasm-1.cpp revision 520c825ff8270d50597dc471316acb6ee63275e2
b736c553dbde2c3b2533c93c57d9b7f07714371cvboxsync * VBox disassembler - Test application
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2006-2012 Oracle Corporation
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * available from http://www.virtualbox.org. This file is free software;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * General Public License (GPL) as published by the Free Software
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync/*******************************************************************************
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync* Header Files *
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync*******************************************************************************/
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync//uint8_t aCode16[] = { 0x66, 0x67, 0x89, 0x07 };
97566036db1dc1dba46ed21be4e147c728fd1027vboxsyncstatic void testDisas(const char *pszSub, uint8_t const *pabInstrs, uintptr_t uEndPtr, DISCPUMODE enmDisCpuMode)
d544fe535c163a24bf8cd831b39264da292b8adfvboxsync size_t const cbInstrs = uEndPtr - (uintptr_t)pabInstrs;
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync int rc = DISInstrToStr(&pabInstrs[off], enmDisCpuMode, &Dis, &cb, szOutput, sizeof(szOutput));
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync RTTestIFailureDetails("rc=%Rrc, off=%#x (%u) cbInstr=%u enmDisCpuMode=%d\n",
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncstatic DECLCALLBACK(int) testReadBytes(PDISSTATE pDis, uint8_t offInstr, uint8_t cbMinRead, uint8_t cbMaxRead)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync memcpy(&pDis->abInstr[offInstr], (void *)((uintptr_t)pDis->uInstrAddr + offInstr), cbMaxRead);
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsyncstatic void testPerformance(const char *pszSub, uint8_t const *pabInstrs, uintptr_t uEndPtr, DISCPUMODE enmDisCpuMode)
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync size_t const cbInstrs = uEndPtr - (uintptr_t)pabInstrs;
b379286f0d2c8d82f5a575eb907c7476aa6ae84bvboxsync for (uint32_t i = 0; i < _512K; i++) /* the samples are way to small. :-) */
9cabb72c6d6feb65e839ce50765643b98bb9a301vboxsync DISInstrWithReader((uintptr_t)&pabInstrs[off], enmDisCpuMode, testReadBytes, NULL, &Dis, &cb);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync RTTestIValueF(cNsElapsed, RTTESTUNIT_NS, "%s-Total", pszSub);
9474d83dcac691984017f8255821b95ec7642804vboxsync RTTestIValueF(cNsElapsed / cInstrs, RTTESTUNIT_NS_PER_CALL, "%s-per-instruction", pszSub);
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstDisasm", &hTest);
9474d83dcac691984017f8255821b95ec7642804vboxsync static const struct
9474d83dcac691984017f8255821b95ec7642804vboxsync const char *pszDesc;
9474d83dcac691984017f8255821b95ec7642804vboxsync { "32-bit", (uint8_t const *)(uintptr_t)TestProc32, (uintptr_t)&TestProc32_EndProc, DISCPUMODE_32BIT },
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync { "64-bit", (uint8_t const *)(uintptr_t)TestProc64, (uintptr_t)&TestProc64_EndProc, DISCPUMODE_64BIT },
666e2c9af6a34f7a05d8069a11194756312f5be6vboxsync for (unsigned i = 0; i < RT_ELEMENTS(aSnippets); i++)
b379286f0d2c8d82f5a575eb907c7476aa6ae84bvboxsync testDisas(aSnippets[i].pszDesc, aSnippets[i].pbStart, aSnippets[i].uEndPtr, aSnippets[i].enmCpuMode);
97566036db1dc1dba46ed21be4e147c728fd1027vboxsync for (unsigned i = 0; i < RT_ELEMENTS(aSnippets); i++)