Annotation of coherent/d/PS2_KERNEL/i286/trap.c, revision 1.1.1.1

1.1       root        1: /* $Header: /kernel/kersrc/i286/RCS/trap.c,v 1.1 92/07/17 15:21:35 bin Exp Locker: bin $ */
                      2: /* (lgl-
                      3:  *     The information contained herein is a trade secret of Mark Williams
                      4:  *     Company, and  is confidential information.  It is provided  under a
                      5:  *     license agreement,  and may be  copied or disclosed  only under the
                      6:  *     terms of  that agreement.  Any  reproduction or disclosure  of this
                      7:  *     material without the express written authorization of Mark Williams
                      8:  *     Company or persuant to the license agreement is unlawful.
                      9:  *
                     10:  *     COHERENT Version 2.3.37
                     11:  *     Copyright (c) 1982, 1983, 1984.
                     12:  *     An unpublished work by Mark Williams Company, Chicago.
                     13:  *     All rights reserved.
                     14:  -lgl) */
                     15: /*
                     16:  * Trap handler.
                     17:  * 8086/8088 Coherent, IBM PC.
                     18:  *
                     19:  * $Log:       trap.c,v $
                     20:  * Revision 1.1  92/07/17  15:21:35  bin
                     21:  * Initial revision
                     22:  * 
                     23:  * Revision 1.1        88/03/24  17:39:53      src
                     24:  * Initial revision
                     25:  * 
                     26:  * 88/03/06    Allan Cornish           /usr/src/sys/i8086/src/trap.c
                     27:  * Exception diagnostistics extended.
                     28:  *
                     29:  * 87/11/02    Allan Cornish           /usr/src/sys/i8086/src/trap.c
                     30:  * iAPX 286 exception traps added.
                     31:  */
                     32: #include <sys/coherent.h>
                     33: #include <sys/i8086.h>
                     34: #include <sys/systab.h>
                     35: #include <errno.h>
                     36: #include <sys/proc.h>
                     37: #include <sys/seg.h>
                     38: #include <signal.h>
                     39: 
                     40: #ifndef        EBUG
                     41: #define        EBUG 1
                     42: #endif
                     43: 
                     44: /*
                     45:  * Trap handler.
                     46:  * The arguments are the registers,
                     47:  * saved on the stack by machine code. This call
                     48:  * is different from most C calls in that the registers
                     49:  * get copied back; if you change a "trap" parameter then
                     50:  * the machine register will be altered when the trap is
                     51:  * dismissed.
                     52:  */
                     53: trap(es, cx, dx, ax, bx, ds, usp, uss, id, ip, cs, fw)
                     54: unsigned es, cx, dx, ax, bx, ds, usp, uss, id, ip, cs, fw;
                     55: {
                     56:        register struct systab  *stp;
                     57:        register int    syscall;
                     58:        register int    callnum;
                     59:        register int    sigcode;
                     60:        long            l;
                     61: 
                     62:        if ( (id >> 8) == SINMI )
                     63:                panic( "Parity error: cs=%x ip=%x\n", cs, ip );
                     64: 
                     65:        if (depth != 0) {
                     66: #if EBUG > 0
                     67:                faddr_t fp;
                     68:                FP_SEL(fp) = ax;  printf("ax "); vprint(fp);
                     69:                FP_SEL(fp) = cs;  printf("cs "); vprint(fp);
                     70:                FP_SEL(fp) = ds;  printf("ds "); vprint(fp);
                     71:                FP_SEL(fp) = es;  printf("es "); vprint(fp);
                     72:                FP_SEL(fp) = uss; printf("ss "); vprint(fp);
                     73: #endif
                     74:                panic("system trap: id=%x ip=%x ax=%x", id, ip, ax);
                     75:        }
                     76: 
                     77:        if ((SELF->p_flags&PFKERN) != 0) {
                     78: #if EBUG > 0
                     79:                faddr_t fp;
                     80:                FP_SEL(fp) = ax;  printf("ax "); vprint(fp);
                     81:                FP_SEL(fp) = cs;  printf("cs "); vprint(fp);
                     82:                FP_SEL(fp) = ds;  printf("ds "); vprint(fp);
                     83:                FP_SEL(fp) = es;  printf("es "); vprint(fp);
                     84:                FP_SEL(fp) = uss; printf("ss "); vprint(fp);
                     85: #endif
                     86:                panic("pid%d: kernel process trap: id=%x, ip=%x ax=%d",
                     87:                        SELF->p_pid, id, ip, ax);
                     88:        }
                     89: 
                     90:        /*
                     91:         * System call.
                     92:         */
                     93:        if ( (id >> 8) == SISYS ) {
                     94:                u.u_error = 0;
                     95:                sigcode = 0;
                     96:                syscall = getuwi(ip-2);
                     97:                if (u.u_error != 0 || (syscall&0xFF) != 0xCD) {
                     98:                        sigcode = SIGSYS;
                     99:                        goto trapend;
                    100:                }
                    101:                callnum = (syscall>>8) & 0x7F;
                    102:                if (callnum >= NMICALL) {
                    103:                        sigcode = SIGSYS;
                    104:                        goto trapend;
                    105:                }
                    106:                stp = &sysitab[callnum];
                    107:                ukcopy(usp+2, u.u_args, stp->s_alen);
                    108:                if (u.u_error != 0) {
                    109:                        sigcode = SIGSYS;
                    110:                        goto trapend;
                    111:                }
                    112:                u.u_io.io_seg = IOUSR;
                    113:                if (envsave(&u.u_sigenv) != 0)
                    114:                        u.u_error = EINTR;
                    115:                else if ( stp->s_alen <= (3 * sizeof(int)) ) {
                    116:                        l = (*(long(*)())stp->s_func)(u.u_args[0],
                    117:                                                      u.u_args[1],
                    118:                                                      u.u_args[2] );
                    119:                        ax = ((struct l *) &l)->l_lo;
                    120:                        dx = ((struct l *) &l)->l_hi;
                    121:                }
                    122:                else {
                    123:                        l = (*(long(*)())stp->s_func)(u.u_args[0],
                    124:                                                      u.u_args[1],
                    125:                                                      u.u_args[2],
                    126:                                                      u.u_args[3],
                    127:                                                      u.u_args[4],
                    128:                                                      u.u_args[5]);
                    129:                        ax = ((struct l *) &l)->l_lo;
                    130:                        dx = ((struct l *) &l)->l_hi;
                    131:                }
                    132:                if (u.u_error != 0) {
                    133:                        ax = -1;
                    134:                        dx = -1;
                    135:                        putuwd(MUERR, u.u_error);
                    136:                        if (u.u_error == EFAULT)
                    137:                                sigcode = SIGSYS;
                    138:                }
                    139:        }
                    140: 
                    141:        /*
                    142:         * Trap.
                    143:         */
                    144:        else switch (id>>8) {
                    145: 
                    146:        case SIDIV:
                    147:                sigcode = SIGDIVE;
                    148:                break;
                    149: 
                    150:        case SISST:
                    151:                sigcode = SIGTRAP;
                    152:                break;
                    153: 
                    154:        case SIBPT:
                    155:                sigcode = SIGTRAP;
                    156:                break;
                    157: 
                    158:        case SIOVF:
                    159:                sigcode = SIGOVFL;
                    160:                break;
                    161: 
                    162:        case SIBND:
                    163:                /*
                    164:                 * Bound
                    165:                 */
                    166:                sigcode = SIGOVFL;
                    167:                break;
                    168: 
                    169:        case SIOP:
                    170:                /*
                    171:                 * Invalid opcode
                    172:                 */
                    173:                sigcode = SIGSEGV;
                    174:                break;
                    175: 
                    176:        case SIXNP:
                    177:                /*
                    178:                 * Processor extension not available
                    179:                 */
                    180:                sigcode = SIGSEGV;
                    181:                break;
                    182: 
                    183:        case SIDBL:
                    184:                /*
                    185:                 * Double exception
                    186:                 */
                    187:                panic("double exception: cs=%x ip=%x", cs, ip);
                    188:                sigcode = SIGSEGV;
                    189:                break;
                    190: 
                    191:        case SIXS:
                    192:                /*
                    193:                 * Processor extension segment overrun
                    194:                 */
                    195:                sigcode = SIGSEGV;
                    196:                break;
                    197: 
                    198:        case SITS:
                    199:                /*
                    200:                 * Invalid task state segment
                    201:                 */
                    202:                panic("invalid tss: cs=%x ip=%x", cs, ip);
                    203:                sigcode = SIGSEGV;
                    204:                break;
                    205: 
                    206:        case SINP:
                    207:                /*
                    208:                 * Segment not present
                    209:                 */
                    210:                sigcode = SIGSEGV;
                    211:                break;
                    212: 
                    213:        case SISS:
                    214:                /*
                    215:                 * Stack segment overrun/not present
                    216:                 */
                    217:                sigcode = SIGKILL;
                    218:                break;
                    219: 
                    220:        case SIGP:
                    221:                /*
                    222:                 * General protection.
                    223:                 */
                    224:                sigcode = SIGSEGV;
                    225:                break;
                    226: 
                    227:        default:
                    228:                panic("user trap: id=%x ip=%x\n", id, ip );
                    229:        }
                    230: 
                    231: trapend:
                    232:        if ( sigcode != 0 ) {
                    233:                if ( sigcode == SIGSEGV ) {
                    234: #if EBUG > 0
                    235:                        faddr_t fp;
                    236:                        FP_SEL(fp) = ax;  printf("\tax "); vprint(fp);
                    237:                        FP_SEL(fp) = cs;  printf("\tcs "); vprint(fp);
                    238:                        FP_SEL(fp) = ds;  printf("\tds "); vprint(fp);
                    239:                        FP_SEL(fp) = es;  printf("\tes "); vprint(fp);
                    240:                        FP_SEL(fp) = uss; printf("\tss "); vprint(fp);
                    241:                        printf("user trap: SEGV id=%x ax=%x pid=%d\n",
                    242:                                id, ax, SELF->p_pid );
                    243:                {  char cmd[11]; int i;
                    244:                        for (i = 0; i < 10; i++) {
                    245:                                cmd[i] = u.u_comm[i];
                    246:                        }
                    247:                        cmd[10] = '\0';
                    248:                        printf("\tip=%x sp=%x cmd=%s\n", ip, usp, cmd);
                    249:                }
                    250: 
                    251:                        /*
                    252:                         * Force core dump.
                    253:                         */
                    254:                        u.u_sfunc[SIGSEGV] = SIG_DFL;
                    255: #endif
                    256:                }
                    257:                sendsig(sigcode, SELF);
                    258:        }
                    259: }

unix.superglobalmegacorp.com

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