Google
 

Trailing-Edge - PDP-10 Archives - BB-H311D-RM - swskit-hacks/lokpgs.c
There is 1 other file named lokpgs.c in the archive. Click here to see a list.
/*
 * lokpgs.c -- program to count locked pages in the monitor
 *
 * Greg Zima, 1984.
 */

#include stdio.h

#define OURNAME "LOKPGS"
#define USAGE "Usage:  lokpgs [/h]"
#define PLKMSK	0777700000000

int	cst1[10000],		/* copy of CST1 table */
	maxcor,			/* size of cst tables */
	cst1adr;		/* address of cst1    */

#include helper.c

main(argc,argv)
	int argc;
	char *argv[];
{
	int i;

/* Parse the input commands */

	if (argc > 1) {
		for (i=1; i<argc; ++i) {
			if (argv[i][0] == '/') {
				switch (argv[i][1]) {
				case 'h':
				case 'H':
					helper(OURNAME); exit();
	
				default:
					badcommand();
				}
				}
			else badcommand();
			}
		}

/* do the work */

	lokpgs();
	return;
}

/*
 * badcommand -- print usage text and exit
 */
badcommand()
{
	fputs(USAGE,stderr); abort(ERRCODE);
}

/*
 * strcat -- append src string to dst string
 */
strcat(dst,src)
	char *dst,*src;
{
	char *olddst;

	olddst=dst; while (*dst) ++dst;
	while (*dst++ = *src++) ;
	return olddst;
}


/*
 * lokpgs -- do the actual work
 */
lokpgs()
{
	int i,count;

	dopeek();				/* peek CST1 into its buffer */
	for (i=count=0; i<=maxcor; ++i) {	/* loop over all core */
		if (cst1[i] & PLKMSK) ++count;	/* count locked pages */
		}
	fputs("\n",stdout);			/* print the result */
	outdec(count);
	fputs(". locked pages counted on system.\n",stdout);
}

/*
 * dopeek -- routine to figure out where the CST1 is in the monitor
 *		and copy it to our buffer.  Size of memory is taken
 *		from NHIPG, which has the number of the highest page.
 */
dopeek()
{

	if ((maxcor=snoopsymbol("NHIPG")) == 0) snperr();
	jpeek(maxcor,1,&maxcor);			/* read size */
	if ((cst1adr=snoopsymbol("CST1")) != 0) {	/* prior to v6 */
		jpeek(cst1adr,maxcor+1,&cst1[0]);	/* read it */
		}
	else if ((cst1adr=snoopsymbol("CST1X")) != 0) {	/* v6 */
		jpeek(cst1adr,1,&cst1adr);		/* get val from table */
		jpeek(cst1adr,maxcor+1,&cst1[0]);	/* read it */
		}
	else snperr();
}

/*
 * jpeek -- do the peek or xpeek jsys to read monitor memory
 */
jpeek(srcadr,size,dstadr)
	int *srcadr,size,*dstadr;
{
#asm
	SEARCH	MONSYM,MACSYM
	SALL

	MOVE	1,-3(P)		;FETCH MONITOR ADDRESS
	TLNE	1,-1		;SECTION ZERO?
	 JRST	JSNO.1		; NO, TRY XPEEK
	HRL	1,-2(P)		;YES, SET WORD COUNT
	MOVE	2,-1(P)		;USER ADDRESS TO COPY INTO
	PEEK%			;DO THE PEEK
	 ERJMP	.+1		;ERROR
	RET			;OK

IFNDEF XPEEK%,<			;IF ON OLD MONITOR...
	XPEEK%==<JSYS ^O626>
	.XPPEK==1
	.XPCN1==2
	.XPMAD==4
	.XPUAD==5
   >				;END OF SYMBOL DEFS

XPKBLK:	6			;WORDS IN BLOCK
	.XPPEK			;XPEEK
	0			;COUNT
	0			;RETURNED COUNT
	0			;MONITOR ADDRESS
	0			;USER ADDRESS

JSNO.1:	MOVEM	1,XPKBLK+.XPMAD	;STORE MONITOR ADDRESS
	MOVE	1,-2(P)		;COUNT
	MOVEM	1,XPKBLK+.XPCN1	;STORE
	MOVE	1,-1(P)		;USER ADDRESS
	MOVEM	1,XPKBLK+.XPUAD	;STORE
	MOVEI	1,XPKBLK	;POINT TO BLOCK
	XPEEK%			;DO IT
	 ERJMP	.+1		;ERROR
#endasm
}

/*
 * snoopsymbol -- snoop the monitor for the value of a symbol
 */
snoopsymbol(str)
	char *str;
{
	int r50sym;

	r50sym=0;
	while (*str) {
		r50sym *= 050;		/* radix 50 */
		if (isalpha(*str)) {	/* alphabetic */
			r50sym += toupper(*str) - 'A'+11;
			}
		else if (isdigit(*str)) { /* numeric */
			r50sym += *str - '0'+1;
			}
		else switch (*str) {	/* special cases */
			case '.':
				r50sym += 045; break;
			case '$':
				r50sym += 046; break;
			case '%':
				r50sym += 047; break;
			default:
			}
		++str;			/* next character */
		}
	return jsnoop(r50sym);		/* do the jsys */
}

/*
 * jsnoop -- do the snoop jsys for the passed radix50 symbol, return value
 */
jsnoop(sym)
	int sym;
{
#asm
	SEARCH MONSYM,MACSYM
	SALL

	MOVX	1,.SNPSY	;SNOOP MONITOR SYMBOL VALUE
	MOVE	2,-1(P)		;SYMBOL NAME
	MOVX	3,0		;SEARCH PAINFULLY WHOLE TABLE
	SNOOP%			;DO IT
	 SETZ	2,		;RETURN ZERO ON ERRORS
	MOVE	H,2		;COPY RESULT
#endasm
}

/*
 * snperr -- here to report fatal snoop errors
 */
snperr()
{
	fputs("\n? Cannot SNOOP proper symbols",stderr);
	exit();
}

/*
 * outdec -- output decimal integer to standard output file
 */
outdec(num)
	int num;
{
	int k;
	if (num<0) {num=-num; putc('-',stdout);}
	k=num/10; if (k) outdec(k);
	putc(num%10+'0',stdout);
}

#include ctype.c

/* End of LOKPGS.C */