I am an electrical engineer who has recently discovered the need to modify the code in the MBR. Basically I need the ability to execute code on the HDD before, the OS starts up
I think your best way is with linux, it has nasm
for compiling, dd
for cluster copying (which means MBR as well), and even a boot loader menu (lilo
for example) if you don't want to mess with your actual partitions.
I had to make my own boot sequence last year. Basically, I had this:
LILO boot menu:
-> WindowsXP
-> linux
I wanted to do something seperately on an MBR, without affecting the actual install, so I created a new (small) partition and added that to the LILO list (omitting details here), which gave this:
LILO boot menu:
-> WindowsXP
-> linux
-> TESTMBR
That way, since every partition has its own MBR as well, I could put any whacky code I wanted in there without the risk of locking myself out (which is a little annoying to fix).
To actually change that MBR I did this:
dd if=/dev/sda3 of=/home/you/mbr−backup count=1
nasm boot.asm -o boot.bin -f bin
correcting if errorsdd if=boot.bin of=/dev/sda3
Sure, you can do that directly on the drive's MBR instead of the partition's MBR like I did here, but for my own case it was more practical.
Concerning the actual code-jumping-out-of-MBR, you'll need to use the INT 13,42 interruption, which loads any cluster on a disk. For the purpose of my test I just had to display its contents, but I can take a closer look if you want.
Hope that could help, sorry for the long reply.