OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochsDevs/] [iodev/] [virt_timer.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
////////////////////////////////////////////////////////////////////////
2
// $Id: virt_timer.h 11183 2012-05-17 09:11:48Z vruppert $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2002-2009  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20
/////////////////////////////////////////////////////////////////////////
21
 
22
#ifndef _BX_VIRT_TIMER_H
23
#define _BX_VIRT_TIMER_H
24
 
25
// should be adjusted if want to support more SMP processors
26
#define BX_MAX_VIRTUAL_TIMERS (32)
27
#define BX_NULL_VIRTUAL_TIMER_HANDLE 10000
28
 
29
#define BX_MAX_VIRTUAL_TIME (0x7fffffff)
30
 
31
class BOCHSAPI bx_virt_timer_c : public logfunctions {
32
private:
33
 
34
  struct {
35
    bx_bool inUse;      // Timer slot is in-use (currently registered).
36
    Bit64u  period;     // Timer periodocity in virtual useconds.
37
    Bit64u  timeToFire; // Time to fire next (in virtual useconds).
38
    bx_bool active;     // 0=inactive, 1=active.
39
    bx_bool continuous; // 0=one-shot timer, 1=continuous periodicity.
40
    bx_timer_handler_t funct;  // A callback function for when the
41
                               //   timer fires.
42
                               //   This function MUST return.
43
    void *this_ptr;            // The this-> pointer for C++ callbacks
44
                               //   has to be stored as well.
45
    char id[BxMaxTimerIDLen]; // String ID of timer.
46
  } timer[BX_MAX_VIRTUAL_TIMERS];
47
 
48
  unsigned   numTimers;  // Number of currently allocated timers.
49
 
50
  //Variables for the timer subsystem:
51
  Bit64u current_timers_time;
52
  Bit64u timers_next_event_time;
53
 
54
  Bit64u last_sequential_time;
55
  bx_bool in_timer_handler;
56
 
57
  //Variables for the time sync subsystem:
58
  Bit64u virtual_next_event_time;
59
  Bit64u current_virtual_time;
60
 
61
  //Real time variables:
62
  Bit64u last_real_time;
63
  Bit64u total_real_usec;
64
  Bit64u last_realtime_delta;
65
  Bit64u real_time_delay;
66
  //System time variables:
67
  Bit64u last_usec;
68
  Bit64u usec_per_second;
69
  Bit64u stored_delta;
70
  Bit64u last_system_usec;
71
  Bit64u em_last_realtime;
72
  //Virtual timer variables:
73
  Bit64u total_ticks;
74
  Bit64u last_realtime_ticks;
75
  Bit64u ticks_per_second;
76
 
77
  // Local copy of IPS value
78
  Bit64u ips;
79
 
80
  bx_bool init_done;
81
 
82
  int system_timer_id;
83
 
84
  //Whether or not to use realtime virtual timers.
85
  bx_bool virtual_timers_realtime;
86
 
87
  // A special null timer is always inserted in the timer[0] slot.  This
88
  // make sure that at least one timer is always active, and that the
89
  // duration is always less than a maximum 32-bit integer, so a 32-bit
90
  // counter can be used for the current countdown.
91
  static const Bit64u NullTimerInterval;
92
  static void nullTimer(void* this_ptr);
93
 
94
  //Step the given number of cycles, optionally calling any timer handlers.
95
  void periodic(Bit64u time_passed);
96
 
97
  //Called when next_event_time changes.
98
  void next_event_time_update(void);
99
 
100
  //Called to advance the virtual time.
101
  // calls periodic as needed.
102
  void advance_virtual_time(Bit64u time_passed);
103
 
104
public:
105
 
106
  bx_virt_timer_c();
107
  virtual ~bx_virt_timer_c() {}
108
 
109
  //Get the current virtual time.
110
  //  This may return the same value on subsequent calls.
111
  Bit64u time_usec(void);
112
 
113
  //Get the current virtual time.
114
  //  This will return a monotonically increasing value.
115
  // MUST NOT be called from within a timer handler.
116
  Bit64u time_usec_sequential(void);
117
 
118
  //Register a timer handler to go off after a given interval.
119
  //Register a timer handler to go off with a periodic interval.
120
  int  register_timer(void *this_ptr, bx_timer_handler_t handler,
121
                         Bit32u useconds,
122
                         bx_bool continuous, bx_bool active, const char *id);
123
 
124
  //unregister a previously registered timer.
125
  bx_bool unregisterTimer(unsigned timerID);
126
 
127
  void start_timers(void);
128
 
129
  //activate a deactivated but registered timer.
130
  void activate_timer(unsigned timer_index, Bit32u useconds,
131
                         bx_bool continuous);
132
 
133
  //deactivate (but don't unregister) a currently registered timer.
134
  void deactivate_timer(unsigned timer_index);
135
 
136
 
137
  //Timer handler passed to pc_system
138
  static void pc_system_timer_handler(void* this_ptr);
139
 
140
  //The real timer handler.
141
  void timer_handler();
142
 
143
  //Initialization step #1 in constructor and for cleanup
144
  void setup(void);
145
 
146
  //Initialization step #2
147
  void init(void);
148
 
149
  void register_state(void);
150
 
151
  //Determine the real time elapsed during runtime config or between save and
152
  //restore.
153
  void set_realtime_delay(void);
154
};
155
 
156
BOCHSAPI extern bx_virt_timer_c bx_virt_timer;
157
 
158
#endif // _BX_VIRT_TIMER_H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.