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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or_debug_proxy/] [src/] [or_debug_proxy.c] - Blame information for rev 431

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 julius
/*$$HEADER*/
2
/******************************************************************************/
3
/*                                                                            */
4
/*                    H E A D E R   I N F O R M A T I O N                     */
5
/*                                                                            */
6
/******************************************************************************/
7
 
8
// Project Name                   : OpenRISC Debug Proxy
9
// File Name                      : or_debug_proxy.c
10
// Prepared By                    : jb
11
// Project Start                  : 2008-10-01
12
 
13
/*$$COPYRIGHT NOTICE*/
14
/******************************************************************************/
15
/*                                                                            */
16
/*                      C O P Y R I G H T   N O T I C E                       */
17
/*                                                                            */
18
/******************************************************************************/
19
/*
20
  This library is free software; you can redistribute it and/or
21
  modify it under the terms of the GNU Lesser General Public
22
  License as published by the Free Software Foundation;
23
  version 2.1 of the License, a copy of which is available from
24
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
25
 
26
  This library is distributed in the hope that it will be useful,
27
  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29
  Lesser General Public License for more details.
30
 
31
  You should have received a copy of the GNU Lesser General Public
32
  License along with this library; if not, write to the Free Software
33
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
34
*/
35
 
36
/*$$DESCRIPTION*/
37
/******************************************************************************/
38
/*                                                                            */
39
/*                           D E S C R I P T I O N                            */
40
/*                                                                            */
41
/******************************************************************************/
42
//
43
// The entry point for the OpenRISC debug proxy console application. Is 
44
// compilable under both Linux/Unix systems and Cygwin Windows.
45
//
46
 
47
#include <assert.h>
48
#include <stdio.h>
49
#include <ctype.h>
50
#include <string.h>
51
#include <stdlib.h>
52
#include <unistd.h>
53
#include <stdarg.h>
54
#include <sys/stat.h>
55
#include <sys/types.h>
56
 
57
// Windows includes
58
#ifdef CYGWIN_COMPILE
59
#include <windows.h>
60
#include "win_FTCJTAG.h"
61
#include "win_FTCJTAG_ptrs.h"
62
#else
63
#include <signal.h>
64
void catch_sigint(int sig_num); // First param must be "int"
65
#endif
66
 
67
#include "gdb.h"
68
 
69
#ifdef USB_ENDPOINT_ENABLED
70
#include "usb_functions.h"
71
#endif
72
 
73
#include "or_debug_proxy.h"
74
 
75
// Defines of endpoint numbers
76
#define ENDPOINT_TARGET_NONE 0
77
#define ENDPOINT_TARGET_USB 1
78 376 julius
#define ENDPOINT_TARGET_OTHER 2
79 39 julius
 
80 376 julius
static int endpoint_target; // Value to hold targeted endpoint
81 39 julius
 
82
#define GDB_PROTOCOL_JTAG  1
83
#define GDB_PROTOCOL_RSP   2
84
#define GDB_PROTOCOL_NONE  3
85
 
86
int err; // Global error value
87
 
88
/* Currently selected scan chain - just to prevent unnecessary transfers. */
89
int current_chain = -1;
90
 
91
/* The chain that should be currently selected. */
92
int dbg_chain = -1;
93
 
94
int main(int argc,  char *argv[]) {
95
 
96
  char *s;
97
  int gdb_protocol = GDB_PROTOCOL_NONE;
98
  endpoint_target = ENDPOINT_TARGET_NONE;
99
  int inp_arg = 1;
100
 
101
  // Check we were compiled with at least one endpoint enabled
102
#ifndef USB_ENDPOINT_ENABLED
103
  printf("No endpoints enabled.\nRecompile the proxy with at least one endpoint enabled\n");
104
  exit(0);
105
#endif
106
 
107
  // init our global error number
108
  err = DBG_ERR_OK;
109
 
110
  // Parse input options
111
  if (argc < 3)
112
    {
113
      print_usage();
114
      exit(1);
115
    }
116
 
117
  err = DBG_ERR_OK;
118
  srand(getpid());
119
 
120
  // Parse through the input, check what we've been given
121
 
122
  while ( argv[inp_arg] != NULL )
123
    {
124 46 julius
      if(strcmp(argv[inp_arg], "-r") == 0)
125 39 julius
        {
126
          gdb_protocol = GDB_PROTOCOL_RSP;
127
          endpoint_target = ENDPOINT_TARGET_USB;
128
        }
129 376 julius
      else if(strcmp(argv[inp_arg], "-o") == 0)
130 39 julius
        {
131
          gdb_protocol = GDB_PROTOCOL_RSP;
132 376 julius
          endpoint_target = ENDPOINT_TARGET_OTHER;
133 39 julius
        }
134
      else
135
        {
136
          serverPort = strtol(argv[2],&s,10);
137
        }
138
 
139
      inp_arg++;
140
    }
141
 
142
  if(endpoint_target == ENDPOINT_TARGET_NONE || gdb_protocol == GDB_PROTOCOL_NONE || serverPort > 65535 || *s != '\0')
143
    {
144
      print_usage();
145
      exit(1);
146
    }
147
 
148
#ifdef CYGWIN_COMPILE
149
  // Load the FTCJTAG DLL function pointers
150
  if (getFTDIJTAGFunctions() < 0){
151
    exit(-1);
152
  }
153
#endif
154
 
155
#ifndef CYGWIN_COMPILE
156
  // Install a signal handler to exit gracefully
157
  // when we receive a sigint
158
  signal(SIGINT, catch_sigint);
159
#endif
160
 
161
  /* Initialise connection to our OR1k system */
162
  current_chain = -1;
163
#ifdef USB_ENDPOINT_ENABLED
164
  /* USB Endpoint */
165
  if (endpoint_target == ENDPOINT_TARGET_USB)
166
    {
167
      printf("\nConnecting to OR1k via USB debug cable\n\n");
168
      if ((err = usb_dbg_reset())) goto JtagIfError;
169
      dbg_test(); // Perform some tests
170
    }
171
#endif
172
 
173
  /* We have a connection to the target system.  Now establish server connection. */
174 46 julius
  if(gdb_protocol == GDB_PROTOCOL_RSP)
175
    { // Connect to RSP server
176
      /* RSP always starts stalled as though we have just reset the processor. */
177
      // rsp_exception (EXCEPT_TRAP);
178
      handle_rsp ();
179 39 julius
    // if((server_fd = GetServerSocket("or1ksim","tcp", serverPort))) {
180 46 julius
    }else {
181 39 julius
    fprintf(stderr,"Cannot start RSP Proxy server on port %d\n", serverPort);
182
    exit(-1);
183
  }
184
 
185
 
186
JtagIfError:
187
  fprintf(stderr,"Connection via USB debug cable failed (err = %d).\nPlease ensure the device is attached and correctly installed\n\n", err);
188
  exit(-1);
189
  return 0;
190
}
191
 
192
 
193
int dbg_reset()
194
{
195
#ifdef USB_ENDPOINT_ENABLED
196
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_reset();
197
#endif
198
  return DBG_ERR_INVALID_ENDPOINT;
199
}
200
 
201
void dbg_test() {
202
#ifdef USB_ENDPOINT_ENABLED
203
  if (endpoint_target == ENDPOINT_TARGET_USB) usb_dbg_test();
204
#endif
205
}
206
 
207
/* Set TAP instruction register */
208
int dbg_set_tap_ir(uint32_t ir) {
209
#ifdef USB_ENDPOINT_ENABLED
210
  if (endpoint_target == ENDPOINT_TARGET_USB) usb_set_tap_ir(ir);
211
#endif
212
  return DBG_ERR_INVALID_ENDPOINT;
213
}
214
 
215
/* Sets scan chain.  */
216
int dbg_set_chain(uint32_t chain) {
217
#ifdef USB_ENDPOINT_ENABLED
218
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_set_chain(chain);
219
#endif
220
  return DBG_ERR_INVALID_ENDPOINT;
221
}
222
 
223
/* sends out a command with 32bit address and 16bit length, if len >= 0 */
224
int dbg_command(uint32_t type, uint32_t adr, uint32_t len) {
225
  // This is never called by any of the VPI functions, so only USB endpoint
226
#ifdef USB_ENDPOINT_ENABLED
227
 if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_command(type,adr,len);
228
#endif
229
 return DBG_ERR_INVALID_ENDPOINT;
230
}
231
 
232
/* writes a ctrl reg */
233
int dbg_ctrl(uint32_t reset, uint32_t stall) {
234
#ifdef USB_ENDPOINT_ENABLED
235
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl(reset, stall);
236
#endif
237
  return DBG_ERR_INVALID_ENDPOINT;
238
}
239
 
240
/* reads control register */
241
int dbg_ctrl_read(uint32_t *reset, uint32_t *stall) {
242
#ifdef USB_ENDPOINT_ENABLED
243
    if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl_read(reset, stall);
244
#endif
245
    return DBG_ERR_INVALID_ENDPOINT;
246
}
247
 
248
/* issues a burst read/write */
249
int dbg_go(unsigned char *data, uint16_t len, uint32_t read) {
250
  // Only USB endpouint32_t option here
251
#ifdef USB_ENDPOINT_ENABLED
252
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_go(data, len, read);
253
#endif
254
  return DBG_ERR_INVALID_ENDPOINT;
255
}
256
 
257 94 julius
/* read a byte from wishbone */
258
int dbg_wb_read8(uint32_t adr, uint8_t *data) {
259
#ifdef USB_ENDPOINT_ENABLED
260
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read8(adr, data);
261
#endif
262
  return DBG_ERR_INVALID_ENDPOINT;
263
}
264
 
265
 
266 39 julius
/* read a word from wishbone */
267
int dbg_wb_read32(uint32_t adr, uint32_t *data) {
268
#ifdef USB_ENDPOINT_ENABLED
269
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read32(adr, data);
270
#endif
271
  return DBG_ERR_INVALID_ENDPOINT;
272
}
273
 
274 46 julius
/* write a word to wishbone */
275
int dbg_wb_write8(uint32_t adr, uint8_t data) {
276
#ifdef USB_ENDPOINT_ENABLED
277
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write8( adr, data);
278
#endif
279
  return DBG_ERR_INVALID_ENDPOINT;
280
}
281 39 julius
 
282
/* write a word to wishbone */
283
int dbg_wb_write32(uint32_t adr, uint32_t data) {
284
#ifdef USB_ENDPOINT_ENABLED
285
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write32( adr, data);
286
#endif
287
  return DBG_ERR_INVALID_ENDPOINT;
288
}
289
 
290
/* read a block from wishbone */
291
int dbg_wb_read_block32(uint32_t adr, uint32_t *data, uint32_t len) {
292
#ifdef USB_ENDPOINT_ENABLED
293
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read_block32( adr, data, len);
294
#endif
295
  return DBG_ERR_INVALID_ENDPOINT;
296
}
297
 
298
/* write a block to wishbone */
299
int dbg_wb_write_block32(uint32_t adr, uint32_t *data, uint32_t len) {
300
#ifdef USB_ENDPOINT_ENABLED
301
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write_block32( adr, data, len);
302
#endif
303
  return DBG_ERR_INVALID_ENDPOINT;
304
}
305
 
306
/* read a register from cpu */
307 47 julius
int dbg_cpu0_read(uint32_t adr, uint32_t *data, uint32_t length) {
308 39 julius
#ifdef USB_ENDPOINT_ENABLED
309 47 julius
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read( adr, data, length);
310 39 julius
#endif
311
  return DBG_ERR_INVALID_ENDPOINT;
312
}
313
 
314
/* write a cpu register */
315 47 julius
int dbg_cpu0_write(uint32_t adr, uint32_t *data, uint32_t length) {
316 39 julius
#ifdef USB_ENDPOINT_ENABLED
317 47 julius
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write( adr, data, length);
318 39 julius
#endif
319
  return DBG_ERR_INVALID_ENDPOINT;
320
}
321
 
322
/* write a cpu module register */
323
int dbg_cpu0_write_ctrl(uint32_t adr, unsigned char data) {
324
#ifdef USB_ENDPOINT_ENABLED
325
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write_ctrl( adr, data);
326
#endif
327
  return DBG_ERR_INVALID_ENDPOINT;
328
}
329
 
330
 
331
/* read a register from cpu module */
332
int dbg_cpu0_read_ctrl(uint32_t adr, unsigned char *data) {
333
#ifdef USB_ENDPOINT_ENABLED
334
  if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read_ctrl( adr, data);
335
#endif
336
  return DBG_ERR_INVALID_ENDPOINT;
337
}
338
 
339
 
340
void test_sdram(void) {
341
        return;
342
}
343
 
344
// Close down gracefully when we receive any kill signals
345
void catch_sigint(int sig_num)
346
{
347
  // Close down any potentially open sockets and USB handles
348
  if (server_fd) close(server_fd);
349
  gdb_close();
350
#ifdef USB_ENDPOINT_ENABLED
351
  usb_close_device_handle();
352
#endif
353
  printf("\nInterrupt signal received. Closing down connections and exiting\n\n");
354
  exit(0);
355
}
356
 
357
void print_usage()
358
{
359
  printf("Invalid or insufficient arguments\n");
360
  printf("\n");
361
  printf("OpenRISC GDB proxy server usage: or_debug_proxy -server_type port\n");
362
  printf("\n");
363
  printf("server_type:\n");
364
#ifdef USB_ENDPOINT_ENABLED
365
  printf("\t-r Start a server using RSP, connection to hadware target via\n\t   USB\n");
366
  printf("\t-j Start a server using legacy OR remote JTAG protocol, to\n\t   hardware target via USB\n");
367
#endif
368
  printf("\n");
369
  printf("port:\n");
370
  printf("\tAny free port within the usable range of 0 - 65535\n");
371
  printf("\n");
372
  printf("Example:\n");
373
#ifdef USB_ENDPOINT_ENABLED
374
  printf("\tStart a GDB server on port 5555, using RSP, connecting to\n\thardware target via USB\n");
375
  printf("\tor_debug_proxy -r 5555\n");
376
  printf("\n");
377
#endif
378
  fflush (stdout);
379
}

powered by: WebSVN 2.1.0

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