Problem with Launching Stage 2 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
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

Hey everyone!

I've been following the BrokenThorn Series on OS Dev. Right now, as a part of my journey through the tutorial I'm currently coding the part that loads in a second stage bootloader, but unfortunately, the code crashes. Here is the portion of the code that I think is troublesome:

Code: Select all

;browse root directory for binary image
         mov     ax, WORD [bpbRootEntries]; load loop counter, bpbRootEntries is the number of entries in the FAT table
         mov     di, 0x0000 ; because rep cmpsb compares the string in es:di to ds:si, and es holds 0x7e00 (the location of the FAT Table), I decided to set di to 0x0000
           mov     cx, 0x000B; eleven character name	 		 
         lea     si, [ImageName] ;set si to the memory location of ImageName so ds:si points to ImageName			 
     .LOOP:     
	  rep  cmpsb     
          jz     LOAD_FAT
          add     di, 32                            ; queue next directory entry
          dec ax
          cmp ax, 0x0
     jne .LOOP
		 
     jmp     FAILURE
This portion of code looks for the file in the FAT table. However, it is not able to find it, and so crashes.
In this code, ImageName is a variable with the value "KRNLDR SYS" in it. In my floppy drive, I have a file called "KRNLDR SYS" in my floppy drive (with the spaces, not "KRNLDR.SYS"). It would be a great help if anyone could offer any advice.

Note: I'm currently runnning a 64-bit Windows 7 PC
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

First, "KRNLDR SYS" does not follow the 8.3 format. "KRNLDR SYS" does.
On fat12, windows will rename "KRNLDR SYS" to "KRNLDR~1" for dos compatibility, so the entry would be "KRNLDR~1 "
"KRNLDR.SYS" Would be stored correctly. the first 8 is the name and last 3 is the extension, not just an 11 character name.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Re: Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

Does this mean I should name the file in the floppy disk "KRNLDR.SYS" and set ImageName to "KRNLDR SYS"?

Thanks!
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

yes, two spaces between KRNLDR and SYS (K|R|N|L|D|R| | |S|Y|S) | seperates characters
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Re: Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

I have tried what you suggested, and unfortunately, the OS still crashes. Specifically, it goes through all of the files in the FAT table, and is not able to find KRNLDR.SYS. So, it crashes.

Thanks!
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

Sorry, I wasn't clear.
In windows, name it KRNLDR.SYS
In your os, look for KRNLDR SYS (11 characters)
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Re: Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

So, I named the file KRNLDR.SYS in windows. In the bootloader, I'm searching for KRNLDR SYS (with 2 spaces). But still, the code is not able to find the file. I'm wondering if it is because I haven't formatted it correctly. I'm using VFD to create a virtual floppy drive and format it. I'm using RawWrite to right the bootloader to sector 0, and using a copy command in windows to load KRNLDR to the floppy. Is there a problem with this setup?

Thanks in advance for all your help!
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

diwgan32 wrote:I'm using VFD to create a virtual floppy drive and format it.
I'm sorry, I thought you were using a real floppy disk. If it is virtual, would you please upload the image and I'll take a look?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Problem with Launching Stage 2 Bootloader

Post by iansjack »

Single-step through the relevant code in a debugger.
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Re: Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

Thanks to everyone for all their help! As m12 asked, I have attached the .vfd that VFD generated when I created the virtual floppy. Unfortunately, the forum would not allow me to directly upload a .vfd file, so I have uploaded it to MediaFire. Here is the link:

http://www.mediafire.com/?6ky9eojglhfglgm
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

You have no bootloader, and no filesystem on this disk image. Starting at sector 33, though, all the sectors are filled with 0xf6. Is there a reason for this?
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
diwgan32
Posts: 6
Joined: Fri Apr 05, 2013 4:45 pm

Re: Problem with Launching Stage 2 Bootloader

Post by diwgan32 »

That is really strange. I'm using Oracle VM, and it boots up fine. How were you able to see the contents of the image?
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

Hex editor
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
MDenham
Member
Member
Posts: 62
Joined: Sat Nov 10, 2012 1:16 pm

Re: Problem with Launching Stage 2 Bootloader

Post by MDenham »

m12 wrote:You have no bootloader, and no filesystem on this disk image. Starting at sector 33, though, all the sectors are filled with 0xf6. Is there a reason for this?
If memory serves, that's the standard "empty byte" on disks when they're initially formatted.

(After looking here, section 24, my memory is correct.)
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Problem with Launching Stage 2 Bootloader

Post by Mikemk »

I was unaware of those.
@OP, this disk image is blank.
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