/[gxemul]/trunk/doc/technical.html
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/doc/technical.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC
# Line 1  Line 1 
1  <html><head><title>GXemul documentation: Technical details</title>  <html><head><title>Gavare's eXperimental Emulator:&nbsp;&nbsp;&nbsp;Technical details</title>
2  <meta name="robots" content="noarchive,nofollow,noindex"></head>  <meta name="robots" content="noarchive,nofollow,noindex"></head>
3  <body bgcolor="#f8f8f8" text="#000000" link="#4040f0" vlink="#404040" alink="#ff0000">  <body bgcolor="#f8f8f8" text="#000000" link="#4040f0" vlink="#404040" alink="#ff0000">
4  <table border=0 width=100% bgcolor="#d0d0d0"><tr>  <table border=0 width=100% bgcolor="#d0d0d0"><tr>
5  <td width=100% align=center valign=center><table border=0 width=100%><tr>  <td width=100% align=center valign=center><table border=0 width=100%><tr>
6  <td align="left" valign=center bgcolor="#d0efff"><font color="#6060e0" size="6">  <td align="left" valign=center bgcolor="#d0efff"><font color="#6060e0" size="6">
7  <b>GXemul documentation:</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <b>Gavare's eXperimental Emulator:&nbsp;&nbsp;&nbsp;</b></font>
8  <font color="#000000" size="6"><b>Technical details</b>  <font color="#000000" size="6"><b>Technical details</b>
9  </font></td></tr></table></td></tr></table><p>  </font></td></tr></table></td></tr></table><p>
10    
11  <!--  <!--
12    
13  $Id: technical.html,v 1.53 2005/06/27 17:31:50 debug Exp $  $Id: technical.html,v 1.67 2005/11/24 12:32:10 debug Exp $
14    
15  Copyright (C) 2004-2005  Anders Gavare.  All rights reserved.  Copyright (C) 2004-2005  Anders Gavare.  All rights reserved.
16    
# Line 40  SUCH DAMAGE. Line 40  SUCH DAMAGE.
40  -->  -->
41    
42    
43    
44  <a href="./">Back to the index</a>  <a href="./">Back to the index</a>
45    
46  <p><br>  <p><br>
# Line 52  SUCH DAMAGE. Line 53  SUCH DAMAGE.
53    <li><a href="#speed">Speed and emulation modes</a>    <li><a href="#speed">Speed and emulation modes</a>
54    <li><a href="#net">Networking</a>    <li><a href="#net">Networking</a>
55    <li><a href="#devices">Emulation of hardware devices</a>    <li><a href="#devices">Emulation of hardware devices</a>
   <li><a href="#regtest">Regression tests</a>  
56  </ul>  </ul>
57    
58    
# Line 64  SUCH DAMAGE. Line 64  SUCH DAMAGE.
64  <a name="speed"></a>  <a name="speed"></a>
65  <h3>Speed and emulation modes</h3>  <h3>Speed and emulation modes</h3>
66    
67  So, how fast is GXemul? There is no good answer to this. There is  So, how fast is GXemul? There is no short answer to this. There is
68  especially no answer to the question <b>What is the slowdown factor?</b>,  especially no answer to the question <b>What is the slowdown factor?</b>,
69  because the host architecture and emulated architecture can usually not be  because the host architecture and emulated architecture can usually not be
70  compared just like that.  compared just like that.
# Line 89  with the emulator. Typical examples woul Line 89  with the emulator. Typical examples woul
89  install NetBSD?", or "How long does it take to compile XYZ inside NetBSD  install NetBSD?", or "How long does it take to compile XYZ inside NetBSD
90  in the emulator?".  in the emulator?".
91    
92    <p>So, how fast is it? :-)&nbsp;&nbsp;&nbsp;Answer: it varies.
93    
94  <p>The emulation technique used varies depending on which processor type  <p>The emulation technique used varies depending on which processor type
95  is being emulated. (One of my main goals with GXemul is to experiment with  is being emulated. (One of my main goals with GXemul is to experiment with
96  different kinds of emulation, so these might change in the future.)  different kinds of emulation, so these might change in the future.)
97    
98  <ul>  <ul>
99    <li><b>MIPS</b><br>    <li><b>MIPS:</b><br>
100          There are two emulation modes. The most important one is an          There are two emulation modes. The most important one is an
101          implementation of a <i>dynamic binary translator</i>.          implementation of a <i>dynamic binary translator</i>.
102          (Compared to real binary translators, though, GXemul's bintrans          (Compared to real binary translators, though, GXemul's bintrans
# Line 105  different kinds of emulation, so these m Line 107  different kinds of emulation, so these m
107          works. It can be forcefully used by using the <tt>-B</tt> command          works. It can be forcefully used by using the <tt>-B</tt> command
108          line option.)          line option.)
109    <p>    <p>
110    <li><b>ARM</b><br>    <li><b>All other modes:</b><br>
111          This mode does not really work yet, but will use          These use a kind of dynamic translation system. (This system does
112          dynamic translation, but not binary translation. Stay tuned. :-)          not use host-specific backends, so it is not "recompilation" or
113    <p>          anything like that.) Speed is slower than real binary translation,
114    <li><b>URISC</b><br>          but faster than traditional interpretation, and with some tricks
115          Simple interpretation, one instruction at a time. There is probably          it will hopefully still give reasonable speed. The ARM and PowerPC
116          no other way to emulate URISC, because it relies too heavily          emulation modes uses this kind of translation.
         on self-modifying code.  
   <p>  
   <li><b>POWER/PowerPC</b><br>  
         This emulation mode is very much unfinished, but still enabled by  
         default. So far it uses plain interpretation, where an instruction  
         is read from emulated memory, and interpreted one at a time.  
         Slow. Not very interesting.  
   <p>  
   <li><b>x86</b><br>  
         Although too unstable and non-working to be enabled by default,  
         there is some code for emulating x86 machines. It simply reads  
         one instruction at a time from emulated memory, and executes it.  
         This is as slow as it gets. Not very interesting.  
117  </ul>  </ul>
118    
119    
# Line 132  different kinds of emulation, so these m Line 121  different kinds of emulation, so these m
121    
122    
123    
   
124  <p><br>  <p><br>
125  <a name="net"></a>  <a name="net"></a>
126  <h3>Networking</h3>  <h3>Networking</h3>
# Line 330  a CDROM ISO image. You can use a read-wr Line 318  a CDROM ISO image. You can use a read-wr
318  files in both directions, but then you should be aware of the  files in both directions, but then you should be aware of the
319  fragmentation issue mentioned above.  fragmentation issue mentioned above.
320    
 <p>TODO: Write a section on how to connect multiple emulator instances.  
 (Using the <tt>local_port</tt> and <tt>add_remote</tt> configuration file  
 commands.)  
321    
322    
323    
# Line 343  commands.) Line 328  commands.)
328  <a name="devices"></a>  <a name="devices"></a>
329  <h3>Emulation of hardware devices</h3>  <h3>Emulation of hardware devices</h3>
330    
331  Each file in the <tt>device/</tt> directory is responsible for one  Each file called <tt>dev_*.c</tt> in the <tt>src/device/</tt> directory is
332  hardware device. These are used from <tt>src/machine.c</tt>, when  responsible for one hardware device. These are used from
333  initializing which hardware a particular machine model will be using, or  <tt>src/machine.c</tt>, when initializing which hardware a particular
334  when adding devices to a machine using the <tt>device()</tt> command in  machine model will be using, or when adding devices to a machine using the
335  configuration files.  <tt>device()</tt> command in configuration files.
   
 <p><font color="#ff0000">NOTE: The device registry subsystem is currently  
 in a state of flux, as it is being redesigned.</font>  
336    
337  <p>(I'll be using the name "<tt>foo</tt>" as the name of the device in all  <p>(I'll be using the name "<tt>foo</tt>" as the name of the device in all
338  these examples.  This is pseudo code, it might need some modification to  these examples.  This is pseudo code, it might need some modification to
# Line 386  actually compile and run.) Line 368  actually compile and run.)
368                    
369                  memory_device_register(devinit->machine->memory, devinit->name,                  memory_device_register(devinit->machine->memory, devinit->name,
370                      devinit->addr, DEV_FOO_LENGTH,                      devinit->addr, DEV_FOO_LENGTH,
371                      dev_foo_access, (void *)d, MEM_DEFAULT, NULL);                      dev_foo_access, (void *)d, DM_DEFAULT, NULL);
372                    
373                  /*  This should only be here if the device                  /*  This should only be here if the device
374                      has a tick function:  */                      has a tick function:  */
# Line 406  actually compile and run.) Line 388  actually compile and run.)
388                  /*  ...  */                  /*  ...  */
389          }          }
390  </pre><br>  </pre><br>
391            (There is an exception to this rule; ugly hacks which allow
392            code in <tt>src/machine.c</tt> to use some structures makes it
393            necessary to place the <tt>struct foo_data</tt> in
394            <tt>src/include/devices.h</tt> instead of in <tt>dev_foo.c</tt>
395            itself. This is useful for example for interrupt controllers.)
396      <p>
397    <li>If <tt>foo</tt> has a tick function (that is, something that needs to be    <li>If <tt>foo</tt> has a tick function (that is, something that needs to be
398          run at regular intervals) then <tt>FOO_TICKSHIFT</tt> and a tick          run at regular intervals) then <tt>FOO_TICKSHIFT</tt> and a tick
399          function need to be defined as well:          function need to be defined as well:
400  <pre>  <pre>
401          #define FOO_TICKSHIFT           10          #define FOO_TICKSHIFT           14
402    
403          void dev_foo_tick(struct cpu *cpu, void *extra)          void dev_foo_tick(struct cpu *cpu, void *extra)
404          {          {
# Line 424  actually compile and run.) Line 411  actually compile and run.)
411          }          }
412  </pre><br>  </pre><br>
413    
414      <li>Does this device belong to a standard bus?
415            <ul>
416              <li>If this device should be detectable as a PCI device, then
417                    glue code should be added to
418                    <tt>src/devices/bus_pci.c</tt>.
419              <li>If this is a legacy ISA device which should be usable by
420                    any machine which has an ISA bus, then the device should
421                    be added to <tt>src/devices/bus_isa.c</tt>.
422            </ul>
423      <p>
424    <li>And last but not least, the device should have an access function.    <li>And last but not least, the device should have an access function.
425          The access function is called whenever there is a load or store          The access function is called whenever there is a load or store
426          to an address which is in the device' memory mapped region.          to an address which is in the device' memory mapped region.
# Line 474  by the caller (in <tt>src/memory_rw.c</t Line 471  by the caller (in <tt>src/memory_rw.c</t
471    
472    
473    
 <p><br>  
 <a name="regtest"></a>  
 <h3>Regression tests</h3>  
   
 In order to make sure that the emulator actually works like it is supposed  
 to, it must be tested. For this purpose, there is a simple regression  
 testing framework in the <tt>tests/</tt> directory.  
   
 <p>  
 <i>NOTE:  The regression testing framework is basically just a skeleton so far.  
 Regression tests are very good to have. However, the fact that complete  
 operating systems can run in the emulator indicate that the emulation is  
 probably not too incorrect. This makes it less of a priority to write  
 regression tests.</i>  
   
 <p>  
 To run all the regression tests, type <tt>make regtest</tt>. Each assembly  
 language file matching the pattern <tt>test_*.S</tt> will be compiled and  
 linked into a 64-bit MIPS ELF (using a gcc cross compiler), and run in the  
 emulator. If everything goes well, you should see something like this:  
   
 <pre>  
         $ make regtest  
         cd tests; make run_tests; cd ..  
         gcc33 -Wall -fomit-frame-pointer -fmove-all-movables -fpeephole -O2  
                 -mcpu=ev5 -I/usr/X11R6/include -lm -L/usr/X11R6/lib -lX11  do_tests.c  
                 -o do_tests  
         do_tests.c: In function `main':  
         do_tests.c:173: warning: unused variable `s'  
         /var/tmp//ccFOupvD.o: In function `do_tests':  
         /var/tmp//ccFOupvD.o(.text+0x3a8): warning: tmpnam() possibly used  
                 unsafely; consider using mkstemp()  
         mips64-unknown-elf-gcc -g -O3 -fno-builtin -fschedule-insns -mips64  
                 -mabi=64 test_common.c -c -o test_common.o  
         ./do_tests "mips64-unknown-elf-gcc -g -O3 -fno-builtin -fschedule-insns  
                 -mips64 -mabi=64" "mips64-unknown-elf-as -mabi=64 -mips64"  
                 "mips64-unknown-elf-ld -Ttext 0xa800000000030000 -e main  
                 --oformat=elf64-bigmips" "../gxemul"  
   
         Starting tests:  
           test_addu.S (-a)  
           test_addu.S (-a -b)  
           test_clo_clz.S (-a)  
           test_clo_clz.S (-a -b)  
           ..  
           test_unaligned.S (-a)  
           test_unaligned.S (-a -b)  
   
         Done. (12 tests done)  
             PASS:     12  
             FAIL:      0  
   
         ----------------  
   
           All tests OK  
   
         ----------------  
 </pre>  
   
 <p>  
 Each test writes output to stdout, and there is a <tt>test_*.good</tt> for  
 each <tt>.S</tt> file which contains the wanted output. If the actual  
 output matches the <tt>.good</tt> file, then the test passes, otherwise it  
 fails.  
   
 <p>  
 Read <tt>tests/README</tt> for more information.  
   
   
   
474    
475  </body>  </body>
476  </html>  </html>

Legend:
Removed from v.10  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26