gxemul (1) - Linux Man Pages
gxemul: an experimental framework for full-system machine emulation
NAMEgxemul - an experimental framework for full-system machine emulation
SYNOPSIS[machine, other, and general options] [file ... ]
[general options] @configfile
[userland, other, and general options] file [args ... ]
DESCRIPTIONis a framework for full-system computer architecture emulation. Several processor architectures and machine types have been implemented. It is working well enough to allow unmodified "guest" operating systems (e.g. NetBSD) to run inside the emulator, as if they were running on real hardware.
The emulator emulates (networks of) real machines. The machines may consist of ARM, MIPS, Motorola 88K, PowerPC, and SuperH processors, and various surrounding hardware components such as framebuffers, busses, interrupt controllers, ethernet controllers, disk controllers, and serial port controllers.
The emulator can be invoked in the following ways:
1. When emulating a complete machine, configuration options can be supplied directly on the command line.
2. Options can be read from a configuration file.
3. When emulating a userland environment (syscall-only emulation, not emulating complete machines), then the program name and its argument should be given on the command line. (This mode is not really usable yet.)
The easiest way to use the emulator is to supply settings directly on the command line.
The most important thing you need to supply is the file argument. This is the name of a binary file (an ELF, a.out, COFF/ECOFF, SREC, or a raw binary image) which you wish to run in the emulator. This file might be an operating system kernel, or perhaps a ROM image file. If more than one filename is supplied, all files are loaded into memory, and the entry point (if available) is taken from the last file.
Apart from the name of a binary file, you must also use the -E and/or -e options to select which emulation mode to use. This is necessary because the emulator cannot in general deduce this from the file being executed. For example, a MIPS-based machine from DEC (a DECstation) is very different from a MIPS-based machine from SGI. Use -H to get a list of available emulation modes.
There are three exceptions to the normal invocation usage mentioned above.
1. For DECstation emulation, if you have a bootable DECstation harddisk or CDROM image, then just supplying the diskimage via the -d option is sufficient. The filename of the kernel can then be skipped, as the emulator runs the bootblocks from the diskimage directly and doesn't need the kernel as a separate file.
2. If you supply an ISO9660 CDROM disk image, then using the -j option to indicate a file on the CDROM filesystem to load is sufficient; no additional kernel filename needs to be supplied on the command line.
3. For Dreamcast emulation, when booting e.g. a NetBSD/dreamcast CDROM image, it is enough to supply the disk image (with the correct ISO partition start offset). Bootblocks will be read directly from the CDROM image, and there is no need to supply the name of an external kernel on the command line.
Gzipped kernels are automatically unzipped, by calling the external gunzip program, both when specifying a gzipped file directly on the command line and when loading such a file using the -j option.
Machine selection options:
- -E t
- Try to emulate machine type t. This option is not always needed, if the -e option uniquely selects a machine. (Use -H to get a list of types.)
- -e st
- Try to emulate machine subtype st. Use this together with -E (This option is not always needed, if a machine type has no subtypes.)
- -C x
- Try to emulate a specific CPU type, x. This overrides the default CPU type for the machine being emulated. (Use -H to get a list of available CPU types.)
- -d [modifiers:]filename
as a disk image. By adding one or more modifier characters and then a
colon (":") as a prefix to
you can modify the way the disk image is treated. Available modifiers are:
- Specifies that this is a boot device.
- DISK (this is the default).
- Override the default geometry; use H heads and S sectors-per-track. (The number of cylinders is calculated automatically.)
- IDE. (This is the default for most machine types.)
- Set the base offset for an ISO9660 filesystem on a disk image. The default is 0. A suitable offset when booting from Dreamcast ISO9660 filesystem images, which are offset by 11702 sectors, is 23965696.
- Read-only (don't allow changes to be written to the file).
- Add an overlay filename to an already defined disk image. (A ID number must also be specified when this flag is used. See the documentation for an example of how to use overlays.)
- Force a specific ID number.
For SCSI devices, the ID number is the SCSI ID. For IDE harddisks, the ID number has the following meaning:
- Primary master.
- Primary slave.
- Secondary master.
- Secondary slave.
Unless otherwise specified, filenames ending with ".iso" or ".cdr" are assumed to be CDROM images. Most others are assumed to be disks. Depending on which machine is being emulated, the default for disks can be either SCSI or IDE. Some disk images that are very small are assumed to be floppy disks. (If you are not happy with the way a disk image is detected, then you need to use explicit prefixes to force a specific type.)
For floppies, the gH;S; prefix is ignored. Instead, the number of heads and cylinders are assumed to be 2 and 80, respectively, and the number of sectors per track is calculated automatically. (This works for 720KB, 1.2MB, 1.44MB, and 2.88MB floppies.)
- -I hz
Set the main CPU's frequency to
Hz. This option does not work for all emulated machine modes. It affects
the way count/compare interrupts are faked to simulate emulated time =
real world time. If the guest operating system relies on RTC interrupts
instead of count/compare interrupts, then this option has no effect.
Setting the frequency to zero disables automatic synchronization of emulated time vs real world time, and the count/compare system runs at a fixed rate.
- Enable instruction trace, i.e. display disassembly of each instruction as it is being executed.
- Disable instruction combinations in the dynamic translator.
- -j n
- Set the name of the kernel to n. When booting from an ISO9660 filesystem, the emulator will try to boot using this file. (In some emulation modes, eg. DECstation, this name is passed along to the boot program. Useful names are "bsd" for OpenBSD/pmax, "vmunix" for Ultrix, or "vmsprite" for Sprite.)
- -M m
- Emulate m MBs of physical RAM. This overrides the default amount of RAM for the selected machine type.
- Display the number of executed instructions per second on average, at regular intervals.
- -n nr
Set the number of processors in the machine, for SMP experiments.
Note 1: The emulator allocates quite a lot of virtual memory for per-CPU translation tables. On 64-bit hosts, this is normally not a problem. On 32-bit hosts, this can use up all available virtual userspace memory. The solution is to either run the emulator on a 64-bit host, or limit the number of emulated CPUs to a reasonably low number.
Note 2: SMP simulation is not working very well yet; multiple processors are simulated, but synchronization between the processors does not map very well to how real-world SMP systems work.
- Force a "netboot" (tftp instead of disk), even when a disk image is present (for DECstation, SGI, and ARC emulation).
- -o arg
- Set the boot argument (mostly useful for DEC, ARC, or SGI emulation). Default arg for DEC is "-a", for ARC/SGI it is "-aN", and for CATS it is "-A".
- -p pc
- Add a breakpoint. pc can be a symbol, or a numeric value. (Remember to use the "0x" prefix for hexadecimal values.)
- Disable the built-in (software-only) PROM emulation. This option is useful for experimenting with running raw ROM images from real machines. The default behaviour of the emulator is to "fake" certain PROM calls used by guest operating systems (e.g. NetBSD), so that no real PROM image is needed.
- Use a random bootstrap cpu, instead of CPU nr 0. (This option is only meaningful together with the -n option.)
- Dump register contents for every executed instruction.
- Initialize emulated RAM to random data, instead of zeroes. This option is useful when trying to trigger bugs in a program that occur because the program assumed that uninitialized memory contains zeros. (Use with care.)
- -s flags:filename
Gather statistics based on the current emulated program counter value,
while the program executes. The statistics is actually just a raw dump of
all program counter values in sequence, suitable for post-analysis with
separate tools. Output is appended to
The flags should include one or more of the following type specifiers:
- Virtual. This means that the program counter value is used.
- Physical. This means that the physical address of where the program is actually running is used.
- Instruction call. This type of statistics gathering is practically only useful during development of the emulator itself. The output is a list of addresses of instruction call functions (ic->f), which after some post-processing can be used as a basis for deciding when to implement instruction combinations.
The flags may also include the following optional modifiers:
- Disabled at startup.
- Overwrite the file, instead of appending to it.
Statistics gathering can be enabled/disabled at runtime by using the "statistics_enabled = yes" and "statistics_enabled = no" debugger commands.
When gathering instruction statistics using the -s option, instruction combinations are always disabled (i.e. an implicit -J flag is added to the command line).
- Halt if the emulated program attempts to access non-existing memory.
- Show a trace tree of all function calls being made.
- Enable slow_serial_interrupts_hack_for_linux.
- Use X11. This option enables graphical framebuffers.
- Open up new xterms for emulated serial ports. The default behaviour is to open up xterms when using configuration files, or if X11 is enabled. When starting up a simple emulation session with settings directly on the command line, and neither -X nor -x is used, then all output is confined to the terminal that started in.
- -Y n
- Scale down framebuffer windows by n x n times. This option is useful when emulating a very large framebuffer, and the actual display is of lower resolution. If n is negative, then there will be no scaledown, but emulation of certain graphic controllers will be scaled up by -n times instead. E.g. Using -2 with VGA text mode emulation will result in 80x25 character cells rendered in a 1280x800 window, instead of the normal resolution of 640x400.
- -Z n
- Set the number of graphics cards, for emulating a dual-head or tripple-head environment. (Only for DECstation emulation so far.)
- -z disp
- Add disp as an X11 display to use for framebuffers.
- -u emul-mode
Userland-only (syscall) emulation. (Use
to get a list of available emulation modes.) Some (but not all) of the
options listed under Other options above can also be used with
Note: Userland (syscall) emulation does not really work yet.
- -c cmd
- Add cmd as a command to run before starting the simulation. A similar effect can be achieved by using the -V option, and entering the commands manually.
- Causes the emulator to skip a call to srandom(). This leads to somewhat more deterministic behaviour than running without this option. However, if the emulated machine has clocks or timer interrupt sources, or if user interaction is taking place (e.g. keyboard input at irregular intervals), then this option is meaningless.
- Display a list of available CPU types, machine types, and userland emulation modes. (Most of these don't work. Please read the documentation included in the distribution for details on which modes that actually work. Userland emulation is not included in stable release builds, since it doesn't work yet.)
- Display a list of all available command line options.
- -k n
- Set the size of the dyntrans cache (per emulated CPU) to n MB. The default size is 48 MB.
- Force the single-step debugger to be entered at the end of a simulation.
- Quiet mode; this suppresses startup messages.
- Start up in the single-step debugger, paused.
- Increase verbosity (show more debug messages). This option can be used multiple times.
Configuration file startup:
- @ configfile
- Start an emulation based on the contents of configfile.
For more information, please read the documentation in the doc/ subdirectory of the distribution.
EXAMPLESThe following command will start NetBSD/pmax on an emulated DECstation 5000/200 (3MAX):
"gxemul -e 3max -d nbsd_pmax.img"
nbsd_pmax.img should be a raw disk image containing a bootable NetBSD/pmax filesystem.
The following command will start an emulation session based on settings in the configuration file "mysession". The -v option tells gxemul to be verbose.
"gxemul -v @mysession"
If you have compiled the small Hello World program mentioned in the documentation, the following command will start up an emulated test machine in "paused" mode:
"gxemul -E testmips -V hello_mips"
Paused mode means that you enter the interactive single-step debugger directly at startup, instead of launching the Hello World program.
The paused mode is also what should be used when running "unknown" files for the first time in the emulator. E.g. if you have a binary which you think is some kind of MIPS ROM image, then you can try the following:
"gxemul -vv -E baremips -V 0xbfc00000:image.raw"
You can then use the single-stepping functionality of the built-in debugger to run the code in the ROM image, to see how it behaves. Based on that, you can deduce what machine type it was actually from (the baremips machine is not a real machine), and perhaps try again with another emulation mode.
In general, however, real ROM images require much more emulation detail than GXemul provides, so they can usually not run.
Please read the documentation for more details.
BUGSThere are many bugs. Some of the known bugs are mentioned in the TODO file in the source distribution, some are marked as TODO in the source code itself.
Userland (syscall-only) emulation, i.e. running a userland binary directly without simulating an entire machine, doesn't really work yet.
is in general not cycle-accurate; it does not simulate individual pipe-line stages or penalties caused by branch-prediction misses or cache misses, so it cannot be used for accurate simulation of any actual real-world processor.
is in general not timing-accurate. Many emulation modes try to make the guest operating system's clock run at the same speed as the host clock. However, the number of instructions executed per clock tick can obviously vary, depending on the current CPU load on the host.
AUTHORGXemul is Copyright (C) 2003-2009 Anders Gavare <anders [at] gavare.se>
See http://gavare.se/gxemul/ for more information. For other Copyright messages, see the corresponding parts of the source code and/or documentation.