1 簡介
1.1 資源
1.bochs-2.6.8源碼下載鏈接:鏈接
1.2 環境搭建
1 虛擬機環境
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
$ file /sbin/init
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x7aa29ded613e503fb09fb75d94026f3256f01e7a, stripped
wityuan@ubuntu:~/Downloads$
2 安裝必要工具
$ sudo apt-get install vgabios bochs-x bximage bochs-sdl xorg-dev nasm bochsbios g++
3 編譯,安裝
編譯,安裝bochs.
$ sudo ./configure --enable-debugger --enable-disasm
$ sudo make
$ sudo make install
4 編寫程序,執行程序
a.編寫程序,命名為hello.asm:
org 07c00h
mov ax,cs
mov ds,ax
mov es,ax
call DispStr
jmp $
DispStr:
mov ax,Str
mov bp,ax
mov cx,13
mov ax,01301h
mov bx,000ch
mov dl,0
int 10h
ret
Str: db "hello world"
times 510-($-$$) db 0
dw 0xaa55
b.編譯程序
$ nasm hello.asm -o hello.bin
c.制作floppy文件
首先制作空test.img磁盤:
$ bximage
bximage
========================================================================
bximage
Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
$Id: bximage.cc 12690 2015-03-20 18:01:52Z vruppert $
========================================================================
1. Create new floppy or hard disk image
2. Convert hard disk image to other format (mode)
3. Resize hard disk image
4. Commit 'undoable' redolog to base image
5. Disk image info
0. Quit
Please choose one [0] 1
Create image
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd
Choose the size of floppy disk image to create, in megabytes.
Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M.
[1.44M] 1.44M
What should be the name of the image?
[a.img] test.img
Creating floppy image 'test.img' with 2880 sectors
The following line should appear in your bochsrc:
floppya: image="test.img", status=inserted
$ dd if=hello.bin of=test.img bs=512 count=1 conv=notrunc
d.編寫bochsrc文件
bochsrc文件內容為:
megs:32
romimage:file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage:file=/usr/share/bochs/VGABIOS-lgpl-latest
floppya:1_44=test.img,status=inserted
boot:floppy
mouse:enabled=0
keyboard:keymap=/usr/share/bochs/keymaps/x11-pc-us.map
e.執行:
$ bochs -f bochsrc
f.啟動成功,可以看到如下界面:
bochs啟動成功
2 bochs操作系統測試
基于bochs,我們可以測試幾個操作系統,以便可以自己去寫一個操作系統,來熟悉x86結構。
1 MenuetOS
我也貼一張使用軟盤啟動后的界面:
MenuetOS啟動界面.png
2 ReactOS
官網地址:鏈接
關于該系統,可以在官網上下載,然后在vmware上進行安裝,我安裝后,體驗的系統效果如下圖所示:
系統啟動-1.png
系統啟動-2.png
系統啟動-3.png