MBR- Help

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

MBR- Help

Post by PatrickV »

Hi ya

My Name is PatrickV. I've been working on creating my os for 3 months and got the hang of using a floppy disk. I decide to make my own os so i have control. Not linux which damaged my motherboard or windows. I understand the funderments of the MBR I know you have 2 bootsectors of a hard drive. But i want to create my own MBR, not use grub or any other MBR.
i even type "MBR" in many ways in google and came clean, Nothing. I want to be able to make my own standard MBR which load the bootsector of the active partition. I know how the partition table works but what to put the code before it, i don't know. Can anyone can point me in the write direction with nasm source code or examples. I would be great full. I need ergent help. :)

PS. i am looking for devlopers to help me build the operating system if anyone is instrested and e-mail @: [email protected]
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: MBR- Help

Post by 01000101 »

you might want to be substituting the acronym 'MBR' for the word bootloader or bootstrap. You should head over to osdever.net or check out the wiki here to look for boot theorem and code to get you started.

Also, I'm kind of bewildered by your claim that linux 'damaged' your motherboard... while semi-possible, very unlikely.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: MBR- Help

Post by PatrickV »

Thanks for that, already been their, Nothing that i am looking for
MBR (Master boot record) i am after. The Nasm code for it. I looked hi and low for MBR help, i just can't seem to find it. Grub is to large and complicated what i have in mind
M-Saunders
Member
Member
Posts: 155
Joined: Fri Oct 27, 2006 5:11 am
Location: Oberbayern
Contact:

Re: MBR- Help

Post by M-Saunders »

PatrickV: my OS has a simple MBR that loads a kernel (from a FAT12 filesystem) and executes it. Download:

http://mikeos.berlios.de

In the source/ directory you'll see bootload.asm -- that's what you want. Many other hobbyist/tutorial OSes include small bootloaders too.

M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: MBR- Help

Post by jnc100 »

Hmm, how about checking the GRUB sources?

Regards,
John.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: MBR- Help

Post by bewing »

On osdever.net, a good start is John Fine's dual booting SMBR. http://www.osdever.net/downloads/bootse ... bmbr03.zip

On the wiki here, you will find http://wiki.osdev.org/MBR_%28x86%29 -- but it needs a bit of a rewrite.

Basically, the BIOS loads your MBR (one sector only, including partition table) off the disk and into memory at 0x7c00, then jumps to the beginning of it. You have a little over 400 bytes of code (in 16 bit Real Mode) to load your "bootsector" from the active partition into memory, and jump to the beginning of that. You will need to use BIOS functions (INT calls) to read the disk for you, after you parse the Partition Table.

If you don't care about loading anyone else's bootsectors, then life is easier.

Most bootsectors expect to also be loaded at 0x7c00, unfortunately. Since your MBR is already loaded at 0x7c00, this causes problems. Most bootsectors also expect to be passed a pointer to the beginning of the memory copy of the active (booted) partition in ESI.

All of low memory from 0x500 to 0x7ffff is available, but you need to use the segment registers to access all of it.

I recommend loading your bootsector at 0x500, and I also recommend loading 14 or 16 sectors of "bootsector", in your MBR. Loading only one is not wise. (You may run into trouble later if you try to load more than 18, though.)
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: MBR- Help

Post by PatrickV »

thanks, not much i use from it, but thanks for the insites, now i have the tricky part of putting it together, which i have no idea where to start and which code goes where
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

Re: MBR- Help

Post by Adek336 »

I think you try too hardly to reuse already availlable code; there is a lot of details you need to understand to reuse such code. The way we recommend here at osdev is first to write a part (if not all) of the code yourself; that way you reassure yourself that you know what you should be careful about, when combining others' code.
I believe a good first step would be to write an assembler DOS program, which writes text putting it directly into video memory and the second step writing and installing on a floppy a bootstrap which writes text using video memory access. If you'll try to understand how this is done and not only blindly reusing code, I believe the wiki, old forum threads, the pages mentioned may be of much help :D
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: MBR- Help

Post by Dex »

When you start writing the code yourself this link will help:
http://thestarman.pcministry.com/asm/mbr/index.html
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: MBR- Help

Post by PatrickV »

Hey dex, thanks but the site does not tell all. By the way, i like your dexos and tried it on vm, it is a bit buggy and crashed a fewtimes, i guess that is comoan when it is a cd image
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: MBR- Help

Post by Dex »

PatrickV wrote:Hey dex, thanks but the site does not tell all. By the way, i like your dexos and tried it on vm, it is a bit buggy and crashed a fewtimes, i guess that is comoan when it is a cd image
Cd image makes no difference, it much more likely to do with vm not emulating the x86 100%.
This may sound big headed, but DexOS's biggest plue point, is it's so stable.
Its stable by design eg: design to be KISS, I also have a very large number of test PC, laptops etc and run many tests.
Also other have tested it, note the word stable not mine words others http://forum.osdev.org/viewtopic.php?f= ... 76&start=0
So if you test it on a real PC/laptop and get any bugs, please give full details and i will try to reproduce any bugs, but most OS Dev's are working on two fronts, they have to get round the bugs in emulators and fix real PC bugs, i for one take no notest of emulators and put 100% effort into real PC.
So thanks for trying DexOS and do your self a favour and try it on a real PC.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

MBR Build- Help

Post by PatrickV »

Hey this is my update of my MBR of my os but i've run into a bit of a snag and i don't know what to do next can someone help me. This is a temp one and is not yet stable and not finished.

Code: Select all

;Patricknet Master Boot Record
;This is for the first sector of the hard drive which has the Partition Paramter Table in it
;This Master Boot Record is free for anyone to use
;Be warned that is might cause loss of data
		
	xor ax, ax
	cli
	mov ss, ax
	mov sp, 0x7c00
	sti
	
unbootable:
	jmp unbootable
	
	times 410 db 0 ;Has to be at this point for partion table to in correct address
	
partition_table:
	db 0                ; non-bootable partition
	db 1, 1, 0          ; cylinder/head/sector
	db 0x12             ; configuration partition
	db 0xef, 0xbf, 0x62 ; C/H/S of last sector
	dd 0x0000003f       ; logical block address
	dd 0x008cf6f1       ; size in sectors

	db 0x80             ; bootable partition
	db 0, 0x81, 0x63    ; cylinder/head/sector
	db 0x07             ; Windows NTFS
	db 0xef, 0xff, 0xff ; C/H/S of last sector
	dd 0x008cf730       ; logical block address
	dd 0x041b5bd0       ; size in sectors

	times 16 db 0       ; no third partition
	times 16 db 0       ; no fourth partition
	
	dw 0xaa55
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: MBR- Help

Post by bewing »

You didn't mention what your "snag" might be, but one of your partitions has a "start sector number" of 0 -- and a sector number == 0 is always illegal.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: MBR Build- Help

Post by egos »

Code: Select all

	org 0x7C00
	
unbootable:
	jmp unbootable
	
	times 7DBE-$ db 0 ; rb 7DBE-$
	
partition_table:
If you have seen bad English in my words, tell me what's wrong, please.
PatrickV
Member
Member
Posts: 151
Joined: Sun Jul 06, 2008 7:50 pm
Location: New Zealand
Contact:

Re: MBR- Help

Post by PatrickV »

well it's a temp, you guys are so mean to me you know i am trying my best to learn. I am just figureing it out, well you guys don't have tutorial of this stuff step by step like you did for baby steps so forgive me i seem a bit angry where can not find any examples full tutuorials that has partition table. Give Me a break will ya. :evil: [-X #-o :x :cry: [-o<
Post Reply