46 #include "iris/detail/IrisCppAdapter.h"
47 #include "iris/detail/IrisObjects.h"
68 iris::EventSourceInfo evSrcInfo;
70 client.registerEventCallback<Self, &Self::breakpointHit>(
71 this,
"ec_IRIS_BREAKPOINT_HIT",
72 "Handle hitting a breakpoint",
"Iris::ThreadContext");
73 call().event_getEventSource(
_instId, evSrcInfo,
"IRIS_BREAKPOINT_HIT");
75 evSrcInfo.evSrcId,
client.getInstId());
77 for (
auto it =
bps.begin(); it !=
bps.end(); it++)
80 client.registerEventCallback<Self, &Self::semihostingEvent>(
81 this,
"ec_IRIS_SEMIHOSTING_CALL_EXTENSION",
82 "Handle a semihosting call",
"Iris::ThreadContext");
84 "IRIS_SEMIHOSTING_CALL_EXTENSION");
86 evSrcInfo.evSrcId,
client.getInstId(),
89 nullptr,
"",
false, 0,
nullptr,
false,
false,
true);
96 return resources.at(
name).rscId;
104 for (
const auto &idx_name: idx_names) {
105 int idx = idx_name.first;
106 const std::string &
name = idx_name.second;
108 if (idx >=
ids.size())
109 ids.resize(idx + 1, iris::IRIS_UINT64_MAX);
138 Tick remaining = next - now;
139 call().step_setup(
_instId, remaining,
"instruction");
147 auto pc_it =
bps.find(
pc);
149 if (pc_it !=
bps.end())
153 panic_if(!res.second,
"Inserting breakpoint failed.");
162 for (
auto sid: space_ids) {
165 it->second->ids.push_back(
id);
172 for (
auto id: it->second->ids)
174 it->second->clearIds();
181 "BP info still had events associated with it.");
183 if (it->second->validIds())
191 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
192 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
194 const std::string &
event = fields.at(
"EVENT").getString();
195 const iris::InstanceId
id = fields.at(
"INST_ID").getU64();
196 const std::string &
name = fields.at(
"INST_NAME").getString();
201 if (
event ==
"added")
203 else if (
event ==
"removed")
204 _instId = iris::IRIS_UINT64_MAX;
213 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
214 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
219 std::map<iris::ResourceId, const iris::ResourceInfo *>
221 for (
const auto &resource: resources) {
222 idToResource[resource.rscId] = &resource;
225 for (
const auto &resource: resources) {
226 std::string
name = resource.name;
227 iris::ResourceId parentId = resource.parentRscId;
228 while (parentId != iris::IRIS_UINT64_MAX) {
229 const auto *parent = idToResource[parentId];
231 parentId = parent->parentRscId;
233 resourceMap[
name] = resource;
243 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
244 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
246 if (fields.at(
"RUNNING").getAsBool()) {
258 call().simulationTime_run(iris::IrisInstIdSimulationEngine);
265 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
266 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
268 Addr pc = fields.at(
"PC").getU64();
272 std::shared_ptr<BpInfo::EventList> events = it->second->events;
273 auto e_it = events->begin();
274 while (e_it != events->end()) {
286 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
287 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
292 call().perInstanceExecution_setState(
_instId,
false);
308 BaseISA *isa, iris::IrisConnectionInterface *iris_if,
309 const std::string &iris_path) :
310 _cpu(cpu), _threadId(
id), _system(
system), _dtb(dtb), _itb(itb), _isa(isa),
313 comInstEventQueue(
"instruction-based event queue"),
314 client(iris_if,
"client." + iris_path)
316 iris::InstanceInfo info;
317 auto ret_code =
noThrow().instanceRegistry_getInstanceInfoByName(
318 info,
"component." + iris_path);
319 if (ret_code == iris::E_ok) {
324 _instId = iris::IRIS_UINT64_MAX;
328 iris::EventSourceInfo evSrcInfo;
330 client.registerEventCallback<Self, &Self::instanceRegistryChanged>(
331 this,
"ec_IRIS_INSTANCE_REGISTRY_CHANGED",
332 "Install the iris instance ID",
"Iris::ThreadContext");
333 call().event_getEventSource(iris::IrisInstIdGlobalInstance, evSrcInfo,
334 "IRIS_INSTANCE_REGISTRY_CHANGED");
337 {
"EVENT",
"INST_ID",
"INST_NAME" };
339 evSrcInfo.evSrcId,
client.getInstId(), &fields);
341 client.registerEventCallback<Self, &Self::phaseInitLeave>(
342 this,
"ec_IRIS_SIM_PHASE_INIT_LEAVE",
343 "Initialize register contexts",
"Iris::ThreadContext");
344 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
345 "IRIS_SIM_PHASE_INIT_LEAVE");
347 call().eventStream_create(
349 evSrcInfo.evSrcId,
client.getInstId());
351 client.registerEventCallback<Self, &Self::simulationTimeEvent>(
352 this,
"ec_IRIS_SIMULATION_TIME_EVENT",
353 "Handle simulation time stopping for breakpoints or stepping",
354 "Iris::ThreadContext");
355 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
356 "IRIS_SIMULATION_TIME_EVENT");
358 call().eventStream_create(
360 evSrcInfo.evSrcId,
client.getInstId());
365 auto enable_lambda = [
this]{
366 call().perInstanceExecution_setState(
_instId,
true);
369 enable_lambda,
"resume after pseudo inst",
375 call().eventStream_destroy(
378 client.unregisterEventCallback(
"ec_IRIS_SIM_PHASE_INIT_LEAVE");
380 call().eventStream_destroy(
383 client.unregisterEventCallback(
"ec_IRIS_INSTANCE_REGISTRY_CHANGED");
385 call().eventStream_destroy(
388 client.unregisterEventCallback(
"ec_IRIS_SIMULATION_TIME_EVENT");
399 it->second->events->push_back(
e);
401 if (
_instId != iris::IRIS_UINT64_MAX && !it->second->validIds())
411 it->second->events->remove(
e);
413 if (it->second->empty())
423 iris::MemoryAddressTranslationResult result;
424 auto ret =
noThrow().memory_translateAddress(
427 if (ret != iris::E_ok) {
431 if (trans.inSpaceId == v_space && trans.outSpaceId == p_space)
434 panic(
"No legal translation IRIS address translation found.");
437 if (result.address.empty())
440 if (result.address.size() > 1) {
441 warn(
"Multiple mappings for address %#x.",
vaddr);
445 paddr = result.address[0];
455 call().simulationTime_stop(iris::IrisInstIdSimulationEngine);
472 panic_if(ret != iris::E_ok,
"Failed to get instruction count.");
502 if (new_status ==
Active) {
504 call().perInstanceExecution_setState(
_instId,
true);
507 call().perInstanceExecution_setState(
_instId,
false);
519 pc.nextThumb(
pc.thumb());
521 pc.nextJazelle(cpsr.j);
522 pc.aarch64(!cpsr.width);
523 pc.nextAArch64(!cpsr.width);
524 pc.illegalExec(
false);
528 iris::ResourceReadResult result;
531 if (cpsr.width && cpsr.t)
543 if (cpsr.width && cpsr.t)
546 iris::ResourceWriteResult result;
559 return pcState().nextInstAddr();
565 iris::ResourceReadResult result;
567 return result.data.at(0);
573 iris::ResourceWriteResult result;
582 iris::ResourceReadResult result;
587 return result.data.at(0);
595 iris::ResourceWriteResult result;
612 if (res_id == iris::IRIS_UINT64_MAX)
614 iris::ResourceReadResult result;
616 return result.data.at(0);
622 iris::ResourceId res_id =
625 panic_if(res_id == iris::IRIS_UINT64_MAX,
626 "Int reg %d is not supported by fast model.", idx);
627 iris::ResourceWriteResult result;
636 iris::ResourceReadResult result;
638 return result.data.at(0);
645 "CC reg %d is not supported by fast model.", idx);
646 iris::ResourceWriteResult result;
663 iris::ResourceReadResult result;
665 size_t data_size = result.data.size() * (
sizeof(*result.data.data()));
666 size_t size = std::min(data_size,
reg.size());
667 memcpy(
reg.raw_ptr<
void>(), (
void *)result.data.data(), size);
689 iris::ResourceReadResult result;
693 size_t num_bits =
reg.NUM_BITS;
694 uint8_t *bytes = (uint8_t *)result.data.data();
695 while (num_bits > 8) {