Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running assembly in an empty virtual machine instance?

How is it possible to run assembly code in an empty virtual machine (virtualbox, vmware) instance?

I want to try writing a simple bootloader. My aim is to work for a hobby operating system.

like image 815
tolga Avatar asked Oct 21 '13 10:10

tolga


Video Answer


2 Answers

You have to write a proper master boot record on the virtual hdd. In order to do this one has to learn how boot process exactly works and at which addresses the code gets executed. Here is not enough space to write all details, but there are many internet pages describing them. Briefly, after initial boot post (power-on self test) the BIOS searches storage devices until it finds one with the last two bytes of the first sector containing the little-endian word AA55h (the MBR boot signature). Then BIOS loads the boot sector from the bootable device to address 0000h:7C00h (note that it is all done in real x86 mode) and transfers execution to the boot code. There is a space limit of only 512 bytes for MBR, so the booting is usually forwarded to the next stage, i.e. the small code in MBR is used to load another boot code somewhere from disk into memory and then transfers the execution there. Booting from a virtual floppy may be somewhat different. In modern systems MBR is exchanged with GPT. As you can see there are many things involved here, although not so difficult as they may seem to be.

like image 84
Igor Popov Avatar answered Sep 24 '22 20:09

Igor Popov


Writing the boot sector in a virtual box is the same as writing it on a real machine. You have to create a boot disc, which will install your boot loader on your target drive. So you must basically execute these steps:

1. Write a bootloader and put it in an imagefile. (http://wiki.osdev.org/Babystep1)
2. create a boot disc, which will put the image into the bootsecotr of your target harddisc (This can be a simple DOS disk or a linux environment, hwatever. (http://wiki.osdev.org/Bootable_CD)
3. boot from the loader in your environment.

Looking at the links that I posted in my first comment above, should explain all these in detail.

like image 22
Devolus Avatar answered Sep 22 '22 20:09

Devolus