Page 1 of 1

Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 5:09 pm
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

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 5:15 pm
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.

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 5:26 pm
by diwgan32
Does this mean I should name the file in the floppy disk "KRNLDR.SYS" and set ImageName to "KRNLDR SYS"?

Thanks!

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 5:38 pm
by Mikemk
yes, two spaces between KRNLDR and SYS (K|R|N|L|D|R| | |S|Y|S) | seperates characters

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 5:49 pm
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!

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 6:24 pm
by Mikemk
Sorry, I wasn't clear.
In windows, name it KRNLDR.SYS
In your os, look for KRNLDR SYS (11 characters)

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 8:05 pm
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!

Re: Problem with Launching Stage 2 Bootloader

Posted: Fri Apr 05, 2013 8:38 pm
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?

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 12:35 am
by iansjack
Single-step through the relevant code in a debugger.

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 6:39 am
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

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 8:28 am
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?

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 8:31 am
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?

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 8:38 am
by Mikemk
Hex editor

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 6:39 pm
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.)

Re: Problem with Launching Stage 2 Bootloader

Posted: Sat Apr 06, 2013 8:18 pm
by Mikemk
I was unaware of those.
@OP, this disk image is blank.