simulavr  1.1.0
flash.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 FLASH_H_INCLUDED
27 #define FLASH_H_INCLUDED
28 #include <string>
29 #include <map>
30 #include <vector>
31 
32 #include "decoder.h"
33 #include "memory.h"
34 
35 class DecodedInstruction;
36 
38 class AvrFlash: public Memory {
39 
40  protected:
42  std::vector <DecodedInstruction*> DecodedMem;
43  unsigned int rww_lock;
44  bool flashLoaded;
45 
46  friend int avr_op_CPSE::operator()();
47  friend int avr_op_SBIC::operator()();
48  friend int avr_op_SBIS::operator()();
49  friend int avr_op_SBRC::operator()();
50  friend int avr_op_SBRS::operator()();
51 
52  public:
53 
54  AvrFlash(AvrDevice *c, int size);
55  ~AvrFlash();
56 
57  void Decode();
60  void Decode(unsigned int addr);
61 
65  void Decode(unsigned int addr, int secSize);
66 
70  void WriteMem(const unsigned char* src, unsigned int addr, unsigned int secSize);
71 
73  void WriteMemByte(unsigned char val, unsigned int address);
74 
76  bool IsProgramLoaded(void) { return flashLoaded; }
77 
79  bool IsRWWLock(unsigned int addr) { return (addr < rww_lock);}
80 
83  void SetRWWLock(unsigned int addr) { rww_lock = addr;}
84 
86  DecodedInstruction* GetInstruction(unsigned int pc);
87 
89  unsigned char ReadMemRaw(unsigned int addr) { return myMemory[addr]; }
90 
92  unsigned char ReadMem(unsigned int addr);
93 
95  unsigned int ReadMemRawWord(unsigned int addr) { return (myMemory[addr] << 8) + myMemory[addr + 1]; }
96 
98  unsigned int ReadMemWord(unsigned int addr);
99 
100  bool LooksLikeContextSwitch(unsigned int addr) const;
101 };
102 
103 #endif
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
unsigned char * myMemory
Definition: memory.h:45
unsigned int ReadMemWord(unsigned int addr)
Definition: flash.cpp:94
void WriteMem(const unsigned char *src, unsigned int addr, unsigned int secSize)
Definition: flash.cpp:62
Holds AVR flash content and symbol informations.
Definition: flash.h:38
int operator()()
Performs instruction.
Definition: decoder.cpp:1349
AvrFlash(AvrDevice *c, int size)
Definition: flash.cpp:43
void WriteMemByte(unsigned char val, unsigned int address)
Definition: flash.cpp:74
int operator()()
Performs instruction.
Definition: decoder.cpp:466
unsigned char ReadMemRaw(unsigned int addr)
Definition: flash.h:89
AvrDevice * core
Definition: flash.h:41
unsigned int ReadMemRawWord(unsigned int addr)
Definition: flash.h:95
std::vector< DecodedInstruction * > DecodedMem
Definition: flash.h:42
bool flashLoaded
Flag, true if there was a write to Flash after constructor call (program load)
Definition: flash.h:44
DecodedInstruction * GetInstruction(unsigned int pc)
Definition: flash.cpp:80
void SetRWWLock(unsigned int addr)
Definition: flash.h:83
unsigned int rww_lock
When Flash write is in progress then addresses below this are inaccesible, otherwise 0...
Definition: flash.h:43
bool IsRWWLock(unsigned int addr)
Definition: flash.h:79
~AvrFlash()
Definition: flash.cpp:55
int operator()()
Performs instruction.
Definition: decoder.cpp:1456
int operator()()
Performs instruction.
Definition: decoder.cpp:1433
Base class of core instruction.
Definition: decoder.h:39
unsigned int size
Definition: memory.h:41
bool LooksLikeContextSwitch(unsigned int addr) const
Definition: flash.cpp:131
void Decode()
Definition: flash.cpp:38
unsigned char ReadMem(unsigned int addr)
Definition: flash.cpp:86
Hold a memory block and symbol informations.
Definition: memory.h:38
bool IsProgramLoaded(void)
Definition: flash.h:76
int operator()()
Performs instruction.
Definition: decoder.cpp:1375