Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
5.4 KiB

  1. ;-----------------------------------------------------------------------;
  2. ; CVT.INC
  3. ;
  4. ; This module contains macros that generate 16-bit code to convert
  5. ; structures in either direction between 16-bit and 32-bit definitions.
  6. ;
  7. ; USE THIS EVERYWHERE! USE THESE IN PACKING MACROS! THESE ARE AS
  8. ; SMALL AND FAST AS INLINE IS EVER GOING TO BE. DO NOT WRITE YOUR OWN.
  9. ;-----------------------------------------------------------------------;
  10. ;-----------------------------------------------------------------------;
  11. ; srcadj
  12. ; adj amount by which to adjust source pointer (DS:ESI)
  13. ;-----------------------------------------------------------------------;
  14. srcadj macro adj
  15. ifnb <adj>
  16. add esi,adj
  17. endif
  18. endm
  19. ;-----------------------------------------------------------------------;
  20. ; dstadj
  21. ; adj amount by which to adjust destination pointer (ES:EDI)
  22. ;-----------------------------------------------------------------------;
  23. dstadj macro adj
  24. ifnb <adj>
  25. add edi,adj
  26. endif
  27. endm
  28. ;-----------------------------------------------------------------------;
  29. ; copyw -- Copy a word
  30. ;-----------------------------------------------------------------------;
  31. copyw macro adj
  32. srcadj adj
  33. movsw es:[edi],ds:[esi]
  34. endm
  35. ;-----------------------------------------------------------------------;
  36. ; ncopyw -- Copy N words
  37. ;-----------------------------------------------------------------------;
  38. ncopyw macro count:req
  39. mov ecx, count
  40. rep movsw es:[edi], ds:[esi]
  41. endm
  42. ;-----------------------------------------------------------------------;
  43. ; copyd -- Copy a dword
  44. ;-----------------------------------------------------------------------;
  45. copyd macro adj
  46. srcadj adj
  47. movsd es:[edi],ds:[esi]
  48. endm
  49. ;-----------------------------------------------------------------------;
  50. ; ncopyd -- Copy N dwords
  51. ;-----------------------------------------------------------------------;
  52. ncopyd macro count:req
  53. mov ecx, count
  54. rep movsd es:[edi],ds:[esi]
  55. endm
  56. ;-----------------------------------------------------------------------;
  57. ; copysx -- Sign-extend an INT to a LONG
  58. ;-----------------------------------------------------------------------;
  59. copysx macro adj
  60. srcadj adj
  61. lodsw ds:[si]
  62. cwde
  63. stosd es:[edi]
  64. endm
  65. ;------------------------------------------------------------------------;
  66. ; ncopysx - Sign-extend N INTs to LONGs
  67. ;------------------------------------------------------------------------;
  68. ncopysx macro count:req, adj
  69. local m1
  70. mov cx, count
  71. m1:
  72. copysx adj
  73. loop m1
  74. endm
  75. ;-----------------------------------------------------------------------;
  76. ; copysx2 -- Copy and sign-extend a word to a dword, mapping 8000h
  77. ; to 80000000h.
  78. ;-----------------------------------------------------------------------;
  79. copysx2 macro adj
  80. local sign_extend_it
  81. local store_it
  82. srcadj adj
  83. lodsw ds:[si]
  84. cmp ax,8000h
  85. jne sign_extend_it
  86. ror eax,16
  87. sub ax,ax
  88. jmp short store_it
  89. sign_extend_it:
  90. cwde
  91. store_it:
  92. stosd es:[edi]
  93. endm
  94. ;-----------------------------------------------------------------------;
  95. ; ncopysx2
  96. ;-----------------------------------------------------------------------;
  97. ncopysx2 macro count:req, adj
  98. local m1
  99. mov cx, count
  100. m1:
  101. copysx2 adj
  102. loop m1
  103. endm
  104. ;-----------------------------------------------------------------------;
  105. ; copyzx -- Copy and zero-extend a word to a dword
  106. ;-----------------------------------------------------------------------;
  107. copyzx macro adj
  108. srcadj adj
  109. lodsw ds:[si]
  110. movzx eax,ax
  111. stosd es:[edi]
  112. endm
  113. ;-----------------------------------------------------------------------;
  114. ; ncopyzx -- Zero-extend N WORDs to DWORDs
  115. ;-----------------------------------------------------------------------;
  116. ncopyzx macro count:req
  117. local m1
  118. xor eax, eax
  119. mov cx, count
  120. m1:
  121. lodsw ds:[si]
  122. stosd es:[edi]
  123. loop m1
  124. endm
  125. ;-----------------------------------------------------------------------;
  126. ; copyt -- Copy and truncate a dword to a word
  127. ;-----------------------------------------------------------------------;
  128. copyt macro adj
  129. srcadj adj
  130. lodsd ds:[esi]
  131. stosw es:[di]
  132. endm
  133. ;-----------------------------------------------------------------------;
  134. ; ncopyt -- Truncate N DWORDs to WORDs
  135. ;-----------------------------------------------------------------------;
  136. ncopyt macro count:req
  137. local m1
  138. mov cx, count
  139. m1:
  140. lodsd ds:[esi]
  141. stosw es:[di]
  142. loop m1
  143. endm
  144. ;-----------------------------------------------------------------------;
  145. ; copyt2 -- Copy and truncate a dword to a word, mapping 80000000
  146. ; to 8000.
  147. ;-----------------------------------------------------------------------;
  148. copyt2 macro adj
  149. local store_it
  150. srcadj adj
  151. lodsd ds:[esi] ;get dword value
  152. cmp eax,80000000h ;is just the high bit set?
  153. jne store_it ;if not, just truncate
  154. ror eax,16 ;if yes, store 8000h
  155. store_it:
  156. stosw es:[di]
  157. endm
  158. ;-----------------------------------------------------------------------;
  159. ; ncopyt2 -- Truncate N special DWORDs to WORDs
  160. ;-----------------------------------------------------------------------;
  161. ncopyt2 macro count:req, adj
  162. local m1
  163. mov cx, count
  164. m1:
  165. copyt2 adj
  166. loop m1
  167. endm