Boot From Flash Drive: Sector change.

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
Falconspire
Posts: 3
Joined: Sun Mar 13, 2011 1:16 am

Boot From Flash Drive: Sector change.

Post by Falconspire »

Hello,
My friend and I are working together and are relatively new to ASM. We are planning on using a 2 part boot loader, but the problem is that we cannot successfully move to the second bin. We have read the tutorials on the FATs but, it never reaches the file. The tutorial we used is located at http://www.omninerd.com/articles/PC_Boo ... ial_in_ASM . Any help is appreciated, as we cannot seem to find the answer.
Thank you,
Matt C.

PS the file attached is the second file we are trying to load (for testing)
Attachments
STAGE2.asm
It is compiled to be KERNEL.BIN to fit to the primary bootstrap.
(389 Bytes) Downloaded 51 times
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Boot From Flash Drive: Sector change.

Post by Chandra »

Hi,

You've attached the Stage2 file. You need to attach the Stage1 file as well, it's where we can possibly track the error.
DW 0xAA55
It's the boot signature and is not required for the Stage2 file. Also a lot of code improvements (setup of segment registers, setup of stack segment etc.) is required. But before we continue on that, we need to see you Stage1 file. Thank you.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Falconspire
Posts: 3
Joined: Sun Mar 13, 2011 1:16 am

Re: Boot From Flash Drive: Sector change.

Post by Falconspire »

Thank you for replying. I did not realize the second stage did not require a signature. The beginning stage is attached. The beginning stage works correctly as far as I can tell, it will load and reaches "ERROR Press any key to reboot." But the beginning stage was not created by me (However I am not stupid, and I have gone over the source code many times.)
Matt C
Attachments
2stageloader0.1.asm
Primary Boot file.
(9.05 KiB) Downloaded 58 times
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Boot From Flash Drive: Sector change.

Post by egos »

Code: Select all

[BITS 16]
ORG 0
jmp     START

OEM_ID                db "Flash"
BytesPerSector        dw 0x0200
SectorsPerCluster     db 0x01
ReservedSectors       dw 0x0001
TotalFATs             db 0x02
MaxRootEntries        dw 0x00E0
TotalSectorsSmall     dw 0x0B40
MediaDescriptor       db 0xF0
SectorsPerFAT         dw 0x0009
SectorsPerTrack       dw 0x0012
NumHeads              dw 0x0002
HiddenSectors         dd 0x00000000
TotalSectorsLarge     dd 0x00000000
DriveNumber           db 0x00
Flags                 db 0x00
Signature             db 0x29
VolumeID              dd 0xFFFFFFFF
VolumeLabel           db "Flash"
SystemID              db "W95 FAT32  "
...
Wow! Read the books guys.
http://msdn.microsoft.com/en-us/windows ... e/gg463080
If you have seen bad English in my words, tell me what's wrong, please.
Falconspire
Posts: 3
Joined: Sun Mar 13, 2011 1:16 am

Re: Boot From Flash Drive: Sector change.

Post by Falconspire »

Wow! Read the books guys.
http://msdn.microsoft.com/en-us/windows ... e/gg463080
Ok first, I am asking a question, so obviously I am not getting help from available tutorials. Secondly, thanks for a tutorial filled will C code, thats going to help me a lot when I'm coding with only ASM in the script.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Boot From Flash Drive: Sector change.

Post by Tosi »

If you're writing systems-level code, you should have enough experience in both C and assembly that you can at least translate between the languages, especially C to assembler.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Boot From Flash Drive: Sector change.

Post by egos »

Falconspire wrote:Ok first, I am asking a question, so obviously I am not getting help from available tutorials. Secondly, thanks for a tutorial filled will C code, thats going to help me a lot when I'm coding with only ASM in the script.
If you are changing something you should understand what you doing.
If you have seen bad English in my words, tell me what's wrong, please.
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: Boot From Flash Drive: Sector change.

Post by Combuster »

Falconspire wrote:Ok first, I am asking a question, so obviously I am not getting help from available tutorials.
Tip of the day: do not rely on tutorials alone. what will you do when you want to do something that's not part of a tutorial?

The point here is that you seem to either lacked to do some debugging of yourself, or lack the knowledge mentioned above. Download a hex editor, format a floppy with FAT and dump the bootsector so you have something that's known good for comparison, and then compare it byte-by-byte with your bootsector - You should spot the error soon enough. After that, you can use the hints mentioned above to fix the issue.
"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 ]
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Boot From Flash Drive: Sector change.

Post by Chandra »

Your Bios Parameter Block is wrong. Here's a quick update:

Code: Select all

[BITS 16]
ORG 0
jmp     START

OEM_ID                db "Flash"  ; Must be 8 bytes
BytesPerSector        dw 0x0200
SectorsPerCluster     db 0x01
ReservedSectors       dw 0x0001
TotalFATs             db 0x02
MaxRootEntries        dw 0x00E0
TotalSectorsSmall     dw 0x0B40
MediaDescriptor       db 0xF0
SectorsPerFAT         dw 0x0009
SectorsPerTrack       dw 0x0012
NumHeads              dw 0x0002
HiddenSectors         dd 0x00000000
TotalSectorsLarge     dd 0x00000000
DriveNumber           db 0x00
Flags                 db 0x00
Signature             db 0x29
VolumeID              dd 0xFFFFFFFF
VolumeLabel           db "Flash"  ; Must be 12 bytes
SystemID              db "W95 FAT32  "  ; Must be 8 Bytes
This was just a quick review. I've not even looked at the other portions of code. I'd definately recommend reading FAT specification to start.
Hope this helps...

Thank you.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply