home *** CD-ROM | disk | FTP | other *** search
/ Various Unprotection Examples / unprotect.zip / unprotect / COPYPROT / TIMER.SK < prev    next >
Text File  |  1985-03-20  |  4KB  |  100 lines

  1. TIMER          Found on Compuserve
  2.  
  3.     Keywords: SIDEKICK PRINT BORLAND TIMER INTERRUPT FIX PATCH
  4.     
  5.     This is an explination of the internal workings of Print.Com, a file
  6.     included in DOS for the IBM PC and compatibles.  It explains how this
  7.     program fails to do its part to insure integrity of all registers.  For
  8.     this reason some trouble was being experienced while using both SideKick
  9.     and Print.
  10.     
  11. .op
  12. The timer tick generates an interrupt 8 18.2 per second.  When SK 
  13. is not active, this interrupt is handled by the Bios as follows:
  14.  
  15. It  pushes  all registers used by the routine (AX among  others.)  
  16. It updates the system timer count.
  17. It updates the disk motor timer count.
  18. It generates an int 1C.
  19.  
  20. When  the spooler is active,  it has placed a vector at  int  1C, 
  21. pointing  at  the  spooler's  code.   The  spooler  is  therefore 
  22. activated in the middle of the int 8 handling.   The cause of the 
  23. trouble  is  that the spooler now uses the ax register  with  out   
  24. saving  it first.   The fact that this usually doesn't cause  any 
  25. problems is that the Bios int 8 routine restores the ax  register 
  26. when the Spooler returns.
  27.  
  28. It generates an end-of-interrupt to the interrupt controler.  
  29. It pops the registers that where pushed.
  30. It does an interrupt return.
  31.  
  32. With  SK  loaded it's a different story because SK uses int 8  to 
  33. check  the  keyboard  for CTRL-Alt.   We  therefore  replace  the 
  34. address  of  the bios int 8 routine with the address of  our  own 
  35. routine.  The address of the bios routine is saved in order to be 
  36. able to call it later.
  37.  
  38. When you first start SK from DOS, we read the int 10 detector and 
  39. store  it.   Then, each time you activate SK,  we also  read  and 
  40. store   the  vector  at  int 10 and  then  replace   it  with  an 
  41. interrupt return.
  42.  
  43. At each timer tick, the following happens:
  44.  
  45. SK  received the int  8 and calls the bios int 8 routine to  make 
  46. sure  that the timer tick is properly handles.   The bios  int  8 
  47. routine does the same as above:
  48.  
  49. It pushes all registers used by the routine (AX among others).
  50. It updates the system timer count.
  51. It updates the disk motor timer count.
  52. It generates an int 10.
  53. SK  has replaced the vector that the spooler placed here  with  a 
  54. IRET,  so  nothing happens.   This is because we cannot allow the 
  55. timer tick to pass through to programs which use it,  for example 
  56. to write on the screen.
  57.  
  58. It generates an end-of-interrupt to the interrupt controler.
  59. It pops the registers that were pushed. 
  60. It does an interrupt return.
  61.  
  62. Back in SK's int 8 routine we make a call to the address that was 
  63. stored at int 10 when SK was first started.  In this way he still 
  64. services any resident programs that were loaded before SK.   With 
  65. the spooler active we therefore make a call to the spooler.
  66.  
  67. The  spooler  again corrupts the AX register because it  uses  it 
  68. without saving it first.
  69. Back  in SK we have no way of restoring the original contents  of 
  70. the  AX register because we did not save it (why  should  we,  we 
  71. don't use it.)
  72.  
  73. In  short,  the root of the trouble is that the spooler  destroys 
  74. the AX register.  The fact that the Bio's int 8 routine saves and 
  75. stores it is pure coincidence.
  76.  
  77. I quote from the Technical Reference Manual,  Pages 2-5,  Section 
  78. Interrupt Hex 1C-timer tick:
  79.  
  80. "It is the responsibility of the application to save and  restore 
  81. all registers that will be modified."
  82.  
  83. Relying  on a version of the Bios which happens to save  register 
  84. AX is bad programming practice.   However,  the guy who wrote the 
  85. print  spooler did not rely on this because at another  point  in 
  86. his  program  he  does correctly save AX.   Obviously  he  simply 
  87. forgot and fortunately for him the Bios saved him.
  88.  
  89. The following patch will fix the problem:
  90.  
  91. SK.COM unprotected version change 7F8: 55 to 7F8: 50
  92. SK.COM unprotected version change 805: 5D to 805: 58
  93.  
  94. SK.COM protected version change 801: 55 to 801: 50
  95. SK.COM protected version change 80E: 5D to 80E: 58
  96.  
  97. Also on both above change 012C: 41 to 012C: 42  
  98.  
  99.  
  100.