47 #include "iris/detail/IrisCppAdapter.h"
48 #include "iris/detail/IrisObjects.h"
72 iris::EventSourceInfo evSrcInfo;
74 client.registerEventCallback<Self, &Self::breakpointHit>(
75 this,
"ec_IRIS_BREAKPOINT_HIT",
76 "Handle hitting a breakpoint",
"Iris::ThreadContext");
77 call().event_getEventSource(
_instId, evSrcInfo,
"IRIS_BREAKPOINT_HIT");
79 evSrcInfo.evSrcId,
client.getInstId());
81 for (
auto it =
bps.begin(); it !=
bps.end(); it++)
84 client.registerEventCallback<Self, &Self::semihostingEvent>(
85 this,
"ec_IRIS_SEMIHOSTING_CALL_EXTENSION",
86 "Handle a semihosting call",
"Iris::ThreadContext");
88 "IRIS_SEMIHOSTING_CALL_EXTENSION");
90 evSrcInfo.evSrcId,
client.getInstId(),
93 nullptr,
"",
false, 0,
nullptr,
false,
false,
true);
100 return resources.at(
name).rscId;
108 for (
const auto &idx_name: idx_names) {
109 int idx = idx_name.first;
110 const std::string &
name = idx_name.second;
112 if (idx >=
ids.size())
113 ids.resize(idx + 1, iris::IRIS_UINT64_MAX);
142 Tick remaining = next - now;
143 call().step_setup(
_instId, remaining,
"instruction");
151 auto pc_it =
bps.find(
pc);
153 if (pc_it !=
bps.end())
157 panic_if(!res.second,
"Inserting breakpoint failed.");
166 for (
auto sid: space_ids) {
169 it->second->ids.push_back(
id);
176 for (
auto id: it->second->ids)
178 it->second->clearIds();
185 "BP info still had events associated with it.");
187 if (it->second->validIds())
195 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
196 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
198 const std::string &
event = fields.at(
"EVENT").getString();
199 const iris::InstanceId
id = fields.at(
"INST_ID").getU64();
200 const std::string &
name = fields.at(
"INST_NAME").getString();
205 if (
event ==
"added")
207 else if (
event ==
"removed")
208 _instId = iris::IRIS_UINT64_MAX;
217 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
218 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
223 std::map<iris::ResourceId, const iris::ResourceInfo *>
225 for (
const auto &resource: resources) {
226 idToResource[resource.rscId] = &resource;
229 for (
const auto &resource: resources) {
230 std::string
name = resource.name;
231 iris::ResourceId parentId = resource.parentRscId;
232 while (parentId != iris::IRIS_UINT64_MAX) {
233 const auto *parent = idToResource[parentId];
235 parentId = parent->parentRscId;
237 resourceMap[
name] = resource;
247 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
248 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
250 if (fields.at(
"RUNNING").getAsBool()) {
262 call().simulationTime_run(iris::IrisInstIdSimulationEngine);
269 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
270 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
272 Addr pc = fields.at(
"PC").getU64();
276 std::shared_ptr<BpInfo::EventList> events = it->second->events;
277 auto e_it = events->begin();
278 while (e_it != events->end()) {
290 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
291 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
296 call().perInstanceExecution_setState(
_instId,
false);
312 BaseISA *isa, iris::IrisConnectionInterface *iris_if,
313 const std::string &iris_path) :
314 _cpu(cpu), _threadId(
id), _system(
system), _mmu(mmu), _isa(isa),
315 _irisPath(iris_path), vecRegs(ArmISA::
NumVecRegs),
317 comInstEventQueue(
"instruction-based event queue"),
318 client(iris_if,
"client." + iris_path)
320 iris::InstanceInfo info;
321 auto ret_code =
noThrow().instanceRegistry_getInstanceInfoByName(
322 info,
"component." + iris_path);
323 if (ret_code == iris::E_ok) {
328 _instId = iris::IRIS_UINT64_MAX;
332 iris::EventSourceInfo evSrcInfo;
334 client.registerEventCallback<Self, &Self::instanceRegistryChanged>(
335 this,
"ec_IRIS_INSTANCE_REGISTRY_CHANGED",
336 "Install the iris instance ID",
"Iris::ThreadContext");
337 call().event_getEventSource(iris::IrisInstIdGlobalInstance, evSrcInfo,
338 "IRIS_INSTANCE_REGISTRY_CHANGED");
341 {
"EVENT",
"INST_ID",
"INST_NAME" };
343 evSrcInfo.evSrcId,
client.getInstId(), &fields);
345 client.registerEventCallback<Self, &Self::phaseInitLeave>(
346 this,
"ec_IRIS_SIM_PHASE_INIT_LEAVE",
347 "Initialize register contexts",
"Iris::ThreadContext");
348 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
349 "IRIS_SIM_PHASE_INIT_LEAVE");
351 call().eventStream_create(
353 evSrcInfo.evSrcId,
client.getInstId());
355 client.registerEventCallback<Self, &Self::simulationTimeEvent>(
356 this,
"ec_IRIS_SIMULATION_TIME_EVENT",
357 "Handle simulation time stopping for breakpoints or stepping",
358 "Iris::ThreadContext");
359 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
360 "IRIS_SIMULATION_TIME_EVENT");
362 call().eventStream_create(
364 evSrcInfo.evSrcId,
client.getInstId());
369 auto enable_lambda = [
this]{
370 call().perInstanceExecution_setState(
_instId,
true);
373 enable_lambda,
"resume after pseudo inst",
379 call().eventStream_destroy(
382 client.unregisterEventCallback(
"ec_IRIS_SIM_PHASE_INIT_LEAVE");
384 call().eventStream_destroy(
387 client.unregisterEventCallback(
"ec_IRIS_INSTANCE_REGISTRY_CHANGED");
389 call().eventStream_destroy(
392 client.unregisterEventCallback(
"ec_IRIS_SIMULATION_TIME_EVENT");
403 it->second->events->push_back(
e);
405 if (
_instId != iris::IRIS_UINT64_MAX && !it->second->validIds())
415 it->second->events->remove(
e);
417 if (it->second->empty())
427 iris::MemoryAddressTranslationResult result;
428 auto ret =
noThrow().memory_translateAddress(
431 if (ret != iris::E_ok) {
435 if (trans.inSpaceId == v_space && trans.outSpaceId == p_space)
438 panic(
"No legal translation IRIS address translation found.");
441 if (result.address.empty())
444 if (result.address.size() > 1) {
445 warn(
"Multiple mappings for address %#x.",
vaddr);
449 paddr = result.address[0];
459 call().simulationTime_stop(iris::IrisInstIdSimulationEngine);
476 panic_if(ret != iris::E_ok,
"Failed to get instruction count.");
497 iris_cpu->evs_base_cpu->sendFunc(pkt);
511 if (new_status ==
Active) {
513 call().perInstanceExecution_setState(
_instId,
true);
516 call().perInstanceExecution_setState(
_instId,
false);
528 pc.nextThumb(
pc.thumb());
530 pc.nextJazelle(cpsr.j);
531 pc.aarch64(!cpsr.width);
532 pc.nextAArch64(!cpsr.width);
533 pc.illegalExec(
false);
537 iris::ResourceReadResult result;
540 if (cpsr.width && cpsr.t)
552 if (cpsr.width && cpsr.t)
555 iris::ResourceWriteResult result;
568 return pcState().nextInstAddr();
574 iris::ResourceReadResult result;
576 return result.data.at(0);
582 iris::ResourceWriteResult result;
591 iris::ResourceReadResult result;
596 return result.data.at(0);
604 iris::ResourceWriteResult result;
621 if (res_id == iris::IRIS_UINT64_MAX)
623 iris::ResourceReadResult result;
625 return result.data.at(0);
631 iris::ResourceId res_id =
634 panic_if(res_id == iris::IRIS_UINT64_MAX,
635 "Int reg %d is not supported by fast model.", idx);
636 iris::ResourceWriteResult result;
645 iris::ResourceReadResult result;
647 return result.data.at(0);
654 "CC reg %d is not supported by fast model.", idx);
655 iris::ResourceWriteResult result;
672 iris::ResourceReadResult result;
674 size_t data_size = result.data.size() * (
sizeof(*result.data.data()));
675 size_t size = std::min(data_size,
reg.size());
676 memcpy(
reg.as<uint8_t>(), (
void *)result.data.data(), size);
698 iris::ResourceReadResult result;
702 size_t num_bits =
reg.NUM_BITS;
703 uint8_t *bytes = (uint8_t *)result.data.data();
704 while (num_bits > 8) {