Leaked source code of windows server 2003
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.

417 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. shared.c
  5. Abstract:
  6. Instruction fragments with common (shared) BYTE, WORD, and DWORD flavors.
  7. Author:
  8. 12-Jun-1995 BarryBo
  9. Revision History:
  10. --*/
  11. // THIS FILE IS #include'd INTO FILES WHICH DEFINE THE FOLLOWING MACROS:
  12. // MSB - most significant bit
  13. // UTYPE - UNSIGNED type which defines registers (BYTE/USHORT/DWORD)
  14. // STYPE - SIGNED type which defines registers (char/short/long)
  15. // GET_VAL - dereference a pointer of the right type (GET_BYTE/...)
  16. // PUT_VAL - writes a value into memory
  17. // FRAGCOMMON{0,1,2} - mangles the function name and declares parameters
  18. // AREG - al/ax/eax
  19. // BREG - ...
  20. // CREG - ...
  21. // DREG - ...
  22. FRAGCOMMON1IMM(OPT_FastTestFrag)
  23. {
  24. SET_ZFLAG(op1);
  25. SET_PFLAG(op1);
  26. SET_SFLAG(op1 << (31-LMB));
  27. SET_CFLAG_OFF;
  28. SET_OFLAG_OFF;
  29. }
  30. FRAGCOMMON2IMM(CmpFrag)
  31. {
  32. UTYPE result;
  33. result = op1 - op2;
  34. SET_FLAGS_SUB(result, op1, op2, MSB);
  35. }
  36. FRAGCOMMON2IMM(TestFrag)
  37. {
  38. UTYPE result;
  39. result = op1 & op2;
  40. SET_ZFLAG(result);
  41. SET_PFLAG(result);
  42. SET_SFLAG(result << (31-LMB));
  43. SET_CFLAG_OFF;
  44. SET_OFLAG_OFF;
  45. }
  46. FRAGCOMMON0(RepMovsFrag)
  47. {
  48. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  49. while (ecx) {
  50. PUT_VAL(edi, GET_VAL(esi));
  51. esi += LoopIncr;
  52. edi += LoopIncr;
  53. ecx--;
  54. }
  55. }
  56. FRAGCOMMON0(FsRepMovsFrag)
  57. {
  58. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  59. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  60. while (ecx) {
  61. PUT_VAL(edi, GET_VAL(esi + Base));
  62. esi += LoopIncr;
  63. edi += LoopIncr;
  64. ecx--;
  65. }
  66. }
  67. FRAGCOMMON0(MovsFrag)
  68. {
  69. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  70. PUT_VAL(edi, GET_VAL(esi));
  71. esi += LoopIncr;
  72. edi += LoopIncr;
  73. }
  74. FRAGCOMMON0(FsMovsFrag)
  75. {
  76. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  77. PUT_VAL(edi, GET_VAL(esi + (DWORD)(ULONGLONG)NtCurrentTeb()));
  78. esi += LoopIncr;
  79. edi += LoopIncr;
  80. }
  81. FRAGCOMMON0(RepnzCmpsFrag)
  82. {
  83. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  84. UTYPE result, op1, op2;
  85. while (ecx) {
  86. op1 = GET_VAL(esi);
  87. op2 = GET_VAL(edi);
  88. result = op1 - op2;
  89. SET_FLAGS_SUB(result, op1, op2, MSB);
  90. esi += LoopIncr;
  91. edi += LoopIncr;
  92. ecx--;
  93. if (cpu->flag_zf == 0) { // inverse logic
  94. break;
  95. }
  96. }
  97. }
  98. FRAGCOMMON0(FsRepnzCmpsFrag)
  99. {
  100. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  101. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  102. UTYPE result, op1, op2;
  103. while (ecx) {
  104. op1 = GET_VAL(esi + Base);
  105. op2 = GET_VAL(edi);
  106. result = op1 - op2;
  107. SET_FLAGS_SUB(result, op1, op2, MSB);
  108. esi += LoopIncr;
  109. edi += LoopIncr;
  110. ecx--;
  111. if (cpu->flag_zf == 0) { // inverse logic
  112. break;
  113. }
  114. }
  115. }
  116. FRAGCOMMON0(RepzCmpsFrag)
  117. {
  118. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  119. UTYPE result, op1, op2;
  120. while (ecx) {
  121. op1 = GET_VAL(esi);
  122. op2 = GET_VAL(edi);
  123. result = op1 - op2;
  124. SET_FLAGS_SUB(result, op1, op2, MSB);
  125. esi += LoopIncr;
  126. edi += LoopIncr;
  127. ecx--;
  128. if (cpu->flag_zf) { // inverse logic
  129. break;
  130. }
  131. }
  132. }
  133. FRAGCOMMON0(FsRepzCmpsFrag)
  134. {
  135. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  136. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  137. UTYPE result, op1, op2;
  138. while (ecx) {
  139. op1 = GET_VAL(esi + Base);
  140. op2 = GET_VAL(edi);
  141. result = op1 - op2;
  142. SET_FLAGS_SUB(result, op1, op2, MSB);
  143. esi += LoopIncr;
  144. edi += LoopIncr;
  145. ecx--;
  146. if (cpu->flag_zf) { // inverse logic
  147. break;
  148. }
  149. }
  150. }
  151. FRAGCOMMON0(CmpsFrag)
  152. {
  153. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  154. UTYPE result, op1, op2;
  155. op1 = GET_VAL(esi);
  156. op2 = GET_VAL(edi);
  157. result = op1 - op2;
  158. SET_FLAGS_SUB(result, op1, op2, MSB);
  159. esi += LoopIncr;
  160. edi += LoopIncr;
  161. }
  162. FRAGCOMMON0(FsCmpsFrag)
  163. {
  164. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  165. UTYPE result, op1, op2;
  166. op1 = GET_VAL(esi + (DWORD)(ULONGLONG)NtCurrentTeb());
  167. op2 = GET_VAL(edi);
  168. result = op1 - op2;
  169. SET_FLAGS_SUB(result, op1, op2, MSB);
  170. esi += LoopIncr;
  171. edi += LoopIncr;
  172. }
  173. FRAGCOMMON0(RepStosFrag)
  174. {
  175. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  176. UTYPE Value = AREG;
  177. while (ecx) {
  178. PUT_VAL(edi, Value);
  179. edi += LoopIncr;
  180. ecx--;
  181. }
  182. }
  183. FRAGCOMMON0(StosFrag)
  184. {
  185. PUT_VAL(edi, AREG);
  186. edi += sizeof(UTYPE)*cpu->flag_df;
  187. }
  188. FRAGCOMMON0(RepnzScasFrag)
  189. {
  190. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  191. UTYPE result, op2;
  192. UTYPE Value = AREG;
  193. while (ecx) {
  194. op2 = GET_VAL(edi);
  195. result = Value - op2;
  196. SET_FLAGS_SUB(result, Value, op2, MSB);
  197. edi += LoopIncr;
  198. ecx--;
  199. if (cpu->flag_zf == 0) { // inverse logic
  200. break;
  201. }
  202. }
  203. }
  204. FRAGCOMMON0(RepnzScasNoFlagsFrag)
  205. {
  206. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  207. UTYPE result, op2;
  208. UTYPE Value = AREG;
  209. while (ecx) {
  210. op2 = GET_VAL(edi);
  211. result = Value - op2;
  212. edi += LoopIncr;
  213. ecx--;
  214. if (result == 0) { // inverse logic
  215. break;
  216. }
  217. }
  218. }
  219. FRAGCOMMON0(FsRepnzScasFrag)
  220. {
  221. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  222. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  223. UTYPE result, op2;
  224. UTYPE Value = AREG;
  225. while (ecx) {
  226. op2 = GET_VAL(edi + Base);
  227. result = Value - op2;
  228. SET_FLAGS_SUB(result, Value, op2, MSB);
  229. edi += LoopIncr;
  230. ecx--;
  231. if (cpu->flag_zf == 0) { // inverse logic
  232. break;
  233. }
  234. }
  235. }
  236. FRAGCOMMON0(FsRepnzScasNoFlagsFrag)
  237. {
  238. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  239. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  240. UTYPE result, op2;
  241. UTYPE Value = AREG;
  242. while (ecx) {
  243. op2 = GET_VAL(edi + Base);
  244. result = Value - op2;
  245. edi += LoopIncr;
  246. ecx--;
  247. if (result == 0) { // inverse logic
  248. break;
  249. }
  250. }
  251. }
  252. FRAGCOMMON0(RepzScasFrag)
  253. {
  254. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  255. UTYPE result, op2;
  256. UTYPE Value = AREG;
  257. while (ecx) {
  258. op2 = GET_VAL(edi);
  259. result = Value - op2;
  260. SET_FLAGS_SUB(result, Value, op2, MSB);
  261. edi += LoopIncr;
  262. ecx--;
  263. if (cpu->flag_zf) { // inverse logic
  264. break;
  265. }
  266. }
  267. }
  268. FRAGCOMMON0(RepzScasNoFlagsFrag)
  269. {
  270. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  271. UTYPE result, op2;
  272. UTYPE Value = AREG;
  273. while (ecx) {
  274. op2 = GET_VAL(edi);
  275. result = Value - op2;
  276. edi += LoopIncr;
  277. ecx--;
  278. if (result) { // inverse logic
  279. break;
  280. }
  281. }
  282. }
  283. FRAGCOMMON0(FsRepzScasFrag)
  284. {
  285. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  286. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  287. UTYPE result, op2;
  288. UTYPE Value = AREG;
  289. while (ecx) {
  290. op2 = GET_VAL(edi + Base);
  291. result = Value - op2;
  292. SET_FLAGS_SUB(result, Value, op2, MSB);
  293. edi += LoopIncr;
  294. ecx--;
  295. if (cpu->flag_zf) { // inverse logic
  296. break;
  297. }
  298. }
  299. }
  300. FRAGCOMMON0(FsRepzScasNoFlagsFrag)
  301. {
  302. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  303. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  304. UTYPE result, op2;
  305. UTYPE Value = AREG;
  306. while (ecx) {
  307. op2 = GET_VAL(edi + Base);
  308. result = Value - op2;
  309. edi += LoopIncr;
  310. ecx--;
  311. if (result) { // inverse logic
  312. break;
  313. }
  314. }
  315. }
  316. FRAGCOMMON0(ScasFrag)
  317. {
  318. UTYPE result, op2;
  319. op2 = GET_VAL(edi);
  320. result = AREG - op2;
  321. SET_FLAGS_SUB(result, AREG, op2, MSB);
  322. edi += sizeof(UTYPE)*cpu->flag_df;
  323. }
  324. FRAGCOMMON0(ScasNoFlagsFrag)
  325. {
  326. UTYPE result, op2;
  327. op2 = GET_VAL(edi);
  328. result = AREG - op2;
  329. edi += sizeof(UTYPE)*cpu->flag_df;
  330. }
  331. FRAGCOMMON0(FsScasFrag)
  332. {
  333. UTYPE result, op2;
  334. op2 = GET_VAL(edi + (DWORD)(ULONGLONG)NtCurrentTeb());
  335. result = AREG - op2;
  336. SET_FLAGS_SUB(result, AREG, op2, MSB);
  337. edi += sizeof(UTYPE)*cpu->flag_df;
  338. }
  339. FRAGCOMMON0(FsScasNoFlagsFrag)
  340. {
  341. UTYPE result, op2;
  342. op2 = GET_VAL(edi + (DWORD)(ULONGLONG)NtCurrentTeb());
  343. result = AREG - op2;
  344. edi += sizeof(UTYPE)*cpu->flag_df;
  345. }
  346. FRAGCOMMON0(LodsFrag)
  347. {
  348. AREG = GET_VAL(esi);
  349. esi += sizeof(UTYPE)*cpu->flag_df;
  350. }
  351. FRAGCOMMON0(FsLodsFrag)
  352. {
  353. AREG = GET_VAL(esi + (DWORD)(ULONGLONG)NtCurrentTeb());
  354. esi += sizeof(UTYPE)*cpu->flag_df;
  355. }
  356. FRAGCOMMON0(RepLodsFrag)
  357. {
  358. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  359. while (ecx) {
  360. AREG = GET_VAL(esi);
  361. esi += LoopIncr;
  362. ecx--;
  363. }
  364. }
  365. FRAGCOMMON0(FsRepLodsFrag)
  366. {
  367. DWORD LoopIncr = sizeof(UTYPE)*cpu->flag_df;
  368. DWORD Base = (DWORD)(ULONGLONG)NtCurrentTeb();
  369. while (ecx) {
  370. AREG = GET_VAL(esi + Base);
  371. esi += LoopIncr;
  372. ecx--;
  373. }
  374. }