We shall install both bochs and bochs-x packages first to realize further examples in this book.
# sudo apt-get install bochs bochs-x
boot.s .globl begtext, begdata, begbss, endtext, enddata, endbss .text begtext: .data begdata: .bss begbss: .text BOOTSEG=0x07c0 entry start start: jmpi go, BOOTSEG go: mov ax, cs mov ds, ax mov es, ax mov [msg1+17], ah mov cx, #20 mov dx, #0x1004 mov bx, #0x000c mov bp, #msg1 mov ax, #0x1301 int 0x10 loop1: jmp loop1 msg1: .ascii "Loading system ..." .byte 13, 10 .org 510 .word 0xAA55 .text endtext: .data enddata: .bss endbss:
# as86 -0 -a -o boot.o boot.s
# ld86 -0 -s -o boot boot.o
# dd bs=32 if=boot of=boot.img skip=1
Now we'll start bochs to test our boot image. However we shall edit the configuration before testing. I tried in this way
# bochs
======================================================================== Bochs x86 Emulator 2.4.2 Build from CVS snapshot on November 12, 2009 ======================================================================== 00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins' 00000000000i[ ] BXSHARE not set. using compile time default '/usr/share/bochs' 00000000000e[ ] Switching off quick start, because no configuration file was found. ------------------------------ 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: [2] 3 ------------------ Bochs Options Menu ------------------ 0. Return to previous menu 1. Logfile options 2. Log options for all devices 3. Log options for individual devices 4. CPU options 5. Memory options 6. Clock & CMOS options 7. PCI options 8. Bochs Display & Interface options 9. Keyboard & Mouse options 10. Disk options 11. Serial / Parallel / USB options 12. Network card options 13. Sound Blaster 16 options 14. Other options 15. User-defined options Please choose one: [0] 10 ------------------ Bochs Disk Options ------------------ 0. Return to previous menu 1. First Floppy Drive 2. Second Floppy Drive 3. ATA channel 0 4. First HD/CD on channel 0 5. Second HD/CD on channel 0 6. ATA channel 1 7. First HD/CD on channel 1 8. Second HD/CD on channel 1 9. ATA channel 2 10. First HD/CD on channel 2 (disabled) 11. Second HD/CD on channel 2 (disabled) 12. ATA channel 3 13. First HD/CD on channel 3 (disabled) 14. Second HD/CD on channel 3 (disabled) 15. Boot Options Please choose one: [0] 1 ------------------ First Floppy Drive ------------------ What type of floppy drive? [none] ? Type of floppy drive Valid values are: none, 5.25" 360K, 5.25" 1.2M, 3.5" 720K, 3.5" 1.44M, 3.5" 2.88M What type of floppy drive? [none] 3.5" 1.44M Enter new filename, or 'none' for no disk: [none] /home/yenping/workspace/boot.img What type of floppy media? (auto=detect) [none] ? Type of floppy media Valid values are: none, 1.2M, 1.44M, 2.88M, 720K, 360K, 160K, 180K, 320K, auto What type of floppy media? (auto=detect) [none] 1.44M Is media inserted in drive? [no] yes ------------------ Bochs Disk Options ------------------ 0. Return to previous menu 1. First Floppy Drive 2. Second Floppy Drive 3. ATA channel 0 4. First HD/CD on channel 0 5. Second HD/CD on channel 0 6. ATA channel 1 7. First HD/CD on channel 1 8. Second HD/CD on channel 1 9. ATA channel 2 10. First HD/CD on channel 2 (disabled) 11. Second HD/CD on channel 2 (disabled) 12. ATA channel 3 13. First HD/CD on channel 3 (disabled) 14. Second HD/CD on channel 3 (disabled) 15. Boot Options Please choose one: [0] 15 ------------ Boot Options ------------ 0. Return to previous menu 1. Boot drive #1: floppy 2. Boot drive #2: none 3. Boot drive #3: none 4. Skip Floppy Boot Signature Check: no 5. 32-bit OS Loader Hack Please choose one: [0] 0 ------------------ Bochs Disk Options ------------------ 0. Return to previous menu 1. First Floppy Drive 2. Second Floppy Drive 3. ATA channel 0 4. First HD/CD on channel 0 5. Second HD/CD on channel 0 6. ATA channel 1 7. First HD/CD on channel 1 8. Second HD/CD on channel 1 9. ATA channel 2 10. First HD/CD on channel 2 (disabled) 11. Second HD/CD on channel 2 (disabled) 12. ATA channel 3 13. First HD/CD on channel 3 (disabled) 14. Second HD/CD on channel 3 (disabled) 15. Boot Options Please choose one: [0] 0 ------------------ Bochs Options Menu ------------------ 0. Return to previous menu 1. Logfile options 2. Log options for all devices 3. Log options for individual devices 4. CPU options 5. Memory options 6. Clock & CMOS options 7. PCI options 8. Bochs Display & Interface options 9. Keyboard & Mouse options 10. Disk options 11. Serial / Parallel / USB options 12. Network card options 13. Sound Blaster 16 options 14. Other options 15. User-defined options Please choose one: [0] 0 ------------------------------ 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] 4 Save configuration to what file? To cancel, type 'none'. [none] myBochs.cfg 00000000000i[ ] write current configuration to myBochs.cfg Wrote configuration to 'myBochs.cfg'. ------------------------------ 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
Next time, we can start bochs with our config as below.
# bochs -f myBochs.cfg