Annotation of researchv10dc/630/src/trap.c, revision 1.1

1.1     ! root        1: #include <jerq.h>
        !             2: #include <layer.h>
        !             3: #include <jerqproc.h>
        !             4: #include <font.h>
        !             5: 
        !             6: char           *patchedspot;
        !             7: char           patch;
        !             8: char *         itox();
        !             9: extern long    traploc;
        !            10: extern short   traptype;
        !            11: extern Layer   *whichlayer();
        !            12: extern Texture eightball;
        !            13: struct Proc    *debugger;
        !            14: 
        !            15: #define        RESET   0
        !            16: #define PROCESS 1
        !            17: #define STACK  2
        !            18: #define NORMAL 3
        !            19: 
        !            20: char *trapmsg[]={
        !            21:        "",
        !            22:        "Process",
        !            23:        "Stack",
        !            24:        0,      /* Normal, handled by next table */
        !            25: };
        !            26: char *normalmsg[]={
        !            27:        /* 0*/  "Zero divide",
        !            28: #define TRACE  1
        !            29:        /* 1*/  "Trace trap",
        !            30:        /* 2*/  "Illegal opcode",
        !            31:        /* 3*/  "Reserved opcode",
        !            32:        /* 4*/  "Invalid address mode",
        !            33:        /* 5*/  "Memory fault",
        !            34:        /* 6*/  "Gate vector fault",
        !            35:        /* 7*/  "Illegal level change",
        !            36:        /* 8*/  "Reserved data type",
        !            37:        /* 9*/  "Integer overflow",
        !            38:        /*10*/  "Privileged opcode",
        !            39:        /*11*/  0,
        !            40:        /*12*/  0,
        !            41:        /*13*/  0,
        !            42: #define BRKPT  14
        !            43:        /*14*/  "Breakpoint trap",
        !            44:        /*15*/  "Privileged register",
        !            45: };
        !            46: /* Called at spl7() */
        !            47: trap(type,bad_pc,bad_psw,psw_bad,bad_pcbp)
        !            48:        register int type;
        !            49:        register char **bad_pc;
        !            50:        register *bad_psw;
        !            51:        register int psw_bad;
        !            52:        int bad_pcbp;
        !            53: {
        !            54:        register int isc=((psw_bad >> 3) & 0xf);
        !            55: 
        !            56:        if(patchedspot){
        !            57:                *patchedspot=patch;
        !            58:                patchedspot=0;
        !            59:        }
        !            60:        spl0();
        !            61:        P->state|=ZOMBIE;
        !            62:        P->traploc=bad_pc;               /* for debugger */
        !            63:        P->traptype=bad_psw;
        !            64:        if(debugger && (type==NORMAL) && ((isc==TRACE)||(isc==BRKPT))){ 
        !            65:                sw(0);                  /* BPT or trace */
        !            66:                /* ZOMBIE bit is now off; we are free to continue */
        !            67:                return;
        !            68:        }
        !            69:        P->nchars=0;
        !            70:        P->cbufpin=P->cbufpout=P->cbuf;
        !            71:        if(type==NORMAL)
        !            72:                copy(normalmsg[isc]? normalmsg[isc] : "Undefined normal exception");
        !            73:        else{
        !            74:                copy(trapmsg[type]);
        !            75:                if(type==PROCESS){
        !            76:                        copy(" psw: 0x");
        !            77:                        copy(itox(psw_bad));
        !            78:                }else{
        !            79:                        copy(" exception #0x");
        !            80:                        copy(itox(isc));
        !            81:                }
        !            82:        }
        !            83:        copy(" at 0x");
        !            84:        copy(itox((unsigned long)(*bad_pc-P->text)));
        !            85:        *P->cbufpin='\0';
        !            86:        if(P-proctab<=1)        /* DEMUX, CONTROL */
        !            87:                error(P-proctab==0? "demux" : "control", P->cbuf);
        !            88:        /* let the user Delete to kill the Unix process */
        !            89:        shutdown(P);
        !            90:        P->state&=~ZOMBIE;
        !            91:        Urequest(MOUSE);
        !            92:        Ucursswitch(&eightball);
        !            93:        P->state|=ZOMBIE;
        !            94:        mesg(P->cbuf);
        !            95:        for(;;)
        !            96:                sw(0);  /* ZOMBIE ==> will never return, but in case of pi */
        !            97: }
        !            98: 
        !            99: copy(s)
        !           100:        register char *s;
        !           101: {
        !           102:        register unsigned char *p=P->cbufpin;
        !           103: 
        !           104:        while(*s){
        !           105:                *p++= *s++;
        !           106:                P->nchars++;
        !           107:                if(p>=&P->cbuf[sizeof(P->cbuf)])
        !           108:                        p=P->cbuf;
        !           109:        }
        !           110:        P->cbufpin=p;
        !           111: }
        !           112: 
        !           113: char *
        !           114: itox(n)
        !           115:        register unsigned long n;
        !           116: {
        !           117:        static char hex[10];
        !           118:        register char *hp;
        !           119:        hp= &hex[sizeof hex];
        !           120:        *--hp='\0';
        !           121:        if(n>0)
        !           122:                do{
        !           123:                        if((*--hp=(n&0xf)+'0') > '9')
        !           124:                                *hp+='A'-'9'-1;
        !           125:                        n>>=4;
        !           126:                }while(n);
        !           127:        else
        !           128:                *--hp='0';
        !           129:        return hp;
        !           130: }
        !           131: error(s1, s2)
        !           132:        char *s1, *s2;
        !           133: {
        !           134:        char buf[64];
        !           135:        rectf(&display, Rect(0, 0, 600, 50), F_OR);
        !           136:        strcpy(buf, s1);
        !           137:        strcat(buf, ": ");
        !           138:        strcat(buf, s2);
        !           139:        string(&defont, buf, &display, Pt(10, 20), F_XOR);
        !           140:        P->state|=ZOMBIE;
        !           141:        sw(0);
        !           142: }
        !           143: /*
        !           144: **info(s)
        !           145: **     char *s;
        !           146: **{
        !           147: **     register i;
        !           148: **     jrectf(Rect(XMAX-300, YMAX-50, XMAX, YMAX), F_CLR);
        !           149: **     string(&defont, s, &display, Pt(XMAX-290, YMAX-30), F_XOR);
        !           150: **}
        !           151: **buzz(n)
        !           152: **{
        !           153: **     register i;
        !           154: **     while(n--)
        !           155: **     for(i=0; i<200000; i++)
        !           156: **             ;
        !           157: **}
        !           158: **sstep(s)
        !           159: **     char *  s;
        !           160: **{
        !           161: **     jrectf(Rect(XMAX-300, YMAX-50, XMAX, YMAX), F_CLR);
        !           162: **     string(&defont, s, &display, Pt(XMAX-290, YMAX-30), F_XOR);
        !           163: **     do; while(button12()==0);
        !           164: **     if(button1())
        !           165: **             (*(long *)0)=0;
        !           166: **     do; while(button12());
        !           167: **     *DADDR = 156*(1024/4);
        !           168: **     jrectf(Rect(XMAX-300, YMAX-50, XMAX, YMAX), F_XOR);
        !           169: **}
        !           170: **help(s, n)
        !           171: **     char *s;
        !           172: **     unsigned long n;
        !           173: **{
        !           174: **     static char buf[64];
        !           175: **     strcpy(buf, s);
        !           176: **     strcat(buf, itox(n));
        !           177: **     sstep(buf);
        !           178: **}
        !           179: */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.