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"
14 string
RubyRequestType_to_string(const RubyRequestType
& obj
)
17 case RubyRequestType_IFETCH
:
19 case RubyRequestType_LD
:
21 case RubyRequestType_ST
:
23 case RubyRequestType_Locked_Read
:
25 case RubyRequestType_Locked_Write
:
26 return "Locked_Write";
27 case RubyRequestType_RMW_Read
:
29 case RubyRequestType_RMW_Write
:
31 case RubyRequestType_NULL
:
38 RubyRequestType
string_to_RubyRequestType(std::string str
)
41 return RubyRequestType_IFETCH
;
43 return RubyRequestType_LD
;
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
;
56 return RubyRequestType_NULL
;
59 ostream
& operator<<(ostream
& out
, const RubyRequestType
& obj
)
61 out
<< RubyRequestType_to_string(obj
);
66 ostream
& operator<<(std::ostream
& out
, const RubyRequest
& obj
)
68 out
<< hex
<< "0x" << obj
.paddr
<< flush
;
72 vector
<string
> tokenizeString(string str
, string delims
)
74 vector
<string
> tokens
;
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
);
83 if (tmp_str
== "null") tmp_str
= "";
84 tokens
.push_back(tmp_str
);
86 pch
= strtok(NULL
, c_delims
);
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
101 void libruby_init(const char* cfg_filename
)
103 ifstream
cfg_output(cfg_filename
);
105 vector
<RubyObjConf
> * sys_conf
= new vector
<RubyObjConf
>;
108 getline(cfg_output
, line
) ;
109 while ( !cfg_output
.eof() ) {
110 vector
<string
> tokens
= tokenizeString(line
, " ");
111 assert(tokens
.size() >= 2);
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
]);
118 sys_conf
->push_back(RubyObjConf(tokens
[0], tokens
[1], argv
));
121 getline(cfg_output
, line
);
124 RubySystem::create(*sys_conf
);
129 RubyPortHandle
libruby_get_port(const char* port_name
, void (*hit_callback
)(int64_t access_id
))
131 return static_cast<RubyPortHandle
>(RubySystem::getPort(port_name
, hit_callback
));
134 RubyPortHandle
libruby_get_port_by_name(const char* port_name
)
136 return static_cast<RubyPortHandle
>(RubySystem::getPortOnly(port_name
));
139 void libruby_write_ram(uint64_t paddr
, uint8_t* data
, int len
)
141 RubySystem::getMemoryVector()->write(Address(paddr
), data
, len
);
144 void libruby_read_ram(uint64_t paddr
, uint8_t* data
, int len
)
146 RubySystem::getMemoryVector()->read(Address(paddr
), data
, len
);
149 int64_t libruby_issue_request(RubyPortHandle p
, struct RubyRequest request
)
151 return static_cast<RubyPort
*>(p
)->makeRequest(request
);
154 int libruby_tick(int n
)
156 RubySystem::getEventQueue()->triggerEvents(RubySystem::getEventQueue()->getTime() + n
);
160 void libruby_destroy()
164 const char* libruby_last_error()
169 void libruby_print_config(std::ostream
& out
)
171 RubySystem::printConfig(out
);
174 void libruby_print_stats(std::ostream
& out
)
176 RubySystem::printStats(out
);
178 void libruby_playback_trace(char * trace_filename
)
180 RubySystem::getTracer()->playbackTrace(trace_filename
);
183 void libruby_start_tracing(char * record_filename
) {
185 RubySystem::getTracer()->startTrace(record_filename
);
188 void libruby_stop_tracing() {
190 RubySystem::getTracer()->stopTrace();
193 uint64_t libruby_get_time() {
194 return RubySystem::getCycleCount(0);