tstX86-1.cpp revision e39e9ca944f684a8b310c320b54aa43bbaa072da
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * X86 instruction set exploration/testcase #1.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Copyright (C) 2011 Oracle Corporation
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * available from http://www.virtualbox.org. This file is free software;
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * you can redistribute it and/or modify it under the terms of the GNU
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * General Public License (GPL) as published by the Free Software
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/*******************************************************************************
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync* Header Files *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync*******************************************************************************/
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/*******************************************************************************
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync* Structures and Typedefs *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync*******************************************************************************/
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsynctypedef struct TRAPINFO
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/*******************************************************************************
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync* Global Variables *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync*******************************************************************************/
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/*******************************************************************************
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync* Internal Functions *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync*******************************************************************************/
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncstatic void sigHandler(int iSig, siginfo_t *pSigInfo, void *pvSigCtx)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync# if defined(RT_ARCH_AMD64) && defined(RT_OS_DARWIN)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__rip;
e39e9ca944f684a8b310c320b54aa43bbaa072davboxsync# elif defined(RT_ARCH_AMD64) && defined(RT_OS_FREEBSD)
e39e9ca944f684a8b310c320b54aa43bbaa072davboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_rip;
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RIP];
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync# elif defined(RT_ARCH_X86) && defined(RT_OS_DARWIN)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext->__ss.__eip;
e39e9ca944f684a8b310c320b54aa43bbaa072davboxsync# elif defined(RT_ARCH_X86) && defined(RT_OS_FREEBSD)
e39e9ca944f684a8b310c320b54aa43bbaa072davboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.mc_eip;
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_EIP];
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync /** @todo verify the kind of trap */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Set up the test environment.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstX86-1", &hTest);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync g_pbEfPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync static int const s_aiSigs[] = { SIGBUS, SIGSEGV, SIGFPE };
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync for (unsigned i = 0; i < RT_ELEMENTS(s_aiSigs); i++)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync RTTESTI_CHECK_BREAK(sigaction(s_aiSigs[i], NULL, &SigAct) == 0);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync RTTESTI_CHECK(sigaction(s_aiSigs[i], &SigAct, NULL) == 0);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync /** @todo implement me. */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Do the testing.