/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by Mike Parker.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#include <vax/psl.h>

#include "../sys/rciext/kacrash.h"

char pslmode(mode)
int mode;
{
 if ((mode >= 0) && (mode <= 3))
  { return("KESU"[mode]);
  }
 else
  { return('?');
  }
}

printpsl(psl)
int psl;
{
 static struct {
	  int bit;
	  char *name;
	  } bits[] = {
#define BIT(x) { PSL_/**/x, "x" }
		       BIT(CM),
		       BIT(TP),
		       BIT(FPD),
		       BIT(IS),
		       BIT(DV),
		       BIT(FU),
		       BIT(IV),
		       BIT(T),
		       BIT(N),
		       BIT(Z),
		       BIT(V),
		       BIT(C),
		       { 0, 0 } };
#undef BIT
 int i;

 printf("<CUR=%c",pslmode((psl&PSL_CURMOD)/(PSL_CURMOD&-PSL_CURMOD)));
 printf(",PRV=%c",pslmode((psl&PSL_PRVMOD)/(PSL_PRVMOD&-PSL_PRVMOD)));
 printf(",IPL=%d",(psl&PSL_IPL)/(PSL_IPL&-PSL_IPL));
 for (i=0;bits[i].name;i++)
  { printf(",%s=%c",bits[i].name,(psl&bits[i].bit)?'1':'0');
  }
 printf(">");
}

accvio(args,regs)
struct {
  int bits;
  int vaddr;
  int pc;
  int psl; } *args;
int regs[];
{
 if (((args->bits&3) == 1) && growstack(args->vaddr))
  { return;
  }
 if ((args->psl & PSL_CURMOD) == PSL_CURMOD)
  { extern CRASHINFO crashinfo;
    crashinfo.type = CI_MEMFAULT;
    crashinfo.pc = args->pc; /* XXX */
    crashinfo.psl = args->psl;
    crashinfo.u.memfault.bits = args->bits;
    crashinfo.u.memfault.vaddr = args->vaddr;
    usercrash(regs);
    return;
  }
 splhigh();
 printf("\
Access violation\n\
	%s access\n\
	addr 0x%08x\n\
	%s fault\n\
	%s violation\n\
	pc 0x%08x\n\
	psl 0x%08x\n\
",
		(args->bits&4) ? "write" : "read",
		args->vaddr,
		(args->bits&2) ? "PTE" : "page",
		(args->bits&1) ? "length" : "protection",
		args->pc,
		args->psl );
 printpsl(args->psl);
 printf("\n");
 regdump(regs);
 panic("accvio");
}
