Reading from a floppy
-
- Member
- Posts: 36
- Joined: Wed Sep 01, 2010 3:54 pm
Reading from a floppy
I've been doing some research on reading from a floppy and had a few questions. The first is that the address you specify for bx, is that just where in memory you want to load the sectors your reading from and then by jumping to that address the code you loaded will start exectuing? The other thing I was wondering is that if your searching for a file on a floppy disk to load, once the file is found, how exactly do you load it if it takes up more then one sector? Do you have to figure out how many sectors it takes up and then continue reading those into memory? And if so, is there an easy way to figure out how many sectors your file takes up on the floppy disk?
- smwikipedia
- Member
- Posts: 49
- Joined: Tue Apr 20, 2010 1:11 am
Re: Reading from a floppy
Yes, bx is the location in memory where the sectors are loaded into. And after loading, you can jump to that address to execute the code from floppy.rkennedy9064 wrote:I've been doing some research on reading from a floppy and had a few questions. The first is that the address you specify for bx, is that just where in memory you want to load the sectors your reading from and then by jumping to that address the code you loaded will start exectuing? The other thing I was wondering is that if your searching for a file on a floppy disk to load, once the file is found, how exactly do you load it if it takes up more then one sector? Do you have to figure out how many sectors it takes up and then continue reading those into memory? And if so, is there an easy way to figure out how many sectors your file takes up on the floppy disk?
As to knowing how many sectors are used by a file, there're 2 approaches:
1- Carefully arrange the file on the floppy so that you know where it begins and how many sectors it take. (Easy to implement, but you will need some tools to directly write the floppy sectors.)
2- Use some file system, such as FAT12. (Difficult to implement, you will need to write code to parse FAT12 file system, i.e. your floppy driver.)
Re: Reading from a floppy
Before I started using Grub, I had a single sector boot loader that could search the root directory of a floppy and find my kernel file by name. Because the first sector pointer is in the directory entry, there was just enough space in the 512 bytes to then load the first sector of the kernel to 0x7e00.The other thing I was wondering is that if your searching for a file on a floppy disk to load, once the file is found, how exactly do you load it if it takes up more then one sector? Do you have to figure out how many sectors it takes up and then continue reading those into memory? And if so, is there an easy way to figure out how many sectors your file takes up on the floppy disk?
The first 512 bytes of the kernel file were a continuation of the boot loader. The kernel itself started at the 513th byte of the kernel file.
This in effect gave me a 2 sector boot loader. A second sector is easily enough space to enable a20, switch to big real mode, follow the FAT chain and load the rest of the kernel to the 1MB mark.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 36
- Joined: Wed Sep 01, 2010 3:54 pm
Re: Reading from a floppy
I'm using mkbt.exe to put the bootsector onto the first sector of the floppy. If I used fat12 for a floppy format I saw a few examples of how to search for the file name using the first 11 bits to compare the file names. My other question would be once I find the file, I know it has a bit description of the first cluster and how big the file is, so once I find the file, would I need to see how big the file is and calculate how many sectors the file takes up then load those into memory, or once the file is found will it automaticall load the whole file into memory?
Re: Reading from a floppy
Yes, you will need to do it. You will need to walk the FAT.... would I need to see how big the file is and calculate how many sectors the file takes up then load those into memory, ...
If a trainstation is where trains stop, what is a workstation ?
- smwikipedia
- Member
- Posts: 49
- Joined: Tue Apr 20, 2010 1:11 am
Re: Reading from a floppy
You don't need to calculate the size of the file, though you can get the file size from the Root Directory Section (RDS) of the FAT12 file system. Once you find your file name in one of the RDS entries, you can get the the first FAT entry index of the file. And the each FAT entry contains the index of the next FAT entry. The last FAT entry value is >=0xFF8, so you can detect the end of the file. FAT index - 2 = Floppy disk logical sector numberrkennedy9064 wrote:I'm using mkbt.exe to put the bootsector onto the first sector of the floppy. If I used fat12 for a floppy format I saw a few examples of how to search for the file name using the first 11 bits to compare the file names. My other question would be once I find the file, I know it has a bit description of the first cluster and how big the file is, so once I find the file, would I need to see how big the file is and calculate how many sectors the file takes up then load those into memory, or once the file is found will it automaticall load the whole file into memory?
FAT file system specificationhttp://staff.washington.edu/dittrich/misc/fatgen103.pdf could be helpful.