Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / legion / src / simcore / signals.c
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: signals.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)signals.c 1.6 06/08/31 SMI"
/*
* Signal handling code
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>
#include <stropts.h>
#include <poll.h>
#include "basics.h"
/*
* Definitions
*/
static void exit_handler(int);
static void hup_handler(int);
static void poll_handler(int);
/*
* Default signal settings for the main LWP
*/
void
init_signals()
{
/*
* typically these two delivered as a result of terminal
* attach/detach
*/
signal(SIGPOLL, poll_handler);
signal(SIGHUP, hup_handler);
/* standard signals */
signal(SIGINT, exit_handler);
signal(SIGILL, exit_handler);
signal(SIGIOT, exit_handler);
signal(SIGFPE, exit_handler);
#if !defined(HOST_OS_LINUX)
signal(SIGEMT, exit_handler);
#endif
signal(SIGBUS, exit_handler);
signal(SIGSEGV, exit_handler);
signal(SIGSYS, exit_handler);
}
static void
exit_handler(int sig)
{
char *strp;
switch (sig) {
case SIGINT:
strp = "Interrupted";
break;
case SIGILL:
strp = "Illegal Instruction";
break;
case SIGTRAP:
strp = "Trace Trap";
break;
case SIGSEGV:
strp = "Segmentation violation";
break;
case SIGBUS:
strp = "Bus Error";
break;
case SIGIOT:
strp = "IOT Trap";
break;
#if !defined(HOST_OS_LINUX)
case SIGEMT:
strp = "EMT Trap";
break;
#endif
case SIGFPE:
strp = "Numeric Exception (Divide by Zero?)";
break;
case SIGSYS:
strp = "Bad System Call Argument";
break;
default:
strp = NULL;
break;
}
fflush(stdout);
if (strp != NULL)
fprintf(stderr, "SIGNAL: %s\n", strp);
else
fprintf(stderr, "SIGNAL: Unknown signal %d\n", sig);
fflush(stderr);
exit(1);
}
static void
hup_handler(int sig)
{
fprintf(stderr, "Hup !\n");
}
static void
poll_handler(int sig)
{
fprintf(stderr, "Poll !\n");
}