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.2 6/26/85 7: */ 8: #include <stdio.h> 9: #include <signal.h> 10: #include "../libI77/fiodefs.h" 11: 12: int xargc; 13: char **xargv; 14: 15: main(argc, argv, arge) 16: int argc; 17: char **argv; 18: char **arge; 19: { 20: int sigdie(); 21: int (*sigf)(); 22: int signum; 23: 24: xargc = argc; 25: xargv = argv; 26: 27: for (signum=1; signum<=16; signum++) 28: { 29: if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf); 30: } 31: 32: #ifdef pdp11 33: ldfps(01200); /* detect overflow as an exception */ 34: #endif 35: 36: f_init(); 37: MAIN_(); 38: f_exit(); 39: return 0; 40: } 41: 42: struct action { 43: char *mesg; 44: int core; 45: } sig_act[16] = { 46: {"Hangup", 0}, /* SIGHUP */ 47: {"Interrupt!", 0}, /* SIGINT */ 48: {"Quit!", 1}, /* SIGQUIT */ 49: {"Illegal ", 1}, /* SIGILL */ 50: {"Trace Trap", 1}, /* SIGTRAP */ 51: {"IOT Trap", 1}, /* SIGIOT */ 52: {"EMT Trap", 1}, /* SIGEMT */ 53: {"Arithmetic Exception", 1}, /* SIGFPE */ 54: { 0, 0}, /* SIGKILL */ 55: {"Bus error", 1}, /* SIGBUS */ 56: {"Segmentation violation", 1}, /* SIGSEGV */ 57: {"Sys arg", 1}, /* SIGSYS */ 58: {"Open pipe", 0}, /* SIGPIPE */ 59: {"Alarm", 0}, /* SIGALRM */ 60: {"Terminated", 0}, /* SIGTERM */ 61: {"Sig 16", 0}, /* unassigned */ 62: }; 63: 64: struct action act_fpe[] = { 65: {"Integer overflow", 1}, 66: {"Integer divide by 0", 1}, 67: {"Floating point overflow trap", 1}, 68: {"Floating divide by zero trap", 1}, 69: {"Floating point underflow trap", 1}, 70: {"Decimal overflow", 1}, 71: {"Subscript range", 1}, 72: {"Floating point overflow", 0}, 73: {"Floating divide by zero", 0}, 74: {"Floating point underflow", 0}, 75: }; 76: 77: struct action act_ill[] = { 78: {"addr mode", 1}, 79: {"instruction", 1}, 80: {"operand", 0}, 81: }; 82: 83: sigdie(s, t, sc) 84: int s; int t; struct sigcontext *sc; 85: { 86: extern unit units[]; 87: register struct action *act = &sig_act[s-1]; 88: /* print error message, then flush buffers */ 89: 90: if (s == SIGHUP || s == SIGINT || s == SIGQUIT) 91: signal(s, SIG_IGN); /* don't allow it again */ 92: else 93: signal(s, SIG_DFL); /* shouldn't happen again, but ... */ 94: 95: if (act->mesg) 96: { 97: fprintf(units[STDERR].ufd, "*** %s", act->mesg); 98: if (s == SIGFPE) 99: { 100: if (t >= 1 && t <= 10) 101: fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); 102: else 103: fprintf(units[STDERR].ufd, ": Type=%d?", t); 104: } 105: else if (s == SIGILL) 106: { 107: if (t == 4) t = 2; /* 4.0bsd botch */ 108: if (t >= 0 && t <= 2) 109: fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); 110: else 111: fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); 112: } 113: putc('\n', units[STDERR].ufd); 114: } 115: f77_abort( 2, s, act->core ); 116: }