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("../ETISS.ini"); // will be loaded within the run.sh
27 // iniFiles.push_back("additional.ini");
28 etiss::Initializer initializer(
29 argc, argv); // add &iniFiles as the first argument if .ini files are loaded explicitly here
30 bool quiet = etiss::cfg().get<bool>("vp.quiet", false);
31 if (!quiet)
32 std::cout << "=== Finished setting up configurations ===" << std::endl << std::endl;
33
34 if (!quiet)
35 std::cout << "=== Setting up test system ===" << std::endl;
36 if (!quiet)
37 std::cout << " Setting up Memory" << std::endl;
38
39 bool is_fault_injection = !(etiss::cfg().get<std::string>("faults.xml", "")).empty();
40
41 std::shared_ptr<etiss::SimpleMemSystem> dsys;
42 if (is_fault_injection)
43 {
44 dsys = std::make_shared<etiss::MemoryManipulationSystem>();
45 }
46 else
47 {
48 dsys = std::make_shared<etiss::SimpleMemSystem>();
49 }
50 dsys->init_memory();
51
52 if (!etiss::cfg().isSet("arch.cpu"))
53 {
54 std::cout << " CPU architecture was not set anywhere! Please set it manually using the arch.cpu configuration "
55 "option!";
56 return 3;
57 }
58
59 if (false)
60 {
61 std::list<etiss::uint32> instructions;
62 {
63 instructions.push_back(0x80b584b0); // push {r7, lr}, sub sp, #16
64 }
65 // write instructions into debug system
66 unsigned pos = 0;
67 for (auto it_instr : instructions)
68 {
69 etiss::uint8 buf[4];
70 buf[0] = it_instr >> 24;
71 buf[1] = it_instr >> 16;
72 buf[2] = it_instr >> 8;
73 buf[3] = it_instr;
74 dsys->dbg_write(pos, buf, 4);
75 pos += 4;
76 }
77 }
78
79 if (!quiet)
80 std::cout << " Setting up CPUCore" << std::endl;
81 // create a cpu core named core0 with the or1k architecture
82 std::string CPUArchName = etiss::cfg().get<std::string>("arch.cpu", "");
83 etiss::uint64 sa = etiss::cfg().get<uint64_t>("vp.entry_point", dsys->get_startaddr());
84 if (!quiet)
85 std::cout << " CPU start address: 0x" << std::hex << sa << std::dec << std::endl;
86
87 std::shared_ptr<etiss::CPUCore> cpu = etiss::CPUCore::create(CPUArchName, "core0");
88 if (!cpu)
89 {
90 etiss::log(etiss::FATALERROR, " Failed to create CPU core!");
91 }
92
93 // disable timer plugin
94 cpu->setTimer(false);
95
96 // reset CPU with a manual start address
97 cpu->reset(&sa);
98
99 // bind the cpu's VirtualStruct to etiss' root VirtualStruct and initialize faults
100 // if those where specified in config/cmdline
101 if (is_fault_injection)
102 {
103 dynamic_cast<etiss::MemoryManipulationSystem &>(*dsys).init_manipulation(cpu);
104
106 cpu,
107 [](const etiss::fault::Fault &fault, const etiss::fault::Action &action, std::string &errormsg)
108 {
109 auto cmd = action.getCommand();
110 std::cout << "custom command: " << cmd << std::endl;
111 return true;
112 });
113 }
114 else
115 {
117 }
118 if (!quiet)
119 std::cout << "=== Finished Setting up test system ===" << std::endl << std::endl;
120
121 if (!quiet)
122 std::cout << "=== Setting up plug-ins ===" << std::endl;
123
124 auto irq_handler = std::make_shared<etiss::InterruptHandler>(cpu->getInterruptVector(), cpu->getInterruptEnable(),
125 cpu->getArch(), etiss::LEVEL_TRIGGERED, false);
126 cpu->addPlugin(irq_handler);
127
128 initializer.loadIniPlugins(cpu);
129 initializer.loadIniJIT(cpu);
130 // here own developped plug-ins can be added with:
131 if (etiss::cfg().get<bool>("etiss.log_pc", false))
132 {
133 etiss::cfg().set<int>("etiss.max_block_size", 1);
134 cpu->addPlugin(std::make_shared<TracePrinter>(0x88888));
135 }
136
137 if (!quiet)
138 std::cout << "=== Setting up plug-ins ===" << std::endl << std::endl;
139
140 // Simulation start
141 if (!quiet)
142 std::cout << std::endl << "=== Simulation start ===" << std::endl;
143 // float startTime = (float)clock() / CLOCKS_PER_SEC; // TESTING
144 // run cpu with the SimpleMemSystem (in other cases that "system" is most likely a
145 // bus that connects the cpu to memory,periphery,etc)
146 etiss_int32 exception = cpu->execute(*dsys);
147 // float endTime = (float)clock() / CLOCKS_PER_SEC;
148 if (!quiet)
149 std::cout << "=== Simulation end ===" << std::endl << std::endl;
150
151 // print the exception code returned by the cpu core
152 if (!quiet)
153 std::cout << "CPU0 exited with exception: 0x" << std::hex << exception << std::dec << ": "
154 << etiss::RETURNCODE::getErrorMessages()[exception] << std::endl;
155
156 switch (exception)
157 {
158 case etiss::RETURNCODE::CPUFINISHED:
159 case etiss::RETURNCODE::NOERROR:
160 case etiss::RETURNCODE::CPUTERMINATED:
161 return 0;
162 break;
163 case etiss::RETURNCODE::DBUS_READ_ERROR:
164 case etiss::RETURNCODE::DBUS_WRITE_ERROR:
165 case etiss::RETURNCODE::IBUS_READ_ERROR:
166 case etiss::RETURNCODE::IBUS_WRITE_ERROR:
167 case etiss::RETURNCODE::INTERRUPT:
168 case etiss::RETURNCODE::RESET:
169 case etiss::RETURNCODE::ILLEGALINSTRUCTION:
170 case etiss::RETURNCODE::ILLEGALJUMP:
171 case etiss::RETURNCODE::INSTR_PAGEFAULT:
172 case etiss::RETURNCODE::LOAD_PAGEFAULT:
173 case etiss::RETURNCODE::STORE_PAGEFAULT:
174 case etiss::RETURNCODE::GDBNOERROR:
175 case etiss::RETURNCODE::SYSCALL:
176 case etiss::RETURNCODE::PAGEFAULT:
177 return 1;
178 break;
179 case etiss::RETURNCODE::JITERROR:
180 case etiss::RETURNCODE::JITCOMPILATIONERROR:
181 return 2;
182 break;
183 case etiss::RETURNCODE::GENERALERROR:
184 case etiss::RETURNCODE::RELOADBLOCKS:
185 case etiss::RETURNCODE::RELOADCURRENTBLOCK:
186 case etiss::RETURNCODE::BREAKPOINT:
187 case etiss::RETURNCODE::ARCHERROR:
188 case etiss::RETURNCODE::EMULATIONNOTSUPPORTED:
189 case etiss::RETURNCODE::INVALIDSYSTEM:
190 return 3;
191 break;
192 default:
193 return -1;
194 break;
195 }
196}
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:910
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