#ident "$Header: pte.c 1.3 88/07/12 $"

/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#include "crash.h"

#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/dir.h>
#include <sys/resource.h>
#include <signal.h>
#include <sys/user.h>
#include <sys/timer.h>
#include <sys/proc.h>
#include <sys/pte.h>

#define	INDEX1	0xff0000
#define	INDEX2	0x00fe00
#define	OFFSET	0x0001ff

Upte()
{

	struct proc *p;
	struct user *u;
	char *arg;
	unsigned long vaddr;
	unsigned long idx1;
	unsigned long idx2;
	unsigned long phys;
	struct pte pte;
	char *c;

	if ((arg = token()) == NULL) {
		printf("need a number\n");
		return;
	}

	if ((p = readproc(getproc(arg))) == NULL)
		return;
	

	printf("\tul1pt(phys) ul1pt(virt) ul2pt(phys) ul2pt(virt)\n");
	printf("\t %#x    %#x    %#x    %#x\n",
		 p->p_ptb1, p->p_pttop, vtop(p->p_ul2pt), p->p_ul2pt);

	if ((arg = token()) == NULL) 
		return;

	vaddr = atoi(arg);

	idx1 = p->p_ptb1 + ((vaddr & INDEX1) >> 14);
	if (readp(idx1, &pte, sizeof pte) != sizeof pte) {
		printf("read error on pte\n");
		return;
	}
	printf("\n");
	printf("\tpage\t addr of\t:valid:prot:pg_pfnum << 9\n");
	printf("\ttable\tpte entry\n");
	printf("\tUL1PT:\t%#x\t", idx1);
	printf("%s:", pte.pg_v & PG_V ? "v" : "i");
	if (pte.pg_prot & PG_KR)
		c = "kr";
	if (pte.pg_prot & PG_KW)
		c = "kw";
	if (pte.pg_prot & PG_URKW)
		c = "ur";
	if (pte.pg_prot & PG_UW)
		c = "uw";
	printf("%2s:%#x \n", c, pte.pg_pfnum << 9);

	idx2 = (pte.pg_pfnum << 9) + ((vaddr & INDEX2) >> 7);	
	if (readp(idx2, &pte, sizeof pte) != sizeof pte) {
		printf("read error on pte\n");
		return;
	}
	printf("\tUL2PT:\t%#x\t", idx2);
	printf("%s:", pte.pg_v & PG_V ? "v" : "i");
	if (pte.pg_prot & PG_KR)
		c = "kr";
	if (pte.pg_prot & PG_KW)
		c = "kw";
	if (pte.pg_prot & PG_URKW)
		c = "ur";
	if (pte.pg_prot & PG_UW)
		c = "uw";
	printf("%2s:%#x \n", c, pte.pg_pfnum << 9);

	phys = (pte.pg_pfnum << 9) + (vaddr & OFFSET);
	printf("\t\tphysaddr = %#x\n", phys);
		
}
