VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstX86-1.cpp@ 36847

Last change on this file since 36847 was 36791, checked in by vboxsync, 14 years ago

tstX86-1: Build fix for FreeBSD

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: tstX86-1.cpp 36791 2011-04-21 13:39:15Z vboxsync $ */
2/** @file
3 * X86 instruction set exploration/testcase #1.
4 */
5
6/*
7 * Copyright (C) 2011 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/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/test.h>
23#include <iprt/param.h>
24
25#ifdef RT_OS_WINDOWS
26# include <Windows.h>
27#else
28# ifdef RT_OS_DARWIN
29# define _XOPEN_SOURCE
30# endif
31# include <signal.h>
32# include <ucontext.h>
33# define USE_SIGNAL
34#endif
35
36
37/*******************************************************************************
38* Structures and Typedefs *
39*******************************************************************************/
40typedef struct TRAPINFO
41{
42 uintptr_t uTrapPC;
43 uintptr_t uResumePC;
44 uint8_t u8Trap;
45 uint8_t cbInstr;
46 uint8_t auAlignment[sizeof(uintptr_t) * 2 - 2];
47} TRAPINFO;
48typedef TRAPINFO const *PCTRAPINFO;
49
50/*******************************************************************************
51* Global Variables *
52*******************************************************************************/
53RT_C_DECLS_BEGIN
54uint8_t *g_pbEfPage = NULL;
55extern TRAPINFO g_aTrapInfo[];
56RT_C_DECLS_END
57
58
59/*******************************************************************************
60* Internal Functions *
61*******************************************************************************/
62DECLASM(int32_t) x861_Test1(void);
63
64
65
66static PCTRAPINFO findTrapInfo(uintptr_t uTrapPC)
67{
68 for (unsigned i = 0; g_aTrapInfo[i].uTrapPC; i++)
69 if (g_aTrapInfo[i].uTrapPC == uTrapPC)
70 return &g_aTrapInfo[i];
71
72 return NULL;
73}
74
75#ifdef USE_SIGNAL
76static void sigHandler(int iSig, siginfo_t *pSigInfo, void *pvSigCtx)
77{
78 ucontext_t *pCtx = (ucontext_t *)pvSigCtx;
79# if defined(RT_ARCH_AMD64) && defined(RT_OS_DARWIN)
80 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__rip;
81# elif defined(RT_ARCH_AMD64) && defined(RT_OS_FREEBSD)
82 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_rip;
83# elif defined(RT_ARCH_AMD64)
84 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RIP];
85# elif defined(RT_ARCH_X86) && defined(RT_OS_DARWIN)
86 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__eip;
87# elif defined(RT_ARCH_X86) && defined(RT_OS_FREEBSD)
88 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_eip;
89# elif defined(RT_ARCH_X86)
90 uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_EIP];
91# else
92 uintptr_t *puPC = NULL;
93# endif
94
95 PCTRAPINFO pTrapInfo = findTrapInfo(*puPC);
96 if (pTrapInfo)
97 {
98 /** @todo verify the kind of trap */
99 *puPC = pTrapInfo->uResumePC;
100 return;
101 }
102
103 /* die */
104 signal(iSig, SIG_IGN);
105}
106#else
107
108#endif
109
110int main()
111{
112 /*
113 * Set up the test environment.
114 */
115 RTTEST hTest;
116 RTEXITCODE rcExit = RTTestInitAndCreate("tstX86-1", &hTest);
117 if (rcExit != RTEXITCODE_SUCCESS)
118 return rcExit;
119 g_pbEfPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE);
120 RTTESTI_CHECK(g_pbEfPage != NULL);
121
122#ifdef USE_SIGNAL
123 static int const s_aiSigs[] = { SIGBUS, SIGSEGV, SIGFPE };
124 for (unsigned i = 0; i < RT_ELEMENTS(s_aiSigs); i++)
125 {
126 struct sigaction SigAct;
127 RTTESTI_CHECK_BREAK(sigaction(s_aiSigs[i], NULL, &SigAct) == 0);
128 SigAct.sa_sigaction = sigHandler;
129 SigAct.sa_flags |= SA_SIGINFO;
130 RTTESTI_CHECK(sigaction(s_aiSigs[i], &SigAct, NULL) == 0);
131 }
132#else
133 /** @todo implement me. */
134#endif
135
136
137 if (!RTTestErrorCount(hTest))
138 {
139
140 /*
141 * Do the testing.
142 */
143 RTTestSub(hTest, "part 1");
144 int32_t rc = x861_Test1();
145 if (rc != 0)
146 RTTestFailed(hTest, "x861_Test1 -> %d", rc);
147 }
148
149 return RTTestSummaryAndDestroy(hTest);
150}
151
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