22a048b5b13b19982415cf0eda8948769ead0498
[gem5.git] / src / mem / ruby / init.cc
1
2 /*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * init.C
32 *
33 * Description: See init.h
34 *
35 * $Id$
36 *
37 */
38
39 #include "mem/ruby/common/Global.hh"
40 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
41 #include "mem/ruby/system/System.hh"
42 #include "mem/ruby/common/Debug.hh"
43 #include "mem/ruby/profiler/Profiler.hh"
44 #include "mem/ruby/tester/Tester.hh"
45 #include "mem/ruby/init.hh"
46
47 using namespace std;
48 #include <string>
49 #include <map>
50 #include <stdlib.h>
51
52 #include "mem/gems_common/ioutil/confio.hh"
53 #include "mem/gems_common/ioutil/initvar.hh"
54
55 // A generated file containing the default parameters in string form
56 // The defaults are stored in the variable global_default_param
57 #include "mem/protocol/default_param.hh"
58
59 static initvar_t *ruby_initvar_obj = NULL;
60
61 //***************************************************************************
62 static void init_generate_values( void )
63 {
64 /* update generated values, based on input configuration */
65 }
66
67 //***************************************************************************
68 void init_variables( void )
69 {
70 // allocate the "variable initialization" package
71 ruby_initvar_obj = new initvar_t( "ruby", "../../../ruby/",
72 global_default_param,
73 &init_simulator,
74 &init_generate_values );
75 }
76
77 void init_simulator()
78 {
79 // Set things to NULL to make sure we don't de-reference them
80 // without a seg. fault.
81 g_system_ptr = NULL;
82 g_debug_ptr = NULL;
83 g_eventQueue_ptr = NULL;
84
85 cout << "Ruby Timing Mode" << endl;
86
87 RubyConfig::init();
88
89 g_debug_ptr = new Debug( DEBUG_FILTER_STRING,
90 DEBUG_VERBOSITY_STRING,
91 DEBUG_START_TIME,
92 DEBUG_OUTPUT_FILENAME );
93
94 cout << "Creating event queue..." << endl;
95 g_eventQueue_ptr = new RubyEventQueue;
96 cout << "Creating event queue done" << endl;
97
98 cout << "Creating system..." << endl;
99 cout << " Processors: " << RubyConfig::numberOfProcessors() << endl;
100
101 g_system_ptr = new RubySystem;
102 cout << "Creating system done" << endl;
103
104 cout << "Ruby initialization complete" << endl;
105 }
106
107 void destroy_simulator()
108 {
109 cout << "Deleting system..." << endl;
110 delete g_system_ptr;
111 cout << "Deleting system done" << endl;
112
113 cout << "Deleting event queue..." << endl;
114 delete g_eventQueue_ptr;
115 cout << "Deleting event queue done" << endl;
116
117 delete g_debug_ptr;
118 }
119
120 /*-------------------------------------------------------------------------+
121 | DG: These are the external load and unload hooks that will be called by |
122 | M5 in phase 1 integration, and possibly afterwards, too. |
123 +-------------------------------------------------------------------------*/
124
125 extern "C"
126 int OnLoadRuby() {
127 init_variables();
128 return 0;
129 }
130
131 extern "C"
132 int OnInitRuby() {
133 init_simulator();
134 return 0;
135 }
136
137 extern "C"
138 int OnUnloadRuby() {
139 destroy_simulator();
140 return 0;
141 }
142
143 /* I have to put it somewhere for now */
144 void tester_main(int argc, char **argv) {
145 std::cout << __FILE__ << "(" << __LINE__ << "): Not implemented." << std::endl;
146 }