ruby: Converted the sequencer deadlock event to m5 eventq
[gem5.git] / src / mem / ruby / libruby.cc
1
2 #include <sys/wait.h>
3 #include <algorithm>
4
5 #include "config/gems_root.hh"
6 #include "mem/ruby/libruby_internal.hh"
7 #include "mem/ruby/system/RubyPort.hh"
8 #include "mem/ruby/system/System.hh"
9 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
10 #include "mem/ruby/system/MemoryVector.hh"
11 #include "mem/ruby/common/Address.hh"
12 #include "mem/ruby/recorder/Tracer.hh"
13
14 string RubyRequestType_to_string(const RubyRequestType& obj)
15 {
16 switch(obj) {
17 case RubyRequestType_IFETCH:
18 return "IFETCH";
19 case RubyRequestType_LD:
20 return "LD";
21 case RubyRequestType_ST:
22 return "ST";
23 case RubyRequestType_Locked_Read:
24 return "Locked_Read";
25 case RubyRequestType_Locked_Write:
26 return "Locked_Write";
27 case RubyRequestType_RMW_Read:
28 return "RMW_Read";
29 case RubyRequestType_RMW_Write:
30 return "RMW_Write";
31 case RubyRequestType_NULL:
32 default:
33 assert(0);
34 return "";
35 }
36 }
37
38 RubyRequestType string_to_RubyRequestType(std::string str)
39 {
40 if (str == "IFETCH")
41 return RubyRequestType_IFETCH;
42 else if (str == "LD")
43 return RubyRequestType_LD;
44 else if (str == "ST")
45 return RubyRequestType_ST;
46 else if (str == "Locked_Read")
47 return RubyRequestType_Locked_Read;
48 else if (str == "Locked_Write")
49 return RubyRequestType_Locked_Write;
50 else if (str == "RMW_Read")
51 return RubyRequestType_RMW_Read;
52 else if (str == "RMW_Write")
53 return RubyRequestType_RMW_Write;
54 else
55 assert(0);
56 return RubyRequestType_NULL;
57 }
58
59 ostream& operator<<(ostream& out, const RubyRequestType& obj)
60 {
61 out << RubyRequestType_to_string(obj);
62 out << flush;
63 return out;
64 }
65
66 ostream& operator<<(std::ostream& out, const RubyRequest& obj)
67 {
68 out << hex << "0x" << obj.paddr << flush;
69 return out;
70 }
71
72 vector<string> tokenizeString(string str, string delims)
73 {
74 vector<string> tokens;
75 char* pch;
76 char* tmp;
77 const char* c_delims = delims.c_str();
78 tmp = new char[str.length()+1];
79 strcpy(tmp, str.c_str());
80 pch = strtok(tmp, c_delims);
81 while (pch != NULL) {
82 string tmp_str(pch);
83 if (tmp_str == "null") tmp_str = "";
84 tokens.push_back(tmp_str);
85
86 pch = strtok(NULL, c_delims);
87 }
88 delete [] tmp;
89 return tokens;
90 }
91
92
93 /*
94 * The current state of M5/Ruby integration breaks the libruby
95 * interface. This code is ifdef'd out for now so that we can move
96 * forward with the integration process for non-libruby uses. We'll
97 * have to go back and resolve the libruby compatibility issue at a
98 * later date.
99 */
100 #if 0
101 void libruby_init(const char* cfg_filename)
102 {
103 ifstream cfg_output(cfg_filename);
104
105 vector<RubyObjConf> * sys_conf = new vector<RubyObjConf>;
106
107 string line;
108 getline(cfg_output, line) ;
109 while ( !cfg_output.eof() ) {
110 vector<string> tokens = tokenizeString(line, " ");
111 assert(tokens.size() >= 2);
112 vector<string> argv;
113 for (size_t i=2; i<tokens.size(); i++) {
114 std::replace(tokens[i].begin(), tokens[i].end(), '%', ' ');
115 std::replace(tokens[i].begin(), tokens[i].end(), '#', '\n');
116 argv.push_back(tokens[i]);
117 }
118 sys_conf->push_back(RubyObjConf(tokens[0], tokens[1], argv));
119 tokens.clear();
120 argv.clear();
121 getline(cfg_output, line);
122 }
123
124 RubySystem::create(*sys_conf);
125 delete sys_conf;
126 }
127 #endif
128
129 RubyPortHandle libruby_get_port(const char* port_name, void (*hit_callback)(int64_t access_id))
130 {
131 return static_cast<RubyPortHandle>(RubySystem::getPort(port_name, hit_callback));
132 }
133
134 RubyPortHandle libruby_get_port_by_name(const char* port_name)
135 {
136 return static_cast<RubyPortHandle>(RubySystem::getPortOnly(port_name));
137 }
138
139 void libruby_write_ram(uint64_t paddr, uint8_t* data, int len)
140 {
141 RubySystem::getMemoryVector()->write(Address(paddr), data, len);
142 }
143
144 void libruby_read_ram(uint64_t paddr, uint8_t* data, int len)
145 {
146 RubySystem::getMemoryVector()->read(Address(paddr), data, len);
147 }
148
149 int64_t libruby_issue_request(RubyPortHandle p, struct RubyRequest request)
150 {
151 return static_cast<RubyPort*>(p)->makeRequest(request);
152 }
153
154 int libruby_tick(int n)
155 {
156 RubySystem::getEventQueue()->triggerEvents(RubySystem::getEventQueue()->getTime() + n);
157 return 0;
158 }
159
160 void libruby_destroy()
161 {
162 }
163
164 const char* libruby_last_error()
165 {
166 return "";
167 }
168
169 void libruby_print_config(std::ostream & out)
170 {
171 RubySystem::printConfig(out);
172 }
173
174 void libruby_print_stats(std::ostream & out)
175 {
176 RubySystem::printStats(out);
177 }
178 void libruby_playback_trace(char * trace_filename)
179 {
180 RubySystem::getTracer()->playbackTrace(trace_filename);
181 }
182
183 void libruby_start_tracing(char * record_filename) {
184 // start the trace
185 RubySystem::getTracer()->startTrace(record_filename);
186 }
187
188 void libruby_stop_tracing() {
189 // start the trace
190 RubySystem::getTracer()->stopTrace();
191 }
192
193 uint64_t libruby_get_time() {
194 return RubySystem::getCycleCount(0);
195 }