OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 5:50 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 8:37 am 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
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


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 9:03 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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?"

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 9:05 am 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
I want a sample to put in a bootloader.


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 9:11 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 12:03 pm 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
That's exactly what I mean but is there something simpler? I'm not being lazy.


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Tue Apr 11, 2017 1:17 pm 
Offline
Member
Member
User avatar

Joined: Thu Aug 06, 2015 6:41 am
Posts: 97
Location: Netherlands
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.


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 2:35 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 3:53 am 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
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?


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 4:09 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
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?


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 4:14 am 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
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)?


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 4:33 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
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.


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 6:06 am 
Offline

Joined: Sun Apr 09, 2017 12:58 pm
Posts: 13
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.


Top
 Profile  
 
 Post subject: Re: How do I do a BPB and MBR in x86 assembly?
PostPosted: Wed Apr 12, 2017 6:36 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5103
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: cloudapio, Majestic-12 [Bot] and 178 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group