VMMR0TripleFaultHack.cpp revision b3690ccf41161ecb6ac258be10fa7e93e6bcd6d4
/* $Id$ */
/** @file
* VMM - Host Context Ring 0, Triple Fault Debugging Hack.
*
* Only use this when desperate. May not work on all systems, esp. newer ones,
* since it require BIOS support for the warm reset vector at 0467h.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* 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 *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VMM
#include "VMMInternal.h"
#include <iprt/asm-amd64-x86.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static RTR0MEMOBJ g_hMemPage0;
static RTR0MEMOBJ g_hMapPage0;
static RTR0MEMOBJ g_hMemLowCore;
static RTR0MEMOBJ g_hMapLowCore;
static uint8_t *g_pbLowCore;
static RTHCPHYS g_HCPhysLowCore;
/** @name For restoring memory we've overwritten.
* @{ */
static uint32_t g_u32SavedVector;
static uint16_t g_u16SavedCadIndicator;
static void *g_pvSavedLowCore;
/** @} */
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
/* VMMR0TripleFaultHackA.asm */
DECLASM(void) vmmR0TripleFaultHackStart(void);
DECLASM(void) vmmR0TripleFaultHackEnd(void);
DECLASM(void) vmmR0TripleFaultHackTripleFault(void);
/**
* Initalizes the triple fault / boot hack.
*
* Always call vmmR0TripleFaultHackTerm to clean up, even when this call fails.
*
* @returns VBox status code.
*/
int vmmR0TripleFaultHackInit(void)
{
/*
* Map the first page.
*/
rc = RTR0MemObjMapKernel(&g_hMapPage0, g_hMemPage0, (void *)-1, 0, RTMEM_PROT_READ | RTMEM_PROT_WRITE);
LogRel(("0040:0067 = %04x:%04x\n", RT_MAKE_U16(g_pbPage0[0x467+2], g_pbPage0[0x467+3]), RT_MAKE_U16(g_pbPage0[0x467+0], g_pbPage0[0x467+1]) ));
/*
* Allocate some "low core" memory. If that fails, just grab some memory.
*/
//rc = RTR0MemObjAllocPhys(&g_hMemLowCore, PAGE_SIZE, _1M - 1);
//__debugbreak();
rc = RTR0MemObjMapKernel(&g_hMapLowCore, g_hMemLowCore, (void *)-1, 0, RTMEM_PROT_READ | RTMEM_PROT_WRITE);
/*
* Save memory we'll be overwriting.
*/
g_u32SavedVector = RT_MAKE_U32_FROM_U8(g_pbPage0[0x467], g_pbPage0[0x467+1], g_pbPage0[0x467+2], g_pbPage0[0x467+3]);
/*
* Install the code.
*/
/*
* Configure the status port and cmos shutdown command.
*/
ASMInU8(0x71);
ASMReloadCR3();
#if 1 /* For testing & debugging. */
#endif
return VINF_SUCCESS;
}
/**
* Try undo the harm done by the init function.
*
* This may leave the system in an unstable state since we might have been
* hijacking memory below 1MB that is in use by the kernel.
*/
void vmmR0TripleFaultHackTerm(void)
{
/*
* Restore overwritten memory.
*/
if ( g_pvSavedLowCore
&& g_pbLowCore)
if (g_pbPage0)
{
}
/*
* Fix the CMOS.
*/
if (g_pvSavedLowCore)
{
ASMInU8(0x71);
ASMReloadCR3();
}
/*
* Release resources.
*/
g_pbLowCore = NULL;
}