1

For learning bootstrapping of operating systems I do some simple tests this way:

  • I install oracle viratualbox and create hdd disk

  • I install hex-editor HxD and write code to this hdd disk, opening the file which presents this hdd

In the end of first 512-byte sector I write 55 AA in 1FE and 1FF bytes consiquently,

and other code I write from first byte of the first sector.

In this way I must unblock hdd file from HxD, because virtualbox can't start it until this is done.

I want to use a virtual machine or another real machine (the second way is less convenient), because it creates an independent development environment.

How can I more efficiently do this tests for learning bootstrapping (and after simple developing) operating system ?

jah
  • 157
  • 1
  • 4
  • 13

1 Answers1

4

When I do this sort of development I build a disk image from scratch and point the VM at it as a floppy disk. In this way, the output of your assembler, the object file, can be a complete boot sector for a floppy and you can easily chain load further sectors. For example:

;   x86 architecture systems all support MBR style boot sectors.  An
;   MBR boot sector must be 512 bytes in length and have machine
;   language code originating at 0000:7c00.  Additionally, it must
;   have the signature "0x55aa" as the final word in the sector or it
;   is not a valid boot sector.



org 0x7c00                  ; BIOS will load the MBR to this location 
                            ; and then jump here to continue execution

; Your code here!

                            ; As stated above, the boot sector must 
times   510-($-$$) db 0     ; Create padding to fill out to 510 bytes
dw      0xaa55              ; Magic number in the trailer of a boot sector
                            ; We write it as 0xaa55 because we're little
                            ; endian and it will be reversed to the required
                            ; 0x55 0xaa

Simply add your initial code. Create a link to the object file that is named "floppy.img" or something like that and then tell VirtualBox where to find it. Voila!

You didn't ask, but I'm hoping that you can see that you can actually put all of your code in this file; simply add the code to be chain loaded from later sectors after the 0xaa55 and you can simply load it to memory because you know that it falls at the beginning of the next sector.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
  • If you run into trouble let me know. I can certainly post more example code to flesh that out. I didn't want to take away from your fun, though. :) – David Hoelzer Apr 19 '15 at 18:35
  • oh, thanks so much, now I will try to print "Hello, world" to the screen in the beggining of mbr, i'm deep begginer and now use hiew32 to convert assembler to binary :) – jah Apr 19 '15 at 19:22
  • I discover fasm (http://flatassembler.net/) - good way to convert assembler commands to hex and also discover bochs (http://bochs.sourceforge.net/) - IA-32 emulator – jah Apr 27 '15 at 17:48