standard.mac 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ;; --------------------------------------------------------------------------
  2. ;;
  3. ;; Copyright 1996-2016 The NASM Authors - All Rights Reserved
  4. ;; See the file AUTHORS included with the NASM distribution for
  5. ;; the specific copyright holders.
  6. ;;
  7. ;; Redistribution and use in source and binary forms, with or without
  8. ;; modification, are permitted provided that the following
  9. ;; conditions are met:
  10. ;;
  11. ;; * Redistributions of source code must retain the above copyright
  12. ;; notice, this list of conditions and the following disclaimer.
  13. ;; * Redistributions in binary form must reproduce the above
  14. ;; copyright notice, this list of conditions and the following
  15. ;; disclaimer in the documentation and/or other materials provided
  16. ;; with the distribution.
  17. ;;
  18. ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. ;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. ;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. ;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. ;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. ;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. ;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. ;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. ;; EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ;;
  32. ;; --------------------------------------------------------------------------
  33. ; Standard macro set for NASM -*- nasm -*-
  34. ; Macros to make NASM ignore some TASM directives
  35. STD: tasm
  36. %idefine IDEAL
  37. %idefine JUMPS
  38. %idefine P386
  39. %idefine P486
  40. %idefine P586
  41. %idefine END
  42. ; The normal standard macros
  43. STD: nasm
  44. ; Note that although some user-level forms of directives are defined
  45. ; here, not all of them are: the user-level form of a format-specific
  46. ; directive should be defined in the module for that directive.
  47. ; These three need to be defined, though the actual definitions will
  48. ; be constantly updated during preprocessing.
  49. %define __FILE__
  50. %define __LINE__
  51. %define __BITS__
  52. %define __SECT__ ; it ought to be defined, even if as nothing
  53. %imacro section 1+.nolist
  54. %define __SECT__ [section %1]
  55. __SECT__
  56. %endmacro
  57. %imacro segment 1+.nolist
  58. %define __SECT__ [segment %1]
  59. __SECT__
  60. %endmacro
  61. %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
  62. %imacro sectalign 1.nolist
  63. %ifnum %1
  64. %if __SECTALIGN_ALIGN_UPDATES_SECTION__ = 1
  65. [sectalign %1]
  66. %endif
  67. %else
  68. %ifidni %1,off
  69. %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 0
  70. %elifidni %1,on
  71. %define __SECTALIGN_ALIGN_UPDATES_SECTION__ 1
  72. %endif
  73. %endif
  74. %endmacro
  75. %imacro absolute 1+.nolist
  76. %define __SECT__ [absolute %1]
  77. __SECT__
  78. %endmacro
  79. %imacro struc 1-2.nolist 0
  80. %push
  81. %define %$strucname %1
  82. [absolute %2]
  83. %$strucname: ; allow definition of `.member' to work sanely
  84. %endmacro
  85. %imacro endstruc 0.nolist
  86. %{$strucname}_size equ ($-%$strucname)
  87. %pop
  88. __SECT__
  89. %endmacro
  90. %imacro istruc 1.nolist
  91. %push
  92. %define %$strucname %1
  93. %$strucstart:
  94. %endmacro
  95. %imacro at 1-2+.nolist
  96. times (%1-%$strucname)-($-%$strucstart) db 0
  97. %2
  98. %endmacro
  99. %imacro iend 0.nolist
  100. times %{$strucname}_size-($-%$strucstart) db 0
  101. %pop
  102. %endmacro
  103. %imacro align 1-2+.nolist nop
  104. sectalign %1
  105. times (((%1) - (($-$$) % (%1))) % (%1)) %2
  106. %endmacro
  107. %imacro alignb 1-2+.nolist
  108. sectalign %1
  109. %ifempty %2
  110. resb (((%1) - (($-$$) % (%1))) % (%1))
  111. %else
  112. times (((%1) - (($-$$) % (%1))) % (%1)) %2
  113. %endif
  114. %endmacro
  115. %imacro bits 1+.nolist
  116. [bits %1]
  117. %endmacro
  118. %imacro use16 0.nolist
  119. [bits 16]
  120. %endmacro
  121. %imacro use32 0.nolist
  122. [bits 32]
  123. %endmacro
  124. %imacro use64 0.nolist
  125. [bits 64]
  126. %endmacro
  127. %imacro extern 1-*.nolist
  128. %rep %0
  129. [extern %1]
  130. %rotate 1
  131. %endrep
  132. %endmacro
  133. %imacro static 1-*.nolist
  134. %rep %0
  135. [static %1]
  136. %rotate 1
  137. %endrep
  138. %endmacro
  139. %imacro global 1-*.nolist
  140. %rep %0
  141. [global %1]
  142. %rotate 1
  143. %endrep
  144. %endmacro
  145. %imacro common 1-*.nolist
  146. %rep %0
  147. [common %1]
  148. %rotate 1
  149. %endrep
  150. %endmacro
  151. %imacro cpu 1+.nolist
  152. [cpu %1]
  153. %endmacro
  154. %define __FLOAT_DAZ__ nodaz
  155. %define __FLOAT_ROUND__ near
  156. ; __FLOAT__ contains the whole floating-point configuration so it can
  157. ; be saved and restored
  158. %define __FLOAT__ __FLOAT_DAZ__,__FLOAT_ROUND__
  159. %imacro float 1-*.nolist
  160. %rep %0
  161. [float %1]
  162. %ifidni %1,daz
  163. %define __FLOAT_DAZ__ daz
  164. %elifidni %1,nodaz
  165. %define __FLOAT_DAZ__ nodaz
  166. %elifidni %1,near
  167. %define __FLOAT_ROUND__ near
  168. %elifidni %1,up
  169. %define __FLOAT_ROUND__ up
  170. %elifidni %1,down
  171. %define __FLOAT_ROUND__ down
  172. %elifidni %1,zero
  173. %define __FLOAT_ROUND__ zero
  174. %elifidni %1,default
  175. %define __FLOAT_DAZ__ nodaz
  176. %define __FLOAT_ROUND__ near
  177. %endif
  178. %rotate 1
  179. %endrep
  180. %endmacro
  181. %imacro default 1+.nolist
  182. [default %1]
  183. %endmacro
  184. %imacro userel 0.nolist
  185. [default rel]
  186. %endmacro
  187. %imacro useabs 0.nolist
  188. [default abs]
  189. %endmacro
  190. %imacro usebnd 0.nolist
  191. [default bnd]
  192. %endmacro
  193. %imacro usenobnd 0.nolist
  194. [default nobnd]
  195. %endmacro
  196. %imacro incbin 1-2+.nolist 0
  197. %push
  198. %pathsearch %$dep %1
  199. %depend %$dep
  200. %? %$dep,%2
  201. %pop
  202. %endmacro