Search code examples
assemblybochsx86-16

two-byte operating system does not what I want


I created a floppy boot image from an example, it should:

  1. disable all interrups
  2. reboot

However, once I start it with bochs, it consumes 100% CPU until I kill it.

Here is the floppy image:

$ hd floppy.img
00000000  fa f4 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00168000

Disassembled image:

$ objdump -b binary -D floppy.img -m i386

floppy.img:     file format binary


Disassembly of section .data:

00000000 :
       0:   fa                      cli    
       1:   f4                      hlt    
    ...
     1fe:   55                      push   %ebp
     1ff:   aa                      stos   %al,%es:(%edi)

Bochs output (pastebin).

bochsrc.txt:

romimage:    file=/usr/share/bochs/BIOS-bochs-latest, address=0xe0000
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest 
floppya: 1_44=floppy.img, status=inserted 
boot: a
log: OSDev.log
mouse: enabled=0
megs: 32
display_library: sdl

I run bochs this way:

However, once I start it with bochs, it consumes 100% CPU until I kill it.

$ bochs -f bochsrc.txt

Bochs version: 2.4.6-4, running on ubuntu 12.04 i686.

What am I doing wrong?


Solution

  • hlt does not reboot; that's not what it's for. It pauses the processor until an interrupt arrives, and since you've disabled interrupts, it will just sit there doing nothing forever.

    As to why the emulator consumes 100% CPU, that's probably due to the way the emulator is implemented. On (some versions of) Linux, hlt is used to idle the processor until the next timeslice, so of course it doesn't make the processor busy-wait. :-)