| plan 9 kernel history: overview | file list | diff list |
1993/0212/power/trap.c (diff list | history)
| 1993/0212/sys/src/9/power/trap.c:1,615 – 1993/0225/sys/src/9/power/trap.c:1,616 (short | long | prev | next) | ||
| 1990/0227 | #include "u.h" | |
| 1992/0321 | #include "../port/lib.h" | |
| 1990/0227 | #include "mem.h" #include "dat.h" #include "fns.h" #include "ureg.h" #include "io.h" | |
| 1992/0111 | #include "../port/error.h" | |
| 1990/0227 | void (*vmevec[256])(int); | |
| 1991/0717 | void noted(Ureg**, ulong); | |
| 1990/0227 | void rfnote(Ureg**); char *excname[] = { | |
| 1992/0102 | "trap: external interrupt", "trap: TLB modification", "trap: TLB miss (load or fetch)", "trap: TLB miss (store)", "trap: address error (load or fetch)", "trap: address error (store)", "trap: bus error (fetch)", "trap: bus error (data load or store)", "trap: system call", | |
| 1990/0227 | "breakpoint", | |
| 1992/0102 | "trap: reserved instruction", "trap: coprocessor unusable", "trap: arithmetic overflow", "trap: undefined 13", "trap: undefined 14", | |
| 1992/0803 | "trap: undefined 15", /* used as sys call for debugger */ | |
| 1990/0227 | }; | |
| 1992/1129 | char *fpcause[] = { "inexact operation", "underflow", "overflow", "division by zero", "invalid operation", }; | |
| 1992/0806 | char *fpexcname(Ureg*, ulong, char*); | |
| 1992/1129 | #define FPEXPMASK (0x3f<<12) /* Floating exception bits in fcr31 */ | |
| 1990/0227 | char *regname[]={ "STATUS", "PC", "SP", "CAUSE", "BADADDR", "TLBVIRT", "HI", "LO", "R31", "R30", "R28", "R27", "R26", "R25", "R24", "R23", "R22", "R21", "R20", "R19", "R18", "R17", "R16", "R15", "R14", "R13", "R12", "R11", "R10", "R9", "R8", "R7", "R6", "R5", "R4", "R3", "R2", "R1", }; void trap(Ureg *ur) { int ecode; | |
| 1992/0802 | ulong fcr31; | |
| 1992/1129 | int user, cop, x, fpchk; | |
| 1992/1128 | char buf[2*ERRLEN], buf1[ERRLEN], *fpexcep; | |
| 1992/1129 | ||
| 1992/1202 | m->ur = ur; | |
| 1992/1129 | ecode = (ur->cause>>2)&0xf; | |
| 1990/0227 | user = ur->status&KUP; | |
| 1992/1129 | fpchk = 0; | |
| 1993/0106 | if(user) { u->dbgreg = ur; if(u->p->fpstate == FPactive) { if((ur->status&CU1) == 0) /* Paranoid */ panic("FPactive but no CU1"); u->p->fpstate = FPinactive; ur->status &= ~CU1; savefpregs(&u->fpsave); fptrap(ur); fpchk = 1; } | |
| 1992/1128 | } | |
| 1990/0227 | switch(ecode){ case CINT: | |
| 1992/1128 | if(ur->cause&INTR3) { /* FP trap */ | |
| 1992/1129 | clrfpintr(); | |
| 1992/1128 | ur->cause &= ~INTR3; | |
| 1991/0209 | } intr(ur); | |
| 1990/0227 | break; case CTLBM: case CTLBL: case CTLBS: if(u == 0) | |
| 1990/0802 | panic("fault u==0 pc %lux addr %lux", ur->pc, ur->badvaddr); | |
| 1992/1129 | ||
| 1990/0227 | x = u->p->insyscall; u->p->insyscall = 1; | |
| 1992/1130 | spllo(); | |
| 1990/1212 | faultmips(ur, user, ecode); | |
| 1990/0227 | u->p->insyscall = x; break; case CCPU: | |
| 1992/1128 | cop = (ur->cause>>28)&3; | |
| 1993/0106 | if(user && cop == 1) { | |
| 1992/1128 | if(u->p->fpstate == FPinit) { | |
| 1992/1129 | u->p->fpstate = FPinactive; fcr31 = u->fpsave.fpstatus; u->fpsave = initfp; u->fpsave.fpstatus = fcr31; | |
| 1992/1128 | break; } | |
| 1992/1129 | if(u->p->fpstate == FPinactive) | |
| 1992/1128 | break; | |
| 1990/0227 | } | |
| 1992/1128 | /* Fallthrough */ | |
| 1990/0227 | default: | |
| 1992/1128 | if(user) { | |
| 1990/0227 | spllo(); | |
| 1992/1128 | sprint(buf, "sys: %s", excname[ecode]); | |
| 1990/0227 | postnote(u->p, 1, buf, NDebug); | |
| 1992/1128 | break; | |
| 1990/0227 | } | |
| 1992/1128 | print("kernel %s pc=%lux\n", excname[ecode], ur->pc); dumpregs(ur); dumpstack(); if(m->machno == 0) spllo(); exit(1); | |
| 1990/0227 | } | |
| 1991/0705 | ||
| 1992/1129 | if(fpchk) { fcr31 = u->fpsave.fpstatus; if((fcr31>>12) & ((fcr31>>7)|0x20) & 0x3f) { spllo(); fpexcep = fpexcname(ur, fcr31, buf1); sprint(buf, "sys: fp: %s", fpexcep); postnote(u->p, 1, buf, NDebug); | |
| 1991/1114 | } | |
| 1990/0227 | } | |
| 1992/1129 | splhi(); if(!user) return; notify(ur); if(u->p->fpstate == FPinactive) { | |
| 1993/0107 | restfpregs(&u->fpsave, u->fpsave.fpstatus); | |
| 1992/1129 | u->p->fpstate = FPactive; ur->status |= CU1; } | |
| 1990/0227 | } void | |
| 1991/0209 | intr(Ureg *ur) | |
| 1990/0227 | { long v; | |
| 1993/0211 | int i, any, limit; | |
| 1991/0209 | ulong cause; | |
| 1991/0219 | static int bogies; | |
| 1992/1217 | uchar pend, xxx; | |
| 1990/0227 | ||
| 1991/0425 | m->intr++; | |
| 1991/0209 | cause = ur->cause&(INTR5|INTR4|INTR3|INTR2|INTR1); | |
| 1992/1128 | ||
| 1990/0227 | if(cause & INTR1){ duartintr(); cause &= ~INTR1; } | |
| 1992/1128 | ||
| 1993/0211 | for(limit = 50; (cause&INTR5) && limit; limit--) { | |
| 1991/0212 | any = 0; | |
| 1990/0227 | if(!(*MPBERR1 & (1<<8))){ | |
| 1990/0911 | print("MP bus error %lux %lux\n", *MPBERR0, *MPBERR1); | |
| 1992/1128 | print("PC %lux R31 %lux\n", ur->pc, ur->r31); | |
| 1990/0227 | *MPBERR0 = 0; i = *SBEADDR; | |
| 1990/1214 | USED(i); | |
| 1991/0212 | any = 1; | |
| 1990/0227 | } /* * directions from IO2 manual * 1. clear all IO2 masks */ | |
| 1991/0212 | *IO2CLRMASK = 0xff000000; | |
| 1990/0227 | /* * 2. wait for interrupt in progress */ while(!(*INTPENDREG & (1<<5))) ; /* * 3. read pending interrupts */ | |
| 1991/0316 | pend = SBCCREG->fintpending; | |
| 1990/0227 | /* * 4. clear pending register */ i = SBCCREG->flevel; | |
| 1990/1214 | USED(i); | |
| 1991/0316 | /* * 4a. attempt to fix problem */ if(!(*INTPENDREG & (1<<5))) print("pause again\n"); while(!(*INTPENDREG & (1<<5))) ; xxx = SBCCREG->fintpending; if(xxx){ print("new pend %ux\n", xxx); i = SBCCREG->flevel; | |
| 1991/0425 | USED(i); | |
| 1991/0316 | } | |
| 1990/0227 | /* * 5a. process lance, scsi */ if(pend & 1) { v = INTVECREG->i[0].vec; | |
| 1990/0907 | if(!(v & (1<<12))){ | |
| 1992/1128 | print("ioberr %lux %lux\n", *MPBERR0, *MPBERR1); print("PC %lux R31 %lux\n", ur->pc, ur->r31); | |
| 1990/0907 | *MPBERR0 = 0; | |
| 1991/0212 | any = 1; | |
| 1990/0907 | } | |
| 1990/0911 | if(ioid < IO3R1){ | |
| 1991/0212 | if(!(v & 7)) any = 1; | |
| 1990/0907 | if(!(v & (1<<2))) lanceintr(); if(!(v & (1<<1))) lanceparity(); if(!(v & (1<<0))) print("SCSI interrupt\n"); | |
| 1991/0212 | }else{ if(v & 7) any = 1; | |
| 1990/0907 | if(v & (1<<2)) | |
| 1990/0911 | lanceintr(); | |
| 1990/0907 | if(v & (1<<1)) | |
| 1992/1208 | scsiintr(1); | |
| 1990/0907 | if(v & (1<<0)) | |
| 1992/1208 | scsiintr(0); | |
| 1990/0907 | } | |
| 1990/0227 | } /* * 5b. process vme | |
| 1991/0212 | * i can guess your level | |
| 1990/0227 | */ | |
| 1991/0212 | for(i=1; pend>>=1; i++){ | |
| 1990/0227 | if(pend & 1) { v = INTVECREG->i[i].vec; | |
| 1990/0907 | if(!(v & (1<<12))){ | |
| 1991/0212 | print("io2 mp bus error %d %lux %lux\n", i, *MPBERR0, *MPBERR1); | |
| 1990/0907 | *MPBERR0 = 0; } | |
| 1990/0227 | v &= 0xff; (*vmevec[v])(v); | |
| 1991/0212 | any = 1; | |
| 1990/0227 | } } /* * 6. re-enable interrupts */ | |
| 1991/0212 | *IO2SETMASK = 0xff000000; | |
| 1992/1209 | if(any == 0) cause &= ~INTR5; | |
| 1990/0227 | } | |
| 1993/0211 | if(limit == 0) { | |
| 1993/0212 | LEDON(LED5); | |
| 1993/0211 | print("intr: unable to identify and clear level5\n"); cause &= ~INTR5; | |
| 1993/0212 | LEDOFF(LED5); | |
| 1993/0211 | } | |
| 1992/1128 | ||
| 1992/1129 | if(cause & (INTR2|INTR4)) { | |
| 1992/1128 | clock(ur); cause &= ~(INTR2|INTR4); } | |
| 1990/0227 | if(cause) panic("cause %lux %lux\n", u, cause); } | |
| 1992/0803 | char* | |
| 1992/0806 | fpexcname(Ureg *ur, ulong fcr31, char *buf) | |
| 1990/0227 | { int i; | |
| 1992/0806 | char *s; ulong fppc; | |
| 1990/0227 | ||
| 1992/0806 | fppc = ur->pc; if(ur->cause & (1<<31)) /* branch delay */ fppc += 4; s = 0; | |
| 1992/0803 | if(fcr31 & (1<<17)) | |
| 1992/0806 | s = "unimplemented operation"; else{ fcr31 >>= 7; /* trap enable bits */ fcr31 &= (fcr31>>5); /* anded with exceptions */ for(i=0; i<5; i++) if(fcr31 & (1<<i)) | |
| 1992/1129 | s = fpcause[i]; | |
| 1992/0806 | } if(s == 0) return "no floating point exception"; | |
| 1992/1129 | ||
| 1992/0806 | sprint(buf, "%s fppc=0x%lux", s, fppc); return buf; | |
| 1990/0227 | } | |
| 1990/03091 | ||
| 1990/0227 | void dumpstack(void) { ulong l, v; extern ulong etext; | |
| 1992/1129 | if(u == 0) return; for(l=(ulong)&l; l<USERADDR+BY2PG; l+=4){ v = *(ulong*)l; if(KTZERO < v && v < (ulong)&etext){ print("%lux=%lux\n", l, v); delay(100); | |
| 1990/0227 | } | |
| 1992/1129 | } | |
| 1990/0227 | } void dumpregs(Ureg *ur) { int i; ulong *l; if(u) | |
| 1992/1124 | print("registers for %s %d\n", u->p->text, u->p->pid); | |
| 1990/0227 | else | |
| 1992/1124 | print("registers for kernel\n"); | |
| 1992/1129 | ||
| 1990/0227 | l = &ur->status; | |
| 1992/0319 | for(i=0; i<sizeof regname/sizeof(char*); i+=2, l+=2){ | |
| 1992/1124 | print("%s\t%.8lux\t%s\t%.8lux\n", regname[i], l[0], regname[i+1], l[1]); prflush(); | |
| 1992/0319 | } | |
| 1990/0227 | } | |
| 1992/0108 | int | |
| 1990/0227 | notify(Ureg *ur) { | |
| 1992/1129 | int l; ulong sp; | |
| 1991/1218 | Note *n; | |
| 1990/0227 | ||
| 1991/1110 | if(u->p->procctl) procctl(u->p); | |
| 1991/1230 | if(u->nnote == 0) | |
| 1992/0108 | return 0; | |
| 1991/1114 | ||
| 1992/1129 | spllo(); | |
| 1991/1216 | qlock(&u->p->debug); | |
| 1991/0727 | u->p->notepending = 0; | |
| 1991/1218 | n = &u->note[0]; | |
| 1992/1129 | if(strncmp(n->msg, "sys:", 4) == 0) { | |
| 1991/1218 | l = strlen(n->msg); if(l > ERRLEN-15) /* " pc=0x12345678\0" */ l = ERRLEN-15; | |
| 1992/1128 | ||
| 1992/0806 | sprint(n->msg+l, " pc=0x%lux", ur->pc); | |
| 1991/1218 | } | |
| 1992/1128 | ||
| 1992/1129 | if(n->flag != NUser && (u->notified || u->notify==0)) { | |
| 1992/0714 | if(n->flag == NDebug) | |
| 1991/1218 | pprint("suicide: %s\n", n->msg); | |
| 1992/1128 | ||
| 1991/1216 | qunlock(&u->p->debug); | |
| 1991/1218 | pexit(n->msg, n->flag!=NDebug); | |
| 1990/0227 | } | |
| 1992/1128 | if(u->notified) { qunlock(&u->p->debug); | |
| 1992/1129 | splhi(); | |
| 1992/1128 | return 0; | |
| 1990/0227 | } | |
| 1992/1128 | if(!u->notify) { qunlock(&u->p->debug); pexit(n->msg, n->flag!=NDebug); } u->svstatus = ur->status; | |
| 1992/1129 | sp = ur->usp - sizeof(Ureg); | |
| 1992/1128 | ||
| 1992/1129 | if(sp&0x3 || !okaddr((ulong)u->notify, BY2WD, 0) | |
| 1992/1208 | || !okaddr(sp-ERRLEN-3*BY2WD, sizeof(Ureg)+ERRLEN+3*BY2WD, 1)) { | |
| 1992/1128 | pprint("suicide: bad address or sp in notify\n"); qunlock(&u->p->debug); pexit("Suicide", 0); } | |
| 1992/1129 | ||
| 1992/1128 | u->ureg = (void*)sp; memmove((Ureg*)sp, ur, sizeof(Ureg)); sp -= ERRLEN; memmove((char*)sp, u->note[0].msg, ERRLEN); sp -= 3*BY2WD; *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ u->svr1 = ur->r1; /* save away r1 */ | |
| 1993/0225 | ur->r1 = (ulong)u->ureg; /* arg 1 (R1) is ureg* */ *(ulong*)(sp+1*BY2WD) = (ulong)u->ureg; /* arg 1 0(FP) is ureg* */ | |
| 1992/1128 | *(ulong*)(sp+0*BY2WD) = 0; /* arg 0 is pc */ ur->usp = sp; ur->pc = (ulong)u->notify; u->notified = 1; u->nnote--; memmove(&u->lastnote, &u->note[0], sizeof(Note)); memmove(&u->note[0], &u->note[1], u->nnote*sizeof(Note)); | |
| 1991/1216 | qunlock(&u->p->debug); | |
| 1992/1129 | splhi(); | |
| 1992/1128 | return 1; | |
| 1990/0227 | } /* * Return user to state before notify() */ void | |
| 1991/0717 | noted(Ureg **urp, ulong arg0) | |
| 1990/0227 | { | |
| 1991/0503 | Ureg *nur; nur = u->ureg; | |
| 1992/1130 | if(nur->status != u->svstatus) { | |
| 1991/0717 | pprint("bad noted ureg status %lux\n", nur->status); | |
| 1991/0503 | pexit("Suicide", 0); } | |
| 1991/1216 | qlock(&u->p->debug); | |
| 1992/1129 | if(!u->notified) { | |
| 1991/1216 | qunlock(&u->p->debug); | |
| 1991/0814 | pprint("call to noted() when not notified\n"); | |
| 1992/1129 | pexit("Suicide", 0); | |
| 1990/0619 | } | |
| 1990/0227 | u->notified = 0; | |
| 1991/0318 | memmove(*urp, u->ureg, sizeof(Ureg)); | |
| 1992/0102 | (*urp)->r1 = u->svr1; | |
| 1992/1129 | switch(arg0) { | |
| 1991/0717 | case NCONT: | |
| 1992/0616 | if(!okaddr(nur->pc, 1, 0) || !okaddr(nur->usp, BY2WD, 0)){ | |
| 1991/0814 | pprint("suicide: trap in noted\n"); | |
| 1991/1216 | qunlock(&u->p->debug); | |
| 1992/1129 | pexit("Suicide", 0); | |
| 1991/0814 | } | |
| 1991/0717 | splhi(); | |
| 1991/1216 | qunlock(&u->p->debug); | |
| 1991/0717 | rfnote(urp); break; default: pprint("unknown noted arg 0x%lux\n", arg0); u->lastnote.flag = NDebug; /* fall through */ | |
| 1991/0718 | case NDFLT: | |
| 1991/0717 | if(u->lastnote.flag == NDebug) pprint("suicide: %s\n", u->lastnote.msg); | |
| 1991/1216 | qunlock(&u->p->debug); | |
| 1991/0717 | pexit(u->lastnote.msg, u->lastnote.flag!=NDebug); } | |
| 1990/0227 | } | |
| 1991/0731 | #include "../port/systab.h" | |
| 1990/0227 | long syscall(Ureg *aur) { long ret; ulong sp; Ureg *ur; | |
| 1992/0407 | Proc *p; | |
| 1990/0227 | ||
| 1991/0425 | m->syscall++; | |
| 1992/0407 | p = u->p; p->insyscall = 1; | |
| 1990/0227 | ur = aur; | |
| 1992/0805 | p->pc = ur->pc; | |
| 1991/1110 | u->dbgreg = aur; | |
| 1992/1130 | ur->cause = 15<<2; /* for debugging: system call is undef 15; */ | |
| 1992/0407 | if(p->fpstate == FPactive) { | |
| 1992/1129 | if((ur->status&CU1) == 0) panic("syscall: FPactive but no CU1"); | |
| 1991/0314 | u->fpsave.fpstatus = fcr31(); | |
| 1992/0407 | p->fpstate = FPinit; | |
| 1990/0227 | ur->status &= ~CU1; } | |
| 1992/1129 | ||
| 1990/0227 | spllo(); | |
| 1991/0705 | ||
| 1992/0803 | if(p->procctl) procctl(p); | |
| 1992/06271 | u->scallnr = ur->r1; | |
| 1990/0227 | u->nerrlab = 0; | |
| 1992/1130 | sp = ur->sp; | |
| 1990/0227 | ret = -1; | |
| 1990/0511 | if(!waserror()){ | |
| 1992/06271 | if(u->scallnr >= sizeof systab/sizeof systab[0]) { pprint("bad sys call number %d pc %lux\n", u->scallnr, ur->pc); | |
| 1992/0625 | postnote(p, 1, "sys: bad sys call", NDebug); | |
| 1990/11211 | error(Ebadarg); | |
| 1990/0511 | } | |
| 1992/0625 | ||
| 1990/0511 | if(sp & (BY2WD-1)){ | |
| 1992/0625 | pprint("odd sp in sys call pc %lux sp %lux\n", ur->pc, ur->sp); postnote(p, 1, "sys: odd stack", NDebug); error(Ebadarg); | |
| 1990/0511 | } | |
| 1992/0625 | if(sp<(USTKTOP-BY2PG) || sp>(USTKTOP-sizeof(Sargs))) validaddr(sp, sizeof(Sargs), 0); u->s = *((Sargs*)(sp+BY2WD)); | |
| 1992/06271 | p->psstate = sysctab[u->scallnr]; | |
| 1992/0625 | ||
| 1992/06271 | ret = (*systab[u->scallnr])(u->s.args); | |
| 1992/0803 | poperror(); | |
| 1990/0511 | } | |
| 1990/0227 | ur->pc += 4; u->nerrlab = 0; | |
| 1992/0407 | p->psstate = 0; p->insyscall = 0; | |
| 1992/0803 | if(u->scallnr == NOTED) /* ugly hack */ | |
| 1991/0717 | noted(&aur, *(ulong*)(sp+BY2WD)); /* doesn't return */ | |
| 1992/1129 | ||
| 1991/1114 | splhi(); | |
| 1992/06271 | if(u->scallnr!=RFORK && (p->procctl || u->nnote)){ | |
| 1992/1128 | ur->r1 = ret; /* load up for noted() */ | |
| 1992/0108 | if(notify(ur)) return ur->r1; | |
| 1990/0227 | } | |
| 1991/0705 | ||
| 1990/0227 | return ret; } | |
| 1991/1214 | long execregs(ulong entry, ulong ssize, ulong nargs) | |
| 1990/1226 | { | |
| 1991/1214 | ulong *sp; sp = (ulong*)(USTKTOP - ssize); *--sp = nargs; ((Ureg*)UREGADDR)->usp = (ulong)sp; ((Ureg*)UREGADDR)->pc = entry - 4; /* syscall advances it */ | |
| 1992/0805 | u->fpsave.fpstatus = initfp.fpstatus; | |
| 1991/1214 | return USTKTOP-BY2WD; /* address of user-level clock */ | |
| 1990/0227 | } | |
| 1992/0120 | ulong userpc(void) { return ((Ureg*)UREGADDR)->pc; } | |
| 1990/0227 | void novme(int v) { static count = 0; print("vme intr 0x%.2x\n", v); count++; if(count >= 10) panic("too many vme intr"); } void setvmevec(int v, void (*f)(int)) { void (*g)(int); v &= 0xff; g = vmevec[v]; | |
| 1992/0612 | if(g && g != novme && g != f) | |
| 1990/0227 | print("second setvmevec to 0x%.2x\n", v); vmevec[v] = f; | |
| 1991/1110 | } | |
| 1991/1111 | /* This routine must save the values of registers the user is not permitted to write | |
| 1992/0802 | * from devproc and then restore the saved values before returning | |
| 1991/1110 | */ void setregisters(Ureg *xp, char *pureg, char *uva, int n) { ulong status; status = xp->status; memmove(pureg, uva, n); xp->status = status; | |
| 1990/0227 | } | |