Line 68... |
Line 68... |
|
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
#include "usb_functions.h"
|
#include "usb_functions.h"
|
#endif
|
#endif
|
|
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
#include "vpi_functions.h"
|
|
#endif
|
|
|
|
#include "or_debug_proxy.h"
|
#include "or_debug_proxy.h"
|
|
|
// Defines of endpoint numbers
|
// Defines of endpoint numbers
|
#define ENDPOINT_TARGET_NONE 0
|
#define ENDPOINT_TARGET_NONE 0
|
#define ENDPOINT_TARGET_USB 1
|
#define ENDPOINT_TARGET_USB 1
|
#define ENDPOINT_TARGET_VPI 2
|
#define ENDPOINT_TARGET_OTHER 2
|
|
|
static int endpoint_target; // Either VPI interface via sockets, or the USB device
|
static int endpoint_target; // Value to hold targeted endpoint
|
|
|
#define GDB_PROTOCOL_JTAG 1
|
#define GDB_PROTOCOL_JTAG 1
|
#define GDB_PROTOCOL_RSP 2
|
#define GDB_PROTOCOL_RSP 2
|
#define GDB_PROTOCOL_NONE 3
|
#define GDB_PROTOCOL_NONE 3
|
|
|
Line 102... |
Line 98... |
endpoint_target = ENDPOINT_TARGET_NONE;
|
endpoint_target = ENDPOINT_TARGET_NONE;
|
int inp_arg = 1;
|
int inp_arg = 1;
|
|
|
// Check we were compiled with at least one endpoint enabled
|
// Check we were compiled with at least one endpoint enabled
|
#ifndef USB_ENDPOINT_ENABLED
|
#ifndef USB_ENDPOINT_ENABLED
|
#ifndef VPI_ENDPOINT_ENABLED
|
|
printf("No endpoints enabled.\nRecompile the proxy with at least one endpoint enabled\n");
|
printf("No endpoints enabled.\nRecompile the proxy with at least one endpoint enabled\n");
|
exit(0);
|
exit(0);
|
#endif
|
#endif
|
#endif
|
|
|
|
// init our global error number
|
// init our global error number
|
err = DBG_ERR_OK;
|
err = DBG_ERR_OK;
|
|
|
// Parse input options
|
// Parse input options
|
Line 130... |
Line 124... |
if(strcmp(argv[inp_arg], "-r") == 0)
|
if(strcmp(argv[inp_arg], "-r") == 0)
|
{
|
{
|
gdb_protocol = GDB_PROTOCOL_RSP;
|
gdb_protocol = GDB_PROTOCOL_RSP;
|
endpoint_target = ENDPOINT_TARGET_USB;
|
endpoint_target = ENDPOINT_TARGET_USB;
|
}
|
}
|
else if(strcmp(argv[inp_arg], "-v") == 0)
|
else if(strcmp(argv[inp_arg], "-o") == 0)
|
{
|
{
|
gdb_protocol = GDB_PROTOCOL_RSP;
|
gdb_protocol = GDB_PROTOCOL_RSP;
|
endpoint_target = ENDPOINT_TARGET_VPI;
|
endpoint_target = ENDPOINT_TARGET_OTHER;
|
}
|
}
|
else
|
else
|
{
|
{
|
serverPort = strtol(argv[2],&s,10);
|
serverPort = strtol(argv[2],&s,10);
|
}
|
}
|
Line 173... |
Line 167... |
printf("\nConnecting to OR1k via USB debug cable\n\n");
|
printf("\nConnecting to OR1k via USB debug cable\n\n");
|
if ((err = usb_dbg_reset())) goto JtagIfError;
|
if ((err = usb_dbg_reset())) goto JtagIfError;
|
dbg_test(); // Perform some tests
|
dbg_test(); // Perform some tests
|
}
|
}
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
/* RTL simulation endpoint */
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI){
|
|
printf("\nConnecting to OR1k RTL simulation\n\n");
|
|
// Connect to the (hopefully) already running RTL simulation server running via VPI
|
|
vpi_fd = vpi_connect();
|
|
|
|
if ((err = vpi_dbg_reset())) goto JtagIfError;
|
|
vpi_dbg_test(); // Perform some tests
|
|
}
|
|
#endif
|
|
|
|
/* We have a connection to the target system. Now establish server connection. */
|
/* We have a connection to the target system. Now establish server connection. */
|
if(gdb_protocol == GDB_PROTOCOL_RSP)
|
if(gdb_protocol == GDB_PROTOCOL_RSP)
|
{ // Connect to RSP server
|
{ // Connect to RSP server
|
/* RSP always starts stalled as though we have just reset the processor. */
|
/* RSP always starts stalled as though we have just reset the processor. */
|
Line 210... |
Line 193... |
int dbg_reset()
|
int dbg_reset()
|
{
|
{
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_reset();
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_reset();
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_reset();
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
void dbg_test() {
|
void dbg_test() {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) usb_dbg_test();
|
if (endpoint_target == ENDPOINT_TARGET_USB) usb_dbg_test();
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) vpi_dbg_test();
|
|
#endif
|
|
}
|
}
|
|
|
/* Set TAP instruction register */
|
/* Set TAP instruction register */
|
int dbg_set_tap_ir(uint32_t ir) {
|
int dbg_set_tap_ir(uint32_t ir) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
Line 238... |
Line 215... |
/* Sets scan chain. */
|
/* Sets scan chain. */
|
int dbg_set_chain(uint32_t chain) {
|
int dbg_set_chain(uint32_t chain) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_set_chain(chain);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_set_chain(chain);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_set_chain(chain);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* sends out a command with 32bit address and 16bit length, if len >= 0 */
|
/* sends out a command with 32bit address and 16bit length, if len >= 0 */
|
int dbg_command(uint32_t type, uint32_t adr, uint32_t len) {
|
int dbg_command(uint32_t type, uint32_t adr, uint32_t len) {
|
Line 258... |
Line 232... |
/* writes a ctrl reg */
|
/* writes a ctrl reg */
|
int dbg_ctrl(uint32_t reset, uint32_t stall) {
|
int dbg_ctrl(uint32_t reset, uint32_t stall) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl(reset, stall);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl(reset, stall);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_ctrl(reset, stall);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* reads control register */
|
/* reads control register */
|
int dbg_ctrl_read(uint32_t *reset, uint32_t *stall) {
|
int dbg_ctrl_read(uint32_t *reset, uint32_t *stall) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl_read(reset, stall);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_ctrl_read(reset, stall);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_ctrl_read(reset, stall);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* issues a burst read/write */
|
/* issues a burst read/write */
|
int dbg_go(unsigned char *data, uint16_t len, uint32_t read) {
|
int dbg_go(unsigned char *data, uint16_t len, uint32_t read) {
|
Line 289... |
Line 257... |
/* read a byte from wishbone */
|
/* read a byte from wishbone */
|
int dbg_wb_read8(uint32_t adr, uint8_t *data) {
|
int dbg_wb_read8(uint32_t adr, uint8_t *data) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read8(adr, data);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read8(adr, data);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_wb_read32(adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
|
|
/* read a word from wishbone */
|
/* read a word from wishbone */
|
int dbg_wb_read32(uint32_t adr, uint32_t *data) {
|
int dbg_wb_read32(uint32_t adr, uint32_t *data) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read32(adr, data);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read32(adr, data);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_wb_read32(adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* write a word to wishbone */
|
/* write a word to wishbone */
|
int dbg_wb_write8(uint32_t adr, uint8_t data) {
|
int dbg_wb_write8(uint32_t adr, uint8_t data) {
|
Line 320... |
Line 282... |
/* write a word to wishbone */
|
/* write a word to wishbone */
|
int dbg_wb_write32(uint32_t adr, uint32_t data) {
|
int dbg_wb_write32(uint32_t adr, uint32_t data) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write32( adr, data);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write32( adr, data);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_wb_write32( adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* read a block from wishbone */
|
/* read a block from wishbone */
|
int dbg_wb_read_block32(uint32_t adr, uint32_t *data, uint32_t len) {
|
int dbg_wb_read_block32(uint32_t adr, uint32_t *data, uint32_t len) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read_block32( adr, data, len);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_read_block32( adr, data, len);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_wb_read_block32( adr, data, len);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* write a block to wishbone */
|
/* write a block to wishbone */
|
int dbg_wb_write_block32(uint32_t adr, uint32_t *data, uint32_t len) {
|
int dbg_wb_write_block32(uint32_t adr, uint32_t *data, uint32_t len) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write_block32( adr, data, len);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_wb_write_block32( adr, data, len);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_wb_write_block32( adr, data, len);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* read a register from cpu */
|
/* read a register from cpu */
|
int dbg_cpu0_read(uint32_t adr, uint32_t *data, uint32_t length) {
|
int dbg_cpu0_read(uint32_t adr, uint32_t *data, uint32_t length) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read( adr, data, length);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read( adr, data, length);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_cpu0_read( adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* write a cpu register */
|
/* write a cpu register */
|
int dbg_cpu0_write(uint32_t adr, uint32_t *data, uint32_t length) {
|
int dbg_cpu0_write(uint32_t adr, uint32_t *data, uint32_t length) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write( adr, data, length);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write( adr, data, length);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_cpu0_write( adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
/* write a cpu module register */
|
/* write a cpu module register */
|
int dbg_cpu0_write_ctrl(uint32_t adr, unsigned char data) {
|
int dbg_cpu0_write_ctrl(uint32_t adr, unsigned char data) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write_ctrl( adr, data);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_write_ctrl( adr, data);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_cpu0_write_ctrl( adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
|
|
/* read a register from cpu module */
|
/* read a register from cpu module */
|
int dbg_cpu0_read_ctrl(uint32_t adr, unsigned char *data) {
|
int dbg_cpu0_read_ctrl(uint32_t adr, unsigned char *data) {
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read_ctrl( adr, data);
|
if (endpoint_target == ENDPOINT_TARGET_USB) return usb_dbg_cpu0_read_ctrl( adr, data);
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (endpoint_target == ENDPOINT_TARGET_VPI) return vpi_dbg_cpu0_read_ctrl( adr, data);
|
|
#endif
|
|
return DBG_ERR_INVALID_ENDPOINT;
|
return DBG_ERR_INVALID_ENDPOINT;
|
}
|
}
|
|
|
|
|
void test_sdram(void) {
|
void test_sdram(void) {
|
Line 402... |
Line 343... |
|
|
// Close down gracefully when we receive any kill signals
|
// Close down gracefully when we receive any kill signals
|
void catch_sigint(int sig_num)
|
void catch_sigint(int sig_num)
|
{
|
{
|
// Close down any potentially open sockets and USB handles
|
// Close down any potentially open sockets and USB handles
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
if (vpi_fd) close(vpi_fd);
|
|
#endif
|
|
if (server_fd) close(server_fd);
|
if (server_fd) close(server_fd);
|
gdb_close();
|
gdb_close();
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
usb_close_device_handle();
|
usb_close_device_handle();
|
#endif
|
#endif
|
Line 425... |
Line 363... |
printf("server_type:\n");
|
printf("server_type:\n");
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
printf("\t-r Start a server using RSP, connection to hadware target via\n\t USB\n");
|
printf("\t-r Start a server using RSP, connection to hadware target via\n\t USB\n");
|
printf("\t-j Start a server using legacy OR remote JTAG protocol, to\n\t hardware target via USB\n");
|
printf("\t-j Start a server using legacy OR remote JTAG protocol, to\n\t hardware target via USB\n");
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
printf("\t-v Start a server using RSP, connection to RTL sim. VPI server\n\t target via sockets\n");
|
|
#endif
|
|
printf("\n");
|
printf("\n");
|
printf("port:\n");
|
printf("port:\n");
|
printf("\tAny free port within the usable range of 0 - 65535\n");
|
printf("\tAny free port within the usable range of 0 - 65535\n");
|
printf("\n");
|
printf("\n");
|
printf("Example:\n");
|
printf("Example:\n");
|
#ifdef USB_ENDPOINT_ENABLED
|
#ifdef USB_ENDPOINT_ENABLED
|
printf("\tStart a GDB server on port 5555, using RSP, connecting to\n\thardware target via USB\n");
|
printf("\tStart a GDB server on port 5555, using RSP, connecting to\n\thardware target via USB\n");
|
printf("\tor_debug_proxy -r 5555\n");
|
printf("\tor_debug_proxy -r 5555\n");
|
printf("\n");
|
printf("\n");
|
#endif
|
#endif
|
#ifdef VPI_ENDPOINT_ENABLED
|
|
printf("\tStart a GDB server on port 5555, using RSP, connecting to\n\trtl target via VPI\n");
|
|
printf("\tor_debug_proxy -v 5555\n");
|
|
printf("\n");
|
|
#endif
|
|
fflush (stdout);
|
fflush (stdout);
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|