/usr/include/gpsim/gpsim_time.h is in gpsim-dev 0.27.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | /*
Copyright (C) 1998-2000 T. Scott Dattalo
This file is part of the libgpsim library of gpsim
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.1 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, see
<http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
#ifndef __GPSIM_TIME_H__
#define __GPSIM_TIME_H__
#include "breakpoints.h"
#include "exports.h"
//---------------------------------------------------------
// Cycle Counter
//
// The cycle counter class is used to coordinate the timing
// between the different peripherals within a processor and
// in some cases, the timing between several simulated processors
// and modules.
//
// The smallest quantum of simulated time is called a 'cycle'.
// The simuluation engine increments a 'Cycle Counter' at quantum
// simulation step. Simulation objects that wished to be notified
// at a specific instance in time can set a cycle counter break
// point that will get invoked whenever the cycle counter reaches
// that instance.
//------------------------------------------------------------
//
// Cycle counter breakpoint list
//
// This is a friend class to the Cycle Counter class. Its purpose
// is to maintain a doubly linked list of cycle counter break
// points.
class Cycle_Counter_breakpoint_list
{
public:
// This is the value compared to the cycle counter.
guint64 break_value;
// True when this break is active.
bool bActive;
// The breakpoint_number is a number uniquely identifying this
// cycle counter break point. Note, this number is used only
// when the break point was assigned by a user
unsigned int breakpoint_number;
// If non-null, the TriggerObject will point to an object that will get invoked
// when the breakpoint is encountered.
TriggerObject *f;
// Doubly-linked list mechanics..
// (these will be made private eventually)
Cycle_Counter_breakpoint_list *next;
Cycle_Counter_breakpoint_list *prev;
Cycle_Counter_breakpoint_list *getNext();
Cycle_Counter_breakpoint_list *getPrev();
void clear();
void invoke();
};
class Cycle_Counter
{
public:
#define BREAK_ARRAY_SIZE 32
#define BREAK_ARRAY_MASK (BREAK_ARRAY_SIZE -1)
// Largest cycle counter value
static const guint64 END_OF_TIME=0xFFFFFFFFFFFFFFFFULL;
bool reassigned; // Set true when a break point is reassigned (or deleted)
Cycle_Counter_breakpoint_list
active, // Head of the active breakpoint linked list
inactive; // Head of the inactive one.
bool bSynchronous; // a flag that's true when the time per counter tick is constant
Cycle_Counter();
void preset(guint64 new_value); // not used currently.
/*
increment - This inline member function is called once or
twice for every simulated instruction. Its purpose is to
increment the cycle counter using roll over arithmetic.
If there's a breakpoint set on the new value of the cycle
counter then the simulation is either stopped or a callback
function is invoked. In either case, the break point is
cleared.
*/
inline void increment()
{
// This has been changed so the cycle counter (value)
// is incremented after processing breakpoints
// Increment the current cycle then check if
// we have a break point set here
if(value == break_on_this)
breakpoint();
value++;
// Note that it's really inefficient to trace every cycle increment.
// Instead, we implicitly trace the increments with the instruction traces.
}
/*
advance the Cycle Counter by more than one instruction quantum.
This is almost identical to the increment() function except that
we allow the counter to be advanced by an arbitrary amount.
They're separated only for efficiency reasons. This one runs slower.
*/
inline void advance(guint64 step)
{
while (step--) {
if (value == break_on_this)
breakpoint();
}
value++;
}
// Return the current cycle counter value
guint64 get()
{
return value;
}
// Return the cycle counter for some time off in the future:
guint64 get(double future_time_from_now);
bool set_break(guint64 future_cycle,
TriggerObject *f=0, unsigned int abp = MAX_BREAKPOINTS);
bool set_break_delta(guint64 future_cycle,
TriggerObject *f=0, unsigned int abp = MAX_BREAKPOINTS);
bool reassign_break(guint64 old_cycle,guint64 future_cycle, TriggerObject *f=0);
void clear_current_break(TriggerObject *f=0);
void dump_breakpoints();
void clear_break(guint64 at_cycle);
void clear_break(TriggerObject *f);
void set_instruction_cps(guint64 cps);
double instruction_cps() { return m_instruction_cps; }
double seconds_per_cycle() { return m_seconds_per_cycle; }
private:
// The number of instruction cycles that correspond to one second
double m_instruction_cps;
double m_seconds_per_cycle;
guint64 value; // Current value of the cycle counter.
guint64 break_on_this; // If there's a pending cycle break point, then it'll be this
/*
breakpoint
when the member function "increment()" encounters a break point,
breakpoint() is called.
*/
void breakpoint();
};
#if defined(IN_MODULE) && defined(_WIN32)
// we are in a module: don't access cycles object directly!
LIBGPSIM_EXPORT Cycle_Counter &get_cycles();
#else
// we are in gpsim: use of get_cycles() is recommended,
// even if cycles object can be accessed directly.
extern Cycle_Counter cycles;
inline Cycle_Counter &get_cycles()
{
return cycles;
}
#endif
/// The stopwatch object is used to keep track of the amount of
/// time between events. It can be controlled either through the
/// class API or through its attributes
class StopWatch : public TriggerObject
{
public:
StopWatch();
~StopWatch();
guint64 get();
double get_time();
void set_enable(bool);
void set_direction(bool);
void set_rollover(guint64);
void set_value(guint64);
void set_break(bool);
void update();
virtual void callback();
virtual void callback_print();
private:
Integer *value;
Integer *rollover;
Boolean *enable;
Boolean *direction;
bool count_dir;
guint64 offset;
guint64 break_cycle;
};
extern StopWatch *stop_watch;
#endif
|