Page 1 of 1

How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 8:37 am
by Timmy100
Sup guys. I managed to learn a few things with Assembly. I want to run my OS on physical hardware. I know about INT 13h. How do I do a valid MBR or BPB?

By the way, which places in the manuals do I need to read?

Cheers
Timmy

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 9:03 am
by SpyderTL
You need to be more specific when asking questions.

Do you mean "How do I put a valid MBR on a floppy disk, hard disk, CD-ROM and/or USB drive using Windows and/or Linux?"

Or do you mean "How do I build a valid MBR structure that can be put on a disk in NASM/MASM?"

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 9:05 am
by Timmy100
I want a sample to put in a bootloader.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 9:11 am
by SpyderTL
You need to be more specific when asking questions.

Do you mean "How do I put a valid MBR on a floppy disk, hard disk, CD-ROM and/or USB drive using Windows and/or Linux?"

Edit: Did you read the wiki? http://wiki.osdev.org/MBR#x86_Examples

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 12:03 pm
by Timmy100
That's exactly what I mean but is there something simpler? I'm not being lazy.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Tue Apr 11, 2017 1:17 pm
by sleephacker
Timmy100 wrote:How do I do a valid MBR or BPB?
Timmy100 wrote:I want a sample to put in a bootloader.
Timmy100 wrote:That's exactly what I mean but is there something simpler? I'm not being lazy.
You are asking for information that can be found on google (instead of asking a question because you don't understand the information you found), you're essentially asking others to look up something for you. So by my definition of the word you are in fact being very lazy.

Having said that, this short tutorial is about as simple as it gets, from the first page when googling "bootsector x86 assembly" (I know, googling is a tough job, even for non-lazy people). Since you're probably too busy "not being lazy" to read it and find the link yourself: this is the copy&paste-ready code.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 2:35 am
by SpyderTL
Before we can help, you have to answer a few basic questions.

What type of storage device do you want to boot your physical machine from? Floppy disk, CD-ROM, or USB drive?

And, to be clear, you don't technically need a BPB or an MBR. You only need those if you want other OSes like Windows or Linux to be able to read your disk information.

You can just write some code in assembly, compile it, and copy the results to the first block of a floppy drive, and your machine will execute it.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 3:53 am
by Timmy100
Can I still read and write on the floppy in my OS using INT 13h?
OK. Thank you. It's just my computer won't boot it without a BPB (I think so).

Sorry, I got mixed up with MBR. I mean code to put in the MBR. By the way, how can I go to a sector (extended or just change 0 to 80) with INT 13h?

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 4:09 am
by Octocontrabass
Timmy100 wrote:Can I still read and write on the floppy in my OS using INT 13h?
You can read and write floppy disks using INT 0x13. (You shouldn't use INT 0x13 in your OS, because it's terrible compared to a real driver.)
Timmy100 wrote:It's just my computer won't boot it without a BPB (I think so).
A real floppy disk does not need a BPB. If you are not using a real floppy disk, you might need a BPB.
Timmy100 wrote:By the way, how can I go to a sector (extended or just change 0 to 80) with INT 13h?
I don't understand your question. What does "go to a sector" mean?

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 4:14 am
by Timmy100
Read sector.

I'm using an USB for floppy disk emulation. I am planning on switching to hard drive or USB. How do I use DD on Linux for this by the way? How would I put a file on the first sector of USB? Is it the same as floppy (with bs=512 count=1 conv=notrunc)?

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 4:33 am
by Octocontrabass
Timmy100 wrote:Read sector.
You can read a sector using INT 0x13 AH=0x02 or INT 0x13 AH=0x42 (but AH=0x42 will not work on real floppy disks and may not work on emulated floppy disks). For more information about AH=0x42, you can also refer to the standard where it is defined.
Timmy100 wrote:I'm using an USB for floppy disk emulation.
USB floppy disk emulation requires a BPB. Without it, you may end up with hard disk emulation, no boot, or a crash from corrupted data.
Timmy100 wrote:I am planning on switching to hard drive or USB.
In that case, why not use USB hard disk emulation (with a partition table) instead? You can generate a valid partition table using diskpart (Windows) or fdisk/parted (Linux).
Timmy100 wrote:Is it the same as floppy (with bs=512 count=1 conv=notrunc)?
Yes.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 6:06 am
by Timmy100
I've just tried writing a sector and booting my bootloader (using VirtualBox). However, it just shows blank. Why is this happening? It doesn't print my string or boot kernel from INT 13h (with 80h as hard disk drive). I'm using 0x7C00 memory address if that helps.

Re: How do I do a BPB and MBR in x86 assembly?

Posted: Wed Apr 12, 2017 6:36 am
by Octocontrabass
Timmy100 wrote:Why is this happening?
Probably because there's something wrong with your code. I can't give you a better answer than that without more information.