52 #include "iris/detail/IrisCppAdapter.h"
53 #include "iris/detail/IrisObjects.h"
81 iris::EventSourceInfo evSrcInfo;
83 client.registerEventCallback<Self, &Self::breakpointHit>(
84 this,
"ec_IRIS_BREAKPOINT_HIT",
85 "Handle hitting a breakpoint",
"Iris::ThreadContext");
86 call().event_getEventSource(
_instId, evSrcInfo,
"IRIS_BREAKPOINT_HIT");
88 evSrcInfo.evSrcId,
client.getInstId());
90 for (
auto it =
bps.begin(); it !=
bps.end(); it++)
93 client.registerEventCallback<Self, &Self::semihostingEvent>(
94 this,
"ec_IRIS_SEMIHOSTING_CALL_EXTENSION",
95 "Handle a semihosting call",
"Iris::ThreadContext");
97 "IRIS_SEMIHOSTING_CALL_EXTENSION");
99 evSrcInfo.evSrcId,
client.getInstId(),
102 nullptr,
"",
false, 0,
nullptr,
false,
false,
true);
109 return resources.at(
name).rscId;
117 for (
const auto &idx_name: idx_names) {
118 int idx = idx_name.first;
119 const std::string &
name = idx_name.second;
121 if (idx >=
ids.size())
122 ids.resize(idx + 1, iris::IRIS_UINT64_MAX);
132 return it ==
memorySpaceIds.end() ? iris::IRIS_UINT64_MAX : it->second;
158 Tick remaining = next - now;
159 call().step_setup(
_instId, remaining,
"instruction");
167 auto pc_it =
bps.find(
pc);
169 if (pc_it !=
bps.end())
173 panic_if(!res.second,
"Inserting breakpoint failed.");
182 for (
auto sid: space_ids) {
185 it->second->ids.push_back(
id);
192 for (
auto id: it->second->ids)
194 it->second->clearIds();
201 "BP info still had events associated with it.");
203 if (it->second->validIds())
211 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
212 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
214 const std::string &
event = fields.at(
"EVENT").getString();
215 const iris::InstanceId
id = fields.at(
"INST_ID").getU64();
216 const std::string &
name = fields.at(
"INST_NAME").getString();
221 if (
event ==
"added")
223 else if (
event ==
"removed")
224 _instId = iris::IRIS_UINT64_MAX;
233 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
234 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
239 std::map<iris::ResourceId, const iris::ResourceInfo *>
241 for (
const auto &resource: resources) {
242 idToResource[resource.rscId] = &resource;
245 for (
const auto &resource: resources) {
246 std::string
name = resource.name;
247 iris::ResourceId parentId = resource.parentRscId;
248 while (parentId != iris::IRIS_UINT64_MAX) {
249 const auto *parent = idToResource[parentId];
251 parentId = parent->parentRscId;
253 resourceMap[
name] = resource;
263 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
264 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
266 if (fields.at(
"RUNNING").getAsBool()) {
278 call().simulationTime_run(iris::IrisInstIdSimulationEngine);
285 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
286 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
288 Addr pc = fields.at(
"PC").getU64();
292 std::shared_ptr<BpInfo::EventList> events = it->second->events;
293 auto e_it = events->begin();
294 while (e_it != events->end()) {
306 uint64_t esId,
const iris::IrisValueMap &fields, uint64_t time,
307 uint64_t sInstId,
bool syncEc, std::string &error_message_out)
312 call().perInstanceExecution_setState(
_instId,
false);
328 BaseISA *isa, iris::IrisConnectionInterface *iris_if,
329 const std::string &iris_path) :
330 _cpu(cpu), _threadId(
id), _system(
system), _mmu(mmu), _isa(isa),
331 _irisPath(iris_path), vecRegs(ArmISA::
NumVecRegs),
333 comInstEventQueue(
"instruction-based event queue"),
334 client(iris_if,
"client." + iris_path)
336 iris::InstanceInfo info;
337 auto ret_code =
noThrow().instanceRegistry_getInstanceInfoByName(
338 info,
"component." + iris_path);
339 if (ret_code == iris::E_ok) {
344 _instId = iris::IRIS_UINT64_MAX;
348 iris::EventSourceInfo evSrcInfo;
350 client.registerEventCallback<Self, &Self::instanceRegistryChanged>(
351 this,
"ec_IRIS_INSTANCE_REGISTRY_CHANGED",
352 "Install the iris instance ID",
"Iris::ThreadContext");
353 call().event_getEventSource(iris::IrisInstIdGlobalInstance, evSrcInfo,
354 "IRIS_INSTANCE_REGISTRY_CHANGED");
357 {
"EVENT",
"INST_ID",
"INST_NAME" };
359 evSrcInfo.evSrcId,
client.getInstId(), &fields);
361 client.registerEventCallback<Self, &Self::phaseInitLeave>(
362 this,
"ec_IRIS_SIM_PHASE_INIT_LEAVE",
363 "Initialize register contexts",
"Iris::ThreadContext");
364 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
365 "IRIS_SIM_PHASE_INIT_LEAVE");
367 call().eventStream_create(
369 evSrcInfo.evSrcId,
client.getInstId());
371 client.registerEventCallback<Self, &Self::simulationTimeEvent>(
372 this,
"ec_IRIS_SIMULATION_TIME_EVENT",
373 "Handle simulation time stopping for breakpoints or stepping",
374 "Iris::ThreadContext");
375 call().event_getEventSource(iris::IrisInstIdSimulationEngine, evSrcInfo,
376 "IRIS_SIMULATION_TIME_EVENT");
378 call().eventStream_create(
380 evSrcInfo.evSrcId,
client.getInstId());
385 auto enable_lambda = [
this]{
386 call().perInstanceExecution_setState(
_instId,
true);
389 enable_lambda,
"resume after pseudo inst",
395 call().eventStream_destroy(
398 client.unregisterEventCallback(
"ec_IRIS_SIM_PHASE_INIT_LEAVE");
400 call().eventStream_destroy(
403 client.unregisterEventCallback(
"ec_IRIS_INSTANCE_REGISTRY_CHANGED");
405 call().eventStream_destroy(
408 client.unregisterEventCallback(
"ec_IRIS_SIMULATION_TIME_EVENT");
419 it->second->events->push_back(
e);
421 if (
_instId != iris::IRIS_UINT64_MAX && !it->second->validIds())
431 it->second->events->remove(
e);
433 if (it->second->empty())
441 iris::MemorySpaceId space,
Addr addr,
void *
p,
size_t size)
443 iris::r0master::MemoryReadResult
r;
445 panic_if(
err != iris::r0master::E_ok,
"readMem failed.");
446 std::memcpy(
p,
r.data.data(), size);
451 iris::MemorySpaceId space,
Addr addr,
const void *
p,
size_t size)
454 std::memcpy(
data.data(),
p, size);
455 iris::MemoryWriteResult
r;
457 panic_if(
err != iris::r0master::E_ok,
"writeMem failed.");
464 iris::MemoryAddressTranslationResult result;
465 auto ret =
noThrow().memory_translateAddress(
468 if (ret != iris::E_ok) {
472 if (trans.inSpaceId == v_space && trans.outSpaceId == p_space)
475 panic(
"No legal translation IRIS address translation found.");
478 if (result.address.empty())
481 if (result.address.size() > 1) {
482 warn(
"Multiple mappings for address %#x.",
vaddr);
486 paddr = result.address[0];
496 call().simulationTime_stop(iris::IrisInstIdSimulationEngine);
513 panic_if(ret != iris::E_ok,
"Failed to get instruction count.");
546 if (new_status ==
Active) {
548 call().perInstanceExecution_setState(
_instId,
true);
551 call().perInstanceExecution_setState(
_instId,
false);
562 pc.nextThumb(
pc.thumb());
564 pc.nextJazelle(cpsr.j);
565 pc.aarch64(!cpsr.width);
566 pc.nextAArch64(!cpsr.width);
567 pc.illegalExec(
false);
571 iris::ResourceReadResult result;
574 if (cpsr.width && cpsr.t)
586 if (cpsr.width && cpsr.t)
589 iris::ResourceWriteResult result;
596 iris::ResourceReadResult result;
598 return result.data.at(0);
604 iris::ResourceWriteResult result;
613 iris::ResourceReadResult result;
618 return result.data.at(0);
626 iris::ResourceWriteResult result;
643 if (res_id == iris::IRIS_UINT64_MAX)
645 iris::ResourceReadResult result;
647 return result.data.at(0);
653 iris::ResourceId res_id =
656 panic_if(res_id == iris::IRIS_UINT64_MAX,
657 "Int reg %d is not supported by fast model.", idx);
658 iris::ResourceWriteResult result;
667 iris::ResourceReadResult result;
669 return result.data.at(0);
676 "CC reg %d is not supported by fast model.", idx);
677 iris::ResourceWriteResult result;
694 iris::ResourceReadResult result;
696 size_t data_size = result.data.size() * (
sizeof(*result.data.data()));
697 size_t size = std::min(data_size,
reg.size());
698 memcpy(
reg.as<uint8_t>(), (
void *)result.data.data(), size);
720 iris::ResourceReadResult result;
724 size_t num_bits =
reg.NUM_BITS;
725 uint8_t *bytes = (uint8_t *)result.data.data();
726 while (num_bits > 8) {