Question about second stage of bootloader.

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.
Post Reply
dash
Posts: 3
Joined: Sun Mar 17, 2013 11:13 pm

Question about second stage of bootloader.

Post by dash »

Hi, :)
I am a new learning OS development,and got confused with one problem. Here is the detail:

step 1.wrote a boot program(stage1) and copy it to the first sector of a floppy disk using debug command(-w 100 0 0 1).
step 2.tried to use "copy stage2.sys A:\stage2.sys" to copy my stage2 program to the disk

but at the second step,my OS just complained that the file system of the floppy disk could not be recognized.I really get confused with this. My OS is windows 7.Seems like the behavior of copy of the bootloader(stage1) has crashed the FAT fs of the floppy ,but how could this happen?

Thanks in advance! :)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Question about second stage of bootloader.

Post by Brendan »

Hi,
dash wrote:Seems like the behavior of copy of the bootloader(stage1) has crashed the FAT fs of the floppy ,but how could this happen?
The first sector of the floppy disk (that you overwrote) is also the first sector of the FAT file system and contains important information needed to understand the FAT file system.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Question about second stage of bootloader.

Post by Mikemk »

It would seem you overwrote the BIOS parameter block...
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
dash
Posts: 3
Joined: Sun Mar 17, 2013 11:13 pm

Re: Question about second stage of bootloader.

Post by dash »

I see~~~.yes,I forgot to put the BPB into my boot loader.but still there's a little strange.
the first time I put the BPB like this,which still caused the same problem:
-------------------------

Code: Select all

bpbOEM:                  DB "My OS   "  ;8 bytes
bpbBytesPerSector:       DW 512
bpbSectorsPerCluster:    DB 1
bpbReservedSectors:      DW 1
bpbNumberOfFATs:         DB 2
bpbRootEntries:          DW 224
bpbTotalSectors:         DW 2880
bpbMedia:DB 0xF0
bpbSectorsPerFAT: 	    DW 9
bpbSectorsPerTrack: 	  DW 18
bpbHeadsPerCylinder: 	 DW 2
bpbHiddenSectors:        DD 0
bpbTotalSectorsBig:      DD 0
bsDriveNumber: 	       DB 0
bsUnused: 	            DB 0
bsExtBootSignature:      DB 0x29
bsSerialNumber:	       DD 0xa0a1a2a3
bsVolumeLabel: 	       DB "MOS FLOPPY "
bsFileSystem: 	        DB "FAT12   "

--------------------------
and after I replaced

Code: Select all

bpbOEM:               DB "My OS   "   ;8 bytes
with

Code: Select all

TIMES 0Bh - ($-start) db 0 
,the problme was fixed.(start is label of the first jmp instruction)
Is there any differences?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Question about second stage of bootloader.

Post by Combuster »

dash wrote:and after I replaced

Code: Select all

bpbOEM:               DB "My OS   "   ;8 bytes
with

Code: Select all

TIMES 0Bh - ($-start) db 0 
,the problme was fixed.(start is label of the first jmp instruction)
Is there any differences?
The first option isn't guaranteed to put the BPB at the right place (jmp + OEM must be 11 bytes), while the latter simply puts the BPB where it should regardless of what opcode the assembler put in for the jump.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
dash
Posts: 3
Joined: Sun Mar 17, 2013 11:13 pm

Re: Question about second stage of bootloader.

Post by dash »

I understand.
Thank you all very much :)
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Question about second stage of bootloader.

Post by Mikemk »

Also, some versions of windows require that the oem label be either blank or "MSWIN4.0" (It's 4, not 2, right?)
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Post Reply