[SOLVED] Writing to floppy causes data to be wiped!
Posted: Fri Nov 07, 2014 1:23 pm
Hello fellow os devers!
I am currently writing an OS in protected mode, and have just put my finishing touches to the "Floppy disk: read sector"-related driver code. All works great.
So now was time for writing the "Floppy disk: write sector". Well. No problem: They're kind of similar in terms of programming. All there is to do is change what command is sent to the FDC, and SEND bytes instead of receiving them. I finish writing and programming, and start the bug-hunt. Some minor bugs occured (inc instead of dec in a loop counter, and off-by-one errors) and the driver was ready. I loaded my new system onto a floppy disk, and lo and behold: It executed with no errors. I took out the floppy, put it in my development machine, and examined the desired sector in a Hex-editor. Yup. The sector was filled with 0x00 0x01 0x02 0x03 0x04... 0xff. Test was successful!
I then wipe that sector back to null, just to see it run again. I like it when stuff works twice. But this time my OS was not able to boot! Not even an error showed up!
I examined the floppy again, and in this closer look i discover that random chunks had been filled with zeros!
I reloaded my OS to the floppy and changed some code. Instead of filling a sector with 0x00 0x01 0x02 0x03... 0xff, I made it fill a sector with 512 x 0xdc, just to see what would happen.
Now I ran the code, and saw the same result. Random chunks loaded with 0x00 in the middle of my masterpiece! Except for one of these chunks! It started with 15-20 bytes of 0xdc, and then 4-500 bytes of 0.
I have read the FDC manual and article on the wiki countless times. I have searched hither (this very forum) and thither (Google...) for an answer on what is going on.
I have a guess though: The FDC starts writing before the right sector has been reached.
Does anyone know what is happening here?
I am currently writing an OS in protected mode, and have just put my finishing touches to the "Floppy disk: read sector"-related driver code. All works great.
So now was time for writing the "Floppy disk: write sector". Well. No problem: They're kind of similar in terms of programming. All there is to do is change what command is sent to the FDC, and SEND bytes instead of receiving them. I finish writing and programming, and start the bug-hunt. Some minor bugs occured (inc instead of dec in a loop counter, and off-by-one errors) and the driver was ready. I loaded my new system onto a floppy disk, and lo and behold: It executed with no errors. I took out the floppy, put it in my development machine, and examined the desired sector in a Hex-editor. Yup. The sector was filled with 0x00 0x01 0x02 0x03 0x04... 0xff. Test was successful!
I then wipe that sector back to null, just to see it run again. I like it when stuff works twice. But this time my OS was not able to boot! Not even an error showed up!
I examined the floppy again, and in this closer look i discover that random chunks had been filled with zeros!
I reloaded my OS to the floppy and changed some code. Instead of filling a sector with 0x00 0x01 0x02 0x03... 0xff, I made it fill a sector with 512 x 0xdc, just to see what would happen.
Now I ran the code, and saw the same result. Random chunks loaded with 0x00 in the middle of my masterpiece! Except for one of these chunks! It started with 15-20 bytes of 0xdc, and then 4-500 bytes of 0.
I have read the FDC manual and article on the wiki countless times. I have searched hither (this very forum) and thither (Google...) for an answer on what is going on.
I have a guess though: The FDC starts writing before the right sector has been reached.
Does anyone know what is happening here?