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