📄 ctc.c
字号:
/*
COPYRIGHT (c) 1996 by Philips Semiconductors
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor.
PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
*/
/*
Copyright (c) 1996 Philips Semiconductors - TriMedia. All rights reserved.
FILE ctc.c
HISTORY :
#define TR Tilakraj Roy
960201 TR Created ( Tilakraj Roy )
960213 TR Added stuff for calling vtmman - the to be TriMedia manager
960217 TR Added thread for waiting for exit code and printf
960218 TR Added PCI register configuration stuff
960221 TR Added flags for SDRAM size and hardware emulation
960222 TR Added the TE command ( Jim's request )
Release 1.00
960222 TR Pass linear addx instead of physical addx to TaskTest
960222 TR All a halGetSDRAMLen function.
960222 TR BUG: Go does not check for first time running.
Release 2.00
960223 TR hal to allocate virtual mem for SDRAM emulation.
960223 TR Disabled ThreadFunc during TE command.
960223 TR Changed GetNextToken to allow any character in a string.
Release 3.00
960223 JS Added function ctc_output ( Jim Schimandle )
960223 JS Made Parser as a global structure.
960223 JS Changed printfs to fprintf ( stdout )
960223 TR Changed ThreadFunc to destroy itself when debugger exits.
Release 4.00
960232 TR Added the set param function to set the bus, dev and func
960223 TR Check for PCI return status.
960223 TR Include Bus Dev and Func in PCI read.
960223 TR Change printf after halInit to fprintf (stdout)
960223 TR Go ahead even if halInit fails.
Release 5.00
960228 TR Added parameters to TE command
960228 TR Command can be terminated by CR and LF.
Release 10.00
960229 TR Fixed a communicaiton bug resulting in missing character.
960229 TR Initialization of PCi transfer address.
Release 11.00
960229 TR Decreased EXIT_VALUE, PRINT_SEMAPHORE,PRINT_value offsets.
Release 12.00
960305 TR Added version information
960305 TR Initialized parser->dwExitValue with 0x7fffffff
Release 13.00
960306 TR Added reset using LPT and IIC interface.
960306 TR Added re-writing of saves PCI configuration.
960306 TR Started adding the system call routines
Release 14.00
960308 TR Added code for clearing BSS at loading time.
960309 TR Completed adding the system call routines.
960309 TR Added command for examining DMA memory on PC
960329 TR Added code for isatty and link
960405 TR Added the SI,EI, SO,EO commands
960406 TR Removed support for legacy features
960406 TR Introduced vtmman version checking.
Release 15.00
960506 TR Exit code monitoring thread disabled.
960506 TR pe command added to print exit code.
960508 TR Support for new TD format.
ASR 2.0
Version 4.1.27
961113 TR State Machine for image loading, running and stopping
961114 TR Added GetComputerName() for trace file
961114 TR Added reading of SDRAM and MMIO locations modified.
961114 TR Added killing RPCServ threads in ST_CMD
Version 4.1.27
961202 TR Added back SS_CMD support.
COMMNETS
Developed for the CTC test program for TriMedia.
Uses Win32 calls for File I/O and Communicaitons.
Uses stdio calls for Con I/O.
For JTAG specific interface change pcihal.c
PCI interface requires file vtmman.vxd to run.
*/
#include "windows.h"
#include "stdio.h"
#include "fcntl.h"
#include "io.h"
#include "time.h"
#include "sys\stat.h"
#include "stdcom.h"
#include "iodev.h"
#include "cons.h"
#include "comm.h"
#include "file.h"
#include "tmwincom.h"
#include "tmman32.h"
#include "tmif.h"
#include "pcihal.h"
#include "test.h"
#include "tmhd.h"
#include "verinfo.h"
#include "tmobj.h"
#undef USE_RPCSERV
#define MAX_STRING 256
#define TM_IRQ_GO 28
#define L2_STDIN_HANDLE 0
#define L2_STDOUT_HANDLE 1
#define L2_STDERR_HANDLE 2
#define MAX_ARGUMENT_COUNT 256
#define MAX_ARGUMENT_BUFFER 1024
#define PROG_STATE_NOTINIT 1
#define PROG_STATE_LOADED 2
#define PROG_STATE_STARTED 3
#define PROG_STATE_STOPPED 4
// DECLERATIONS
typedef struct _CMD_ENTRY
{
PSTR pszCmd; /* command strings for debug commands */
WORD wCmdState; /* initial state for this command */
} CMD_ENTRY, *PCMD_ENTRY;
typedef struct _EXE_VERSION
{
// new fields to be added for version control
DWORD dwMagicNumber; // TM1[0xaa] 0x544d31aa
WORD wFlags;
BYTE bMinorVersion; //0x00
BYTE bMajorVersion; //0x01
} EXE_VERSION, *PEXE_VERSION;
typedef struct _EXE_HEADER
{
DWORD dwPtrArgc;
DWORD dwPtrArgv;
DWORD dwPtrMMIOBase;
DWORD dwPtrBeginHeap;
DWORD dwPtrEndHeap;
DWORD dwPCIXferAddress;
DWORD dwBSSEnd;
} EXE_HEADER, *PEXE_HEADER;
typedef struct _EXE_HEADER0
{
DWORD dwStartAddress;
DWORD dwPtrArgc;
DWORD dwPtrArgv;
DWORD dwPtrMMIOBase;
DWORD dwPtrBeginHeap;
DWORD dwPtrEndHeap;
DWORD dwPtrPCIXferAddress;
DWORD dwPtrPCIXferLength;
DWORD dwPtrSystemXferAddress;
DWORD dwPtrSystemXferLength;
DWORD dwPtrCRTXferAddress;
DWORD dwPtrCRTXferLength;
DWORD dwExitAddress;
DWORD dwBSSEnd;// additional fields required
} EXE_HEADER0, *PEXE_HEADER0;
typedef struct _CMD_LD_PARAM
{
DWORD dwCountArg;
DWORD dwIdxArgStr;
BOOL fDynamicApplicaiton; /* szApplicaitonFile field is valid */
CHAR szExecutableFile[MAX_PATH];
CHAR szApplicationFile[MAX_PATH];
PVOID ArgumentPtr[MAX_ARGUMENT_COUNT];
CHAR ArgumentBuffer[MAX_ARGUMENT_BUFFER];
} CMD_LD_PARAM, *PCMD_LD_PARAM;
/*
typedef struct _CMD_SX_PARAM
{
DWORD dwFile;
BOOL fFlag;
} CMD_SX_PARAM, *PCMD_SX_PARAM;
*/
typedef struct _PARSER
{
/* persistent storage */
WORD wState; /* state of the parser FSM */
WORD wDataSize; /* word size for current command */
DWORD dwAddress;
DWORD dwData;
DWORD dwLength;
DWORD dwStartAddress; /* address where the writing started */
BOOL fSDRAM; /* is this address in SDRAM range */
PVOID pTMHW; /* pointer to tm h/w information */
DWORD dwScreenSize; /* number of lines to scroll and stop */
DWORD dwLinesWritten;
PVOID pDevice;
// DWORD dwPCIRegister;
// DWORD dwExitValue;
DWORD dwIdxArgStr;
// DWORD dwCountArg;
// BOOL fExitDebugger;
BOOL fSerial;
BOOL fServerLoaded;
HANDLE hCRTThread;
DWORD dwCRTThreadID;
DWORD dwTaskTestArgCount;
DWORD dwExecutableStartAddress;
DWORD dwExecutableExitAddress;
// added for debug options and trace commands
BOOL DebugOn;
DWORD DebugOptions;
BOOL fTraceIntoFile;
DWORD ProgramState;
PFILE_VTBL pFileVtbl;
CMD_LD_PARAM CmdLDParam;
TMMAN_TMCONS_PARAMS TMCons;
/* function pointers */
BOOL (*ReadChar)(PVOID pDevice, PVOID pBuffer, DWORD dwLength);
BOOL (*WriteChar)(PVOID pDevice, PVOID pBuffer, DWORD dwLength);
BOOL (*WriteStr)(PVOID pDevice, PSTR szString );
VOID (*GetHandles)(PVOID pDevice, HANDLE *, HANDLE *, HANDLE *);
VOID (*Close)(PVOID pDevice);
/* string placeholders */
CHAR szOutputString[MAX_STRING];
CHAR szInputString[MAX_STRING];
CHAR szPrompt[MAX_STRING];
CHAR szTestName[MAX_STRING];
CHAR szTraceFileName[MAX_STRING]; /* trace filename */
} PARSER, *PPARSER;
/* INSTANCIATION */
enum ParserState
{ CMD_WAIT,
RB_CMD, RW_CMD, RD_CMD, RX_ADDRESS, RX_LENGTH,
WB_CMD, WW_CMD, WD_CMD, WX_ADDRESS, WX_DATA,
PF_CMD, PF_ADDRESS, PF_LENGTH, PF_FILENAME,
GF_CMD, GF_ADDRESS, GF_FILENAME,
GI_CMD,
LD_CMD, LD_FILENAME, LD_ARGS,
GO_CMD,
SS_CMD, SS_SIZE,
QU_CMD,
HL_CMD,
TE_CMD, TE_ARGS,
SP_CMD, SP_PARAM,
CF_CMD,
RE_CMD,
RL_CMD, RL_ADDRESS, RL_LENGTH,
WL_CMD, WL_ADDRESS, WL_DATA,
SI_CMD, SI_FILENAME,
EI_CMD,
SO_CMD, SO_FILENAME,
EO_CMD,
SE_CMD, SE_FILENAME,
EE_CMD,
HE_CMD,
ST_CMD,
DEBUGON_CMD, DEBUGON_OPTIONS,
DEBUGOFF_CMD, DEBUGOFF_OPTIONS,
TRACEV_CMD,
TRACEP_CMD, TRACEP_FILENAME
};
/* update this when command table size changes */
CMD_ENTRY CmdTable[] = {
/* implemented */
{ "RB", RB_CMD }, /* Read Memory */
{ "RW", RW_CMD },
{ "RD", RD_CMD },
{ "WB", WB_CMD }, /* Write Memory */
{ "WW", WW_CMD },
{ "WD", WD_CMD },
{ "PF", PF_CMD }, /* Put File */
{ "GF", GF_CMD }, /* Get File */
{ "GI", GI_CMD }, /* Generate Interrupt */
{ "LD", LD_CMD }, /* Load Executable */
{ "SS", SS_CMD }, /* Scroll Size */
{ "QU", QU_CMD }, /* Quit Debugger */
{ "HL", HL_CMD }, /* Help */
{ "GO", GO_CMD }, /* Go - Execute*/
{ "TE", TE_CMD }, /* task execute */
{ "SP", SP_CMD }, /* set parameters */
{ "RE", RE_CMD }, /* Reset command */
{ "RL", RL_CMD }, /* Read Local Memory */
{ "WL", WL_CMD }, /* Write Local Memory */
/* NEW Commands */
{ "SI", SI_CMD }, /* Start Log NI*/
{ "EI", EI_CMD }, /* End Log NI*/
{ "SO", SO_CMD }, /* Start Log NI*/
{ "EO", EO_CMD }, /* End Log NI*/
{ "SE", SE_CMD }, /* Start Log NI*/
{ "EE", EE_CMD }, /* End Log NI*/
{ "ST", ST_CMD }, /* Stop TriMedia Code */
/* NOVICE COMMANDS */
{ "HELP", HL_CMD }, /* Help Command */
{ "QUIT", QU_CMD },
{ "BYE", QU_CMD },
{ "EXIT", QU_CMD },
{ "LOAD", LD_CMD },
{ "START", GO_CMD },
{ "RUN", GO_CMD },
{ "STOP", ST_CMD },
{ "HALT", ST_CMD },
{ "DEBUGON", DEBUGON_CMD },
{ "DEBUGOFF", DEBUGOFF_CMD },
{ "TRACEP", TRACEP_CMD },
{ "DP", TRACEP_CMD },
{ "TRACEV", TRACEV_CMD },
{ "DV", TRACEV_CMD },
};
typedef BOOL (*PINITFUNC)(
PVOID open,
PVOID close,
PVOID read,
PVOID write,
PVOID seek,
PVOID isatty,
PVOID fstat,
PVOID Argc,
PVOID Argv,
PVOID exit,
DWORD ServerCount,
DWORD Stdin,
DWORD Stdout,
DWORD Stderr );
typedef VOID (*PEXITFUNC)(VOID);
DWORD MaxCommands = sizeof (CmdTable) / sizeof ( CMD_ENTRY );
PARSER Parser;
TM_HW TMHW;
PINITFUNC pRPCServInitFunc = NULL;
PEXITFUNC pRPCServExitFunc = NULL;
BOOL IsValidHex ( PSTR pszString, DWORD dwSize );
BOOL GetNextToken( PBYTE pszString, PWORD pwPosition,
PBYTE pszToken );
BOOL ReadInputLine (PVOID pDevice, PSTR pszInputString);
BOOL ProcessLine ( PVOID pContext );
BOOL ScreenScroll ( PVOID pContext );
BOOL ValidateData ( WORD wDataSize, DWORD dwData);
DWORD WINAPI ThreadFunction ( PVOID pContext );
DWORD WINAPI CRTServiceThread ( PVOID pContext );
BOOL ctcLoadExecuteable ( PPARSER pParser, PCMD_LD_PARAM this );
BOOL ctcStartExecuteable ( PPARSER pParser );
BOOL ctcStopExecuteable ( PPARSER pParser );
DWORD GetDebugBit ( PCHAR szToken );
char *ctcGetDownloaderErrorString ( DWORD Code );
/*----------------------------------------------------------------------------
FUNC GetNextToken
ABOUT
Given a CR terminated line this function returns the next available
token, skipping all preceeding white spaces.
----------------------------------------------------------------------------*/
BOOL GetNextToken( PBYTE pszString, PWORD pwPosition,
PBYTE pszToken )
{
// the different states of the Finite State Machine
enum { GNT_WHITE_SPACE, GNT_ALPHA, GNT_NUM };
WORD wState = GNT_WHITE_SPACE, fExit = 0;
while ( ! fExit )
{
switch ( wState )
{
case GNT_WHITE_SPACE:
// check if the string starts with a NULL
if ( pszString[*pwPosition] == '\0' )
{
return FALSE ;
}
// check for white space
//TR960223
if ( ( iscntrl ( pszString[*pwPosition] ) )||
( isspace ( pszString[*pwPosition] ) ) )
//( pszString[*pwPosition] == ' ') )
{
// go to the next character
*pwPosition = *pwPosition + 1;
break;
}
// all character that are not whitespace or control are
// valid token characters.
// check for alphabetiacal characters.
//if ( isalnum ( pszString[*pwPosition] ) )
// TR960223
{
*pszToken++ = pszString[*pwPosition];
*pwPosition = *pwPosition + 1;
wState = GNT_ALPHA;
break;
}
// non alpha, non WS, non numeric;
//*pszToken++ = pszString[*pwPosition];
//*pwPosition = *pwPosition + 1;
//fExit=1;
break;
case GNT_ALPHA:
// if( ( isalnum ( pszString[*pwPosition] ) ) ||
// ( pszString[*pwPosition] == '.') )
// is a control or space appears within a string
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -