/usr/include/gpsim/registers.h is in gpsim-dev 0.29.0-1.
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | /*
Copyright (C) 1998-2003 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 __REGISTERS_H__
#define __REGISTERS_H__
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <glib.h>
class symbol;
class XrefObject;
class Processor;
class Module;
#include "gpsim_classes.h"
#include "value.h"
#include "ValueCollections.h"
#include "clock_phase.h"
#define AN_INVALID_ADDRESS 0xffffffff
//---------------------------------------------------------
// RegisterValue class
//
// This class is used to represent the value of registers.
// It also defines which bits have been initialized and which
// are valid.
//
class RegisterValue
{
public:
unsigned int data; // The actual numeric value of the register.
unsigned int init; // bit mask of initialized bits.
RegisterValue()
{
data = 0;
init = 0xff; // assume 8-bit wide, uninitialized registers
}
RegisterValue(unsigned int d, unsigned int i) :
data(d), init(i)
{
}
RegisterValue(const RegisterValue &value) :
data(value.data), init(value.init)
{
}
inline bool initialized()
{
return init == 0;
}
inline unsigned int get()
{
return data;
}
inline void put(unsigned int d)
{
data = d;
}
inline void put(unsigned int d, unsigned int i)
{
data = d;
init = i;
}
inline unsigned int geti()
{
return init;
}
inline void puti(unsigned int i)
{
init = i;
}
inline void operator = (RegisterValue rv)
{
data = rv.data;
init = rv.init;
}
inline operator unsigned int ()
{
return data;
}
inline operator int ()
{
return (int)data;
}
bool operator == (const RegisterValue &rv) const {
return data == rv.data && init == rv.init;
}
bool operator != (const RegisterValue &rv) const {
return data != rv.data || init != rv.init;
}
void operator >>= (unsigned int val) {
data >>= val;
init >>= val;
}
char * toString(char *str, int len, int regsize=2) const;
char * toBitStr(char *s, int len, unsigned int BitPos,
const char *ByteSeparator="_",
const char *HiBitNames=0,
const char *LoBitNames=0,
const char *UndefBitNames=0) const;
};
//---------------------------------------------------------
/// Register - base class for gpsim registers.
/// The Register class is used by processors and modules to
/// to create memory maps and special function registers.
///
class Register : public Value
{
public:
enum REGISTER_TYPES
{
INVALID_REGISTER,
GENERIC_REGISTER,
FILE_REGISTER,
SFR_REGISTER,
BP_REGISTER
};
RegisterValue value;
unsigned int address;
// If non-zero, the alias_mask describes all address at which
// this file register appears. The assumption (that is true so
// far for all pic architectures) is that the aliased register
// locations differ by one bit. For example, the status register
// appears at addresses 0x03 and 0x83 in the 14-bit core.
// Consequently, alias_mask = 0x80 and address (above) is equal
// to 0x03.
unsigned int alias_mask;
RegisterValue por_value; // power on reset value
unsigned int mValidBits; // = 255 for 8-bit registers, = 65535 for 16-bit registers.
// The read_trace and write_trace variables are used while
// tracing register reads and writes. Essentially, these are
// the trace commands.
RegisterValue write_trace;
RegisterValue read_trace;
// The trace_state is used to reconstruct the state of the
// register while traversing a trace buffer.
RegisterValue trace_state;
guint64 read_access_count;
guint64 write_access_count;
public:
Register(Module *, const char *pName, const char *pDesc=0);
virtual ~Register();
virtual int set_break(ObjectBreakTypes bt=eBreakAny, ObjectActionTypes at=eActionHalt, Expression *expr=0);
virtual int clear_break();
/// get - method for accessing the register's contents.
virtual unsigned int get();
/// put - method for writing a new value to the register.
virtual void put(unsigned int new_value);
/// put_value - is the same as put(), but some extra stuff like
/// interfacing to the gui is done. (It's more efficient than
/// burdening the run time performance with (unnecessary) gui
/// calls.)
virtual void put_value(unsigned int new_value);
/// get_value - same as get(), but no trace is performed
virtual unsigned int get_value() { return(value.get()); }
/// getRV - get the whole register value - including the info
/// of the three-state bits.
virtual RegisterValue getRV()
{
value.data = get();
return value;
}
/// putRV - write a new value to the register.
/// \deprecated {use SimPutAsRegisterValue()}
///
virtual void putRV(RegisterValue rv)
{
value.init = rv.init;
put(rv.data);
}
/// getRV_notrace and putRV_notrace are analogous to getRV and putRV
/// except that the action (in the derived classes) will not be
/// traced. The primary reason for this is to allow the gui to
/// refresh it's windows without having the side effect of filling
/// up the trace buffer
virtual RegisterValue getRV_notrace()
{
value.data = value.get();
return value;
}
virtual void putRV_notrace(RegisterValue rv)
{
value.init = rv.init;
put_value(rv.data);
}
virtual RegisterValue getRVN()
{
return getRVN_notrace();
}
virtual RegisterValue getRVN_notrace()
{
return getRV_notrace();
}
/// set --- cast another Value object type into a register type
/// this is used primarily by expression and stimuli processing
/// (the put() methods are used by the processors).
/// FIXME -- consolidate the get, set, and put methods
virtual void set(Value *);
/// copy --- This is used during expression parsing.
virtual Value *copy();
/// get(gint64 &i) --- ugh.
virtual void get(gint64 &i);
virtual void initialize()
{
}
/// get3StateBit - returns the 3-state value of a bit
/// if a bit is known then a '1' or '0' is returned else,
/// a '?' is returned. No check is performed to ensure
/// that only a single bit is checked, thus it's possible
/// to get the state of a group of bits using this method.
virtual char get3StateBit(unsigned int bitMask)
{
RegisterValue rv = getRV_notrace();
return (rv.init&bitMask) ? '?' : (rv.data&bitMask ? '1':'0');
}
/// In the Register class, the 'Register *get()' returns a
/// pointer to itself. Derived classes may return something
/// else (e.g. a break point may be pointing to the register
/// it replaced and will return that instead).
virtual Register *getReg()
{
return this;
}
virtual REGISTER_TYPES isa() {return GENERIC_REGISTER;};
virtual void reset(RESET_TYPE r) { return; };
/// The setbit function is not really intended for general purpose
/// registers. Instead, it is a place holder which is over-ridden
/// by the IO ports.
virtual void setbit(unsigned int bit_number, bool new_value);
/// like setbit, getbit is used mainly for breakpoints.
virtual bool get_bit(unsigned int bit_number);
virtual double get_bit_voltage(unsigned int bit_number);
/// Breakpoint objects will overload this function and return true.
virtual bool hasBreak()
{
return false;
}
/// register_size returns the number of bytes required to store the register
/// (this is used primarily by the gui to determine how wide to make text fields)
virtual unsigned int register_size () const;
/*
When the register is accessed, this action is recorded in the trace buffer.
Here we can specify the exact trace command to use.
*/
virtual void set_write_trace(RegisterValue &rv);
virtual void set_read_trace(RegisterValue &rv);
virtual void put_trace_state(RegisterValue rv)
{
trace_state = rv;
}
virtual RegisterValue get_trace_state()
{
return trace_state;
}
/*
convert value to a string:
*/
virtual char * toString(char *str, int len);
virtual char * toBitStr(char *s, int len);
virtual string &baseName()
{
return name_str;
}
virtual unsigned int getAddress()
{
return address;
}
virtual void setAddress(unsigned int addr)
{
address = addr;
}
Register *getReplaced() { return m_replaced; }
void setReplaced(Register *preg) { m_replaced = preg; }
virtual void new_name(string &);
virtual void new_name(const char *);
protected:
// A pointer to the register that this register replaces.
// This is used primarily by the breakpoint code.
Register *m_replaced;
};
//---------------------------------------------------------
// define a special 'invalid' register class. Accessess to
// to this class' value get 0
class InvalidRegister : public Register
{
public:
InvalidRegister(Processor *, const char *pName, const char *pDesc=0);
void put(unsigned int new_value);
unsigned int get();
virtual REGISTER_TYPES isa() {return INVALID_REGISTER;};
virtual Register *getReg() {return 0; }
};
//---------------------------------------------------------
// Base class for a special function register.
class BitSink;
class sfr_register : public Register
{
public:
sfr_register(Module *, const char *pName, const char *pDesc=0);
RegisterValue wdtr_value; // wdt or mclr reset value
virtual REGISTER_TYPES isa() {return SFR_REGISTER;};
virtual void initialize() {};
virtual void reset(RESET_TYPE r);
// The assign and release BitSink methods don't do anything
// unless derived classes redefine them. Their intent is to
// provide an interface to the BitSink design - a design that
// allows clients to be notified when bits change states.
virtual bool assignBitSink(unsigned int bitPosition, BitSink *) {return false;}
virtual bool releaseBitSink(unsigned int bitPosition, BitSink *) {return false;}
};
//---------------------------------------------------------
// Program Counter
//
class PCTraceType;
class Program_Counter : public Value
{
public:
unsigned int value; /* pc's current value */
unsigned int memory_size;
unsigned int pclath_mask; /* pclath confines PC to banks */
unsigned int instruction_phase;
unsigned int trace_state; /* used while reconstructing the trace history */
// Trace commands
unsigned int trace_increment;
unsigned int trace_branch;
unsigned int trace_skip;
unsigned int trace_other;
Program_Counter(const char *name, const char *desc, Module *pM);
~Program_Counter();
virtual void increment();
virtual void start_skip();
virtual void skip();
virtual void jump(unsigned int new_value);
virtual void interrupt(unsigned int new_value);
virtual void computed_goto(unsigned int new_value);
virtual void new_address(unsigned int new_value);
virtual void put_value(unsigned int new_value);
virtual unsigned int get_value()
{
return value;
}
virtual unsigned int get_PC() {
return value;
}
virtual void set_PC(unsigned int new_value) {
value = new_value;
this->update();
}
/// set --- cast another Value object type into a program counter register type
/// this is used primarily by expression and stimuli processing
/// (the put() methods are used by the processors).
/// FIXME -- consolidate the get, set, and put methods
virtual void set(Value *);
// initialize the dynamically allocated trace type
virtual void set_trace_command();
/// get_raw_value -- on the 16-bit cores, get_value is multiplied by 2
/// whereas get_raw_value isn't. The raw value of the program counter
/// is used as an index into the program memory.
virtual unsigned int get_raw_value()
{
return value;
}
virtual void set_phase(int phase)
{
instruction_phase = phase;
}
virtual int get_phase()
{
return instruction_phase;
}
void set_reset_address(unsigned int _reset_address)
{
reset_address = _reset_address;
}
unsigned int get_reset_address()
{
return reset_address;
}
void reset();
virtual unsigned int get_next();
virtual void put_trace_state(unsigned int ts)
{
trace_state = ts;
}
protected:
unsigned int reset_address; /* Value pc gets at reset */
PCTraceType *m_pPCTraceType;
};
// Used in the command prompt interface
class RegisterCollection : public IIndexedCollection
{
public:
RegisterCollection(Processor *pProcessor,
const char *collection_name,
Register **ppRegisters,
unsigned int uiSize);
~RegisterCollection();
virtual unsigned int GetSize();
virtual Value &GetAt(unsigned int uIndex, Value *pValue=0);
virtual void SetAt(unsigned int uIndex, Value *pValue);
virtual void ConsolidateValues(int &iColumnWidth,
vector<string> &aList,
vector<string> &aValue);
// virtual void SetAt(ExprList_t* pIndexers, Expression *pExpr);
virtual unsigned int GetLowerBound();
virtual unsigned int GetUpperBound();
private:
Processor * m_pProcessor;
Register ** m_ppRegisters;
unsigned int m_uSize;
Integer m_ReturnValue;
};
//------------------------------------------------------------------------
// BitSink
//
// A BitSink is an object that can direct bit changes in an SFR to some
// place where they're needed. The purpose is to abstract the interface
// between special bits and the various peripherals.
//
// A client wishing to be notified whenever an SFR bit changes states
// will create a BitSink object and pass its pointer to the SFR. The
// client will also tell the SFR which bit this applies to. Now, when
// the bit changes states in the SFR, the SFR will call the setSink()
// method.
class BitSink
{
public:
virtual ~BitSink()
{
}
virtual void setSink(bool) = 0;
};
#endif // __REGISTERS__
|