ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
MemMappedPeriph.cpp
Go to the documentation of this file.
2 #include "etiss/jit/ReturnCode.h"
3 
4 namespace etiss
5 {
6 namespace plugin
7 {
8 
9 etiss_int32 dread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
10 {
11  auto customH = (MemMappedPeriph::CustomHandle *)handle;
12  if (addr < customH->base || addr >= customH->end)
13  {
14  return customH->origSys->dread(customH->origSys->handle, cpu, addr, buf, len);
15  }
16 
17  switch (len)
18  {
19  case 1:
20  *buf = customH->mmp->read8(addr);
21  break;
22  case 2:
23  *(etiss_uint16 *)buf = customH->mmp->read16(addr);
24  break;
25  case 4:
26  *(etiss_uint32 *)buf = customH->mmp->read32(addr);
27  break;
28  case 8:
29  *(etiss_uint64 *)buf = customH->mmp->read64(addr);
30  break;
31  default:
32  etiss::log(etiss::WARNING, "Ignored access to MemMappedPeriph because of unusual size");
33  }
34 
35  return ETISS_RETURNCODE_NOERROR;
36 }
37 
38 etiss_int32 dwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
39 {
40  auto customH = (MemMappedPeriph::CustomHandle *)handle;
41  if (addr < customH->base || addr >= customH->end)
42  {
43  return customH->origSys->dwrite(customH->origSys->handle, cpu, addr, buf, len);
44  }
45 
46  switch (len)
47  {
48  case 1:
49  customH->mmp->write8(addr, *buf);
50  break;
51  case 2:
52  customH->mmp->write16(addr, *(etiss_uint16 *)buf);
53  break;
54  case 4:
55  customH->mmp->write32(addr, *(etiss_uint32 *)buf);
56  break;
57  case 8:
58  customH->mmp->write64(addr, *(etiss_uint64 *)buf);
59  break;
60  default:
61  etiss::log(etiss::WARNING, "Ignored access to MemMappedPeriph because of unusual size");
62  }
63 
64  return ETISS_RETURNCODE_NOERROR;
65 }
66 
68 {
69  customHandle_.origSys = origSystem;
70  customHandle_.mmp = this;
71 
72  auto mm = getMappedMem();
73  customHandle_.base = mm.base;
74  customHandle_.end = mm.base + mm.size;
75 
76  ETISS_System wrapInfo = {};
77  wrapInfo.handle = &customHandle_;
78  wrapInfo.dread = &dread;
79  wrapInfo.dwrite = &dwrite;
80  return wrapInfo;
81 }
82 
83 } // namespace plugin
84 } // namespace etiss
uint64_t etiss_uint64
Definition: types.h:96
uint32_t etiss_uint32
Definition: types.h:93
uint8_t etiss_uint8
Definition: types.h:87
int32_t etiss_int32
Definition: types.h:92
uint16_t etiss_uint16
Definition: types.h:90
virtual MappedMemory getMappedMem() const =0
Defines in which memory region to map this peripheral.
ETISS_System getWrapInfo(ETISS_System *origSystem) final
Defines which System functions to wrap.
etiss_int32 dread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
etiss_int32 dwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ WARNING
Definition: Misc.h:128
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125
basic cpu state structure needed for execution of any cpu architecture.
Definition: CPU.h:89
memory access and time synchronization functions.
Definition: System.h:78
etiss_int32(* dwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write data
Definition: System.h:97
void * handle
custom handle that will be passed to the functions of this structure
Definition: System.h:116
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition: System.h:93