1/* Simulator signal support 2 Copyright (C) 1997, 2007, 2008, 2009, 2010, 2011 3 Free Software Foundation, Inc. 4 Contributed by Cygnus Support 5 6This file is part of the GNU Simulators. 7 8This program is free software; you can redistribute it and/or modify 9it under the terms of the GNU General Public License as published by 10the Free Software Foundation; either version 3 of the License, or 11(at your option) any later version. 12 13This program is distributed in the hope that it will be useful, 14but WITHOUT ANY WARRANTY; without even the implied warranty of 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16GNU General Public License for more details. 17 18You should have received a copy of the GNU General Public License 19along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21#include <signal.h> 22#include "sim-main.h" 23 24/* Convert SIM_SIGFOO to SIGFOO. 25 What to do when the host doesn't have SIGFOO is handled on a case by case 26 basis. Generally, in the case of passing a value back to gdb, we want gdb 27 to not think the process has died (so it can be debugged at the point of 28 failure). */ 29 30#ifdef _WIN32 31#ifndef SIGTRAP 32#define SIGTRAP 5 33#endif 34#ifndef SIGBUS 35#define SIGBUS 10 36#endif 37#ifndef SIGQUIT 38#define SIGQUIT 3 39#endif 40#endif 41 42int 43sim_signal_to_host (SIM_DESC sd, SIM_SIGNAL sig) 44{ 45 switch (sig) 46 { 47 case SIM_SIGINT : 48 return SIGINT; 49 50 case SIM_SIGABRT : 51 return SIGABRT; 52 53 case SIM_SIGILL : 54#ifdef SIGILL 55 return SIGILL; 56#else 57 return SIGSEGV; 58#endif 59 60 case SIM_SIGTRAP : 61 return SIGTRAP; 62 63 case SIM_SIGBUS : 64#ifdef SIGBUS 65 return SIGBUS; 66#else 67 return SIGSEGV; 68#endif 69 70 case SIM_SIGSEGV : 71 return SIGSEGV; 72 73 case SIM_SIGXCPU : 74#ifdef SIGXCPU 75 return SIGXCPU; 76#endif 77 break; 78 79 case SIM_SIGFPE: 80#ifdef SIGFPE 81 return SIGFPE; 82#endif 83 break; 84 85 case SIM_SIGNONE: 86 return 0; 87 break; 88 } 89 90 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig); 91#ifdef SIGHUP 92 return SIGHUP; /* FIXME: Suggestions? */ 93#else 94 return 1; 95#endif 96} 97 98enum target_signal 99sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig) 100{ 101 switch (sig) 102 { 103 case SIM_SIGINT : 104 return TARGET_SIGNAL_INT; 105 106 case SIM_SIGABRT : 107 return TARGET_SIGNAL_ABRT; 108 109 case SIM_SIGILL : 110 return TARGET_SIGNAL_ILL; 111 112 case SIM_SIGTRAP : 113 return TARGET_SIGNAL_TRAP; 114 115 case SIM_SIGBUS : 116 return TARGET_SIGNAL_BUS; 117 118 case SIM_SIGSEGV : 119 return TARGET_SIGNAL_SEGV; 120 121 case SIM_SIGXCPU : 122 return TARGET_SIGNAL_XCPU; 123 124 case SIM_SIGFPE: 125 return TARGET_SIGNAL_FPE; 126 break; 127 128 case SIM_SIGNONE: 129 return TARGET_SIGNAL_0; 130 break; 131 } 132 133 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig); 134 return TARGET_SIGNAL_HUP; 135} 136