ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
main.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
7#include "TracePrinter.h"
10#include "etiss/fault/Action.h"
11#include "etiss/ETISS.h"
12#include "etiss/CPUCore.h"
14
15int main(int argc, const char *argv[])
16{
17 // by default etiss wil search for plugin libraries in its install path and
18 // relative to the library using the file plugins/list.txt.
19 // For loading configurations and ETISS internal plug-ins you can add a list
20 // with .ini file to the Initializer. See ETISS.ini for more details. Ini
21 // files and All configurations can be set with program arguments, too. E.g.:
22 // ./main [-o<option> <value>] [-f[no]<flag>] [-i<additionalinifile>]
23 // All arguments with this format will be evaluated by the Initializer.
24 std::cout << "=== Setting up configurations ===" << std::endl;
25 // std::list<std::string> iniFiles;
26 // iniFiles.push_back("additional.ini");
27 etiss::Initializer initializer(
28 argc, argv); // add &iniFiles as the first argument if .ini files are loaded explicitly here
29 bool quiet = etiss::cfg().get<bool>("vp.quiet", false);
30 if (!quiet)
31 std::cout << "=== Finished setting up configurations ===" << std::endl << std::endl;
32
33 if (!quiet)
34 std::cout << "=== Setting up test system ===" << std::endl;
35 if (!quiet)
36 std::cout << " Setting up Memory" << std::endl;
37
38 bool is_fault_injection = !(etiss::cfg().get<std::string>("faults.xml", "")).empty();
39
40 std::shared_ptr<etiss::SimpleMemSystem> dsys;
41 if (is_fault_injection)
42 {
43 dsys = std::make_shared<etiss::MemoryManipulationSystem>();
44 }
45 else
46 {
47 dsys = std::make_shared<etiss::SimpleMemSystem>();
48 }
49 dsys->init_memory();
50
51 if (!etiss::cfg().isSet("arch.cpu"))
52 {
53 std::cout << " CPU architecture was not set anywhere! Please set it manually using the arch.cpu configuration "
54 "option!";
55 return 3;
56 }
57
58 if (false)
59 {
60 std::list<etiss::uint32> instructions;
61 {
62 instructions.push_back(0x80b584b0); // push {r7, lr}, sub sp, #16
63 }
64 // write instructions into debug system
65 unsigned pos = 0;
66 for (auto it_instr : instructions)
67 {
68 etiss::uint8 buf[4];
69 buf[0] = it_instr >> 24;
70 buf[1] = it_instr >> 16;
71 buf[2] = it_instr >> 8;
72 buf[3] = it_instr;
73 dsys->dbg_write(pos, buf, 4);
74 pos += 4;
75 }
76 }
77
78 if (!quiet)
79 std::cout << " Setting up CPUCore" << std::endl;
80 // create a cpu core named core0 with the or1k architecture
81 std::string CPUArchName = etiss::cfg().get<std::string>("arch.cpu", "");
82 etiss::uint64 sa = etiss::cfg().get<uint64_t>("vp.entry_point", dsys->get_startaddr());
83 if (!quiet)
84 std::cout << " CPU start address: 0x" << std::hex << sa << std::dec << std::endl;
85
86 std::shared_ptr<etiss::CPUCore> cpu = etiss::CPUCore::create(CPUArchName, "core0");
87 if (!cpu)
88 {
89 etiss::log(etiss::FATALERROR, " Failed to create CPU core!");
90 }
91
92 // disable timer plugin
93 cpu->setTimer(false);
94
95 // reset CPU with a manual start address
96 cpu->reset(&sa);
97
98 // bind the cpu's VirtualStruct to etiss' root VirtualStruct and initialize faults
99 // if those where specified in config/cmdline
100 if (is_fault_injection)
101 {
102 dynamic_cast<etiss::MemoryManipulationSystem &>(*dsys).init_manipulation(cpu);
103
105 cpu,
106 [](const etiss::fault::Fault &fault, const etiss::fault::Action &action, std::string &errormsg)
107 {
108 auto cmd = action.getCommand();
109 std::cout << "custom command: " << cmd << std::endl;
110 return true;
111 });
112 }
113 else
114 {
116 }
117 if (!quiet)
118 std::cout << "=== Finished Setting up test system ===" << std::endl << std::endl;
119
120 if (!quiet)
121 std::cout << "=== Setting up plug-ins ===" << std::endl;
122
123 bool enable_irq_handler = etiss::cfg().get<bool>("vp.enable_irq_handler", true);
124 if (enable_irq_handler)
125 {
126 auto irq_handler = std::make_shared<etiss::InterruptHandler>(
127 cpu->getInterruptVector(), cpu->getInterruptEnable(), cpu->getArch(), etiss::LEVEL_TRIGGERED, false);
128 cpu->addPlugin(irq_handler);
129 }
130
131 initializer.loadIniPlugins(cpu);
132 initializer.loadIniJIT(cpu);
133 // here own developped plug-ins can be added with:
134 if (etiss::cfg().get<bool>("etiss.log_pc", false))
135 {
136 etiss::cfg().set<int>("etiss.max_block_size", 1);
137 cpu->addPlugin(std::make_shared<TracePrinter>(0x88888));
138 }
139
140 if (!quiet)
141 std::cout << "=== Setting up plug-ins ===" << std::endl << std::endl;
142
143 // Simulation start
144 if (!quiet)
145 std::cout << std::endl << "=== Simulation start ===" << std::endl;
146 // float startTime = (float)clock() / CLOCKS_PER_SEC; // TESTING
147 // run cpu with the SimpleMemSystem (in other cases that "system" is most likely a
148 // bus that connects the cpu to memory,periphery,etc)
149 etiss_int32 exception = cpu->execute(*dsys);
150 // float endTime = (float)clock() / CLOCKS_PER_SEC;
151 if (!quiet)
152 std::cout << "=== Simulation end ===" << std::endl << std::endl;
153
154 // print the exception code returned by the cpu core
155 if (!quiet)
156 std::cout << "CPU0 exited with exception: 0x" << std::hex << exception << std::dec << ": "
157 << etiss::RETURNCODE::getErrorMessages()[exception] << std::endl;
158
159 switch (exception)
160 {
161 case etiss::RETURNCODE::CPUFINISHED:
162 case etiss::RETURNCODE::NOERROR:
163 case etiss::RETURNCODE::CPUTERMINATED:
164 return 0;
165 break;
166 case etiss::RETURNCODE::DBUS_READ_ERROR:
167 case etiss::RETURNCODE::DBUS_WRITE_ERROR:
168 case etiss::RETURNCODE::IBUS_READ_ERROR:
169 case etiss::RETURNCODE::IBUS_WRITE_ERROR:
170 case etiss::RETURNCODE::INTERRUPT:
171 case etiss::RETURNCODE::RESET:
172 case etiss::RETURNCODE::ILLEGALINSTRUCTION:
173 case etiss::RETURNCODE::ILLEGALJUMP:
174 case etiss::RETURNCODE::INSTR_PAGEFAULT:
175 case etiss::RETURNCODE::LOAD_PAGEFAULT:
176 case etiss::RETURNCODE::STORE_PAGEFAULT:
177 case etiss::RETURNCODE::GDBNOERROR:
178 case etiss::RETURNCODE::SYSCALL:
179 case etiss::RETURNCODE::PAGEFAULT:
180 return 1;
181 break;
182 case etiss::RETURNCODE::JITERROR:
183 case etiss::RETURNCODE::JITCOMPILATIONERROR:
184 return 2;
185 break;
186 case etiss::RETURNCODE::GENERALERROR:
187 case etiss::RETURNCODE::RELOADBLOCKS:
188 case etiss::RETURNCODE::RELOADCURRENTBLOCK:
189 case etiss::RETURNCODE::BREAKPOINT:
190 case etiss::RETURNCODE::ARCHERROR:
191 case etiss::RETURNCODE::EMULATIONNOTSUPPORTED:
192 case etiss::RETURNCODE::INVALIDSYSTEM:
193 return 3;
194 break;
195 default:
196 return -1;
197 break;
198 }
199}
contains an action class that describes actions associated with a fault
defines main cpu core interface
Header file of the ETISS library.
interrupt checking and signaling
simple test system implementation with fault functionality
simple test system implementation
static __inline__ uint64_t
Definition arm_cde.h:31
int32_t etiss_int32
Definition types.h:54
static std::shared_ptr< CPUCore > create(std::string archname, std::string instancename="", std::map< std::string, std::string > archoptions=std::map< std::string, std::string >())
Create a CPUCore instance.
Definition CPUCore.cpp:234
bool set(const std::string &key, T value)
template function to set the value of a configuration key.
Definition Misc.h:335
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Definition Misc.h:312
Wrapper for the initialize and shutdown of the ETISS environment.
Definition ETISS.h:234
void loadIniPlugins(std::shared_ptr< etiss::CPUCore > cpu)
loads the plugins given with the previous loaded .ini files
Definition ETISS.cpp:548
void loadIniJIT(std::shared_ptr< etiss::CPUCore > cpu)
sets the JIT given with the previous loaded .ini files
Definition ETISS.cpp:663
Simple etiss:System implementation for testing.
void init_manipulation(std::shared_ptr< etiss::VirtualStructSupport > vs_parent)
initialize this virtual struct and mount it to cpu_core
const std::string & getCommand() const
COMMAND only.
Definition Action.cpp:155
void initialize_virtualstruct(std::shared_ptr< etiss::CPUCore > cpu_core)
Initialize and configure etiss::VirtualStruct root with etiss::CPUCore cpu_core.
Definition ETISS.cpp:911
int main(int argc, const char *argv[])
Definition main.cpp:15
@ FATALERROR
Definition Misc.h:84
Configuration & cfg()
Definition Misc.cpp:548
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94