1 |
63 |
julius |
// ----------------------------------------------------------------------------
|
2 |
|
|
|
3 |
|
|
// SystemC OpenRISC 1000 Debug Unit: definition
|
4 |
|
|
|
5 |
|
|
// Copyright (C) 2008 Embecosm Limited <info@embecosm.com>
|
6 |
|
|
|
7 |
|
|
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
8 |
|
|
|
9 |
|
|
// This file is part of the GDB interface to the cycle accurate model of the
|
10 |
|
|
// OpenRISC 1000 based system-on-chip, ORPSoC, built using Verilator.
|
11 |
|
|
|
12 |
|
|
// This program is free software: you can redistribute it and/or modify it
|
13 |
|
|
// under the terms of the GNU Lesser General Public License as published by
|
14 |
|
|
// the Free Software Foundation, either version 3 of the License, or (at your
|
15 |
|
|
// option) any later version.
|
16 |
|
|
|
17 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
18 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
20 |
|
|
// License for more details.
|
21 |
|
|
|
22 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
23 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24 |
|
|
|
25 |
|
|
// ----------------------------------------------------------------------------
|
26 |
|
|
|
27 |
64 |
julius |
// $Id$
|
28 |
63 |
julius |
|
29 |
|
|
#ifndef DEBUG_UNIT_SC__H
|
30 |
|
|
#define DEBUG_UNIT_SC__H
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
// Define if no cache is wanted
|
34 |
|
|
#define NOCACHE
|
35 |
|
|
|
36 |
|
|
#include <stdint.h>
|
37 |
|
|
|
38 |
|
|
#include "systemc"
|
39 |
|
|
|
40 |
64 |
julius |
#include "JtagSC_includes.h"
|
41 |
63 |
julius |
#include "OrpsocAccess.h"
|
42 |
|
|
#include "SprCache.h"
|
43 |
|
|
#include "MemCache.h"
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
//-----------------------------------------------------------------------------
|
47 |
|
|
//! Module modeling the OpenRISC 1000 Debug Unit
|
48 |
|
|
|
49 |
|
|
//! Provides a high level interface to the GDB Server module with functions to
|
50 |
|
|
//! access SPRs, Wishbone memory and CPU control.
|
51 |
|
|
|
52 |
|
|
//! Provides a low level interface to the Embecosm SystemC JTAG interface,
|
53 |
|
|
//! queueing requests to read and write JTAG registers.
|
54 |
|
|
//-----------------------------------------------------------------------------
|
55 |
|
|
class DebugUnitSC
|
56 |
|
|
: public sc_core::sc_module
|
57 |
|
|
{
|
58 |
|
|
public:
|
59 |
|
|
|
60 |
|
|
// Constructor and destructor
|
61 |
|
|
DebugUnitSC (sc_core::sc_module_name name,
|
62 |
|
|
sc_core::sc_fifo<TapAction *> *_tapActionQueue);
|
63 |
|
|
~DebugUnitSC ();
|
64 |
|
|
|
65 |
|
|
// Reset function for the debug unit
|
66 |
|
|
void resetDebugUnit ();
|
67 |
|
|
|
68 |
|
|
// Functions to control and report on the CPU
|
69 |
|
|
void reset ();
|
70 |
|
|
void stall ();
|
71 |
|
|
void unstall ();
|
72 |
|
|
bool isStalled ();
|
73 |
|
|
|
74 |
|
|
// Functions to access SPRs
|
75 |
|
|
uint32_t readSpr (uint16_t sprNum);
|
76 |
|
|
void writeSpr (uint16_t sprNum,
|
77 |
|
|
uint32_t value);
|
78 |
|
|
void andSpr (uint16_t sprNum,
|
79 |
|
|
uint32_t value);
|
80 |
|
|
void orSpr (uint16_t sprNum,
|
81 |
|
|
uint32_t value);
|
82 |
|
|
|
83 |
|
|
// Functions to access memory
|
84 |
|
|
uint32_t readMem32 (uint32_t addr);
|
85 |
|
|
bool writeMem32 (uint32_t addr,
|
86 |
|
|
uint32_t value);
|
87 |
|
|
uint8_t readMem8 (uint32_t addr);
|
88 |
|
|
bool writeMem8 (uint32_t addr,
|
89 |
|
|
uint8_t value);
|
90 |
|
|
|
91 |
|
|
private:
|
92 |
|
|
|
93 |
|
|
// JTAG instructions
|
94 |
|
|
static const uint32_t CHAIN_SELECT_IR = 0x3; //!< Chain Select instruction
|
95 |
|
|
static const uint32_t DEBUG_IR = 0x8; //!< Debug instruction
|
96 |
|
|
|
97 |
|
|
//! JTAG instruction register length. There is no CRC for this register.
|
98 |
|
|
static const int JTAG_IR_LEN = 4; //!< JTAG instr reg length
|
99 |
|
|
|
100 |
|
|
// DEBUG UNIT CHAIN data register fields
|
101 |
|
|
static const int DUSEL_DR_LEN = 73; //!< total DUSEL DR size
|
102 |
|
|
static const int DUSEL_SEL_OFF = 0; //!< start of select field
|
103 |
|
|
static const int DUSEL_SEL_LEN = 1; //!< length of select field
|
104 |
|
|
static const int DUSEL_OPCODE_OFF = DUSEL_SEL_OFF + DUSEL_SEL_LEN; //!< start of opcode field
|
105 |
|
|
static const int DUSEL_OPCODE_LEN = 4; //!< length of opcode field
|
106 |
|
|
static const int DUSEL_CRC_OFF = DUSEL_OPCODE_OFF + DUSEL_OPCODE_LEN; //!< start of CRC field
|
107 |
|
|
static const int DUSEL_CRC_LEN = 32; //!< length of CRC field
|
108 |
|
|
static const int DUSEL_RESP_STATUS_OFF = DUSEL_CRC_OFF + DUSEL_CRC_LEN;
|
109 |
|
|
static const int DUSEL_RESP_STATUS_LEN = 4;
|
110 |
|
|
static const int DUSEL_RESP_CRC_OFF = DUSEL_RESP_STATUS_OFF + DUSEL_RESP_STATUS_LEN;
|
111 |
|
|
static const int DUSEL_RESP_CRC_LEN = 32;
|
112 |
|
|
|
113 |
|
|
static const uint32_t DBG_CRC32_POLY = 0x04c11db7;
|
114 |
|
|
|
115 |
|
|
// OpenRISC 1000 scan chains (values in DUSEL data register field)
|
116 |
|
|
static const int OR1K_SC_UNDEF = -1; //!< Undefined OR1K scan chain
|
117 |
|
|
static const int OR1K_SC_WISHBONE = 0; //!< for memory access
|
118 |
|
|
static const int OR1K_SC_CPU0 = 1; //!< for access to CPU0
|
119 |
|
|
static const int OR1K_SC_CPU1 = 2; //!< for access to CPU1
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
// JTAG RISC_DEBUG (for accessing SPR) data register fields
|
124 |
|
|
static const int RISC_DEBUG_DR_LEN = 74; //!< Total RISC_DEBUG DR size
|
125 |
|
|
static const int RISC_DEBUG_ADDR_OFF = 0; //!< start of address field
|
126 |
|
|
static const int RISC_DEBUG_ADDR_LEN = 32; //!< length of address field
|
127 |
|
|
static const int RISC_DEBUG_RW_OFF = 32; //!< start of read/write field
|
128 |
|
|
static const int RISC_DEBUG_RW_LEN = 1; //!< length of read/write field
|
129 |
|
|
static const int RISC_DEBUG_DATA_OFF = 33; //!< start of data field
|
130 |
|
|
static const int RISC_DEBUG_DATA_LEN = 32; //!< length of data field
|
131 |
|
|
static const int RISC_DEBUG_CRC_OFF = 65; //!< start of CRC field
|
132 |
|
|
static const int RISC_DEBUG_CRC_LEN = 8; //!< length of CRC field
|
133 |
|
|
static const int RISC_DEBUG_SPARE_OFF = 73; //!< start of spare bits
|
134 |
|
|
static const int RISC_DEBUG_SPARE_LEN = 1; //!< length of spare bit field
|
135 |
|
|
|
136 |
|
|
// JTAG REGISTER (for controlling the CPU) data register fields
|
137 |
|
|
static const int REGISTER_DR_LEN = 47; //!< Total REGISTER DR size
|
138 |
|
|
static const int REGISTER_ADDR_OFF = 0; //!< start of address field
|
139 |
|
|
static const int REGISTER_ADDR_LEN = 5; //!< length of address field
|
140 |
|
|
static const int REGISTER_RW_OFF = 5; //!< start of read/write field
|
141 |
|
|
static const int REGISTER_RW_LEN = 1; //!< length of read/write field
|
142 |
|
|
static const int REGISTER_DATA_OFF = 6; //!< start of data field
|
143 |
|
|
static const int REGISTER_DATA_LEN = 32; //!< length of data field
|
144 |
|
|
static const int REGISTER_CRC_OFF = 38; //!< start of CRC field
|
145 |
|
|
static const int REGISTER_CRC_LEN = 8; //!< length of CRC field
|
146 |
|
|
static const int REGISTER_SPARE_OFF = 46; //!< start of spare bits
|
147 |
|
|
static const int REGISTER_SPARE_LEN = 1; //!< length of spare bit field
|
148 |
|
|
|
149 |
|
|
// Register addresses for the REGISTER scan chain
|
150 |
|
|
static const uint8_t OR1K_RSC_RISCOP = 0x04; //!< Used to reset/stall CPU
|
151 |
|
|
|
152 |
|
|
// Bits for the RISCOP register
|
153 |
|
|
static const uint32_t RISCOP_RESET = 0x00000001; //!< Reset the CPU
|
154 |
|
|
static const uint32_t RISCOP_STALL = 0x00000002; //!< Stall the CPU
|
155 |
|
|
|
156 |
|
|
// JTAG WISHBONE (for accessing SPR) data register fields
|
157 |
|
|
static const int WISHBONE_DR_LEN = 74; //!< Total WISHBONE DR size
|
158 |
|
|
static const int WISHBONE_ADDR_OFF = 0; //!< start of address field
|
159 |
|
|
static const int WISHBONE_ADDR_LEN = 32; //!< length of address field
|
160 |
|
|
static const int WISHBONE_RW_OFF = 32; //!< start of read/write field
|
161 |
|
|
static const int WISHBONE_RW_LEN = 1; //!< length of read/write field
|
162 |
|
|
static const int WISHBONE_DATA_OFF = 33; //!< start of data field
|
163 |
|
|
static const int WISHBONE_DATA_LEN = 32; //!< length of data field
|
164 |
|
|
static const int WISHBONE_CRC_OFF = 65; //!< start of CRC field
|
165 |
|
|
static const int WISHBONE_CRC_LEN = 8; //!< length of CRC field
|
166 |
|
|
static const int WISHBONE_SPARE_OFF = 73; //!< start of spare bits
|
167 |
|
|
static const int WISHBONE_SPARE_LEN = 1; //!< length of spare bit field
|
168 |
|
|
|
169 |
|
|
//! The NPC is special, so we need to know about it
|
170 |
|
|
static const int SPR_NPC = 0x10;
|
171 |
|
|
|
172 |
|
|
//! The JTAG fifo we queue on
|
173 |
|
|
sc_core::sc_fifo<TapAction *> *tapActionQueue;
|
174 |
|
|
|
175 |
|
|
//! The processor stall state. When stalled we can use cacheing on
|
176 |
|
|
//! reads/writes of memory and SPRs.
|
177 |
|
|
enum {
|
178 |
|
|
UNKNOWN,
|
179 |
|
|
STALLED,
|
180 |
|
|
} stallState;
|
181 |
|
|
|
182 |
|
|
//! The currently selected scan chain
|
183 |
|
|
int currentScanChain;
|
184 |
|
|
|
185 |
|
|
#ifdef NOCACHE
|
186 |
|
|
//! Even if no cached, we need to cache the NPC
|
187 |
|
|
uint32_t npcCachedValue;
|
188 |
|
|
|
189 |
|
|
//! Cached NPC is valid
|
190 |
|
|
bool npcCacheIsValid;
|
191 |
|
|
|
192 |
|
|
#else
|
193 |
|
|
//! The SPR cache
|
194 |
|
|
SprCache *sprCache;
|
195 |
|
|
|
196 |
|
|
//! The memory cache
|
197 |
|
|
MemCache *memCache;
|
198 |
|
|
#endif
|
199 |
|
|
|
200 |
|
|
// Functions to control the CPU
|
201 |
|
|
uint32_t readRiscop ();
|
202 |
|
|
void writeRiscop (uint32_t value);
|
203 |
|
|
|
204 |
|
|
// Or1k JTAG actions
|
205 |
|
|
void selectDebugModule (int chain);
|
206 |
|
|
uint32_t readJtagReg (uint32_t addr);
|
207 |
|
|
uint32_t readJtagReg1 (uint32_t addr,
|
208 |
|
|
int bitSizeNoCrc);
|
209 |
|
|
uint32_t readJtagReg1 (uint64_t *dRegArray,
|
210 |
|
|
uint32_t addr,
|
211 |
|
|
int bitSizeNoCrc);
|
212 |
|
|
void writeJtagReg (uint32_t addr,
|
213 |
|
|
uint32_t data);
|
214 |
|
|
|
215 |
|
|
// Utilities to pack and unpack bits to/from data registers.
|
216 |
|
|
void clearBits (uint64_t regArray[],
|
217 |
|
|
int regBits);
|
218 |
|
|
|
219 |
|
|
void packBits (uint64_t regArray[],
|
220 |
|
|
int fieldOffset,
|
221 |
|
|
int fieldBits,
|
222 |
|
|
uint64_t fieldVal);
|
223 |
|
|
|
224 |
|
|
uint64_t unpackBits (uint64_t regArray[],
|
225 |
|
|
int fieldOffset,
|
226 |
|
|
int fieldBits);
|
227 |
|
|
|
228 |
|
|
// Utility to compute CRC-8 the OpenRISC way.
|
229 |
|
|
uint8_t crc8 (uint64_t dataArray[],
|
230 |
|
|
int size);
|
231 |
|
|
|
232 |
|
|
// Utility to compute CRC-32 for the debug unit
|
233 |
|
|
uint32_t crc32 (uint64_t dataArray[],
|
234 |
|
|
int size,
|
235 |
|
|
int offset);
|
236 |
|
|
|
237 |
|
|
// Functions to bitreverse values
|
238 |
|
|
uint32_t bit_reverse_swar_2(uint32_t x);
|
239 |
|
|
uint32_t bit_reverse_swar_4(uint32_t x);
|
240 |
|
|
uint32_t bit_reverse_swar_8(uint32_t x);
|
241 |
|
|
uint32_t bit_reverse_swar_16(uint32_t x);
|
242 |
|
|
uint32_t bit_reverse_swar_32(uint32_t x);
|
243 |
|
|
#define BITREV(x,y) bit_reverse_data(x,y)
|
244 |
|
|
uint32_t bit_reverse_data(uint32_t x, int length);
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
}; // DebugUnitSC ()
|
249 |
|
|
|
250 |
|
|
#endif // DEBUG_UNIT_SC__H
|