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 * 6 * @(#)main.c 5.4 09/13/89 7 */ 8 #include <stdio.h> 9 #include <signal.h> 10 #include "../libI77/fiodefs.h" 11 12 extern int errno; 13 char *getenv(); 14 int xargc; 15 char **xargv; 16 17 main(argc, argv, arge) 18 int argc; 19 char **argv; 20 char **arge; 21 { 22 sig_t sigdie; 23 sig_t sigf; 24 int signum; 25 26 xargc = argc; 27 xargv = argv; 28 29 for (signum=1; signum<=16; signum++) 30 { 31 if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf); 32 } 33 34 #ifdef pdp11 35 ldfps(01200); /* detect overflow as an exception */ 36 #endif 37 38 f_init(); 39 MAIN_(); 40 f_exit(); 41 return 0; 42 } 43 44 struct action { 45 char *mesg; 46 int core; 47 } sig_act[16] = { 48 {"Hangup", 0}, /* SIGHUP */ 49 {"Interrupt!", 0}, /* SIGINT */ 50 {"Quit!", 1}, /* SIGQUIT */ 51 {"Illegal ", 1}, /* SIGILL */ 52 {"Trace Trap", 1}, /* SIGTRAP */ 53 {"IOT Trap", 1}, /* SIGIOT */ 54 {"EMT Trap", 1}, /* SIGEMT */ 55 {"Arithmetic Exception", 1}, /* SIGFPE */ 56 { 0, 0}, /* SIGKILL */ 57 {"Bus error", 1}, /* SIGBUS */ 58 {"Segmentation violation", 1}, /* SIGSEGV */ 59 {"Sys arg", 1}, /* SIGSYS */ 60 {"Open pipe", 0}, /* SIGPIPE */ 61 {"Alarm", 0}, /* SIGALRM */ 62 {"Terminated", 0}, /* SIGTERM */ 63 {"Sig 16", 0}, /* unassigned */ 64 }; 65 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 85 struct action act_fpe[] = { 86 {"Integer overflow", 1}, 87 {"Integer divide by 0", 1}, 88 {"Floating point overflow trap", 1}, 89 {"Floating divide by zero trap", 1}, 90 {"Floating point underflow trap", 1}, 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 }; 97 #endif vax || pdp11 98 99 struct action act_ill[] = { 100 {"addr mode", 1}, 101 {"instruction", 1}, 102 {"operand", 0}, 103 #ifdef tahoe 104 {"alignment", 1}, 105 #endif tahoe 106 }; 107 108 #if (defined(vax) || defined(tahoe)) 109 sigdie(s, t, sc) 110 int s; int t; struct sigcontext *sc; 111 112 #else pdp11 113 114 sigdie(s, t, pc) 115 int s; int t; long pc; 116 117 #endif pdp11 118 { 119 extern unit units[]; 120 register struct action *act = &sig_act[s-1]; 121 /* print error message, then flush buffers */ 122 123 if (s == SIGHUP || s == SIGINT || s == SIGQUIT) 124 signal(s, SIG_IGN); /* don't allow it again */ 125 else 126 signal(s, SIG_DFL); /* shouldn't happen again, but ... */ 127 128 if (act->mesg) 129 { 130 fprintf(units[STDERR].ufd, "*** %s", act->mesg); 131 if (s == SIGFPE) 132 { 133 #ifndef tahoe 134 if (t >= 1 && t <= 10) 135 #else tahoe 136 if ((t-1) >= 0 && t < N_ACT_FPE) 137 #endif tahoe 138 fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); 139 else 140 fprintf(units[STDERR].ufd, ": Type=%d?", t); 141 } 142 else if (s == SIGILL) 143 { 144 #ifndef tahoe 145 if (t == 4) t = 2; /* 4.0bsd botch */ 146 if (t >= 0 && t <= 2) 147 #else tahoe 148 if (t == ILL_ALIGN_FAULT) /* ILL_ALIGN_FAULT maps to last 149 t = N_ACT_ILL-1; entry in act_ill[] */ 150 if (t >= 0 && t < N_ACT_ILL) 151 #endif tahoe 152 fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); 153 else 154 fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); 155 } 156 putc('\n', units[STDERR].ufd); 157 } 158 f77_abort( s, act->core ); 159 } 160