ruby: Removed the obsolete file specified network files
[gem5.git] / src / mem / ruby / libruby.cc
1 /*
2 * Copyright (c) 2009 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/wait.h>
30 #include <algorithm>
31
32 #include "config/gems_root.hh"
33 #include "mem/ruby/libruby_internal.hh"
34 #include "mem/ruby/system/RubyPort.hh"
35 #include "mem/ruby/system/System.hh"
36 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
37 #include "mem/ruby/system/MemoryVector.hh"
38 #include "mem/ruby/common/Address.hh"
39 #include "mem/ruby/recorder/Tracer.hh"
40
41 string RubyRequestType_to_string(const RubyRequestType& obj)
42 {
43 switch(obj) {
44 case RubyRequestType_IFETCH:
45 return "IFETCH";
46 case RubyRequestType_LD:
47 return "LD";
48 case RubyRequestType_ST:
49 return "ST";
50 case RubyRequestType_Locked_Read:
51 return "Locked_Read";
52 case RubyRequestType_Locked_Write:
53 return "Locked_Write";
54 case RubyRequestType_RMW_Read:
55 return "RMW_Read";
56 case RubyRequestType_RMW_Write:
57 return "RMW_Write";
58 case RubyRequestType_NULL:
59 default:
60 assert(0);
61 return "";
62 }
63 }
64
65 RubyRequestType string_to_RubyRequestType(std::string str)
66 {
67 if (str == "IFETCH")
68 return RubyRequestType_IFETCH;
69 else if (str == "LD")
70 return RubyRequestType_LD;
71 else if (str == "ST")
72 return RubyRequestType_ST;
73 else if (str == "Locked_Read")
74 return RubyRequestType_Locked_Read;
75 else if (str == "Locked_Write")
76 return RubyRequestType_Locked_Write;
77 else if (str == "RMW_Read")
78 return RubyRequestType_RMW_Read;
79 else if (str == "RMW_Write")
80 return RubyRequestType_RMW_Write;
81 else
82 assert(0);
83 return RubyRequestType_NULL;
84 }
85
86 ostream& operator<<(ostream& out, const RubyRequestType& obj)
87 {
88 out << RubyRequestType_to_string(obj);
89 out << flush;
90 return out;
91 }
92
93 ostream& operator<<(std::ostream& out, const RubyRequest& obj)
94 {
95 out << hex << "0x" << obj.paddr << " data: 0x" << flush;
96 for (int i = 0; i < obj.len; i++) {
97 out << (int)obj.data[i];
98 }
99 out << dec << " type: " << RubyRequestType_to_string(obj.type) << endl;
100 return out;
101 }
102
103 vector<string> tokenizeString(string str, string delims)
104 {
105 vector<string> tokens;
106 char* pch;
107 char* tmp;
108 const char* c_delims = delims.c_str();
109 tmp = new char[str.length()+1];
110 strcpy(tmp, str.c_str());
111 pch = strtok(tmp, c_delims);
112 while (pch != NULL) {
113 string tmp_str(pch);
114 if (tmp_str == "null") tmp_str = "";
115 tokens.push_back(tmp_str);
116
117 pch = strtok(NULL, c_delims);
118 }
119 delete [] tmp;
120 return tokens;
121 }
122
123
124 /*
125 * The current state of M5/Ruby integration breaks the libruby
126 * interface. This code is ifdef'd out for now so that we can move
127 * forward with the integration process for non-libruby uses. We'll
128 * have to go back and resolve the libruby compatibility issue at a
129 * later date.
130 */
131 #if 0
132 void libruby_init(const char* cfg_filename)
133 {
134 ifstream cfg_output(cfg_filename);
135
136 vector<RubyObjConf> * sys_conf = new vector<RubyObjConf>;
137
138 string line;
139 getline(cfg_output, line) ;
140 while ( !cfg_output.eof() ) {
141 vector<string> tokens = tokenizeString(line, " ");
142 assert(tokens.size() >= 2);
143 vector<string> argv;
144 for (size_t i=2; i<tokens.size(); i++) {
145 std::replace(tokens[i].begin(), tokens[i].end(), '%', ' ');
146 std::replace(tokens[i].begin(), tokens[i].end(), '#', '\n');
147 argv.push_back(tokens[i]);
148 }
149 sys_conf->push_back(RubyObjConf(tokens[0], tokens[1], argv));
150 tokens.clear();
151 argv.clear();
152 getline(cfg_output, line);
153 }
154
155 RubySystem::create(*sys_conf);
156 delete sys_conf;
157 }
158 #endif
159
160 RubyPortHandle libruby_get_port(const char* port_name, void (*hit_callback)(int64_t access_id))
161 {
162 //
163 // Fix me: Hit callback is now a non-static member function pointer of
164 // RubyPort and cannot be set to an arbitrary global function
165 //
166 return NULL;//static_cast<RubyPortHandle>(RubySystem::getPort(port_name, hit_callback));
167 }
168
169 RubyPortHandle libruby_get_port_by_name(const char* port_name)
170 {
171 //
172 // Fix me: Ports should now be initialized using the python configuration
173 // system
174 //
175 return NULL;//static_cast<RubyPortHandle>(RubySystem::getPortOnly(port_name));
176 }
177
178 void libruby_write_ram(uint64_t paddr, uint8_t* data, int len)
179 {
180 RubySystem::getMemoryVector()->write(Address(paddr), data, len);
181 }
182
183 void libruby_read_ram(uint64_t paddr, uint8_t* data, int len)
184 {
185 RubySystem::getMemoryVector()->read(Address(paddr), data, len);
186 }
187
188 int64_t libruby_issue_request(RubyPortHandle p, struct RubyRequest request)
189 {
190 //
191 // Fix me: Ports should now be accessed using the python configuration
192 // system
193 //
194 return 0;//return static_cast<RubyPort*>(p)->makeRequest(request);
195 }
196
197 int libruby_tick(int n)
198 {
199 RubySystem::getEventQueue()->triggerEvents(RubySystem::getEventQueue()->getTime() + n);
200 return 0;
201 }
202
203 void libruby_destroy()
204 {
205 }
206
207 const char* libruby_last_error()
208 {
209 return "";
210 }
211
212 void libruby_print_config(std::ostream & out)
213 {
214 RubySystem::printConfig(out);
215 }
216
217 void libruby_print_stats(std::ostream & out)
218 {
219 RubySystem::printStats(out);
220 }
221 void libruby_playback_trace(char * trace_filename)
222 {
223 RubySystem::getTracer()->playbackTrace(trace_filename);
224 }
225
226 void libruby_start_tracing(char * record_filename) {
227 // start the trace
228 RubySystem::getTracer()->startTrace(record_filename);
229 }
230
231 void libruby_stop_tracing() {
232 // start the trace
233 RubySystem::getTracer()->stopTrace();
234 }
235
236 uint64_t libruby_get_time() {
237 return RubySystem::getCycleCount(0);
238 }