bochs 基本使用测试

参考博客:https://blog.csdn.net/qq_66026801/article/details/129753062

我参考的书是 Orange's 一个操作系统的实现

首先用bximage 创建一个a.img的软盘

[xxx@xxx os]$ bximage

ERROR: Parameter -func missing - switching to interactive mode.

========================================================================
                                bximage
  Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
                                  $Id$
========================================================================

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]

Creating floppy image 'a.img' with 2880 sectors

The following line should appear in your bochsrc:
  floppya: image="a.img", status=inserted
[xxx@xxx os]$ ls
a.img
[xxx@xxx os]$ vim boot.asm
a.img  boot.asm
[xxx@xxx os]$ nasm boot.asm -o boot.bin
[xxx@xxx os]$ ls
a.img  boot.asm  boot.bin
[xxx@xxx os]$ dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000310029 s, 1.7 MB/s
[xxx@xxx os]$ ls
a.img  boot.asm  boot.bin
[xxx@xxx os]$ vim bochsrc

boot.asm:

    org 07c00h ; 告诉编译器程序加载到 7c00处
    mov ax, cs
    mov ds, ax
    mov es, ax
    call DispStr ; 调用显示字符串例程
    jmp $ ; 无限循环
DispStr:
    mov ax, BootMessage
    mov bp, ax ; es:bp = 串地址
    mov cx, 16 ; cx = 串长度
    mov ax, 1301h ; ah = 13, al = 01h
    mov bx, 000eh ; 页号为 0(bh = 0) 黑底红字(bl = 0Ch,高亮)
    mov dl, 0
    int 10h ; 10h 号中断
    ret
BootMessage:
    db "Hello, OS world!"
    times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为
    dw 0xaa55 ; 结束标志

bochsrc:

megs: 32
display_library: x
floppya: 1_44=a.img, status=inserted
boot: floppy

启动

bochs -f bochsrc
...
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
...

Bochs internal debugger, type 'help' for help or 'c' to continue
Switching to CPU0
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
<bochs:1> c

这样按理说会弹出一个窗口,上面有hello world。

文章目录