Commit | Line | Data |
---|---|---|
989888af RE |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
e89e4676 | 6 | * @(#)main.c 5.5 %G% |
989888af | 7 | */ |
dd27c76e DW |
8 | #include <stdio.h> |
9 | #include <signal.h> | |
d2397273 | 10 | #include "../libI77/fiodefs.h" |
dd27c76e | 11 | |
0ab3343e KM |
12 | extern int errno; |
13 | char *getenv(); | |
dd27c76e DW |
14 | int xargc; |
15 | char **xargv; | |
16 | ||
17 | main(argc, argv, arge) | |
18 | int argc; | |
19 | char **argv; | |
20 | char **arge; | |
21 | { | |
e89e4676 | 22 | void sigdie(); |
77635fde | 23 | sig_t sigf; |
66aca6b3 | 24 | int signum; |
dd27c76e DW |
25 | |
26 | xargc = argc; | |
27 | xargv = argv; | |
66aca6b3 DW |
28 | |
29 | for (signum=1; signum<=16; signum++) | |
30 | { | |
31 | if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf); | |
32 | } | |
dd27c76e DW |
33 | |
34 | #ifdef pdp11 | |
35 | ldfps(01200); /* detect overflow as an exception */ | |
36 | #endif | |
37 | ||
38 | f_init(); | |
6e1c8476 | 39 | MAIN_(); |
dd27c76e | 40 | f_exit(); |
d1485af3 | 41 | return 0; |
dd27c76e DW |
42 | } |
43 | ||
be7a6737 DW |
44 | struct action { |
45 | char *mesg; | |
46 | int core; | |
47 | } sig_act[16] = { | |
66aca6b3 | 48 | {"Hangup", 0}, /* SIGHUP */ |
be7a6737 DW |
49 | {"Interrupt!", 0}, /* SIGINT */ |
50 | {"Quit!", 1}, /* SIGQUIT */ | |
f81417e8 | 51 | {"Illegal ", 1}, /* SIGILL */ |
66aca6b3 | 52 | {"Trace Trap", 1}, /* SIGTRAP */ |
be7a6737 | 53 | {"IOT Trap", 1}, /* SIGIOT */ |
e0eb2f2c | 54 | {"EMT Trap", 1}, /* SIGEMT */ |
eb5713ad | 55 | {"Arithmetic Exception", 1}, /* SIGFPE */ |
be7a6737 DW |
56 | { 0, 0}, /* SIGKILL */ |
57 | {"Bus error", 1}, /* SIGBUS */ | |
58 | {"Segmentation violation", 1}, /* SIGSEGV */ | |
66aca6b3 DW |
59 | {"Sys arg", 1}, /* SIGSYS */ |
60 | {"Open pipe", 0}, /* SIGPIPE */ | |
61 | {"Alarm", 0}, /* SIGALRM */ | |
be7a6737 | 62 | {"Terminated", 0}, /* SIGTERM */ |
66aca6b3 | 63 | {"Sig 16", 0}, /* unassigned */ |
be7a6737 DW |
64 | }; |
65 | ||
0ab3343e KM |
66 | #ifdef tahoe |
67 | /* The following arrays are defined & used assuming that signal codes are | |
68 | 1 to 5 for SIGFPE, and 0 to 3 for SIGILL. | |
69 | Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */ | |
70 | ||
71 | #define N_ACT_ILL 4 /* number of entries in act_ill[] */ | |
72 | #define N_ACT_FPE 5 /* number of entries in act_fpe[] */ | |
73 | #define ILL_ALIGN_FAULT 14 | |
74 | ||
75 | struct action act_fpe[] = { | |
76 | {"Integer overflow", 1}, | |
77 | {"Integer divide by 0", 1}, | |
78 | {"Floating divide by zero", 1}, | |
79 | {"Floating point overflow", 1}, | |
80 | {"Floating point underflow", 1}, | |
81 | }; | |
82 | ||
83 | #else vax || pdp11 | |
84 | ||
eb5713ad DW |
85 | struct action act_fpe[] = { |
86 | {"Integer overflow", 1}, | |
87 | {"Integer divide by 0", 1}, | |
7ba43308 DW |
88 | {"Floating point overflow trap", 1}, |
89 | {"Floating divide by zero trap", 1}, | |
90 | {"Floating point underflow trap", 1}, | |
eb5713ad DW |
91 | {"Decimal overflow", 1}, |
92 | {"Subscript range", 1}, | |
93 | {"Floating point overflow", 0}, | |
94 | {"Floating divide by zero", 0}, | |
95 | {"Floating point underflow", 0}, | |
96 | }; | |
0ab3343e | 97 | #endif vax || pdp11 |
f81417e8 DW |
98 | |
99 | struct action act_ill[] = { | |
100 | {"addr mode", 1}, | |
101 | {"instruction", 1}, | |
102 | {"operand", 0}, | |
0ab3343e KM |
103 | #ifdef tahoe |
104 | {"alignment", 1}, | |
105 | #endif tahoe | |
f81417e8 | 106 | }; |
be7a6737 | 107 | |
0ab3343e | 108 | #if (defined(vax) || defined(tahoe)) |
e89e4676 | 109 | void |
fc66b163 DW |
110 | sigdie(s, t, sc) |
111 | int s; int t; struct sigcontext *sc; | |
112 | ||
113 | #else pdp11 | |
0ab3343e | 114 | |
e89e4676 | 115 | void |
eb5713ad DW |
116 | sigdie(s, t, pc) |
117 | int s; int t; long pc; | |
fc66b163 | 118 | |
0ab3343e | 119 | #endif pdp11 |
dd27c76e | 120 | { |
d2397273 | 121 | extern unit units[]; |
be7a6737 | 122 | register struct action *act = &sig_act[s-1]; |
2913b66e DW |
123 | /* print error message, then flush buffers */ |
124 | ||
04e8957b DW |
125 | if (s == SIGHUP || s == SIGINT || s == SIGQUIT) |
126 | signal(s, SIG_IGN); /* don't allow it again */ | |
127 | else | |
128 | signal(s, SIG_DFL); /* shouldn't happen again, but ... */ | |
129 | ||
eb5713ad DW |
130 | if (act->mesg) |
131 | { | |
511b0121 | 132 | fprintf(units[STDERR].ufd, "*** %s", act->mesg); |
eb5713ad | 133 | if (s == SIGFPE) |
66aca6b3 | 134 | { |
0ab3343e | 135 | #ifndef tahoe |
66aca6b3 | 136 | if (t >= 1 && t <= 10) |
0ab3343e KM |
137 | #else tahoe |
138 | if ((t-1) >= 0 && t < N_ACT_FPE) | |
139 | #endif tahoe | |
66aca6b3 DW |
140 | fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); |
141 | else | |
142 | fprintf(units[STDERR].ufd, ": Type=%d?", t); | |
143 | } | |
144 | else if (s == SIGILL) | |
f81417e8 | 145 | { |
0ab3343e | 146 | #ifndef tahoe |
f81417e8 DW |
147 | if (t == 4) t = 2; /* 4.0bsd botch */ |
148 | if (t >= 0 && t <= 2) | |
0ab3343e KM |
149 | #else tahoe |
150 | if (t == ILL_ALIGN_FAULT) /* ILL_ALIGN_FAULT maps to last | |
151 | t = N_ACT_ILL-1; entry in act_ill[] */ | |
152 | if (t >= 0 && t < N_ACT_ILL) | |
153 | #endif tahoe | |
f81417e8 DW |
154 | fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); |
155 | else | |
156 | fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); | |
157 | } | |
66aca6b3 | 158 | putc('\n', units[STDERR].ufd); |
eb5713ad | 159 | } |
d1485af3 DL |
160 | f77_abort( s, act->core ); |
161 | } |