3 ms·
When I was young, I discovered the joy of writing TSR programs in assembly. TSR stands for "terminate and stay resident", basically background programs in DOS.
by anyfoo 2y ago
When I was young, I discovered the joy of writing TSR programs in assembly. TSR stands for "terminate and stay resident", basically background programs in DOS. It's somewhat similar to what you would call a "daemon" in Unix, though much more "free form" and low level.
One such early TSR of mine hooked the disk services interrupt (INT 13h I believe), which got invoked whenever you want to access the disk through the BIOS (so, almost always), and my program then output a little "click" over the speaker. The result was as if you took the already very audible seeking of spinning hard disks and made it really, really loud. It wasn't even my idea, just a fun premise to fiddle with hooking interrupt handlers.
I compiled/assembled the TSR, ran it, and typed "DIR". The expected clicking came out of the speaker with every disk access, which indeed sounded funny and great, but at the end of the directory listing, an error appeared. I typed "DIR" again, and now listing the directory failed entirely.
In a bout of incredible stupidity, I typed "CD \" to change to the root directory, and "DIR" again. Now I couldn't list my root directory. I reset my computer and... DOS did not boot anymore.
It suddenly became immediately clear what I had done. My interrupt handler, after outputting the click over the speaker, obviously had to call back into the old handler, to actually service the requested disk access. When saving and restoring the registers that instruct the original handler what disk access to perform, I must have messed up in a way that it, at least sufficiently often, converted a read access into a write access. I don't remember the details, probably just flipping a single bit would do that. But effectively I've overwritten every sector of my root directory (and the original working one) with junk.
So I had destroyed at least my root directory, and hence lost access to all my data.
With lots of work I probably could have pieced my root directory back together. Nowadays, I'd probably have taken it as an exciting challenge to write a program that heuristically does just that by itself. Back then, I'm pretty sure I just abandoned the file system and started over.