home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advos2 / ch17 / template.asm next >
Encoding:
Assembly Source File  |  1988-12-12  |  8.6 KB  |  325 lines

  1.     title    TEMPLATE -- Sample Device Driver
  2.         page    55,132
  3.         .286
  4.  
  5. ;
  6. ; TEMPLATE.ASM
  7. ;
  8. ; A sample OS/2 character device driver.  The driver command code
  9. ; routines are stubs only and have no effect but to return a
  10. ; nonerror "done" status.
  11. ;
  12. ; Assemble with:  C> masm template.asm;
  13. ; Link with:  C> link template,template.sys,,os2,template
  14. ;
  15. ; To install the driver, add "DEVICE=TEMPLATE.SYS" to CONFIG.SYS
  16. ; and reboot.
  17. ;
  18. ; Copyright (C) 1988 Ray Duncan
  19. ;
  20.  
  21. maxcmd  equ     26              ; maximum allowed command code
  22.  
  23. stdin   equ     0               ; standard device handles
  24. stdout  equ     1
  25. stderr  equ     2
  26.  
  27. cr      equ     0dh             ; ASCII carriage return
  28. lf    equ    0ah        ; ASCII linefeed
  29.  
  30.         extrn   DosWrite:far
  31.  
  32.  
  33. DGROUP  group   _DATA
  34.  
  35. _DATA   segment word public 'DATA'
  36.  
  37.                                 ; device driver header...
  38. header  dd      -1              ; link to next device driver
  39.         dw      8880h           ; device attribute word
  40.         dw      Strat           ; Strategy entry point
  41.     dw    0        ; IDC entry point
  42.         db      'TEMPLATE'      ; logical device name
  43.     db    8 dup (0)    ; reserved
  44.  
  45. devhlp  dd      ?               ; DevHlp entry point
  46.  
  47. wlen    dw      ?               ; receives DosWrite length 
  48.  
  49.                                 ; Strategy routine dispatch table
  50.                 ; for request packet command code...
  51. dispch  dw      Init            ; 0  = initialize driver
  52.         dw      MediaChk        ; 1  = media check
  53.         dw      BuildBPB        ; 2  = build BIOS parameter block
  54.         dw      Error           ; 3  = not used
  55.         dw      Read            ; 4  = read from device
  56.     dw    NdRead        ; 5  = nondestructive read
  57.         dw      InpStat         ; 6  = return input status
  58.         dw      InpFlush        ; 7  = flush device input buffers
  59.         dw      Write           ; 8  = write to device
  60.         dw      WriteVfy        ; 9  = write with verify
  61.         dw      OutStat         ; 10 = return output status
  62.         dw      OutFlush        ; 11 = flush output buffers
  63.         dw      Error           ; 12 = not used
  64.         dw      DevOpen         ; 13 = device open
  65.         dw      DevClose        ; 14 = device close
  66.     dw    RemMedia    ; 15 = removable media
  67.         dw      GenIOCTL        ; 16 = generic IOCTL
  68.         dw      ResetMed        ; 17 = reset media
  69.         dw      GetLogDrv       ; 18 = get logical drive
  70.         dw      SetLogDrv       ; 19 = set logical drive
  71.         dw      DeInstall       ; 20 = de-install
  72.         dw      Error           ; 21 = not used
  73.         dw      PartFD          ; 22 = partitionable fixed disks
  74.         dw      FDMap           ; 23 = get fixed disk unit map
  75.         dw      Error           ; 24 = not used
  76.         dw      Error           ; 25 = not used
  77.         dw      Error           ; 26 = not used
  78.  
  79. ident   db      cr,lf,lf
  80.     db    'TEMPLATE Sample OS/2 Device Driver'
  81.         db      cr,lf
  82. ident_len equ $-ident
  83.  
  84. _DATA   ends
  85.  
  86.  
  87. _TEXT   segment word public 'CODE'
  88.  
  89.         assume  cs:_TEXT,ds:DGROUP,es:NOTHING
  90.  
  91. Strat   proc    far             ; Strategy entry point
  92.                                 ; ES:BX = request packet address
  93.  
  94.         mov     di,es:[bx+2]    ; get command code from packet
  95.         and     di,0ffh
  96.         cmp     di,maxcmd       ; supported by this driver?
  97.         jle     Strat1          ; jump if command code OK
  98.  
  99.         call    Error           ; bad command code
  100.         jmp     Strat2
  101.  
  102. Strat1: add     di,di           ; branch to command code routine
  103.         call    word ptr [di+dispch]
  104.  
  105. Strat2: mov     es:[bx+3],ax    ; status into request packet
  106.         ret                     ; back to OS/2 kernel
  107.  
  108. Strat   endp
  109.  
  110.  
  111. Intr    proc  far               ; driver Interrupt handler
  112.  
  113.         clc                     ; signal we owned interrupt
  114.         ret                     ; return from interrupt
  115.  
  116. Intr    endp
  117.  
  118.  
  119. ; Command code routines are called by the Strategy routine
  120. ; via the Dispatch table with ES:BX pointing to the request
  121. ; header.  Each routine should return ES:BX unchanged
  122. ; and AX = status to be placed in request packet:
  123. ; 0100H if 'done' and no error
  124. ; 0000H if thread should block pending interrupt
  125. ; 81xxH if 'done' and error detected (xx=error code)
  126.  
  127. MediaChk proc   near            ; function 1 = media check
  128.         
  129.         mov     ax,0100h        ; return 'done' status
  130.         ret
  131.  
  132. MediaChk endp
  133.  
  134.  
  135. BuildBPB proc   near            ; function 2 = build BPB
  136.  
  137.         mov     ax,0100h        ; return 'done' status
  138.         ret
  139.  
  140. BuildBPB endp
  141.  
  142.  
  143. Read    proc    near            ; function 4 = read
  144.  
  145.         mov     ax,0100h        ; return 'done' status
  146.         ret
  147.  
  148. Read    endp
  149.  
  150.  
  151. NdRead    proc    near        ; function 5 = nondestructive read
  152.  
  153.         mov     ax,0100h        ; return 'done' status
  154.         ret
  155.  
  156. NdRead  endp
  157.  
  158.  
  159. InpStat proc    near            ; function 6 = input status
  160.  
  161.         mov     ax,0100h        ; return 'done' status
  162.         ret
  163.  
  164. InpStat endp
  165.  
  166.  
  167. InpFlush proc   near            ; function 7 = flush input buffers
  168.  
  169.         mov     ax,0100h        ; return 'done' status
  170.         ret
  171.  
  172. InpFlush endp
  173.  
  174.  
  175. Write   proc    near            ; function 8 = write
  176.  
  177.         mov     ax,0100h        ; return 'done' status
  178.         ret
  179.  
  180. Write   endp
  181.  
  182.  
  183. WriteVfy proc   near            ; function 9 = write with verify
  184.  
  185.         mov     ax,0100h        ; return 'done' status
  186.         ret
  187.         
  188. WriteVfy endp
  189.  
  190.  
  191. OutStat proc    near            ; function 10 = output status
  192.  
  193.         mov     ax,0100h        ; return 'done' status
  194.         ret
  195.  
  196. OutStat endp
  197.  
  198.  
  199. OutFlush proc   near            ; function 11 = flush output buffers
  200.  
  201.         mov     ax,0100h        ; return 'done' status
  202.         ret
  203.  
  204. OutFlush endp
  205.  
  206.  
  207. DevOpen proc    near            ; function 13 = device open
  208.  
  209.         mov     ax,0100h        ; return 'done' status
  210.         ret
  211.  
  212. DevOpen endp
  213.         
  214.  
  215. DevClose proc   near            ; function 14 = device close
  216.  
  217.         mov     ax,0100h        ; return 'done' status
  218.         ret
  219.  
  220. DevClose endp
  221.  
  222.  
  223. RemMedia proc   near            ; function 15 = removable media
  224.  
  225.         mov     ax,0100h        ; return 'done' status
  226.         ret
  227.  
  228. RemMedia endp
  229.  
  230.  
  231. GenIOCTL proc   near            ; function 16 = generic IOCTL
  232.  
  233.         mov     ax,0100h        ; return 'done' status
  234.         ret
  235.  
  236. GenIOCTL endp
  237.  
  238.  
  239. ResetMed proc   near            ; function 17 = reset media
  240.  
  241.         mov     ax,0100h        ; return 'done' status
  242.         ret
  243.  
  244. ResetMed endp
  245.  
  246.  
  247. GetLogDrv proc  near            ; function 18 = get logical drive
  248.  
  249.         mov     ax,0100h        ; return 'done' status
  250.         ret
  251.  
  252. GetLogDrv endp
  253.  
  254.  
  255. SetLogDrv proc  near            ; function 19 = set logical drive
  256.  
  257.         mov     ax,0100h        ; return 'done' status
  258.         ret
  259.  
  260. SetLogDrv endp
  261.  
  262.  
  263. DeInstall proc    near        ; function 20 = deinstall driver
  264.  
  265.         mov     ax,0100h        ; return 'done' status
  266.         ret
  267.  
  268. DeInstall endp
  269.  
  270.  
  271. PartFD  proc    near            ; function 22 = partitionable 
  272.                                 ;               fixed disk 
  273.         mov     ax,0100h        ; return 'done' status
  274.         ret
  275.  
  276. PartFD  endp
  277.  
  278.  
  279. FDMap   proc    near            ; function 23 = get fixed disk
  280.                                 ;               logical unit map
  281.         mov     ax,0100h        ; return 'done' status
  282.         ret
  283.  
  284. FDMap   endp
  285.  
  286.  
  287. Error   proc    near            ; bad command code
  288.  
  289.         mov     ax,8103h        ; error bit + 'done' status
  290.                                 ; + "Unknown Command" code
  291.         ret
  292.  
  293. Error   endp
  294.  
  295.  
  296. Init    proc    near            ; function 0 = initialize
  297.  
  298.         mov     ax,es:[bx+14]   ; get DevHlp entry point
  299.         mov     word ptr devhlp,ax
  300.         mov     ax,es:[bx+16]
  301.         mov     word ptr devhlp+2,ax
  302.  
  303.                                 ; set offsets to end of code
  304.                                 ; and data segments
  305.         mov     word ptr es:[bx+14],offset _TEXT:Init
  306.         mov     word ptr es:[bx+16],offset DGROUP:ident
  307.  
  308.                                 ; display sign-on message...
  309.         push    stdout          ; standard output handle
  310.         push    ds              ; address of message
  311.         push    offset DGROUP:ident
  312.         push    ident_len       ; length of message
  313.         push    ds              ; receives bytes written
  314.         push    offset DGROUP:wlen
  315.         call    DosWrite        ; transfer to OS/2
  316.                                       
  317.         mov     ax,0100h        ; return 'done' status
  318.         ret
  319.  
  320. Init    endp
  321.  
  322. _TEXT   ends
  323.  
  324.         end
  325.