bochsを使ってHello World!
x86仮想マシンのbochsを使ってみました。オプションの設定に苦労した。
以下、ブートセクタにHello Worldを出すコードを入れたFDイメージをつくり、bochsで起動させています。
FDイメージの作成
; hello.asm org 0x7C00 ; start address for BIOS start: mov si, msg putc: lodsb ; load a byte at "si" into "al", then inc "si" cmp al, 0x00 jz exit mov ah, 0x0E ; print ascii mov bl, 0x07 ; set color white int 10h ; display access jmp putc exit: jmp exit ; infinite loop :-p msg: db 'Hello World!', 0x0A, 0x0D, 0x00 padding: ;; $: line top address (inf loop: jmp $) ;; $$: current section(.xxx) address (($-$$): a distance to its line) times 510-($-$$) db 0x00 ; padding by 0 last of code to 510 bytes db 0x55, 0xAA ; 2byte magic number for boot sector check
以下のbashコマンドでFDイメージを作成。アセンブラはyasmを使用しました。nasmの64bit対応みたい。
$ yasm hello.asm -o hello.bin -f bin $ dd if=/dev/zero of=hello.fd144.img bz=512 count=2880 $ dd if=hello.bin of=hello.fd144.img conv=notrunc
アセンブラで512バイトのブートセクタhello.binをつくり、空の1.44MBイメージhello.fd144.imgを作って、その先頭に埋め込んでいます。
bochsのインストール
ubuntuでは、bochsとbochs-termパッケージを入れます。後者は、仮想マシンのディスプレイをターミナル上に出すプラグインライブラリです(ほかにはbochs-xなど)。
apt-get install bochs bochs-term
bochsで起動させる
ここが問題で、以下のようにやってます。
bochs "floppya: 1_44=hello.fd144.img, status=inserted" \ "display_library: term" "log: hello.fd144.log" "boot: a"
このコマンドを立ち上げると、メニューが出てくるので、6 (Begin simurator)を入力すれば起動し、以下の状態になり、ます。
Plex86/Bochs VGABios current-cvs 24 Jun 2008 This VGA/VBE Bios is released under the GNU LGPL Please visit : . http://bochs.sourceforge.net . http://www.nongnu.org/vgabios Bochs VBE Display Adapter enabled Bochs BIOS - build: 08/15/08 $Revision: 1.209 $ $Date: 2008/06/02 20:08:10 $ Options: apmbios pcibios eltorito rombios32 Press F12 for boot menu. Booting from Floppy... Hello World!
この端末は、入力はすべてbochsに乗っ取られてます。
別の端末からbochsプロセスを殺すことで、終わらせます。
killall -s 9 bochs-bin