📄 xds510.cpp
字号:
/*
* xds510 simulator for Wine
* Copyright (c) 2001 Blaise Gassend (blaise.gassend@m4x.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. This program is
* distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. You should have received a
* copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
* */
// This code assumes at least 32-bit ints as does wine.
#define PAR_ADDR (0x378)
#include <stdio.h>
#include "xds510.h"
#include "xds510_io.h"
#ifndef _WINDOWS
#include "debugtools.h"
#else
#include "..\stdafx.h"
#define MESSAGE TRACE
#define WARN TRACE
#define FIXME TRACE
#define DECLARE_DEBUG_CHANNEL(X)
#define DEFAULT_DEBUG_CHANNEL(X)
int state_id(int s)
{
s &= 0x7;
if (s < 4)
return s / 2;
else
return s - 2;
}
#endif
DECLARE_DEBUG_CHANNEL(xds510);
DEFAULT_DEBUG_CHANNEL(xds510);
#define BTAB "\t\t\t\t"
#define INTERFACE_VERSION (6)
static int interface_interrupt;
//static int read800;
static int interface_reset;
static int counter1;
static int counter1_update;
static int counter1_capture;
static int active_command;
#define NUM_LOW_REGISTERS (0xC)
#define NUM_STATUS_REGISTERS (4)
static int low_register_val[NUM_LOW_REGISTERS];
static int status_register[NUM_STATUS_REGISTERS];
static int fifo_buffer;
static unsigned int read_buffer;
static int read_buffer_pos;
static unsigned int write_buffer;
static int write_buffer_pos;
#define TAP_TEST_LOGIC_RESET (0)
#define TAP_RUN_TEST_IDLE (2)
#define TAP_SHIFT_DR (4)
#define TAP_SHIFT_IR (5)
#define TAP_PAUSE_DR (6)
#define TAP_PAUSE_IR (7)
static int tap_state;
//static FILE *debugf; // ####
//static int outdata, indata, indatap, outdatap, databitsp;
int get_outbit()
{
int outbit;
switch (low_register_val[4] & 0x0300)
{
default:
case 0x0000:
outbit = 0;
break;
case 0x0100:
outbit = 1;
break;
case 0x0200:
outbit = fifo_buffer & 1;
break;
case 0x0300:
outbit = write_buffer & 1;
break;
}
return outbit;
}
/*static void tap_log(int tms, int tdo, int tdi)
{
void printbuff(unsigned char *buff, int len)
{
int i;
int bytes = len / 8;
int bits = len % 8;
int mask = 1 << bits;
for (i = 0; i < bytes; i++)
{
fprintf(debugf, "%02x", (int) buff[i]);
}
if (bits > 0)
{
buff[bytes] &= mask - 1;
fprintf(debugf, "%0*x", (bits + 3) / 4, buff[bytes]);
}
}
static unsigned char inbuff[256];
static unsigned char outbuff[256];
static int buffp = 0;
static int state = 0; // 0 reset, 1 run, then DR top to bot, ir top to bot.
static int trans[2][16] =
{ { 1, 1, 3, 4, 4, 6, 6, 4, 1, 10, 11, 11, 13, 13, 11, 1 },
{ 0, 2, 9, 5, 5, 8, 7, 8, 2, 0, 12, 12, 15, 14, 15, 2 } };
if (state == 4 || state == 11) // Shifting
{
int byte = buffp / 8;
int bit = buffp % 8;
int mask = 1 << bit;
if (buffp < 2048)
{
inbuff[byte] = (inbuff[byte] & (mask - 1)) | (tdi ? mask : 0);
outbuff[byte] = (outbuff[byte] & (mask - 1)) | (tdo ? mask : 0);
buffp++;
}
}
state = trans[tms][state & 0xF];
switch (state)
{
case 0: // reset
fputs("RESET ", debugf);
break;
case 1: // run
fputs("RUN ", debugf);
break;
case 8: // update dr
fprintf(debugf, "\n DRU %i ", buffp);
printbuff(outbuff, buffp);
fputs(" -> ", debugf);
printbuff(inbuff, buffp);
fputc(' ', debugf);
fflush(debugf);
buffp = 0;
break;
case 15: // update ir
fprintf(debugf, "\nIRU %i ", buffp - 16);
printbuff(outbuff + 2, buffp - 16);
fputs(" -> ", debugf);
printbuff(inbuff, buffp - 16);
fputc(' ', debugf);
fflush(debugf);
buffp = 0;
break;
}
}
*/
static int io_cycle(int tms)
{
int tdo = get_outbit();
int tdi = xds510_io_write_cycle(tdo, tms);
// tap_log(tms, tdo, tdi);
return tdi;
}
static void XDS510_reset()
{
int i;
TRACE("XDS510_reset\n");
counter1 = 0;
counter1_update = 0;
counter1_capture = 0;
interface_interrupt = 0;
// read800 = 0;
active_command = 0;
fifo_buffer = 0xFFFFFFFF;
read_buffer = 0;
read_buffer_pos = 0;
write_buffer = 0;
write_buffer_pos = 0;
/* for (i = 0; i < 6; i++)
{
io_cycle(1);
}
io_cycle(0); */
tap_state = TAP_TEST_LOGIC_RESET;
for (i = 0; i < NUM_LOW_REGISTERS; i++)
low_register_val[i] = 0;
for (i = 0; i < NUM_STATUS_REGISTERS; i++)
status_register[i] = 0;
TRACE("returning\n\n");
}
void XDS510_init()
{
TRACE("XDS510_init\n");
if (xds510_io_init(PAR_ADDR))
{
MESSAGE("\n\n***** Root privileges necessary to access XDS510.\n\n");
}
else
{
MESSAGE("\n\n***** XDS510 on port 0x%03x.\n\n", PAR_ADDR);
}
// if (debugf == NULL)
// debugf = /*stderr; /*/fopen("debug.txt", "w");
xds510_io_write_trst(0);
io_cycle(1);
xds510_io_write_trst(1);
io_cycle(1);
XDS510_reset();
}
static void go_tap_state(int state)
{
// The order is RESET, RUN, S-DR, S-IR, P-DR, P-IR
static const char *transitions[6][6] = { // [from][to]
{ "11111", "0", "0100", "01100", "01010", "011010" },
{ "11111", "0", "100", "1100", "1010", "11010" },
{ "11111", "110", "0", "111100", "10", "1111010" },
{ "11111", "110", "11100", "0", "111010", "10" },
{ "11111", "110", "10", "111100", "0", "1111010" },
{ "11111", "110", "11100", "10", "111010", "0" } };
int i;
#ifndef _WINDOWS
int state_id(int s)
{
s &= 0x7;
if (s < 4)
return s / 2;
else
return s - 2;
}
#endif
const char *trans = transitions[state_id(tap_state)][state_id(state)];
// printf("Goto Tap %i From %i\n", state, tap_state);
while (*trans)
{
io_cycle(*trans - '0');
trans++;
}
if ((state & 0x6) == 2)
for (i = 0; i < 10; i++)
io_cycle(0);
tap_state = state & 0x7;
}
static void go_tap_state2(int state)
{
// The order is RESET, RUN, S-DR, S-IR, P-DR, P-IR
static const char *transitions[6][6] = { // [from][to]
{ "11111", "0", "0100", "01100", "01010", "011010" },
{ "11111", "0", "100", "1100", "1010", "11010" },
{ "11111", "110", "0", "111100", "10", "1111010" },
{ "11111", "110", "11100", "0", "111010", "10" },
{ "11111", "110", "10", "111100", "111010", "1111010" },
{ "11111", "110", "11100", "10", "111010", "1111010" } };
int i;
#ifndef _WINDOWS
int state_id(int s)
{
s &= 0x7;
if (s < 4)
return s / 2;
else
return s - 2;
}
#endif
const char *trans = transitions[state_id(tap_state)][state_id(state)];
// printf("Goto Tap 2 %i From %i\n", state, tap_state);
while (*trans)
{
io_cycle(*trans - '0');
trans++;
}
if ((state & 0x6) == 2)
for (i = 0; i < 10; i++)
io_cycle(0);
tap_state = state & 0x7;
}
static void minor_command(int value)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -