init.cc (10178:0d8e24faf1f8) init.cc (10453:d0365cc3d05f)
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 32 unchanged lines hidden (view full) ---

41 * Authors: Nathan Binkert
42 */
43
44#include <Python.h>
45
46#include <marshal.h>
47#include <zlib.h>
48
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 32 unchanged lines hidden (view full) ---

41 * Authors: Nathan Binkert
42 */
43
44#include <Python.h>
45
46#include <marshal.h>
47#include <zlib.h>
48
49#include <csignal>
50#include <iostream>
51#include <list>
52#include <string>
53
54#include "base/cprintf.hh"
55#include "base/misc.hh"
56#include "base/types.hh"
57#include "config/have_protobuf.hh"
58#include "sim/async.hh"
59#include "sim/core.hh"
60#include "sim/init.hh"
61
62#if HAVE_PROTOBUF
63#include <google/protobuf/stubs/common.h>
64#endif
65
66using namespace std;
67
49#include <iostream>
50#include <list>
51#include <string>
52
53#include "base/cprintf.hh"
54#include "base/misc.hh"
55#include "base/types.hh"
56#include "config/have_protobuf.hh"
57#include "sim/async.hh"
58#include "sim/core.hh"
59#include "sim/init.hh"
60
61#if HAVE_PROTOBUF
62#include <google/protobuf/stubs/common.h>
63#endif
64
65using namespace std;
66
68/// Stats signal handler.
69void
70dumpStatsHandler(int sigtype)
71{
72 async_event = true;
73 async_statdump = true;
74}
75
76void
77dumprstStatsHandler(int sigtype)
78{
79 async_event = true;
80 async_statdump = true;
81 async_statreset = true;
82}
83
84/// Exit signal handler.
85void
86exitNowHandler(int sigtype)
87{
88 async_event = true;
89 async_exit = true;
90}
91
92/// Abort signal handler.
93void
94abortHandler(int sigtype)
95{
96 ccprintf(cerr, "Program aborted at tick %d\n", curTick());
97}
98
99// Handle SIGIO
100static void
101ioHandler(int sigtype)
102{
103 async_event = true;
104 async_io = true;
105}
106
107static void
108installSignalHandler(int signal, void (*handler)(int sigtype))
109{
110 struct sigaction sa;
111
112 memset(&sa, 0, sizeof(sa));
113 sigemptyset(&sa.sa_mask);
114 sa.sa_handler = handler;
115 sa.sa_flags = SA_RESTART;
116
117 if (sigaction(signal, &sa, NULL) == -1)
118 panic("Failed to setup handler for signal %i\n", signal);
119}
120
121/*
122 * M5 can do several special things when various signals are sent.
123 * None are mandatory.
124 */
125void
126initSignals()
127{
128 // Floating point exceptions may happen on misspeculated paths, so
129 // ignore them
130 signal(SIGFPE, SIG_IGN);
131
132 // We use SIGTRAP sometimes for debugging
133 signal(SIGTRAP, SIG_IGN);
134
135 // Dump intermediate stats
136 installSignalHandler(SIGUSR1, dumpStatsHandler);
137
138 // Dump intermediate stats and reset them
139 installSignalHandler(SIGUSR2, dumprstStatsHandler);
140
141 // Exit cleanly on Interrupt (Ctrl-C)
142 installSignalHandler(SIGINT, exitNowHandler);
143
144 // Print out cycle number on abort
145 installSignalHandler(SIGABRT, abortHandler);
146
147 // Install a SIGIO handler to handle asynchronous file IO. See the
148 // PollQueue class.
149 installSignalHandler(SIGIO, ioHandler);
150}
151
152// The python library is totally messed up with respect to constness,
153// so make a simple macro to make life a little easier
154#define PyCC(x) (const_cast<char *>(x))
155
156EmbeddedPython *EmbeddedPython::importer = NULL;
157PyObject *EmbeddedPython::importerModule = NULL;
158EmbeddedPython::EmbeddedPython(const char *filename, const char *abspath,
159 const char *modpath, const unsigned char *code, int zlen, int len)

--- 169 unchanged lines hidden ---
67// The python library is totally messed up with respect to constness,
68// so make a simple macro to make life a little easier
69#define PyCC(x) (const_cast<char *>(x))
70
71EmbeddedPython *EmbeddedPython::importer = NULL;
72PyObject *EmbeddedPython::importerModule = NULL;
73EmbeddedPython::EmbeddedPython(const char *filename, const char *abspath,
74 const char *modpath, const unsigned char *code, int zlen, int len)

--- 169 unchanged lines hidden ---