stevewoods1986 wrote:
I know how to read a sector. The sector is my kernel. I want to load my kernel if it's more than 512 bytes. Do I have to read two sectors? I believe I am using FAT12. I am using disk dump.
A sector is a part of a track.
I might just need a very good resource on filesystems.
You sound somewhat confused to me. Let me try to explain.
- FAT is a filesystem, which is a way for you (and other operating systems) to figure out which sectors contain which files. It has nothing to do with actually reading the sectors.
- You can read any sector you want, ignoring the filesystem.
- You can put your data wherever you want, without a filesystem.
- The size of your kernel is irrelevant.
You have two options:
- Create a bootloader (may be more than 512 bytes) that can read the FAT filesystem, and thereby load your kernel. Copy your kernel to the disk as an ordinary file using e.g. Windows Explorer.
- Create a boot sector with the location (on disk) and size of your kernel hardcoded (contained in the boot sector code itself), and load your kernel from this location on disk. Copy your kernel to disk using a utility that lets you write a file to any arbitrary location on the disk (instructions for how to do this depend on what operating system and tools you are using).
My advice would be to go with the former option, using an actual filesystem. This will be less confusing and more robust in the future.
The code for reading the FAT filesystem probably won't fit in the boot sector, so you will need to put it elsewhere on the disk. Your boot sector will contain, hardcoded, the location on the disk of the code that reads the FAT filesystem and loads your kernel. You will write this code to disk using a special utility that lets you write to any arbitrary location on the disk. Your boot sector will load these hardcoded sectors into memory and then jump to it to execute it.
Now the code for reading the FAT filesystem takes over. This code will need to be able to read any single sector from disk into any memory location, so you should write a subroutine/function/method that you can call with parameters giving the sector that you want to read and the memory location that you want it to be read into. At this point you will be working with sectors numbered from 0 at the beginning of the disk all the way to 2879 at the end (assuming that you're working with a regular floppy disk) - this is called LBA (logical block addressing) - so write your sector-reading function such that it will calculate the correct cylinder, head, and sector within the track from a logical block address. Now you can read the FAT filesystem tables, parse them to find the location of your kernel file, and then read the kernel. At this point, hopefully, you can understand why the size of your kernel doesn't matter, because you will simply read whichever sectors contain your kernel according to the filesystem, no matter how many there are and where they are on the disk (note that the sectors may not be contiguous, called fragmentation).