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

📄 machine.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ *									* *			Copyright (c) 1986 by				* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any  other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or  reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//************************************************************************ *									* *			Modification History				* *									* *  008	- Added support for vectors.							* *		  (L Miller, 18JAN90)									* *									* *	007 - Added depositField based on MIPS version; needed to	* *	      make assign to a bitfield work.				* *	      (jlr, January 21, 1989)					* *									* *	006 - Re-merged 4.3 changes.  Negates 001,003.			* *	      (jlr, June 9, 1987)					* *									* *	005 - Fixed double-execute of one-line loops.			* *	      (Jon Reeves, April 22, 1987)				* *									* *	004 - Merged in 4.3 changes.					* *	      (vjh, April 29, 1986)					* *									* *	003 - Added mkuchar and mkushort macros.			* *	      (vjh, July 8, 1985)					* *									* *	002 - Added a call to bpact() in nextaddr(), under the 		* *	      conditional-branch case (eg. O_BGEQ).  After the call	* * 	      to pstep(), dbx needed to see if it had stopped at a	* *	      breakpoint.  This was not done before because dbx		* *	      always assumed no breakpoints between source lines 	* *	      when single stepping.					* *	      Also - moved call to bpact() under the O_RET case, 	* *	      because stepto() now calls bpact() as well.  Still 	* *	      need to call it after pstep, though.			* *	      (vjh, April 25, 1985)					* *									* *	001 - Temporarily renamed findnextaddr() to nextaddr; 		* *	      commented out nextaddr().  Fixes usignal() bug 		* *	      (single stepping - dostep() gets into infinite loop).	* *	      (Victoria Holt, April 9, 1985)				* *									* ************************************************************************//* * Copyright (c) 1983 Regents of the University of California. * All rights reserved.  The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */#ifndef lintstatic char sccsid[] = "@(#)machine.c	4.2	Ultrix	11/9/90";#endif not lint/* * Target machine dependent stuff. */#include "defs.h"#include "machine.h"#include "process.h"#include "runtime.h"#include "events.h"#include "main.h"#include "symbols.h"#include "source.h"#include "mappings.h"#include "object.h"#include "keywords.h"#include "ops.h"#include "eval.h"#include <signal.h>#include <errno.h>#include <sys/sysinfo.h>#ifndef publictypedef unsigned int Address;typedef unsigned char Byte;typedef unsigned int Word;#define NVREG 64typedef struct _vquad {long val[2]} Vquad;typedef struct Vreg *Vreg;struct Vreg {    Vquad reg[NVREG];};#define NREG 16#define ARGP 12#define FRP 13#define STKP 14#define PROGCTR 15#define VCR 16#define VLR 17#define VMR 18#define VAER 19#define A_VCR 1#define A_VLR 2#define A_VMRLO 3#define A_VMRHI 4#define A_VREGLO 5#define A_VREGHI 6#define A_VAER 7#define BITSPERBYTE 8#define BITSPERWORD (BITSPERBYTE * sizeof(Word))#define nargspassed(frame) argn(0, frame)#include "source.h"#include "symbols.h"Address pc;Address prtaddr;#endifprivate Address printop();/* * Decode and print the instructions within the given address range. */public printinst(lowaddr, highaddr)Address lowaddr;Address highaddr;{    register Address addr;    for (addr = lowaddr; addr <= highaddr; ) {	addr = printop(addr);    }    prtaddr = addr;}/* * Another approach:  print n instructions starting at the given address. */public printninst(count, addr)int count;Address addr;{    register Integer i;    register Address newaddr;    if (count <= 0) {	error("non-positive repetition count");    } else {	newaddr = addr;	for (i = 0; i < count; i++) {	    newaddr = printop(newaddr);	}	prtaddr = newaddr;    }}/* * Hacked version of adb's VAX instruction decoder. */private Address printop(addr)Address addr;{    Optab op;	VaxOpcode ins, ins2;    unsigned char mode;    int argtype, amode, argno, argval;	float f;	double d;    String reg;    Boolean indexf;    short offset;    Ctrl_word ctrl_word;    Boolean ctrlf;    char *iname;    int i;    struct {      	int     regval;      	Boolean regdef;    } vregs[3];    argval = 0;    indexf = false;    for (i = 0; i < 3; i++) {      	vregs[i].regdef = false;    }    ctrlf = false;    printf("%08x  ", addr);    iread(&ins, addr, sizeof(ins));    addr += 1;    op = optab[ins];    argno = 0;	if (ins == O_ESCD) {      	iread(&ins2, addr, sizeof(ins));      	addr += 1;      	op = eoptab[ins2-FIRST_EOP];      	iname = op.iname;      	if ((ins2 == O_MTVP) || (ins2 == O_MFVP) || (ins2 == O_VSYNC)) {			ctrlf = true;			iread(&mode, addr, sizeof(mode));			addr += 1;			argno = 1;			switch (ins2) {				case O_MTVP: 					iname = mtvpname[mode];					break;				case O_MFVP:					iname = mfvpname[mode];					break;				case O_VSYNC:					iname = vsyncname[mode];					break;			}			printf("%s", iname);	  		if(strlen(iname) < 6)	    		printf("\t");      	}      	if (op.fmt != 0) {			ctrlf = true;			iread(&mode, addr, sizeof(mode));			addr += 1;			reg = regname[regnm(mode)];			amode = addrmode(mode);			argval = getdisp(addr, 2, reg, amode);			addr += 2;			ctrl_word = *(Ctrl_word *)&argval;			argno = 1;			switch (vinst_fmt[op.fmt].va) {				case vreg:	  				vregs[0].regdef = true;	  				vregs[0].regval = ctrl_word.va;	  				break;				case cmp:	  				iname = vcmpname[((VaxOpcode) op.val - O_VVCMP)]															[ctrl_word.va];	  				break;				case cvt:	  				iname = vcvtname[ctrl_word.va];	  				break;				default:	  				break;			}			switch (vinst_fmt[op.fmt].vb) {				case vreg:	  				vregs[1].regdef = true;	  				vregs[1].regval = ctrl_word.vb;	  				break;				case cmp:	  				iname = vcmpname[((VaxOpcode) op.val - O_VVCMP)]															[ctrl_word.vb];	  				break;				case cvt:	  				iname = vcvtname[ctrl_word.vb];	  				break;				default:	  				break;			}			switch (vinst_fmt[op.fmt].vc) {				case vreg:	  				vregs[2].regdef = true;	  				vregs[2].regval = ctrl_word.vc;	  				break;				case cmp:	  				iname = vcmpname[((VaxOpcode) op.val - O_VVCMP)]															[ctrl_word.vc];	  				break;				case cvt:	  				iname = vcvtname[ctrl_word.vc];	  				break;				default:	  				break;			}			printf("%s", iname);			if((strlen(iname) + printmod(ins2, ctrl_word.modifiers)) < 6)	    		printf("\t");      	}	}    if (ctrlf == false) {      printf("%s", op.iname);	  if(strlen(op.iname) < 6)	    printf("\t");	}    for (argno; argno < op.numargs; argno++) {	if (indexf == true) {	    indexf = false;	} else if ((argno == 0) || (ctrlf == true)) {	    ctrlf = false;	    printf("\t");      	if ((ins2 == O_VSTL) || (ins2 == O_VSTQ) ||	  				(ins2 == O_VSCATL) || (ins2 == O_VSCATQ)) {			printf("v%d,", vregs[2].regval);      		vregs[2].regdef = false;      	}	} else {	    printf(",");	}	argtype = op.argtype[argno];	if (is_branch_disp(argtype)) {	    mode = 0xAF + (typelen(argtype) << 5);	} else {	    iread(&mode, addr, sizeof(mode));	    addr += 1;	}	reg = regname[regnm(mode)];	amode = addrmode(mode);	switch (amode) {	    case LITSHORT:	    case LITUPTO31:	    case LITUPTO47:	    case LITUPTO63:		if (typelen(argtype) == TYPF || typelen(argtype) == TYPD ||		    typelen(argtype) == TYPG)		    printf("$%s", fltimm[mode]);		else		    printf("$%x", mode);		argval = mode;		break;	    case INDEX:		printf("[%s]", reg);		indexf = true;		argno--;		break;	    case REG:		printf("%s", reg);		break;	    case REGDEF:		printf("(%s)", reg);		break;	    case AUTODEC:		printf("-(%s)", reg);		break;	    case AUTOINC:		if (reg != regname[PROGCTR]) {		    printf("(%s)+", reg);		} else {		    printf("$");		    switch (typelen(argtype)) {			case TYPB:			    argval = printdisp(addr, 1, reg, amode);			    addr += 1;			    break;			case TYPW:			    argval = printdisp(addr, 2, reg, amode);			    addr += 2;			    break;			case TYPL:			    argval = printdisp(addr, 4, reg, amode);			    addr += 4;			    break;			case TYPF:			    iread(&f, addr, sizeof(f));				printf("0f%e", f);			    addr += 4;			    break;			case TYPD:			    iread(&d, addr, sizeof(d));				printf("0d%E", d);			    addr += 8;			    break;			case TYPQ:			case TYPG:			    iread(&argval, addr, sizeof(argval));			    printf("%06x", argval);			    iread(&argval, addr+4, sizeof(argval));			    printf("%06x", argval);			    addr += 8;			    break;		    }		}		break;	    case AUTOINCDEF:		if (reg == regname[PROGCTR]) {		    printf("*$");		    argval = printdisp(addr, 4, reg, amode);		    addr += 4;		} else {		    printf("*(%s)+", reg);		}		break;	    case BYTEDISP:		argval = printdisp(addr, 1, reg, amode);		addr += 1;		break;	    case BYTEDISPDEF:		printf("*");		argval = printdisp(addr, 1, reg, amode);		addr += 1;		break;	    case WORDDISP:		argval = printdisp(addr, 2, reg, amode);		addr += 2;		break;	    case WORDDISPDEF:		printf("*");		argval = printdisp(addr, 2, reg, amode);		addr += 2;		break;	    case LONGDISP:		argval = printdisp(addr, 4, reg, amode);		addr += 4;		break;	    case LONGDISPDEF:		printf("*");		argval = printdisp(addr, 4, reg, amode);		addr += 4;		break;	}    }    for (i = 0; i <= 2; i++) {      	if (vregs[i].regdef == true) {			if (ctrlf == true) {	  			printf("\t");	  			ctrlf = false;			} else	  			printf(",");			printf("v%d", vregs[i].regval);      	}    }        if (ins == O_CASEB || ins == O_CASEW || ins == O_CASEL) {	for (argno = 0; argno <= argval; argno++) {	    iread(&offset, addr, sizeof(offset));	    printf("\n\t\t%d", offset);	    addr += 2;	}    }        printf("\n");    return addr;}    /* * Print the displacement of an instruction that uses displacement * addressing. */

⌨️ 快捷键说明

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