Hello, I am new here to the whole assembly thing.

I have written a bootsector that is to fit on a floppy and/or flashdrive, and have got it working upto this point ... enabling A20, PMode, loading a basic GDT, the basic stuff that sounds an awefull lot like OSDev. :lol:

My problem is, I need to find a way to avoid overwriting the FileSystem/Partition information within the bootsector.

Will someone please tell me (NASM Syntax preferred) what they would recommend doing to perform such a task.  I use dd as my preferred tool to copy bootsectors to disks, but if your advice requires a different (still runs on Linux) program, I would be happy to switch.

Thanks for all the help!
Posted on 2009-09-16 21:39:49 by XeonX369

Hello, I am new here to the whole assembly thing.

I have written a bootsector that is to fit on a floppy and/or flashdrive, and have got it working upto this point ... enabling A20, PMode, loading a basic GDT, the basic stuff that sounds an awefull lot like OSDev. :lol:

My problem is, I need to find a way to avoid overwriting the FileSystem/Partition information within the bootsector.

Will someone please tell me (NASM Syntax preferred) what they would recommend doing to perform such a task.  I use dd as my preferred tool to copy bootsectors to disks, but if your advice requires a different (still runs on Linux) program, I would be happy to switch.

Thanks for all the help!


With DD, you can indicate, among other things, byte size, byte count and initial number of bytes to skip (i.e. seek). Using DD alone, you can easily make a working copy of your MBR, and "superimpose" the partition table from the working copy onto your assembled MBR binary before sending it to sector zero with DD.

Personally, I would encourage you to invest in an emulator such as Bochs or QEmu. You're not far enough along in OS development to have a significant need for a "real" computer, so using such robust emulators will dramatically decrease your development/testing time (no reboots) as well as give you a nice sandbox to play in.
Posted on 2009-09-17 01:38:51 by SpooK
I do use Bochs as my current emulator for testing my code.

So, how exactly would I do what you said with DD.

(sorry for the late reply, I have been out of commission for surgery)
Posted on 2009-09-28 09:43:13 by XeonX369

So, how exactly would I do what you said with DD.


Check out DD's manpage, it will list the available options to skip/seek to a particular part of a file and copy the desired amount of data, among other things.
Posted on 2009-09-28 12:08:03 by SpooK
Well to preserve... just don't write over it... there is a good document on MBR structure. your initial bootloader shouldn't take up more then 446 bytes but this also includes the BPB. Enough to add code to load some other sectors though. so in english and asm. Links are to various info about MBR and various file systems. Hope this helps!
http://home.teleport.com/~brainy/fat16.htm
http://bootmaster.filerecovery.biz/appnote3.html
http://en.wikipedia.org/wiki/Master_boot_record
http://mirror.href.com/thestarman/asm/mbr/STDMBR.htm

JMP start
NOP

;BIOS PARAMETER BLOCK
...
;code to load additional sectors of your choosing into memory (I use the sectors not in use by the filesystem for Fat12 i use LBA1-LBA10)
...
JMP
Posted on 2009-10-29 00:29:52 by Goose007
Folks used to write a "dropper" program to do this...

; read your "mbr.bin" into a buffer
; read original MBR into a different buffer
; copy partition table from "old_buffer" to "new_buffer"
; write "new_buffer" back to disk

Learning to use "dd" might be easier, but writing the "dropper" program might be good practice.

All MBRs do pretty much the same thing - move itself out of the way, parse the partition table, read the bootsector from the "active" partition to 0:7C00h, jump to 0:7C00h. So... is there any point to writing your own? This is *not* the place to switch to PMODE!

You haven't got an MBR on a floppy, in any case. I've never worked with a flash drive (sounds like a good idea), or with an emulator... Finally got Bochs to build (had to download a "release candidate" - the "current" version gives "unresolved symbol"...), but I don't know what to do with it...

Best,
Frank

Posted on 2009-10-29 12:06:51 by fbkotler