Line 30... |
Line 30... |
|
|
/* Dirty way to include inb and outb from, but they say it is
|
/* Dirty way to include inb and outb from, but they say it is
|
a standard one. */
|
a standard one. */
|
#include <asm/io.h>
|
#include <asm/io.h>
|
#include <asm/system.h>
|
#include <asm/system.h>
|
|
#include "mc.h"
|
|
|
#define GDB_IN "../sim/rtl_sim/run/gdb_in.dat"
|
#define GDB_IN "../sim/rtl_sim/run/gdb_in.dat"
|
#define GDB_OUT "../sim/rtl_sim/run/gdb_out.dat"
|
#define GDB_OUT "../sim/rtl_sim/run/gdb_out.dat"
|
|
|
/* Libraries for JTAG proxy server. */
|
/* Libraries for JTAG proxy server. */
|
Line 71... |
Line 72... |
#define TMS_BIT (0x08) /* D0, pin #5 */
|
#define TMS_BIT (0x08) /* D0, pin #5 */
|
#define TDO_BIT (0x20) /* PE, pin #12 */
|
#define TDO_BIT (0x20) /* PE, pin #12 */
|
#define TMS (0x02)
|
#define TMS (0x02)
|
#define TDI (0x01)
|
#define TDI (0x01)
|
#else
|
#else
|
|
#ifdef XILINX
|
|
#define TCLK_BIT (0x02) /* D1 pin 3 */
|
|
#define TRST_BIT (0x10) /* Not used */
|
|
#define TDI_BIT (0x01) /* D0 pin 2 */
|
|
#define TMS_BIT (0x04) /* D2 pin 4 */
|
|
#define TDO_BIT (0x10) /* S6 pin 13*/
|
|
#define TMS (0x02)
|
|
#define TDI (0x01)
|
|
//#define TDO_INV
|
|
#else
|
#define TCLK_BIT (0x04) /* D2 pin 4 */
|
#define TCLK_BIT (0x04) /* D2 pin 4 */
|
#define TRST_BIT (0x08) /* D3 pin 5 */
|
#define TRST_BIT (0x08) /* D3 pin 5 */
|
#define TDI_BIT (0x10) /* D4 pin 6 */
|
#define TDI_BIT (0x10) /* D4 pin 6 */
|
#define TMS_BIT (0x20) /* D5 pin 7 */
|
#define TMS_BIT (0x20) /* D5 pin 7 */
|
#define TDO_BIT (0x20) /* S5 pin 12*/
|
#define TDO_BIT (0x20) /* S5 pin 12*/
|
#define TMS (0x02)
|
#define TMS (0x02)
|
#define TDI (0x01)
|
#define TDI (0x01)
|
#endif
|
#endif
|
|
#endif
|
#ifdef RTL_SIM
|
#ifdef RTL_SIM
|
# define JTAG_WAIT() usleep(1000)
|
# define JTAG_WAIT() usleep(1000)
|
# define NUM_RETRIES (16)
|
# define NUM_RETRIES (16)
|
# define JTAG_RETRY_WAIT() usleep (1000)
|
# define JTAG_RETRY_WAIT() usleep (1000)
|
#else
|
#else
|
Line 217... |
Line 229... |
inline static unsigned char
|
inline static unsigned char
|
jp1_in () {
|
jp1_in () {
|
int data;
|
int data;
|
#ifndef RTL_SIM
|
#ifndef RTL_SIM
|
data = inb (LPT_READ);
|
data = inb (LPT_READ);
|
|
#ifdef TDO_INV
|
|
data = (data & TDO_BIT) != TDO_BIT;
|
|
#else
|
data = (data & TDO_BIT) == TDO_BIT;
|
data = (data & TDO_BIT) == TDO_BIT;
|
|
#endif
|
#else
|
#else
|
FILE *fin = 0;
|
FILE *fin = 0;
|
char ch;
|
char ch;
|
time_t time;
|
time_t time;
|
struct stat s;
|
struct stat s;
|
Line 346... |
Line 362... |
{
|
{
|
int i;
|
int i;
|
debug2 ("\nreset(");
|
debug2 ("\nreset(");
|
jp1_out (0);
|
jp1_out (0);
|
JTAG_RETRY_WAIT();
|
JTAG_RETRY_WAIT();
|
|
/* In case we don't have TRST reset it manually */
|
|
for (i = 0; i < 8; i++)
|
|
jp1_write_JTAG (TMS);
|
jp1_out (TRST_BIT);
|
jp1_out (TRST_BIT);
|
JTAG_RETRY_WAIT();
|
JTAG_RETRY_WAIT();
|
jp1_write_JTAG (0);
|
jp1_write_JTAG (0);
|
debug2(")\n");
|
debug2(")\n");
|
select_dr = 0;
|
select_dr = 0;
|
Line 609... |
Line 628... |
jtag_write_reg (regno, data)
|
jtag_write_reg (regno, data)
|
int regno;
|
int regno;
|
ULONGEST data;
|
ULONGEST data;
|
{
|
{
|
/* Set PC */
|
/* Set PC */
|
if (current_chain == SC_RISC_DEBUG && regno == 0x10)
|
// if (current_chain == SC_RISC_DEBUG && regno == 0x10)
|
data = data - 4;
|
// data = data - 4;
|
|
|
jtag_write_reg_support (regno, data);
|
jtag_write_reg_support (regno, data);
|
}
|
}
|
|
|
/* Stalls the CPU. */
|
/* Stalls the CPU. */
|
Line 647... |
Line 666... |
jtag_init () {
|
jtag_init () {
|
int tmp, i;
|
int tmp, i;
|
unsigned int npc, ppc, r1, insn, result;
|
unsigned int npc, ppc, r1, insn, result;
|
current_chain = -1;
|
current_chain = -1;
|
jp1_reset_JTAG ();
|
jp1_reset_JTAG ();
|
|
#if 0
|
|
#define MC_BASE_ADD 0x60000000
|
|
#define MC_CSR_VAL 0x04300300
|
|
#define MC_MASK_VAL 0x000000ff
|
|
#define FLASH_BASE_ADD 0x04000000
|
|
#define FLASH_TMS_VAL 0x0010a10a
|
|
#define SDRAM_BASE_ADD 0x00000000
|
|
#define SDRAM_TMS_VAL 0x07248230
|
|
|
|
jtag_set_chain (SC_REGISTER);
|
|
jtag_write_reg (4, 0x00000001);
|
|
|
|
jtag_set_chain (SC_WISHBONE);
|
|
jtag_write_reg (MC_BASE_ADD + MC_CSC(0), (((FLASH_BASE_ADD & 0xffff0000) >> 5) | 0x25));
|
|
jtag_write_reg (MC_BASE_ADD + MC_TMS(0), FLASH_TMS_VAL);
|
|
|
|
jtag_write_reg (MC_BASE_ADD + MC_BA_MASK, MC_MASK_VAL);
|
|
jtag_write_reg (MC_BASE_ADD + MC_CSR, MC_CSR_VAL);
|
|
|
|
jtag_write_reg (MC_BASE_ADD + MC_TMS(1), SDRAM_TMS_VAL);
|
|
jtag_write_reg (MC_BASE_ADD + MC_CSC(1), (((SDRAM_BASE_ADD & 0xffff0000) >> 5) | 0x0411));
|
|
|
|
sleep(1);
|
|
#endif
|
|
|
#if 1
|
#if 1
|
|
|
#define RAM_BASE 0x40000000
|
#define RAM_BASE 0x00000000
|
/* Stall risc */
|
/* Stall risc */
|
jtag_set_chain (SC_REGISTER);
|
jtag_set_chain (SC_REGISTER);
|
jtag_write_reg (4, 0x00000001);
|
jtag_write_reg (4, 0x00000001);
|
|
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
Line 708... |
Line 751... |
/* Read R1 */
|
/* Read R1 */
|
jtag_set_chain (SC_RISC_DEBUG);
|
jtag_set_chain (SC_RISC_DEBUG);
|
r1 = jtag_read_reg (0x401);
|
r1 = jtag_read_reg (0x401);
|
r1 = jtag_read_reg (0x401);
|
r1 = jtag_read_reg (0x401);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x4000000c, 0x40000024, 5);
|
result = npc + ppc + r1;
|
result = npc + ppc + r1;
|
|
|
|
|
/* Reset step bit */
|
/* Reset step bit */
|
jtag_set_chain (SC_RISC_DEBUG);
|
jtag_set_chain (SC_RISC_DEBUG);
|
Line 748... |
Line 792... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x24, insn);
|
jtag_write_reg (RAM_BASE + 0x24, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x4000000c, 0x40000024, 8);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
|
|
/* Set trap insn in place of branch insn */
|
/* Set trap insn in place of branch insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
Line 786... |
Line 831... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x20, insn);
|
jtag_write_reg (RAM_BASE + 0x20, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x40000024, 0x40000020, 11);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
|
|
/* Set trap insn before branch insn */
|
/* Set trap insn before branch insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
Line 824... |
Line 870... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x1c, insn);
|
jtag_write_reg (RAM_BASE + 0x1c, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x40000020, 0x4000001c, 24);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
|
|
/* Set trap insn behind lsu insn */
|
/* Set trap insn behind lsu insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
Line 862... |
Line 909... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x18, insn);
|
jtag_write_reg (RAM_BASE + 0x18, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x4000001c, 0x40000018, 49);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
/* Set trap insn very near previous one */
|
/* Set trap insn very near previous one */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
insn = jtag_read_reg (RAM_BASE + 0x1c);
|
insn = jtag_read_reg (RAM_BASE + 0x1c);
|
Line 899... |
Line 947... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x1c, insn);
|
jtag_write_reg (RAM_BASE + 0x1c, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x40000020, 0x4000001c, 50);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
|
|
/* Set trap insn to the start */
|
/* Set trap insn to the start */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
Line 937... |
Line 986... |
|
|
/* Set back original insn */
|
/* Set back original insn */
|
jtag_set_chain (SC_WISHBONE);
|
jtag_set_chain (SC_WISHBONE);
|
jtag_write_reg (RAM_BASE + 0x0c, insn);
|
jtag_write_reg (RAM_BASE + 0x0c, insn);
|
|
|
printf("npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x40000010, 0x4000000c, 99);
|
|
result = npc + ppc + r1 + result;
|
|
|
|
|
|
/* Set step bit */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
jtag_write_reg ((6 << 11) + 16, 1 << 22);
|
|
|
|
for (i = 0; i < 5; i++)
|
|
{
|
|
/* Unstall */
|
|
jtag_set_chain (SC_REGISTER);
|
|
jtag_write_reg (4, 0x00000000);
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
}
|
|
|
|
/* Read NPC */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
npc = jtag_read_reg ((0 << 11) + 16);
|
|
npc = jtag_read_reg ((0 << 11) + 16);
|
|
|
|
/* Read PPC */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
ppc = jtag_read_reg ((0 << 11) + 18);
|
|
ppc = jtag_read_reg ((0 << 11) + 18);
|
|
|
|
/* Read R1 */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
r1 = jtag_read_reg (0x401);
|
|
r1 = jtag_read_reg (0x401);
|
|
|
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x40000024, 0x40000020, 101);
|
|
result = npc + ppc + r1 + result;
|
|
|
|
/* Set PC */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
jtag_write_reg ((0 << 11) + 16, RAM_BASE + 0x20);
|
|
|
|
for (i = 0; i < 2; i++)
|
|
{
|
|
/* Unstall */
|
|
jtag_set_chain (SC_REGISTER);
|
|
jtag_write_reg (4, 0x00000000);
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
}
|
|
|
|
/* Read NPC */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
npc = jtag_read_reg ((0 << 11) + 16);
|
|
npc = jtag_read_reg ((0 << 11) + 16);
|
|
|
|
/* Read PPC */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
ppc = jtag_read_reg ((0 << 11) + 18);
|
|
ppc = jtag_read_reg ((0 << 11) + 18);
|
|
|
|
/* Read R1 */
|
|
jtag_set_chain (SC_RISC_DEBUG);
|
|
r1 = jtag_read_reg (0x401);
|
|
r1 = jtag_read_reg (0x401);
|
|
|
|
printf("Read npc = %.8lx ppc = %.8lx r1 = %.8lx\n", npc, ppc, r1);
|
|
printf("Expected npc = %.8lx ppc = %.8lx r1 = %.8lx\n", 0x4000000c, 0x40000024, 201);
|
result = npc + ppc + r1 + result;
|
result = npc + ppc + r1 + result;
|
|
|
printf("result = %.8lx\n", result + 0x5eaddc4b);
|
printf("result = %.8lx\n", result + 0x5eaddaa9);
|
|
|
#endif
|
#endif
|
|
|
return err;
|
return err;
|
}
|
}
|