PeterX wrote:Also I have the impression you take too advanced code. You kind of copy code from somewhere without truly understanding it.
I am going to agree with Peter here.
The FAT file system occupies certain parts of the partition. This is a must. Therefore, you *must* preserve these areas when writing boot code to the partition.
The first sector of the partition, sometimes called a Logical Sector Number of zero, must contain a valid BPB for the FAT type it uses. The FAT-12 and FAT-16 use the same data region, while FAT-32 occupies a little more of the first sector. As long as you preserve these areas, you are free to add code to the rest.
Please note that the utility that is writing the code to LSN 0 will already know if it is a FAT-12, -16, or -32 file system and will act accordingly.
For FAT-12 and -16 file systems, as long as you use a short jump plus a NOP as the first three bytes of LSN 0, and skip over the BPB, you can use the remaining part of the sector as code, minus the last two bytes, which must be the 0xAA55 signature. In fact, the FAT-12 and -16 file systems allow you to use additional sectors for code starting at LSN 1. However, since the MBR code only loaded 1 sector, your code within the LSN 0 *must* load any remaining sectors to memory.
For FAT-32, LSN 1 through x are used for the file system and must be preserved. This includes a INFO sector.
However, with all three types, as long as you preserved these areas, you can have many sectors worth of code for your boot code.
As with Peter's suggestion, I suggest that you study how the FAT file system works *before* you try to write boot code for it.
As for the code you posted, it makes a lot of assumptions that a newbie will completely miss. One huge example will be the ORG 0x0600 line. Yes, this is correct, given the code doesn't make any memory references until after it moves to 0x00600, but a quick glance over and one might assume too much about this assumption.
Ben
-
http://www.fysnet.net/osdesign_book_series.htm