simulavr  1.1.0
hwstack.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 HWSTACK
27 #define HWSTACK
28 
29 #include "rwmem.h"
30 #include "funktor.h"
31 #include "avrdevice.h"
32 #include "traceval.h"
33 
34 #include <map>
35 
40 class Thread
41 {
42 public:
44  int m_sp;
45  int m_ip;
46  bool m_alive;
49  unsigned char registers[32];
51 };
52 
57 {
59  std::vector<Thread*> m_threads;
60  enum {eNormal, eReaded, eWritten, eWritten2} m_phase_of_switch;
65  int m_cur_thread;
68 
69  ThreadList& operator=(const ThreadList&); // not assignable
70 public:
71 
72  ThreadList(AvrDevice & core);
73  ~ThreadList();
74  void OnReset();
75  void OnCall();
76  void OnSPRead(int SP_value);
77  void OnSPWrite(int new_SP);
78  void OnPush();
79  void OnPop();
80  int GetThreadBySP(int SP) const;
81 
82  int GetCurrentThreadForGDB() const;
83  const Thread * GetThreadFromGDB(int thread_id) const;
84  bool IsGDBThreadAlive(int thread_id) const;
85  unsigned int GetCount() const;
86 };
87 
89 
91 class HWStack {
92 
93  protected:
95  uint32_t stackPointer;
96  uint32_t lowestStackPointer;
97  std::multimap<unsigned long, Funktor*> returnPointList;
98 
100  void CheckReturnPoints();
101 
102  public:
104  HWStack(AvrDevice *core);
106  virtual ~HWStack();
107 
108  virtual void Push(unsigned char val)=0;
109  virtual unsigned char Pop()=0;
110  virtual void PushAddr(unsigned long addr)=0;
111  virtual unsigned long PopAddr()=0;
112 
113  virtual void Reset();
114 
116  unsigned long GetStackPointer() const { return stackPointer; }
118  void SetStackPointer(unsigned long val) { stackPointer = val; }
120 
122  void SetReturnPoint(unsigned long stackPointer, Funktor *listener);
123 
125  void ResetLowestStackpointer(void) { lowestStackPointer = stackPointer; }
127  unsigned long GetLowestStackpointer(void) { return lowestStackPointer; }
128 };
129 
131 class HWStackSram: public HWStack, public TraceValueRegister {
132 
133  protected:
134  unsigned long stackCeil;
136 
137  void SetSpl(unsigned char);
138  void SetSph(unsigned char);
139  unsigned char GetSpl();
140  unsigned char GetSph();
141  void OnSPReadByTarget();
142 
143  public:
145  HWStackSram(AvrDevice *core, int bitsize, bool initRAMEND = false);
146 
147  virtual void Push(unsigned char val);
148  virtual unsigned char Pop();
149  virtual void PushAddr(unsigned long addr);
150  virtual unsigned long PopAddr();
151 
152  virtual void Reset();
153 
156 };
157 
160 
161  protected:
162  unsigned long *stackArea;
163 
164  public:
165  ThreeLevelStack(AvrDevice *core);
166  ~ThreeLevelStack();
167 
168  virtual void Push(unsigned char val);
169  virtual unsigned char Pop();
170  virtual void PushAddr(unsigned long addr);
171  virtual unsigned long PopAddr();
172 
173  virtual void Reset();
174 };
175 
176 #endif
uint32_t lowestStackPointer
marker: lowest stackpointer used by program
Definition: hwstack.h:96
unsigned long * stackArea
Definition: hwstack.h:162
Basic AVR device, contains the core functionality.
Definition: avrdevice.h:66
unsigned long stackCeil
Definition: hwstack.h:134
void ResetLowestStackpointer(void)
Sets lowest stack marker back to current stackpointer.
Definition: hwstack.h:125
bool m_alive
Definition: hwstack.h:46
Implements a stack with stack register using RAM as stackarea.
Definition: hwstack.h:131
int m_on_call_sp
Definition: hwstack.h:63
uint32_t stackPointer
current value of stack pointer
Definition: hwstack.h:95
Implements a stack register with stack logic.
Definition: hwstack.h:91
int m_last_SP_read
Definition: hwstack.h:61
AvrDevice * core
Link to device.
Definition: hwstack.h:94
Implements a stack with 3 levels deep (used as returnstack by ATtiny15 an other)
Definition: hwstack.h:159
std::vector< Thread * > m_threads
List of known threads. First addition (of main) is special.
Definition: hwstack.h:59
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
bool initRAMEND
Definition: hwstack.h:135
int m_created_by_thread
Definition: hwstack.h:50
std::multimap< unsigned long, Funktor * > returnPointList
Maps adresses to listeners for return addresses.
Definition: hwstack.h:97
IOReg< HWStackSram > sph_reg
Definition: hwstack.h:154
int m_on_call_ip
Definition: hwstack.h:64
int m_last_SP_writen
Definition: hwstack.h:62
Definition: hwstack.h:40
unsigned char registers[32]
Definition: hwstack.h:49
unsigned long GetLowestStackpointer(void)
Gets back the lowest stack pointer (for measuring stack usage)
Definition: hwstack.h:127
unsigned long GetStackPointer() const
Returns current stack pointer value.
Definition: hwstack.h:116
ThreadList m_ThreadList
Definition: hwstack.h:103
int m_ip
address (in bytes, not index)
Definition: hwstack.h:45
IOReg< HWStackSram > spl_reg
Definition: hwstack.h:155
int m_sp
Stack Pointer. Address 0x0000 is invalid; used for running thread. GDB never sees the 0...
Definition: hwstack.h:44
AvrDevice & m_core
Definition: hwstack.h:67
void SetStackPointer(unsigned long val)
Sets current stack pointer value (used by GDB interface)
Definition: hwstack.h:118