summaryrefslogtreecommitdiffstats
path: root/private/ntos/nthals/x86new/bitops.c
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/ntos/nthals/x86new/bitops.c
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/ntos/nthals/x86new/bitops.c')
-rw-r--r--private/ntos/nthals/x86new/bitops.c256
1 files changed, 256 insertions, 0 deletions
diff --git a/private/ntos/nthals/x86new/bitops.c b/private/ntos/nthals/x86new/bitops.c
new file mode 100644
index 000000000..caf36f3d2
--- /dev/null
+++ b/private/ntos/nthals/x86new/bitops.c
@@ -0,0 +1,256 @@
+/*++
+
+Copyright (c) 1994 Microsoft Corporation
+
+Module Name:
+
+ bitops.c
+
+Abstract:
+
+ This module implements the code to emulate the bit opcodes.
+
+Author:
+
+ David N. Cutler (davec) 12-Nov-1994
+
+Environment:
+
+ Kernel mode only.
+
+Revision History:
+
+--*/
+
+#include "nthal.h"
+#include "emulate.h"
+
+VOID
+XmBsfOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an bsf opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ ULONG Result;
+ ULONG Source;
+
+ //
+ // If the source operand is zero, then set ZF and set the destination
+ // to zero, Otherwise, find the first bit set scanning from right to
+ // left.
+ //
+
+ Result = 0;
+ Source = P->SrcValue.Long;
+ P->Eflags.ZF = 1;
+ while (Source != 0) {
+ if ((Source & 1) != 0) {
+ P->Eflags.ZF = 0;
+ break;
+ }
+
+ Result += 1;
+ Source >>= 1;
+ };
+
+ XmStoreResult(P, Result);
+ return;
+}
+
+VOID
+XmBsrOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an bsr opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ ULONG Result;
+ ULONG Source;
+
+ //
+ // If the source operand is zero, then set ZF and set the destination
+ // to zero, Otherwise, find the first bit set scanning from left to
+ // right.
+ //
+
+ Result = ((P->DataType + 1) << 3) - 1;
+ Source = P->SrcValue.Long;
+ P->Eflags.ZF = 1;
+ while (Source != 0) {
+ if (((Source >> Result) & 1) != 0) {
+ P->Eflags.ZF = 0;
+ break;
+ }
+
+ Result -= 1;
+ };
+
+ XmStoreResult(P, Result);
+ return;
+}
+
+VOID
+XmBtOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an bt opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ //
+ // Test the specified bit and store the bit in CF.
+ //
+
+ P->Eflags.CF = P->DstValue.Long >> P->SrcValue.Long;
+ return;
+}
+
+VOID
+XmBtsOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an bts opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ //
+ // Test and set the specified bit and store the bit in CF.
+ //
+ //
+
+ P->Eflags.CF = P->DstValue.Long >> P->SrcValue.Long;
+ P->DstValue.Long |= (1 << P->SrcValue.Long);
+ XmStoreResult(P, P->DstValue.Long);
+ return;
+}
+
+VOID
+XmBtrOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an btr opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ //
+ // Test and reset the specified bit and store the bit in CF.
+ //
+ //
+
+ P->Eflags.CF = P->DstValue.Long >> P->SrcValue.Long;
+ P->DstValue.Long &= ~(1 << P->SrcValue.Long);
+ XmStoreResult(P, P->DstValue.Long);
+ return;
+}
+
+VOID
+XmBtcOp (
+ IN PRXM_CONTEXT P
+ )
+
+/*++
+
+Routine Description:
+
+ This function emulates an btc opcode.
+
+Arguments:
+
+ P - Supplies a pointer to the emulation context structure.
+
+Return Value:
+
+ None.
+
+--*/
+
+{
+
+ //
+ // Test and reset the specified bit and store the bit in CF.
+ //
+ //
+
+ P->Eflags.CF = P->DstValue.Long >> P->SrcValue.Long;
+ P->DstValue.Long ^= (1 << P->SrcValue.Long);
+ XmStoreResult(P, P->DstValue.Long);
+ return;
+}