-
Notifications
You must be signed in to change notification settings - Fork 4
/
README.html
194 lines (145 loc) · 8.16 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<p>[This is Markdown format; README.html is auto-generated from this file.]</p>
<h1>The CSPIM MIPS simulator</h1>
<p>More details about this project can be found
<a href="http://zvrba.net/software/cspim.html">here.</a> Detailed description of CSPIM
internals as well as the motivation and possible use cases can be found in the
following publication:</p>
<p>Vrba, Z.; Halvorsen, P.; Griwodz, C., "Program obfuscation by strong
cryptography" The International Dependability Conference, 2010. ARES
'10. International Conference on, 15-18 February, 2010.
<a href="http://dx.doi.org/10.1109/ARES.2010.47">DOI:10.1109/ARES.2010.47</a></p>
<p>Copies of the paper are available on explicit request by email.</p>
<h1>COPYRIGHT NOTICE</h1>
<p>All files in this distribution, unless otherwise explicitly noted, are</p>
<ul>
<li>(c) 2008-2012 Zeljko Vrba <a href="mailto:zvrba.external@zvrba.net">zvrba.external@zvrba.net</a></li>
</ul>
<p>and are distributed under the following license:</p>
<blockquote>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.</p>
</blockquote>
<h1>Project structure</h1>
<p>The top-level directory contains the following subdirectories:</p>
<ul>
<li>bmips: precompiled programs for MIPS I; directly runnable by CSPIM</li>
<li>hostapps: host utilities [the interpreter itself]</li>
<li>mipsapps: source fof programs runnable by CSPIM; precompiled in <code>bmips</code></li>
<li>vm: core simulator: MIPS instruction set and ELF loader</li>
</ul>
<h1>How to build</h1>
<p>This package has been developed and tested with Solaris cc, gcc and Visual
Studio 2008. Prerequisites for building:</p>
<ul>
<li>Working native compiler. Solaris cc, gcc and Visual Studio 2008 have been
tested.</li>
<li>Working cross-compiler which can generate little-endian MIPS I ELF
executables. gcc 4.2.4 and binutils 2.22 have been tested.</li>
<li><a href="http://www.cmake.org">CMake</a></li>
</ul>
<p>The interpreter is built by executing</p>
<pre><code>cmake .
make
</code></pre>
<p>This will build host applicactions in <code>hostapps</code> and MIPS applications in
<code>mipsapps</code>. (Files in <code>bmips</code> directory are for reference only and are not
overwritten.)</p>
<h2>Host applications</h2>
<p>The following applications are built in <code>hostapps</code>:</p>
<ul>
<li><code>runtorture</code>: use to run the MIPS torture test</li>
<li><code>run</code>: use to run (possibly encrypted) MIPS executables</li>
<li><code>runbench</code>: use to run the MIPS benchmarks</li>
<li><code>elfcrpyt</code>: use to encrypt MIPS ELF executables</li>
</ul>
<p><code>sstep</code>, <code>hanoi-bench-native</code>, <code>mmult-bench-native</code> are benchmarking
applications; see the above paper for details. The "run" programs
take as parameter a MIPS ELF executable; an example invocation is
./hostapps/run ./mipsapps/hanoi
<code>runtorture</code> should only be used to run the <code>cputorture</code> program.</p>
<h2>MIPS CPU torture test</h2>
<p>Torture test assembly source is generated by preprocessing the <code>*.sm4</code> files
with M4:</p>
<pre><code>m4 cputorture.sm4 > cputorture.s
</code></pre>
<p>The pregenerated source is already provided in the distribution. The test
is run by executing</p>
<pre><code>./hostapps/runtorture ./mipsapps/cputorture
</code></pre>
<p>If the test is successfully passed, the last lines of the output will be
something like (note the <code>(near SUCCESS)</code> in the last line):</p>
<pre><code>finished: exception=5, code=0x0, last_branch=0x2e74(near t_link)
***MIPS@0xb7c6b008***
BASE=200000@0xb7c6b008 BRK=00003fd0 STKSZ=00004000
R00=00000000 R01=00000000 R02=00000000 R03=0000000c
R04=00000001 R05=00005678 R06=00005678 R07=00001234
R08=00001234 R09=0000e7f8 R10=0000e7f8 R11=0000c5d6
R12=0000c5d6 R13=12345678 R14=12345678 R15=c5d6e7f8
R16=c5d6e7f8 R17=56787800 R18=56787800 R19=12345678
R20=12345678 R21=00001234 R22=ffffe7f8 R23=00000000
R24=90000000 R25=f0000000 R26=00003fc0 R27=00003fc4
R28=00003fc0 R29=00003fc4 R30=00003fc8 R31=00002fa0
HI =12345678 LO =9abcdef0
PC =00002fb0 DS =00000000
(near SUCCESS)
</code></pre>
<p>If the execution stops at a label name other than <code>SUCCESS</code> in the last line,
something has gone wrong and the preceding output can be determined to find
out what.</p>
<h2>MIPS applications</h2>
<p>Many of the other example problems are are solved assignments (in C) from
Appendix of the third edition of Hennessy & Patterson, Computer Organization
and Design: The Hardware/Software Interface; available at. This appendix is
also available online <a href="http://pages.cs.wisc.edu/~larus/HP_AppA.pdf">here.</a>
These programs should be executed with <code>./hostapps/run program</code>.</p>
<h2>Encrypted execution</h2>
<p>All LOAD ELF segments of executables can be encrypted with RC-5 encryption
algorithm using 32-bit block size and 128-bit key. The encryption uses ECB
mode, which should <em>not be used for anything but simple demos</em>! Example
session:</p>
<pre><code>./hostapps/elfcrypt mipsapps/hanoi /tmp/hanoi-crypt 0123456789ABCDEF0123456789ABCDEF
./hostapps/run /tmp/hanoi-crypt 0123456789ABCDEF0123456789ABCDEF
</code></pre>
<p>Failing to provide the key in the last command will terminate execution with
exception 3 (invalid instruction).</p>
<h2>Self-simulation</h2>
<p>Compile both HOSTED and non-HOSTED build (configure this by using <code>ccmake</code>).
This must be done in two separate build directories; note that cmake supports
builds in directories other than the source directory (so-called
"out-of-source build"). This builds an extra executable,
<code>./mipsapps/run-lvl1</code>, which should be run with <code>./hostapps/load-lvl1</code>.
<code>./run-lvl1</code> can currently only run cputorture, since the nested simulation
does not yet forward system calls to the outer simulation.</p>
<p>NOTE: You need to remove all files previously generated by CMake for
out-of-source build to work.</p>
<p>Suppose that the hosted interpreter has been built in the <code>./HH</code> directory,
and the non-hosted in the <code>./NH</code> directory. Then the CPU torture test can
be run in the nested simulation with the following command:</p>
<pre><code>./HH/hostapps/load-lvl1 ./NH/mipsapps/run-lvl1 ./NH/mipsapps/cputorture
</code></pre>
<h2>Building cross-gcc</h2>
<p>Note that gcc 4.2.x is the highest gcc version that doesn't require GMP, MPFR
and MPC libraries, which significantly eases installation.</p>
<ol>
<li><p>Download and build binutils (tested with version 2.22).
Configure and build as:</p>
<p><code>./configure --prefix=$HOME --disable-debug --disable-nls --target=mipsel-elf</code>
<code>make install</code></p></li>
<li><p>Download and build gcc; it MUST NOT be built in the source dir (hence ../).
Make sure that the installed binutils (mipsel-elf-as etc.) are in PATH.</p>
<p><code>../gcc-4.2.4/configure --prefix=$HOME --disable-debug --disable-nls --target=mipsel-elf --disable-bootstrap --disable-libssp</code></p>
<p><code>make install</code></p></li>
</ol>