OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [include/] [DebugUnitSC.h] - Blame information for rev 462

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
// Define if no cache is wanted
33
#define NOCACHE
34
 
35
#include <stdint.h>
36
 
37
#include "systemc"
38
 
39 64 julius
#include "JtagSC_includes.h"
40 63 julius
#include "OrpsocAccess.h"
41
#include "SprCache.h"
42
#include "MemCache.h"
43
 
44
//-----------------------------------------------------------------------------
45
//! Module modeling the OpenRISC 1000 Debug Unit
46
 
47
//! Provides a high level interface to the GDB Server module with functions to
48
//! access SPRs, Wishbone memory and CPU control.
49
 
50
//! Provides a low level interface to the Embecosm SystemC JTAG interface,
51
//! queueing requests to read and write JTAG registers.
52
//-----------------------------------------------------------------------------
53 462 julius
class DebugUnitSC:public sc_core::sc_module {
54 63 julius
public:
55
 
56 462 julius
        // Constructor and destructor
57
        DebugUnitSC(sc_core::sc_module_name name,
58
                    sc_core::sc_fifo < TapAction * >*_tapActionQueue);
59
        ~DebugUnitSC();
60 63 julius
 
61 462 julius
        // Reset function for the debug unit
62
        void resetDebugUnit();
63 63 julius
 
64 462 julius
        // Functions to control and report on the CPU
65
        void reset();
66
        void stall();
67
        void unstall();
68
        bool isStalled();
69 63 julius
 
70 462 julius
        // Functions to access SPRs
71
        uint32_t readSpr(uint16_t sprNum);
72
        void writeSpr(uint16_t sprNum, uint32_t value);
73
        void andSpr(uint16_t sprNum, uint32_t value);
74
        void orSpr(uint16_t sprNum, uint32_t value);
75 63 julius
 
76 462 julius
        // Functions to access memory
77
        uint32_t readMem32(uint32_t addr);
78
        bool writeMem32(uint32_t addr, uint32_t value);
79
        uint8_t readMem8(uint32_t addr);
80
        bool writeMem8(uint32_t addr, uint8_t value);
81 63 julius
 
82
private:
83
 
84 462 julius
        // JTAG instructions
85
        static const uint32_t CHAIN_SELECT_IR = 0x3;    //!< Chain Select instruction
86
        static const uint32_t DEBUG_IR = 0x8;   //!< Debug instruction
87 63 julius
 
88 462 julius
        //! JTAG instruction register length. There is no CRC for this register.
89
        static const int JTAG_IR_LEN = 4;       //!< JTAG instr reg length
90 63 julius
 
91 462 julius
        // DEBUG UNIT CHAIN data register fields
92
        static const int DUSEL_DR_LEN = 73;     //!< total DUSEL DR size
93
        static const int DUSEL_SEL_OFF = 0;      //!< start of select field
94
        static const int DUSEL_SEL_LEN = 1;     //!< length of select field
95
        static const int DUSEL_OPCODE_OFF = DUSEL_SEL_OFF + DUSEL_SEL_LEN;      //!< start of opcode field
96
        static const int DUSEL_OPCODE_LEN = 4;  //!< length of opcode field
97
        static const int DUSEL_CRC_OFF = DUSEL_OPCODE_OFF + DUSEL_OPCODE_LEN;   //!< start of CRC field
98
        static const int DUSEL_CRC_LEN = 32;    //!< length of CRC field
99
        static const int DUSEL_RESP_STATUS_OFF = DUSEL_CRC_OFF + DUSEL_CRC_LEN;
100
        static const int DUSEL_RESP_STATUS_LEN = 4;
101
        static const int DUSEL_RESP_CRC_OFF =
102
            DUSEL_RESP_STATUS_OFF + DUSEL_RESP_STATUS_LEN;
103
        static const int DUSEL_RESP_CRC_LEN = 32;
104 63 julius
 
105 462 julius
        static const uint32_t DBG_CRC32_POLY = 0x04c11db7;
106 63 julius
 
107 462 julius
        // OpenRISC 1000 scan chains (values in DUSEL data register field)
108
        static const int OR1K_SC_UNDEF = -1;    //!< Undefined OR1K scan chain
109
        static const int OR1K_SC_WISHBONE = 0;   //!< for memory access
110
        static const int OR1K_SC_CPU0 = 1;      //!< for access to CPU0
111
        static const int OR1K_SC_CPU1 = 2;      //!< for access to CPU1
112 63 julius
 
113 462 julius
        // JTAG RISC_DEBUG (for accessing SPR) data register fields
114
        static const int RISC_DEBUG_DR_LEN = 74;        //!< Total RISC_DEBUG DR size
115
        static const int RISC_DEBUG_ADDR_OFF = 0;        //!< start of address field
116
        static const int RISC_DEBUG_ADDR_LEN = 32;      //!< length of address field
117
        static const int RISC_DEBUG_RW_OFF = 32;        //!< start of read/write field
118
        static const int RISC_DEBUG_RW_LEN = 1; //!< length of read/write field
119
        static const int RISC_DEBUG_DATA_OFF = 33;      //!< start of data field
120
        static const int RISC_DEBUG_DATA_LEN = 32;      //!< length of data field
121
        static const int RISC_DEBUG_CRC_OFF = 65;       //!< start of CRC field
122
        static const int RISC_DEBUG_CRC_LEN = 8;        //!< length of CRC field
123
        static const int RISC_DEBUG_SPARE_OFF = 73;     //!< start of spare bits
124
        static const int RISC_DEBUG_SPARE_LEN = 1;      //!< length of spare bit field
125 63 julius
 
126 462 julius
        // JTAG REGISTER (for controlling the CPU) data register fields
127
        static const int REGISTER_DR_LEN = 47;  //!< Total REGISTER DR size
128
        static const int REGISTER_ADDR_OFF = 0;  //!< start of address field
129
        static const int REGISTER_ADDR_LEN = 5; //!< length of address field
130
        static const int REGISTER_RW_OFF = 5;   //!< start of read/write field
131
        static const int REGISTER_RW_LEN = 1;   //!< length of read/write field
132
        static const int REGISTER_DATA_OFF = 6; //!< start of data field
133
        static const int REGISTER_DATA_LEN = 32;        //!< length of data field
134
        static const int REGISTER_CRC_OFF = 38; //!< start of CRC field
135
        static const int REGISTER_CRC_LEN = 8;  //!< length of CRC field
136
        static const int REGISTER_SPARE_OFF = 46;       //!< start of spare bits
137
        static const int REGISTER_SPARE_LEN = 1;        //!< length of spare bit field
138 63 julius
 
139 462 julius
        // Register addresses for the REGISTER scan chain
140
        static const uint8_t OR1K_RSC_RISCOP = 0x04;    //!< Used to reset/stall CPU
141 63 julius
 
142 462 julius
        // Bits for the RISCOP register
143
        static const uint32_t RISCOP_RESET = 0x00000001;        //!< Reset the CPU
144
        static const uint32_t RISCOP_STALL = 0x00000002;        //!< Stall the CPU
145 63 julius
 
146 462 julius
        // JTAG WISHBONE (for accessing SPR) data register fields
147
        static const int WISHBONE_DR_LEN = 74;  //!< Total WISHBONE DR size
148
        static const int WISHBONE_ADDR_OFF = 0;  //!< start of address field
149
        static const int WISHBONE_ADDR_LEN = 32;        //!< length of address field
150
        static const int WISHBONE_RW_OFF = 32;  //!< start of read/write field
151
        static const int WISHBONE_RW_LEN = 1;   //!< length of read/write field
152
        static const int WISHBONE_DATA_OFF = 33;        //!< start of data field
153
        static const int WISHBONE_DATA_LEN = 32;        //!< length of data field
154
        static const int WISHBONE_CRC_OFF = 65; //!< start of CRC field
155
        static const int WISHBONE_CRC_LEN = 8;  //!< length of CRC field
156
        static const int WISHBONE_SPARE_OFF = 73;       //!< start of spare bits
157
        static const int WISHBONE_SPARE_LEN = 1;        //!< length of spare bit field
158 63 julius
 
159 462 julius
        //! The NPC is special, so we need to know about it
160
        static const int SPR_NPC = 0x10;
161 63 julius
 
162 462 julius
        //! The JTAG fifo we queue on
163
        sc_core::sc_fifo < TapAction * >*tapActionQueue;
164 63 julius
 
165 462 julius
        //! The processor stall state. When stalled we can use cacheing on
166
        //! reads/writes of memory and SPRs.
167
        enum {
168
                UNKNOWN,
169
                STALLED,
170
        } stallState;
171 63 julius
 
172 462 julius
        //! The currently selected scan chain
173
        int currentScanChain;
174 63 julius
 
175
#ifdef NOCACHE
176 462 julius
        //! Even if no cached, we need to cache the NPC
177
        uint32_t npcCachedValue;
178 63 julius
 
179 462 julius
        //! Cached NPC is valid
180
        bool npcCacheIsValid;
181 63 julius
 
182
#else
183 462 julius
        //! The SPR cache
184
        SprCache *sprCache;
185 63 julius
 
186 462 julius
        //! The memory cache
187
        MemCache *memCache;
188 63 julius
#endif
189
 
190 462 julius
        // Functions to control the CPU
191
        uint32_t readRiscop();
192
        void writeRiscop(uint32_t value);
193 63 julius
 
194 462 julius
        // Or1k JTAG actions
195
        void selectDebugModule(int chain);
196
        uint32_t readJtagReg(uint32_t addr);
197
        uint32_t readJtagReg1(uint32_t addr, int bitSizeNoCrc);
198
        uint32_t readJtagReg1(uint64_t * dRegArray,
199
                              uint32_t addr, int bitSizeNoCrc);
200
        void writeJtagReg(uint32_t addr, uint32_t data);
201 63 julius
 
202 462 julius
        // Utilities to pack and unpack bits to/from data registers.
203
        void clearBits(uint64_t regArray[], int regBits);
204 63 julius
 
205 462 julius
        void packBits(uint64_t regArray[],
206
                      int fieldOffset, int fieldBits, uint64_t fieldVal);
207 63 julius
 
208 462 julius
        uint64_t unpackBits(uint64_t regArray[],
209
                            int fieldOffset, int fieldBits);
210 63 julius
 
211 462 julius
        // Utility to compute CRC-8 the OpenRISC way.
212
        uint8_t crc8(uint64_t dataArray[], int size);
213 63 julius
 
214 462 julius
        // Utility to compute CRC-32 for the debug unit
215
        uint32_t crc32(uint64_t dataArray[], int size, int offset);
216
 
217
        // Functions to bitreverse values
218
        uint32_t bit_reverse_swar_2(uint32_t x);
219
        uint32_t bit_reverse_swar_4(uint32_t x);
220
        uint32_t bit_reverse_swar_8(uint32_t x);
221
        uint32_t bit_reverse_swar_16(uint32_t x);
222
        uint32_t bit_reverse_swar_32(uint32_t x);
223 63 julius
#define BITREV(x,y) bit_reverse_data(x,y)
224 462 julius
        uint32_t bit_reverse_data(uint32_t x, int length);
225 63 julius
 
226 462 julius
};                              // DebugUnitSC ()
227 63 julius
 
228 462 julius
#endif // DEBUG_UNIT_SC__H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.