tstAnimate.cpp revision b1c3cdef473df2fbc621d5da81acc82dbfb8a11a
/* $Id$ */
/** @file
* VBox Animation Testcase / Tool.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include <signal.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static volatile bool g_fSignaled = false;
static void SigInterrupt(int iSignal)
{
g_fSignaled = true;
RTPrintf("caught SIGINT\n");
}
typedef FNSETGUESTGPR *PFNSETGUESTGPR;
{
if (RT_FAILURE(rc))
return rc;
}
typedef FNSETGUESTSEL *PFNSETGUESTSEL;
{
if (RT_FAILURE(rc))
return rc;
}
typedef FNSETGUESTSYS *PFNSETGUESTSYS;
{
if (RT_FAILURE(rc))
return rc;
}
typedef FNSETGUESTDTR *PFNSETGUESTDTR;
{
if (!pszPart2)
return -1;
*pszPart2++ = '\0';
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
}
{
int rc = VINF_SUCCESS;
if (pszEqual)
{
/*
* var = value
*/
*pszEqual = '\0';
/* variables */
static struct
{
const char *pszVar;
} aVars[] =
{
};
rc = -1;
for (unsigned i = 0; i < RT_ELEMENTS(aVars); i++)
{
{
break;
}
}
}
return rc;
}
{
RTPrintf("info: running script...\n");
if (RT_SUCCESS(rc))
{
if (cb == 0)
return VINF_SUCCESS;
{
if (pszBuf)
{
if (RT_SUCCESS(rc))
{
/*
* Now process what's in the buffer.
*/
{
/* skip blanks. */
psz++;
if (!*psz)
break;
/* end of line */
char *pszNext;
if (!pszEnd)
if (!pszEnd)
else
{
/* strip end */
*pszEnd = '\0';
*--pszEnd = '\0';
/* process the line */
if (RT_FAILURE(rc))
{
break;
}
}
/* else comment line */
/* next */
}
}
else
}
else
{
rc = VERR_NO_MEMORY;
}
}
else
}
else
return rc;
}
{
RTPrintf("info: loading memory...\n");
if (RT_SUCCESS(rc))
{
for (;;)
{
/* read a page from the file */
{
rc = VINF_SUCCESS;
else
break;
}
/* Write that page to the guest - skip known rom areas for now. */
}
}
else
return rc;
}
/**
* Creates the default configuration.
* This assumes an empty tree.
*
* @returns VBox status code.
* @param pVM VM handle.
*/
{
int rc;
int rcAll = VINF_SUCCESS;
bool fIOAPIC = false;
/*
* Create VM default values.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/** @todo CFGM Defaults: RawR0, PATMEnabled and CASMEnabled needs attention later. */
UPDATERC();
UPDATERC();
UPDATERC();
/*
* PDM.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/*
* Devices
*/
UPDATERC();
/* device */
#if 0
#endif
/*
* PC Arch.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/*
* PC Bios.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
RTUuidClear(&Uuid);
/* Bios logo. */
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/*
* ACPI
*/
/*
* DMA
*/
/*
* PCI bus.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/*
* PS/2 keyboard & mouse
*/
UPDATERC();
UPDATERC();
UPDATERC();
/*
* Floppy
*/
/*
* i8254 Programmable Interval Timer And Dummy Speaker
*/
UPDATERC();
UPDATERC();
UPDATERC();
/*
* i8259 Programmable Interrupt Controller.
*/
UPDATERC();
UPDATERC();
UPDATERC();
UPDATERC();
/*
* APIC.
*/
if (fIOAPIC)
{
/*
* I/O Advanced Programmable Interrupt Controller.
*/
}
/*
* RTC MC146818.
*/
/*
* VGA.
*/
//rc = CFGMR3InsertInteger(pCfg, "MonitorCount", 1); UPDATERC();
/*
* IDE controller.
*/
UPDATERC();
UPDATERC();
UPDATERC();
/*
* Network card.
*/
/*
* VMM Device
*/
/*
* ...
*/
return rcAll;
}
static void syntax(void)
{
RTPrintf("Syntax: tstAnimate < -r <raw-mem-file> | -z <saved-state> > \n"
" [-o <rawmem offset>]\n"
" [-s <script file>]\n"
" [-m <memory size>]\n"
" [-w <warp drive percent>]\n"
" [-p]\n"
"\n"
"The script is on the form:\n"
"<reg>=<value>\n");
}
{
int rcRet = 1;
int rc;
/*
* Parse input.
*/
if (argc <= 1)
{
syntax();
return 1;
}
bool fPowerOn = false;
const char *pszSavedState = NULL;
for (int i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
/* check that it's on short form */
if (argv[i][2])
{
else
syntax();
return 1;
}
/* check for 2nd argument */
switch (argv[i][1])
{
case 'r':
case 'o':
case 'c':
case 'm':
case 'w':
case 'z':
if (i + 1 < argc)
break;
return 1;
}
/* process argument */
switch (argv[i][1])
{
case 'r':
break;
case 'z':
pszSavedState = argv[++i];
break;
case 'o':
{
if (RT_FAILURE(rc))
{
RTPrintf("tstAnimate: Syntax error: Invalid offset given to -o.\n");
return 1;
}
break;
}
case 'm':
{
char *pszNext;
if (RT_FAILURE(rc))
{
RTPrintf("tstAnimate: Syntax error: Invalid memory size given to -m.\n");
return 1;
}
switch (*pszNext)
{
case '\0': break;
default:
RTPrintf("tstAnimate: Syntax error: Invalid memory size given to -m.\n");
return 1;
}
if (*pszNext)
{
RTPrintf("tstAnimate: Syntax error: Invalid memory size given to -m.\n");
return 1;
}
break;
}
case 's':
break;
case 'p':
fPowerOn = true;
break;
case 'w':
{
if (RT_FAILURE(rc))
{
RTPrintf("tstAnimate: Syntax error: Invalid number given to -w.\n");
return 1;
}
break;
}
case 'h':
case 'H':
case '?':
syntax();
return 1;
default:
return 1;
}
}
else
{
syntax();
return 1;
}
}
/*
* Check that the basic requirements are met.
*/
if (pszRawMem && pszSavedState)
{
RTPrintf("tstAnimate: Syntax error: Either -z or -r, not both.\n");
return 1;
}
if (!pszRawMem && !pszSavedState)
{
RTPrintf("tstAnimate: Syntax error: The -r argument is compulsory.\n");
return 1;
}
/*
* Open the files.
*/
if (pszRawMem)
{
if (RT_FAILURE(rc))
{
return 1;
}
}
if (pszScript)
{
if (RT_FAILURE(rc))
{
return 1;
}
}
/*
* Figure the memsize if not specified.
*/
{
if (FileRawMem != NIL_RTFILE)
{
}
else
{
RTPrintf("tstAnimate: error: too lazy to figure out the memsize in a saved state.\n");
return 1;
}
}
/*
* Open a release log.
*/
static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
if (RT_SUCCESS(rc))
else
/*
* Create empty VM.
*/
if (RT_SUCCESS(rc))
{
/*
* Load memory.
*/
if (FileRawMem != NIL_RTFILE)
rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq1, RT_INDEFINITE_WAIT, (PFNRT)loadMem, 3, pVM, FileRawMem, &offRawMem);
else
rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq1, RT_INDEFINITE_WAIT, (PFNRT)SSMR3Load, 4, pVM, pszSavedState, SSMAFTER_DEBUG_IT, NULL, NULL);
if (RT_SUCCESS(rc))
{
/*
* Load register script.
*/
if (FileScript != NIL_RTFILE)
{
rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq1, RT_INDEFINITE_WAIT, (PFNRT)scriptRun, 2, pVM, FileScript);
}
if (RT_SUCCESS(rc))
{
if (fPowerOn)
{
/*
* Adjust warpspeed?
*/
if (u32WarpDrive != 100)
{
if (RT_FAILURE(rc))
}
/*
* Start the thing with single stepping and stuff enabled.
* (Try make sure we don't execute anything in raw mode.)
*/
RTPrintf("info: powering on the VM...\n");
if (RT_SUCCESS(rc))
{
rc = VMR3ReqCall(pVM, VMREQDEST_ANY, &pReq1, RT_INDEFINITE_WAIT, (PFNRT)EMR3RawSetMode, 2, pVM, EMRAW_NONE);
if (fPowerOn)
if (RT_SUCCESS(rc))
{
RTPrintf("info: VM is running\n");
while (!g_fSignaled)
RTThreadSleep(1000);
}
else
}
else
}
else
{
/*
* Don't start it, just enter the debugger.
*/
RTPrintf("info: entering debugger...\n");
while (!g_fSignaled)
RTThreadSleep(1000);
}
RTPrintf("info: shutting down the VM...\n");
}
/* execScript complains */
}
/*
* Cleanup.
*/
if (!RT_SUCCESS(rc))
{
rcRet++;
}
}
else
{
rcRet++;
}
return rcRet;
}