1.使用bximage,创建软盘映像。(1 - > fd -> boot.img)
root@ubuntu:~# bximage
========================================================================
bximage
Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
$Id: bximage.cc 13069 2017-02-12 16:51: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.
Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M.
[1.44M]
What should be the name of the image?
[a.img] boot.img
Creating floppy image 'boot.img' with 2880 sectors
The following line should appear in your bochsrc:
floppya: image="boot.img", status=inserted
root@ubuntu:~#
2.编写boot.asm源码,好读书不求甚解,先照抄书中源码。
org 0x7c00
BaseOfStack equ 0x7c00
Lable_Start:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, BaseOfStack
;====== clear screen
mov ax, 0600h
mov bx, 0700h
mov cx, 0
mov dx, 0184h
int 10h
;====== set focus
mov ax, 0200h
mov bx, 0000h
mov dx, 0000h
int 10h
;====== display on screen:Start Booting ...
mov ax, 1301h
mov bx, 000fh
mov dx, 0000h
mov cx, 10
push ax
mov ax, ds
mov es, ax
pop ax
mov bp, StartBootMessage
int 10h
;====== reset floppy
xor ah, ah
xor dl, dl
int 13h
jmp $
StartBootMessage: db "Start Boot"
;====== fill zero until whole sector
times 510 - ($ - $$) db 0
dw 0xaa55
3.用nasm汇编器编译boot.asm源码,生成二进制文件boot.bin
root@ubuntu:~# nasm boot.asm -o boot.bin
4.用dd命令工具把二进制文件boot.bin,复制到boot.img软盘中。
root@ubuntu:~# dd if=boot.bin of=boot.img bs=512 count=1 conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 0.00980426 s, 52.2 kB/s
root@ubuntu:~#
5.编写bochs虚拟机配置文件,粘贴一下源码。
root@ubuntu:~# vi bochsconfig
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/local/share/bochs/VGABIOS-lgpl-latest
floppya: 1_44=boot.img, status=inserted
boot: floppy
6.按bochsconfig配置文件运行bochs虚拟机。
root@ubuntu:~# bochs -f bochsconfig
========================================================================
Bochs x86 Emulator 2.6.9
Built from SVN snapshot on April 9, 2017
Compiled on Mar 28 2019 at 10:03:12
========================================================================
00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/lib/bochs/plugins'
00000000000i[ ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
00000000000i[ ] lt_dlhandle is 0x1d26220
00000000000i[PLUGIN] loaded plugin libbx_usb_common.so
00000000000i[ ] lt_dlhandle is 0x1d26ba0
00000000000i[PLUGIN] loaded plugin libbx_unmapped.so
00000000000i[ ] lt_dlhandle is 0x1d273a0
00000000000i[PLUGIN] loaded plugin libbx_biosdev.so
00000000000i[ ] lt_dlhandle is 0x1d27ce0
00000000000i[PLUGIN] loaded plugin libbx_speaker.so
00000000000i[ ] lt_dlhandle is 0x1d28ad0
00000000000i[PLUGIN] loaded plugin libbx_extfpuirq.so
00000000000i[ ] lt_dlhandle is 0x1d29310
00000000000i[PLUGIN] loaded plugin libbx_parallel.so
00000000000i[ ] lt_dlhandle is 0x1d2af20
00000000000i[PLUGIN] loaded plugin libbx_serial.so
00000000000i[ ] lt_dlhandle is 0x1d2f2d0
00000000000i[PLUGIN] loaded plugin libbx_iodebug.so
00000000000i[ ] reading configuration from bochsconfig
------------------------------
Bochs Configuration: Main Menu
------------------------------
This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate. Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found. When you are satisfied with the configuration, go
ahead and start the simulation.
You can also start bochs with the -q option to skip these menus.
1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now
Please choose one: [6] 6
接下来按C回车运行bochs虚拟机
接下来就能看到bochs虚拟机上第一行显示"Start Boot"的字符串了,这个是之前boot.asm源码里面定义的。
到此,boot的开发已经完成。开心不?容易不?
点开shell界面,按下Ctrl+C后,输入exit命令退出bochs虚拟机
接下来我们要知其然,知其所以然。汇编源代码需要自己理解,开发终究是自己的事。
------------------------------------------------------------------------------------------
预留