flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
rhyno_dagreat 09 Apr 2007, 01:50
I am wondering, can someone please explain to me how FAT bootsectors work? I have seen plenty of FAT code and it confounds (confuses?) me.
|
|||
![]() |
|
rhyno_dagreat 09 Apr 2007, 19:58
Thanks Fagot, though it's not the bootsector itself that confuses me. It's how the FAT works in it.
|
|||
![]() |
|
tom tobias 10 Apr 2007, 09:22
Fagot wrote: First two bytes is empty byte (nop) and jump to main code. A. Do you have a reference from Intel which explains the requirement to insert "nop" in the bootsector? I suspect this notion may be a holdover from the late 1970's when state of the art was the 8080, and floppies were, well, floppy. B. Why can you not write "start" and "print", instead of "_start" and "_print"? Are "start" and "print" reserved words in FASM? |
|||
![]() |
|
Hayden 10 Apr 2007, 10:41
Microsoft Hardware White Paper
_________________ New User.. Hayden McKay. |
|||||||||||
![]() |
|
Fagot 13 Apr 2007, 17:37
tom tobias wrote:
A - all information in pdf ![]() B - "start" and "print" not reserved words in FASN. it's my style of programming ![]() _________________ I learn English ![]() |
|||
![]() |
|
Goplat 13 Apr 2007, 23:02
tom tobias wrote:
Intel has nothing to do with it. The FAT filesystem was first used in Microsoft Disk BASIC in 1977. I can't find much info about this but my guess is it was available for various computers, including some with a 6502 processor where unconditional jumps were always 3 bytes long. The boot sector's data has to be in the same format and in the same location no matter what kind of processor there is, so on processors where you have 2 byte jumps (like x86) you need an extra byte to make the data start at offset 3. |
|||
![]() |
|
tom tobias 14 Apr 2007, 00:37
Fagot wrote: "start" and "print" not reserved words in FASN. it's my style of programming Goplat wrote: Intel has nothing to do with it. The FAT filesystem was first used in Microsoft .... Thanks again for your excellent response to my previous question... ![]() |
|||
![]() |
|
Hayden 14 Apr 2007, 02:41
Yeah... the three byte jump is only specific to the microsoft FAT format.
All boot sectors only need to have the word signature AA55h at bytes 510-512 in the secotor to make the medium bootable. execution begins at the first byte of the boot sector. The first byte may be any insctruction you wish although usualy a jump to skip over some data structure. ie: here is a simple 'name brand' boot sector Code: org 7C00h jmp bootcode align 4 ; make the data address static at 7C04H BS_MaxCylCount dd ? ; C BS_HeadsPerCyl dd ? ; H BS_SecsPerHead dd ? ; S BS_BytesPerSec dd 512d ; default - 512 bytes BS_MediaType db ? ; hdd, fdd etc... bootcode: ; code to boot the machine... bootsign: rb 7C00h+512-2-$ db 055h,0AAh ; expected to be l_endian it always pay's to keep at least some kind of media info in the bootsector. even if your not useing the microsoft FAT format. _________________ New User.. Hayden McKay. Last edited by Hayden on 15 Apr 2007, 17:38; edited 2 times in total |
|||
![]() |
|
tom tobias 14 Apr 2007, 16:14
Hayden wrote: The first byte may be any insctruction you wish although usualy a jump to skip over some data structure.... For me, this is completely the opposite of the proper way to program. So, again, is there somewhere, in some obscure journal, or white paper, or vendor's application note, or any other location, an explanation for WHY everyone commences the startup this way? To me, a logical, and proper, PROGRAM, not code, at the very outset, ought to begin with the DATA, not the code. Hayden wrote: it always pay's to keep at least some kind of media info in the bootsector. even if your not useing the microsoft FAT format. ![]() |
|||
![]() |
|
bogdanontanu 15 Apr 2007, 00:53
Quote:
Well, mainly because the BIOS jumps you there at boot sector start. A JMP instruction is performed by the BIOS to this location... and a JMP instruction tells the CPU to continue the execution of CODE to a certain memory location. Guess what? Location is right there at the start... This means that the very first byte is forced to be code It is (ironically) because the programmers want to have DATA at start that they do perform yet another JMP... this time over the initial DATA. This is the reason for this JMP: to keep data positioned at start of boot sector and perform this action with a minimum amount of code. And the minimum amount of code that can do this action is a jump over the data zone... Quote:
To me the logical physical layout is CODE first and DATA last. However please note that because some executable formats and layouts support "sections" in one way or another... the format of the source code does not have to mirror the format of the binary layout. You can start your program with section ".data" and continue with section ."code" and still end up with them reversed in the resulting binary (most common). Usually it does not matter much. But the boot sector is a case where the physical layout does matter for multiple reasons...some reasons are real and some are imaginations and desires. I find it kind of funny, I find it kind of sad when people tend to get into "program" versus "code" design principles and talk about a boot sector ![]() One thing I notice here is the fact that you/others seem to believe or speak as if they believe that the boot sector is the first code that will setup/initialize the CPU? In fact the boot sector is the first part of loading/starting an OS or an application. However the machine/CPU was initialized by the BIOS and countless complicated operations have been done for this... Quote:
I agree with this ... however some people do find advantages to filling up the boot sector with as much code and functionality as possible... 512bytes is pretty small for "normal" loading code and I guess that people find it funny to fit many things "in" there ![]() I presume that in another 50+ posts we would have had solved all the possible implications of the first 3 bytes of the boot sector... and advanced to the new frontier of the 4 and 5th bytes... I also have "a vison" of a dilema at bytes 510: do they have to be 0x55, 0xAA ? Or could it be 0xAA, 0x55? This is the Question... The rest is silence _________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." |
|||
![]() |
|
Hayden 15 Apr 2007, 04:25
The data at the start of a boot sector it usualy refered to as partition infomation. logicly speaking the partition comes before anything else on the disk medium.
Even though the BIOS has set up interrupt vectors ect... there may still be some stuff left to do like enableing the A20 gate, turn on FPU ect... before the o/s can be loaded. |
|||
![]() |
|
tom tobias 15 Apr 2007, 10:06
Bogdan wrote: It is (ironically) because the programmers want to have DATA at start that they do perform yet another JMP... this time over the initial DATA. My notion, of declaring data BEFORE executing instructions, is similar to the mechanical engineer who FIRST studies a problem, makes drawings, and perhaps even assembles a scale model, BEFORE commencing with the operations needed to build the first prototype unit. It seems to me, silly to place data before instructions, if one intends to skip over the data structure anyway. The whole point of placing the data structure at the outset, is to define WHAT IT IS THAT THE SUBSEQUENT CODE WILL BE USING for operands, instead of inserting the piece of metal stock, turning on the lathe, and commence carving WITHOUT benefit of a drawing. For me, the distinction is akin to that of the artisan, compared to the engineer. An artist creates ON THE FLY. An engineer thinks first, designs, modifies, thinks some more, then finally, acts. The artisan in the meantime has produced two dozen devices, some of which are marketable, some of which may prove to be more than simple, costly ornaments, but most of which represent a waste of time and resources. Bogdan wrote: ...dilema at bytes 510: do they have to be 0x55, 0xAA ? Or could it be 0xAA, 0x55? The entire "boot" process appears to me, at least, both obscure, and obsolete. I simply wonder how many of these eccentricities are actually required, and how many are thought to be required, because of an underlying assumption about the operating system, or the storage medium, etc.... Hayden wrote: The data at the start of a boot sector it usualy refered to as partition infomation. logicly speaking the partition comes before anything else on the disk medium. What if the storage medium is memory itself, NOT a disk? I can envision a motherboard with a gig of flash memory.... ![]() |
|||
![]() |
|
Hayden 15 Apr 2007, 17:30
BIOS scans the boot order for a medium that has the boot signature.
Flash storage devices have a partition defined for driver compatability. The answers are in fatgen103.pdf |
|||
![]() |
|
tom tobias 16 Apr 2007, 01:12
Hayden wrote: The answers are in fatgen103.pdf http://www.microsoft.com/whdc/default.mspx Hayden wrote: Flash storage devices have a partition defined for driver compatability Hayden wrote: BIOS scans the boot order for a medium that has the boot signature. That's not very clever BIOS, if so.... |
|||
![]() |
|
LocoDelAssembly 16 Apr 2007, 01:46
The system will prompt an error or will start the ROM BASIC if present when no boot device has the signature. If the signature is present but the sector is not really executable then the result is unpredictable but in some moment it will end with an invalid opcode exception and will hang the computer.
About flash media like my pen drive writing an image of the MenuetOS works perfectly but if I write a sector which have only the signature and executable code the BIOS simply skips my pen drive and try the next device (hard disk). The reason of this is that I didn't include the BPB so the BIOS can't take parameters for floppy emulation. And the reason for placing the structure after a JMP I think it's more for future expandability than programmers' preference. If for example you put the structure just before the signature, then there is no way to add more fields to the structure because it will overlap with the signature and will go out of the bounds of the sector. However, placing the structure just after the jump that skips it allows for future expansion. Yes, I know, you can still put the structure at the end and reserve a field that when is non-zero the meaning is the offset of the expansion having every expansion as a linked list but is a lot easier to have a single structure and pay the miserable latency the first jumps adds. |
|||
![]() |
|
Hayden 16 Apr 2007, 03:29
Nice post locoDelAssembly...
_________________ New User.. Hayden McKay. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.