home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n21.zip / DGREBOOT.PAS < prev    next >
Pascal/Delphi Source File  |  1990-09-25  |  11KB  |  262 lines

  1. {
  2.  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3.  █                                                                         █
  4.  █        TITLE :      DGREBOOT.TPU                                        █
  5.  █      PURPOSE :      Reboot functions.  USE WITH EXTREME CARE.           █
  6.  █       AUTHOR :      David Gerrold, CompuServe ID:  70307,544            █
  7.  █ ______________________________________________________________________  █
  8.  █                                                                         █
  9.  █   Written in Turbo Pascal, Version 5.5,                                 █
  10.  █   with routines from TurboPower, Object Professional.                   █
  11.  █                                                                         █
  12.  █   Turbo Pascal is a product of Borland International.                   █
  13.  █   Object Professional is a product of TurboPower Software.              █
  14.  █ ______________________________________________________________________  █
  15.  █                                                                         █
  16.  █   This is not public domain software.                                   █
  17.  █   This software is copyright 1990, by David Gerrold.                    █
  18.  █   Permission is hereby granted for personal use.                        █
  19.  █                                                                         █
  20.  █        The Brass Cannon Corporation                                     █
  21.  █        9420 Reseda Blvd., #804                                          █
  22.  █        Northridge, CA  91324-2932.                                      █
  23.  █                                                                         █
  24.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  25.                                                                             }
  26. { Compiler Directives ===================================================== }
  27.  
  28. {$A-}    {Switch word alignment off, necessary for cloning}
  29. {$R-}    {Range checking off}
  30. {$B-}    {Boolean complete evaluation off}
  31. {$S-}    {Stack checking off}
  32. {$I-}    {I/O checking off}
  33. {$N+,E+} {Simulate numeric coprocessor}
  34. {$M 16384,0,327680} {stack and heap}
  35. {$V-}    {Variable range checking off}
  36.  
  37. { Name ==================================================================== }
  38.  
  39. UNIT DgReboot;
  40. {
  41.   The purpose of DgReboot is to provide routines for handling rebooting
  42.   the system from within a program.
  43. }
  44.  
  45. { Interface =============================================================== }
  46.  
  47. INTERFACE
  48.  
  49. USES
  50.  
  51. { Turbo Pascal 5.5 Unit }
  52.   Dos;
  53.  
  54. { Declarations ============================================================ }
  55. { Functions and Procedures ================================================ }
  56. {
  57.   USE WITH EXTREME CARE!
  58. }
  59. PROCEDURE WarmBoot;
  60. { like pressing Ctrl-Alt-Delete }
  61.  
  62. PROCEDURE ColdBoot;
  63. { like hitting the Big Red Switch }
  64.  
  65. PROCEDURE DisableReboot;
  66. { no more Ctrl-Alt-Delete }
  67.  
  68. PROCEDURE EnableReboot;
  69. { reinstalls Ctrl-Alt-Delete }
  70.  
  71. { Implementation ========================================================== }
  72.  
  73. IMPLEMENTATION
  74.  
  75. { ========================================================================= }
  76. { Disable/Enable declarations --------------------------------------------- }
  77.  
  78. CONST
  79.   D_Key   = 83;                                  { delete key scancode }
  80.  
  81. VAR
  82.   Kbd_Vec : Pointer;
  83.  
  84. { ========================================================================= }
  85. { WarmBoot ================================================================ }
  86. {
  87.   WarmBoot and ColdBoot, written by Carley Philips of Borland International.
  88.   Downloaded from CompuServe, BPROGA forum.
  89. }
  90.  
  91. PROCEDURE WarmBoot;
  92. { Warm boot.  Same as Ctrl-Alt-Del }
  93.  
  94. BEGIN
  95. Inline(                    {Assembly by Inline 04/04/88 21:41}
  96.   $B8/$40/$00/             {mov ax,$40         ;BIOS data segment}
  97.   $8E/$D8/                 {mov ds,ax          ;mov to DS}
  98.   $C7/$06/$72/$00/$34/$12/ {mov wo [$72],$1234 ;set keyboard reset flag}
  99.   $EA/$00/$00/$FF/$FF);    {jmp $FFFF:0000     ;go to BIOS reset}
  100. END;
  101.  
  102. { ColdBoot ================================================================ }
  103.  
  104. PROCEDURE ColdBoot;
  105. { Cold boot.  Same as reset button except hardware is not reset }
  106.  
  107. BEGIN
  108. Inline(                    {Assembly by Inline 04/04/88 21:41}
  109.   $B8/$40/$00/             {mov ax,$40         ;BIOS data segment}
  110.   $8E/$D8/                 {mov ds,ax          ;mov to DS}
  111.   $C7/$06/$72/$00/$00/$00/ {mov wo [$72],$0000 ;say not keyboard reset}
  112.   $EA/$00/$00/$FF/$FF);    {jmp $FFFF:0000     ;go to BIOS reset}
  113. END;
  114.  
  115. { PROCEDURE Int9_ISR ====================================================== }
  116.  
  117. {
  118.   Giving credit where credit is due:
  119.  
  120.   This inline code is lifted directly from Neil Rubenking's article
  121.   on page 8 of the Jan/Feb 88 issue of Turbo Technix.
  122.  
  123.   It is also available on CompuServe, Borland's Turbo Pascal Forum,
  124.   BPROGA, as part of a file called KEYINT.ARC;  KEYINT.ARC demonstrates
  125.   a number of things that can be done by replacing the standard keyboard
  126.   interrupt handler.  It can be found in the Turbo Pascal 4.x library.
  127. }
  128. PROCEDURE INT9_ISR (_Flags, _CS, _IP, _AX, _BX, _CX, _DX,
  129.                             _SI, _DI, _DS, _ES, _BP:word);
  130. INTERRUPT;
  131.   (* ======================================== *)
  132.   (* This routine suppresses the <Del> key.   *)
  133.   (* If it detects either a "make" or a       *)
  134.   (* "break" from the <Del> key, it simply    *)
  135.   (* resets the keyboard.  Without <Del>      *)
  136.   (* there's no way to enter <Ctrl><Alt><Del> *)
  137.   (* so you can't reboot.                     *)
  138.   (* ======================================== *)
  139.  
  140. BEGIN
  141.   INLINE(
  142.   $FB/              {STI            ;Allow interrupts}
  143.   $9C/              {PUSHF          ;Save the flags}
  144.   $E4/$60/          {IN   AL,$60    ;READ the keyboard port}
  145.   $24/$7F/          {AND  AL,$7F    ;Mask off "break bit"}
  146.   $3C/<D_KEY/       {CMP  AL,<D_KEY ;Is it a "Del" key?}
  147.   $74/$18/          {JZ   GetOut    ;If so, throw it away}
  148.   (* ============================ *)
  149.   (* CHAIN to the regular INT 9   *)
  150.   (* ============================ *)
  151.   $9D/              {POPF         ;Restore the flags}
  152.   $A1/>KBD_VEC+2/   {MOV  AX,[>KBD_VEC+2] ;Old vector seg to AX}
  153.   $8B/$1E/>KBD_VEC/ {MOV  BX,[>KBD_VEC]   ;Old vector ofs to BX}
  154.   $87/$5E/$0E/      {XCHG BX,[BP+$0E] ;Swap ofs w/ return address}
  155.   $87/$46/$10/      {XCHG AX,[BP+$10] ;Swap seg w/ return address}
  156.   $89/$EC/          {MOV  SP,BP ;UNDO procedure's entry code}
  157.   $5D/              {POP  BP}
  158.   $07/              {POP  ES}
  159.   $1F/              {POP  DS}
  160.   $5F/              {POP  DI}
  161.   $5E/              {POP  SI}
  162.   $5A/              {POP  DX}
  163.   $59/              {POP  CX}
  164.   $CB/              {RETF ;in effect, JMP to old vector}
  165. {GetOut:}
  166.   $E4/$61/          {IN   AL,$61  ;Read Kbd controller port}
  167.   $88/$C4/          {MOV  AH,AL}
  168.   $0C/$80/          {OR   AL,$80  ;Set the "reset" bit and}
  169.   $E6/$61/          {OUT  $61,AL  ;  send it back to control}
  170.   $86/$C4/          {XCHG AH,AL   ;Get back control value}
  171.   $E6/$61/          {OUT  $61,AL  ;  and send it too}
  172.   $9D/              {POPF         ;Restore the flags}
  173.   $FA/              {CLI          ;No interrupts }
  174.   $B0/$20/          {MOV  AL,+$20 ;Send an EOI to the}
  175.   $E6/$20);         {OUT  $20,AL  ;  interrupt controller }
  176. END;
  177.  
  178. { DisableReboot =========================================================== }
  179.  
  180. PROCEDURE DisableReboot;
  181. { shell for interrupt handler, disables Ctrl-Alt-Delete }
  182.  
  183. BEGIN
  184.   SetIntVec (9, @INT9_ISR);                      { install new vector }
  185. END;
  186.  
  187. { EnableReboot ============================================================ }
  188.  
  189. PROCEDURE EnableReboot;
  190. { shell for interrupt handler, re-enables Ctrl-Alt-Delete }
  191.  
  192. BEGIN
  193.   SetIntVec (9, Kbd_vec);                        { restore OLD INT9 }
  194. END;
  195.  
  196. { ========================================================================= }
  197. { Initialization Variables ================================================ }
  198.  
  199. VAR
  200.   ExitSave     : pointer;                        { for ExitProc }
  201.  
  202. { ExitUnit ================================================================ }
  203.  
  204. {$F+} PROCEDURE ExitUnit; {$F-}
  205.  
  206. BEGIN
  207.   ExitProc := ExitSave;                          { reset original address }
  208.   EnableReboot;                                  { in case it's disabled }
  209. END;
  210.  
  211. { Initialization ========================================================== }
  212.  
  213. BEGIN
  214.   ExitSave := ExitProc;                          { save old exit address }
  215.   ExitProc := @ExitUnit;                         { get new exit address }
  216.  
  217. {
  218.   If the user wants to disable the reboot, he'll need to replace the
  219.   interrupt 9 vector;  to make sure that the original vector can be
  220.   reinstalled, so that rebooting can be re-enabled, its address will
  221.   be automatically saved in Kbd_Vec.
  222. }
  223.   GetIntVec (9, Kbd_Vec);                        { save old INT9 vector }
  224. END.
  225.  
  226. { ========================================================================= }
  227. { DgReboot History ======================================================== }
  228.  
  229. VERSION HISTORY:
  230.   9005.05
  231.     Totally restructured for consistency with Object Professional.
  232.  
  233. { DgReboot Needs ========================================================== }
  234.  
  235. NEED TO ADD:
  236.   Nothing right now.
  237.  
  238. { Bug Reports ============================================================= }
  239.  
  240. BUGS:
  241.   Would you believe that these are actually features?
  242.  
  243.   DisableReboot will not work with Sidekick installed.  Sidekick replaces
  244.   the standard interrupt 9 vector with its own and is very resistant to
  245.   any other program grabbing interrupt 9.  Therefore, while Sidekick is
  246.   active, the user will be able to ctrl-alt-delete reboot out of a locked
  247.   system.
  248.  
  249.   Do not use the DOS print command for background printing if you intend
  250.   to blank the screen or lock the system.  The argument over which routine
  251.   is entitled to use interrupt 9 will produce a fatal crash.  Plan on using
  252.   the big red switch.
  253.  
  254.   If you don't use Sidekick, and you don't use the DOS print command, you
  255.   should have no problem.  If you use either of these regularly, don't be
  256.   casual about using the lock program routines or anything else which uses
  257.   DisableReboot.
  258.  
  259. { ========================================================================= }
  260. { ========================================================================= }
  261.  
  262.