home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / GDT.ZIP / DEVHLP.ASM next >
Assembly Source File  |  1989-01-08  |  7KB  |  245 lines

  1. ; devhlp.asm -- to produce DEVHLP.SYS
  2. ; cf. template in MSJ, March 1988
  3. ; Andrew Schulman, December 1988
  4.  
  5. ; DEF file:
  6. ; LIBRARY DEVHLP
  7. ; DESCRIPTION 'DEVHLP.SYS (c) Andrew Schulman 1988'
  8. ; PROTMODE
  9.  
  10. ; masm devhlp && link devhlp,devhlp.sys,,\msc\lib\doscalls,devhlp.def
  11.  
  12. ; put in config.sys:
  13. ; device=devhlp.sys
  14.  
  15. ; access with DosOpen ("DEVHLPXX"), DosDevIOCTL (category 128)
  16.  
  17. ; make sure this works in real mode -- possibly use as bridge for OS/2
  18. ; programs to call real-mode code?
  19.  
  20. ; make sure can be used by multiple apps at same time
  21.  
  22. .286p
  23.  
  24. maxcmd      equ     26
  25. stdout      equ     1
  26. cr          equ     0dh
  27. lf          equ     0ah
  28.  
  29. ; the only specific DevHlp that DEVHLP.SYS should know about
  30. VerifyAccess    equ     27h
  31.  
  32. ioctlpkt    struc
  33.                 db      13 dup(?)           ; header
  34.     cat         db      ?                   ; category
  35.     fun         db      ?                   ; function
  36.     param       dd      ?                   ; param area
  37.     dataptr     dd      ?                   ; data area
  38. ioctlpkt    ends
  39.  
  40. ; typedef struct {
  41. ;     USHORT ax,bx,cx,dx,si,di,ds,es;
  42. ;     FLAGS flags;
  43. ;     } REGS;
  44.     
  45. regs        struc
  46.     regs_ax     dw      ?
  47.     regs_bx     dw      ?
  48.     regs_cx     dw      ?
  49.     regs_dx     dw      ?
  50.     regs_si     dw      ?
  51.     regs_di     dw      ?
  52.     regs_ds     dw      ?
  53.     regs_es     dw      ?
  54.     regs_flags  dw      ?
  55. regs        ends
  56.  
  57. regs_size   equ     18
  58.  
  59. dgroup      group   _DATA
  60.  
  61. _DATA       segment word public 'DATA'
  62.  
  63. header      dd          -1
  64.             dw          8880h
  65.             dw          Strat
  66.             dw          0
  67.             db          'DEVHLPXX'
  68.             db          8 dup (0)
  69.  
  70. DevHlp      dd      0
  71.  
  72. dispch      dw      Init            ; 0 -- Init
  73.             dw      Error           ; 1
  74.             dw      Error           ; 2
  75.             dw      Error           ; 3
  76.             dw      Error           ; 4
  77.             dw      Error           ; 5
  78.             dw      Error           ; 6
  79.             dw      Error           ; 7
  80.             dw      Error           ; 8
  81.             dw      Error           ; 9
  82.             dw      Error           ; 10
  83.             dw      Error           ; 11
  84.             dw      Error           ; 12
  85.             dw      DevOp           ; 13 -- DevOpen
  86.             dw      DevOp           ; 14 -- DevClose
  87.             dw      Error           ; 15
  88.             dw      GenIOCtl        ; 16 -- DevIOCtl
  89.             dw      Error           ; 17
  90.             dw      Error           ; 18
  91.             dw      Error           ; 19
  92.             dw      Error           ; 20
  93.             dw      Error           ; 21
  94.             dw      Error           ; 22
  95.             dw      Error           ; 23
  96.             dw      Error           ; 24
  97.             dw      Error           ; 25
  98.             dw      Error           ; 26
  99.  
  100. Ident       db      ?   ; ?????
  101.  
  102. _DATA       ends
  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]
  110.             and di,0ffh
  111.             cmp di,maxcmd
  112.             jle Strat1
  113.             call Error
  114.             jmp short Strat2
  115. Strat1:     add di,di
  116.             call word ptr [di+dispch]
  117. Strat2:     mov word ptr es:[bx+3],ax       ; set request header status
  118.             ret
  119. Strat       endp
  120.  
  121. ; used by DevOpen and DevClose
  122. DevOp       proc near
  123.             mov ax,0100h
  124.             ret
  125. DevOp       endp
  126.  
  127. ;; use category #128, function 0x60 (bitmapped function codes!)
  128. ;; entry point for app access to DevHlp
  129. ;; INPUT:  regs struct (using only ax,bx,cx,dx,di)
  130. ;; OUTPUT: regs struct (using only ax,bx,es,ds,si,di,flags)
  131. ;; GenIOCtl is a completely ignorant data pass-through.  Knows nothing
  132. ;; about any specific DevHlp (except VerifyAccess, which it should use
  133. ;; for its own purposes).  Just passes along registers (including DX,
  134. ;; which includes the DevHlp number).
  135. ;; The calling app must piece together output, just as in int86() function
  136. ;; in C for MS-DOS.  Note that GenIOCtl doesn't even look at flags --
  137. ;; just passes them back for the app to inspect.
  138. ;; essentially, this is Remote Procedure Call via packets
  139.  
  140. GenIOCtl    proc near
  141.  
  142.             push es
  143.             push bx
  144.  
  145.             mov ax,8101h                        ; assume error
  146.  
  147.             cmp es:[bx].cat,128
  148.             jne done
  149.             mov ch,es:[bx].fun
  150.             cmp ch,60h
  151.             je Op_DevHlp
  152.             ; other functions could go here
  153.             jmp short done
  154.  
  155. Op_DevHlp:
  156.             ; verify user's access:
  157.             ; VerifyAccess will shut down user's app in the event of error,
  158.             ; We could use VERR, VERW, and LSL, but these won't work 
  159.             ; in real-mode, and the device driver must work in real mode too!
  160.             mov ax,word ptr es:[bx+17]          ; selector
  161.             mov di,word ptr es:[bx+15]          ; offset
  162.             mov cx,regs_size                    ; length to be read
  163.             mov dh,0                            ; read
  164.             mov dl,VerifyAccess
  165.             call DevHlp
  166.             jc fini                             ; if carry flag set
  167.     
  168.             mov ax,word ptr es:[bx+21]          ; selector
  169.             mov di,word ptr es:[bx+19]          ; offset
  170.             mov cx,regs_size                    ; length to be written
  171.             mov dh,1                            ; read/write
  172.             mov dl,VerifyAccess
  173.             call DevHlp
  174.             jc fini
  175.  
  176.             push es                             ; going to be bashed!
  177.             push bx
  178.  
  179.             ; get the parameters for DevHlp from regs
  180.             ; need some way to possibly pass in ds and es??
  181.             push ds                             ; NB!!!!
  182.             lds di,es:[bx].param
  183.             mov ax,ds:[di].regs_ax
  184.             mov bx,ds:[di].regs_bx
  185.             mov cx,ds:[di].regs_cx
  186.             mov dx,ds:[di].regs_dx
  187.             mov di,ds:[di].regs_di
  188.             pop ds
  189.  
  190.             ; here it is, the whole point of this exercise!
  191.             call DevHlp     
  192.  
  193.             ; save ES:BX to put in out-regs
  194.             mov cx,es   
  195.             mov dx,bx   
  196.  
  197.             ; get back old ES:BX
  198.             pop bx
  199.             pop es
  200.  
  201.             ; save FLAGS, SI, DS on stack
  202.             pushf
  203.             push si
  204.             push ds
  205.  
  206.             ; set up regs to return to the app
  207.             lds si,es:[bx].dataptr
  208.             mov ds:[si].regs_ax,ax
  209.             pop ds:[si].regs_ds
  210.             pop ds:[si].regs_si
  211.             pop ds:[si].regs_flags
  212.             mov ds:[si].regs_bx,dx
  213.             mov ds:[si].regs_es,cx
  214.             mov ds:[si].regs_di,di
  215.  
  216. fini:
  217.             mov ax,0100h                        ; no error
  218. done:
  219.             pop bx
  220.             pop es
  221.             ret
  222. GenIOCtl    endp
  223.  
  224. Error       proc near
  225.             mov ax,8103h
  226.             ret
  227. Error       endp
  228.  
  229. Init        proc near
  230.             mov ax,es:[bx+14]
  231.             mov word ptr DevHlp,ax
  232.             mov ax,es:[bx+16]
  233.             mov word ptr DevHlp+2,ax
  234.  
  235.             mov word ptr es:[bx+14],offset _TEXT:Init
  236.             mov word ptr es:[bx+16],offset DGROUP:Ident
  237.  
  238.             mov ax,0100h
  239.             ret
  240. Init        endp
  241.  
  242. _TEXT       ends
  243.             
  244.             end
  245.