45 ULONG SignFlag = 1 << (Bits - 1);
46 ULONG MaxValue = (SignFlag - 1) | SignFlag;
49 FirstValue &= MaxValue;
50 SecondValue &= MaxValue;
58 Result = (FirstValue + SecondValue) & MaxValue;
62 State->Flags.Of = ((FirstValue & SignFlag) == (SecondValue & SignFlag))
63 && ((FirstValue & SignFlag) != (
Result & SignFlag));
64 State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
72 Result = FirstValue | SecondValue;
82 Result = (FirstValue + SecondValue + Carry) & MaxValue;
85 State->Flags.Cf = ((SecondValue == MaxValue) && (Carry == 1))
86 || ((
Result < FirstValue) && (
Result < (SecondValue + Carry)));
87 State->Flags.Of = ((FirstValue & SignFlag) == (SecondValue & SignFlag))
88 && ((FirstValue & SignFlag) != (
Result & SignFlag));
89 State->Flags.Af = ((FirstValue ^ SecondValue ^
Result) & 0x10) != 0;
99 Result = (FirstValue - SecondValue - Carry) & MaxValue;
102 State->Flags.Cf = Carry
103 ? (FirstValue <= SecondValue)
104 : (FirstValue < SecondValue);
105 State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
106 && ((FirstValue & SignFlag) != (
Result & SignFlag));
107 State->Flags.Af = ((FirstValue ^ SecondValue ^
Result) & 0x10) != 0;
115 Result = FirstValue & SecondValue;
124 Result = (FirstValue - SecondValue) & MaxValue;
127 State->Flags.Cf = (FirstValue < SecondValue);
128 State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
129 && ((FirstValue & SignFlag) != (
Result & SignFlag));
130 State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
138 Result = FirstValue ^ SecondValue;
168 ULONG HighestBit = 1 << (Bits - 1);
169 ULONG MaxValue = HighestBit | (HighestBit - 1);
192 ^ ((
Result & HighestBit) != 0);
206 ^ ((
Result & (HighestBit >> 1)) != 0);
252 ^ ((
Result & HighestBit) != 0);
303 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
307 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
314 if (!Fast486FetchByte(
State, &Immediate))
321 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
340 BOOLEAN OperandSize, AddressSize;
342 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
347 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
358 if (!Fast486FetchDword(
State, &Immediate))
365 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
385 if (!Fast486FetchWord(
State, &Immediate))
392 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
413 BOOLEAN OperandSize, AddressSize;
415 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
420 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
439 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
460 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
481 BOOLEAN OperandSize, AddressSize;
483 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
495 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
504 Fast486Exception(
State, FAST486_EXCEPTION_UD);
508 if (OperandSize) Fast486WriteModrmDwordOperands(
State, &ModRegRm,
FALSE,
Value);
516 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
520 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
534 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
555 BOOLEAN OperandSize, AddressSize;
557 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
562 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
580 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
601 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
623 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
627 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
636 Fast486Exception(
State, FAST486_EXCEPTION_UD);
641 if (!Fast486FetchByte(
State, &Immediate))
647 Fast486WriteModrmByteOperands(
State, &ModRegRm,
FALSE, Immediate);
653 BOOLEAN OperandSize, AddressSize;
655 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
660 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
669 Fast486Exception(
State, FAST486_EXCEPTION_UD);
678 if (!Fast486FetchDword(
State, &Immediate))
684 Fast486WriteModrmDwordOperands(
State, &ModRegRm,
FALSE, Immediate);
691 if (!Fast486FetchWord(
State, &Immediate))
697 Fast486WriteModrmWordOperands(
State, &ModRegRm,
FALSE, Immediate);
705 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
709 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
716 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
733 BOOLEAN OperandSize, AddressSize;
735 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
740 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
751 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
768 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
786 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
790 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
797 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
808 State->GeneralRegs[FAST486_REG_ECX].LowByte));
817 BOOLEAN OperandSize, AddressSize;
819 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
824 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
835 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
846 State->GeneralRegs[FAST486_REG_ECX].LowByte);
856 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
867 State->GeneralRegs[FAST486_REG_ECX].LowByte));
878 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
882 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
889 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
904 if (!Fast486FetchByte(
State, &Immediate))
961 State->GeneralRegs[FAST486_REG_EAX].LowWord =
Result;
989 Fast486Exception(
State, FAST486_EXCEPTION_DE);
993 Quotient =
State->GeneralRegs[FAST486_REG_EAX].LowWord /
Value;
999 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1004 State->GeneralRegs[FAST486_REG_EAX].LowByte = (
UCHAR)Quotient;
1019 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1029 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1034 State->GeneralRegs[FAST486_REG_EAX].LowByte = (
UCHAR)((
CHAR)Quotient);
1046 BOOLEAN OperandSize, AddressSize;
1048 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
1053 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
1067 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
1094 if (!Fast486FetchDword(
State, &Immediate))
1146 if (!OperandSize)
Result &= 0xFFFF;
1179 State->Flags.Cf =
State->Flags.Of = ((
Result & 0xFFFFFFFF00000000ULL) != 0);
1182 State->GeneralRegs[FAST486_REG_EAX].Long =
Result & 0xFFFFFFFFULL;
1183 State->GeneralRegs[FAST486_REG_EDX].Long =
Result >> 32;
1211 State->GeneralRegs[FAST486_REG_EAX].Long =
Result & 0xFFFFFFFFULL;
1212 State->GeneralRegs[FAST486_REG_EDX].Long =
Result >> 32;
1235 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1246 if (Quotient > 0xFFFFFFFFULL)
1249 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1254 State->GeneralRegs[FAST486_REG_EAX].Long = (
ULONG)Quotient;
1260 | ((
ULONG)
State->GeneralRegs[FAST486_REG_EDX].LowWord << 16);
1264 if (Quotient > 0xFFFF)
1267 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1272 State->GeneralRegs[FAST486_REG_EAX].LowWord = (
USHORT)Quotient;
1285 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1292 | ((
LONGLONG)
State->GeneralRegs[FAST486_REG_EDX].Long << 32);
1299 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1304 State->GeneralRegs[FAST486_REG_EAX].Long = (
ULONG)((
LONG)Quotient);
1309 LONG Dividend = (
LONG)
State->GeneralRegs[FAST486_REG_EAX].LowWord
1310 | ((
LONG)
State->GeneralRegs[FAST486_REG_EDX].LowWord << 16);
1317 Fast486Exception(
State, FAST486_EXCEPTION_DE);
1335 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
1339 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
1348 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1353 if (!Fast486ReadModrmByteOperands(
State, &ModRegRm,
NULL, &
Value))
1377 State->Flags.Pf = Fast486CalculateParity(
Value);
1386 BOOLEAN OperandSize, AddressSize;
1388 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
1393 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
1402 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1411 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
1434 if (!Fast486StackPush(
State,
State->InstPtr.Long))
1446 FAST486_SEG_REGS
Segment = FAST486_REG_DS;
1468 && !
State->Flags.Vm)
1478 if (!Fast486StackPush(
State,
State->SegmentRegs[FAST486_REG_CS].Selector))
1485 if (!Fast486StackPush(
State,
State->InstPtr.Long))
1492 if (!Fast486LoadSegment(
State, FAST486_REG_CS, Selector))
1509 FAST486_SEG_REGS
Segment = FAST486_REG_DS;
1531 && !
State->Flags.Vm)
1541 if (!Fast486LoadSegment(
State, FAST486_REG_CS, Selector))
1562 State->Flags.Pf = Fast486CalculateParity(
Value);
1572 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
1595 if (!Fast486StackPush(
State,
State->InstPtr.LowWord))
1605 State->InstPtr.Long &= 0xFFFF;
1610 FAST486_SEG_REGS
Segment = FAST486_REG_DS;
1632 && !
State->Flags.Vm)
1642 if (!Fast486StackPush(
State,
State->SegmentRegs[FAST486_REG_CS].Selector))
1649 if (!Fast486StackPush(
State,
State->InstPtr.LowWord))
1656 if (!Fast486LoadSegment(
State, FAST486_REG_CS, Selector))
1666 State->InstPtr.Long &= 0xFFFF;
1674 State->InstPtr.Long &= 0xFFFF;
1679 FAST486_SEG_REGS
Segment = FAST486_REG_DS;
1701 && !
State->Flags.Vm)
1711 if (!Fast486LoadSegment(
State, FAST486_REG_CS, Selector))
1721 State->InstPtr.Long &= 0xFFFF;
1732 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1741 State->Flags.Pf = Fast486CalculateParity(
Value);
1752 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
1757 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
1773 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1777 Fast486WriteModrmWordOperands(
State, &ModRegRm,
FALSE,
State->Ldtr.Selector);
1788 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1792 Fast486WriteModrmWordOperands(
State, &ModRegRm,
FALSE,
State->TaskReg.Selector);
1801 FAST486_SYSTEM_DESCRIPTOR GdtEntry;
1807 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1812 if (Fast486GetCurrentPrivLevel(
State) != 0)
1814 Fast486Exception(
State, FAST486_EXCEPTION_GP);
1818 if (!Fast486ReadModrmWordOperands(
State,
1834 if (!Fast486ReadDescriptorEntry(
State,
1837 (PFAST486_GDT_ENTRY)&GdtEntry))
1856 if (!GdtEntry.Present)
1870 State->Ldtr.Selector = Selector;
1871 State->Ldtr.Base = GdtEntry.Base | (GdtEntry.BaseMid << 16) | (GdtEntry.BaseHigh << 24);
1872 State->Ldtr.Limit = GdtEntry.Limit | (GdtEntry.LimitHigh << 16);
1874 if (GdtEntry.Granularity)
1876 State->Ldtr.Limit <<= 12;
1877 State->Ldtr.Limit |= 0x00000FFF;
1888 FAST486_SYSTEM_DESCRIPTOR GdtEntry;
1894 Fast486Exception(
State, FAST486_EXCEPTION_UD);
1899 if (Fast486GetCurrentPrivLevel(
State) != 0)
1901 Fast486Exception(
State, FAST486_EXCEPTION_GP);
1905 if (!Fast486ReadModrmWordOperands(
State,
1921 if (!Fast486ReadDescriptorEntry(
State,
1924 (PFAST486_GDT_ENTRY)&GdtEntry))
1939 Fast486Exception(
State, FAST486_EXCEPTION_GP);
1943 if (!GdtEntry.Present)
1960 State->TaskReg.Selector = Selector;
1961 State->TaskReg.Base = GdtEntry.Base | (GdtEntry.BaseMid << 16) | (GdtEntry.BaseHigh << 24);
1962 State->TaskReg.Limit = GdtEntry.Limit | (GdtEntry.LimitHigh << 16);
1966 if (GdtEntry.Granularity)
1968 State->TaskReg.Limit <<= 12;
1969 State->TaskReg.Limit |= 0x00000FFF;
1976 GdtEntry.Signature |= 2;
1978 Fast486WriteLinearMemory(
State,
1994 FAST486_GDT_ENTRY GdtEntry;
2000 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2004 if (!Fast486ReadModrmWordOperands(
State,
2013 if (!Fast486ReadDescriptorEntry(
State, Selector, &Valid, &GdtEntry))
2027 State->Flags.Zf = GdtEntry.Present
2028 && GdtEntry.SystemType
2031 && (!GdtEntry.Executable || GdtEntry.ReadWrite))
2034 && (!GdtEntry.Executable && GdtEntry.ReadWrite)))
2039 && (((!GdtEntry.Executable || !GdtEntry.DirConf)
2041 && (Fast486GetCurrentPrivLevel(
State) <= GdtEntry.Dpl))
2043 || ((GdtEntry.Executable && GdtEntry.DirConf)
2044 && (GdtEntry.Dpl <= Fast486GetCurrentPrivLevel(
State))));
2053 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2063 BOOLEAN OperandSize, AddressSize;
2064 FAST486_SEG_REGS
Segment = FAST486_REG_DS;
2066 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
2072 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
2094 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2119 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2142 if (Fast486GetCurrentPrivLevel(
State) != 0)
2144 Fast486Exception(
State, FAST486_EXCEPTION_GP);
2151 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2173 if (!OperandSize)
State->Gdtr.Address &= 0x00FFFFFF;
2182 if (Fast486GetCurrentPrivLevel(
State) != 0)
2184 Fast486Exception(
State, FAST486_EXCEPTION_GP);
2191 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2213 if (!OperandSize)
State->Idtr.Address &= 0x00FFFFFF;
2222 Fast486WriteModrmWordOperands(
State,
2225 LOWORD(
State->ControlRegisters[FAST486_REG_CR0]));
2233 USHORT MachineStatusWord;
2238 if (Fast486GetCurrentPrivLevel(
State) != 0)
2240 Fast486Exception(
State, FAST486_EXCEPTION_GP);
2246 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &MachineStatusWord))
2253 State->ControlRegisters[FAST486_REG_CR0] &= 0xFFFFFFF1;
2254 State->ControlRegisters[FAST486_REG_CR0] |= MachineStatusWord & 0x0F;
2262#ifndef FAST486_NO_PREFETCH
2268 if (Fast486GetCurrentPrivLevel(
State) != 0)
2270 Fast486Exception(
State, FAST486_EXCEPTION_GP);
2277 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2293 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2301 BOOLEAN AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
2305 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
2312 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2319 BOOLEAN OperandSize, AddressSize;
2323 OperandSize = AddressSize =
State->SegmentRegs[FAST486_REG_CS].Size;
2332 if (!Fast486ParseModRegRm(
State, AddressSize, &ModRegRm))
2341 Fast486Exception(
State, FAST486_EXCEPTION_UD);
2346 if (!Fast486FetchByte(
State, &BitNumber))
2369 if (!Fast486ReadModrmDwordOperands(
State, &ModRegRm,
NULL, &
Value))
2381 Value |= 1 << BitNumber;
2386 Value &= ~(1 << BitNumber);
2391 Value ^= 1 << BitNumber;
2409 if (!Fast486ReadModrmWordOperands(
State, &ModRegRm,
NULL, &
Value))
2421 Value |= 1 << BitNumber;
2426 Value &= ~(1 << BitNumber);
2431 Value ^= 1 << BitNumber;
#define FAST486_BUSY_TSS_16_SIGNATURE
#define FAST486_TSS_SIGNATURE
#define FAST486_PREFIX_SEG
#define FAST486_TSS_16_SIGNATURE
#define FAST486_SHORT_MAX
#define FAST486_SHORT_MIN
#define FAST486_LDT_SIGNATURE
#define FAST486_BUSY_TSS_SIGNATURE
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
#define FAST486_OPCODE_HANDLER(x)
static ULONG Fast486ArithmeticOperation(PFAST486_STATE State, INT Operation, ULONG FirstValue, ULONG SecondValue, UCHAR Bits)
static ULONG Fast486RotateOperation(PFAST486_STATE State, INT Operation, ULONG Value, UCHAR Bits, UCHAR Count)
VOID FASTCALL Fast486ExceptionWithErrorCode(PFAST486_STATE State, FAST486_EXCEPTIONS ExceptionCode, ULONG ErrorCode)
BOOLEAN FASTCALL Fast486WriteMemory(PFAST486_STATE State, FAST486_SEG_REGS SegmentReg, ULONG Offset, PVOID Buffer, ULONG Size)
BOOLEAN FASTCALL Fast486ReadMemory(PFAST486_STATE State, FAST486_SEG_REGS SegmentReg, ULONG Offset, BOOLEAN InstFetch, PVOID Buffer, ULONG Size)
#define GET_SEGMENT_RPL(s)
#define INVALID_TLB_FIELD
#define GET_SEGMENT_INDEX(s)
#define SEGMENT_TABLE_INDICATOR
FAST486_GEN_REGS Register
#define RtlZeroMemory(Destination, Length)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder