What does TSR stands for?
TSR stands for Terminate- and Stay-Resident programs
What’s Special about TSR!
As the name says Terminate-and-Stay-Resident TSR are programs which get loaded in memory and remain or stay there (resident) in memory permanently. They will be removed only when the computer is rebooted or if the TSR is explicitly removed from memory. Until then they will stay (resident) in memory active
Working Technology of TSR
Nothing happens because of TSR occupying place in memory. In other words when TSR is not running it does not affect the running of other DOS programs. It stays in memory in idle state. Only thing it does is it occupies memory space and the occupied TSR memory space cannot be occupied by other programs. So users have to take care of this aspect when writing TSR’s. Since when number of TSR’s is written then each occupies memory space and these spaces cannot be occupied by other programs. So design the TSR’s taking this aspect into consideration.
Now let us see the working technology of TSR.
We know that TSR gets loaded into memory and stays there. When number of TSR’s is loaded the TSR gets loaded in the structure of STACK. This is nothing but the TSR gets piled up one above the other with the latest TSR loaded on the top. So one may get amazed how to activate a particular TSR if there are number of TSR available in stack.
This is done by activating keys which gets associated with TSR. When the particular key associated with TSR gets activated then the corresponding TSR is called which means the program that is associated with that TSR from memory (which is already present in memory) gets activated. Now the next question that pops into one’s mind is how the keys and TSR gets associated. In other words when a key is presses how is the TSR corresponding to it gets activated.
This is done if we understand the simple technology of IVT named as Interrupt Vector Table. Let us see in detail how it works.
Normally Interrupt Vector Table has the address of Interrupt Service Routine which is nothing but the routine that should be handled in case of an interrupt. So in a normal process when an interrupt occurs the interrupt number is multiplied by four and this result is searched in Interrupt Vector Table and the contents of this result in Interrupt Vector Table gives the address of interrupt service routine. After getting the routine’s address the control passes to the routine and the action as specified in routine gets executed. This is normal process that takes place.
But now interesting fact to know is how TSR gets activated here on event of pressing a key that is in case of an interrupt. This is done by TSR as follows. When a normal interrupt occur the address of Interrupt Service Routine is replaced with address from TSR routines. So after this the process continues as before. That is the routine checks to find if the interrupt has any association with TSR keys if it is then the corresponding routine gets executed. Otherwise the control returns to Interrupt service Routine which is the original process.
Suppose if we have number of TSR loaded as stack the process is same except that check is made to find if the interrupt has association with TSR key sequence that is in top of stack in other words with the TSR that was loaded the latest. If it is it executes the process associated with that TSR otherwise control passes to the next TSR in stack to perform the check whether it has association with the interrupt and this process goes on. After all TSR is checked and processed the control gets back to the original Interrupt Service Routine and the process continues as usual.
Relationship between Virus and TSR
One more interesting fact to know about is about the similarities between virus and TSR. All viruses are TSR’s but none of the TSR’s is virus. This fact is because TSR are Terminate-Stay-Resident programs which will get loaded in memory and stay there permanently until explicitly removed. Similarly viruses also get loaded and stay in memory. But the main difference is virus gets into memory without users knowledge but TSR gets into memory in the control of user since it is written by users only.
So having known about TSR and its working terminology one may get an idea that we can remove virus by changing the contents of Interrupt vector table into original state. We can do that but the greatest risk associated here is while changing the contents of Interrupt vector table there is a possibility that some Terminate Stay Resident Programs which are already written and which exists in memory previously may have associated interrupts placed in Interrupt Vector Table.
While changing the Interrupt Vector Table for virus cleaning if we write on any of these TSR associated interrupt by mistake then the interrupts associated with existing TSR gets damaged . As a result of this activity the TSR will exist but without any use that is in other words the associated interrupt will not be called. These effects cause the TSR to stay in memory without having any effect. So users have to take care while doing this process and it is better to avoid this activity.