home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12362.ZIP / BOOTDD.ASM < prev    next >
Assembly Source File  |  1989-05-11  |  4KB  |  129 lines

  1. ;bootdd.asm - Reboot Device Driver example
  2.  
  3. ;The driver installs and waits for an ioctl call.  When the call is
  4. ;received - it reboots the machine.
  5.  
  6. .286
  7.  
  8.             extrn DosPutMessage:far
  9.  
  10. CR          equ   0Dh
  11. LF          equ   0Ah
  12. CON         equ   0
  13.  
  14. DAW_CHAR    equ   8000h
  15. DAW_LEVEL   equ   0080h
  16. DAW_IOCTL   equ   0040h
  17.  
  18. INIT_CMD    equ   0
  19. IOCTL_CMD   equ   10h
  20.  
  21.  
  22. _DATA       segment word public 'DATA'
  23.  
  24. devhdr      dd    -1
  25. devatt      dw    DAW_CHAR or DAW_LEVEL or DAW_IOCTL
  26. strat       dw    offset strategy
  27. ipc         dw    0
  28. devname     db    'REBOOT$ '
  29. reserved    db    8 DUP (0)
  30.  
  31. devhlp      dd    ?     ;devhlp entry
  32. reboot      dd    ?     ;reboot vector
  33.  
  34. initmsg     db    LF,'Reboot Driver "REBOOT$" successfully installed!',CR,LF
  35. initlen     equ   $-initmsg
  36.  
  37. failmsg     db    LF,'Reboot Driver "REBOOT$" failed to install!',CR,LF
  38. faillen     equ   $-failmsg
  39.  
  40.  
  41. _DATA       ends
  42.  
  43.  
  44.             assume cs:_TEXT,ds:_DATA
  45.  
  46. _TEXT       segment word public 'CODE'
  47.  
  48. strategy    proc far
  49.  
  50.             mov      di,es:[bx+2]      ;get command
  51.  
  52.             cmp      di,INIT_CMD       ;init command?
  53.             jne      ioctl
  54.             call     init
  55.             jmp      short sdone
  56.  
  57. ioctl:      cmp      di,IOCTL_CMD      ;ioctl command?
  58.             jne      serr
  59.             jmp      dword ptr [reboot]      ;reboot machine
  60.  
  61. serr:       mov      ax,8103h          ;bad command - return error
  62.  
  63. sdone:      mov      es:[bx+3],ax
  64.             ret
  65.  
  66. strategy    endp
  67.  
  68.  
  69. init        proc near
  70.  
  71.             mov      ax, es:[bx+14]       ;save devhlp address
  72.             mov      word ptr devhlp, ax
  73.             mov      ax, es:[bx+16]
  74.             mov      word ptr devhlp+2,ax
  75.  
  76.             push     bx                ;save interesting registers
  77.             push     es
  78.             push     dx
  79.             mov      al,5              ;get reboot vector
  80.             mov      dl,24H
  81.             call     devhlp            ;GetDosVar
  82.             jc       fail              ;GetDosVar failed - quit install.
  83.  
  84.             mov      es, ax                     ;place reboot vector in
  85.             mov      ax,  word ptr es:[bx]      ;data segment
  86.             mov      word ptr reboot, ax
  87.             mov      bx,  word ptr es:[bx+2]
  88.             mov      word ptr reboot+2, bx
  89.  
  90. fail:       pop      dx                ;restore regs
  91.             pop      es
  92.             pop      bx
  93.             jnc      success           ;no carry - GetDosVar succeeded
  94.                                        ;and reboot vector saved
  95.  
  96.             push     CON               ;print failure message
  97.             push     faillen
  98.             push     ds
  99.             push     offset _DATA:failmsg
  100.             call     DosPutMessage
  101.  
  102. ;return zeros for end of code and data segments
  103.  
  104.             mov      word ptr es:[bx+14], offset _TEXT:0
  105.             mov      word ptr es:[bx+16], offset _DATA:0
  106.  
  107.             mov      ax,8103h          ;return failure
  108.             jmp      short idone
  109.  
  110. success:    push     CON               ;print appropriate message
  111.             push     initlen
  112.             push     ds
  113.             push     offset _DATA:initmsg
  114.             call     DosPutMessage
  115.  
  116. ;return end of code and data segments
  117.  
  118.             mov      word ptr es:[bx+14], offset _TEXT:init
  119.             mov      word ptr es:[bx+16], offset _DATA:initmsg
  120.  
  121.             mov      ax, 0100h         ;return successful init
  122.  
  123. idone:      ret
  124.  
  125. init        endp
  126.  
  127. _TEXT       ends
  128.             end
  129.