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

📄 onindy.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
	 * lose all the transmission parameters we've set up.	 */	success = 0;	pid = fork();	if ( pid == -1 ){		perror( "Can't fork process:" );	} else if ( pid == 0 ){		/* CHILD */		dup2( nindy_fd, 0 );	/* Redirect stdin */		dup2( nindy_fd, 1 );	/* Redirect stout */		if ( quiet ){			execl( p, p, "-q", fn, (char*)0 );		} else {			execl( p, p, fn, (char*)0 );		}		/* Don't get here unless execl fails */		sprintf( buf, "Can't exec %s", p );		perror( buf );	} else {			/* PARENT */		if ( wait(&w) == -1 ){			perror( "Wait failed" );		} else if (WIFEXITED(w) && (WEXITSTATUS(w) == 0)){			success = 1;		}	}	return success;}/****************************************************************************** * ninGdbExit: *	Ask NINDY to leave GDB mode and print a NINDY prompt. *	Since it'll no longer be in GDB mode, don't wait for a response. ******************************************************************************/OninGdbExit(){        putpkt( "E" );}/****************************************************************************** * ninGo: *	Ask NINDY to start or continue execution of an application program *	in it's memory at the current ip. ******************************************************************************/OninGo( step_flag )    int step_flag;	/* 1 => run in single-step mode */{	putpkt( step_flag ? "s" : "c" );}/****************************************************************************** * ninMemGet: *	Read a string of bytes from NINDY's address space (960 memory). ******************************************************************************/OninMemGet(ninaddr, hostaddr, len)     long ninaddr;	/* Source address, in the 960 memory space	*/     char *hostaddr;	/* Destination address, in our memory space	*/     int len;		/* Number of bytes to read			*/{	char buf[2*BUFSIZE+20];	/* Buffer: hex in, binary out		*/	int cnt;		/* Number of bytes in next transfer	*/	for ( ; len > 0; len -= BUFSIZE ){		cnt = len > BUFSIZE ? BUFSIZE : len;		sprintf( buf, "m%x,%x", ninaddr, cnt );		send( buf, FALSE );		hexbin( cnt, buf, hostaddr );		ninaddr += cnt;		hostaddr += cnt;	}}/****************************************************************************** * ninMemPut: *	Write a string of bytes into NINDY's address space (960 memory). ******************************************************************************/OninMemPut( destaddr, srcaddr, len )     long destaddr;	/* Destination address, in NINDY memory space	*/     char *srcaddr;	/* Source address, in our memory space		*/     int len;		/* Number of bytes to write			*/{	char buf[2*BUFSIZE+20];	/* Buffer: binary in, hex out		*/	char *p;		/* Pointer into buffer			*/	int cnt;		/* Number of bytes in next transfer	*/	for ( ; len > 0; len -= BUFSIZE ){		cnt = len > BUFSIZE ? BUFSIZE : len;		sprintf( buf, "M%x,", destaddr );		p = buf + strlen(buf);		binhex( cnt, srcaddr, p );		*(p+(2*cnt)) = '\0';		send( buf, TRUE );		srcaddr += cnt;		destaddr += cnt;	}}/****************************************************************************** * ninRegGet: *	Retrieve the contents of a 960 register, and return them as a long *	in host byte order. * *	THIS ROUTINE CAN ONLY BE USED TO READ THE LOCAL, GLOBAL, AND *	ip/ac/pc/tc REGISTERS. * ******************************************************************************/longOninRegGet( regname )    char *regname;	/* Register name recognized by NINDY, subject to the			 * above limitations.			 */{	char buf[200];	long val;	sprintf( buf, "u%s", regname );	send( buf, FALSE );	hexbin( 4, buf, (char *)&val );	return byte_order(val);}/****************************************************************************** * ninRegPut: *	Set the contents of a 960 register. * *	THIS ROUTINE CAN ONLY BE USED TO SET THE LOCAL, GLOBAL, AND *	ip/ac/pc/tc REGISTERS. * ******************************************************************************/OninRegPut( regname, val )    char *regname;	/* Register name recognized by NINDY, subject to the			 * above limitations.			 */    long val;		/* New contents of register, in host byte-order	*/{	char buf[200];	sprintf( buf, "U%s,%08x", regname, byte_order(val) );	send( buf, TRUE );}/****************************************************************************** * ninRegsGet: *	Get a dump of the contents of the entire 960 register set.  The *	individual registers appear in the dump in the following order: * *		pfp  sp   rip  r3   r4   r5   r6   r7  *		r8   r9   r10  r11  r12  r13  r14  r15  *		g0   g1   g2   g3   g4   g5   g6   g7  *		g8   g9   g10  g11  g12  g13  g14  fp  *		pc   ac   ip   tc   fp0  fp1  fp2  fp3 * *	Each individual register comprises exactly 4 bytes, except for *	fp0-fp3, which are 8 bytes. * * WARNING: *	Each register value is in 960 (little-endian) byte order. * ******************************************************************************/OninRegsGet( regp )    char *regp;		/* Where to place the register dump */{	char buf[(2*REGISTER_BYTES)+10];   /* Registers in ASCII hex */	strcpy( buf, "r" );	send( buf, FALSE );	hexbin( REGISTER_BYTES, buf, regp );}/****************************************************************************** * ninRegsPut: *	Initialize the entire 960 register set to a specified set of values. *	The format of the register value data should be the same as that *	returned by ninRegsGet. * * WARNING: *	Each register value should be in 960 (little-endian) byte order. * ******************************************************************************/OninRegsPut( regp )    char *regp;		/* Pointer to desired values of registers */{	char buf[(2*REGISTER_BYTES)+10];   /* Registers in ASCII hex */	buf[0] = 'R';	binhex( REGISTER_BYTES, regp, buf+1 );	buf[ (2*REGISTER_BYTES)+1 ] = '\0';	send( buf, TRUE );}/****************************************************************************** * ninReset: *      Ask NINDY to perform a soft reset; wait for the reset to complete. ******************************************************************************/OninReset(){	putpkt( "X" );	while ( readchar() != '+' ){		;	}}/****************************************************************************** * ninSrq: *	Assume NINDY has stopped execution of the 960 application program in *	order to process a host service request (srq).  Ask NINDY for the *	srq arguments, perform the requested service, and send an "srq *	complete" message so NINDY will return control to the application. * ******************************************************************************/OninSrq(){	char buf[BUFSIZE];	int retcode;	unsigned char srqnum;	char *p;	char *argp;	int nargs;	int arg[MAX_SRQ_ARGS];	/* Get srq number and arguments	 */	strcpy( buf, "!" );	send( buf, FALSE );	hexbin( 1, buf, (char *)&srqnum );	/* Set up array of pointers the each of the individual	 * comma-separated args	 */	nargs=0;	argp = p = buf+2;        while ( 1 ){                while ( *p != ',' && *p != '\0' ){                        p++;                }                sscanf( argp, "%x", &arg[nargs++] );                if ( *p == '\0' || nargs == MAX_SRQ_ARGS ){                        break;                }                argp = ++p;        }	/* Process Srq	 */	switch( srqnum ){	case BS_CLOSE:		/* args: file descriptor */		if ( arg[0] > 2 ){			retcode = close( arg[0] );		} else {			retcode = 0;		}		break;	case BS_CREAT:		/* args: filename, mode */		OninStrGet( arg[0], buf );		retcode = creat(buf,arg[1]);		break;	case BS_OPEN:		/* args: filename, flags, mode */		OninStrGet( arg[0], buf );		retcode = open(buf,arg[1],arg[2]);		break;	case BS_READ:		/* args: file descriptor, buffer, count */		retcode = read(arg[0],buf,arg[2]);		if ( retcode > 0 ){			OninMemPut( arg[1], buf, retcode );		}		break;	case BS_SEEK:		/* args: file descriptor, offset, whence */		retcode = lseek(arg[0],arg[1],arg[2]);		break;	case BS_WRITE:		/* args: file descriptor, buffer, count */		OninMemGet( arg[1], buf, arg[2] );		retcode = write(arg[0],buf,arg[2]);		break;	default:		retcode = ERROR;		break;	}	/* Tell NINDY to continue	 */	sprintf( buf, "e%x", retcode );	send( buf, TRUE );}/****************************************************************************** * ninStopWhy: *	Assume the application program has stopped (i.e., a DLE was received *	from NINDY).  Ask NINDY for status information describing the *	reason for the halt. * *	Returns a non-zero value if the user program has exited, 0 otherwise. *	Also returns the following information, through passed pointers: *           - why: an exit code if program the exited; otherwise the reason *			why the program halted (see stop.h for values). *	    - contents of register ip (little-endian byte order) *	    - contents of register sp (little-endian byte order) *	    - contents of register fp (little-endian byte order) ******************************************************************************/charOninStopWhy( whyp, ipp, fpp, spp )    char *whyp;	/* Return the 'why' code through this pointer	*/    char *ipp;	/* Return contents of register ip through this pointer	*/    char *fpp;	/* Return contents of register fp through this pointer	*/    char *spp;	/* Return contents of register sp through this pointer	*/{	char buf[30];	char stop_exit;	strcpy( buf, "?" );	send( buf, FALSE );	hexbin( 1, buf, &stop_exit );	hexbin( 1, buf+2, whyp );	hexbin( 4, buf+4, ipp );	hexbin( 4, buf+12, fpp );	hexbin( 4, buf+20, spp );	return stop_exit;}/****************************************************************************** * ninStrGet: *	Read a '\0'-terminated string of data out of the 960 memory space. * ******************************************************************************/staticOninStrGet( ninaddr, hostaddr )     unsigned long ninaddr;	/* Address of string in NINDY memory space */     char *hostaddr;		/* Address of the buffer to which string should				 *	be copied.				 */{	char buf[BUFSIZE];	/* String as 2 ASCII hex digits per byte */	int numchars;		/* Length of string in bytes.		*/	sprintf( buf, "\"%x", ninaddr );	send( buf, FALSE );	numchars = strlen(buf)/2;	hexbin( numchars, buf, hostaddr );	hostaddr[numchars] = '\0';}/****************************************************************************** * ninVersion: *	Ask NINDY for version information about itself. *	The information is sent as an ascii string in the form "x.xx,<arch>", *	where, *		x.xx	is the version number *		<arch>	is the processor architecture: "KA", "KB", "MC", "CA" * * ******************************************************************************/intOninVersion( p )     char *p;		/* Where to place version string */{	char buf[BUFSIZE];	strcpy( buf, "v" );	send( buf, FALSE );	strcpy( p, buf );	return strlen( buf );}

⌨️ 快捷键说明

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