2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2003-03-03 02:59:12 +03:00
|
|
|
// $Id: pc_system.cc,v 1.33 2003-03-02 23:59:08 cbothamy Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2002-06-16 19:02:28 +04:00
|
|
|
// Copyright (C) 2002 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "bochs.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS bx_pc_system.
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
// #include <winsock2.h> // +++
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_SHOW_IPS
|
|
|
|
unsigned long ips_count=0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(PROVIDE_M_IPS)
|
|
|
|
double m_ips; // Millions of Instructions Per Second
|
|
|
|
#endif
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// Option for turning off BX_TIMER_DEBUG?
|
|
|
|
// Check out m_ips and ips
|
|
|
|
|
|
|
|
#define SpewPeriodicTimerInfo 0
|
|
|
|
#define MinAllowableTimerPeriod 1
|
|
|
|
|
|
|
|
|
|
|
|
#if SpewPeriodicTimerInfo
|
|
|
|
// If debugging, set the heartbeat to 5M cycles. Each heartbeat
|
|
|
|
// spews the active timer info.
|
|
|
|
const Bit64u bx_pc_system_c::NullTimerInterval = 5000000;
|
|
|
|
#else
|
|
|
|
// This must be the maximum 32-bit unsigned int value, NOT (Bit64u) -1.
|
|
|
|
const Bit64u bx_pc_system_c::NullTimerInterval = 0xffffffff;
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// constructor
|
|
|
|
bx_pc_system_c::bx_pc_system_c(void)
|
|
|
|
{
|
2001-06-27 23:16:01 +04:00
|
|
|
this->put("SYS");
|
2002-10-03 19:47:13 +04:00
|
|
|
|
|
|
|
// Timer[0] is the null timer. It is initialized as a special
|
|
|
|
// case here. It should never be turned off or modified, and its
|
|
|
|
// duration should always remain the same.
|
|
|
|
ticksTotal = 0; // Reset ticks since emulator started.
|
|
|
|
timer[0].period = NullTimerInterval;
|
|
|
|
timer[0].timeToFire = ticksTotal + NullTimerInterval;
|
|
|
|
timer[0].active = 1;
|
|
|
|
timer[0].continuous = 1;
|
|
|
|
timer[0].funct = nullTimer;
|
|
|
|
timer[0].this_ptr = this;
|
2002-10-04 20:26:10 +04:00
|
|
|
currCountdown = NullTimerInterval;
|
|
|
|
currCountdownPeriod = NullTimerInterval;
|
2002-10-03 19:47:13 +04:00
|
|
|
numTimers = 1; // So far, only the nullTimer.
|
2003-02-14 07:22:16 +03:00
|
|
|
lastTimeUsec = 0;
|
|
|
|
usecSinceLast = 0;
|
2002-08-27 22:53:30 +04:00
|
|
|
}
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
|
2002-08-27 22:53:30 +04:00
|
|
|
void
|
|
|
|
bx_pc_system_c::init_ips(Bit32u ips)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
HRQ = 0;
|
|
|
|
|
|
|
|
enable_a20 = 1;
|
2001-05-23 12:16:07 +04:00
|
|
|
//set_INTR (0);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL < 2
|
|
|
|
a20_mask = 0xfffff;
|
|
|
|
#elif BX_CPU_LEVEL == 2
|
|
|
|
a20_mask = 0xffffff;
|
|
|
|
#else /* 386+ */
|
|
|
|
a20_mask = 0xffffffff;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// parameter 'ips' is the processor speed in Instructions-Per-Second
|
|
|
|
m_ips = double(ips) / 1000000.0L;
|
2002-10-03 19:47:13 +04:00
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("ips = %u", (unsigned) ips));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_pc_system_c::set_HRQ(bx_bool val)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
HRQ = val;
|
|
|
|
if (val)
|
2001-05-23 12:16:07 +04:00
|
|
|
BX_CPU(0)->async_event = 1;
|
2001-12-18 16:14:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if (BX_NUM_SIMULATORS < 2)
|
|
|
|
void
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_pc_system_c::set_INTR(bx_bool value)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2001-05-23 12:16:07 +04:00
|
|
|
if (bx_dbg.interrupts)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("pc_system: Setting INTR=%d on bootstrap processor %d", (int)value, BX_BOOTSTRAP_PROCESSOR));
|
2001-05-23 12:16:07 +04:00
|
|
|
//INTR = value;
|
2002-09-20 19:35:44 +04:00
|
|
|
BX_CPU(BX_BOOTSTRAP_PROCESSOR)->set_INTR(value);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// Read from the IO memory address space
|
|
|
|
//
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
Bit32u BX_CPP_AttrRegparmN(2)
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system_c::inp(Bit16u addr, unsigned io_len)
|
|
|
|
{
|
|
|
|
Bit32u ret;
|
|
|
|
|
|
|
|
ret = bx_devices.inp(addr, io_len);
|
|
|
|
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Write to the IO memory address space.
|
|
|
|
//
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system_c::outp(Bit16u addr, Bit32u value, unsigned io_len)
|
|
|
|
{
|
|
|
|
bx_devices.outp(addr, value, io_len);
|
|
|
|
}
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(1)
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system_c::set_enable_a20(Bit8u value)
|
|
|
|
{
|
|
|
|
#if BX_CPU_LEVEL < 2
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("set_enable_a20() called: 8086 emulation"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
#if BX_SUPPORT_A20
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
unsigned old_enable_a20 = enable_a20;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if (value) {
|
|
|
|
enable_a20 = 1;
|
|
|
|
#if BX_CPU_LEVEL == 2
|
|
|
|
a20_mask = 0xffffff; /* 286: enable all 24 address lines */
|
|
|
|
#else /* 386+ */
|
|
|
|
a20_mask = 0xffffffff; /* 386: enable all 32 address lines */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
enable_a20 = 0;
|
|
|
|
a20_mask = 0xffefffff; /* mask off A20 address line */
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_DBG_A20_REPORT(value);
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("A20: set() = %u", (unsigned) enable_a20));
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
|
|
|
|
// If there has been a transition, we need to notify the CPUs so
|
|
|
|
// they can potentially invalidate certain cache info based on
|
|
|
|
// A20-line-applied physical addresses.
|
|
|
|
if (old_enable_a20 != enable_a20) {
|
|
|
|
for (unsigned i=0; i<BX_SMP_PROCESSORS; i++)
|
|
|
|
BX_CPU(i)->pagingA20Changed();
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("set_enable_a20: ignoring: SUPPORT_A20 = 0"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_SUPPORT_A20
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system_c::get_enable_a20(void)
|
|
|
|
{
|
|
|
|
#if BX_SUPPORT_A20
|
|
|
|
if (bx_dbg.a20)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("A20: get() = %u", (unsigned) enable_a20));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (enable_a20) return(1);
|
|
|
|
else return(0);
|
|
|
|
#else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("get_enable_a20: ignoring: SUPPORT_A20 = 0"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1);
|
|
|
|
#endif // #if BX_SUPPORT_A20
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bx_pc_system_c::ResetSignal( PCS_OP operation )
|
|
|
|
{
|
|
|
|
UNUSED( operation );
|
|
|
|
// Reset the processor.
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_ERROR(( "# bx_pc_system_c::ResetSignal() called" ));
|
2001-05-23 12:16:07 +04:00
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS; i++)
|
|
|
|
BX_CPU(i)->reset(BX_RESET_SOFTWARE);
|
2002-10-25 01:07:56 +04:00
|
|
|
DEV_reset_devices(BX_RESET_SOFTWARE);
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Bit8u
|
|
|
|
bx_pc_system_c::IAC(void)
|
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
return( DEV_pic_iac() );
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
bx_pc_system_c::exit(void)
|
|
|
|
{
|
2002-10-25 01:07:56 +04:00
|
|
|
if (DEV_hd_present())
|
|
|
|
DEV_hd_close_harddrive();
|
|
|
|
|
|
|
|
BX_INFO(("Last time is %u", (unsigned) DEV_cmos_get_timeval()));
|
|
|
|
|
|
|
|
if (bx_gui) bx_gui->exit();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// ================================================
|
|
|
|
// Bochs internal timer delivery framework features
|
|
|
|
// ================================================
|
|
|
|
|
|
|
|
int
|
|
|
|
bx_pc_system_c::register_timer( void *this_ptr, void (*funct)(void *),
|
2002-10-25 15:44:41 +04:00
|
|
|
Bit32u useconds, bx_bool continuous, bx_bool active, const char *id)
|
2002-10-03 19:47:13 +04:00
|
|
|
{
|
|
|
|
Bit64u ticks;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// Convert useconds to number of ticks.
|
|
|
|
ticks = (Bit64u) (double(useconds) * m_ips);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
return register_timer_ticks(this_ptr, funct, ticks, continuous, active, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bx_pc_system_c::register_timer_ticks(void* this_ptr, bx_timer_handler_t funct,
|
2002-10-25 15:44:41 +04:00
|
|
|
Bit64u ticks, bx_bool continuous, bx_bool active, const char *id)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
#if BX_TIMER_DEBUG
|
2002-10-03 19:47:13 +04:00
|
|
|
if (numTimers >= BX_MAX_TIMERS) {
|
|
|
|
BX_PANIC(("register_timer: too many registered timers."));
|
|
|
|
}
|
|
|
|
if (this_ptr == NULL)
|
|
|
|
BX_PANIC(("register_timer_ticks: this_ptr is NULL"));
|
|
|
|
if (funct == NULL)
|
|
|
|
BX_PANIC(("register_timer_ticks: funct is NULL"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// If the timer frequency is rediculously low, make it more sane.
|
|
|
|
// This happens when 'ips' is too low.
|
|
|
|
if (ticks < MinAllowableTimerPeriod) {
|
|
|
|
//BX_INFO(("register_timer_ticks: adjusting ticks of %llu to min of %u",
|
|
|
|
// ticks, MinAllowableTimerPeriod));
|
|
|
|
ticks = MinAllowableTimerPeriod;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-06 21:29:22 +04:00
|
|
|
for (i=0; i < numTimers; i++) {
|
|
|
|
if (timer[i].inUse == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer[i].inUse = 1;
|
2002-10-03 19:47:13 +04:00
|
|
|
timer[i].period = ticks;
|
2002-10-04 20:26:10 +04:00
|
|
|
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) +
|
2002-10-03 19:47:13 +04:00
|
|
|
ticks;
|
|
|
|
timer[i].active = active;
|
|
|
|
timer[i].continuous = continuous;
|
|
|
|
timer[i].funct = funct;
|
|
|
|
timer[i].this_ptr = this_ptr;
|
|
|
|
strncpy(timer[i].id, id, BxMaxTimerIDLen);
|
|
|
|
timer[i].id[BxMaxTimerIDLen-1] = 0; // Null terminate if not already.
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
if (active) {
|
2002-10-04 20:26:10 +04:00
|
|
|
if (ticks < Bit64u(currCountdown)) {
|
2002-10-03 19:47:13 +04:00
|
|
|
// This new timer needs to fire before the current countdown.
|
|
|
|
// Skew the current countdown and countdown period to be smaller
|
|
|
|
// by the delta.
|
2002-10-04 20:26:10 +04:00
|
|
|
currCountdownPeriod -= (currCountdown - Bit32u(ticks));
|
|
|
|
currCountdown = Bit32u(ticks);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 19:47:13 +04:00
|
|
|
|
2002-10-06 21:29:22 +04:00
|
|
|
// If we didn't find a free slot, increment the bound, numTimers.
|
|
|
|
if (i==numTimers)
|
|
|
|
numTimers++; // One new timer installed.
|
2002-10-03 19:47:13 +04:00
|
|
|
|
|
|
|
// Return timer id.
|
|
|
|
return(i);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
void
|
2002-10-03 19:47:13 +04:00
|
|
|
bx_pc_system_c::countdownEvent(void)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
unsigned i;
|
2002-10-03 19:47:13 +04:00
|
|
|
Bit64u minTimeToFire;
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_bool triggered[BX_MAX_TIMERS];
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// The countdown decremented to 0. We need to service all the active
|
|
|
|
// timers, and invoke callbacks from those timers which have fired.
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_TIMER_DEBUG
|
2002-10-03 19:47:13 +04:00
|
|
|
if (currCountdown != 0)
|
|
|
|
BX_PANIC(("countdownEvent: ticks!=0"));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// Increment global ticks counter by number of ticks which have
|
|
|
|
// elapsed since the last update.
|
2002-10-04 20:26:10 +04:00
|
|
|
ticksTotal += Bit64u(currCountdownPeriod);
|
2002-10-03 19:47:13 +04:00
|
|
|
minTimeToFire = (Bit64u) -1;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
for (i=0; i < numTimers; i++) {
|
|
|
|
triggered[i] = 0; // Reset triggered flag.
|
|
|
|
if (timer[i].active) {
|
|
|
|
#if BX_TIMER_DEBUG
|
|
|
|
if (ticksTotal > timer[i].timeToFire)
|
|
|
|
BX_PANIC(("countdownEvent: ticksTotal > timeToFire[%u], D %llu", i,
|
|
|
|
timer[i].timeToFire-ticksTotal));
|
|
|
|
#endif
|
|
|
|
if (ticksTotal == timer[i].timeToFire) {
|
|
|
|
// This timer is ready to fire.
|
|
|
|
triggered[i] = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
if (timer[i].continuous==0) {
|
|
|
|
// If triggered timer is one-shot, deactive.
|
|
|
|
timer[i].active = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Continuous timer, increment time-to-fire by period.
|
|
|
|
timer[i].timeToFire += timer[i].period;
|
|
|
|
if (timer[i].timeToFire < minTimeToFire)
|
|
|
|
minTimeToFire = timer[i].timeToFire;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// This timer is not ready to fire yet.
|
|
|
|
if (timer[i].timeToFire < minTimeToFire)
|
|
|
|
minTimeToFire = timer[i].timeToFire;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// Calculate next countdown period. We need to do this before calling
|
|
|
|
// any of the callbacks, as they may call timer features, which need
|
|
|
|
// to be advanced to the next countdown cycle.
|
|
|
|
currCountdown = currCountdownPeriod =
|
2002-10-04 20:26:10 +04:00
|
|
|
Bit32u(minTimeToFire - ticksTotal);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
for (i=0; i < numTimers; i++) {
|
|
|
|
// Call requested timer function. It may request a different
|
|
|
|
// timer period or deactivate etc.
|
|
|
|
if (triggered[i]) {
|
|
|
|
timer[i].funct(timer[i].this_ptr);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-03 19:47:13 +04:00
|
|
|
bx_pc_system_c::nullTimer(void* this_ptr)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-10-03 19:47:13 +04:00
|
|
|
// This function is always inserted in timer[0]. It is sort of
|
|
|
|
// a heartbeat timer. It ensures that at least one timer is
|
|
|
|
// always active to make the timer logic more simple, and has
|
|
|
|
// a duration of less than the maximum 32-bit integer, so that
|
|
|
|
// a 32-bit size can be used for the hot countdown timer. The
|
|
|
|
// rest of the timer info can be 64-bits. This is also a good
|
|
|
|
// place for some logic to report actual emulated
|
|
|
|
// instructions-per-second (IPS) data when measured relative to
|
|
|
|
// the host computer's wall clock.
|
|
|
|
|
|
|
|
UNUSED(this_ptr);
|
|
|
|
|
|
|
|
#if SpewPeriodicTimerInfo
|
|
|
|
BX_INFO(("==================================="));
|
|
|
|
for (unsigned i=0; i < bx_pc_system.numTimers; i++) {
|
|
|
|
if (bx_pc_system.timer[i].active) {
|
|
|
|
BX_INFO(("BxTimer(%s): period=%llu, continuous=%u",
|
|
|
|
bx_pc_system.timer[i].id, bx_pc_system.timer[i].period,
|
|
|
|
bx_pc_system.timer[i].continuous));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
void
|
|
|
|
bx_pc_system_c::timebp_handler(void* this_ptr)
|
|
|
|
{
|
2001-05-23 12:16:07 +04:00
|
|
|
BX_CPU(0)->break_point = BREAK_POINT_TIME;
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "Time breakpoint triggered" ));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (timebp_queue_size > 1) {
|
2001-09-24 04:35:42 +04:00
|
|
|
Bit64s new_diff = timebp_queue[1] - bx_pc_system.time_ticks();
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_pc_system.activate_timer_ticks(timebp_timer, new_diff, 1);
|
|
|
|
}
|
|
|
|
timebp_queue_size--;
|
|
|
|
for (int i = 0; i < timebp_queue_size; i++)
|
|
|
|
timebp_queue[i] = timebp_queue[i+1];
|
|
|
|
}
|
|
|
|
#endif // BX_DEBUGGER
|
|
|
|
|
2003-02-14 07:22:16 +03:00
|
|
|
Bit64u
|
|
|
|
bx_pc_system_c::time_usec_sequential() {
|
|
|
|
Bit64u this_time_usec = time_usec();
|
|
|
|
if(this_time_usec != lastTimeUsec) {
|
|
|
|
Bit64u diff_usec = this_time_usec-lastTimeUsec;
|
|
|
|
lastTimeUsec = this_time_usec;
|
|
|
|
if(diff_usec >= usecSinceLast) {
|
|
|
|
usecSinceLast = 0;
|
|
|
|
} else {
|
|
|
|
usecSinceLast -= diff_usec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
usecSinceLast++;
|
|
|
|
return (this_time_usec+usecSinceLast);
|
|
|
|
}
|
2002-10-03 19:47:13 +04:00
|
|
|
Bit64u
|
2001-07-02 00:42:56 +04:00
|
|
|
bx_pc_system_c::time_usec() {
|
2001-08-14 10:24:12 +04:00
|
|
|
return (Bit64u) (((double)(Bit64s)time_ticks()) / m_ips );
|
2001-07-02 00:42:56 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
bx_pc_system_c::start_timers(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_pc_system_c::activate_timer_ticks(unsigned i, Bit64u ticks, bx_bool continuous)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-10-03 19:47:13 +04:00
|
|
|
#if BX_TIMER_DEBUG
|
|
|
|
if (i >= numTimers)
|
|
|
|
BX_PANIC(("activate_timer_ticks: timer %u OOB", i));
|
|
|
|
if (timer[i].period < MinAllowableTimerPeriod)
|
|
|
|
BX_PANIC(("activate_timer_ticks: timer[%u].period of %llu < min of %u",
|
|
|
|
i, timer[i].period, MinAllowableTimerPeriod));
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
// If the timer frequency is rediculously low, make it more sane.
|
|
|
|
// This happens when 'ips' is too low.
|
|
|
|
if (ticks < MinAllowableTimerPeriod) {
|
|
|
|
//BX_INFO(("activate_timer_ticks: adjusting ticks of %llu to min of %u",
|
|
|
|
// ticks, MinAllowableTimerPeriod));
|
|
|
|
ticks = MinAllowableTimerPeriod;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
timer[i].period = ticks;
|
2002-10-04 20:26:10 +04:00
|
|
|
timer[i].timeToFire = (ticksTotal + Bit64u(currCountdownPeriod-currCountdown)) +
|
2002-10-03 19:47:13 +04:00
|
|
|
ticks;
|
|
|
|
timer[i].active = 1;
|
|
|
|
timer[i].continuous = continuous;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-04 20:26:10 +04:00
|
|
|
if (ticks < Bit64u(currCountdown)) {
|
2002-10-03 19:47:13 +04:00
|
|
|
// This new timer needs to fire before the current countdown.
|
|
|
|
// Skew the current countdown and countdown period to be smaller
|
|
|
|
// by the delta.
|
2002-10-04 20:26:10 +04:00
|
|
|
currCountdownPeriod -= (currCountdown - Bit32u(ticks));
|
|
|
|
currCountdown = Bit32u(ticks);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-25 15:44:41 +04:00
|
|
|
bx_pc_system_c::activate_timer(unsigned i, Bit32u useconds, bx_bool continuous)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-10-03 19:47:13 +04:00
|
|
|
Bit64u ticks;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
#if BX_TIMER_DEBUG
|
|
|
|
if (i >= numTimers)
|
|
|
|
BX_PANIC(("activate_timer: timer %u OOB", i));
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
// if useconds = 0, use default stored in period field
|
|
|
|
// else set new period from useconds
|
2002-10-03 19:47:13 +04:00
|
|
|
if (useconds==0) {
|
|
|
|
ticks = timer[i].period;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-10-03 19:47:13 +04:00
|
|
|
// convert useconds to number of ticks
|
|
|
|
ticks = (Bit64u) (double(useconds) * m_ips);
|
|
|
|
|
|
|
|
// If the timer frequency is rediculously low, make it more sane.
|
|
|
|
// This happens when 'ips' is too low.
|
|
|
|
if (ticks < MinAllowableTimerPeriod) {
|
|
|
|
//BX_INFO(("activate_timer: adjusting ticks of %llu to min of %u",
|
|
|
|
// ticks, MinAllowableTimerPeriod));
|
|
|
|
ticks = MinAllowableTimerPeriod;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-10-03 19:47:13 +04:00
|
|
|
|
|
|
|
timer[i].period = ticks;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-10-03 19:47:13 +04:00
|
|
|
|
|
|
|
activate_timer_ticks(i, ticks, continuous);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-10-03 19:47:13 +04:00
|
|
|
bx_pc_system_c::deactivate_timer( unsigned i )
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2002-10-03 19:47:13 +04:00
|
|
|
#if BX_TIMER_DEBUG
|
|
|
|
if (i >= numTimers)
|
|
|
|
BX_PANIC(("deactivate_timer: timer %u OOB", i));
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-10-03 19:47:13 +04:00
|
|
|
timer[i].active = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2002-10-06 18:55:06 +04:00
|
|
|
|
|
|
|
unsigned
|
2002-10-06 21:29:22 +04:00
|
|
|
bx_pc_system_c::unregisterTimer(int timerIndex)
|
2002-10-06 18:55:06 +04:00
|
|
|
{
|
2002-10-06 21:29:22 +04:00
|
|
|
unsigned i = (unsigned) timerIndex;
|
|
|
|
|
|
|
|
#if BX_TIMER_DEBUG
|
|
|
|
if (i >= numTimers)
|
|
|
|
BX_PANIC(("unregisterTimer: timer %u OOB", i));
|
|
|
|
if (i == 0)
|
|
|
|
BX_PANIC(("unregisterTimer: timer 0 is the nullTimer!"));
|
|
|
|
if (timer[i].inUse == 0)
|
|
|
|
BX_PANIC(("unregisterTimer: timer %u is not in-use!", i));
|
|
|
|
#endif
|
|
|
|
|
2002-10-06 18:55:06 +04:00
|
|
|
if (timer[i].active) {
|
|
|
|
BX_PANIC(("unregisterTimer: timer '%s' is still active!", timer[i].id));
|
|
|
|
return(0); // Fail.
|
|
|
|
}
|
2002-10-06 21:29:22 +04:00
|
|
|
|
|
|
|
// Reset timer fields for good measure.
|
|
|
|
timer[i].inUse = 0; // No longer registered.
|
|
|
|
timer[i].period = Bit64s(-1); // Max value (invalid)
|
|
|
|
timer[i].timeToFire = Bit64s(-1); // Max value (invalid)
|
|
|
|
timer[i].continuous = 0;
|
|
|
|
timer[i].funct = NULL;
|
|
|
|
timer[i].this_ptr = NULL;
|
|
|
|
memset(timer[i].id, 0, BxMaxTimerIDLen);
|
|
|
|
|
|
|
|
return(1); // OK
|
2002-10-06 18:55:06 +04:00
|
|
|
}
|