Ejemplo n.º 1
0
Archivo: bm.c Proyecto: palmerc/lab
int bm(void)
{
	int totcnt, rdrequest;
	union {
		unsigned char c[BUFSIZE];
		unsigned short s[BUFSIZE/2];
		unsigned int l[BUFSIZE/4];
	} buffer;

	if((totcnt = trans.adr2 - trans.adr1) < 0)
		return(-1);

	if(transinit(bmerror, LONG) == -1)
		return(-1);
	
	while(totcnt)
	{
		rdrequest = (totcnt > BUFSIZE) ? BUFSIZE: totcnt;
		
		if(rdwr((M_SEGANY | M_RD), trans.adr1, (char *)&buffer, rdrequest) == -1)
			return(-1);

		if(rdwr((M_SEGANY | M_WR), trans.expr, (char *)&buffer, rdrequest) == -1)
			return(-1);

		totcnt -= rdrequest;
		trans.expr += rdrequest;
		trans.adr1 += rdrequest;
	}
	return(0);
}
Ejemplo n.º 2
0
Archivo: sim_io.c Proyecto: palmerc/lab
char *copystr(int argc,char *ptr)
{
	char *saveptr = ptr;
	int i;
	union {
		char c[4];
		int l;
	} buf;

	trans.adr1 = getarg(argc);

	while(1)
	{
		if(rdwr((M_DATA | M_RD), trans.adr1, &buf.l, 4) == -1)
			return(0);

		for(i = 0; i < 4; i++)
		{
			*ptr++ = buf.c[i];
			if(!buf.c[i])
				return(saveptr);
		}
		trans.adr1 += 4;
	}
}
Ejemplo n.º 3
0
Archivo: sim_io.c Proyecto: palmerc/lab
int fake_io(int vec)
{
	char ch;
	static char *head = inbuf;
	static char *tail = inbuf;
	static char inbuf[500] = { 0 };

	switch(vec)
	{
		case 0x1FC:	/*print*/

			trans.adr1 = m88000.Regs[2];   /* address of print buffer is in r2 */

			while(1)
			{
				if(rdwr((M_DATA | M_RD), trans.adr1, &ch, 1) == -1)
					return(-1);
				if(ch == '\0')
					break;
				putchar(ch);
				trans.adr1++;
			}
			break;

		case 0x1FD:	/* putchar - char sent from reg #2 */
			putchar(m88000.Regs[2]);
			break;	

		case 0x1FE:	/* getchar - char returned in reg #2 */
			if(head == tail)
			{
				do
				{
					*head = (ch = getchar());
					if(head++ == (inbuf+499))
						head = inbuf;
				}
				while(ch != '\n');
			}
			m88000.Regs[2] = *tail++;
			if(tail == &inbuf[499])
				tail = inbuf;
			break;	

		case 0x1ff:			/* exit */
			return(-1);

		default: 			/* unsupported trap */
			 return(1);
	}
	IP += 4;
	return(0);
}
Ejemplo n.º 4
0
Archivo: bf.c Proyecto: palmerc/lab
int bf(void)
{
	int totcnt, Index, rdrequest;
	union {
		unsigned char c[BUFSIZE];
		unsigned short s[BUFSIZE/2];
		unsigned int l[BUFSIZE/4];
	} buffer;

	if((totcnt = trans.adr2 - trans.adr1) < 0)
		return(-1);

	if(transinit(bferror, LONG) == -1)
		return(-1);
	
	while(totcnt)
	{
		rdrequest = (totcnt > BUFSIZE) ? BUFSIZE: totcnt;
		
		totcnt -= rdrequest;

		for(Index = 0; Index < (rdrequest / trans.size); Index++)
		{
			switch(trans.size)
			{
				case	BYTE:
					buffer.c[Index] = trans.expr;
					break;

				case	WRD:
					buffer.s[Index] = trans.expr;
					break;

				case	LONG:
					buffer.l[Index] = trans.expr;
					break;
			}
		}
		if(rdwr((M_SEGANY | M_WR), trans.adr1, (char *)&buffer, rdrequest) == -1)
			return(-1);

		trans.adr1 += rdrequest;
	}
	return(0);
}
Ejemplo n.º 5
0
Archivo: sim_io.c Proyecto: palmerc/lab
int stdio_enable(void)
{
	char *err = NULL;
	unsigned int value = 0;
	unsigned instruct = 0;


	if (getexpr("_printf",&err,&value) != 0) return 0;
	/* If we get here, _printf was found */

	if(rdwr((M_INSTR|M_RD),value,&instruct,sizeof(instruct)) == -1)
		return 0;

	if(instruct != 0xF000D104)
		return 0;

	return 1;
}
Ejemplo n.º 6
0
Archivo: sim_io.c Proyecto: palmerc/lab
int stdio_io(int vec)
{
	union {
		double d;
		int    i[2];
	} db1, db2, db3;
	register int arg1, arg2, arg3, arg4;
	int i, j, k;
	char str1[150], str2[150], rdwrbuf[RDWRBUF];
	FILE *fp_out = stdout;

	arg1 = getarg(1);
	arg2 = getarg(2);
	arg3 = getarg(3);
	arg4 = getarg(4);

	switch(vec)
	{			/* unsupported trap */
		default: 
			 return(1);

		case 0x1fb:   /* Unix times */
/*			addr = m88000.Regs[2];			*/
			i = readtime();
			PPrintf("at clock = %d\n",i);
/*			membyte(addr+0) = (char) uext(i,0,8);	*/
/*			membyte(addr+1) = (char) uext(i,8,8);	*/
/*			membyte(addr+2) = (char) uext(i,16,8);	*/
/*			membyte(addr+3) = (char) uext(i,24,8);	*/
			break;	

		case S_PRINTF:        /* printf     */
			if(!copystr(1, str1))
			    return(-1);
			sim_printf(fp_out, str1, 2);
			break;	

		case S_FPRINTF:       /* fprintf:   */
			if(!copystr(2, str1))
			    return(-1);
			sim_printf(ckiob((TARGETFILE *)arg1), str1, 3);
			break;

		case S_SPRINTF:       /* _sprintf:  */
			Eprintf("sorry, sprintf not yet supported\n");
			break;

		case S_SCANF:         /* _scanf:    */
		case S_FSCANF:     /* _fscanf:   */
		case S_SSCANF:     /* _sscanf:   */
		    Eprintf("sorry, scanf not yet supported\n");
		    break;

		case S_FOPEN:
		    if(!copystr(1, str1) || !copystr(2, str2))
			return(-1);
		    m88000.Regs[2] = (int)fopen(str1, str2);
                           break;

		case S_FREOPEN:
		    if(!copystr(1, str1) || !copystr(2, str2))
			return(-1);
		    m88000.Regs[2] = (int)freopen(str1, str2, ckiob((TARGETFILE *)arg3));
                           break;

		case S_FDOPEN:
		    if(!copystr(2, str1))
			return(-1);
		    m88000.Regs[2] = (int)fdopen(arg1, str1);
		    break;

		case S_FREAD:
		    k = arg2 * arg3;
		    j = 0;
		    do
		    {
		 	i = fread(rdwrbuf, sizeof(char), RDWRBUF, ckiob((TARGETFILE *)getarg(4)));
		 	if(rdwr((M_DATA | M_RD), arg1, rdwrbuf, (i < k) ? k: i) == -1)
					return(-1);
			j += (i < k) ? k: i;
			arg1 += i;
		    }
		    while((k -= i) < 0);
		    m88000.Regs[2] = j;
		    break;

		case S_FWRITE:
		    k = arg2 * arg3;
		    j = 0;
		    do
		    {
			if((i = k / RDWRBUF) == 0)
				i = k % RDWRBUF;
		 	if(rdwr((M_DATA | M_WR), arg1, rdwrbuf, i) == -1)
				return(-1);
		 	if(i != fwrite(rdwrbuf, sizeof(char), i, ckiob((TARGETFILE *)getarg(4))))
			{
				j = 0;
				break;
			}
			j += i;
			arg1 += i;
		    }
		    while((k -= i) < 0);
		    m88000.Regs[2] = j;
		    break;

		case S_FCLOSE:
		    m88000.Regs[2] = (int)fclose(ckiob((TARGETFILE *)arg1));
		    break;

		case S_FFLUSH:
		    m88000.Regs[2] = (int)fflush(ckiob((TARGETFILE *)arg1));
		    break;

		case 0x203:
		case 0x204:
		case S__FILBUF:    /* __filbuf:  */
		case S__FLSBUF:    /* __flsbuf:  */
		case S_MALLOC:     /* _malloc:   */
		case S_SETBUF:
		case S_SETBUFFER:
		case S_SETLINEBUF:
		    Eprintf("unsupported trap\n");
		    break;

		case S_FSEEK:
		    m88000.Regs[2] = (int)fseek(ckiob((TARGETFILE *)arg1), arg2, arg3);
		    break;

		case S_GETS:
		    if(fgets(rdwrbuf, sizeof(rdwrbuf), stdin) == 0)
			m88000.Regs[2] = 0;
		    else
		    {
			i = strchr(rdwrbuf, '\0') - rdwrbuf + 1;
		 	if(rdwr((M_DATA | M_WR), arg1, rdwrbuf, i) == -1)
				return(-1);
		    }
		    break;

		case S_FGETS:
		    i = (arg2 < sizeof(rdwrbuf)) ? arg2: sizeof(rdwrbuf);
		    if(fgets(rdwrbuf, i, ckiob((TARGETFILE *)arg3)) == 0)
			m88000.Regs[2] = 0;
		    else
		    {
			i = strchr(rdwrbuf, '\0') - rdwrbuf + 1;
		 	if(rdwr((M_DATA | M_WR), arg1, rdwrbuf, i) == -1)
				return(-1);
		    }
		    break;

		case S_REWIND:
		    rewind(ckiob((TARGETFILE *)arg1));
			    break;

		case S_FTELL:
		    m88000.Regs[2] = (int)ftell(ckiob((TARGETFILE *)arg1));
		    break;

		case S_FEOF:
		    m88000.Regs[2] = feof((FILE *)ckiob((TARGETFILE *)arg1));
		    break;

		case S_FERROR:
		    m88000.Regs[2] = ferror((FILE *)ckiob((TARGETFILE *)arg1));
		    break;

		case S_CLEARERR:
		    clearerr((FILE *)ckiob((TARGETFILE *)arg1));
		    break;

		case S_FILENO:
		    m88000.Regs[2] = (int)fileno((FILE *)ckiob((TARGETFILE *)arg1));
		    break;

		case S_GETC:
		case S_FGETC:
		    m88000.Regs[2] = (int)getc((FILE *)ckiob((TARGETFILE *)arg1));
		    break;

		case S_GETCHAR:
		    m88000.Regs[2] = (int)getchar();
		    break;

		case S_GETW:
		    m88000.Regs[2] = (int)getw(ckiob((TARGETFILE *)arg1));
		    break;

		case S_PUTC:
		case S_FPUTC:
		    m88000.Regs[2] = (int)fputc(arg1,ckiob((TARGETFILE *)arg2));
		    break;

		case S_PUTCHAR:
		    m88000.Regs[2] = (int)putchar(arg1);
		    break;


		case S_PUTW:
		    m88000.Regs[2] = (int)putw(arg1,ckiob((TARGETFILE *)arg2));
		    break;

		case S_PUTS:
		    if(!copystr(1, str1))
			return(-1);
		    m88000.Regs[2] = (int)puts(str1);
		    break;

		case S_FPUTS:
		    if(!copystr(1, str1))
			return(-1);
		    m88000.Regs[2] = (int)fputs(str1, ckiob((TARGETFILE *)arg2));
		    break;

		case S_UNGETC:
		    m88000.Regs[2] = (int)ungetc(arg1, ckiob((TARGETFILE *)arg2));
		    break;
		case S_GETTIME:
			m88000.Regs[2] = (int)readtime();
			break;
		case S_SYSTEM:
			if(!copystr(1, str1))
				return(-1);
			m88000.Regs[2] = (int)system(str1);
			break;
		case S_EXP:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = exp(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_LOG:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = log(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_LOG10:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = log10(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_SQRT:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = sqrt(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_SINH:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = sinh(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_COSH:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = cosh(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_TANH:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = tanh(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
     			break;	
		case S_FLOOR:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = floor(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_CEIL:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.d = ceil(db1.d);
			m88000.Regs[2] = db2.i[0];
			m88000.Regs[3] = db2.i[1];
			break;
		case S_POW:
			db1.i[0] = arg1;
			db1.i[1] = arg2;
			db2.i[0] = arg3;
			db2.i[1] = arg4;
			db3.d = pow(db1.d,db2.d);
			m88000.Regs[2] = db3.i[0];
			m88000.Regs[3] = db3.i[1];
			break;
	}

	IP += 4;
	return(0);
}
Ejemplo n.º 7
0
/*
 * Read the file to be transfered.
 * Write that file on the data socket.
 * The caller closes the socket.
 */
int
source(int sock)
{
	int	fd, n, size;
	char	*s;
	char	file[100];
	char	hbuf[1024];
	struct	stat sb;
#define		name	&buf[5]

	n = read(sock, buf, XFERSIZE);
	if (n <= 0) {
		perror("control nbytes");
		return (-1);
	}
	buf[n] = 0;
	if (dflg) printf("%.*s\n", n, buf); 
	if (zflg) {
		return (0);
	}
	if (!strncmp(buf, "EXIT", 4)) {
		exit(0);
	}
	if (strncmp(buf, "GET /", 5)) {
		perror(buf);
		return(1);
	}
	for (s = buf; *s && *s != '\r' && *s != '\n'; s++)
		;
	*s = 0;
	for (s = name; *s && *s != ' '; s++) 
		;
	*s = 0;
	if (lflg) strncpy(file, name, sizeof(file));
	if (dflg) printf("OPEN %s\n", name);
	fd = open(name, 0);
	if (fd == -1) {
error:		perror(name);
		close(fd);
		return (1);
	}
	if (fstat(fd, &sb) == -1) {
		if (dflg) printf("Couldn't stat %s\n", name);
		goto error;
	}
	size = sb.st_size;
	n = sprintf(hbuf, "HTTP/1.0 200 OK\r\n%s\r\nServer: lmhttp/0.1\r\nContent-Type: %s\r\nLast-Modified: %s\r\n\r\n",
	    http_time(), type(name), date(&sb.st_mtime));
	if (write(sock, hbuf, n) != n) {
		goto error;
	}
	if (Dflg && isdir(name)) {
		dodir(name, sock);
	} else if (nflg) {
		fake(sock, buf, size);
	} else if ((size > MMAPS_BETTER)) {	/* XXX */
		if (mmap_rdwr(fd, sock, size) == -1) {
			printf("%s mmap failed\n", name);
		}
	} else {
		rdwr(fd, sock, buf);
	}
	if (lflg) logit(sock, file, size);
	close(fd);
	return(0);
}
Ejemplo n.º 8
0
Archivo: runsim.c Proyecto: palmerc/lab
int run(void)
{
	unsigned int	r31;
	unsigned int 	argvptrs[MAXCMD];
	int 		strsize, cnt, idx;

	extern char		cmdbuf[];
	extern char		ccmdbuf[];
	extern struct dirtree	dir[];

	r31 = STKBASE+STKSIZE;

	if(argc == 0)
	{
		PPrintf("No program loaded\n");
		return(-1);
	}

	if(cmdcount != 1)
	{
#ifdef NOT_SPEC95
				/* Expand the cmdbuf line using the
				 * shell (echo) and reparse.
				 */
		expand(ccmdbuf, cmdbuf);
		parse(cmdbuf, dir);

		argv[1] = strchr(args, '\0') + 1;
		cmd_argv[1] = strchr(args, '\0') + 1;
		for(argc = 1; argc <= cmdcount; argc++)
		{
			strcpy(argv[argc], cmdptrs[argc]);
			strcpy(cmd_argv[argc], cmdptrs[argc]);
			argv[argc+1] = strchr(argv[argc], '\0') + 1;
			cmd_argv[argc+1] = strchr(cmd_argv[argc], '\0') + 1;
		}
		argc--;
#else
		PPrintf("run command not accepted in SPEC95\n");
		return(-1);
#endif
	}

	cmd_argc = argc - 1;
	for(idx = (cnt = argc) - 1; cnt; cnt--, idx--)
	{
		strsize = strlen(argv[idx]) + 1;
		r31 = (r31 - strsize) & 0xFFFFFFFC;
		argvptrs[idx] = r31;
		if(rdwr((M_SEGANY | M_WR), r31, argv[idx], strsize) == -1)
			return(-1);
	}

	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &cnt, 4) == -1)  /*write NULL to stack */
		return(-1);


	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &cnt, 4) == -1)  /*write NULL to stack */
		return(-1);

	for(idx = (cnt = argc) - 1; cnt; cnt--, idx--)
	{
		if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &argvptrs[idx], 4) == -1)
			return(-1);
	}

	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &argc, 4) == -1)
		return(-1);

	sysVclose();			/* close all open fildes */
	m88000.Regs[31] = r31;

	m88000.Regs[2] = STKBASE;

	m88000.Regs[2] = argc;

/*
** argv is located just above argc (hence the + 4)
*/

	m88000.Regs[3] = r31 + 4;

/*
** envp is located past the NULL after the last argv pointer
** hence the argc * 4 (number of argv pointers) + 4 (the NULL)
** the firt + 4 is to bump past argc
*/

	m88000.Regs[4] = r31 + 4 + (argc * 4) + 4;

	PPrintf("Effective address: %08X\n", IP = startadr);
	brkptenb();
	return(goexec());
}
Ejemplo n.º 9
0
Archivo: runsim.c Proyecto: palmerc/lab
int rrn(void)
{
	unsigned int r31;
	int strsize, cnt, idx;
	unsigned int argvptrs[MAXCMD];

	r31 = STKBASE+STKSIZE;

	if (cmd_argc == 0 && !prog_loaded)
	{
		PPrintf("No program loaded\n");
		return(-1);
	}

	PPrintf("Argcnt = %d, Args:", cmd_argc);

	for (cnt = 1; cnt < cmd_argc; cnt++)
	{
		PPrintf(" %s", cmd_argv[cnt]);
	}

	PPrintf("\n");

	for(idx = (cnt = cmd_argc) - 1; cnt; cnt--, idx--)
	{
		strsize = strlen(argv[idx]) + 1;
		r31 = (r31 - strsize) & 0xFFFFFFFC;
		argvptrs[idx] = r31;
		if(rdwr((M_SEGANY | M_WR), r31, argv[idx], strsize) == -1)
			return(-1);
	}

	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &cnt, 4) == -1)  /*write NULL to stack */
		return(-1);


	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &cnt, 4) == -1)  /*write NULL to stack */
		return(-1);

	for(idx = (cnt = cmd_argc) - 1; cnt; cnt--, idx--)
	{
		if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &argvptrs[idx], 4) == -1)
			return(-1);
	}

	if(rdwr((M_SEGANY | M_WR), (r31 -= 4), &cmd_argc, 4) == -1)
		return(-1);

	rstsys();			/* reset processor and CMMU */
	sysVclose();			/* close all open fildes */
	m88000.Regs[31] = r31;

	m88000.Regs[2] = STKBASE;

	m88000.Regs[2] = cmd_argc;

/*
** argv is located just above argc (hence the + 4)
*/

	m88000.Regs[3] = r31 + 4;

/*
** envp is located past the NULL after the last argv pointer
** hence the argc * 4 (number of argv pointers) + 4 (the NULL)
** the firt + 4 is to bump past argc
*/

	m88000.Regs[4] = r31 + 4 + (cmd_argc * 4) + 4;

	PPrintf("Effective address: %08X\n", IP = startadr);
	brkptenb();
	return(goexec());
}
Ejemplo n.º 10
0
Archivo: runsim.c Proyecto: palmerc/lab
void loadcore(void)
{
	extern struct symbols *symtable;
	extern void *nametable;
	struct core88 core;
	register int i = 0, x, y, z;
	FILE *core88;
	char outbuf[0x4000];
	struct symbols *sym;

	if((core88 = fopen("core88", "r")) == NULL)
	{
		fprintf(stderr, "Can not open \"core88\" for reading\n");
		return;
	}

	if(fread(&core, sizeof(struct core88), 1, core88) == 0)
	{
		fprintf(stderr, "Can not read \"core88\"\n");
		fclose(core88);
		return;
	}

	printf("Loading core image for \"core88\"\n");

	m88000 = core.pstate;	/* get registers */
	Icmmu = core.Icmmu;	/* get instruction CMMU */
	Dcmmu = core.Dcmmu;	/* get data CMMU */
	vecyes = core.vecyes;
	unixvec = core.unixvec;
	usecmmu = core.usecmmu;
	argc = core.argc;

	for(i = 0; i < MAXCMD; i++)
		argv[i] = core.argv[i];

	for(i = 0; i < BSIZE+10; i++)
		args[i] = core.args[i];

	for(i = 0; i < TMPBRK; i++)
		brktable[i] = core.brktable[i];

	curbrkaddr = core.curbrkaddr;
	startadr = core.startadr;
	releasemem();
	sID = core.sID;

	for(i = 0; i < MAXSEGS; i++)
	{
		if(core.mem[i].seg == NULL)
			continue;
		x = core.mem[i].endaddr - core.mem[i].baseaddr;
		if(getmem(core.mem[i].baseaddr, x, core.mem[i].flags, core.mem[i].physaddr) != 0)
		{
			printf("Can not open memory\n");
			perror("loadcore");
			return;
		}
		trans.adr1 = core.mem[i].physaddr;
		do
		{
			y = (x < 0x4000) ? x : 0x4000;		/* size for buffer */
			if((z = fread(outbuf, sizeof(char), y, core88)) == 0)
			{
				fprintf(stderr, "Can not read \"core88\"\n");
				return;
			}
 			if(rdwr((M_SEGANY | M_WR), trans.adr1, outbuf, y) == -1)	/* move */
				return;
			trans.adr1 += z;			/* update memory pointer */
		}
		while((z == y) && ((x -= z) > 0));		/* go until done */
	}

	if(core.syms == 0)
		return;

	if((symtable = (struct symbols *)malloc(core.syms * sizeof(struct symbols))) == 0)
	{
		perror("loadcore:");
		return;
	}

	if((nametable = calloc(core.nmtbsz, sizeof(char)))== 0)
	{
		perror("loadcore:");
		symtable = 0;
		return;
	}

	if(fread(symtable, sizeof(struct symbols), core.syms, core88) != core.syms)
	{
		fprintf(stderr, "Can not read \"core88\"\n");
		perror("loadcore:");
		symtable = 0;
		return;
	}

	if(fread(nametable, sizeof(char), core.nmtbsz, core88) == 0)
	{
		fprintf(stderr, "Can not read \"core88\"\n");
		perror("loadcore:");
		symtable = 0;
		return;
	}

	sym = symtable;

	for(i = 0; i < (core.syms - 1); i++, sym++)
		sym->sym += (int)nametable;

	dm();

	if(debug)
	{
		Data_path();
		rdexec(0);
	}

	fclose(core88);
	return;
}
Ejemplo n.º 11
0
Archivo: runsim.c Proyecto: palmerc/lab
int dumpcore(void)
{
	extern struct symbols *symtable;
	extern void *nametable;

	struct core88 core;
	register int i = 0, x, y, z;
	FILE *core88;
	char outbuf[0x4000];
	struct symbols *sym = symtable;

	fprintf(stderr, "Dumping core into file \"core88\"\n");

	core.pstate = m88000;	/* get registers */
	core.Icmmu = Icmmu;	/* get instruction CMMU */
	core.Dcmmu = Dcmmu;	/* get data CMMU */

	for(i = 0; i < MAXSEGS; i++)
		core.mem[i] = memory[i];

	core.vecyes = vecyes;
	core.unixvec = unixvec;
	core.usecmmu = usecmmu;
	core.argc = argc;

	for(i = 0; i < MAXCMD; i++)
		core.argv[i] = argv[i];

	for(i = 0; i < BSIZE+10; i++)
		core.args[i] = args[i];

	for(i = 0; i < TMPBRK; i++)
		core.brktable[i] = brktable[i];

	core.curbrkaddr = curbrkaddr;
	core.startadr = startadr;
	core.nmtbsz = core.syms = 0;

	while(sym && ++core.syms && sym->sym)
	{
		core.nmtbsz += (strlen(sym->sym) + 1);
		sym->sym -= (int)nametable;
		sym++;
	}

	if((core88 = fopen("core88", "w")) == NULL)
	{
		fprintf(stderr, "Can not open \"core88\" for writing\n");
		return 0;
	}

	if(fwrite(&core, sizeof(struct core88), 1, core88) == 0)
	{
		fprintf(stderr, "Can not write to \"core88\"\n");
		fclose(core88);
		return 0;
	}

	core.sID = sID;

	for(i = 0; i < MAXSEGS; i++)
	{
		if(memory[i].seg == NULL)
			continue;
		trans.adr1 = memory[i].physaddr;
		x = memory[i].phyeaddr - memory[i].physaddr;
		do
		{
			y = (x < 0x4000) ? x : 0x4000;		/* size for buffer */
 			if(rdwr((M_SEGANY | M_RD), trans.adr1, outbuf, y) == -1)	/* move */
				return 0;
			if((z = fwrite(outbuf, sizeof(char), y, core88)) == -1)
			{
				fprintf(stderr, "Can not write to \"core88\"\n");
				return 0;			/* if error return error */
			}
			trans.adr1 += z;			/* update memory pointer */
		}
		while((z == y) && ((x -= z) > 0));		/* go until done */
	}

	if(core.syms && (fwrite(symtable, sizeof(struct symbols), core.syms, core88) == 0))
	{
		fprintf(stderr, "Can not write to \"core88\"\n");
		return 0;			/* if error return error */
	}

	if(core.syms && (fwrite(nametable, sizeof(char), core.nmtbsz, core88) == 0))
	{
		fprintf(stderr, "Can not write to \"core88\"\n");
		return 0;			/* if error return error */
	}

	fclose(core88);
	return 0;
}