Reading from a floppy

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
rkennedy9064
Member
Member
Posts: 36
Joined: Wed Sep 01, 2010 3:54 pm

Reading from a floppy

Post by rkennedy9064 »

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?
User avatar
smwikipedia
Member
Member
Posts: 49
Joined: Tue Apr 20, 2010 1:11 am

Re: Reading from a floppy

Post by smwikipedia »

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?
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.

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.)
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Reading from a floppy

Post by gerryg400 »

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?
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 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 ?
rkennedy9064
Member
Member
Posts: 36
Joined: Wed Sep 01, 2010 3:54 pm

Re: Reading from a floppy

Post by rkennedy9064 »

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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Reading from a floppy

Post by gerryg400 »

... would I need to see how big the file is and calculate how many sectors the file takes up then load those into memory, ...
Yes, you will need to do it. You will need to walk the FAT.
If a trainstation is where trains stop, what is a workstation ?
User avatar
smwikipedia
Member
Member
Posts: 49
Joined: Tue Apr 20, 2010 1:11 am

Re: Reading from a floppy

Post by smwikipedia »

rkennedy9064 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?
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 number

FAT file system specificationhttp://staff.washington.edu/dittrich/misc/fatgen103.pdf could be helpful.
Post Reply