Windows NT 4.0 source code leak
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.

247 lines
3.3 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. logops.c
  5. Abstract:
  6. This module implements the code to emulate the and, or, test, xor,
  7. and not opcodes.
  8. Author:
  9. David N. Cutler (davec) 12-Sep-1994
  10. Environment:
  11. Kernel mode only.
  12. Revision History:
  13. --*/
  14. #include "nthal.h"
  15. #include "emulate.h"
  16. //
  17. // Define forward referenced prototypes.
  18. //
  19. VOID
  20. XmSetLogicalResult (
  21. IN PRXM_CONTEXT P,
  22. IN ULONG Result
  23. );
  24. VOID
  25. XmAndOp (
  26. IN PRXM_CONTEXT P
  27. )
  28. /*++
  29. Routine Description:
  30. This function emulates an and opcode.
  31. Arguments:
  32. P - Supplies a pointer to the emulation context structure.
  33. Return Value:
  34. None.
  35. --*/
  36. {
  37. //
  38. // And operands and store result.
  39. //
  40. XmSetLogicalResult(P, P->DstValue.Long & P->SrcValue.Long);
  41. return;
  42. }
  43. VOID
  44. XmOrOp (
  45. IN PRXM_CONTEXT P
  46. )
  47. /*++
  48. Routine Description:
  49. This function emulates an or opcode.
  50. Arguments:
  51. P - Supplies a pointer to the emulation context structure.
  52. Return Value:
  53. None.
  54. --*/
  55. {
  56. //
  57. // Or operands and store result.
  58. //
  59. XmSetLogicalResult(P, P->DstValue.Long | P->SrcValue.Long);
  60. return;
  61. }
  62. VOID
  63. XmTestOp (
  64. IN PRXM_CONTEXT P
  65. )
  66. /*++
  67. Routine Description:
  68. This function emulates a test opcode.
  69. Arguments:
  70. P - Supplies a pointer to the emulation context structure.
  71. Return Value:
  72. None.
  73. --*/
  74. {
  75. //
  76. // And operands but don't store result.
  77. //
  78. XmSetLogicalResult(P, P->DstValue.Long & P->SrcValue.Long);
  79. return;
  80. }
  81. VOID
  82. XmXorOp (
  83. IN PRXM_CONTEXT P
  84. )
  85. /*++
  86. Routine Description:
  87. This function emulates a xor opcode.
  88. Arguments:
  89. P - Supplies a pointer to the emulation context structure.
  90. Return Value:
  91. None.
  92. --*/
  93. {
  94. //
  95. // Xor operands and store result.
  96. //
  97. XmSetLogicalResult(P, P->DstValue.Long ^ P->SrcValue.Long);
  98. return;
  99. }
  100. VOID
  101. XmNotOp (
  102. IN PRXM_CONTEXT P
  103. )
  104. /*++
  105. Routine Description:
  106. This function emulates a not opcode.
  107. Arguments:
  108. P - Supplies a pointer to the emulation context structure.
  109. Return Value:
  110. None.
  111. --*/
  112. {
  113. ULONG Mask;
  114. ULONG Shift;
  115. //
  116. // Complement operand and store result.
  117. //
  118. Shift = Shift = ((P->DataType + 1) << 3) - 1;
  119. Mask = ((1 << Shift) - 1) | (1 << Shift);
  120. XmStoreResult(P, ~P->DstValue.Long & Mask);
  121. return;
  122. }
  123. VOID
  124. XmSetLogicalResult (
  125. IN PRXM_CONTEXT P,
  126. IN ULONG Result
  127. )
  128. /*++
  129. Routine Description:
  130. This function conditionally stores the result of a logical operation
  131. and computes the resultant condtion codes.
  132. Arguments:
  133. P - Supplies a pointer to the emulation context structure.
  134. Result - Supplies the result value (note that the result is always
  135. zero extended to a long with no carry bits into the zero extended
  136. part).
  137. Return Value:
  138. None.
  139. --*/
  140. {
  141. ULONG Shift;
  142. //
  143. // Store the result and compute auxilary carry flag, parity flag, sign
  144. // and zero flags.
  145. //
  146. if (P->FunctionIndex != X86_TEST_OP) {
  147. XmStoreResult(P, Result);
  148. }
  149. Shift = Shift = ((P->DataType + 1) << 3) - 1;
  150. P->Eflags.CF = 0;
  151. P->Eflags.PF = XmComputeParity(Result);
  152. P->Eflags.AF = 0;
  153. P->Eflags.ZF = (Result == 0);
  154. P->Eflags.SF = Result >> Shift;
  155. P->Eflags.OF = 0;
  156. return;
  157. }