home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_03 / 1003042a < prev    next >
Text File  |  1991-10-07  |  4KB  |  150 lines

  1. ; -----------------------------------------------------
  2. ;   LISTING 1, start.asm
  3. ;
  4. ;   Device driver start-up module for C.
  5. ;   This module must appear first in the link order.
  6. ;
  7. ;   Coded for TASM 2.0
  8. ;
  9. ;   Source code Copyright (c) 1991 T.W. Nelson.
  10. ;   May be used only with appropriate
  11. ;   acknowledgement of copyright.
  12. ; -----------------------------------------------------
  13. ;
  14. ; define segment order first ....
  15. ;
  16.  
  17. _TEXT   segment byte    public  'CODE'
  18. _TEXT   ends
  19. _DATA   segment word    public  'DATA'
  20. _DATA   ends
  21. _BSS    segment word    public  'BSS'
  22. _BSS    ends
  23. ENDSEG  segment word    public  'ENDSEG'
  24. ENDSEG  ends
  25.  
  26. ; Establish TINY model segment group ....
  27. ;
  28. DGROUP  group   _TEXT,_DATA,_BSS,ENDSEG
  29. ASSUME  cs:DGROUP,ds:DGROUP,es:NOTHING,ss:NOTHING
  30.  
  31. STACKSIZ    equ     256     ;stack size, words
  32.  
  33. _TEXT   segment
  34.  
  35. org 0           ;all driver headers start at 0
  36.  
  37. ; driver header data .......
  38. ;
  39.     db  4 dup(0ffh)     ;points to ground (NULL)
  40.     dw  8000h + 4000h   ;driver attributes: char device
  41.                         ;...and ioctl read/write
  42.     dw  _dev_strategy   ;offset to strategy routine
  43.     dw  _dev_interrupt  ;offset to interrupt routine
  44.     db  'TAPEXXXX'      ;device name = 8 bytes
  45.  
  46. rhdr_seg    dw  ?               ;request header segment
  47. rhdr_off    dw  ?               ;request header offset
  48. caller_ss   dw  ?               ;for stack setup
  49. caller_sp   dw  ?
  50.  
  51. ; Function appears in module 'exec.c' and must be
  52. ; defined as:
  53. ;
  54. ;   void exec_command( REQHDR far *rhdr )
  55. ;
  56. extrn _exec_command:near
  57.  
  58. ; First part of two-step driver call from DOS. This
  59. ; only saves a pointer to the request header used in
  60. ; the interrupt routine ......
  61. ;
  62. _dev_strategy   proc    far     ;always far DOS call
  63.         mov     cs:rhdr_seg,es
  64.         mov     cs:rhdr_off,bx
  65.         ret
  66. _dev_strategy   endp
  67.  
  68. ; Second (workhorse) part of 2-step driver call.
  69. ; Although called an 'interrupt' function, this is
  70. ; not a true interrupt handler .......
  71. ;
  72. _dev_interrupt  proc    far     ;always far DOS call
  73.  
  74. ;-----  Save caller's CPU state and stack context ....
  75.         push    ax
  76.         push    bx
  77.         push    cx
  78.         push    dx
  79.         push    di
  80.         push    si
  81.         push    bp
  82.         push    ds
  83.         push    es
  84.         pushf
  85.         mov     cs:caller_ss,ss
  86.         mov     cs:caller_sp,sp
  87.  
  88. ;-----  Setup segment addressability and driver
  89. ;       stack frame ............
  90.         mov     ax,cs               ;local data seg
  91.         cli
  92.         mov     ds,ax
  93.         mov     es,ax
  94.         mov     ss,ax
  95.         mov     sp,offset cs:stack_top
  96.         mov     bp,sp               ;set C stack frame
  97.         sti
  98.  
  99. ;-----  Pass pointer to req hdr and execute command....
  100.         mov     ax,cs:rhdr_seg
  101.         push    ax
  102.         mov     ax,cs:rhdr_off
  103.         push    ax
  104.         call    _exec_command
  105.         pop     ax
  106.         pop     ax
  107.  
  108. ;-----  restore CPU state ..........
  109.         cli
  110.         mov     ss,cs:caller_ss
  111.         mov     sp,cs:caller_sp
  112.         sti
  113.         popf
  114.         pop     es
  115.         pop     ds
  116.         pop     bp
  117.         pop     si
  118.         pop     di
  119.         pop     dx
  120.         pop     cx
  121.         pop     bx
  122.         pop     ax
  123.         ret
  124. _dev_interrupt  endp
  125.  
  126. _TEXT   ends
  127.  
  128. ;------------------------------------------------------
  129.  
  130. _DATA  segment
  131.  
  132.             dw  STACKSIZ dup(?)      ;driver's stack
  133. stack_top   dw  ?
  134.  
  135. _DATA  ends
  136.  
  137. ;------------------------------------------------------
  138.  
  139. ENDSEG    segment
  140.  
  141. __TheEnd  label byte    ;location of cs:__TheEnd
  142.                         ;marks break address for DOS
  143. public  __TheEnd
  144.  
  145. ENDSEG    ends
  146.  
  147.     END
  148.  
  149. ; ----- End of File -----------------------------------
  150.