Bochs
From OSR
Contents |
What is Bochs?
Bochs is a program that simulates a complete Intel x86 computer. It can be configured to act like a 386, 486, Pentium, Pentium Pro, or x86-64 CPU, including optional MMX, SSE, PAE, SMP, APIC instructions. Bochs interprets every instruction from power-up to reboot, and has device models for all of the standard PC peripherals: keyboard, mouse, VGA card/monitor, disks, timer chips, network card, etc. Because Bochs simulates the whole PC environment, the software running in the simulation believes it is running on a real machine. This approach allows Bochs to run a wide variety of software with no modification, including the most popular x86 operating systems: Windows 95/98/NT/2000, all Linux flavors, all BSD flavors, and more.
Bochs is written in the C++ programming language, and is designed to run on many different host platforms, including x86, PPC, Alpha, Sun, and MIPS. No matter what the host platform is, Bochs still simulates x86 software. In other words, it does not depend on the native instructions of the host machine at all.
Installing Bochs
You can download the latest release of Bochs from here. For Linux, you can download either the RPM or the source package. Binary packages will be quicker to install, however, some features can only be enabled if you compile Bochs yourself (e.g. SMP support and the Bochs debugger).
Download the gzipped tarball containing the source code, called bochs-version.tar.gz, untar it, and then run the configure script to build it with options to support the x86_64 chipset and the virtual ne2k ethernet device. We also enable the terminal (curses) and nogui display drivers so that it can be run on a remote machine without using X. There are many compiletime configuration options that can be specified.
tar zxvf bochs-2.3.tar.gz
cd bochs-2.3
./configure \
--enable-cpu-level=6 \
--enable-x86-64 \
--enable-smp \
--enable-vbe \
--enable-debugger \
--enable-x86-debugger \
--enable-pnic \
--enable-ne2000 \
--enable-pci \
--enable-pcidev \
--with-term \
--with-nogui \
--with-x11 \
After configure finishes checking and generating the makes files, issue the make command. Then change to su (super user) and issue the make install.
make su -c 'make install'
Configuring Bochs
The Bochs operating environment is regulated by a single file called .bochsrc, which is located in the base directory. Bochs uses this file to know where to look for disk images, how much memory the virtual system should emulate, how the emulation layer should work, etc. Further details are in bochs configuration. When you start Bochs, it looks around for its configuration file and then parses it. You can also specify the configuration file that Bochs should use using the -f flag (bochs -f bochsrc.txt).
To use the virtual serial port it is necessary to do some hackery on the config file. Start an xterm or other emulator and run `tty ; sleep 360000`. Update the `com1 dev` line in the config file to use the pty named for the xterm, then run bochs as normal. Attempts to pre-allocate a pty so far have been unsuccessful with modern Linux.
Configuration file sample for the nway lwk:
# $Id$ # # N-Way lightweight kernel Bochs configuration # # Simulate a fairly stripped down 2 CPU x 2 core system with a PCI # bus an ne2k card installed. # log: bochsout.txt debugger_log: - romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000 vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest # Dual CPU, dual core, one thread per core cpu: count=2:2:1, ips=10000000, reset_on_triple_fault=1 megs: 256 vga: none ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 ata0-master: type=disk, mode=flat, path="root.img", cylinders=0, heads=0, spt=0 boot: disk panic: action=ask error: action=report info: action=report debug: action=ignore # We really should use the comport for our serial console in our LWK. # This is still to be determined. #com1: enabled=1, mode=term, dev=/dev/ttyp9 ne2k: enabled=1, ioaddr=0x240, irq=9, mac=b0:c4:20:00:00:00, ethmod=linux, ethdev=eth0 i440fxsupport: enabled=1, slot1=ne2k
Starting Bochs
To start Bochs, issue the following command from the command line:
- bochs –f bochsrc.txt
The following list shows some arguments that can be used on the command line:
- -q: quick start (skip configuration interface)
- -f filename: specify configuration file
- -n: don't try to load a configuration file
- --help: display help message and exit
Start the simulation by selecting the 'Begin simulation' option from the menu. Bochs will then read the configuration file and open the emulation window, which is like the monitor of your new machine.
Nothing will work without a disk image. To get started you may download one from the Bochs diskimage website. For NWay work we build our own root file system, as described in Compute Linux.
To use the ethernet device, you must run bochs as root or have the 'CAP_NET_RAW' priviledge. Due to a bug(?) in the eth_linux driver, the bochs client can not contact the host system over the ethernet. This may be fixable with the tuntap driver or perhaps some iptables work.