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
<< " data: 0x" << flush
;
69 for (int i
= 0; i
< obj
.len
; i
++) {
70 out
<< (int)obj
.data
[i
];
72 out
<< dec
<< " type: " << RubyRequestType_to_string(obj
.type
) << endl
;
76 vector
<string
> tokenizeString(string str
, string delims
)
78 vector
<string
> tokens
;
81 const char* c_delims
= delims
.c_str();
82 tmp
= new char[str
.length()+1];
83 strcpy(tmp
, str
.c_str());
84 pch
= strtok(tmp
, c_delims
);
87 if (tmp_str
== "null") tmp_str
= "";
88 tokens
.push_back(tmp_str
);
90 pch
= strtok(NULL
, c_delims
);
98 * The current state of M5/Ruby integration breaks the libruby
99 * interface. This code is ifdef'd out for now so that we can move
100 * forward with the integration process for non-libruby uses. We'll
101 * have to go back and resolve the libruby compatibility issue at a
105 void libruby_init(const char* cfg_filename
)
107 ifstream
cfg_output(cfg_filename
);
109 vector
<RubyObjConf
> * sys_conf
= new vector
<RubyObjConf
>;
112 getline(cfg_output
, line
) ;
113 while ( !cfg_output
.eof() ) {
114 vector
<string
> tokens
= tokenizeString(line
, " ");
115 assert(tokens
.size() >= 2);
117 for (size_t i
=2; i
<tokens
.size(); i
++) {
118 std::replace(tokens
[i
].begin(), tokens
[i
].end(), '%', ' ');
119 std::replace(tokens
[i
].begin(), tokens
[i
].end(), '#', '\n');
120 argv
.push_back(tokens
[i
]);
122 sys_conf
->push_back(RubyObjConf(tokens
[0], tokens
[1], argv
));
125 getline(cfg_output
, line
);
128 RubySystem::create(*sys_conf
);
133 RubyPortHandle
libruby_get_port(const char* port_name
, void (*hit_callback
)(int64_t access_id
))
135 return static_cast<RubyPortHandle
>(RubySystem::getPort(port_name
, hit_callback
));
138 RubyPortHandle
libruby_get_port_by_name(const char* port_name
)
140 return static_cast<RubyPortHandle
>(RubySystem::getPortOnly(port_name
));
143 void libruby_write_ram(uint64_t paddr
, uint8_t* data
, int len
)
145 RubySystem::getMemoryVector()->write(Address(paddr
), data
, len
);
148 void libruby_read_ram(uint64_t paddr
, uint8_t* data
, int len
)
150 RubySystem::getMemoryVector()->read(Address(paddr
), data
, len
);
153 int64_t libruby_issue_request(RubyPortHandle p
, struct RubyRequest request
)
155 return static_cast<RubyPort
*>(p
)->makeRequest(request
);
158 int libruby_tick(int n
)
160 RubySystem::getEventQueue()->triggerEvents(RubySystem::getEventQueue()->getTime() + n
);
164 void libruby_destroy()
168 const char* libruby_last_error()
173 void libruby_print_config(std::ostream
& out
)
175 RubySystem::printConfig(out
);
178 void libruby_print_stats(std::ostream
& out
)
180 RubySystem::printStats(out
);
182 void libruby_playback_trace(char * trace_filename
)
184 RubySystem::getTracer()->playbackTrace(trace_filename
);
187 void libruby_start_tracing(char * record_filename
) {
189 RubySystem::getTracer()->startTrace(record_filename
);
192 void libruby_stop_tracing() {
194 RubySystem::getTracer()->stopTrace();
197 uint64_t libruby_get_time() {
198 return RubySystem::getCycleCount(0);