Debian Codegraph @

src/jtag2.h

raw symbols SCIP
1 /*
2 * avarice - The "avarice" program.
3 * Copyright (C) 2005,2006,2007 Joerg Wunsch
4 * Copyright (C) 2007, Colin O'Flynn
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
18 *
19 * This file extends the generic "jtag" class for the mkII protocol.
20 *
21 * $Id: jtag2.h 391 2021-08-23 20:57:14Z joerg_wunsch $
22 */
23
24 #ifndef JTAG2_H
25 #define JTAG2_H
26
27 #include "jtag.h"
28
29 class jtag2: public jtag
30 {
31 private:
32 unsigned short command_sequence;
33 int devdescrlen;
34 bool signedIn;
35 bool debug_active;
36 enum debugproto proto;
37 bool has_full_xmega_support; // Firmware revision of JTAGICE mkII or AVR Dragon
38 // allows for full Xmega support (>= 7.x)
39 unsigned long cached_pc;
40 bool cached_pc_is_valid;
41
42 unsigned char flashCache[MAX_FLASH_PAGE_SIZE];
43 unsigned int flashCachePageAddr;
44 unsigned char eepromCache[MAX_EEPROM_PAGE_SIZE];
45 unsigned int eepromCachePageAddr;
46
47 bool nonbreaking_events[EVT_MAX - EVT_BREAK + 1];
48
49 public:
50 jtag2(const char *dev, char *name, enum debugproto prot = PROTO_JTAG,
51 bool is_dragon = false, bool nsrst = false,
52 bool xmega = false):
53 jtag(dev, name, is_dragon? EMULATOR_DRAGON: EMULATOR_JTAGICE) {
54 signedIn = debug_active = false;
55 command_sequence = 0;
56 devdescrlen = sizeof(jtag2_device_desc_type);
57 proto = prot;
58 apply_nSRST = nsrst;
59 is_xmega = xmega;
60 xmega_n_bps = 0;
61 flashCachePageAddr = (unsigned int)-1;
62 eepromCachePageAddr = (unsigned short)-1;
63
64 for (int j = 0; j < MAX_TOTAL_BREAKPOINTS2; j++)
65 bp[j] = default_bp;
66 cached_pc_is_valid = false;
67 };
68 virtual ~jtag2(void);
69
70 virtual void initJtagBox(void);
71 virtual void initJtagOnChipDebugging(unsigned long bitrate);
72
73 virtual void deleteAllBreakpoints(void);
74 virtual void updateBreakpoints(void);
75 virtual bool codeBreakpointAt(unsigned int address);
76 virtual void parseEvents(const char *);
77
78 virtual void enableProgramming(void);
79 virtual void disableProgramming(void);
80 virtual void eraseProgramMemory(void);
81 virtual void eraseProgramPage(unsigned long address);
82 virtual void downloadToTarget(const char* filename, bool program, bool verify);
83
84 virtual unsigned long getProgramCounter(void);
85 virtual void setProgramCounter(unsigned long pc);
86 virtual void resetProgram(bool ignored = false);
87 virtual void interruptProgram(void);
88 virtual void resumeProgram(void);
89 virtual void jtagSingleStep(void);
90 virtual bool jtagContinue(void);
91
92 virtual uchar *jtagRead(unsigned long addr, unsigned int numBytes);
93 virtual void jtagWrite(unsigned long addr, unsigned int numBytes, uchar buffer[]);
94 virtual unsigned int statusAreaAddress(void) const {
95 return (is_xmega? 0x3D: 0x5D) + DATA_SPACE_ADDR_OFFSET;
96 };
97 virtual unsigned int cpuRegisterAreaAddress(void) const {
98 return is_xmega? REGISTER_SPACE_ADDR_OFFSET: DATA_SPACE_ADDR_OFFSET;
99 }
100
101 private:
102 virtual void changeBitRate(int newBitRate);
103 virtual void setDeviceDescriptor(jtag_device_def_type *dev);
104 virtual bool synchroniseAt(int bitrate);
105 virtual void startJtagLink(void);
106 virtual void deviceAutoConfig(void);
107 virtual void configDaisyChain(void);
108
109 void sendFrame(uchar *command, int commandSize);
110 int recvFrame(unsigned char *&msg, unsigned short &seqno);
111 int recv(unsigned char *&msg);
112
113 unsigned long b4_to_u32(unsigned char *b) {
114 unsigned long l;
115 l = (unsigned)b[0];
116 l += (unsigned)b[1] << 8;
117 l += (unsigned)(unsigned)b[2] << 16;
118 l += (unsigned)b[3] << 24;
119
120 return l;
121 };
122
123 void u32_to_b4(unsigned char *b, unsigned long l) {
124 b[0] = l & 0xff;
125 b[1] = (l >> 8) & 0xff;
126 b[2] = (l >> 16) & 0xff;
127 b[3] = (l >> 24) & 0xff;
128 };
129
130 unsigned short b2_to_u16(unsigned char *b) {
131 unsigned short l;
132 l = (unsigned)b[0];
133 l += (unsigned)b[1] << 8;
134
135 return l;
136 };
137
138 void u16_to_b2(unsigned char *b, unsigned short l) {
139 b[0] = l & 0xff;
140 b[1] = (l >> 8) & 0xff;
141 };
142
143
144 bool sendJtagCommand(uchar *command, int commandSize, int &tries,
145 uchar *&msg, int &msgsize, bool verify = true);
146
147 /** Send a command to the jtag, with retries, and return the
148 'responseSize' byte &response, response size in
149 &responseSize. If retryOnTimeout is true, retry the command
150 if no (positive or negative) response arrived in time, abort
151 after too many retries.
152
153 If a negative response arrived, throw an exception.
154
155 Caller must delete [] the response.
156 **/
157 void doJtagCommand(uchar *command, int commandSize,
158 uchar *&response, int &responseSize,
159 bool retryOnTimeout = true);
160
161 /** Simplified form of doJtagCommand:
162 Send 1-byte command 'cmd' to JTAG ICE, with retries, expecting a
163 response that consists only of the status byte which must be
164 RSP_OK.
165 **/
166 void doSimpleJtagCommand(uchar cmd);
167
168 // Miscellaneous
169 // -------------
170
171 /** Set JTAG ICE parameter 'item' to 'newValue' **/
172 void setJtagParameter(uchar item, uchar *newValue, int valSize);
173
174 /** Return value of JTAG ICE parameter 'item'; caller must delete
175 [] resp
176 **/
177 void getJtagParameter(uchar item, uchar *&resp, int &respSize);
178
179 uchar memorySpace(unsigned long &addr);
180
181 /** debugWire version of the breakpoint updater.
182 **/
183 void updateBreakpintsDW(void);
184
185 /** Wait until either the ICE or GDB issued an event. As this is
186 the heart of jtagContinue for the mkII, it returns true when a
187 breakpoint was reached, and false for GDB input.
188 **/
189 bool eventLoop(void);
190
191 /** Expect an ICE event in the input stream.
192 **/
193 void expectEvent(bool &breakpoint, bool &gdbInterrupt);
194
195 /** Update Xmega breakpoints on target
196 **/
197 void xmegaSendBPs(void);
198 };
199
200 #endif