1 |
63 |
julius |
// ----------------------------------------------------------------------------
|
2 |
|
|
|
3 |
|
|
// SystemC GDB RSP server: 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 |
|
|
// $Id$
|
28 |
|
|
|
29 |
|
|
#ifndef GDB_SERVER_SC__H
|
30 |
|
|
#define GDB_SERVER_SC__H
|
31 |
|
|
|
32 |
|
|
#include <stdint.h>
|
33 |
|
|
|
34 |
|
|
#include "systemc"
|
35 |
|
|
|
36 |
64 |
julius |
#include "JtagSC_includes.h"
|
37 |
63 |
julius |
|
38 |
|
|
#include "OrpsocAccess.h"
|
39 |
|
|
#include "RspConnection.h"
|
40 |
|
|
#include "MpHash.h"
|
41 |
|
|
#include "RspPacket.h"
|
42 |
|
|
#include "DebugUnitSC.h"
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
//! Module implementing a GDB RSP server.
|
46 |
|
|
|
47 |
|
|
//! A thread listens for RSP requests, which are converted to requests to read
|
48 |
|
|
//! and write registers, memory or control the CPU in the debug unit
|
49 |
|
|
|
50 |
|
|
class GdbServerSC
|
51 |
|
|
: public sc_core::sc_module
|
52 |
|
|
{
|
53 |
|
|
public:
|
54 |
|
|
|
55 |
|
|
// Constructor and destructor
|
56 |
|
|
GdbServerSC (sc_core::sc_module_name name,
|
57 |
|
|
uint32_t _flashStart,
|
58 |
|
|
uint32_t _flashEnd,
|
59 |
|
|
int rspPort,
|
60 |
|
|
sc_core::sc_fifo<TapAction *> *tapActionQueue);
|
61 |
|
|
~GdbServerSC ();
|
62 |
|
|
|
63 |
|
|
private:
|
64 |
|
|
|
65 |
|
|
//! Definition of GDB target signals.
|
66 |
|
|
|
67 |
|
|
//! Data taken from the GDB 6.8 source. Only those we use defined here.
|
68 |
|
|
enum TargetSignal {
|
69 |
|
|
TARGET_SIGNAL_NONE = 0,
|
70 |
|
|
TARGET_SIGNAL_INT = 2,
|
71 |
|
|
TARGET_SIGNAL_ILL = 4,
|
72 |
|
|
TARGET_SIGNAL_TRAP = 5,
|
73 |
|
|
TARGET_SIGNAL_FPE = 8,
|
74 |
|
|
TARGET_SIGNAL_BUS = 10,
|
75 |
|
|
TARGET_SIGNAL_SEGV = 11,
|
76 |
|
|
TARGET_SIGNAL_ALRM = 14,
|
77 |
|
|
TARGET_SIGNAL_USR2 = 31,
|
78 |
|
|
TARGET_SIGNAL_PWR = 32
|
79 |
|
|
};
|
80 |
|
|
|
81 |
|
|
// Register numbering. Matches GDB client
|
82 |
|
|
static const int MAX_SPRS = 0x10000; //!< Max number of OR1K SPRs
|
83 |
|
|
static const int max_gprs = 32; //!< Max number of OR1K GPRs
|
84 |
|
|
|
85 |
|
|
static const int PPC_REGNUM = max_gprs + 0; //!< Previous PC
|
86 |
|
|
static const int NPC_REGNUM = max_gprs + 1; //!< Next PC
|
87 |
|
|
static const int SR_REGNUM = max_gprs + 2; //!< Supervision Register
|
88 |
|
|
|
89 |
|
|
static const int NUM_REGS = max_gprs + 3; //!< Total GDB registers
|
90 |
|
|
|
91 |
|
|
//! Maximum size of a GDB RSP packet
|
92 |
|
|
//static const int RSP_PKT_MAX = NUM_REGS * 8 + 1;
|
93 |
|
|
static const int RSP_PKT_MAX = 1024*16;
|
94 |
|
|
|
95 |
|
|
// OpenRISC exception addresses. Only the ones we need to know about
|
96 |
|
|
static const uint32_t EXCEPT_NONE = 0x000; //!< No exception
|
97 |
|
|
static const uint32_t EXCEPT_RESET = 0x100; //!< Reset
|
98 |
|
|
|
99 |
|
|
// SPR numbers
|
100 |
|
|
static const uint16_t SPR_NPC = 0x0010; //!< Next program counter
|
101 |
|
|
static const uint16_t SPR_SR = 0x0011; //!< Supervision register
|
102 |
|
|
static const uint16_t SPR_PPC = 0x0012; //!< Previous program counter
|
103 |
|
|
static const uint16_t SPR_GPR0 = 0x0400; //!< GPR 0
|
104 |
|
|
|
105 |
|
|
static const uint16_t SPR_DVR0 = 0x3000; //!< Debug value register 0
|
106 |
|
|
static const uint16_t SPR_DVR1 = 0x3001; //!< Debug value register 1
|
107 |
|
|
static const uint16_t SPR_DVR2 = 0x3002; //!< Debug value register 2
|
108 |
|
|
static const uint16_t SPR_DVR3 = 0x3003; //!< Debug value register 3
|
109 |
|
|
static const uint16_t SPR_DVR4 = 0x3004; //!< Debug value register 4
|
110 |
|
|
static const uint16_t SPR_DVR5 = 0x3005; //!< Debug value register 5
|
111 |
|
|
static const uint16_t SPR_DVR6 = 0x3006; //!< Debug value register 6
|
112 |
|
|
static const uint16_t SPR_DVR7 = 0x3007; //!< Debug value register 7
|
113 |
|
|
|
114 |
|
|
static const uint16_t SPR_DCR0 = 0x3008; //!< Debug control register 0
|
115 |
|
|
static const uint16_t SPR_DCR1 = 0x3009; //!< Debug control register 1
|
116 |
|
|
static const uint16_t SPR_DCR2 = 0x300a; //!< Debug control register 2
|
117 |
|
|
static const uint16_t SPR_DCR3 = 0x300b; //!< Debug control register 3
|
118 |
|
|
static const uint16_t SPR_DCR4 = 0x300c; //!< Debug control register 4
|
119 |
|
|
static const uint16_t SPR_DCR5 = 0x300d; //!< Debug control register 5
|
120 |
|
|
static const uint16_t SPR_DCR6 = 0x300e; //!< Debug control register 6
|
121 |
|
|
static const uint16_t SPR_DCR7 = 0x300f; //!< Debug control register 7
|
122 |
|
|
|
123 |
|
|
static const uint16_t SPR_DMR1 = 0x3010; //!< Debug mode register 1
|
124 |
|
|
static const uint16_t SPR_DMR2 = 0x3011; //!< Debug mode register 2
|
125 |
|
|
static const uint16_t SPR_DSR = 0x3014; //!< Debug stop register
|
126 |
|
|
static const uint16_t SPR_DRR = 0x3015; //!< Debug reason register
|
127 |
|
|
|
128 |
|
|
// SPR masks and offsets
|
129 |
|
|
static const uint32_t SPR_DMR1_ST = 0x00400000; //!< Single-step trace
|
130 |
|
|
static const uint32_t SPR_DMR2_WGB = 0x003ff000; //!< W/pt generating B/pt
|
131 |
|
|
static const uint32_t SPR_DMR2_WBS = 0xffc00000; //!< W/pt B/pt status
|
132 |
|
|
static const uint32_t SPR_DSR_TE = 0x00002000; //!< Trap
|
133 |
|
|
static const uint32_t SPR_DCR_DP_MASK = 0x00000001; //!< Debug Pair Present
|
134 |
|
|
static const uint32_t SPR_DCR_CC_MASK = 0x0000000e; //!< Compare Condition
|
135 |
|
|
static const uint32_t SPR_DCR_SC_MASK = 0x00000010; //!< Signed Comparison
|
136 |
|
|
static const uint32_t SPR_DCR_CT_MASK = 0x000000e0; //!< Compare To
|
137 |
|
|
static const uint32_t SPR_DMR2_WGB_SHIFT = 12; //!< W/pt Generate B/pt
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
// DRR (Debug Reason Register) Bits
|
141 |
|
|
static const uint32_t SPR_DRR_RSTE = 0x00000001; //!< Reset
|
142 |
|
|
static const uint32_t SPR_DRR_BUSEE = 0x00000002; //!< Bus error
|
143 |
|
|
static const uint32_t SPR_DRR_DPFE = 0x00000004; //!< Data page fault
|
144 |
|
|
static const uint32_t SPR_DRR_IPFE = 0x00000008; //!< Insn page fault
|
145 |
|
|
static const uint32_t SPR_DRR_TTE = 0x00000010; //!< Tick timer
|
146 |
|
|
static const uint32_t SPR_DRR_AE = 0x00000020; //!< Alignment
|
147 |
|
|
static const uint32_t SPR_DRR_IIE = 0x00000040; //!< Illegal instruction
|
148 |
|
|
static const uint32_t SPR_DRR_IE = 0x00000080; //!< Interrupt
|
149 |
|
|
static const uint32_t SPR_DRR_DME = 0x00000100; //!< DTLB miss
|
150 |
|
|
static const uint32_t SPR_DRR_IME = 0x00000200; //!< ITLB miss
|
151 |
|
|
static const uint32_t SPR_DRR_RE = 0x00000400; //!< Range fault
|
152 |
|
|
static const uint32_t SPR_DRR_SCE = 0x00000800; //!< System call
|
153 |
|
|
static const uint32_t SPR_DRR_FPE = 0x00001000; //!< Floating point
|
154 |
|
|
static const uint32_t SPR_DRR_TE = 0x00002000; //!< Trap
|
155 |
|
|
|
156 |
|
|
//! RSP Signal valu
|
157 |
|
|
uint32_t rsp_sigval;
|
158 |
|
|
|
159 |
|
|
//! Trap instruction for OR32
|
160 |
|
|
static const uint32_t OR1K_TRAP_INSTR = 0x21000001;
|
161 |
|
|
|
162 |
|
|
//! Thread ID used by Or1ksim
|
163 |
|
|
static const int OR1KSIM_TID = 1;
|
164 |
|
|
|
165 |
|
|
// The bounds of flash memory
|
166 |
|
|
uint32_t flashStart; //<! Start of flash memory
|
167 |
|
|
uint32_t flashEnd; //<! End of flash memory
|
168 |
|
|
|
169 |
|
|
//! Our associated Debug Unit
|
170 |
|
|
DebugUnitSC *debugUnit;
|
171 |
|
|
|
172 |
|
|
//! Our associated RSP interface (which we create)
|
173 |
|
|
RspConnection *rsp;
|
174 |
|
|
|
175 |
|
|
//! The packet pointer. There is only ever one packet in use at one time, so
|
176 |
|
|
//! there is no need to repeatedly allocate and delete it.
|
177 |
|
|
RspPacket *pkt;
|
178 |
|
|
|
179 |
|
|
//! Hash table for matchpoints
|
180 |
|
|
MpHash *mpHash;
|
181 |
|
|
|
182 |
|
|
//! Is the target stopped
|
183 |
|
|
bool targetStopped;
|
184 |
|
|
|
185 |
|
|
// SystemC thread to listen for and service RSP requests
|
186 |
|
|
void rspServer ();
|
187 |
|
|
|
188 |
|
|
// Main RSP request handler
|
189 |
|
|
void rspClientRequest ();
|
190 |
|
|
|
191 |
|
|
// Handle the various RSP requests
|
192 |
|
|
void rspCheckForException();
|
193 |
|
|
void rspReportException ();
|
194 |
|
|
void rspContinue ();
|
195 |
|
|
void rspContinue (uint32_t except);
|
196 |
|
|
void rspContinue (uint32_t addr,
|
197 |
|
|
uint32_t except);
|
198 |
|
|
void rspInterrupt ();
|
199 |
|
|
void rspReadAllRegs ();
|
200 |
|
|
void rspWriteAllRegs ();
|
201 |
|
|
void rspReadMem ();
|
202 |
|
|
void rspWriteMem ();
|
203 |
|
|
void rspReadReg ();
|
204 |
|
|
void rspWriteReg ();
|
205 |
|
|
void rspQuery ();
|
206 |
|
|
void rspCommand ();
|
207 |
|
|
void rspSet ();
|
208 |
|
|
void rspRestart ();
|
209 |
|
|
void rspStep ();
|
210 |
|
|
void rspStep (uint32_t except);
|
211 |
|
|
void rspStep (uint32_t addr,
|
212 |
|
|
uint32_t except);
|
213 |
|
|
void rspVpkt ();
|
214 |
|
|
void rspWriteMemBin ();
|
215 |
|
|
void rspRemoveMatchpoint ();
|
216 |
|
|
void rspInsertMatchpoint ();
|
217 |
|
|
|
218 |
|
|
// Convenience wrappers for getting particular registers, which are really
|
219 |
|
|
// SPRs.
|
220 |
|
|
uint32_t readNpc ();
|
221 |
|
|
void writeNpc (uint32_t addr);
|
222 |
|
|
|
223 |
|
|
uint32_t readGpr (int regNum);
|
224 |
|
|
void writeGpr (int regNum,
|
225 |
|
|
uint32_t value);
|
226 |
|
|
|
227 |
|
|
// Check if we got a message from the or1200 monitor module telling us
|
228 |
|
|
// to stall
|
229 |
|
|
bool checkMonitorPipe ();
|
230 |
|
|
|
231 |
|
|
}; // GdbServerSC ()
|
232 |
|
|
|
233 |
|
|
#endif // GDB_SERVER_SC__H
|