home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / LordLucifer / win32asm / files / win32asm.exe / Win32ASM / ASMInc / Instr32.mac < prev    next >
Encoding:
Text File  |  1997-09-02  |  9.7 KB  |  306 lines

  1. ; Macros definition file (instruction / directives extensions).
  2.  
  3. ; $Id: Instr32.mac 1.2 1997/09/02 11:39:24 Philippe Exp $
  4.  
  5. ; $Log: /Win32Equ/Instr32.mac $
  6. ; 1     18/09/97 14:24 Philippe
  7. ; Initial checkin into SourceSafe.
  8. ; Revision 1.2  1997/09/02 11:39:24  Philippe
  9. ; Added HighItem optional parm to ENUMEND macro.
  10. ;
  11. ; Revision 1.1  1997/09/02 09:50:38  Philippe
  12. ; Initial revision
  13. ;
  14.  
  15.  
  16.  
  17. ; MASM 6.x Structured coding directives extensions.
  18.  
  19.     OPTION DOTNAME                      ;Allow names such as .BLOCK
  20.     OPTION PROC:PRIVATE                 ;PROCs are private by default.
  21.  
  22. ; The .BLOCK/.ENDBLOCK directives provide a non-looping, non generating
  23. ; frame that can be used for generating a block with multiway exits to
  24. ; a single point (thru .BREAK .IF <condition> directives).
  25.  
  26. .BLOCK          MACRO                   ;; Begin code block.
  27.                 .REPEAT
  28.                 ENDM
  29.  
  30. .ENDBLOCK       MACRO                   ;; End code block.
  31.                 .UNTIL 1                ;; (Generates no code.)
  32.                 ENDM
  33.  
  34.  
  35. ; More readable/explicit than .UNTIL 0 or .UNTIL FALSE.
  36.  
  37. .FOREVER        MACRO                   ;; Loop forever (.REPEAT / .FOREVER)
  38.                 .UNTIL 0                ;;
  39.                 ENDM
  40.  
  41. ; The Microserfs who did MASM didn't take the obvious decision of simply
  42. ; deriving the Intel J<cond> mnemonics for simple condition testing in their
  43. ; structured programming directive (like allowing .IF AE?, .WHILE GE?,
  44. ; .UNTIL BE?, .BREAK .IF A?, whatever...).
  45. ; So it looks like there is no simple way to use the directives to generate
  46. ; some of the jumps from preexisting conditions.
  47. ; But for those that are supported (and their NOT form), here are a few
  48. ; additional mnemonics:
  49.  
  50. EQUAL?          TEXTEQU <ZERO?>
  51. BELOW?          TEXTEQU <CARRY?>
  52. ABOVEorEQUAL?   TEXTEQU <!!CARRY?>
  53.  
  54.  
  55.  
  56. ; This macro because of a silly bug in MASM:
  57. ; MASM does generate a LINK directive in a module object code that has an
  58. ; END Label
  59. ; directive. The problem is, it does it wrong <sigh>.
  60. ; If an STDCALL directive is in effect, and the entry procedure is Start,
  61. ; the "END Start" directive will generate an inline
  62. ; /Entry:_Start"
  63. ; directive.
  64. ; Now, note that LINK will in turn decorate the name and internally change
  65. ; it to "__Start", that it expects to be a PUBLIC in the object file.
  66. ; The net result is that an END Start will generate a reference to __Start.
  67. ;
  68. ; Strike 2: There can't be neither _Start nor __Start defined in the MASM
  69. ; module, because the use of STDCALL will change any "Start" PROC
  70. ; in the source into a PUBLIC reference of _Start@0.
  71. ; So we endup with MASM declaring _Start@0 and referencing __Start.
  72. ; The error here is in the embedded link directive the END statement generates.
  73. ; If MASM were consistent with itself, it would apply the default interface
  74. ; convention for the module to the END directive, thus generating an inline
  75. ; /Entry:_Start@0
  76. ; link directive for everything to be fine. But even though MASM is not
  77. ; consistent with itself, we can fix the problem, by replacing the END
  78. ; directive with the following Entry macro:
  79. ;   ENTRY Start
  80. ; This macro will only work with the STDCALL parms convention (the one Win32
  81. ; uses). It would be easy to test for the parm passing model and generate
  82. ; the proper code for other conventions.
  83.  
  84. ENTRY MACRO EntryPoint:REQ
  85.       LOCAL EntryPoint
  86.         IF @Version GE 611
  87.         ALIAS <_&EntryPoint&@0>=<&EntryPoint>
  88.         ENDIF
  89.       END &EntryPoint
  90.       ENDM
  91.  
  92.  
  93. ; SAVE & RESTORE. - Ph.A., 16.05.86.
  94. ; SAVE   : Save registers to the stack.
  95. ; RESTORE: Restore registers from the stack.
  96. ; RESTORE generates POPs from the parm list in backward order, so the same
  97. ; list that was used for a SAVE can be used to restore the registers to
  98. ; their SAVED values.
  99. ; Changed to generate PUSHFD / POPFD for 32 bits.
  100.  
  101. SAVE MACRO R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,TESTARG
  102.     .ERRNB <TESTARG>    ;Too many things to push.
  103.       IFNB <R1>
  104.         IFIDNI <R1>,<F>
  105.           PUSHFD
  106.         ELSE
  107.           PUSH R1
  108.         ENDIF
  109.           SAVE R2,R3,R4,R5,R6,R7,R8,R9,R10,R11
  110.       ENDIF
  111.     ENDM
  112.     .XCREF SAVE
  113.  
  114. RESTORE MACRO R11,R10,R9,R8,R7,R6,R5,R4,R3,R2,R1,TESTARG
  115.     .ERRNB <TESTARG>                    ;Too many things to pop.
  116.       IFNB <R11>
  117.           RESTORE R10,R9,R8,R7,R6,R5,R4,R3,R2,R1
  118.         IFIDNI <R11>,<F>
  119.           POPFD
  120.         ELSE
  121.           POP R11
  122.         ENDIF
  123.       ENDIF
  124.     .CREF
  125.     ENDM
  126.     .XCREF RESTORE
  127.  
  128.  
  129. ; Dummy macro used to suppress MASM warning about unused parms (declared
  130. ; in function headers but actually not used in a proc).
  131.  
  132. UnusedParm      Macro ParmName:REQ
  133.                 Local Dummy
  134. Dummy           EQU ParmName            ;Fool MASM by using parm.
  135.                 ENDM
  136.  
  137.  
  138. ; MUSTBE & SHOULDBE macros - Ph.A., 26.05.86.
  139.  
  140. ; MUSTBE & SHOULDBE are called with a valid condition mnemonic value, such
  141. ; as A, NZ, NGE. If the required condition is not met, MUSTBE calls the
  142. ; FATALERR routine, which is a no-return, ABEND type of routine, and SHOULDBE
  143. ; calls the WARNING routine, which would probably be implemented as a snapshot
  144. ; dump or trace routine, and would return control.
  145.  
  146. MUSTBE MACRO C1
  147.     Local Around
  148.     FatalError PROTO STDCALL MsgAddr:DWORD
  149.     IFNB <C1>
  150.      J&C1 SHORT Around                  ;Jump around lethal call.
  151.     ENDIF
  152.     INVOKE FatalError,0                 ;Die horribly.
  153.     IFNB <C1>
  154. Around:
  155.     ENDIF
  156.     ENDM
  157.     .XCREF MUSTBE
  158.  
  159.  
  160. MUSTBEM MACRO C1,MSG
  161.     Local szMsg,Around
  162.     FatalError PROTO STDCALL MsgAddr:DWORD
  163.     .XCREF
  164.     IFNB <C1>                           ;If cond defined and met,
  165.     J&C1 Around                         ;Jump around jump the lethal call
  166.     ENDIF
  167.      IFB <MSG>
  168.      INVOKE FatalErr,0                  ;No error message this time
  169.      ELSE
  170.      .CONST
  171.      BYTE SIZEOF szMsg
  172. szMsg BYTE MSG,0                        ;Give error msg.
  173.      .CODE
  174.      INVOKE FatalError,ADDR szMsg
  175.      ENDIF
  176.     IFNB <C1>
  177. Around:
  178.     ENDIF
  179.     ENDM
  180.     .XCREF MUSTBEM
  181.  
  182. MUSTBEMGLE MACRO C1,MSG
  183.     Local szMsg,Around
  184.     FatalErrorGLE PROTO STDCALL MsgAddr:DWORD
  185.     .XCREF
  186.       IFNB <C1>                         ;If cond defined and met,
  187.       J&C1 Around                       ;Jump around jump the lethal call
  188.       ENDIF
  189.       IFB <MSG>
  190.       INVOKE FatalErrorGLE,0
  191.       ELSE
  192.       .CONST
  193.       BYTE SIZEOF szMsg
  194. szMsg BYTE MSG,0                        ;Give error msg
  195.       .CODE
  196.       INVOKE FatalErrorGLE,ADDR szMsg
  197.       ENDIF
  198.     IFNB <C1>
  199. Around:
  200.     ENDIF
  201.     ENDM
  202.     .XCREF MUSTBEMGLE
  203.  
  204.  
  205. SHOULDBE MACRO C1
  206.     Local Around
  207.     Warning PROTO STDCALL
  208.     IFNB <C1>
  209.      J&C1 SHORT Around                  ;Jump around warning call.
  210.     ENDIF
  211.     INVOKE Warning                      ;Indicate some strange condition.
  212.     IFNB <C1>
  213. Around:
  214.     ENDIF
  215.     ENDM
  216.     .XCREF SHOULDBE
  217.  
  218.  
  219. ; Define enumerated, sequential equate values.
  220. ; Useful for defining indices or offset into tables.
  221. ; Example of use:
  222. ;
  223. ;    ENUM WORD
  224. ;      ENUMITEM FBTxStIdle              ;TXer does plenty of nothing.
  225. ;      ENUMITEM FBTxStHead2             ;About to send 'B', second header byte.
  226. ;      ENUMITEM FBTxStData              ;About to send a data byte.
  227. ;      ENUMITEM FBTxStCRC8              ;TxEr about to send CRC-8 (negociation).
  228. ;      ENUMITEM FBTxStCRC16L            ;TxEr about to send CRC-16, LSB
  229. ;      ENUMITEM FBTxStCRC16M            ;TxEr about to send CRC-16, MSB
  230. ;      ENUMITEM FBTxStDLEd              ;TXer about to send DLE'd data.
  231. ;      ENUMITEM FBTxStRing              ;Transmitting from ring buffer.
  232. ;      ENUMITEM FBTxStChain             ;Txer about to check for chained
  233. ;                                       ;transmission.
  234. ;    ENUMEND Foo                        ;Foo (optional arg) is a symbol that
  235. ;                                       ;will be equated to the value
  236. ;                                       ;of the highest item generated.
  237.  
  238.  
  239. ENUM            MACRO ItemType:REQ
  240.                 LOCAL ItemType
  241.                 IFDEF $$$ItemValue
  242.                 .ERRNZ $$$ItemValue - (-1) ; Wrong ENUM macros nesting
  243.                 ENDIF
  244. $$$ItemSize   = SIZEOF ItemType
  245. $$$ItemValue  = 0
  246.                 ENDM
  247.  
  248. ENUMITEM        MACRO ItemName:REQ
  249.                 LOCAL ItemName
  250.                 .ERRNZ ($$$ItemValue EQ -1)  ;Missing ENUM macro.
  251. ItemName        = $$$ItemValue
  252. $$$ItemValue    = $$$ItemValue + $$$ItemSize
  253.                 ENDM
  254.  
  255. ENUMEND         MACRO HighItem
  256.                 Local HighItem
  257.                 IFNB <HighItem>              ;If HighItem is defined,
  258. HighItem        = $$$ItemValue - $$$ItemSize ;Equate the symbol with highitem
  259.                 ENDIF                        ;value.
  260.                 .ERRNZ ($$$ItemValue EQ -1)  ;Wrong ENUM macros nesting.
  261. $$$ItemValue    = -1
  262.                 ENDM
  263.  
  264.  
  265. ; For compatibility with older stuff.
  266. ; For long strings, use the MEMMOVE routine that moves aligned DWORDs
  267.  
  268. BXFER MACRO
  269.       REP MOVSB
  270.       ENDM
  271.  
  272.  
  273. ; Breakpoint instructions. Ph.A.
  274. ; Breakpoint may be implemented thru INT 3 (one byte interrupt) or INT 2
  275. ; (NMI).
  276.  
  277. BREAK MACRO
  278.     INT 3                               ;Use Breakpoint interrupt.
  279.     ENDM
  280.     .XCREF BREAK
  281.  
  282. DEBUG MACRO
  283.     INT 1                               ;Use Debugger Call interrupt.
  284.     ENDM
  285.     .XCREF DEBUG
  286.  
  287. NMI MACRO
  288.     INT 2                               ;Use NMI interrupt.
  289.     ENDM
  290.     .XCREF NMI
  291.  
  292.  
  293. ; For use between back-to-back I/O to the same chip (for AT compatibility).
  294. ; Should add yet another JMP SHORT $+2 to make provision for fast processors
  295. ; and slow busses (it purges the instruction prefetch queue).
  296. ; How much of these will we need for 486 ?!
  297. ; Is this still enough with 586 branch prediction ? Ph.A.
  298.  
  299. IODELAY MACRO
  300.     JMP SHORT @F
  301. @@:
  302.     ENDM
  303.     .XCREF IODELAY
  304.  
  305.