Installing Bochs

Bochs is an x86-emulator that can be installed on different platforms. Here I describe my experiences of installing Bochs on Linux and on MacOS Mountain Lion.

Ubuntu Linux

Installing Bochs on Ubuntu was simple. I did

sudo apt-get install bochs

Then I located the Bochs configuration file. It was found, and copied to the directory where I intended to run Bochs, as

cp /usr/local/share/doc/bochs/bochsrc-sample.txt bochsrc.txt

My goal was to simulate an x86-computer with a floppy-disc unit. Changes were therefore done, in the file bochsrc.txt. The changes can be seen from the diff-command

diff /usr/local/share/doc/bochs/bochsrc-sample.txt bochsrc.txt

as

387c387
< floppya: 1_44=/dev/fd0, status=inserted
---
> #floppya: 1_44=/dev/fd0, status=inserted
392c392
< #floppya: 1_44=a.img, status=inserted, write_protected=1
---
> floppya: 1_44=arch/x86_fd_target/a.img, status=inserted, write_protected=1
474c474
< ata0-master: type=disk, mode=flat, path="30M.sample"
---
> #ata0-master: type=disk, mode=flat, path="30M.sample"
494,495c494,495
< #boot: floppy
< boot: disk
---
> boot: floppy
> #boot: disk

Then I am ready to run Bochs, using the command

bochs -f arch/x86_fd_target/bochsrc.txt -q

resulting in a simulated PC screen, as

bochs hello

Linux

The Bochs project is found at http://bochs.sourceforge.net.

After reading information about the latest release, I navigated to the releases page. I then downloaded release 2.6 in source format, resulting in download of the file

bochs-2.6.tar.gz

I then unpacked the source and navigated to the newly created bochs source directory, as

tar zxvf bochs-2.6.tar.gz
cd bochs-2.6

Then the configure script shall be run. Since I was not root on the machine, I used a prefix to configure, indicating the directory where I wanted Bochs to be installed. The configure command used was

./configure --prefix=/nobackup/local/prog/bochs

Bochs was then built, using the command

make

and installed using the command

make install

Then I located the Bochs configuration file. It was found, and copied to the directory where I intended to run Bochs, as

cp /nobackup/local/prog/bochs/share/doc/bochs/bochsrc-sample.txt arch/x86_fd_target/bochsrc.txt

My goal was to simulate an x86-computer with a floppy-disc unit. Changes were therefore done, in the file bochsrc.txt. The changes can be seen from the diff-command

diff /nobackup/local/prog/bochs/share/doc/bochs/bochsrc-sample.txt arch/x86_fd_target/bochsrc.txt

as

190c190
< cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
---
> cpu: count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
415c415
< floppya: 1_44=/dev/fd0, status=inserted
---
> #floppya: 1_44=/dev/fd0, status=inserted
420c420
< #floppya: 1_44=a.img, status=inserted, write_protected=1
---
> floppya: 1_44=arch/x86_fd_target/a.img, status=inserted, write_protected=1
502c502
< ata0-master: type=disk, mode=flat, path="30M.sample"
---
> #ata0-master: type=disk, mode=flat, path="30M.sample"
522,523c522,523
< #boot: floppy
< boot: disk
---
> boot: floppy
> #boot: disk
636c636
< debug: action=ignore, pci=report # report BX_DEBUG from module 'pci'
---
> debug: action=ignore, # pci=report # report BX_DEBUG from module 'pci'

I also added the following changes

export PATH=/nobackup/local/prog/bochs/bin:$PATH
export BXSHARE=/nobackup/local/prog/bochs/share/bochs

to my setup script, where I also set up other environment variables.

Then I am ready to run Bochs, using the command

bochs -f arch/x86_fd_target/bochsrc.txt -q

resulting in a simulated PC screen as shown above.

Mac Mountain Lion

I navigated to the releases page. I then downloaded release 2.6 in source format, resulting in download of the file

bochs-2.6.tar.gz

I then unpacked the source and navigated to the newly created bochs source directory, as

tar zxvf bochs-2.6.tar.gz
cd bochs-2.6

The configure command used was

./configure --with-x11

The –with-x11 indicates that X11 shall be used. For this purpose I had installed XQuartz, as described by Apple in this support note.

Bochs was then built, using the command

make

and installed using the command

sudo make install

I used the same configuration file as described above for Ubuntu, and I could then run Bochs using the command

bochs -f arch/x86_fd_target/bochsrc.txt -q

resulting in a simulated PC screen, as shown above.

Advertisements

Installing NASM

NASM is an assembler for x86-based computers. Here I describe my experiences from installing NASM on Linux and on Mac Mountain Lion.

Ubuntu Linux

NASM was installed using the command

sudo apt-get install nasm

Linux

Starting from the NASM site I navigated to the NASM download page.

I downloaded NASM version 2.10.05 in source format, by downloading the file

nasm-2.10.05.tar.bz2

I unpacked the file and navigated to the newly created directory, using the commands

tar xvjf nasm-2.10.05.tar.bz2
cd nasm-2.10.05

As a preparation for building NASM, a configure command shall be issued. Since I was not root for the machine, I used a prefix, indicating the place where I wanted NASM to be installed. The command used was

./configure --prefix=/nobackup/local/prog/nasm

Then I could build and install NASM, using the commands

make
make install

I also added the following changes

export PATH=/nobackup/local/prog/nasm/bin:$PATH

to my setup script, where I also set up other environment variables.

Mac Mountain Lion

Starting from the NASM site I navigated to the NASM download page. From there I continued to the Mac OS download page, from where I downloaded the file

nasm-2.10.05-macosx.zip

Unzipping this file resulted in a directory named nasm-2.10.05 being created.

I now noticed that I already had nasm on my computer, as could be seen from

Olas-MacBook-Air:nasm-2.10.05 oladahl$ nasm -v
NASM version 0.98.40 (Apple Computer, Inc. build 11) compiled on Aug 4 2012

That version was however older than the newly downloaded, as could be seen by doing

Olas-MacBook-Air:nasm-2.10.05 oladahl$ ./nasm -v
NASM version 2.10.05 compiled on Sep 9 2012

I decided to put the downloaded nasm in a directory called prog/nasm inside my home directory. I moved it there using

mkdir -p ~/prog/nasm
mv * ~/prog/nasm

I then added the following changes

export PATH=~/prog/nasm:$PATH

to my setup script, where I also set up other environment variables. After having rerun the setup script I could use the downloaded nasm, after first having verified that it was found using

Olas-MacBook-Air:i1_bare_metal oladahl$ nasm -v
NASM version 2.10.05 compiled on Sep 9 2012

Installing an ARM cross-compiler on Mac Mountain Lion

Here I will describe my installation of an ARM cross compiler, on a MacBook Air with Mac OS Mountain Lion.

After some searching on the net I decided to try the YAGARTO toolchain.

Navigating to the download place for Mac, I downloaded the file

yagarto-bu-2.22_gcc-4.7.1-c-c++_nl-1.20.0_gdb-7.4.1_eabi_intelmac_20120616.dmg

Using this file however led to an error, saying

selected processor does not support requested special purpose register -- `mrs r0,cpsr'

I reverted to an older version, found at YAGARTO’s Sourceforge page. This led to download of the file

yagarto-bu-2.21_gcc-4.6.2-c-c++_nl-1.19.0_gdb-7.3.1_eabi_intelmac_20111119.dmg

Double-clicking on this downloaded file, I was able to install the toolchain.

I then added the following changes

export ARM_GCC_LOCATION=/Users/oladahl/yagarto/yagarto-4.6.2/bin
export PATH=$ARM_GCC_LOCATION:$PATH

to my setup script, where I also set up other environment variables.

Now I can start programming for ARM!

As an example, I can compile, link, and run the example described in Chapter The Bare Metal in the book Into Embedded.

Installing QEMU

QEMU is an open source computer emulator. Here I describe how I installed QEMU on Linux and on Mac Mountain Lion.

My goal was to create a simulator for machines with ARM architecture and for machines with x86 architecture.

Updates to this post

  • July 15, 2013 – changed the section on Ubuntu Linux to cover QEMU 1.5.1 instead of QEMU 1.2.0.

Ubuntu Linux

Starting from the QEMU home page I navigated to the download page. From there I downloaded the file

qemu-1.5.1.tar.bz2

I unpacked the file, and navigated to the directory created during the unpacking, using the commands

tar xvjf qemu-1.5.1.tar.bz2
cd qemu-1.5.1

As a preparation, I needed to update my Ubuntu 13.04 installation. It turned out that the following installations were needed:

sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could then configure QEMU, using the command

./configure --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc --enable-sdl

I could then build and install, using

make
sudo make install

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.elf

and simulation of an x86 computer, e.g. as

qemu-system-x86_64 -kernel prog_x86_grub_target.elf

Problems encountered – I had some trouble before realizing which packages to add to Ubuntu in order to get QEMU to build. The first thing that happened was that the configure command failed, with

ERROR: zlib check failed
Make sure to have the zlib libs and headers installed.

which, after some searching, led me to install zlib as

sudo apt-get install zlib1g-dev

Then I got a message I recognized from my installation of QEMU on Mac, saying that

ERROR: glib-2.12 required to compile QEMU

which, again after some searching, led to the installation of glib as

sudo apt-get install libglib2.0

Configure was now happy but make was not. The make command gave an error, as

(cd /home/ola/Downloads/qemu-1.5.1/pixman; autoreconf -v --install)
/bin/sh: autoreconf: command not found
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 127

Trying the command autoreconf, as

ola@ola-Aspire-S3-391:~/Downloads/qemu-1.5.1$ autoreconf
The program 'autoreconf' can be found in the following packages:
* autoconf

led to the installation of autoconf, as

sudo apt-get install autoconf

An error telling me to install libtool then appeared, as

../../lib/autoconf/general.m4:2678: AC_LINK_IFELSE is expanded from...
configure.ac:552: the top level
configure.ac:75: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
make: *** [/home/ola/Downloads/qemu-1.5.1/pixman/configure] Error 1
make: *** Deleting file `/home/ola/Downloads/qemu-1.5.1/pixman/configure'

which, by help from Erik Rull, led me to the installation of libtool, as

sudo apt-get install libtool

Now everything built, and I could also do an installation of QEMU, as

sudo make install

The ARM simulation worked fine, but there was no screen in the x86 simulation. I guessed that I needed also SDL for this purpose, and after the installation of sdl, as

sudo apt-get install libsdl-console
sudo apt-get install libsdl-console-dev

I could see a console, and the long-awaited “Hello, world”-message from my program.

Linux

I downloaded and unpacked QEMU in the same way as described above for Ubuntu Linux.

Then, since I was not root on the machine, I used the configure command

./configure --prefix=/nobackup/local/prog/qemu --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

followed by commands for build and installation, as

make
make install

I also added the following changes

export PATH=/nobackup/local/prog/qemu/bin:$PATH

to my setup script, where I also set up other environment variables.

I could then use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin

Mac Mountain Lion

I downloaded and unpacked QEMU 1.2.0 in the same way as described above for Ubuntu Linux.

Then, based on information from Ruben Schade, I used the configure command

./configure --enable-cocoa --target-list=i386-softmmu,arm-softmmu,x86_64-softmmu --disable-vnc

This command generated an error, telling me that “glib-2.12” was “required to compile QEMU”. I searched for this error, and after having read at this MacPorts-related page, I ended up doing

sudo port install glib-2.12
sudo port selfupdate
sudo port upgrade outdated

which, as a result, made it possible to redo the configure command as decribed above.

I then built QEMU, which succeeded but with several warnings, and installed it, using

make
sudo make install

I could now use QEMU, for simulation of an ARM computer, e.g. as

qemu-system-arm -M realview-pb-a8 -nographic -kernel prog_arm_rpb_a8.bin