home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 307_01 / comxfe.asm < prev    next >
Assembly Source File  |  1990-03-20  |  6KB  |  204 lines

  1.     page    66,132
  2. comment !
  3. /*
  4. HEADER:     ;
  5. TITLE:        PC com port driver front end;
  6. VERSION:    1.0;
  7.  
  8. DESCRIPTION:    "Assembler front end (start up module) for COMX.C.
  9.         Contains MS-DOS device driver interface and ISR
  10.         prototype.  Defines DGROUP to coerce the linkage
  11.         editor to produce a tiny memory model executable
  12.         file.";
  13.  
  14. WARNINGS:    "Microsoft specific.  Start up code does NOT zero
  15.         uninitialized static data.";
  16. SYSTEM:     MS-DOS v2 or later;
  17. FILENAME:    COMXFE.ASM;
  18.  
  19. SEE-ALSO:    COMX, COMX.C, COMXBE.C;
  20. AUTHORS:    Hugh Daschbach;
  21. COMPILERS:    Microsoft v5.1;
  22. */
  23. !
  24. ;-----------------------------------------------------------------------------;
  25. ;  dfe.asm:  The routines in this file provide an assembler front end
  26. ;  to a MS-DOS driver written in C.
  27. ;-----------------------------------------------------------------------------;
  28.     .model     small,c
  29. dgroup    group    _TEXT,_DATA
  30.     assume    cs:dgroup,ds:nothing,es:nothing,ss:nothing
  31.  
  32. ;-----------------------------------------------------------------------------;
  33. ;    Define Device Header
  34. ;-----------------------------------------------------------------------------;
  35.     .code
  36. com1:    dw    offset dgroup : com2    ; offset of next header
  37.     dw    -1            ; segment of next header
  38.     dw    0c000h            ; attribute: character, supports ioctl,
  39.                     ; and generic ioctl
  40.     dw    offset dgroup : dev_strategy
  41.     dw    offset dgroup : dev_inter1
  42.     db    'COM1     '
  43.  
  44. com2:    dw    offset dgroup : com3    ; offset of next header
  45.     dw    -1            ; segment of next header
  46.     dw    0c000h            ; attribute: character, supports ioctl,
  47.                     ; and generic ioctl
  48.     dw    offset dgroup : dev_strategy
  49.     dw    offset dgroup : dev_inter2
  50.     db    'COM2     '
  51.  
  52. com3:    dw    offset dgroup : com4    ; offset of next header
  53.     dw    -1            ; segment of next header
  54.     dw    0c000h            ; attribute: character, supports ioctl,
  55.                     ; and generic ioctl
  56.     dw    offset dgroup : dev_strategy
  57.     dw    offset dgroup : dev_inter3
  58.     db    'COM3     '
  59.  
  60. com4:    dw    -1            ; offset of next header
  61.     dw    -1            ; segment of next header
  62.     dw    0c000h            ; attribute: character, supports ioctl,
  63.                     ; and generic ioctl
  64.     dw    offset dgroup : dev_strategy
  65.     dw    offset dgroup : dev_inter4
  66.     db    'COM4     '
  67.  
  68.  
  69.     .data
  70. save_sp dw    ?            ; register save space for stack seg
  71. save_ss dw    ?            ; and pointer
  72.                     ;-------------------------------------;
  73.                     ; The stack and request block pointer
  74.                     ; are defined adjacently to deliver
  75.                     ; the request block and line number as
  76.                     ; parameters to the driver() when it
  77.                     ; is called from the interrpt entry
  78.                     ; point.
  79.                     ;-------------------------------------;
  80.     db    16 dup ('stack     ')    ; local stack space
  81. rb_off    dw    ?            ; request block offset
  82. rb_seg    dw    ?            ; request block segment
  83. line_no dw    ?            ; com line number (0 - 3)
  84.  
  85.     .code
  86.                     ;-------------------------------------;
  87.                     ; declare external reference to the
  88.                     ; driver, resolve reference to C
  89.                     ; startup module (_acrtused) with
  90.                     ; dummy label
  91.                     ;-------------------------------------;
  92.     extrn    driver : near
  93.     public    _acrtused
  94. _acrtused =    0
  95.  
  96. ;-----------------------------------------------------------------------------;
  97. ;    Device Strategy Entry Point
  98. ;-----------------------------------------------------------------------------;
  99. dev_strategy proc far
  100.     mov    cs:rb_seg,es        ; save pointer to request block
  101.     mov    cs:rb_off,bx
  102.     ret
  103. dev_strategy endp
  104.  
  105. ;-----------------------------------------------------------------------------;
  106. ;    Device Interrut Entry Points
  107. ;-----------------------------------------------------------------------------;
  108. dev_inter1:
  109.     mov    cs:line_no,0
  110.     jmp    dev_interrupt
  111. dev_inter2:
  112.     mov    cs:line_no,1
  113.     jmp    dev_interrupt
  114. dev_inter3:
  115.     mov    cs:line_no,2
  116.     jmp    dev_interrupt
  117. dev_inter4:
  118.     mov    cs:line_no,3
  119.     jmp    dev_interrupt
  120.  
  121. ;-----------------------------------------------------------------------------;
  122. ;    Device Interrupt Entry Point
  123. ;
  124. ;  Note: if this is to execute on first run 8088/8086 processors, interrupts
  125. ;  must be disabled while the stack registers are being manipulated.  Newer
  126. ;  processors gaurentee that interrupts are disabled for one instruction cycle
  127. ;  after the move to SS.
  128. ;-----------------------------------------------------------------------------;
  129. dev_interrupt proc far
  130.  
  131.     push    es            ; save registers that C does not
  132.     push    ds
  133.     push    bp
  134.     push    di
  135.     push    si
  136.     push    dx
  137.     push    cx
  138.     push    bx
  139.     push    ax
  140.     mov    ax,cs            ; establish data addressability
  141.     mov    ds,ax
  142.     assume    ds:dgroup
  143.     mov    save_ss,ss        ; connect to local stack.
  144.     mov    save_sp,sp
  145.     mov    ss,ax
  146.     mov    sp,offset dgroup : rb_off
  147.     call    driver            ; call the driver
  148.     mov    ss,save_ss        ; restore stack
  149.     mov    sp,save_sp
  150.     pop    ax            ; restore registers
  151.     pop    bx
  152.     pop    cx
  153.     pop    dx
  154.     pop    si
  155.     pop    di
  156.     pop    bp
  157.     pop    ds
  158.     pop    es
  159.     ret                ; and return
  160.     assume    ds:nothing
  161. dev_interrupt endp
  162.  
  163. ;-----------------------------------------------------------------------------;
  164. ;  ISR prototype - This routine is copied to an isr structure by hookvect().
  165. ;  The target of the call and jump are adjusted before hooking the structure
  166. ;  to a hardware interrupt vector.  This routine assumes that the called
  167. ;  C routine saves and restores BP, SI, and DI.
  168. ;-----------------------------------------------------------------------------;
  169. isr_prototype proc far
  170.     push    es            ; save registers that C does not
  171.     push    ds
  172.     push    dx
  173.     push    cx
  174.     push    bx
  175.     push    ax
  176.     mov    ax,cs            ; get data addressability
  177.     mov    ds,ax
  178.     call    driver            ; call the interrupt service routine
  179.     or    ax,ax            ; test return value
  180.     pop    ax            ; restore registers
  181.     pop    bx
  182.     pop    cx
  183.     pop    dx
  184.     pop    ds
  185.     pop    es
  186.     jz    ip01            ; if return value no zero
  187.     jmp    dword ptr cs:dummy    ;     chain to old vector
  188. ip01:                    ; else
  189.     iret                ;     return directly from interrupt
  190.                     ; endif
  191. dummy    dd    ?
  192. isr_prototype endp
  193. ;-----------------------------------------------------------------------------;
  194. ; int10(ax, bx) - video I/O service
  195. ;-----------------------------------------------------------------------------;
  196. int10    proc    near a:word, b:word
  197.     mov    ax,a
  198.     mov    bx,b
  199.     int    10h
  200.     ret
  201. int10    endp
  202.  
  203.     end
  204.