Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/gnot/trap.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname gnot/trap.c 1990/03091
## diff -e /dev/null /n/bootesdump/1990/03091/sys/src/9/68020/trap.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"ureg.h"
#include	"io.h"

void	notify(Ureg*);
void	noted(Ureg**);
void	rfnote(Ureg**);

char *regname[]={
	"R0",
	"R1",
	"R2",
	"R3",
	"R4",
	"R5",
	"R6",
	"R7",
	"A0",
	"A1",
	"A2",
	"A3",
	"A4",
	"A5",
	"A6",
	"A7",
};

long	ticks;

char *trapname[]={
	"reset isp",
	"reset ipc",
	"bus error",
	"address error",
	"illegal instruction",
	"zero divide",
	"chk, chk2 instruction",
	"cptrapcc, trapcc, trapv instruction",
	"privilege violation",
	"trace",
	"line 1010 emulator",
	"line 1111 emulator",
	"reserved",
	"coprocessor protocol violation",
	"format error",
	"uninitialized interrupt",
	"unassigned 0x40",
	"unassigned 0x44",
	"unassigned 0x48",
	"unassigned 0x4C",
	"unassigned 0x50",
	"unassigned 0x54",
	"unassigned 0x58",
	"unassigned 0x5C",
	"spurious interrupt",
	"level 1 autovector (tac)",
	"level 2 autovector (port)",
	"level 3 autovector (incon)",
	"level 4 autovector (mouse)",
	"level 5 autovector (uart)",
	"level 6 autovector (sync)",
	"level 7 autovector",
};

char*
excname(unsigned vo)
{
	static char buf[32];	/* BUG: not reentrant! */

	vo &= 0x0FFF;
	vo >>= 2;
	if(vo < sizeof trapname/sizeof(char*))
		return trapname[vo];
	sprint(buf, "offset 0x%ux", vo<<2);
	return buf;
}

void
trap(Ureg *ur)
{
	int user;
	char buf[64];

	user = !(ur->sr&SUPER);

	if(u)
		u->p->pc = ur->pc;		/* BUG */
	if(user){
		sprint(buf, "pc=%lux trap: %s", ur->pc, excname(ur->vo));
		postnote(u->p, 1, buf, NDebug);
	}else{
		print("kernel trap vo=%ux pc=%lux\n", ur->vo, ur->pc);
		dumpregs(ur);
		exit();
	}
	if(user && u->nnote)
		notify(ur);
}

void
dumpstack(void)
{
	ulong l, v;
	extern ulong etext;

	if(u)
		for(l=(ulong)&l; l<USERADDR+BY2PG; l+=4){
			v = *(ulong*)l;
			if(KTZERO < v && v < (ulong)&etext)
				print("%lux=%lux\n", l, v);
		}
}

void
dumpregs(Ureg *ur)
{
	int i;
	ulong *l;

	if(u)
		print("registers for %s %d\n", u->p->text, u->p->pid);
	else
		print("registers for kernel\n");
	print("SR=%ux PC=%lux VO=%lux, USP=%lux\n", ur->sr, ur->pc, ur->vo, ur->usp);
	l = &ur->r0;
	for(i=0; i<sizeof regname/sizeof(char*); i+=2, l+=2)
		print("%s\t%.8lux\t%s\t%.8lux\n", regname[i], l[0], regname[i+1], l[1]);
	dumpstack();
}

/*
 * Call user, if necessary, with note
 */
void
notify(Ureg *ur)
{
	ulong sp;

	lock(&u->p->debug);
	if(u->nnote==0){
		unlock(&u->p->debug);
		return;
	}
	if(u->note[0].flag!=NUser && (u->notified || u->notify==0)){
		if(u->note[0].flag == NDebug)
			pprint("suicide: %s\n", u->note[0].msg);
    Die:
		unlock(&u->p->debug);
		pexit(u->note[0].msg, u->note[0].flag!=NDebug);
	}
	if(!u->notified){
		if(!u->notify)
			goto Die;
		#ifdef asdfasdf
		sp = ur->sp;
		sp -= sizeof(Ureg);
		u->ureg = (void*)sp;
		memcpy((Ureg*)sp, ur, sizeof(Ureg));
		sp -= ERRLEN;
		memcpy((char*)sp, u->note[0].msg, ERRLEN);
		sp -= 3*BY2WD;
		*(ulong*)(sp+2*BY2WD) = sp+3*BY2WD;	/* arg 2 is string */
		*(ulong*)(sp+1*BY2WD) = (ulong)u->ureg;	/* arg 1 is ureg* */
		*(ulong*)(sp+0*BY2WD) = 0;		/* arg 0 is pc */
		ur->sp = sp;
		ur->pc = (ulong)u->notify;
		u->notified = 1;
		u->nnote--;
		memcpy(&u->note[0], &u->note[1], u->nnote*sizeof(Note));
		#endif
		panic("notify");
	}
	unlock(&u->p->debug);
}

/*
 * Return user to state before notify()
 */
void
noted(Ureg **urp)
{
	#ifdef asdfasdf
	lock(&u->p->debug);
	u->notified = 0;
	memcpy(*urp, u->ureg, sizeof(Ureg));
	unlock(&u->p->debug);
	splhi();
	rfnote(urp);
	#endif
	panic("noted");
}

#undef	CHDIR	/* BUG */
#include "/sys/src/libc/680209sys/sys.h"

typedef long Syscall(ulong*);
Syscall	sysr1, sysfork, sysexec, sysgetpid, syssleep, sysexits, syslasterr, syswait;
Syscall	sysopen, sysclose, sysread, syswrite, sysseek, syserrstr, sysaccess, sysstat, sysfstat;
Syscall sysdup, syschdir, sysforkpgrp, sysbind, sysmount, syspipe, syscreate, sysuserstr;
Syscall	sysbrk_, sysremove, syswstat, sysfwstat;

Syscall *systab[]={
	sysr1,
	sysaccess,
	sysbind,
	syschdir,
	sysclose,
	sysdup,
	syserrstr,
	sysexec,
	sysexits,
	sysfork,
	sysforkpgrp,
	sysfstat,
	syslasterr,
	sysmount,
	sysopen,
	sysread,
	sysseek,
	syssleep,
	sysstat,
	syswait,
	syswrite,
	syspipe,
	syscreate,
	sysuserstr,
	sysbrk_,
	sysremove,
	syswstat,
	sysfwstat,
};

long
syscall(Ureg *aur)
{
	long ret;
	ulong sp;
	ulong r0;
	Ureg *ur;

	u->p->insyscall = 1;
	ur = aur;
	if(ur->sr & SUPER)
		panic("recursive system call");
#ifdef asdf
	/*
	 * since the system call interface does not
	 * guarantee anything about registers
	 */
	if(u->p->fpstate == FPactive) {
		u->p->fpstate = FPinit;		/* BUG */
		ur->status &= ~CU1;
	}
#endif
	r0 = ur->r0;
	sp = ur->usp;
	if(r0 >= sizeof systab/BY2WD)
		panic("syscall %d\n", r0);
	if(sp & (BY2WD-1))
		panic("syscall odd sp");
	if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-4*BY2WD))
		validaddr(sp, 4*BY2WD, 0);

	u->nerrlab = 0;
	ret = -1;
	if(!waserror())
		ret = (*systab[r0])((ulong*)(sp+BY2WD));
	u->nerrlab = 0;
	u->p->insyscall = 0;
	if(r0 == NOTED)	/* ugly hack */
		noted(&aur);	/* doesn't return */
	if(u->nnote){
		ur->r0 = ret;
		notify(ur);
	}
{ulong *arg=(ulong*)(sp+BY2WD);
if(ret==-1)print("syscall %d(%lux %lux %lux) returns error %d\n", r0, arg[0], arg[1], arg[2], u->error.code);}
	return ret;
}

void
error(Chan *c, int code)
{
	if(c){
		u->error.type = c->type;
		u->error.dev = c->dev;
	}else{
		u->error.type = 0;
		u->error.dev = 0;
	}
	u->error.code = code;
	nexterror();
}

void
nexterror(void)
{
	gotolabel(&u->errlab[--u->nerrlab]);
}
.
## diffname gnot/trap.c 1990/0312
## diff -e /n/bootesdump/1990/03091/sys/src/9/68020/trap.c /n/bootesdump/1990/0312/sys/src/9/68020/trap.c
246a
	u->p->pc = ur->pc;
.
## diffname gnot/trap.c 1990/0315
## diff -e /n/bootesdump/1990/0312/sys/src/9/68020/trap.c /n/bootesdump/1990/0315/sys/src/9/68020/trap.c
281,282d
## diffname gnot/trap.c 1990/0321
## diff -e /n/bootesdump/1990/0315/sys/src/9/68020/trap.c /n/bootesdump/1990/0321/sys/src/9/68020/trap.c
272a
else print("syscall %d err %d %d\n", r0, u->error.type, u->error.code);
.
## diffname gnot/trap.c 1990/0322
## diff -e /n/bootesdump/1990/0321/sys/src/9/68020/trap.c /n/bootesdump/1990/0322/sys/src/9/68020/trap.c
273c
/* else print("syscall %d err %d %d\n", r0, u->error.type, u->error.code); /**/
.
## diffname gnot/trap.c 1990/0511
## diff -e /n/bootesdump/1990/0322/sys/src/9/68020/trap.c /n/bootesdump/1990/0511/sys/src/9/68020/trap.c
271,273c
	if(!waserror()){
		if(r1 >= sizeof systab/BY2WD){
			pprint("bad sys call number %d pc %lux\n", r1, ((Ureg*)UREGADDR)->pc);
			msg = "bad sys call";
	    Bad:
			postnote(u->p, 1, msg, NDebug);
			error(0, Ebadarg);
		}
		if(sp & (BY2WD-1)){
			pprint("odd sp in sys call pc %lux sp %lux\n", ((Ureg*)UREGADDR)->pc, ((Ureg*)UREGADDR)->sp);
			msg = "odd stack";
			goto Bad;
		}
		if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-4*BY2WD))
			validaddr(ur->sp, 4*BY2WD, 0);
		ret = (*systab[r1])((ulong*)(sp+2*BY2WD));
	}
.
262,267d
## diffname gnot/trap.c 1990/0513
## diff -e /n/bootesdump/1990/0511/sys/src/9/68020/trap.c /n/bootesdump/1990/0513/sys/src/9/68020/trap.c
280c
		ret = (*systab[r0])((ulong*)(sp+2*BY2WD));
.
266,267c
		if(r0 >= sizeof systab/BY2WD){
			pprint("bad sys call number %d pc %lux\n", r0, ((Ureg*)UREGADDR)->pc);
.
243a
	char *msg;
.
7a
#include	"errno.h"
.
## diffname gnot/trap.c 1990/0515
## diff -e /n/bootesdump/1990/0513/sys/src/9/68020/trap.c /n/bootesdump/1990/0515/sys/src/9/68020/trap.c
281,282c
			validaddr(sp, 4*BY2WD, 0);
		ret = (*systab[r0])((ulong*)(sp+BY2WD));
.
## diffname gnot/trap.c 1990/0619
## diff -e /n/bootesdump/1990/0515/sys/src/9/68020/trap.c /n/bootesdump/1990/0619/sys/src/9/68020/trap.c
188a
	if(!u->notified){
		unlock(&u->p->debug);
		return;
	}
.
## diffname gnot/trap.c 1990/08141
## diff -e /n/bootesdump/1990/0619/sys/src/9/68020/trap.c /n/bootesdump/1990/08141/sys/src/9/68020/trap.c
239a
	sysnotify,
	sysnoted,
.
209c
Syscall	sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted;
.
## diffname gnot/trap.c 1990/0816
## diff -e /n/bootesdump/1990/08141/sys/src/9/68020/trap.c /n/bootesdump/1990/0816/sys/src/9/68020/trap.c
198,199d
187d
175,176d
170c
		ur->usp = sp;
.
159,160c
		sp = ur->usp;
.
## diffname gnot/trap.c 1990/08163
## diff -e /n/bootesdump/1990/0816/sys/src/9/68020/trap.c /n/bootesdump/1990/08163/sys/src/9/68020/trap.c
261c
	spllo();
.
257,259c
	splhi();
	fpsave(&u->fpsave);
	if(u->p->fpstate==FPactive || u->fpsave.type){
		fprestore((FPsave*)&fpnull);
		u->p->fpstate = FPinit;
		m->fpstate = FPinit;
.
255c
	 * guarantee anything about registers, but the fpcr is more than
	 * just a register...  BUG
.
252d
245a
	long fpnull = 0;
.
## diffname gnot/trap.c 1990/0905
## diff -e /n/bootesdump/1990/08163/sys/src/9/68020/trap.c /n/bootesdump/1990/0905/sys/src/9/68020/trap.c
261c
		fprestore(&initfp);
.
246d
97c
		print("kernel trap vo=0x%ux pc=%lux\n", ur->vo, ur->pc);
.
## diffname gnot/trap.c 1990/1104
## diff -e /n/bootesdump/1990/0905/sys/src/9/68020/trap.c /n/bootesdump/1990/1104/sys/src/9/68020/trap.c
235a
	sysfilsys,
.
203c
Syscall	sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted, sysfilsys;
.
## diffname gnot/trap.c 1990/1110
## diff -e /n/bootesdump/1990/1104/sys/src/9/68020/trap.c /n/bootesdump/1990/1110/sys/src/9/68020/trap.c
281c
			msg = "sys: odd stack";
.
274c
			msg = "sys: bad sys call";
.
94c
		sprint(buf, "sys: trap: %s", ur->pc, excname(ur->vo));
.
## diffname gnot/trap.c 1990/11211
## diff -e /n/bootesdump/1990/1110/sys/src/9/68020/trap.c /n/bootesdump/1990/11211/sys/src/9/68020/trap.c
311a

void
errors(char *err)
{
	strncpy(u->error, err, NAMELEN);
	nexterror();
}

.
302,309c
	strncpy(u->error, errstrtab[code], NAMELEN);
.
300c
error(int code)
.
298a
#include "errstr.h"

.
284,285c
		if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-5*BY2WD))
			validaddr(sp, 5*BY2WD, 0);
.
277c
			error(Ebadarg);
.
236c
	sysdeath,	/* sysfilsys */
.
229c
	sysdeath,
.
218c
	sysdeath,
.
212c
	sysdeath,
.
207c
	syserrstr,
.
202,203c
Syscall sysdup, syschdir, sysforkpgrp, sysbind, sysmount, syspipe, syscreate;
Syscall	sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted;
.
200c
Syscall	sysr1, sysfork, sysexec, sysgetpid, syssleep, sysexits, sysdeath, syswait;
.
## diffname gnot/trap.c 1990/1127
## diff -e /n/bootesdump/1990/11211/sys/src/9/68020/trap.c /n/bootesdump/1990/1127/sys/src/9/68020/trap.c
97c
		print("kernel trap vo=0x%ux pc=0x%lux\n", ur->vo, ur->pc);
.
94c
		sprint(buf, "sys: trap: pc=0x%lux %s", ur->pc, excname(ur->vo));
.
## diffname gnot/trap.c 1990/1226
## diff -e /n/bootesdump/1990/1127/sys/src/9/68020/trap.c /n/bootesdump/1990/1226/sys/src/9/68020/trap.c
298a
void
execpc(ulong entry)
{
	((Ureg*)UREGADDR)->pc = entry;
}

.
## diffname gnot/trap.c 1991/0115
## diff -e /n/bootesdump/1990/1226/sys/src/9/68020/trap.c /n/bootesdump/1991/0115/sys/src/9/68020/trap.c
310c
	strncpy(u->error, errstrtab[code], ERRLEN);
.
## diffname gnot/trap.c 1991/0318
## diff -e /n/bootesdump/1991/0201/sys/src/9/68020/trap.c /n/bootesdump/1991/0318/sys/src/9/gnot/trap.c
190c
	memmove(*urp, u->ureg, sizeof(Ureg));
.
173c
		memmove(&u->note[0], &u->note[1], u->nnote*sizeof(Note));
.
164c
		memmove((char*)sp, u->note[0].msg, ERRLEN);
.
162c
		memmove((Ureg*)sp, ur, sizeof(Ureg));
.
## diffname gnot/trap.c 1991/0322
## diff -e /n/bootesdump/1991/0318/sys/src/9/gnot/trap.c /n/bootesdump/1991/0322/sys/src/9/gnot/trap.c
317c
	strncpy(u->error, err, ERRLEN);
.
## diffname gnot/trap.c 1991/0503
## diff -e /n/bootesdump/1991/0322/sys/src/9/gnot/trap.c /n/bootesdump/1991/0503/sys/src/9/gnot/trap.c
291c
		noted(aur);	/* doesn't return */
.
193c
	rfnote(ur);
.
190c
	memmove(ur, u->ureg, sizeof(Ureg));
.
183a
	Ureg *nur;

	nur = u->ureg;
	validaddr(nur->pc, 1, 0);
	validaddr(nur->usp, BY2WD, 0);
	if(nur->sr!=u->svsr || nur->vo!=u->svvo){
		pprint("bad noted ureg sr %ux vo %ux\n", nur->sr, nur->vo);
		pexit("Suicide", 0);
	}
.
182c
noted(Ureg *ur)
.
158a
		u->svvo = ur->vo;
		u->svsr = ur->sr;
.
11,12c
void	noted(Ureg*);
void	rfnote(Ureg*);
.
## diffname gnot/trap.c 1991/0513
## diff -e /n/bootesdump/1991/0503/sys/src/9/gnot/trap.c /n/bootesdump/1991/0513/sys/src/9/gnot/trap.c
223c
	sysalarm,
.
214c
Syscall	sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted, sysalarm;
.
## diffname gnot/trap.c 1991/0614
## diff -e /n/bootesdump/1991/0513/sys/src/9/gnot/trap.c /n/bootesdump/1991/0614/sys/src/9/gnot/trap.c
299c
	if(u->nerrlab){
		print("unbalanced error stack: %d extra\n", u->nerrlab);
		for(i = 0; i < NERR; i++)
			print("sp=%lux pc=%lux\n", u->errlab[i].sp, u->errlab[i].pc);
		panic("bad rob");
	}
.
297a
		poperror();
.
295,296c
		if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-(1+MAXSYSARG)*BY2WD))
			validaddr(sp, (1+MAXSYSARG)*BY2WD, 0);
.
252a
	int i;
.
## diffname gnot/trap.c 1991/0705
## diff -e /n/bootesdump/1991/0614/sys/src/9/gnot/trap.c /n/bootesdump/1991/0705/sys/src/9/gnot/trap.c
308c

	if(r0 == NOTED)		/* ugly hack */
.
306a
#endif

.
302c
		print("bad errstack [%d]: %d extra\n", r0, u->nerrlab);
.
300a

#ifdef Check
.
292c
			pprint("odd sp in sys call pc %lux sp %lux\n", 
				((Ureg*)UREGADDR)->pc, ((Ureg*)UREGADDR)->sp);
.
247c
	syssegattach,
	syssegdetach,
	syssegfree,
	syssegflush,
.
229c
	syssegbrk,
.
214a
Syscall syssegattach, syssegdetach, syssegfree, syssegflush, syssegbrk;
.
132a
	for(;;);
.
100a

.
94c
		sprint(buf, "sys: %s pc=0x%lux", excname(ur->vo), ur->pc);
.
## diffname gnot/trap.c 1991/0709
## diff -e /n/bootesdump/1991/0705/sys/src/9/gnot/trap.c /n/bootesdump/1991/0709/sys/src/9/gnot/trap.c
316d
314c
		panic("error stack");
.
309d
## diffname gnot/trap.c 1991/0710
## diff -e /n/bootesdump/1991/0709/sys/src/9/gnot/trap.c /n/bootesdump/1991/0710/sys/src/9/gnot/trap.c
331,353d
210c
#include "/sys/src/libc/9syscall/sys.h"
.
## diffname gnot/trap.c 1991/0717
## diff -e /n/bootesdump/1991/0710/sys/src/9/gnot/trap.c /n/bootesdump/1991/0717/sys/src/9/gnot/trap.c
319c
		noted(aur, *(ulong*)(sp+BY2WD));	/* doesn't return */
.
204,206c
	ur->r0 = -1;	/* return error from the interrupted call */
	switch(arg0){
	case NCONT:
		splhi();
		unlock(&u->p->debug);
		rfnote(ur);
		break;
		/* never returns */

	default:
		pprint("unknown noted arg 0x%lux\n", arg0);
		u->lastnote.flag = NDebug;
		/* fall through */
		
	case NTERM:
		if(u->lastnote.flag == NDebug)
			pprint("suicide: %s\n", u->lastnote.msg);
		unlock(&u->p->debug);
		pexit(u->lastnote.msg, u->lastnote.flag!=NDebug);
	}
.
186c
noted(Ureg *ur, ulong arg0)
.
176a
		memmove(&u->lastnote, &u->note[0], sizeof(Note));
.
11c
void	noted(Ureg*, ulong);
.
## diffname gnot/trap.c 1991/0718
## diff -e /n/bootesdump/1991/0717/sys/src/9/gnot/trap.c /n/bootesdump/1991/0718/sys/src/9/gnot/trap.c
219c
	case NDFLT:
.
## diffname gnot/trap.c 1991/0719
## diff -e /n/bootesdump/1991/0718/sys/src/9/gnot/trap.c /n/bootesdump/1991/0719/sys/src/9/gnot/trap.c
174a
		ur->vo = 0x0080;	/* pretend we're returning from syscall */
.
## diffname gnot/trap.c 1991/0722
## diff -e /n/bootesdump/1991/0719/sys/src/9/gnot/trap.c /n/bootesdump/1991/0722/sys/src/9/gnot/trap.c
164a
		if(waserror()){
			pprint("suicide: trap in notify\n");
			unlock(&u->p->debug);
			pexit("Suicide", 0);
		}
		validaddr((ulong)u->notify, 1, 0);
		validaddr(sp-ERRLEN-3*BY2WD, sizeof(Ureg)+ERRLEN-3*BY2WD, 0);
		poperror();
.
## diffname gnot/trap.c 1991/0725
## diff -e /n/bootesdump/1991/0722/sys/src/9/gnot/trap.c /n/bootesdump/1991/0725/sys/src/9/gnot/trap.c
347c
	if(u->nnote && r0!=FORK){
.
214d
## diffname gnot/trap.c 1991/0727
## diff -e /n/bootesdump/1991/0725/sys/src/9/gnot/trap.c /n/bootesdump/1991/0727/sys/src/9/gnot/trap.c
150a
	u->p->notepending = 0;
.
## diffname gnot/trap.c 1991/0731
## diff -e /n/bootesdump/1991/0727/sys/src/9/gnot/trap.c /n/bootesdump/1991/0731/sys/src/9/gnot/trap.c
317c
		if(r0 >= sizeof systab/sizeof systab[0]){
.
239,282d
236,237c
#include "../port/systab.h"
.
## diffname gnot/trap.c 1991/0814
## diff -e /n/bootesdump/1991/0731/sys/src/9/gnot/trap.c /n/bootesdump/1991/0814/sys/src/9/gnot/trap.c
216a
		if(waserror()){
			pprint("suicide: trap in noted\n");
			unlock(&u->p->debug);
			goto Die;
		}
		validaddr(nur->pc, 1, 0);
		validaddr(nur->usp, BY2WD, 0);
		poperror();
.
211c
		pprint("call to noted() when not notified\n");
		goto Die;
.
205a
    Die:
.
202,203d
## diffname gnot/trap.c 1991/0821
## diff -e /n/bootesdump/1991/0814/sys/src/9/gnot/trap.c /n/bootesdump/1991/0821/sys/src/9/gnot/trap.c
134c

.
## diffname gnot/trap.c 1991/0926
## diff -e /n/bootesdump/1991/0821/sys/src/9/gnot/trap.c /n/bootesdump/1991/0926/sys/src/9/gnot/trap.c
306a
	u->p->psstate = 0;
.
294a
		u->p->psstate = sysctab[r0];
.
## diffname gnot/trap.c 1991/1108
## diff -e /n/bootesdump/1991/0926/sys/src/9/gnot/trap.c /n/bootesdump/1991/1108/sys/src/9/gnot/trap.c
300,305c
	u->nerrlab = 0;
	if(u->p->procctl)
		procctl(u->p);
.
273a

	if(u->p->procctl)
		procctl(u->p);

.
102,103c
	if(user) {
		if(u->p->procctl)
			procctl(u->p);
		if(u->nnote)
			notify(ur);
	}
.
## diffname gnot/trap.c 1991/1112
## diff -e /n/bootesdump/1991/1108/sys/src/9/gnot/trap.c /n/bootesdump/1991/1112/sys/src/9/gnot/trap.c
327a
}

/* This routine must save the values of registers the user is not permitted to write
 * from devproc and the restore the saved values before returning
 */
void
setregisters(Ureg *xp, char *pureg, char *uva, int n)
{
	ushort sr;
	ulong magic;
	ushort vo;
	char microstate[UREGVARSZ];

	sr = xp->sr;
	vo = xp->vo;
	magic = xp->magic;
	memmove(microstate, xp->microstate, UREGVARSZ);

	memmove(pureg, uva, n);

	xp->sr = (sr&0xff00) |(xp->sr&0xff);
	xp->vo = vo;
	xp->magic = magic;
	memmove(xp->microstate, microstate, UREGVARSZ);
.
317c
	if(u->p->procctl || (u->nnote && r0!=FORK)){
.
309,311d
261a
	u->dbgreg = aur;
.
154c

	lock(&u->p->debug);
.
150,152c
	if(u->p->procctl)
		procctl(u->p);
	if(u->nnote==0)
.
102,107c
	if(user)
		notify(ur);
.
92a
		u->dbgreg = ur;
	}
.
91c
	if(u) {
.
## diffname gnot/trap.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/gnot/trap.c /n/bootesdump/1991/1113/sys/src/9/gnot/trap.c
99c
		print("kernel trap %s pc=0x%lux\n", excname(ur->vo, ur->pc), ur->pc);
.
96c
		sprint(buf, "sys: %s pc=0x%lux", excname(ur->vo, ur->pc), ur->pc);
.
78a
	}
.
77c
	if(vo < sizeof trapname/sizeof(char*)){
		/* special case, and pc will be o.k. */
		if(vo==4 && *(ushort*)pc==0x4848)
			return "breakpoint";
.
71c
excname(unsigned vo, ulong pc)
.
## diffname gnot/trap.c 1991/1114
## diff -e /n/bootesdump/1991/1113/sys/src/9/gnot/trap.c /n/bootesdump/1991/1114/sys/src/9/gnot/trap.c
318c
	splhi();
	if(r0!=FORK && (u->p->procctl || u->nnote)){
.
197a
	splx(s);
.
156a
	s = spllo();
.
150c
	ulong s, sp;
.
## diffname gnot/trap.c 1991/1115
## diff -e /n/bootesdump/1991/1114/sys/src/9/gnot/trap.c /n/bootesdump/1991/1115/sys/src/9/gnot/trap.c
140,141d
## diffname gnot/trap.c 1991/1214
## diff -e /n/bootesdump/1991/1115/sys/src/9/gnot/trap.c /n/bootesdump/1991/1214/sys/src/9/gnot/trap.c
329a
	return USTKTOP-BY2WD;			/* address of user-level clock */
.
328a
	ulong *sp;

	sp = (ulong*)(USTKTOP - ssize);
	*--sp = nargs;
	((Ureg*)UREGADDR)->usp = (ulong)sp;
.
326,327c
long
execregs(ulong entry, ulong ssize, ulong nargs)
.
## diffname gnot/trap.c 1991/1216
## diff -e /n/bootesdump/1991/1214/sys/src/9/gnot/trap.c /n/bootesdump/1991/1216/sys/src/9/gnot/trap.c
246c
		qunlock(&u->p->debug);
.
233c
		qunlock(&u->p->debug);
.
226c
			qunlock(&u->p->debug);
.
216c
		qunlock(&u->p->debug);
.
214c
	qlock(&u->p->debug);
.
196c
	qunlock(&u->p->debug);
.
174c
			qunlock(&u->p->debug);
.
162c
		qunlock(&u->p->debug);
.
156c
	qlock(&u->p->debug);
.
## diffname gnot/trap.c 1991/12171
## diff -e /n/bootesdump/1991/1216/sys/src/9/gnot/trap.c /n/bootesdump/1991/12171/sys/src/9/gnot/trap.c
82a
	if(49<=vo && vo<=54)
		return fptrapname[vo-49];
.
69a
char *fptrapname[]={
[49-49]	"fp: inexact result",
[50-49]	"fp: divide by zero",
[51-49]	"fp: underflow",
[52-49]	"fp: operand error",
[53-49]	"fp: overflow",
[54-49]	"fp: signaling NaN",
};

.
49c
	"fp: or cp: coprocessor protocol violation",
.
43c
	"fp: trapcc or cp:trapcc instruction",
.
## diffname gnot/trap.c 1991/1218
## diff -e /n/bootesdump/1991/12171/sys/src/9/gnot/trap.c /n/bootesdump/1991/1218/sys/src/9/gnot/trap.c
174c
		pexit(n->msg, n->flag!=NDebug);
.
171c
			pprint("suicide: %s\n", n->msg);
.
169c
	n = &u->note[0];
	if(strncmp(n->msg, "sys:", 4) == 0){
		l = strlen(n->msg);
		if(l > ERRLEN-15)	/* " pc=0x12345678\0" */
			l = ERRLEN-15;
		sprint(n->msg+l, " pc=0x%.8lux", ur->pc);
	}
	if(n->flag!=NUser && (u->notified || u->notify==0)){
.
159a
	Note *n;
.
158a
	int l;
.
111c
		sprint(buf, "sys: %s", excname(ur->vo, ur->pc));
.
92,93c
	if(49<=vo && vo<=54){
		sprint(buf, "fp: %s", fptrapname[vo-49]);
		return buf;
	}
.
90c
		sprint(buf, "trap: %s", trapname[vo]);
		return buf;
.
71,76c
[49-49]	"inexact result",
[50-49]	"divide by zero",
[51-49]	"underflow",
[52-49]	"operand error",
[53-49]	"overflow",
[54-49]	"signaling NaN",
.
49c
	"coprocessor protocol violation",
.
43c
	"trapcc instruction",
.
## diffname gnot/trap.c 1992/0108
## diff -e /n/bootesdump/1991/1218/sys/src/9/gnot/trap.c /n/bootesdump/1992/0108/sys/src/9/gnot/trap.c
220a
	return 1;
.
168,169c
	if(u->nnote == 0)
		return 0;
.
159c
int
.
10d
## diffname gnot/trap.c 1992/0111
## diff -e /n/bootesdump/1992/0108/sys/src/9/gnot/trap.c /n/bootesdump/1992/0111/sys/src/9/gnot/trap.c
8c
#include	"../port/error.h"
.
## diffname gnot/trap.c 1992/0120
## diff -e /n/bootesdump/1992/0111/sys/src/9/gnot/trap.c /n/bootesdump/1992/0120/sys/src/9/gnot/trap.c
360a
ulong
userpc(void)
{
	return ((Ureg*)UREGADDR)->pc;
}

.
## diffname gnot/trap.c 1992/0124
## diff -e /n/bootesdump/1992/0120/sys/src/9/gnot/trap.c /n/bootesdump/1992/0124/sys/src/9/gnot/trap.c
220c
	return sent;
.
189a
		sent = 1;
.
186a
	sent = 0;
.
161c
	int l, sent;
.
## diffname gnot/trap.c 1992/0201
## diff -e /n/bootesdump/1992/0124/sys/src/9/gnot/trap.c /n/bootesdump/1992/0201/sys/src/9/gnot/trap.c
325c
			pprint("odd sp in sys call pc %lux sp %lux\n",
.
## diffname gnot/trap.c 1992/0321
## diff -e /n/bootesdump/1992/0201/sys/src/9/gnot/trap.c /n/bootesdump/1992/0321/sys/src/9/gnot/trap.c
2c
#include	"../port/lib.h"
.
## diffname gnot/trap.c 1992/0430
## diff -e /n/bootesdump/1992/0321/sys/src/9/gnot/trap.c /n/bootesdump/1992/0430/sys/src/9/gnot/trap.c
344c
	if(r0!=RFORK && (u->p->procctl || u->nnote)){
.
## diffname gnot/trap.c 1992/0616
## diff -e /n/bootesdump/1992/0430/sys/src/9/gnot/trap.c /n/bootesdump/1992/0616/sys/src/9/gnot/trap.c
254,256d
249c
		if(!okaddr(nur->pc, 1, 0) || !okaddr(nur->usp, BY2WD, 0)){
.
201,203d
196,197c
		if(!okaddr((ulong)u->notify, 1, 0)
		|| !okaddr(sp-ERRLEN-3*BY2WD, sizeof(Ureg)+ERRLEN-3*BY2WD, 0)){
			pprint("suicide: bad address in notify\n");
.
## diffname gnot/trap.c 1992/0625
## diff -e /n/bootesdump/1992/0616/sys/src/9/gnot/trap.c /n/bootesdump/1992/0625/sys/src/9/gnot/trap.c
328c

		ret = (*systab[r0])(u->s.args);
.
325,326c

		if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-sizeof(Sargs)))
			validaddr(sp, sizeof(Sargs), 0);

		u->s = *((Sargs*)(sp+BY2WD));
.
320,323c
			pprint("odd sp in sys call pc %lux sp %lux\n", ur->pc, ur->sp);
			postnote(u->p, 1, "sys: odd stack", NDebug);
			error(Ebadarg);
.
318a

.
313,316c
			pprint("bad sys call number %d pc %lux\n", r0, ur->pc);
			postnote(u->p, 1, "sys: bad sys call", NDebug);
.
281d
## diffname gnot/trap.c 1992/06271
## diff -e /n/bootesdump/1992/0625/sys/src/9/gnot/trap.c /n/bootesdump/1992/06271/sys/src/9/gnot/trap.c
340c
	if(u->scallnr!=RFORK && (u->p->procctl || u->nnote)){
.
337c
	if(u->scallnr == NOTED)		/* ugly hack */
.
329c
		ret = (*systab[u->scallnr])(u->s.args);
.
327c
		u->p->psstate = sysctab[u->scallnr];
.
311,312c
		if(u->scallnr >= sizeof systab/sizeof systab[0]){
			pprint("bad sys call number %d pc %lux\n", u->scallnr, ur->pc);
.
305c
	u->scallnr = ur->r0;
.
279d
## diffname gnot/trap.c 1992/0701
## diff -e /n/bootesdump/1992/06271/sys/src/9/gnot/trap.c /n/bootesdump/1992/0701/sys/src/9/gnot/trap.c
325c
		u->s = *((Sargs*)(sp+1*BY2WD));
.
## diffname gnot/trap.c 1992/0711
## diff -e /n/bootesdump/1992/0701/sys/src/9/gnot/trap.c /n/bootesdump/1992/0711/sys/src/9/gnot/trap.c
276d
## diffname gnot/trap.c 1992/0714
## diff -e /n/bootesdump/1992/0711/sys/src/9/gnot/trap.c /n/bootesdump/1992/0714/sys/src/9/gnot/trap.c
181c
		if(n->flag == NDebug)
.
## diffname gnot/trap.c 1992/0805
## diff -e /n/bootesdump/1992/0714/sys/src/9/gnot/trap.c /n/bootesdump/1992/0805/sys/src/9/gnot/trap.c
298d
286,296c

	/* must save FP registers before fork */
	if(u->p->fpstate==FPactive && ur->r0==RFORK){
		splhi();
		procsave(u->p);
		spllo();
.
111c

.
108,109c
	if(u)
.
## diffname gnot/trap.c 1992/0806
## diff -e /n/bootesdump/1992/0805/sys/src/9/gnot/trap.c /n/bootesdump/1992/0806/sys/src/9/gnot/trap.c
177c
		sprint(n->msg+l, " pc=0x%lux", ur->pc);
.
111a
		splhi();
		procsave(u->p);
		spllo();
.
93c
		fppc = 0;
		if(u)
			fppc = *(ulong*)(u->fpsave.reg+8);
		sprint(buf, "fp: %s fppc=0x%lux", fptrapname[vo-49], fppc);
.
81a
	ulong fppc;
.
## diffname gnot/trap.c 1992/0812
## diff -e /n/bootesdump/1992/0806/sys/src/9/gnot/trap.c /n/bootesdump/1992/0812/sys/src/9/gnot/trap.c
124c
		exit(1);
.
## diffname gnot/trap.c 1992/1027
## diff -e /n/bootesdump/1992/0812/sys/src/9/gnot/trap.c /n/bootesdump/1992/1027/sys/src/9/gnot/trap.c
142a
	}
	print("\n");
.
137,141c
	if(u==0)
		return;

	i = 0;
	for(l=(ulong)&l; l<USERADDR+BY2PG; l+=4){
		v = *(ulong*)l;
		if(KTZERO < v && v < (ulong)&etext){
			print("%lux\t", v);
			if(++i == 4){
				i = 0;
				print("\n");
			}
.
134c
	ulong l, v, i;
.
## diffname gnot/trap.c 1993/0501 # deleted
## diff -e /n/bootesdump/1992/1027/sys/src/9/gnot/trap.c /n/fornaxdump/1993/0501/sys/src/brazil/gnot/trap.c
1,394d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.