home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / GD386_O / MACROS < prev    next >
Encoding:
Text File  |  1990-07-10  |  4.2 KB  |  214 lines

  1. .386p
  2. Word_size = 4        ; for the 386; min argument passed.
  3. asm_386   = 1           ; this is for the 386.
  4. ebadf     = 4
  5. edeadlock = 5
  6.  
  7. ; Set pointer size.
  8. ifdef    Large_data
  9. Ptr_size    =    8       ; pass 8 bytes at a time for a 6-byte ptr.
  10. Ptr_reg     equ    es    ; Use es.
  11. Stack_reg    equ    ss    ; Use ss.
  12. else
  13. Ptr_size    =    4
  14. Ptr_reg     equ    ds    ; Can use ds, since = es.
  15. Stack_reg    equ    ds    ; Can use ds, since = ss.
  16. endif
  17.  
  18. ifdef    Small_code
  19. Pbase    =    8    ; Location of first parameter.
  20. Routine_size=    8    ; link + offset.
  21. return    macro    Pop_bytes
  22.   ifb    <Pop_bytes>
  23.     db    0c3h
  24.   else
  25.     db    0c2h
  26.     dw    Pop_bytes
  27.   endif
  28.     endm
  29.     extrnf  macro   name
  30.     extrn   name:near
  31.     endm
  32. ;near_far        equ     near
  33. else
  34. Pbase    =    12      ; Location of first parameter.
  35. Routine_size=    12      ; Link + offset + segment.
  36. return    macro    Pop_bytes
  37.   ifb    <Pop_bytes>
  38.     db    0cbh
  39.   else
  40.     db    0cah
  41.     dw    Pop_bytes
  42.   endif
  43.     endm
  44.     extrnf  macro   name
  45.     extrn   name:far
  46.     endm
  47. ;near_far        equ     far
  48. endif
  49.  
  50. prolog    macro
  51.     push    ebp
  52.     mov    ebp,esp
  53.     push    esi
  54.     push    edi
  55.     push    ebx
  56. ifdef    Large_data    ; Save DS whether or not 1 DS, in case we modify it.
  57.     push    ds
  58. endif
  59.     endm
  60. epilog    macro    Pop_bytes
  61. ifdef    Large_data
  62.     pop    ds
  63. endif
  64.     pop     ebx
  65.     pop    edi
  66.     pop    esi
  67.     pop    ebp
  68.     return    Pop_bytes
  69.     endm
  70.  
  71. ; We would have preferred a procbeg and procend macro, but
  72. ; the "proc" directive can't go inside a macro -- yet another
  73. ; of the many bugs in the flaky Microsoft assembler.
  74. publab    macro    procname
  75.     public    _mw&procname
  76. _mw&procname:
  77.     endm
  78. cseg    macro    segname,status
  79.     name    &segname
  80. ifb    <status>
  81. _mw&segname    segment dword 'CODE'
  82. else
  83. _mw&segname    segment dword 'CODE' public
  84. endif
  85.     assume    cs:_mw&segname
  86. ifdef    Small_code
  87. CGROUP    group    _mw&segname
  88.     assume    cs:CGROUP
  89. endif
  90.     endm
  91. endcseg macro    segname
  92. _mw&segname    ends
  93.     endm
  94. pubnames macro    names
  95.     irp    name,<names>
  96. ifdef   USING_MASM
  97.     public    _mw&&name
  98. else    
  99.     public    _mw&name
  100. endif   
  101.     endm
  102.     endm
  103. pubname macro    name
  104.     public    _mw&name
  105.     endm
  106. def    macro    x,y,z
  107. _mw&x    y    z
  108.     endm
  109. defequ    macro    x,y,z
  110. _mw&x    y    z
  111. x    equ    _mw&x
  112.     endm
  113. extequ    macro    x,type
  114.     extrn    _mw&x:type
  115. x    equ    _mw&x
  116.     endm
  117. ext    macro    x,type
  118.     extrn    _mw&x:type
  119.     endm
  120. ; Macros for parameter set-up that take care of small vs. large code
  121. ; and to some extent small vs. large data.
  122. ; Calling sequence:
  123. ;    parms    <<N1,T1>,<N2,T2>,...>
  124. ; where Ni are the names and Ti the types.
  125. ; This expands into
  126. ;    Ni equ T1 ptr offset[bp]
  127. ; where offset starts at the appropriate value for a procedure
  128. ; (assuming BP has been pushed, and taking into account small vs lg code)
  129. ; and is incremented as follows:
  130. ;    if Ti = "ptr" then increment by Ptr_size
  131. ;    otherwise increment by 2.
  132. ; For example:
  133. ;    parms    <<Src,word>,<Dest,ptr>,<Cnt,word>>
  134. ; generates
  135. ;    Src equ word ptr 6[bp]
  136. ;    Dest equ dword ptr 8[bp]
  137. ;    Cnt equ word ptr 12[bp]
  138. ; assuming parms start at 6.
  139. parm    macro    P,Type
  140.     local    Offset
  141. Offset    equ    Poff+0    ; +0 avoids alias; forces pass1 computation of expn.
  142. ifidn    <Type>,<ptr>    ; Type = "ptr"?
  143.   ifdef Small_data
  144. P    equ    dword ptr Offset[ebp]
  145.   else
  146. P    equ    pword ptr Offset[ebp]
  147.   endif
  148. Poff    =    Poff + Ptr_size
  149. else
  150. ifidn    <Type>,<routine>    ; Type = "routine"?
  151.   ifdef Small_code
  152. P    equ    word ptr Offset[ebp]
  153.   else
  154. P    equ    dword ptr Offset[ebp]
  155.   endif
  156. Poff    =    Poff + Routine_size - Word_size ; DOES NOT skip link.
  157. else
  158. P    equ    Type ptr Offset[ebp]
  159. Poff    =    Poff + Word_size
  160. endif
  161. endif
  162.     endm
  163. parms    macro    Parmlist
  164. Poff    =    Pbase    ; ret addr + pushed bp.
  165.     irp    P,<Parmlist>
  166.     parm    P
  167.     endm
  168.     endm
  169. parm386    macro    parmlist
  170.     parms    <parmlist>
  171.     endm
  172. parm86    macro    parmlist
  173.     endm
  174.  
  175. ; Load a pointer.
  176. ifdef    Small_data
  177. loadptr macro    Seginstr,Ireg,Operand
  178.     mov    Ireg,Operand
  179.     endm
  180. else
  181. loadptr macro    Seginstr,Ireg,Operand
  182.     seginstr Ireg,dword ptr Operand
  183.     endm
  184. endif
  185.  
  186. ; Load a formal routine parameter.
  187. ifdef    Small_code
  188. loadrout macro    Segreg,Ireg,Operand
  189.     mov    Ireg,Operand
  190.     push    cs
  191.     pop    Segreg
  192.     endm
  193. else
  194. loadrout macro    Segreg,Ireg,Operand
  195.     L&Segreg Ireg,dword ptr Operand
  196.     endm
  197. endif
  198.  
  199. ; Call a procedure.
  200. ifdef    Small_code
  201. pcall    macro    procname
  202. ifdef   USING_MASM
  203.         call    procname        ; MASM 5.1 BUG!!
  204.                     ; MASM doesn't put out proper LEdata for the call below.
  205. else
  206.      call    CGROUP:(near ptr procname)
  207. endif   
  208.     endm
  209. else
  210. pcall    macro    procname
  211.     call    far ptr procname
  212.     endm
  213. endif
  214.