simulavr  1.1.0
avrdevice.h
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  ****************************************************************************
22  *
23  * $Id$
24  */
25 
26 #ifndef AVRDEVICE
27 #define AVRDEVICE
28 
29 #include <string>
30 #include <map>
31 #include <vector>
32 #include <algorithm>
33 #include <types.h> // for dword
34 
35 #include "systemclocktypes.h"
36 #include "simulationmember.h"
37 #include "pin.h"
38 #include "net.h"
39 #include "traceval.h"
40 #include "flashprog.h"
41 
42 // transfered from global.h
43 #define BREAK_POINT -2
44 #define INVALID_OPCODE -1
45 
46 // transfered from breakpoint.h
47 class Breakpoints: public std::vector<dword> { };
48 class Exitpoints: public std::vector<dword> { };
49 
50 // from hwsreg.h, but not included, because of circular include with this header
51 class HWSreg;
52 class RWSreg;
53 
54 class AvrFlash;
55 class HWEeprom;
56 class HWStack;
57 class HWWado;
58 class Data;
59 class HWIrqSystem;
60 class RWMemoryMember;
61 class Hardware;
62 class DumpManager;
64 
67 
68  private:
70  const unsigned int ioSpaceSize;
71  static const unsigned int totalIoSpace;
72  static const unsigned int registerSpaceSize;
73  const unsigned int iRamSize;
74  const unsigned int eRamSize;
75  unsigned int devSignature;
76  std::string devName;
77 
78  friend class DumpManager;
79  void detachDumpManager() { dumpManager = NULL; }
80 
81  protected:
83  std::map < std::string, Pin *> allPins;
84  std::string actualFilename;
85 
87  int cpuCycles;
88 
89  public:
90  int trace_on;
93  unsigned int PC;
94  unsigned int cPC;
96  const unsigned int PC_size;
97  unsigned int dataAddressMask;
109  bool deferIrq;
110  unsigned int newIrqPc;
111  unsigned int actualIrqVector;
114 
123  bool flagTiny10;
124  bool flagTiny1x;
125  bool flagXMega;
126  int DebugRecentJumps[20];
128 
130 
135 
136  std::vector<Hardware *> hwResetList;
137  std::vector<Hardware *> hwCycleList;
138 
140 
141  AvrDevice(unsigned int ioSpaceSize, unsigned int IRamSize, unsigned int ERamSize, unsigned int flashSize, unsigned int pcSize = 2);
142  virtual ~AvrDevice();
143 
146  void AddToResetList(Hardware *hw);
147 
150  void AddToCycleList(Hardware *hw);
151 
153 
154  void RemoveFromCycleList(Hardware *hw);
155 
156  void Load(const char* n);
157  void ReplaceIoRegister(unsigned int offset, RWMemoryMember *);
158  bool ReplaceMemRegister(unsigned int offset, RWMemoryMember *);
159  RWMemoryMember *GetMemRegisterInstance(unsigned int offset);
160  void RegisterTerminationSymbol(const char *symbol);
161 
162  Pin *GetPin(const char *name);
166  int Step(bool &untilCoreStepFinished, SystemClockOffset *nextStepIn_ns =0);
167  void Reset();
168  void SetClockFreq(SystemClockOffset f);
169  SystemClockOffset GetClockFreq();
170 
171  void RegisterPin(const std::string &name, Pin *p) {
172  allPins.insert(std::pair<std::string, Pin*>(name, p));
173  }
174 
176  void DeleteAllBreakpoints(void);
177 
179  const std::string &GetFname(void) { return actualFilename; }
181  const std::string &GetDeviceName(void) { return devName; }
183  unsigned int GetDeviceSignature(void) { return devSignature; }
185  void SetDeviceNameAndSignature(const std::string &name, unsigned int signature);
186 
188  unsigned int GetMemTotalSize(void) { return totalIoSpace; }
190  unsigned int GetMemIOSize(void) { return ioSpaceSize; }
192  unsigned int GetMemRegisterSize(void) { return registerSpaceSize; }
194  unsigned int GetMemIRamSize(void) { return iRamSize; }
196  unsigned int GetMemERamSize(void) { return eRamSize; }
197 
199  unsigned char GetRWMem(unsigned addr);
201  bool SetRWMem(unsigned addr, unsigned char val);
203  unsigned char GetCoreReg(unsigned addr);
205  bool SetCoreReg(unsigned addr, unsigned char val);
207  unsigned char GetIOReg(unsigned addr);
209  bool SetIOReg(unsigned addr, unsigned char val);
211  bool SetIORegBit(unsigned addr, unsigned bitaddr);
213  bool ClearIORegBit(unsigned addr, unsigned bitaddr);
214 
216  unsigned GetRegX(void);
218  unsigned GetRegY(void);
220  unsigned GetRegZ(void);
221 
223  void DebugOnJump();
224 
225  friend void ELFLoad(const AvrDevice * core);
226 
227 };
228 
229 #endif
AvrFlash * Flash
Definition: avrdevice.h:98
SystemClockOffset clockFreq
Period of a tick (1/F_OSC) in [ns].
Definition: avrdevice.h:82
DumpManager * dumpManager
Definition: avrdevice.h:139
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
void ELFLoad(const AvrDevice *core)
Definition: avrreadelf.cpp:38
unsigned int GetMemERamSize(void)
Get configured external RAM size.
Definition: avrdevice.h:196
bool flagEIJMPInstructions
EICALL and EIJMP instructions are available (only on some devices with bigger flash) ...
Definition: avrdevice.h:118
const unsigned int ioSpaceSize
Definition: avrdevice.h:70
AvrFuses * fuses
Definition: avrdevice.h:100
const unsigned int eRamSize
Definition: avrdevice.h:74
AddressExtensionRegister * rampz
RAMPZ address extension register.
Definition: avrdevice.h:105
unsigned int GetMemIRamSize(void)
Get configured internal RAM size.
Definition: avrdevice.h:194
Pin class, handles input and output to external parts.
Definition: pin.h:98
HWIrqSystem * irqSystem
Definition: avrdevice.h:104
std::vector< Hardware * > hwResetList
Definition: avrdevice.h:136
unsigned int dataAddressMask
which bits in address are significant
Definition: avrdevice.h:97
bool flagJMPInstructions
CALL and JMP instructions are available (only on devices with bigger flash)
Definition: avrdevice.h:116
Holds AVR flash content and symbol informations.
Definition: flash.h:38
bool flagTiny10
core is a tiny4/5/9/10, change used clocks on some instructions and disables instructions ...
Definition: avrdevice.h:123
std::string actualFilename
Definition: avrdevice.h:84
Definition: hwwado.h:38
void RegisterPin(const std::string &name, Pin *p)
Definition: avrdevice.h:171
bool flagIJMPInstructions
ICALL and IJMP instructions are available (not on attiny1x devices)
Definition: avrdevice.h:117
bool flagLPMInstructions
LPM and SPM instructions are available (not on some tiny devices)
Definition: avrdevice.h:119
friend class AvrDevice
Definition: traceval.h:402
Implements a stack register with stack logic.
Definition: hwstack.h:91
Definition: hwsreg.h:52
Definition: hwsreg.h:65
const std::string & GetDeviceName(void)
Return device name.
Definition: avrdevice.h:181
const unsigned int PC_size
Definition: avrdevice.h:96
HWSreg * status
the status register itself
Definition: avrdevice.h:132
int cpuCycles
Count of cycles before next instruction is executed (i.e. countdown)
Definition: avrdevice.h:87
static void Reset(void)
Reset DumpManager instance (e.g. delete available instance)
Definition: traceval.cpp:573
unsigned int GetDeviceSignature(void)
Return device signature.
Definition: avrdevice.h:183
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
Breakpoints BP
Definition: avrdevice.h:91
TraceValueCoreRegister coreTraceGroup
Definition: avrdevice.h:108
static const unsigned int registerSpaceSize
Definition: avrdevice.h:72
bool abortOnInvalidAccess
Flag, that simulation abort if an invalid access occured, default is false.
Definition: avrdevice.h:107
bool flagIWInstructions
ADIW and SBIW instructions are available (not on most tiny&#39;s!)
Definition: avrdevice.h:115
bool flagTiny1x
core is a tiny1x (but not tiny10!), change used clocks on some instructions and disables instructions...
Definition: avrdevice.h:124
bool flagMULInstructions
(F)MULxx instructions are available
Definition: avrdevice.h:121
RWMemoryMember ** invalidRW
hold invalid RW memory cells created by device
Definition: avrdevice.h:69
Member of any memory area in an AVR device.
Definition: rwmem.h:42
unsigned int GetMemIOSize(void)
Get configured IO memory space size.
Definition: avrdevice.h:190
Data * data
a hack for symbol look-up
Definition: avrdevice.h:103
bool flagXMega
core is a XMEGA device, change used clocks on some instructions
Definition: avrdevice.h:125
long long SystemClockOffset
std::vector< Hardware * > hwCycleList
Definition: avrdevice.h:137
const std::string & GetFname(void)
Return filename from loaded program.
Definition: avrdevice.h:179
std::string devName
hold the device name, which this core simulate
Definition: avrdevice.h:76
Support for fuse bits.
Definition: flashprog.h:100
std::map< std::string, Pin * > allPins
Definition: avrdevice.h:83
HWEeprom * eeprom
Definition: avrdevice.h:102
void detachDumpManager()
Definition: avrdevice.h:79
unsigned int GetMemTotalSize(void)
Get configured total memory space size.
Definition: avrdevice.h:188
unsigned int actualIrqVector
Definition: avrdevice.h:111
RWMemoryMember ** rw
The whole memory: R0-R31, IO, Internal RAM.
Definition: avrdevice.h:129
Pin v_supply
represents supply voltage level, needed for analog peripherals
Definition: avrdevice.h:112
bool deferIrq
Almost always false.
Definition: avrdevice.h:109
const unsigned int iRamSize
Definition: avrdevice.h:73
unsigned int GetMemRegisterSize(void)
Get configured register space size.
Definition: avrdevice.h:192
Provides the programming engine for flash self programming.
Definition: flashprog.h:38
Pin v_bandgap
represents bandgap (ref) voltage level, needed for analog peripherals
Definition: avrdevice.h:113
int trace_on
Definition: avrdevice.h:90
unsigned int devSignature
hold the device signature for this core
Definition: avrdevice.h:75
HWStack * stack
Definition: avrdevice.h:131
RWSreg * statusRegister
the memory interface for status
Definition: avrdevice.h:133
Hold data memory block and symbol informations.
Definition: memory.h:95
unsigned int PC
Definition: avrdevice.h:93
HWWado * wado
WDT timer.
Definition: avrdevice.h:134
AddressExtensionRegister * eind
EIND address extension register.
Definition: avrdevice.h:106
FlashProgramming * spmRegister
Definition: avrdevice.h:99
bool flagMOVWInstruction
MOVW instruction is available.
Definition: avrdevice.h:122
static const unsigned int totalIoSpace
Definition: avrdevice.h:71
AvrLockBits * lockbits
Definition: avrdevice.h:101
Support for lock bits.
Definition: flashprog.h:138
unsigned int newIrqPc
Definition: avrdevice.h:110
int DebugRecentJumpsIndex
Index to address of the most recent jump.
Definition: avrdevice.h:127
Exitpoints EP
Definition: avrdevice.h:92
bool flagELPMInstructions
ELPM instructions are available (only on devices with bigger flash)
Definition: avrdevice.h:120