two-byte operating system does not what I want

149 views Asked by At

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?

2

There are 2 answers

0
C. K. Young On BEST ANSWER

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. :-)

1
johnfound On

CLI will not disable NMI (not maskable interrupts) so, following code is still better:

.loop:
    cli
    hlt
    jmp .loop

It is not clear why Bochs gives 100% CPU load. How you are checking this load? By the real CPU load, or Bochs has it's own virtual CPU load indicator?

I would suggest trying with another virtual machine, like QEMU.

So, the above code will boot and then sleep. If the intention is to reboot the computer, following code should do cold restart

    jmp $ffff:$0000

For warm restart:

    mov  [$472], 1234h
    jmp  $ffff:$0000