1 |
<html> |
<html><head><title>Gavare's eXperimental Emulator: Introduction</title> |
2 |
<head><title>GXemul documentation: Introduction</title> |
<meta name="robots" content="noarchive,nofollow,noindex"></head> |
3 |
</head> |
<body bgcolor="#f8f8f8" text="#000000" link="#4040f0" vlink="#404040" alink="#ff0000"> |
4 |
<body bgcolor="#ffffff" text="#000000" link="#4040f0" vlink="#404040" alink="#ff0000"> |
<table border=0 width=100% bgcolor="#d0d0d0"><tr> |
5 |
<p> |
<td width=100% align=center valign=center><table border=0 width=100%><tr> |
6 |
<table width="100%"> |
<td align="left" valign=center bgcolor="#d0efff"><font color="#6060e0" size="6"> |
7 |
<tr><td width="100%" bgcolor="#808070"><font color="#ffffe0" size="6"> |
<b>Gavare's eXperimental Emulator:</b></font><br> |
8 |
<b>GXemul documentation: Introduction</b></font></td></tr> |
<font color="#000000" size="6"><b>Introduction</b> |
9 |
</table> |
</font></td></tr></table></td></tr></table><p> |
|
<p> |
|
|
<!-- The first 10 lines are cut away by the homepage updating script. --> |
|
|
|
|
10 |
|
|
11 |
<!-- |
<!-- |
12 |
|
|
13 |
$Id: intro.html,v 1.30 2005/04/07 15:43:15 debug Exp $ |
$Id: intro.html,v 1.88 2006/06/27 05:25:46 debug Exp $ |
14 |
|
|
15 |
Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
Copyright (C) 2003-2006 Anders Gavare. All rights reserved. |
16 |
|
|
17 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
18 |
modification, are permitted provided that the following conditions are met: |
modification, are permitted provided that the following conditions are met: |
45 |
<h2>Introduction</h2> |
<h2>Introduction</h2> |
46 |
|
|
47 |
<p> |
<p> |
48 |
|
<table border="0" width="99%"><tr><td valign="top" align="left"> |
49 |
<ul> |
<ul> |
50 |
<li><a href="#overview">Overview</a> |
<li><a href="#overview">Overview</a> |
51 |
<li><a href="#free">Is GXemul free software?</a> |
<li><a href="#free">Is GXemul Free software?</a> |
52 |
<li><a href="#build">How to compile/build the emulator</a> |
<li><a href="#build">How to compile/build the emulator</a> |
53 |
<li><a href="#cpus">Which CPU types does GXemul emulate?</a> |
<li><a href="#run">How to run the emulator</a> |
54 |
|
<li><a href="#cpus">Which processor architectures does GXemul emulate?</a> |
55 |
|
<li><a href="#hosts">Which host architectures are supported?</a> |
56 |
|
<li><a href="#translation">What kind of translation does GXemul use?</a> |
57 |
<li><a href="#accuracy">Emulation accuracy</a> |
<li><a href="#accuracy">Emulation accuracy</a> |
58 |
<li><a href="#emulmodes">Which machines does GXemul emulate?</a> |
<li><a href="#emulmodes">Which machines does GXemul emulate?</a> |
|
<li><a href="#guestos">Which guest OSes are possible to run?</a> |
|
59 |
</ul> |
</ul> |
60 |
|
</td><td valign="center" align="center"> |
61 |
|
<a href="20050317-example.png"><img src="20050317-example_small.png"></a> |
62 |
|
<p>NetBSD/pmax 1.6.2 with X11<br>running in GXemul</td></tr></table> |
63 |
|
|
64 |
|
|
65 |
|
|
68 |
<a name="overview"></a> |
<a name="overview"></a> |
69 |
<h3>Overview:</h3> |
<h3>Overview:</h3> |
70 |
|
|
71 |
GXemul is a machine emulator, which can be used to experiment with |
GXemul is an experimental instruction-level machine emulator. Several |
72 |
binary code for (among others) MIPS-based machines. Several emulation |
emulation modes are available. In some modes, processors and surrounding |
|
modes are available. For some emulation modes, processors and surrounding |
|
73 |
hardware components are emulated well enough to let unmodified operating |
hardware components are emulated well enough to let unmodified operating |
74 |
systems run as if they were running on a real machine. |
systems (e.g. NetBSD) run as if they were running on a real machine. |
75 |
|
|
76 |
<p> |
<p>Devices and processors (ARM, MIPS, PowerPC) are not simulated with 100% |
77 |
It is important to keep in mind that devices and CPUs are not really |
accuracy. They are only ``faked'' well enough to allow guest operating |
78 |
emulated correctly, they are only "faked" well enough to make eg. NetBSD |
systems run without complaining too much. Still, the emulator could be of |
79 |
run. Still, the emulator could be of interest for academic research and |
interest for academic research and experiments, such as when learning how |
80 |
experiments, such as when learning how to write an OS for a real machine, |
to write operating system code. |
81 |
or profiling SMP, memory, or system call usage. |
|
82 |
|
<p>The emulator is written in C, does not depend on third-party libraries, |
83 |
|
and should compile and run on most 64-bit and 32-bit Unix-like systems. |
84 |
|
|
85 |
|
<p>The emulator contains code which tries to emulate the workings of CPUs |
86 |
|
and surrounding hardware found in real machines, but it does not contain |
87 |
|
any ROM code. You will need some form of program (in binary form) to run |
88 |
|
in the emulator. For many emulation modes, PROM calls are handled by the |
89 |
|
emulator itself, so you do not need to use any ROM image at all. |
90 |
|
|
91 |
<p> |
<p>You can use pre-compiled kernels (for example NetBSD kernels, or |
92 |
The emulator is written in C, does not depend on external libraries (except |
Linux), or other programs that are in binary format, and in some cases |
93 |
X11, but that is optional), and should compile and run on most Unix-like |
even actual ROM images. A couple of different file formats are supported |
94 |
systems. If it doesn't, then that is a bug. |
(ELF, a.out, ECOFF, SREC, and raw binaries). |
95 |
|
|
96 |
|
<p>If you do not have a kernel as a separate file, but you have a bootable |
97 |
|
disk image, then it is sometimes possible to boot directly from that |
98 |
|
image. (This works for example with DECstation emulation, or when booting |
99 |
|
from ISO9660 CDROM images.) |
100 |
|
|
|
<p> |
|
|
The emulator contains code which tries to emulate the workings of CPUs and |
|
|
surrounding hardware found in real machines, but it does not contain any |
|
|
ROM code. You will need some form of program (in binary form) to run in |
|
|
the emulator. For many emulation modes, PROM calls are handled by the |
|
|
emulator itself, so you do not need to use any ROM image at all. |
|
101 |
|
|
|
<p> |
|
|
You can use pre-compiled kernels (for example NetBSD kernels, or Linux), |
|
|
or other programs that are in binary format, and in some cases even actual |
|
|
ROM images. A couple of different file formats are supported (ELF, a.out, |
|
|
ECOFF, SREC, raw binaries). |
|
102 |
|
|
|
<p> |
|
|
(You do not need any MIPS compiler toolchain to build or use GXemul. |
|
|
If you need to compile MIPS binaries from sources, then of course you need |
|
|
such a toolchain, but that is completely separate from GXemul. There |
|
|
is a <a href="technical.html#regtest">regression testing</a> framework, |
|
|
which requires that a GNU CC for mips64-unknown-elf or similar is available. |
|
|
For simply building and using the emulator, it is not required.) |
|
103 |
|
|
104 |
|
|
105 |
|
|
107 |
|
|
108 |
<p><br> |
<p><br> |
109 |
<a name="free"></a> |
<a name="free"></a> |
110 |
<h3>Is GXemul free software?</h3> |
<h3>Is GXemul Free software?</h3> |
|
|
|
|
Yes. I have released GXemul under a free license. |
|
|
(For a definitions of the four freedoms associated with free software, |
|
|
please read <a href="http://www.gnu.org/philosophy/free-sw.html"> |
|
|
http://www.gnu.org/philosophy/free-sw.html</a>.) |
|
111 |
|
|
112 |
<p> |
Yes. I have released GXemul under a Free license. The code in GXemul is |
113 |
The code I have written is released under a 3-clause BSD-style license |
Copyrighted software, it is <i>not</i> public domain. (If this is |
114 |
(or "revised BSD-style" if one wants to use |
confusing to you, you might want to read up on the definitions of the |
115 |
<a href="http://www.gnu.org/philosophy/bsd.html">GNU jargon</a>.) |
four freedoms associated with Free software, <a |
116 |
Apart from the code I have written, some files are copied from other sources |
href="http://www.gnu.org/philosophy/free-sw.html">http://www.gnu.org/philosophy/free-sw.html</a>.) |
117 |
such as NetBSD, for example header files containing symbolic names of |
|
118 |
bitfields in device registers. They are also covered by similar licenses, |
<p>The code I have written is released under a 3-clause BSD-style license |
119 |
but with some additional clauses. If you plan to redistribute GXemul |
(or "revised BSD-style" if one wants to use <a |
120 |
(for example as a binary package), or reuse code from GXemul, |
href="http://www.gnu.org/philosophy/bsd.html">GNU jargon</a>). Apart from |
121 |
then you should check those files for their license terms. |
the code I have written, some files are copied from other sources such as |
122 |
|
NetBSD, for example header files containing symbolic names of bitfields in |
123 |
<p> |
device registers. They are also covered by similar licenses, but with some |
124 |
(The licenses usually require that the original Copyright and license |
additional clauses. The main point, however, is that the licenses require |
125 |
terms are included when you make a copy or modification. The "easiest way |
that the original Copyright and license terms are included when you make a |
126 |
out" if you plan to redistribute code from GXemul is to simply supply |
copy or modification. |
127 |
the source code. You should however check individual files for details.) |
|
128 |
|
<p>If you plan to redistribute GXemul <i>without</i> supplying the source |
129 |
|
code, then you need to comply with each individual source file some other |
130 |
|
way, for example by writing additional documentation containing copyright |
131 |
|
notes. I have not done this, since I do not plan on making distributions |
132 |
|
without source code. You need to check all individual files for details. |
133 |
|
The "easiest way out" if you plan to redistribute code from GXemul is, of |
134 |
|
course, to let it remain open source and simply supply the source code. |
135 |
|
|
136 |
|
<p>In case you want to reuse parts of GXemul, but you need to do that |
137 |
|
under a different license (e.g. the GPL), then contact me and I might |
138 |
|
re-license/dual-license files on a case-by-case basis. |
139 |
|
|
140 |
|
|
141 |
|
|
151 |
$ <b>make</b> |
$ <b>make</b> |
152 |
</pre> |
</pre> |
153 |
|
|
154 |
<p> |
<p>This should work on most Unix-like systems. GXemul does not require any |
155 |
This should work on most Unix-like systems. If it doesn't, then please |
specific libraries to build, however, if you build on a system which does |
156 |
mail me a bug report. |
not have X11 libraries installed, some functionality will be lost. |
|
|
|
|
<p> |
|
|
(Note for Windows users: there is a possibility that some releases |
|
|
and/or snapshots will also work with Cygwin, but I can't promise that.) |
|
157 |
|
|
158 |
<p> |
<p>The emulator's performance is highly dependent on both runtime settings |
|
The emulator's performance is highly dependent on both runtime settings |
|
159 |
and on compiler settings, so you might want to experiment with different |
and on compiler settings, so you might want to experiment with different |
160 |
CC and CFLAGS environment variable values. For example, on a modern PC, |
CC and CFLAGS environment variable values. For example, on an AMD Athlon |
161 |
you could try the following: |
host, you might want to try setting <tt>CFLAGS</tt> to <tt>-march=athlon</tt> |
162 |
<p> |
before running <tt>configure</tt>. |
163 |
<pre> |
|
164 |
$ <b>CFLAGS="-mcpu=pentium4 -O3" ./configure</b> |
|
165 |
$ <b>make</b> |
|
166 |
</pre> |
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
<p><br> |
171 |
|
<a name="run"></a> |
172 |
|
<h3>How to run the emulator:</h3> |
173 |
|
|
174 |
|
Once you have built GXemul, running it should be rather straight-forward. |
175 |
|
Running <tt><b>gxemul</b></tt> without arguments (or with the |
176 |
|
<b><tt>-h</tt></b> or <b><tt>-H</tt></b> command line options) will |
177 |
|
display a help message. |
178 |
|
|
179 |
<p> |
<p> |
180 |
Run <b>./configure --help</b> to get a list of configure options. (The |
To get some ideas about what is possible to run in the emulator, please |
181 |
possible options differ between different releases and snapshots.) |
read the section about <a href="guestoses.html">installing "guest" |
182 |
|
operating systems</a>. If you are interested in using the emulator to |
183 |
|
develop code on your own, then you should also read the section about |
184 |
|
<a href="experiments.html#hello">Hello World</a>. |
185 |
|
|
186 |
<p> |
<p> |
|
Once you have built GXemul, running it should be rather straight-forward. |
|
187 |
To exit the emulator, type CTRL-C to enter the |
To exit the emulator, type CTRL-C to enter the |
188 |
single-step debugger, and then type <b>quit</b>. By typing CTRL-B instead, |
single-step debugger, and then type <tt><b>quit</b></tt>. |
|
a CTRL-C is sent to the emulated program. |
|
189 |
|
|
190 |
|
<p> |
191 |
|
If you are starting an emulation by entering settings directly on the |
192 |
|
command line, and you are not using the <tt><b>-x</b></tt> option, then all |
193 |
|
terminal input and output will go to the main controlling terminal. |
194 |
|
CTRL-C is used to break into the debugger, so in order to send CTRL-C to |
195 |
|
the running (emulated) program, you may use CTRL-B. |
196 |
|
(This should be a reasonable compromise to allow the emulator to be usable |
197 |
|
even on systems without X Windows.) |
198 |
|
|
199 |
|
<p> |
200 |
|
There is no way to send an actual CTRL-B to the emulated program, when |
201 |
|
typing in the main controlling terminal window. The solution is to either |
202 |
|
use <a href="configfiles.html">configuration files</a>, or use |
203 |
|
<tt><b>-x</b></tt>. Both these solutions cause new xterms to be opened for |
204 |
|
each emulated serial port that is written to. CTRL-B and CTRL-C both have |
205 |
|
their original meaning in those xterm windows. |
206 |
|
|
207 |
|
|
208 |
|
|
210 |
|
|
211 |
<p><br> |
<p><br> |
212 |
<a name="cpus"></a> |
<a name="cpus"></a> |
213 |
<h3>Which CPU types does GXemul emulate?</h3> |
<h3>Which processor architectures does GXemul emulate?</h3> |
214 |
|
|
215 |
<h4>MIPS:</h4> |
The architectures that are emulated well enough to let at least one |
216 |
|
guest operating system run (per architecture) are ARM, MIPS, and |
217 |
|
PowerPC. |
218 |
|
|
|
Emulation of R4000, which is a 64-bit CPU, was my initial goal. Right |
|
|
now, R2000/R3000-like CPUs are also emulated (32-bit), and emulation of |
|
|
R1x000 (at least the parts that are similar to R4000) is beginning to work |
|
|
as expected. Code targeted for MIPS32 and MIPS64 also often work. |
|
219 |
|
|
|
<p> |
|
|
I have written an experimental dynamic binary translation subsystem. |
|
|
This gives higher total performance than interpreting one instruction at a |
|
|
time and executing it. (If you wish to enable bintrans, add <b>-b</b> to |
|
|
the command line, but keep in mind that it is still experimental.) |
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
<h4>URISC:</h4> |
<p><br> |
224 |
|
<a name="hosts"></a> |
225 |
|
<h3>Which host architectures are supported?</h3> |
226 |
|
|
227 |
I have implemented an <a href="http://en.wikipedia.org/wiki/URISC">URISC</a> |
As of release 0.4.0 of GXemul, the old binary translation subsystem, which |
228 |
emulation mode, just for fun. The only instruction available in an URISC |
was used for emulation of MIPS processors on Alpha and i386 hosts, has |
229 |
machine is "reverse subtract and skip on borrow". (It is probably not |
been removed. The current dynamic translation subsystem should work on any |
230 |
worth trying to do bintrans with URISC, because any reasonable URISC |
host. |
|
program relies on self-modifying code, which is bad for bintrans |
|
|
performance.) |
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
<h4>Other CPU types:</h4> |
|
235 |
|
|
236 |
There is some code for 64-bit (and 32-bit) POWER/PowerPC emulation too, |
<p><br> |
237 |
but it only works for "Hello World" and similarly trivial programs. (There |
<a name="translation"></a> |
238 |
are some other CPU modes too, but they are working even less.) |
<h3>What kind of translation does GXemul use?</h3> |
239 |
|
|
240 |
|
<b>Static vs. dynamic:</b> |
241 |
|
|
242 |
|
<p>In order to support guest operating systems, which can overwrite old |
243 |
|
code pages in memory with new code, it is necessary to translate code |
244 |
|
dynamically. It is not possible to do a "one-pass" (static) translation. |
245 |
|
Self-modifying code and Just-in-Time compilers running inside |
246 |
|
the emulator are other things that would not work with a static |
247 |
|
translator. GXemul is a dynamic translator. However, it does not |
248 |
|
necessarily translate into native code, like many other emulators. |
249 |
|
|
250 |
|
<p><b>"Runnable" Intermediate Representation:</b> |
251 |
|
|
252 |
|
<p>Dynamic translators usually translate from the emulated architecture |
253 |
|
(e.g. MIPS) into a kind of <i>intermediate representation</i> (IR), and then |
254 |
|
to native code (e.g. AMD64 or x86 code). Since one of my main goals for |
255 |
|
GXemul is to keep everything as portable as possible, I have tried to make |
256 |
|
sure that the IR is something which can be executed regardless of whether |
257 |
|
the final step (translation from IR to native code) has been implemented |
258 |
|
or not. |
259 |
|
|
260 |
|
<p>The IR in GXemul consists of arrays of pointers to functions, and a few |
261 |
|
arguments which are passed along to those functions. The functions are |
262 |
|
implemented in either manually hand-coded C, or automatically generated C. |
263 |
|
In any case, this is all statically linked into the GXemul binary at link |
264 |
|
time. |
265 |
|
|
266 |
|
<p>Here is a simplified diagram of how these arrays work. |
267 |
|
|
268 |
|
<p><center><img src="simplified_dyntrans.png"></center> |
269 |
|
|
270 |
|
<p>There is one instruction call slot for every possible program counter |
271 |
|
location. In the MIPS case, instruction words are 32 bits in length, |
272 |
|
and pages are (usually) 4 KB large, resulting in 1024 instruction call |
273 |
|
slots. After the last of these instruction calls, there is an additional |
274 |
|
call to a special "end of page" function (which doesn't count as an executed |
275 |
|
instruction). This function switches to the first instruction |
276 |
|
on the next virtual page (which might cause exceptions, etc). |
277 |
|
|
278 |
|
<p>The complexity of individual instructions vary. A simple example of |
279 |
|
what an instruction can look like is the MIPS <tt>addiu</tt> instruction: |
280 |
|
<pre> |
281 |
|
X(addiu) |
282 |
|
{ |
283 |
|
reg(ic->arg[1]) = (int32_t) |
284 |
|
((int32_t)reg(ic->arg[0]) + (int32_t)ic->arg[2]); |
285 |
|
} |
286 |
|
</pre> |
287 |
|
|
288 |
|
<p>It stores the result of a 32-bit addition of the register at arg[0] |
289 |
|
with the immediate value arg[2] (treating both as signed 32-bit |
290 |
|
integers) into register arg[1]. If the emulated CPU is a 64-bit CPU, |
291 |
|
then this will store a correctly sign-extended value into arg[1]. |
292 |
|
If it is a 32-bit CPU, then only the lowest 32 bits will be stored, |
293 |
|
and the high part ignored. <tt>X(addiu)</tt> is expanded to |
294 |
|
<tt>mips_instr_addiu</tt> in the 64-bit case, and <tt>mips32_instr_addiu</tt> |
295 |
|
in the 32-bit case. Both are compiled into the GXemul executable; no code |
296 |
|
is created during run-time. |
297 |
|
|
298 |
|
<p>Here are examples of what the <tt>addiu</tt> instruction actually |
299 |
|
looks like when it is compiled, on various host architectures: |
300 |
|
|
301 |
|
<p><center><table border="0"> |
302 |
|
<tr><td><b>GCC 4.0.1 on Alpha:</b></td> |
303 |
|
<td width="35"></td><td></td> |
304 |
|
<tr> |
305 |
|
<td valign="top"> |
306 |
|
<pre>mips_instr_addiu: |
307 |
|
ldq t1,8(a1) |
308 |
|
ldq t2,24(a1) |
309 |
|
ldq t3,16(a1) |
310 |
|
ldq t0,0(t1) |
311 |
|
addl t0,t2,t0 |
312 |
|
stq t0,0(t3) |
313 |
|
ret</pre> |
314 |
|
</td> |
315 |
|
<td></td> |
316 |
|
<td valign="top"> |
317 |
|
<pre>mips32_instr_addiu: |
318 |
|
ldq t2,8(a1) |
319 |
|
ldq t0,24(a1) |
320 |
|
ldq t3,16(a1) |
321 |
|
ldl t1,0(t2) |
322 |
|
addq t0,t1,t0 |
323 |
|
stl t0,0(t3) |
324 |
|
ret</pre> |
325 |
|
</td> |
326 |
|
</tr> |
327 |
|
|
328 |
|
<tr><td><b><br>GCC 3.4.4 on AMD64:</b></td> |
329 |
|
<tr> |
330 |
|
<td valign="top"> |
331 |
|
<pre>mips_instr_addiu: |
332 |
|
mov 0x8(%rsi),%rdx |
333 |
|
mov 0x18(%rsi),%rax |
334 |
|
mov 0x10(%rsi),%rcx |
335 |
|
add (%rdx),%eax |
336 |
|
cltq |
337 |
|
mov %rax,(%rcx) |
338 |
|
retq</pre> |
339 |
|
</td> |
340 |
|
<td></td> |
341 |
|
<td valign="top"> |
342 |
|
<pre>mips32_instr_addiu: |
343 |
|
mov 0x8(%rsi),%rcx |
344 |
|
mov 0x10(%rsi),%rdx |
345 |
|
mov (%rcx),%eax |
346 |
|
add 0x18(%rsi),%eax |
347 |
|
mov %eax,(%rdx) |
348 |
|
retq</pre> |
349 |
|
</td> |
350 |
|
</tr> |
351 |
|
|
352 |
|
<tr><td><b><br>GCC 4.0.1 on i386:</b></td> |
353 |
|
<tr> |
354 |
|
<td valign="top"> |
355 |
|
<pre>mips_instr_addiu: |
356 |
|
mov 0x8(%esp),%eax |
357 |
|
mov 0x8(%eax),%ecx |
358 |
|
mov 0x4(%eax),%edx |
359 |
|
mov 0xc(%eax),%eax |
360 |
|
add (%edx),%eax |
361 |
|
mov %eax,(%ecx) |
362 |
|
cltd |
363 |
|
mov %edx,0x4(%ecx) |
364 |
|
ret</pre> |
365 |
|
</td> |
366 |
|
<td></td> |
367 |
|
<td valign="top"> |
368 |
|
<pre>mips32_instr_addiu: |
369 |
|
mov 0x8(%esp),%eax |
370 |
|
mov 0x8(%eax),%ecx |
371 |
|
mov 0x4(%eax),%edx |
372 |
|
mov 0xc(%eax),%eax |
373 |
|
add (%edx),%eax |
374 |
|
mov %eax,(%ecx) |
375 |
|
ret</pre> |
376 |
|
</td> |
377 |
|
</tr> |
378 |
|
</table></center> |
379 |
|
|
380 |
|
<p>On 64-bit hosts, there is not much difference, but on 32-bit hosts (and |
381 |
|
to some extent on AMD64), the difference is enough to make it worthwhile. |
382 |
|
|
383 |
|
|
384 |
|
<p><b>Performance:</b> |
385 |
|
|
386 |
|
<p>The performance of using this kind of runnable IR is obviously lower |
387 |
|
than what can be achieved by emulators using native code generation, but |
388 |
|
can be significantly higher than using a naive fetch-decode-execute |
389 |
|
interpretation loop. In my opinion, using a runnable IR is an interesting |
390 |
|
compromise. |
391 |
|
|
392 |
|
<p>The overhead per emulated instruction is usually around or below |
393 |
|
approximately 10 host instructions. This is very much dependent on your |
394 |
|
host architecture and what compiler and compiler switches you are using. |
395 |
|
Added to this instruction count is (of course) also the C code used to |
396 |
|
implement each specific instruction. |
397 |
|
|
398 |
|
<p><b>Instruction Combinations:</b> |
399 |
|
|
400 |
|
<p>Short, common instruction sequences can sometimes be replaced by a |
401 |
|
"compound" instruction. An example could be a compare instruction followed |
402 |
|
by a conditional branch instruction. The advantages of instruction |
403 |
|
combinations are that |
404 |
|
<ul> |
405 |
|
<li>the amortized overhead per instruction is slightly reduced, and |
406 |
|
<p> |
407 |
|
<li>the host's compiler can make a good job at optimizing the common |
408 |
|
instruction sequence. |
409 |
|
</ul> |
410 |
|
|
411 |
|
<p>The special cases where instruction combinations give the most gain |
412 |
|
are in the cores of string/memory manipulation functions such as |
413 |
|
<tt>memset()</tt> or <tt>strlen()</tt>. The core loop can then (at least |
414 |
|
to some extent) be replaced by a native call to the equivalent function. |
415 |
|
|
416 |
|
<p>The implementations of compound instructions still keep track of the |
417 |
|
number of executed instructions, etc. When single-stepping, these |
418 |
|
translations are invalidated, and replaced by normal instruction calls |
419 |
|
(one per emulated instruction). |
420 |
|
|
421 |
|
<p><b>Native Code Back-ends: (not in this release)</b> |
422 |
|
|
423 |
|
<p>In theory, it will be possible to implement native code generation |
424 |
|
(similar to what is used in high-performance emulators such as QEMU), |
425 |
|
as long as that generated code abides to the C ABI on the host, but |
426 |
|
for now I wanted to make sure that GXemul works without such native |
427 |
|
code back-ends. For this reason, as of release 0.4.0, GXemul is |
428 |
|
completely free of native code back-ends. |
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
436 |
<a name="accuracy"></a> |
<a name="accuracy"></a> |
437 |
<h3>Emulation accuracy:</h3> |
<h3>Emulation accuracy:</h3> |
438 |
|
|
439 |
GXemul is an instruction-level simulator; things that would happen in |
GXemul is an instruction-level emulator; things that would happen in |
440 |
several steps within a real CPU are not taken into account (eg. pipe-line |
several steps within a real CPU are not taken into account (e.g. pipe-line |
441 |
stages or out-of-order execution). Still, instruction-level accuracy seems |
stalls or out-of-order execution). Still, instruction-level accuracy seems |
442 |
to be enough to be able to run complete guest operating systems inside the |
to be enough to be able to run complete guest operating systems inside the |
443 |
emulator. |
emulator. |
444 |
|
|
445 |
|
<p>The existance of instruction and data caches is "faked" to let |
446 |
|
operating systems think that they are there, but for all practical |
447 |
|
purposes, these caches are non-working. |
448 |
|
|
449 |
|
<p>The emulator is <i>not</i> timing-accurate. It can be run in a |
450 |
|
"deterministic" mode, <tt><b>-D</b></tt>. The meaning of deterministic is |
451 |
|
simply that running two emulations with the same settings will result in |
452 |
|
identical runs. Obviously, this requires that no user interaction is |
453 |
|
taking place, and that clock speeds are fixed with the <tt><b>-I</b></tt> |
454 |
|
option. (Deterministic in this case does <i>not</i> mean that the |
455 |
|
emulation will be identical to some actual real-world machine.) |
456 |
|
|
457 |
|
<p>(Note that user interaction means <i>both</i> input to the emulated |
458 |
|
program/OS, and interaction with the emulator's debugger. Breaking into the |
459 |
|
debugger and then continuing execution may affect when/how interrupts |
460 |
|
occur.) |
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
468 |
<a name="emulmodes"></a> |
<a name="emulmodes"></a> |
469 |
<h3>Which machines does GXemul emulate?</h3> |
<h3>Which machines does GXemul emulate?</h3> |
470 |
|
|
471 |
A few different machine types are emulated. The machine types that are |
A few different machine types are emulated. The following machine types |
472 |
emulated best at the moment are: |
are emulated well enough to run at least one "guest OS": |
473 |
|
|
474 |
<p> |
<p> |
475 |
<ul> |
<ul> |
476 |
<li><b>DECstation 5000/200</b> ("pmax") |
<li><b><u>ARM</u></b> |
477 |
<br>(Serial controller (including keyboard and mouse), ethernet, |
<ul> |
478 |
SCSI, and graphical framebuffers.) |
<li><b>CATS</b> (<a href="guestoses.html#netbsdcatsinstall">NetBSD/cats</a>, |
479 |
|
<a href="guestoses.html#openbsdcatsinstall">OpenBSD/cats</a>) |
480 |
|
<li><b>IQ80321</b> (<a href="guestoses.html#netbsdevbarminstall">NetBSD/evbarm</a>) |
481 |
|
</ul> |
482 |
<p> |
<p> |
483 |
<li><b>Acer Pica-61</b> (an ARC machine) |
<li><b><u>MIPS</u></b> |
484 |
<br>(Serial controller, "VGA" text console, and SCSI.) |
<ul> |
485 |
|
<li><b>DECstation 5000/200</b> (<a href="guestoses.html#netbsdpmaxinstall">NetBSD/pmax</a>, |
486 |
|
<a href="guestoses.html#openbsdpmaxinstall">OpenBSD/pmax</a>, |
487 |
|
<a href="guestoses.html#ultrixinstall">Ultrix</a>, |
488 |
|
<a href="guestoses.html#declinux">Linux/DECstation</a>, |
489 |
|
<a href="guestoses.html#sprite">Sprite</a>) |
490 |
|
<li><b>Acer Pica-61</b> (<a href="guestoses.html#netbsdarcinstall">NetBSD/arc</a>) |
491 |
|
<li><b>NEC MobilePro 770, 780, 800, and 880</b> (<a href="guestoses.html#netbsdhpcmipsinstall">NetBSD/hpcmips</a>) |
492 |
|
<li><b>Cobalt</b> (<a href="guestoses.html#netbsdcobaltinstall">NetBSD/cobalt</a>) |
493 |
|
<li><b>Malta</b> (<a href="guestoses.html#netbsdevbmipsinstall">NetBSD/evbmips</a>) |
494 |
|
<li><b>SGI O2 (aka IP32)</b> <font color="#0000e0">(<super>*</super>)</font> |
495 |
|
(<a href="guestoses.html#netbsdsgimips">NetBSD/sgi</a>) |
496 |
|
</ul> |
497 |
<p> |
<p> |
498 |
<li><b>NEC MobilePro 770, 780, 800, and 880</b> (HPCmips machines) |
<li><b><u>PowerPC</u></b> |
499 |
<br>(Framebuffer, keyboard, and a PCMCIA IDE controller.) |
<ul> |
500 |
|
<li><b>IBM 6050/6070 (PReP, PowerPC Reference Platform)</b> (<a href="guestoses.html#netbsdprepinstall">NetBSD/prep</a>) |
501 |
|
</ul> |
502 |
</ul> |
</ul> |
503 |
|
|
504 |
<p> |
<p><small><font color="#0000e0">(<super>*</super>)</font> = |
505 |
There is code in GXemul for emulation of many other machine types; |
Enough for root-on-nfs, but not for disk boot.)</small> |
|
the degree to which these work range from "almost" being able to run |
|
|
a complete OS, to almost completely unsupported (perhaps just enough |
|
|
support to output a few boot messages via serial console). |
|
506 |
|
|
507 |
<p> |
<p>There is code in GXemul for emulation of many other machine types; the |
508 |
In addition to specific machine types, a "test-machine" can be emulated. |
degree to which these work range from almost being able to run a complete |
509 |
A test-machine consists of one or more CPUs and a few experimental |
OS, to almost completely unsupported (perhaps just enough support to |
510 |
devices such as: |
output a few boot messages via serial console). |
511 |
|
|
512 |
|
<p>In addition to emulating real machines, there is also a "test-machine". |
513 |
|
A test-machine consists of one or more CPUs and a few experimental devices |
514 |
|
such as: |
515 |
|
|
516 |
<p> |
<p> |
517 |
<ul> |
<ul> |
518 |
<li>a console I/O device (putchar() and getchar()...) |
<li>a console I/O device (putchar() and getchar()...) |
519 |
<li>an inter-processor communication device, for SMP experiments |
<li>an inter-processor communication device, for SMP experiments |
520 |
<li>a very simple linear framebuffer device (for graphics output) |
<li>a very simple linear framebuffer device (for graphics output) |
521 |
|
<li>a simple SCSI disk controller |
522 |
|
<li>a simple ethernet controller |
523 |
</ul> |
</ul> |
524 |
|
|
525 |
<p> |
<p>This mode is useful if you wish to run experimental code, but do not |
|
This mode is useful if you wish to run experimental code, but do not |
|
526 |
wish to target any specific real-world machine type, for example for |
wish to target any specific real-world machine type, for example for |
527 |
educational purposes. |
educational purposes. |
528 |
|
|
529 |
<p> |
<p>You can read more about these experimental devices <a |
530 |
You can read more about these experimental devices |
href="experiments.html#expdevices">here</a>. |
|
<a href="experiments.html#expdevices">here</a>. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p><br> |
|
|
<a name="guestos"></a> |
|
|
<h3>Which guest OSes are possible to run?</h3> |
|
|
|
|
|
This table sums up the guest OSes that run well enough to be considered |
|
|
working in the emulator. They can boot from a harddisk image and be |
|
|
interacted with similar to a real machine: |
|
|
|
|
|
<p><br> |
|
|
<center> |
|
|
<table border="0"> |
|
|
<tr><td> |
|
|
<table border="0"> |
|
|
<tr><td align="center"> |
|
|
<table border="0"> |
|
|
<tr> |
|
|
<td valign="top"><b><u>Guest OS:</u></b></td> |
|
|
<td width="15"> </td> |
|
|
<td valign="top"><b><u>Emulation mode:</u></b></td> |
|
|
<td width="35"> </td> |
|
|
<td valign="top"><b><u>Guest OS:</u></b></td> |
|
|
<td width="15"> </td> |
|
|
<td valign="top"><b><u>Emulation mode:</u></b></td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td height="1"></td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td valign="top"><a href="http://www.netbsd.org/Ports/pmax/">NetBSD/pmax</a></td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
<td></td> |
|
|
<td valign="top"><a href="http://www.netbsd.org/Ports/arc/">NetBSD/arc</a></td> |
|
|
<td></td> |
|
|
<td valign="top">ARC (Acer Pica)</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td valign="top"><a href="http://www.openbsd.org/pmax.html">OpenBSD/pmax</a></td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
<td></td> |
|
|
<td valign="top"><a href="http://www.openbsd.org/arc.html">OpenBSD/arc</a></td> |
|
|
<td></td> |
|
|
<td valign="top">ARC (Acer Pica)</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td valign="top">Ultrix/RISC</td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
<td></td> |
|
|
<td valign="top"><a href="http://www.cs.berkeley.edu/projects/sprite/retrospective.html">Sprite</a></td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td valign="top">Redhat Linux<super>*</super></td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
<td></td> |
|
|
<td valign="top"><a href="http://www.debian.org/">Debian GNU/Linux</a><super>*</super></td> |
|
|
<td></td> |
|
|
<td valign="top">DECstation</td> |
|
|
</tr> |
|
|
|
|
|
<tr> |
|
|
<td valign="top"><a href="http://www.netbsd.org/Ports/hpcmips/">NetBSD/hpcmips</a></td> |
|
|
<td></td> |
|
|
<td valign="top">NEC MobilePro</td> |
|
|
</tr> |
|
|
</table> |
|
|
</td></tr> |
|
|
|
|
|
<tr><td height="15"> </td></tr> |
|
|
|
|
|
<tr><td> |
|
|
<center> |
|
|
<table border="0"> |
|
|
<tr> |
|
|
<td width=160 align=center><a href="netbsd-pmax-20040630.png"><img src="netbsd-pmax-20040630_small.png"></a></td> |
|
|
<td width=160 align=center><a href="openbsd-pmax-20040710.png"><img src="openbsd-pmax-20040710_small.png"></a></td> |
|
|
<td width=160 align=center><a href="ultrix4.5-20040706.png"><img src="ultrix4.5-20040706_small.gif"></a></td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td align=center>NetBSD/pmax 1.6.2</td> |
|
|
<td align=center>OpenBSD/pmax 2.8</td> |
|
|
<td align=center>Ultrix 4.5</td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td height=10> </td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td width=160 align=center><a href="20041024-netbsd-arc-installed.gif"><img src="20041024-netbsd-arc-installed_small.gif"></a></td> |
|
|
<td width=160 align=center><a href="20041024-openbsd-arc-installed.gif"><img src="20041024-openbsd-arc-installed_small.gif"></a></td> |
|
|
<td width=160 align=center><a href="sprite-20040711.png"><img src="sprite-20040711_small.png"></a></td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td align=center>NetBSD/arc 1.6.2</td> |
|
|
<td align=center>OpenBSD/arc 2.3</td> |
|
|
<td align=center>Sprite</td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td height=10> </td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td width=160 align=center><a href="20041129-redhat_mips.png"><img src="20041129-redhat_mips_small.png"></a></td> |
|
|
<td width=160 align=center><a href="20041213-debian_4.png"><img src="20041213-debian_4_small.gif"></a></td> |
|
|
<td width=160 align=center><a href="20050331-netbsd-hpcmips.png"><img src="20050331-netbsd-hpcmips_small.png"></a></td> |
|
|
</tr> |
|
|
<tr> |
|
|
<td align=center>Redhat Linux<super>*</super></td> |
|
|
<td align=center>Debian GNU/Linux<super>*</super></td> |
|
|
<td align=center>NetBSD/hpcmips</td> |
|
|
</tr> |
|
|
</table> |
|
|
</center> |
|
|
</td></tr> |
|
|
</table> |
|
|
</td></tr> |
|
|
</table> |
|
|
</center> |
|
|
|
|
|
<p><br> |
|
|
|
|
|
(<super>*</super> Although Linux runs under DECstation emulation, the |
|
|
default kernel in Debian GNU/Linux does not support keyboards on the 5000/200 |
|
|
(the specific DECstation model being emulated), so when the login prompt |
|
|
is reached you cannot interact with the system. |
|
|
Kaj-Michael Lang has compiled and made available a newer kernel from the |
|
|
current mips-linux development tree. You can find it here: |
|
|
<a href="http://home.tal.org/~milang/o2/kernels/">http://home.tal.org/~milang/o2/kernels</a>/<a href="http://home.tal.org/~milang/o2/kernels/vmlinux-2.4.29-rc2-r3k-mipsel-decstation">vmlinux-2.4.29-rc2-r3k-mipsel-decstation</a> |
|
|
This newer kernel supports keyboard input, but it does not have Debian's |
|
|
ethernet patches, so you will not be able to use keyboard/framebuffer |
|
|
<i>and</i> networking at the same time.) |
|
|
|
|
|
|
|
|
<p> |
|
|
It is non-trivial to get a specific operating system or OS kernel to |
|
|
run in the emulator, so don't expect the list above to grow too quickly. |
|
|
|
|
|
<p> |
|
|
There is no guarantee that anything specific will run in the emulator, but |
|
|
NetBSD is a good starting point for someone who wants to experiment. |
|
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
|
</p> |
|
536 |
|
|
537 |
</body> |
</body> |
538 |
</html> |
</html> |