⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udi2mtip.c

📁 gdb for adsp develop
💻 C
📖 第 1 页 / 共 5 页
字号:
static char     _[] = "@(#)udi2mtip.c	5.31 93/11/03 08:34:07, Srini, AMD.";/****************************************************************************** * Copyright 1991 Advanced Micro Devices, Inc. * * This software is the property of Advanced Micro Devices, Inc  (AMD)  which * specifically  grants the user the right to modify, use and distribute this * software provided this notice is not removed or altered.  All other rights * are reserved by AMD. * * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR * USE OF THIS SOFTWARE. * * So that all may benefit from your experience, please report  any  problems * or  suggestions about this software to the 29K Technical Support Center at * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118. * * Advanced Micro Devices, Inc. * 29K Support Products * Mail Stop 573 * 5900 E. Ben White Blvd. * Austin, TX 78741 * 800-292-9263 ***************************************************************************** *      Engineers: Srini Subramanian. ***************************************************************************** * This module implements the UDI procedural interface routines of MONTIP * for both the Dos and Unix environments. ***************************************************************************** */#include <stdio.h>#include  <signal.h>#ifdef	MSDOS#include <stdlib.h>#include <conio.h>#else#include <malloc.h>#endif#include <string.h>#include "coff.h"#include "messages.h"#include "memspcs.h"#include "macros.h"#include "udiproc.h"#include "udiids.h"#include "udiext.h"#include "mtip.h"#include "hif.h"#include "versions.h"/*  * MsgCode halt1, halt2, halt3, halt4 are variables defined as INT32 * * inside the macro block * */#define	CLEAR_PENDING_STOP	StopFlag=0;/* Stop signal handler / macro */#define	STOP_SIG_HDLR	{\			INT32   MsgCode;\			INT32   halt1, halt2, halt3, halt4;\			StopFlag=0;\			Mini_build_break_msg();\			if (Mini_msg_send() != SUCCESS)\			  return((-1) * MONErrCantSendMsg);\			SIGINT_POLL	\			MsgCode = Wait_For_Ack();\			if (MsgCode == ABORT_FAILURE)\			   return ((-1) * MONErrAbortAborted);\			if (MsgCode == FAILURE)\			   return ((-1) * MONErrNoAck);\			else if (MsgCode != HALT)\			   return ((-1) * MONErrCantRecvMsg);\			Mini_unpack_halt_msg(&halt1, &halt2, &halt3, &halt4);\			};#define	SEND_AND_WAIT_ACK(x)	{\				INT32	MsgCode;\				if (Mini_msg_send() != SUCCESS)\				   return((-1)*MONErrCantSendMsg);\				SIGINT_POLL	\				MsgCode = Wait_For_Ack();\				if (MsgCode == ABORT_FAILURE)\				  return (UDIErrorAborted);\				else if (MsgCode == FAILURE)\				  return ((-1) * MONErrNoAck);\				else if (MsgCode == ERROR)\				  ReturnedError = 1; \				else if (MsgCode != (INT32) (x))\				  return ((-1) * MONErrCantRecvMsg);\				};#define	MONUDISession		1static int      AllSections=(STYP_ABS|STYP_TEXT|STYP_LIT|STYP_DATA|STYP_BSS);static UDIPId   CurrentPID = (UDIPId) UDIProcessProcessor;static UDIUInt32 PreviousProcessorState;static UDIUInt32 ProcessorState;static int      TipAlive = 0;static	int	NumberOfProcesses=0;static int      ContinuingSession = 0;static char    *TargetType;static char    *SecondTarget;static char    *CoreFile;static int      CoreLoaded;static BreakIdType LastBreakId = 0;static UDIBool  SupervisorMode;static UDIBool  RealMode;static UDIBool  ProtectedMode;static UDIBool  VirtualMode;static int      BreaksInPlace;	/* EB29K */static int      StepCmdGiven = 0;static int	ReturnedError=0;static	int	StopFlag=0;static	int	Interrupted=0;static	int	RemoteTarget=0;static	int	NoStepReqd=0;static	int	NoChan1Ack=0;static	int	SendACKFirst=0;static	INT32	MsgAlreadyInBuffer = 0;static	INT32	MsgAlreadyReceived = 0;static	int	Channel0Busy=0;unsigned long	TimeOut;int		MessageRetries;int		BlockCount;int		DelayFactor;unsigned int	MaxMsgBufSize;extern int		lpt_initialize;	/* global */extern int		use_parport;		/* global */static	UDISizeT	ErrCntRemaining=(UDISizeT) 0;static	FILE	*coff_in;static	char	buffer[LOAD_BUFFER_SIZE];/* used in input/output routines */#define	TIP_IO_BUFSIZE		1024static 	char     	channel0_buffer[TIP_IO_BUFSIZE];static 	UDISizeT   	Channel0_count=0;static 	char     	channel1_buffer[TIP_IO_BUFSIZE];static 	UDISizeT   	Channel1_count=0;static	char		channel2_buffer[TIP_IO_BUFSIZE];static 	UDISizeT   	Channel2_count=0;static 	UDIUInt32 	Lr4_count;static 	UDIUInt32 	TotalDone=(UDIUInt32) 0;static 	CPUOffset 	Lr3_addr;#define	TIP_COOKED	0		/* default */#define	TIP_RAW		1#define	TIP_CBREAK	2#define	TIP_ECHO	4#define	TIP_ASYNC	8#define	TIP_NBLOCK	0x10static	UDIUInt32	PgmStdinMode=TIP_COOKED;	/* default */static	UDIUInt32	StdinCharsNeeded=0;/* Cache register values */static UDIUInt32 Glob_Regs[128],                Loc_Regs[128];static int      RefreshRegs = 1;static int	  exitstat;static	char	ConnectString[512];static	char		TempArgString[1024];static	struct tip_break_table  *bp_table=NULL;/* Global variables */TIP_TARGET_CONFIG tip_target_config;TIP_TARGET_STATUS tip_target_status;TIP_CONFIG      tip_config;char           *Msg_Logfile;FILE           *MsgFile;/* ------------- Minimon TIP Specific Error Codes ------------ */#define	MONNoError		0#define	MONErrCantSendMsg	1#define	MONErrCantRecvMsg	2#define	MONErrCantLoadROMfile	3#define	MONErrCantInitMsgSystem	4#define	MONErrCantBreakInROM	5#define	MONErrCantResetComm	6#define	MONErrCantAllocBufs	7#define	MONErrUnknownBreakType	8#define	MONErrNoAck		9#define	MONErrNoSynch		10#define	MONErrCantOpenCoff	11#define	MONErrCantWriteToMem	12#define	MONErrAbortAborted	13#define	MONErrNullConfigString	14#define	MONErrNoTargetType	15#define	MONErrOutofMemory	16#define	MONErrErrorInit		17#define	MONErrErrorRead		18#define	MONErrErrorWrite	19#define	MONErrErrorCopy		20#define	MONErrErrorSetBreak	21#define	MONErrErrorStatBreak	22#define	MONErrErrorRmBreak	23#define	MONErrConfigInterrupt	24#define	MONErrNoConfig		25#define	MONErrMsgInBuf		26#define	MONErrUnknownTIPCmd	27#define	MAX_MONERR		28static char    *monerr_tip[] = {   /* 0 */ "No Error.",   /* 1 */ "Could not send message to target.",   /* 2 */ "Did not receive the correct ACK from target.",   /* 3 */ "Cant load ROM file.",   /* 4 */ "Cant initialize the message system.",   /* 5 */ "Cant set breakpoint in ROM.",   /* 6 */ "Cant reset communication channel.",   /* 7 */ "Cant reallocate message buffers.",   /* 8 */ "Breakpoint type requested is not recognized.",   /* 9 */ "No ACK from target - timed out.",   /* 10 */ "Timed out synching. No response from target.",   /* 11 */ "Cannot open ROM file.",   /* 12 */ "Cannot write to memory while downloading ROM file.",   /* 13 */ "Ctrl-C aborted previous Ctrl-C processing.",   /* 14 */ "Null configuration string specified for connection.",   /* 15 */ "No Target type specified for connection.",   /* 16 */ "Out of memory.",   /* 17 */ "Error on target - trying to initialize process.",   /* 18 */ "Error on target - trying to read.",   /* 19 */ "Error on target - trying to write.",   /* 20 */ "Error on target - trying to do copy.",   /* 21 */ "Error on target - trying to set breakpoint.",   /* 22 */ "Error on target - trying to query breakpoint.",   /* 23 */ "Error on target - trying to remove breakpoint.",   /* 24 */ "User interrupt signal received - Aborting synch.",   /* 25 */ "Couldn't get target config after reset. Try again.",   /* 26 */ "Message received from target waiting in buffer.",   /* 27 */ "Unknown Montip command, Exiting TIP mode."};#define	MAX_MONERR_SIZE		80/* ---------------- Error Codes -------------------------------- *//* Function declarations */extern	void	IntHandler PARAMS((int num));extern	void	print_recv_bytes PARAMS((void));extern	void	set_lpt PARAMS((void));extern	void	unset_lpt PARAMS((void));static	FILE	*FindFile PARAMS((char *));static	char	*GetTargetType PARAMS((char *, char *));static	INT32	SendConfigWait PARAMS((void));extern	void	SendACK PARAMS((void));static 	int 	parse_string PARAMS((char *string));static 	int 	write_args PARAMS((char *argstr, ADDR32 argstart,						     ADDR32 * datahigh));static 	int 	write_argv PARAMS((int arg_count, char *arg_ptr[], 				   ADDR32 argstart, ADDR32 * hi_data));static	INT32 	SpaceMap_udi2mm PARAMS((CPUSpace space));static	CPUSpace	SpaceMap_mm2udi PARAMS((INT32 space));static	int 	Reset_Processor PARAMS((void));static	INT32 	Wait_For_Ack PARAMS((void));static	void 	process_target_msg PARAMS((INT32 msgcode));static	void 	process_HALT_msg PARAMS((void));static	INT32 	process_chan0_ack PARAMS((void));static	void 	process_CHAN1_msg PARAMS((void));static	void 	process_CHAN2_msg PARAMS((void));static	void 	process_stdin_needed_req PARAMS((void));static	void 	set_stdin_mode PARAMS((void));static	void 	process_ERR_msg PARAMS((void));static	void 	process_HIF_msg PARAMS((void));static 	int 	PutAllBreakpoints PARAMS((void));static 	int 	ResetAllBreakpoints PARAMS((void));static 	int 	Write_Glob_Reg PARAMS((INT32 RegVal, int RegNum));/* * these three functions are called from HIF/IO handlers to do terminal * input/output. */extern	void 	set_stdin_needed PARAMS((ADDR32 offset, UDICount count));extern	void 	set_stderr_ready PARAMS((ADDR32 offset, UDICount count));extern	void 	set_stdout_ready PARAMS((ADDR32 offset, UDICount count));static	INT32  	Mini_load_coff PARAMS((char *fname,			       INT32 space, 			       INT32 sym,			       INT32 sects,			       int   msg));static	int 	update_breakpt_at PARAMS((INT32 space, ADDR32 addr, ADDR32 Inst));static	int 	is_breakpt_at PARAMS((INT32 space, ADDR32 addr));static	void 	add_to_bp_table PARAMS((BreakIdType * id, INT32 space,		ADDR32 offset, INT32 count, INT32 type, ADDR32 inst));static	int 	get_from_bp_table PARAMS((BreakIdType id, INT32 * space,				ADDR32 * offset, INT32 * count,				INT32 * type, ADDR32 * inst));static	int 	remove_from_bp_table PARAMS((BreakIdType id));extern	INT32 	CheckForMsg PARAMS((INT32 time));extern	int 	service_HIF PARAMS((UINT32 svcnm, UINT32 lr2, UINT32 lr3, 		   UINT32 lr4, UINT32 * gr96, UINT32 * gr97, UINT32 * gr121));/* ================================================================= *//* UDI Procedure definitions  */UDIError UDIConnect(string, Session)  char           *string;  UDISessionId   *Session;{  INT32           MsgCode;  int		 retval;  if (TipAlive) {	/* already connected */    /* If same TargetType requested, return ConnectionUnavailable */    SecondTarget = NULL;    if ((SecondTarget = GetTargetType (SecondTarget, string)) == NULL)       return (UDIErrorInvalidTIPOption);    if (strcmp (SecondTarget, TargetType) == 0)       return (UDIErrorConnectionUnavailable);    else       return (UDIErrorTryAnotherTIP);  } else {    if (ContinuingSession) {      ContinuingSession=0; /* reset */      *Session = (UDISessionId) MONUDISession;      if ((int) (ProcessorState & 0xFF) != UDINotExecuting) {/* none active */        CurrentPID = (UDIPId) (UDIProcessProcessor+1);        NumberOfProcesses=1;      };      TipAlive = 1;      return (UDINoError);    }    /* Initialize variables */    /* Take control of Ctrl-C until connect time */    signal (SIGINT, IntHandler);    CoreFile = NULL;    TargetType = NULL;    Msg_Logfile = NULL;    CoreLoaded = 0;    CurrentPID = (UDIPId) UDIProcessProcessor;    SupervisorMode = 0;    RealMode = 0;    ProtectedMode = 1;	/* default */    VirtualMode = 0;    BreaksInPlace = 0;	/* EB29K */    TimeOut = (unsigned long) 10000;    MessageRetries = (int) 1000;#ifdef	MSDOS    BlockCount = (int) 1000;#else    BlockCount = (int) 40000;#endif    DelayFactor = (int) 0;    MaxMsgBufSize = (unsigned int) 0;    Channel0_count = 0;    Channel1_count = 0;    Channel2_count = 0;    Channel0Busy=0;    *Session = (UDISessionId) MONUDISession;    TipAlive = 1; /* no more positive error codes */    /* TIP_CONFIG initialization */    tip_config.PC_port_base = (INT32) - 1;	/* default */    tip_config.PC_mem_seg = (INT32) - 1;	/* default */    (void) strcpy(tip_config.baud_rate, DEFAULT_BAUD_RATE);    (void) strcpy(tip_config.comm_port, DEFAULT_COMM_PORT);    (void) strcpy(tip_config.par_port, DEFAULT_PAR_PORT);    /* Get the CFG register value to find out 29kEndian */    tip_target_config.P29KEndian = BIG;	/* default */    if ((retval = parse_string(string)) != (int) 0)      return ((UDIError) retval);	    if (TargetType == NULL)       return ((-1) * MONErrNoTargetType);    /* Open Msg_Logfile if any */    if (Msg_Logfile) {      if ((MsgFile = fopen(Msg_Logfile, "w")) == NULL)	Msg_Logfile = NULL;    }    /* Initialize message system */    if (Mini_msg_init(TargetType) != SUCCESS) {     *Session = (UDISessionId) MONUDISession;      TipAlive = 1;      return ((-1) * MONErrCantInitMsgSystem);    }    /* Reset communication channel */    Mini_reset_comm();    /*     * Should we have different TIPS: one for shared memory & another for     * serial connections?     */    if (CoreFile) {      if ((MsgCode = Mini_load_coff(CoreFile, (INT32) D_MEM, (INT32) 1, (INT32) AllSections, 0)) != SUCCESS) {       *Session = (UDISessionId) MONUDISession;	TipAlive = 1;	return ((UDIError) MsgCode);      }      CoreLoaded = 1;	/* True */      /* Reset communication channel */      Mini_reset_comm();      Mini_go_target();	/* RESET Target Processor */    }    /* Define TIPs endianess */#ifdef	MSDOS    tip_target_config.TipEndian = LITTLE;#else    tip_target_config.TipEndian = BIG;#endif   if (strcmp(TargetType, "serial") &&       strcmp(TargetType, "paral_1") &&       strcmp(TargetType, "pcserver")) { /* non-serial targets */     RemoteTarget = 0;	/* not a remote target */   } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -