1 | /* $Id: DisasmTest.cpp 41714 2012-06-14 16:12:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox disassembler - Test application
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <VBox/dis.h>
|
---|
22 | #include <iprt/test.h>
|
---|
23 | #include <iprt/asm.h>
|
---|
24 | #include <iprt/string.h>
|
---|
25 | #include <VBox/err.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | DECLASM(int) TestProc32(void);
|
---|
29 | char TestProc32_End;
|
---|
30 | #ifndef RT_OS_OS2
|
---|
31 | DECLASM(int) TestProc64(void);
|
---|
32 | char TestProc64_End;
|
---|
33 | #endif
|
---|
34 | //uint8_t aCode16[] = { 0x66, 0x67, 0x89, 0x07 };
|
---|
35 |
|
---|
36 | static void testDisas(uint8_t const *pabInstrs, size_t cbInstrs, DISCPUMODE enmDisCpuMode)
|
---|
37 | {
|
---|
38 | for (size_t off = 0; off < cbInstrs; off++)
|
---|
39 | {
|
---|
40 | uint32_t const cErrBefore = RTTestIErrorCount();
|
---|
41 | uint32_t cb = 1;
|
---|
42 | DISCPUSTATE Cpu;
|
---|
43 | char szOutput[256] = {0};
|
---|
44 | int rc = DISInstrToStr(&pabInstrs[off], enmDisCpuMode, &Cpu, &cb, szOutput, sizeof(szOutput));
|
---|
45 |
|
---|
46 |
|
---|
47 | RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
|
---|
48 | RTTESTI_CHECK(cb == Cpu.opsize);
|
---|
49 | RTTESTI_CHECK(cb > 0);
|
---|
50 | RTTESTI_CHECK(cb <= 16);
|
---|
51 | if (cErrBefore != RTTestIErrorCount())
|
---|
52 | RTTestIFailureDetails("rc=%Rrc, off=%#x (%u) cbInstr=%u enmDisCpuMode=%d",
|
---|
53 | rc, off, Cpu.opsize, enmDisCpuMode);
|
---|
54 | RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", szOutput);
|
---|
55 | off += cb;
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | int main(int argc, char **argv)
|
---|
62 | {
|
---|
63 | RTTEST hTest;
|
---|
64 | RTEXITCODE rcExit = RTTestInitAndCreate("tstDisasm", &hTest);
|
---|
65 | if (rcExit)
|
---|
66 | return rcExit;
|
---|
67 | RTTestBanner(hTest);
|
---|
68 |
|
---|
69 |
|
---|
70 | testDisas((uint8_t const *)(uintptr_t)TestProc32, (uintptr_t)&TestProc32_End - (uintptr_t)TestProc32, DISCPUMODE_32BIT);
|
---|
71 | #ifndef RT_OS_OS2
|
---|
72 | testDisas((uint8_t const *)(uintptr_t)TestProc64, (uintptr_t)&TestProc64_End - (uintptr_t)TestProc64, DISCPUMODE_64BIT);
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | return RTTestSummaryAndDestroy(hTest);
|
---|
76 | }
|
---|
77 |
|
---|