1*47940Sbostic /*- 2*47940Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*47940Sbostic * All rights reserved. 422925Skre * 5*47940Sbostic * %sccs.include.proprietary.c% 622925Skre */ 7*47940Sbostic 8*47940Sbostic #ifndef lint 9*47940Sbostic char copyright[] = 10*47940Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 11*47940Sbostic All rights reserved.\n"; 12*47940Sbostic #endif /* not lint */ 13*47940Sbostic 14*47940Sbostic #ifndef lint 15*47940Sbostic static char sccsid[] = "@(#)main.c 5.6 (Berkeley) 04/12/91"; 16*47940Sbostic #endif /* not lint */ 17*47940Sbostic 184130Sdlw #include <stdio.h> 194130Sdlw #include <signal.h> 204131Sdlw #include "../libI77/fiodefs.h" 214130Sdlw 2229974Smckusick extern int errno; 2329974Smckusick char *getenv(); 244130Sdlw int xargc; 254130Sdlw char **xargv; 264130Sdlw 274130Sdlw main(argc, argv, arge) 284130Sdlw int argc; 294130Sdlw char **argv; 304130Sdlw char **arge; 314130Sdlw { 3242454Sbostic void sigdie(); 3339139Sbostic sig_t sigf; 344168Sdlw int signum; 354130Sdlw 364130Sdlw xargc = argc; 374130Sdlw xargv = argv; 384130Sdlw 394168Sdlw for (signum=1; signum<=16; signum++) 404168Sdlw { 414168Sdlw if((sigf=signal(signum, sigdie)) != SIG_DFL) signal(signum, sigf); 424168Sdlw } 434168Sdlw 444130Sdlw #ifdef pdp11 454130Sdlw ldfps(01200); /* detect overflow as an exception */ 464130Sdlw #endif 474130Sdlw 484130Sdlw f_init(); 4912580Sfortran MAIN_(); 504130Sdlw f_exit(); 5120197Slibs return 0; 524130Sdlw } 534130Sdlw 544134Sdlw struct action { 554134Sdlw char *mesg; 564134Sdlw int core; 574134Sdlw } sig_act[16] = { 584168Sdlw {"Hangup", 0}, /* SIGHUP */ 594134Sdlw {"Interrupt!", 0}, /* SIGINT */ 604134Sdlw {"Quit!", 1}, /* SIGQUIT */ 614170Sdlw {"Illegal ", 1}, /* SIGILL */ 624168Sdlw {"Trace Trap", 1}, /* SIGTRAP */ 634134Sdlw {"IOT Trap", 1}, /* SIGIOT */ 644140Sdlw {"EMT Trap", 1}, /* SIGEMT */ 654137Sdlw {"Arithmetic Exception", 1}, /* SIGFPE */ 664134Sdlw { 0, 0}, /* SIGKILL */ 674134Sdlw {"Bus error", 1}, /* SIGBUS */ 684134Sdlw {"Segmentation violation", 1}, /* SIGSEGV */ 694168Sdlw {"Sys arg", 1}, /* SIGSYS */ 704168Sdlw {"Open pipe", 0}, /* SIGPIPE */ 714168Sdlw {"Alarm", 0}, /* SIGALRM */ 724134Sdlw {"Terminated", 0}, /* SIGTERM */ 734168Sdlw {"Sig 16", 0}, /* unassigned */ 744134Sdlw }; 754130Sdlw 7629974Smckusick #ifdef tahoe 7729974Smckusick /* The following arrays are defined & used assuming that signal codes are 7829974Smckusick 1 to 5 for SIGFPE, and 0 to 3 for SIGILL. 7929974Smckusick Actually ILL_ALIGN_FAULT=14, and is mapped to 3. */ 8029974Smckusick 8129974Smckusick #define N_ACT_ILL 4 /* number of entries in act_ill[] */ 8229974Smckusick #define N_ACT_FPE 5 /* number of entries in act_fpe[] */ 8329974Smckusick #define ILL_ALIGN_FAULT 14 8429974Smckusick 854137Sdlw struct action act_fpe[] = { 864137Sdlw {"Integer overflow", 1}, 874137Sdlw {"Integer divide by 0", 1}, 8829974Smckusick {"Floating divide by zero", 1}, 8929974Smckusick {"Floating point overflow", 1}, 9029974Smckusick {"Floating point underflow", 1}, 9129974Smckusick }; 9229974Smckusick 9329974Smckusick #else vax || pdp11 9429974Smckusick 9529974Smckusick struct action act_fpe[] = { 9629974Smckusick {"Integer overflow", 1}, 9729974Smckusick {"Integer divide by 0", 1}, 9813232Sdlw {"Floating point overflow trap", 1}, 9913232Sdlw {"Floating divide by zero trap", 1}, 10013232Sdlw {"Floating point underflow trap", 1}, 1014137Sdlw {"Decimal overflow", 1}, 1024137Sdlw {"Subscript range", 1}, 1034137Sdlw {"Floating point overflow", 0}, 1044137Sdlw {"Floating divide by zero", 0}, 1054137Sdlw {"Floating point underflow", 0}, 1064137Sdlw }; 10729974Smckusick #endif vax || pdp11 1084170Sdlw 1094170Sdlw struct action act_ill[] = { 1104170Sdlw {"addr mode", 1}, 1114170Sdlw {"instruction", 1}, 1124170Sdlw {"operand", 0}, 11329974Smckusick #ifdef tahoe 11429974Smckusick {"alignment", 1}, 11529974Smckusick #endif tahoe 1164170Sdlw }; 1174130Sdlw 11829974Smckusick #if (defined(vax) || defined(tahoe)) 11942454Sbostic void 12014399Sdlw sigdie(s, t, sc) 12114399Sdlw int s; int t; struct sigcontext *sc; 12214399Sdlw 12314399Sdlw #else pdp11 12429974Smckusick 12542454Sbostic void 1264137Sdlw sigdie(s, t, pc) 1274137Sdlw int s; int t; long pc; 12814399Sdlw 12929974Smckusick #endif pdp11 1304130Sdlw { 1314131Sdlw extern unit units[]; 1324134Sdlw register struct action *act = &sig_act[s-1]; 1334726Sdlw /* print error message, then flush buffers */ 1344726Sdlw 13514840Sdlw if (s == SIGHUP || s == SIGINT || s == SIGQUIT) 13614840Sdlw signal(s, SIG_IGN); /* don't allow it again */ 13714840Sdlw else 13814840Sdlw signal(s, SIG_DFL); /* shouldn't happen again, but ... */ 13914840Sdlw 1404137Sdlw if (act->mesg) 1414137Sdlw { 1424173Sdlw fprintf(units[STDERR].ufd, "*** %s", act->mesg); 1434137Sdlw if (s == SIGFPE) 1444168Sdlw { 14529974Smckusick #ifndef tahoe 1464168Sdlw if (t >= 1 && t <= 10) 14729974Smckusick #else tahoe 14829974Smckusick if ((t-1) >= 0 && t < N_ACT_FPE) 14929974Smckusick #endif tahoe 1504168Sdlw fprintf(units[STDERR].ufd, ": %s", act_fpe[t-1].mesg); 1514168Sdlw else 1524168Sdlw fprintf(units[STDERR].ufd, ": Type=%d?", t); 1534168Sdlw } 1544168Sdlw else if (s == SIGILL) 1554170Sdlw { 15629974Smckusick #ifndef tahoe 1574170Sdlw if (t == 4) t = 2; /* 4.0bsd botch */ 1584170Sdlw if (t >= 0 && t <= 2) 15929974Smckusick #else tahoe 16029974Smckusick if (t == ILL_ALIGN_FAULT) /* ILL_ALIGN_FAULT maps to last 16129974Smckusick t = N_ACT_ILL-1; entry in act_ill[] */ 16229974Smckusick if (t >= 0 && t < N_ACT_ILL) 16329974Smckusick #endif tahoe 1644170Sdlw fprintf(units[STDERR].ufd, "%s", act_ill[t].mesg); 1654170Sdlw else 1664170Sdlw fprintf(units[STDERR].ufd, "compat mode: Code=%d", t); 1674170Sdlw } 1684168Sdlw putc('\n', units[STDERR].ufd); 1694137Sdlw } 17020197Slibs f77_abort( s, act->core ); 17120197Slibs } 172