home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / reboot4.zip / REBOOTDR.ASM < prev    next >
Assembly Source File  |  1990-03-02  |  4KB  |  185 lines

  1.     title    REBOOTDR.ASM -- Installable device driver for OS/2 reboot
  2.     .286
  3.  
  4. ; REBOOTDR.ASM
  5. ; By Mitch Stuart and Paul Chen
  6. ;
  7. ; Reference:  TEMPLATE.ASM, Page 377, in Ray Duncan's "Advanced
  8. ;             OS/2 Programming," Microsoft Press, 1989.
  9. ;
  10. ; To assemble and link:
  11. ;
  12. ;     masm rebootdr.asm;
  13. ;     link rebootdr,rebootdr.sys,,os2,rebootdr
  14. ;
  15. ; Apparently some versions of the linker will call the resulting file
  16. ; "REBOOTDR.DLL" even though we specifed ".SYS" on the command line.
  17. ; In this case, just rename REBOOTDR.DLL to REBOOTDR.SYS and it will
  18. ; work fine.
  19. ;
  20. ; To install, add the line "DEVICE=REBOOTDR.SYS" to the CONFIG.SYS file.
  21. ; To reboot, type REBOOT2.  REBOOT2.EXE is a program file that simply
  22. ; attempts to open the device "REBOOTZZ", thus causing the machine to
  23. ; reboot.
  24. ;
  25. ; Description:
  26. ;
  27. ;    This device driver gets installed at boot time.  It sets up a
  28. ; dummy character device driver called "REBOOTZZ".  Then, when an 
  29. ; application opens the device "REBOOTZZ", this driver gets control.
  30. ; It calls one of the DevHlp functions to get the system reboot
  31. ; vector, and then jumps to that address, causing the system to reboot.
  32. ;
  33. maxcmd        equ        26
  34.  
  35. stdin        equ        0
  36. stdout        equ        1
  37. stderr        equ        2
  38.  
  39. cr        equ        0dh
  40. lf        equ        0ah
  41.  
  42. GetDosVar    equ        24h
  43. GetRebootVector    equ        5
  44.  
  45.         extrn        DosWrite:far
  46.  
  47. DGROUP        group        _DATA
  48.  
  49. _DATA        segment word public 'DATA'
  50.  
  51. ; ***** Device driver header
  52.  
  53. header        dd        -1
  54.         dw        8880h
  55.         dw        Strat        ; our "stragegy" entry point
  56.         dw        0
  57.         db        'REBOOTZZ'    
  58.         db        8 dup (0)
  59.  
  60. ; ***** Device driver variables
  61.  
  62. devhlp        dd        ?        ; DevHlp entry point
  63. wlen        dw        ?        ; DosWrite length
  64.  
  65. ; ***** Dispatch table 
  66.  
  67. dispch        dw        Init        ; 0   Init driver
  68.         dw        ReturnOK    ; 1   Media check
  69.         dw        ReturnOK    ; 2   Build BPB
  70.         dw        Error        ; 3   not used
  71.         dw        ReturnOK    ; 4   Read
  72.         dw        ReturnOK    ; 5   Nondestructive read
  73.         dw        ReturnOK    ; 6   Return input status
  74.         dw        ReturnOK    ; 7   Flush input buffers
  75.         dw        ReturnOK    ; 8   Write
  76.         dw        ReturnOK    ; 9   Write with verify
  77.         dw        ReturnOK    ; 10  Return output status
  78.         dw        ReturnOK    ; 11  Flush output buffers
  79.         dw        Error        ; 12  not used
  80.         dw        DevOpen        ; 13  Open
  81.         dw        ReturnOK    ; 14  Close
  82.         dw        ReturnOK    ; 15  Removable media
  83.         dw        ReturnOK    ; 16  Generic IOCTL
  84.         dw        ReturnOK    ; 17  Reset media
  85.         dw        ReturnOK    ; 18  Get logical drive
  86.         dw        ReturnOK    ; 19  Set logical drive
  87.         dw        ReturnOK    ; 20  Deinstall
  88.         dw        Error        ; 21  not used
  89.         dw        ReturnOK    ; 22  Partitionable fixed disks
  90.         dw        ReturnOK    ; 23  Get fixed disk unit map
  91.         dw        Error        ; 24  not used
  92.         dw        Error        ; 25  not used
  93.         dw        Error        ; 26  not used
  94.  
  95. ident        db        cr,lf
  96.         db        'OS/2 reboot driver loaded.  '
  97.         db        'Type REBOOT2 to reboot system.'
  98.         db        cr,lf
  99. ident_len    equ        $ - ident
  100.  
  101. _DATA        ends
  102.  
  103.  
  104. _TEXT        segment word public 'CODE'
  105.  
  106.         assume cs:_TEXT,ds:DGROUP,es:NOTHING
  107.  
  108. Strat        proc        far
  109.         mov        di,es:[bx+2]    ; get command code
  110.         and        di,0ffh
  111.         cmp        di,maxcmd    ; supported command?
  112.         jle        Strat1        ; yes
  113.         call        Error        ; unsupported command
  114.         jmp        Strat2
  115.  
  116. Strat1:        add        di,di        ; branch to command handler
  117.         call        word ptr [di+dispch]
  118.  
  119. Strat2:        mov        es:[bx+3],ax    ; return status code
  120.         ret
  121. Strat        endp
  122.  
  123.  
  124. DevOpen        proc        near
  125.  
  126.         ; Get the address of the reboot vector
  127.         mov        dl,GetDosVar
  128.         mov        al,GetRebootVector
  129.         call        devhlp
  130.  
  131.                 ; AX:BX now contains the reboot vector
  132.                 ; We want it to be in ES:BX for a far jump
  133.                 mov             es, ax
  134.  
  135.         ; Jump to vector and reboot
  136.         jmp   dword ptr es:[bx]
  137.  
  138.                 ; We should never get here, but return just in case ...
  139.         mov        ax,0100h    ; return "done" status
  140.         ret
  141. DevOpen        endp
  142.  
  143.  
  144. Error        proc        near        ; set error bit, done status
  145.         mov        ax,8103h    ; and unknown command code
  146.         ret
  147. Error        endp
  148.  
  149.  
  150. ReturnOK    proc        near
  151.         mov        ax,0100h    ; return "done" status
  152.         ret
  153. ReturnOK    endp
  154.  
  155.  
  156. Init        proc        near
  157.         mov        ax,es:[bx+14]    ; get DevHlp entry point
  158.         mov        word ptr devhlp,ax
  159.         mov        ax,es:[bx+16]    
  160.         mov        word ptr devhlp+2,ax
  161.  
  162.         ; set offsets to end of code and data segments
  163.         mov        word ptr es:[bx+14],offset _TEXT:Init
  164.         mov        word ptr es:[bx+16],offset DGROUP:ident
  165.  
  166.         ; display sign-on message
  167.         push        stdout
  168.         push        ds
  169.         push        offset DGROUP:ident
  170.         push        ident_len
  171.         push        ds
  172.         push        offset DGROUP:wlen
  173.         call        DosWrite
  174.  
  175.         mov        ax,0100h        ; return "done"
  176.         ret
  177. Init        endp
  178.  
  179. _TEXT        ends
  180.  
  181.         end
  182.  
  183.  
  184.  
  185.