ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
MemMappedPeriph.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
8#include "etiss/jit/ReturnCode.h"
9
10namespace etiss
11{
12namespace plugin
13{
14
15etiss_int32 dread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buf, etiss_uint32 len)
16{
17 auto customH = (MemMappedPeriph::CustomHandle *)handle;
18 if (addr < customH->base || addr >= customH->end)
19 {
20 return customH->origSys->dread(customH->origSys->handle, cpu, addr, buf, len);
21 }
22
23 switch (len)
24 {
25 case 1:
26 *buf = customH->mmp->read8(addr);
27 break;
28 case 2:
29 *(etiss_uint16 *)buf = customH->mmp->read16(addr);
30 break;
31 case 4:
32 *(etiss_uint32 *)buf = customH->mmp->read32(addr);
33 break;
34 case 8:
35 *(etiss_uint64 *)buf = customH->mmp->read64(addr);
36 break;
37 default:
38 etiss::log(etiss::WARNING, "Ignored access to MemMappedPeriph because of unusual size");
39 }
40
41 return ETISS_RETURNCODE_NOERROR;
42}
43
45{
46 auto customH = (MemMappedPeriph::CustomHandle *)handle;
47 if (addr < customH->base || addr >= customH->end)
48 {
49 return customH->origSys->dwrite(customH->origSys->handle, cpu, addr, buf, len);
50 }
51
52 switch (len)
53 {
54 case 1:
55 customH->mmp->write8(addr, *buf);
56 break;
57 case 2:
58 customH->mmp->write16(addr, *(etiss_uint16 *)buf);
59 break;
60 case 4:
61 customH->mmp->write32(addr, *(etiss_uint32 *)buf);
62 break;
63 case 8:
64 customH->mmp->write64(addr, *(etiss_uint64 *)buf);
65 break;
66 default:
67 etiss::log(etiss::WARNING, "Ignored access to MemMappedPeriph because of unusual size");
68 }
69
70 return ETISS_RETURNCODE_NOERROR;
71}
72
74{
75 customHandle_.origSys = origSystem;
76 customHandle_.mmp = this;
77
78 auto mm = getMappedMem();
79 customHandle_.base = mm.base;
80 customHandle_.end = mm.base + mm.size;
81
82 ETISS_System wrapInfo = {};
83 wrapInfo.handle = &customHandle_;
84 wrapInfo.dread = &dread;
85 wrapInfo.dwrite = &dwrite;
86 return wrapInfo;
87}
88
89} // namespace plugin
90} // namespace etiss
uint64_t etiss_uint64
Definition types.h:58
uint32_t etiss_uint32
Definition types.h:55
uint8_t etiss_uint8
Definition types.h:49
int32_t etiss_int32
Definition types.h:54
uint16_t etiss_uint16
Definition types.h:52
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)
forwards: include/jit/*
Definition Benchmark.h:17
@ WARNING
Definition Misc.h:86
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
memory access and time synchronization functions.
Definition System.h:40
etiss_int32(* dwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write data
Definition System.h:59
void * handle
custom handle that will be passed to the functions of this structure
Definition System.h:78
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition System.h:55