home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / andistkt.zip / MACASM.ASM < prev    next >
Assembly Source File  |  1995-04-19  |  8KB  |  187 lines

  1. ;*****************************************************************************
  2. ;*                                                                           *
  3. ;*   Component   : Sample ANDIS MAC Driver                                   *
  4. ;*                                                                           *
  5. ;*   Module      : MACASM.ASM                                                *
  6. ;*                                                                           *
  7. ;*   Description : This module contains assembly language routines and       *
  8. ;*                 segment definitions needed by the MAC.                    *
  9. ;*                                                                           *
  10. ;*****************************************************************************
  11.  
  12. extrn           _Strategy: near
  13. extrn           _pDevHelp: dword
  14.  
  15. ;*****************************************************************************
  16. ;*                             Data Segments                                 *
  17. ;*****************************************************************************
  18.  
  19. HEADER          segment dword public 'DATA'     ;Device driver header
  20.  
  21. public          MACHeader
  22.  
  23. MACHeader       DD      0FFFFFFFFH
  24.                 DW      8080H           ; Char device, No Open/Close, Level 1
  25.                 DW      strategy_asm    ; ASM strategy entry point
  26.                 DW      0               ; No IDC entry point
  27.                 DB      'ANDISMC$'
  28.                 DW      00H
  29.                 DW      00H
  30.                 DW      00H
  31.                 DW      00H
  32.                 DD      00H
  33.  
  34. HEADER          ends
  35.  
  36. _DATA           segment dword public 'DATA'      ;Global initialized data
  37. _DATA           ends
  38.  
  39. CONST           segment dword public 'CONST'     ;Global constants
  40. CONST           ends
  41.  
  42. _BSS            segment dword public 'BSS'       ;Global uninitialized data
  43. _BSS            ends
  44.  
  45. END_DATA        segment dword public 'END_DATA'  ;Marks the end of the data
  46.  
  47. public          _EndofData
  48. _EndofData      dw      0FFFFH
  49.  
  50. END_DATA        ends
  51.  
  52.  
  53. ;*****************************************************************************
  54. ;*                             Code Segments                                 *
  55. ;*****************************************************************************
  56.  
  57. _TEXT           segment dword public 'CODE'     ;Not initialization code
  58.  
  59.  
  60. ;*****************************************************************************
  61. ;*                                                                           *
  62. ;*   Routine     : strategy_asm                                              *
  63. ;*                                                                           *
  64. ;*   Description : This routine is the strategy entry point for the device   *
  65. ;*                 driver.  This routine is simply the assembly language     *
  66. ;*                 interface to the C language stragegy routine.  The        *
  67. ;*                 address of the request block is pushed onto the stack     *
  68. ;*                 and the C language stragegy routine is called.            *
  69. ;*                                                                           *
  70. ;*****************************************************************************
  71.  
  72. public          strategy_asm
  73.  
  74. strategy_asm    proc    far
  75.  
  76.                 push    es              ; Push addr of Req Pkt on stack
  77.                 push    bx
  78.  
  79.                 call    _Strategy       ; Call C strategy routine
  80.  
  81.                 pop     bx
  82.                 pop     es
  83.                 ret
  84.  
  85. strategy_asm    endp
  86.  
  87.  
  88. ;*****************************************************************************
  89. ;*                                                                           *
  90. ;*   Routine     : _DevHelper                                                *
  91. ;*                                                                           *
  92. ;*   Description : This is an assembly language routine that can be called   *
  93. ;*                 from C to issue DevHelp calls to the operating system.    *
  94. ;*                 The calling C routine passes in a register structure      *
  95. ;*                 (defined below).  This routine copies the values from     *
  96. ;*                 the structure into the actual registers and calls         *
  97. ;*                 DevHelp.  The result of the DevHelp (specified with the   *
  98. ;*                 carry flag) is returned to the C routine in the AX        *
  99. ;*                 register (1=Error,0=Success).                             *
  100. ;*                                                                           *
  101. ;*****************************************************************************
  102.  
  103. Registers struc
  104.                 axo     dw      ?       ;ax register
  105.                 bxo     dw      ?       ;bx register
  106.                 cxo     dw      ?       ;cx register
  107.                 dxo     dw      ?       ;dx register
  108.                 sio     dw      ?       ;si register
  109.                 dio     dw      ?       ;di register
  110.                 cflag   dw      ?       ;flags register
  111.                 eso     dw      ?       ;es register-must be NULL or real value
  112. Registers ends
  113.  
  114. devhelpstack struc
  115.                 oldbp   dw      ?       ;saved bp
  116.                 retadr  dd      ?       ;long return address
  117.                 regadd  dd      ?       ;long pointer to reg structure
  118. devhelpstack ends
  119.  
  120. public          _DevHelper
  121.  
  122. _DevHelper      proc    far
  123.  
  124.                 push    bp
  125.                 mov     bp, sp          ;set frame
  126.                 push    di              ;save index regs
  127.                 push    si
  128.  
  129.                 ; get values from addresses
  130.                 les     di,  [bp + regadd] ;get address of start of structure
  131.                 mov     ax, es:[di].sio
  132.                 push    ax                 ;save es and si for last
  133.                 mov     ax, es:[di].eso
  134.                 push    ax                 ;save es and si for last
  135.                 mov     ax, es:[di].axo    ;ax-value
  136.                 mov     cx, es:[di].cxo    ;copy all values from structure to
  137.                 mov     dx, es:[di].dxo    ;the actual registers
  138.                 mov     bx, es:[di].bxo    ;before making the call
  139.                 mov     di, es:[di].dio
  140.                 pop     es
  141.                 pop     si                 ;restore registers for call
  142.  
  143.                 call    [_pDevHelp]        ;call the device-helper routine
  144.  
  145.                 ;return the values to the calling program
  146.                 push    ax              ;save ax
  147.                 lahf                    ;copy flags into ah register
  148.                 mov     cl, ah          ;copy to cl
  149.                 xor     ch, ch          ;zero upper byte
  150.                 pop     ax              ;restore ax
  151.                 push    es              ;save these
  152.                 push    di              ;for last loading
  153.                 les     di, [bp + regadd]  ;get address of start of structure
  154.                 mov     es:[di].cflag, cx  ;return carryflag value
  155.                 mov     es:[di].axo, ax  ;return value of ax
  156.                 mov     es:[di].bxo, bx  ;return bx-value
  157.                 mov     es:[di].dxo, dx  ;return dx-value
  158.                 pop     ax
  159.                 mov     es:[di].dio, ax  ;return di
  160.                 pop     ax               ;and es
  161.                 mov     es:[di].eso, ax
  162.                 mov     ax, cx           ;get carry flag into AX for return
  163.                 and     ax, 1            ;only carry bit is returned
  164.  
  165.                 pop     si               ;restore real si and di
  166.                 pop     di
  167.                 pop     bp               ;and base pointer
  168.                 ret
  169.  
  170. _DevHelper      endp
  171.  
  172. _TEXT           ends
  173.  
  174. INITCODE        segment dword public 'CODE'     ;Initialization code
  175. INITCODE        ends
  176.  
  177.  
  178. ;*****************************************************************************
  179. ;*                                Groups                                     *
  180. ;*****************************************************************************
  181.  
  182. DGROUP          group   HEADER, _DATA, CONST, _BSS, END_DATA
  183. CGROUP          group   _TEXT, INITCODE
  184.  
  185.         end
  186.  
  187.