home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / reboot1.lzh / BOOT.ASM next >
Assembly Source File  |  1990-01-16  |  4KB  |  133 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    'BOOT$   '
  29. reserved    db    8 DUP (0)
  30.  
  31. devhlp      dd    ?     ;devhlp entry
  32. reboot      dd    ?     ;reboot vector
  33.  
  34. initmsg     db    LF,'"BOOT$" successfully installed.',CR,LF
  35. initlen     equ   $-initmsg
  36.  
  37. failmsg     db    LF,'Reboot Driver "BOOT$" 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.             mov      di, es:[bx+13]    ; get category
  60.             cmp      di, 80h
  61.             jne      serr
  62.             jmp      dword ptr [reboot]      ;reboot machine
  63.  
  64. serr:       mov      ax,8103h          ;bad command - return error
  65.  
  66. sdone:      mov      es:[bx+3],ax
  67.             ret
  68.  
  69. strategy    endp
  70.  
  71.  
  72. init        proc near
  73.  
  74.             mov      ax, es:[bx+14]       ;save devhlp address
  75.             mov      word ptr devhlp, ax
  76.             mov      ax, es:[bx+16]
  77.             mov      word ptr devhlp+2,ax
  78.  
  79.             push     bx                ;save interesting registers
  80.             push     es
  81.             push     dx
  82.             mov      al,5              ;get reboot vector
  83.             mov      dl,24H
  84.             call     devhlp            ;GetDosVar
  85.             jc       fail              ;GetDosVar failed - quit install.
  86.  
  87.             mov      es, ax                     ;place reboot vector in
  88.             mov      ax,  word ptr es:[bx]      ;data segment
  89.             mov      word ptr reboot, ax
  90.             mov      bx,  word ptr es:[bx+2]
  91.             mov      word ptr reboot+2, bx
  92.  
  93. fail:       pop      dx                ;restore regs
  94.             pop      es
  95.             pop      bx
  96.             jnc      success           ;no carry - GetDosVar succeeded
  97.                                        ;and reboot vector saved
  98.  
  99.             push     CON               ;print failure message
  100.             push     faillen
  101.             push     ds
  102.             push     offset _DATA:failmsg
  103.             call     DosPutMessage
  104.  
  105. ;return zeros for end of code and data segments
  106.  
  107.             mov      word ptr es:[bx+14], offset _TEXT:0
  108.             mov      word ptr es:[bx+16], offset _DATA:0
  109.  
  110.             mov      ax,8103h          ;return failure
  111.             jmp      short idone
  112.  
  113. success:    push     CON               ;print appropriate message
  114.             push     initlen
  115.             push     ds
  116.             push     offset _DATA:initmsg
  117.             call     DosPutMessage
  118.  
  119. ;return end of code and data segments
  120.  
  121.             mov      word ptr es:[bx+14], offset _TEXT:init
  122.             mov      word ptr es:[bx+16], offset _DATA:initmsg
  123.  
  124.             mov      ax, 0100h         ;return successful init
  125.  
  126. idone:      ret
  127.  
  128. init        endp
  129.  
  130. _TEXT       ends
  131.             end
  132.  
  133.