ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
System.cpp
Go to the documentation of this file.
1 
54 #include <stdlib.h>
55 
56 #include "etiss/System.h"
57 
59 {
60  return ((etiss::System *)handle)->iread(cpu, addr, length);
61 }
62 static etiss_int32 system_call_iwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer,
64 {
65  return ((etiss::System *)handle)->iwrite(cpu, addr, buffer, length);
66 }
67 
68 static etiss_int32 system_call_dread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer,
70 {
71  return ((etiss::System *)handle)->dread(cpu, addr, buffer, length);
72 }
73 static etiss_int32 system_call_dwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer,
75 {
76  return ((etiss::System *)handle)->dwrite(cpu, addr, buffer, length);
77 }
78 
80 {
81  return ((etiss::System *)handle)->dbg_read(addr, buffer, length);
82 }
83 
85 {
86  return ((etiss::System *)handle)->dbg_write(addr, buffer, length);
87 }
88 
89 static void system_call_syncTime(void *handle, ETISS_CPU *cpu)
90 {
91  ((etiss::System *)handle)->syncTime(cpu);
92 }
93 
94 std::shared_ptr<ETISS_System> etiss::wrap(etiss::System *sys)
95 {
96  if (sys == 0)
97  return 0;
98  ETISS_System *ret = new ETISS_System();
99 
100  ret->iread = &system_call_iread;
101  ret->iwrite = &system_call_iwrite;
102 
103  ret->dread = &system_call_dread;
104  ret->dwrite = &system_call_dwrite;
105 
108 
110 
111  ret->handle = (void *)sys;
112 
113  return std::shared_ptr<ETISS_System>(ret);
114 }
115 
116 #ifdef __cplusplus
117 extern "C"
118 {
119 #endif
121  {
122  return sys->iread != 0 && sys->iwrite != 0 && sys->dread != 0 && sys->dwrite != 0 && sys->syncTime != 0;
123  }
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 namespace etiss
130 {
131 
133 {
134  // disabled since this read function is only intended for timing purpose
135  // if (!read(false,cpu,addr,0,len))
136  // return IBUS_READ_ERROR;
137 
138  return 0;
139 }
141 {
142  if (!write(false, cpu, addr, buf, len))
143  return etiss::RETURNCODE::IBUS_WRITE_ERROR;
144 
145  return 0;
146 }
148 {
149  if (!read(false, cpu, addr, buf, len))
150  return etiss::RETURNCODE::DBUS_READ_ERROR;
151 
152  return 0;
153 }
155 {
156  if (!write(false, cpu, addr, buf, len))
157  return etiss::RETURNCODE::IBUS_WRITE_ERROR;
158 
159  return 0;
160 }
162 {
163  if (!read(true, 0, addr, buf, len))
164  return etiss::RETURNCODE::DBUS_READ_ERROR;
165 
166  return 0;
167 }
169 {
170  if (!write(true, 0, addr, buf, len))
171  return etiss::RETURNCODE::DBUS_WRITE_ERROR;
172 
173  return 0;
174 }
176 {
177  // NOP
178 }
180 {
181  // NOP
182  return 0;
183 }
184 } // namespace etiss
etiss_uint8 uint8
Definition: 386-GCC.h:76
etiss_int32 int32
Definition: 386-GCC.h:81
etiss_uint32 uint32
Definition: 386-GCC.h:80
etiss_uint64 uint64
Definition: 386-GCC.h:82
static void system_call_syncTime(void *handle, ETISS_CPU *cpu)
Definition: System.cpp:89
static etiss_int32 system_call_dbg_read(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
Definition: System.cpp:79
static etiss_int32 system_call_iread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint32 length)
Definition: System.cpp:58
static etiss_int32 system_call_dwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
Definition: System.cpp:73
static etiss_int32 system_call_dread(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
Definition: System.cpp:68
int ETISS_System_isvalid(ETISS_System *sys)
Definition: System.cpp:120
static etiss_int32 system_call_dbg_write(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
Definition: System.cpp:84
static etiss_int32 system_call_iwrite(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
Definition: System.cpp:62
struct ETISS_System ETISS_System
Definition: System.h:120
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
virtual etiss::int32 dread(ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
Data read operation.
Definition: System.cpp:147
virtual etiss::int32 dwrite(ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
Data write operation.
Definition: System.cpp:154
virtual etiss::int32 iread(ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint32 len)
Instruction read operation.
Definition: System.cpp:132
virtual bool write(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)=0
virtual etiss::int32 dbg_read(etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
Debug read operation.
Definition: System.cpp:161
virtual etiss::int32 dbg_write(etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
Debug write operation.
Definition: System.cpp:168
virtual bool read(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)=0
virtual etiss::int32 iwrite(ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
Instruction write operation.
Definition: System.cpp:140
virtual void syncTime(ETISS_CPU *cpu)
Synchronize simulation time.
Definition: System.cpp:175
System Interface for the basic system IO operations and time synchronization.
Definition: System.h:77
conatins a convinience class that can be wrapped as a ETISS_System structure
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
etiss::int32 dbg_print(etiss::uint32 reg)
Definition: System.cpp:179
std::shared_ptr< ETISS_System > wrap(etiss::System *sys)
wraps a etiss::System in a ETISS_System structure.
Definition: System.cpp:94
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
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
etiss_int32(* iread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint32 length)
used to simulate an instruction fetch.
Definition: System.h:84
void * handle
custom handle that will be passed to the functions of this structure
Definition: System.h:116
etiss_int32(* dbg_write)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug write
Definition: System.h:108
etiss_int32(* dbg_read)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug read
Definition: System.h:104
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition: System.h:93
void(* syncTime)(void *handle, ETISS_CPU *cpu)
called after a block to synchronize the time
Definition: System.h:114
etiss_int32(* iwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write instruction data over instruction bus
Definition: System.h:88