MSP430EEMTarget.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MSP430Target.h"
4 #include <bzscore/sync.h>
5 #include <set>
6 #include "settings.h"
7 
8 namespace MSP430Proxy
9 {
10  class SoftwareBreakpointManager;
11 
14  {
15  private:
16  bool m_bEEMInitialized;
17 
18  BazisLib::Event m_TargetStopped;
19  DWORD m_LastStopEvent;
20 
21  WORD m_SoftwareBreakpointWrapperHandle;
22  SoftwareBreakpointManager *m_pBreakpointManager;
23  RUN_MODES_t m_LastResumeMode;
24 
25  unsigned m_HardwareBreakpointsUsed;
26 
28  LONG m_BreakpointAddrOfLastResumeOp;
29 
30  private:
31  class RAMBreakpointDatabase
32  {
33  private:
34  unsigned char Flags[65536 / 8];
35 
36  public:
37  RAMBreakpointDatabase()
38  {
39  memset(Flags, 0, sizeof(Flags));
40  }
41 
42  void InsertBreakpoint(USHORT addr)
43  {
44  Flags[addr >> 3] |= (1 << (addr & 7));
45  }
46 
47  void RemoveBreakpoint(USHORT addr)
48  {
49  Flags[addr >> 3] &= ~(1 << (addr & 7));
50  }
51 
52  bool IsBreakpointPresent(USHORT addr)
53  {
54  return (Flags[addr >> 3] & (1 << (addr & 7))) != 0;
55  }
56  };
57 
58  RAMBreakpointDatabase m_RAMBreakpoints;
59  unsigned short m_BreakpointInstruction;
60  BreakpointPolicy m_BreakpointPolicy;
61 
62  protected:
63  virtual bool DoResumeTarget(RUN_MODES_t mode) override;
64 
65  bool IsFLASHAddress(ULONGLONG addr)
66  {
67  return addr >= m_DeviceInfo.mainStart && addr <= m_DeviceInfo.mainEnd;
68  }
69 
70  public:
72  : m_bEEMInitialized(false)
73  , m_SoftwareBreakpointWrapperHandle(0)
74  , m_pBreakpointManager(NULL)
75  , m_LastResumeMode(RUN_TO_BREAKPOINT)
76  , m_BreakpointAddrOfLastResumeOp(-1)
77  , m_BreakpointInstruction(0) //Will be updated in Initialize()
78  , m_HardwareBreakpointsUsed(0)
79  , m_BreakpointPolicy(HardwareThenSoftware)
80  {
81  }
82 
83 
84  public:
85  virtual bool Initialize(const GlobalSettings &settings) override;
87 
88  virtual bool WaitForJTAGEvent() override;
89 
90  private:
91  static void sEEMHandler(UINT MsgId, UINT wParam, LONG lParam, LONG clientHandle);
92  void EEMNotificationHandler(MSP430_MSG wMsg, WPARAM wParam, LPARAM lParam);
93 
94  GDBStatus DoCreateCodeBreakpoint(bool hardware, ULONGLONG Address, INT_PTR *pCookie);
95  GDBStatus DoRemoveCodeBreakpoint(bool hardware, ULONGLONG Address, INT_PTR Cookie);
96 
97  public:
98  virtual GDBStatus CreateBreakpoint(BreakpointType type, ULONGLONG Address, unsigned kind, OUT INT_PTR *pCookie) override;
99  virtual GDBStatus RemoveBreakpoint(BreakpointType type, ULONGLONG Address, INT_PTR Cookie) override;
100 
101  virtual GDBStatus SendBreakInRequestAsync();
102 
103  public:
104  virtual GDBStatus ReadTargetMemory(ULONGLONG Address, void *pBuffer, size_t *pSizeInBytes) override;
105  virtual GDBStatus WriteTargetMemory(ULONGLONG Address, const void *pBuffer, size_t sizeInBytes) override;
106  };
107 }