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.

256 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. bitops.c
  5. Abstract:
  6. This module implements the code to emulate the bit opcodes.
  7. Author:
  8. David N. Cutler (davec) 12-Nov-1994
  9. Environment:
  10. Kernel mode only.
  11. Revision History:
  12. --*/
  13. #include "nthal.h"
  14. #include "emulate.h"
  15. VOID
  16. XmBsfOp (
  17. IN PRXM_CONTEXT P
  18. )
  19. /*++
  20. Routine Description:
  21. This function emulates an bsf opcode.
  22. Arguments:
  23. P - Supplies a pointer to the emulation context structure.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. ULONG Result;
  29. ULONG Source;
  30. //
  31. // If the source operand is zero, then set ZF and set the destination
  32. // to zero, Otherwise, find the first bit set scanning from right to
  33. // left.
  34. //
  35. Result = 0;
  36. Source = P->SrcValue.Long;
  37. P->Eflags.EFLAG_ZF = 1;
  38. while (Source != 0) {
  39. if ((Source & 1) != 0) {
  40. P->Eflags.EFLAG_ZF = 0;
  41. break;
  42. }
  43. Result += 1;
  44. Source >>= 1;
  45. };
  46. XmStoreResult(P, Result);
  47. return;
  48. }
  49. VOID
  50. XmBsrOp (
  51. IN PRXM_CONTEXT P
  52. )
  53. /*++
  54. Routine Description:
  55. This function emulates an bsr opcode.
  56. Arguments:
  57. P - Supplies a pointer to the emulation context structure.
  58. Return Value:
  59. None.
  60. --*/
  61. {
  62. ULONG Result;
  63. ULONG Source;
  64. //
  65. // If the source operand is zero, then set ZF and set the destination
  66. // to zero, Otherwise, find the first bit set scanning from left to
  67. // right.
  68. //
  69. Result = ((P->DataType + 1) << 3) - 1;
  70. Source = P->SrcValue.Long;
  71. P->Eflags.EFLAG_ZF = 1;
  72. while (Source != 0) {
  73. if (((Source >> Result) & 1) != 0) {
  74. P->Eflags.EFLAG_ZF = 0;
  75. break;
  76. }
  77. Result -= 1;
  78. };
  79. XmStoreResult(P, Result);
  80. return;
  81. }
  82. VOID
  83. XmBtOp (
  84. IN PRXM_CONTEXT P
  85. )
  86. /*++
  87. Routine Description:
  88. This function emulates an bt opcode.
  89. Arguments:
  90. P - Supplies a pointer to the emulation context structure.
  91. Return Value:
  92. None.
  93. --*/
  94. {
  95. //
  96. // Test the specified bit and store the bit in CF.
  97. //
  98. P->Eflags.EFLAG_CF = P->DstValue.Long >> P->SrcValue.Long;
  99. return;
  100. }
  101. VOID
  102. XmBtsOp (
  103. IN PRXM_CONTEXT P
  104. )
  105. /*++
  106. Routine Description:
  107. This function emulates an bts opcode.
  108. Arguments:
  109. P - Supplies a pointer to the emulation context structure.
  110. Return Value:
  111. None.
  112. --*/
  113. {
  114. //
  115. // Test and set the specified bit and store the bit in CF.
  116. //
  117. //
  118. P->Eflags.EFLAG_CF = P->DstValue.Long >> P->SrcValue.Long;
  119. P->DstValue.Long |= (1 << P->SrcValue.Long);
  120. XmStoreResult(P, P->DstValue.Long);
  121. return;
  122. }
  123. VOID
  124. XmBtrOp (
  125. IN PRXM_CONTEXT P
  126. )
  127. /*++
  128. Routine Description:
  129. This function emulates an btr opcode.
  130. Arguments:
  131. P - Supplies a pointer to the emulation context structure.
  132. Return Value:
  133. None.
  134. --*/
  135. {
  136. //
  137. // Test and reset the specified bit and store the bit in CF.
  138. //
  139. //
  140. P->Eflags.EFLAG_CF = P->DstValue.Long >> P->SrcValue.Long;
  141. P->DstValue.Long &= ~(1 << P->SrcValue.Long);
  142. XmStoreResult(P, P->DstValue.Long);
  143. return;
  144. }
  145. VOID
  146. XmBtcOp (
  147. IN PRXM_CONTEXT P
  148. )
  149. /*++
  150. Routine Description:
  151. This function emulates an btc opcode.
  152. Arguments:
  153. P - Supplies a pointer to the emulation context structure.
  154. Return Value:
  155. None.
  156. --*/
  157. {
  158. //
  159. // Test and reset the specified bit and store the bit in CF.
  160. //
  161. //
  162. P->Eflags.EFLAG_CF = P->DstValue.Long >> P->SrcValue.Long;
  163. P->DstValue.Long ^= (1 << P->SrcValue.Long);
  164. XmStoreResult(P, P->DstValue.Long);
  165. return;
  166. }