Added an optional device-specific Bit8u parameter to the timer structure.

A device can set it with setTimerParam() and read it in the timer handled using
triggeredTimerParam(). Simplified some timer handler by using these methods.
TODO: implement HD / CD seek timer
This commit is contained in:
Volker Ruppert 2014-01-17 18:25:13 +00:00
parent dfae4b45de
commit 29d40bf9fe
7 changed files with 36 additions and 59 deletions

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2012 The Bochs Project
// Copyright (C) 2004-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -87,6 +87,7 @@ void bx_pci_ide_c::init(void)
if (BX_PIDE_THIS s.bmdma[i].timer_index == BX_NULL_TIMER_HANDLE) {
BX_PIDE_THIS s.bmdma[i].timer_index =
DEV_register_timer(this, timer_handler, 1000, 0,0, "PIIX3 BM-DMA timer");
bx_pc_system.setTimerParam(BX_PIDE_THIS s.bmdma[i].timer_index, i);
}
}
@ -229,20 +230,14 @@ void bx_pci_ide_c::timer_handler(void *this_ptr)
void bx_pci_ide_c::timer()
{
int timer_id, count;
Bit8u channel;
int count;
Bit32u size, sector_size;
struct {
Bit32u addr;
Bit32u size;
} prd;
timer_id = bx_pc_system.triggeredTimerID();
if (timer_id == BX_PIDE_THIS s.bmdma[0].timer_index) {
channel = 0;
} else {
channel = 1;
}
Bit8u channel = bx_pc_system.triggeredTimerParam();
if (((BX_PIDE_THIS s.bmdma[channel].status & 0x01) == 0) ||
(BX_PIDE_THIS s.bmdma[channel].prd_current == 0)) {
return;

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2012 The Bochs Project
// Copyright (C) 2004-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2004-2013 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -279,17 +279,20 @@ bx_serial_c::init(void)
BX_SER_THIS s[i].tx_timer_index =
bx_pc_system.register_timer(this, tx_timer_handler, 0,
0,0, "serial.tx"); // one-shot, inactive
bx_pc_system.setTimerParam(BX_SER_THIS s[i].tx_timer_index, i);
}
if (BX_SER_THIS s[i].rx_timer_index == BX_NULL_TIMER_HANDLE) {
BX_SER_THIS s[i].rx_timer_index =
bx_pc_system.register_timer(this, rx_timer_handler, 0,
0,0, "serial.rx"); // one-shot, inactive
bx_pc_system.setTimerParam(BX_SER_THIS s[i].rx_timer_index, i);
}
if (BX_SER_THIS s[i].fifo_timer_index == BX_NULL_TIMER_HANDLE) {
BX_SER_THIS s[i].fifo_timer_index =
bx_pc_system.register_timer(this, fifo_timer_handler, 0,
0,0, "serial.fifo"); // one-shot, inactive
bx_pc_system.setTimerParam(BX_SER_THIS s[i].fifo_timer_index, i);
}
BX_SER_THIS s[i].rx_pollstate = BX_SER_RXIDLE;
@ -1384,21 +1387,9 @@ void bx_serial_c::tx_timer_handler(void *this_ptr)
void bx_serial_c::tx_timer(void)
{
bx_bool gen_int = 0;
Bit8u port = 0;
int timer_id;
Bit8u port = bx_pc_system.triggeredTimerParam();
char pname[20];
timer_id = bx_pc_system.triggeredTimerID();
if (timer_id == BX_SER_THIS s[0].tx_timer_index) {
port = 0;
} else if (timer_id == BX_SER_THIS s[1].tx_timer_index) {
port = 1;
} else if (timer_id == BX_SER_THIS s[2].tx_timer_index) {
port = 2;
} else if (timer_id == BX_SER_THIS s[3].tx_timer_index) {
port = 3;
}
if (BX_SER_THIS s[port].modem_cntl.local_loopback) {
rx_fifo_enq(port, BX_SER_THIS s[port].tsrbuffer);
} else {
@ -1499,21 +1490,9 @@ void bx_serial_c::rx_timer(void)
struct timeval tval;
fd_set fds;
#endif
Bit8u port = 0;
int timer_id;
Bit8u port = bx_pc_system.triggeredTimerParam();
bx_bool data_ready = 0;
timer_id = bx_pc_system.triggeredTimerID();
if (timer_id == BX_SER_THIS s[0].rx_timer_index) {
port = 0;
} else if (timer_id == BX_SER_THIS s[1].rx_timer_index) {
port = 1;
} else if (timer_id == BX_SER_THIS s[2].rx_timer_index) {
port = 2;
} else if (timer_id == BX_SER_THIS s[3].rx_timer_index) {
port = 3;
}
int bdrate = BX_SER_THIS s[port].baudrate / (BX_SER_THIS s[port].line_cntl.wordlen_sel + 5);
unsigned char chbuf = 0;
@ -1659,19 +1638,8 @@ void bx_serial_c::fifo_timer_handler(void *this_ptr)
void bx_serial_c::fifo_timer(void)
{
Bit8u port = 0;
int timer_id;
Bit8u port = bx_pc_system.triggeredTimerParam();
timer_id = bx_pc_system.triggeredTimerID();
if (timer_id == BX_SER_THIS s[0].fifo_timer_index) {
port = 0;
} else if (timer_id == BX_SER_THIS s[1].fifo_timer_index) {
port = 1;
} else if (timer_id == BX_SER_THIS s[2].fifo_timer_index) {
port = 2;
} else if (timer_id == BX_SER_THIS s[3].fifo_timer_index) {
port = 3;
}
BX_SER_THIS s[port].line_status.rxdata_ready = 1;
raise_interrupt(port, BX_SER_INT_FIFO);
}

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2004-2013 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public

View File

@ -5,7 +5,7 @@
// ES1370 soundcard support (ported from QEMU)
//
// Copyright (c) 2005 Vassili Karpov (malc)
// Copyright (C) 2011-2013 The Bochs Project
// Copyright (C) 2011-2014 The Bochs Project
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -235,11 +235,13 @@ void bx_es1370_c::init(void)
BX_ES1370_THIS s.dac1_timer_index = bx_pc_system.register_timer
(BX_ES1370_THIS_PTR, es1370_timer_handler, 1, 1, 0, "es1370.dac1");
// DAC1 timer: inactive, continuous, frequency variable
bx_pc_system.setTimerParam(BX_ES1370_THIS s.dac1_timer_index, 0);
}
if (BX_ES1370_THIS s.dac2_timer_index == BX_NULL_TIMER_HANDLE) {
BX_ES1370_THIS s.dac2_timer_index = bx_pc_system.register_timer
(BX_ES1370_THIS_PTR, es1370_timer_handler, 1, 1, 0, "es1370.dac2");
// DAC2 timer: inactive, continuous, frequency variable
bx_pc_system.setTimerParam(BX_ES1370_THIS s.dac2_timer_index, 1);
}
// init runtime parameters
@ -576,11 +578,8 @@ void bx_es1370_c::es1370_timer_handler(void *this_ptr)
void bx_es1370_c::es1370_timer(void)
{
int timer_id;
unsigned i;
timer_id = bx_pc_system.triggeredTimerID();
i = (timer_id == BX_ES1370_THIS s.dac1_timer_index) ? 0 : 1;
int timer_id = bx_pc_system.triggeredTimerID();
unsigned i = bx_pc_system.triggeredTimerParam();
run_channel(i, timer_id, BX_ES1370_THIS s.dac_packet_size[i]);
}

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -296,6 +296,7 @@ int bx_pc_system_c::register_timer_ticks(void* this_ptr, bx_timer_handler_t func
timer[i].this_ptr = this_ptr;
strncpy(timer[i].id, id, BxMaxTimerIDLen);
timer[i].id[BxMaxTimerIDLen-1] = 0; // Null terminate if not already.
timer[i].param = 0;
if (active) {
if (ticks < Bit64u(currCountdown)) {
@ -563,3 +564,12 @@ bx_bool bx_pc_system_c::unregisterTimer(unsigned timerIndex)
return(1); // OK
}
bx_bool bx_pc_system_c::setTimerParam(unsigned timerIndex, Bit8u param)
{
#if BX_TIMER_DEBUG
if (timerIndex >= numTimers)
BX_PANIC(("setTimerParam: timer %u OOB", timerIndex));
#endif
timer[timerIndex].param = param;
}

View File

@ -2,7 +2,7 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002-2009 The Bochs Project
// Copyright (C) 2001-2014 The Bochs Project
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -52,7 +52,8 @@ private:
void *this_ptr; // The this-> pointer for C++ callbacks
// has to be stored as well.
#define BxMaxTimerIDLen 32
char id[BxMaxTimerIDLen]; // String ID of timer.
char id[BxMaxTimerIDLen]; // String ID of timer.
Bit8u param; // Device-specific value assigned to timer (optional)
} timer[BX_MAX_TIMERS];
unsigned numTimers; // Number of currently allocated timers.
@ -91,12 +92,16 @@ public:
int register_timer(void *this_ptr, bx_timer_handler_t, Bit32u useconds,
bx_bool continuous, bx_bool active, const char *id);
bx_bool unregisterTimer(unsigned timerID);
bx_bool setTimerParam(unsigned timerID, Bit8u param);
void start_timers(void);
void activate_timer(unsigned timer_index, Bit32u useconds, bx_bool continuous);
void deactivate_timer(unsigned timer_index);
unsigned triggeredTimerID(void) {
return triggeredTimer;
}
Bit8u triggeredTimerParam(void) {
return timer[triggeredTimer].param;
}
static BX_CPP_INLINE void tick1(void) {
if (--bx_pc_system.currCountdown == 0) {
bx_pc_system.countdownEvent();