00001 /* 00002 **************************************************************************** 00003 * 00004 * simulavr - A simulator for the Atmel AVR family of microcontrollers. 00005 * Copyright (C) 2001, 2002, 2003 Klaus Rudolph 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 **************************************************************************** 00022 * 00023 * $Id$ 00024 */ 00025 00026 #ifndef FLASH_H_INCLUDED 00027 #define FLASH_H_INCLUDED 00028 #include <string> 00029 #include <map> 00030 #include <vector> 00031 00032 #include "decoder.h" 00033 #include "memory.h" 00034 00035 class DecodedInstruction; 00036 00038 class AvrFlash: public Memory { 00039 00040 protected: 00041 AvrDevice *core; 00042 std::vector <DecodedInstruction*> DecodedMem; 00043 unsigned int rww_lock; 00044 bool flashLoaded; 00045 00046 friend int avr_op_CPSE::operator()(); 00047 friend int avr_op_SBIC::operator()(); 00048 friend int avr_op_SBIS::operator()(); 00049 friend int avr_op_SBRC::operator()(); 00050 friend int avr_op_SBRS::operator()(); 00051 00052 public: 00053 00054 AvrFlash(AvrDevice *c, int size); 00055 ~AvrFlash(); 00056 00057 void Decode(); 00060 void Decode(unsigned int addr); 00061 00065 void Decode(unsigned int addr, int secSize); 00066 00070 void WriteMem(unsigned char* src, unsigned int addr, unsigned int secSize); 00071 00073 void WriteMemByte(unsigned char val, unsigned int address); 00074 00076 bool IsProgramLoaded(void) { return flashLoaded; } 00077 00079 bool IsRWWLock(unsigned int addr) { return (addr < rww_lock);} 00080 00083 void SetRWWLock(unsigned int addr) { rww_lock = addr;} 00084 00086 DecodedInstruction* GetInstruction(unsigned int pc); 00087 00089 unsigned char ReadMemRaw(unsigned int addr) { return myMemory[addr]; } 00090 00092 unsigned char ReadMem(unsigned int addr); 00093 00095 unsigned int ReadMemRawWord(unsigned int addr) { return (myMemory[addr] << 8) + myMemory[addr + 1]; } 00096 00098 unsigned int ReadMemWord(unsigned int addr); 00099 00100 bool LooksLikeContextSwitch(unsigned int addr) const; 00101 }; 00102 00103 #endif