simulavr  1.1.0
AvrFlash Class Reference

Holds AVR flash content and symbol informations. More...

#include <flash.h>

Inheritance diagram for AvrFlash:

Public Member Functions

 AvrFlash (AvrDevice *c, int size)
 
 ~AvrFlash ()
 
void Decode ()
 
void Decode (unsigned int addr)
 
void Decode (unsigned int addr, int secSize)
 
void WriteMem (const unsigned char *src, unsigned int addr, unsigned int secSize)
 
void WriteMemByte (unsigned char val, unsigned int address)
 
bool IsProgramLoaded (void)
 
bool IsRWWLock (unsigned int addr)
 
void SetRWWLock (unsigned int addr)
 
DecodedInstructionGetInstruction (unsigned int pc)
 
unsigned char ReadMemRaw (unsigned int addr)
 
unsigned char ReadMem (unsigned int addr)
 
unsigned int ReadMemRawWord (unsigned int addr)
 
unsigned int ReadMemWord (unsigned int addr)
 
bool LooksLikeContextSwitch (unsigned int addr) const
 
- Public Member Functions inherited from Memory
 Memory (int size)
 
virtual ~Memory ()
 
std::string GetSymbolAtAddress (unsigned int add)
 
unsigned int GetAddressAtSymbol (const std::string &s)
 
void AddSymbol (std::pair< unsigned int, std::string > p)
 
unsigned int GetSize ()
 

Protected Attributes

AvrDevicecore
 
std::vector< DecodedInstruction * > DecodedMem
 
unsigned int rww_lock
 When Flash write is in progress then addresses below this are inaccesible, otherwise 0. More...
 
bool flashLoaded
 Flag, true if there was a write to Flash after constructor call (program load) More...
 
- Protected Attributes inherited from Memory
unsigned int size
 

Friends

int avr_op_CPSE::operator() ()
 
int avr_op_SBIC::operator() ()
 
int avr_op_SBIS::operator() ()
 
int avr_op_SBRC::operator() ()
 
int avr_op_SBRS::operator() ()
 

Additional Inherited Members

- Public Attributes inherited from Memory
unsigned char * myMemory
 
std::multimap< unsigned int, std::string > sym
 

Detailed Description

Holds AVR flash content and symbol informations.

Definition at line 38 of file flash.h.

Constructor & Destructor Documentation

◆ AvrFlash()

AvrFlash::AvrFlash ( AvrDevice c,
int  size 
)

Definition at line 43 of file flash.cpp.

References Decode(), Memory::myMemory, rww_lock, and Memory::size.

◆ ~AvrFlash()

AvrFlash::~AvrFlash ( )

Definition at line 55 of file flash.cpp.

References DecodedMem, and Memory::size.

Member Function Documentation

◆ Decode() [1/3]

void AvrFlash::Decode ( )

Decode/create all instructions

Definition at line 38 of file flash.cpp.

References Memory::size.

Referenced by AvrFlash(), Decode(), and WriteMem().

◆ Decode() [2/3]

void AvrFlash::Decode ( unsigned int  addr)

Decode/create instruction at address 'addr'.

Definition at line 109 of file flash.cpp.

References core, DecodedMem, lookup_opcode(), Memory::myMemory, and Memory::size.

◆ Decode() [3/3]

void AvrFlash::Decode ( unsigned int  addr,
int  secSize 
)

Decode memory block with offset and size

Parameters
offsetdata offset in memory block, beginning from start of THIS memory block!
secSizecount of available data (bytes) in src

Definition at line 104 of file flash.cpp.

References Decode().

◆ GetInstruction()

DecodedInstruction * AvrFlash::GetInstruction ( unsigned int  pc)

Returns instruction at pointer PC. Aborts if Flash write is in progress.

Definition at line 80 of file flash.cpp.

References avr_error, DecodedMem, and IsRWWLock().

Referenced by SetRWWLock(), and AvrDevice::Step().

◆ IsProgramLoaded()

bool AvrFlash::IsProgramLoaded ( void  )
inline

True if flash was written, i.e. a program was loaded

Definition at line 76 of file flash.h.

References flashLoaded.

◆ IsRWWLock()

bool AvrFlash::IsRWWLock ( unsigned int  addr)
inline

True if simulated Flash write is in progress and the address is in locked area.

Definition at line 79 of file flash.h.

Referenced by GetInstruction(), ReadMem(), and ReadMemWord().

◆ LooksLikeContextSwitch()

bool AvrFlash::LooksLikeContextSwitch ( unsigned int  addr) const

Returns true if insn at address index*2 looks like switching thread stacks (heuristics).

Any switch contains "out SP?,r??" insn. We return false for any other. Problematic uses of "out SP?,r??" that are not a switch:

  • prologue with frame pointer (sbiw, sbci, subi)
  • epilogue with frame pointer (adiw)
  • SP initialization after reset (ldi)
  • -mcall-prologues functions (sub, sbc, add, adc)
  • kernels like AvrX and DTRTK which switch stacks in two phases We analyze few preceding instructions in hope to rule out these cases. (GDB's weak prologue analysis is doctored elsewhere.)

Definition at line 131 of file flash.cpp.

References DecodedMem, DecodedInstruction::GetModifiedR(), DecodedInstruction::GetModifiedRHi(), avr_op_OUT::ioreg, avr_op_OUT::R1, and Memory::size.

Referenced by ThreadList::OnSPWrite(), and ReadMemRawWord().

◆ ReadMem()

unsigned char AvrFlash::ReadMem ( unsigned int  addr)

Returns byte at flash address. Aborts if Flash write is in progress.

Definition at line 86 of file flash.cpp.

References avr_warning, IsRWWLock(), and Memory::myMemory.

Referenced by avr_op_ELPM_Z::operator()(), avr_op_ELPM_Z_incr::operator()(), avr_op_ELPM::operator()(), avr_op_LPM_Z::operator()(), avr_op_LPM::operator()(), avr_op_LPM_Z_incr::operator()(), and ReadMemRaw().

◆ ReadMemRaw()

unsigned char AvrFlash::ReadMemRaw ( unsigned int  addr)
inline

Returns byte at flash address. Works even during flash writing.

Definition at line 89 of file flash.h.

References Memory::myMemory, and ReadMem().

◆ ReadMemRawWord()

unsigned int AvrFlash::ReadMemRawWord ( unsigned int  addr)
inline

Returns 16bits at flash address. Works even during flash writing.

Definition at line 95 of file flash.h.

References LooksLikeContextSwitch(), Memory::myMemory, and ReadMemWord().

◆ ReadMemWord()

unsigned int AvrFlash::ReadMemWord ( unsigned int  addr)

Returns 16bits at flash address. Aborts if Flash write is in progress.

Definition at line 94 of file flash.cpp.

References avr_warning, IsRWWLock(), Memory::myMemory, and Memory::size.

Referenced by avr_op_CALL::operator()(), avr_op_JMP::operator()(), avr_op_LDS::operator()(), avr_op_STS::operator()(), and ReadMemRawWord().

◆ SetRWWLock()

void AvrFlash::SetRWWLock ( unsigned int  addr)
inline

Sets/Resets RWW lock address

Parameters
addraddress, below flash is locked, 0 to disable lock

Definition at line 83 of file flash.h.

References GetInstruction().

Referenced by FlashProgramming::SetRWWLock(), and FlashProgramming::SPM_action().

◆ WriteMem()

void AvrFlash::WriteMem ( const unsigned char *  src,
unsigned int  addr,
unsigned int  secSize 
)
virtual

Write `secSize' bytes from `src' data to byte address `addr'.

Parameters
srcbinary c-string with data to write in
secSizecount of available data (bytes) in src

Implements Memory.

Definition at line 62 of file flash.cpp.

References Decode(), flashLoaded, Memory::myMemory, and Memory::size.

Referenced by ELFLoad(), and FlashProgramming::SPM_action().

◆ WriteMemByte()

void AvrFlash::WriteMemByte ( unsigned char  val,
unsigned int  address 
)

Write byte `val' at `address' (in bytes). Caller must call Decode() later.

Definition at line 74 of file flash.cpp.

References flashLoaded, Memory::myMemory, and Memory::size.

Friends And Related Function Documentation

◆ avr_op_CPSE::operator()

int avr_op_CPSE::operator() ( )
friend

◆ avr_op_SBIC::operator()

int avr_op_SBIC::operator() ( )
friend

◆ avr_op_SBIS::operator()

int avr_op_SBIS::operator() ( )
friend

◆ avr_op_SBRC::operator()

int avr_op_SBRC::operator() ( )
friend

◆ avr_op_SBRS::operator()

int avr_op_SBRS::operator() ( )
friend

Member Data Documentation

◆ core

AvrDevice* AvrFlash::core
protected

Definition at line 41 of file flash.h.

Referenced by Decode().

◆ DecodedMem

◆ flashLoaded

bool AvrFlash::flashLoaded
protected

Flag, true if there was a write to Flash after constructor call (program load)

Definition at line 44 of file flash.h.

Referenced by IsProgramLoaded(), WriteMem(), and WriteMemByte().

◆ rww_lock

unsigned int AvrFlash::rww_lock
protected

When Flash write is in progress then addresses below this are inaccesible, otherwise 0.

Definition at line 43 of file flash.h.

Referenced by AvrFlash().


The documentation for this class was generated from the following files: