2 * Fast486 386/486 CPU Emulation Library
5 * Copyright (C) 2013 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 /* PUBLIC FUNCTIONS ***********************************************************/
28 Fast486GetPageTableEntry(PFAST486_STATE State,
32 ULONG PdeIndex = GET_ADDR_PDE(VirtualAddress);
33 ULONG PteIndex = GET_ADDR_PTE(VirtualAddress);
34 FAST486_PAGE_DIR DirectoryEntry;
35 FAST486_PAGE_TABLE TableEntry;
36 ULONG PageDirectory = State->ControlRegisters[FAST486_REG_CR3];
38 if ((State->Tlb != NULL)
39 && (State->Tlb[VirtualAddress >> 12] != INVALID_TLB_FIELD))
41 /* Return the cached entry */
42 return State->Tlb[VirtualAddress >> 12];
45 /* Read the directory entry */
46 State->MemReadCallback(State,
47 PageDirectory + PdeIndex * sizeof(ULONG),
48 &DirectoryEntry.Value,
49 sizeof(DirectoryEntry));
51 /* Make sure it is present */
52 if (!DirectoryEntry.Present) return 0;
54 /* Was the directory entry accessed before? */
55 if (!DirectoryEntry.Accessed)
58 DirectoryEntry.Accessed = TRUE;
60 /* Write back the directory entry */
61 State->MemWriteCallback(State,
62 PageDirectory + PdeIndex * sizeof(ULONG),
63 &DirectoryEntry.Value,
64 sizeof(DirectoryEntry));
67 /* Read the table entry */
68 State->MemReadCallback(State,
69 (DirectoryEntry.TableAddress << 12)
70 + PteIndex * sizeof(ULONG),
74 /* Make sure it is present */
75 if (!TableEntry.Present) return 0;
77 if (MarkAsDirty) TableEntry.Dirty = TRUE;
79 /* Was the table entry accessed before? */
80 if (!TableEntry.Accessed)
83 TableEntry.Accessed = TRUE;
85 /* Write back the table entry */
86 State->MemWriteCallback(State,
87 (DirectoryEntry.TableAddress << 12)
88 + PteIndex * sizeof(ULONG),
94 * The resulting permissions depend on the permissions
95 * in the page directory table too
97 TableEntry.Writeable &= DirectoryEntry.Writeable;
98 TableEntry.Usermode &= DirectoryEntry.Usermode;
100 if (State->Tlb != NULL)
102 /* Set the TLB entry */
103 State->Tlb[VirtualAddress >> 12] = TableEntry.Value;
106 /* Return the table entry */
107 return TableEntry.Value;
112 Fast486ReadLinearMemory(PFAST486_STATE State,
117 INT Cpl = Fast486GetCurrentPrivLevel(State);
119 /* Check if paging is enabled */
120 if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PG)
123 FAST486_PAGE_TABLE TableEntry;
125 for (Page = PAGE_ALIGN(LinearAddress);
126 Page <= PAGE_ALIGN(LinearAddress + Size - 1);
129 ULONG PageOffset = 0, PageLength = PAGE_SIZE;
131 /* Get the table entry */
132 TableEntry.Value = Fast486GetPageTableEntry(State, Page, FALSE);
134 if (!TableEntry.Present || (!TableEntry.Usermode && (Cpl > 0)))
137 Fast486ExceptionWithErrorCode(State,
138 FAST486_EXCEPTION_PF,
139 TableEntry.Value & 0x07);
143 /* Check if this is the first page */
144 if (Page == PAGE_ALIGN(LinearAddress))
146 /* Start copying from the offset from the beginning of the page */
147 PageOffset = PAGE_OFFSET(LinearAddress);
150 /* Check if this is the last page */
151 if (Page == PAGE_ALIGN(LinearAddress + Size - 1))
153 /* Copy only a part of the page */
154 PageLength = PAGE_OFFSET(LinearAddress + Size);
157 /* Read the memory */
158 State->MemReadCallback(State,
159 (TableEntry.Address << 12) | PageOffset,
166 /* Read the memory */
167 State->MemReadCallback(State, LinearAddress, Buffer, Size);
175 Fast486WriteLinearMemory(PFAST486_STATE State,
180 INT Cpl = Fast486GetCurrentPrivLevel(State);
182 /* Check if paging is enabled */
183 if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PG)
186 FAST486_PAGE_TABLE TableEntry;
188 for (Page = PAGE_ALIGN(LinearAddress);
189 Page <= PAGE_ALIGN(LinearAddress + Size - 1);
192 ULONG PageOffset = 0, PageLength = PAGE_SIZE;
194 /* Get the table entry */
195 TableEntry.Value = Fast486GetPageTableEntry(State, Page, TRUE);
197 if ((!TableEntry.Present || (!TableEntry.Usermode && (Cpl > 0)))
198 || ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_WP)
199 && !TableEntry.Writeable))
202 Fast486ExceptionWithErrorCode(State,
203 FAST486_EXCEPTION_PF,
204 TableEntry.Value & 0x07);
208 /* Check if this is the first page */
209 if (Page == PAGE_ALIGN(LinearAddress))
211 /* Start copying from the offset from the beginning of the page */
212 PageOffset = PAGE_OFFSET(LinearAddress);
215 /* Check if this is the last page */
216 if (Page == PAGE_ALIGN(LinearAddress + Size - 1))
218 /* Copy only a part of the page */
219 PageLength = PAGE_OFFSET(LinearAddress + Size);
222 /* Write the memory */
223 State->MemWriteCallback(State,
224 (TableEntry.Address << 12) | PageOffset,
231 /* Write the memory */
232 State->MemWriteCallback(State, LinearAddress, Buffer, Size);
240 Fast486Exception(PFAST486_STATE State,
241 FAST486_EXCEPTIONS ExceptionCode)
243 /* Call the internal function */
244 Fast486ExceptionWithErrorCode(State, ExceptionCode, 0);
249 Fast486StackPush(PFAST486_STATE State,
252 BOOLEAN Size = State->SegmentRegs[FAST486_REG_SS].Size;
254 /* The OPSIZE prefix toggles the size */
255 if (State->PrefixFlags & FAST486_PREFIX_OPSIZE) Size = !Size;
261 /* Check if ESP is between 1 and 3 */
262 if (State->GeneralRegs[FAST486_REG_ESP].Long >= 1
263 && State->GeneralRegs[FAST486_REG_ESP].Long <= 3)
265 Fast486Exception(State, FAST486_EXCEPTION_SS);
269 /* Subtract ESP by 4 */
270 State->GeneralRegs[FAST486_REG_ESP].Long -= 4;
272 /* Store the value in SS:ESP */
273 return Fast486WriteMemory(State,
275 State->GeneralRegs[FAST486_REG_ESP].Long,
282 USHORT ShortValue = LOWORD(Value);
284 /* Check if SP is 1 */
285 if (State->GeneralRegs[FAST486_REG_ESP].Long == 1)
287 Fast486Exception(State, FAST486_EXCEPTION_SS);
291 /* Subtract SP by 2 */
292 State->GeneralRegs[FAST486_REG_ESP].LowWord -= 2;
294 /* Store the value in SS:SP */
295 return Fast486WriteMemory(State,
297 State->GeneralRegs[FAST486_REG_ESP].LowWord,
305 Fast486StackPop(PFAST486_STATE State,
310 BOOLEAN Size = State->SegmentRegs[FAST486_REG_SS].Size;
312 /* The OPSIZE prefix toggles the size */
313 if (State->PrefixFlags & FAST486_PREFIX_OPSIZE) Size = !Size;
319 /* Check if ESP is 0xFFFFFFFF */
320 if (State->GeneralRegs[FAST486_REG_ESP].Long == 0xFFFFFFFF)
322 Fast486Exception(State, FAST486_EXCEPTION_SS);
326 /* Read the value from SS:ESP */
327 if (!Fast486ReadMemory(State,
329 State->GeneralRegs[FAST486_REG_ESP].Long,
334 /* An exception occurred */
338 /* Increment ESP by 4 */
339 State->GeneralRegs[FAST486_REG_ESP].Long += 4;
341 /* Store the value in the result */
348 /* Check if SP is 0xFFFF */
349 if (State->GeneralRegs[FAST486_REG_ESP].LowWord == 0xFFFF)
351 Fast486Exception(State, FAST486_EXCEPTION_SS);
355 /* Read the value from SS:SP */
356 if (!Fast486ReadMemory(State,
358 State->GeneralRegs[FAST486_REG_ESP].LowWord,
363 /* An exception occurred */
367 /* Increment SP by 2 */
368 State->GeneralRegs[FAST486_REG_ESP].Long += 2;
370 /* Store the value in the result */
379 Fast486LoadSegment(PFAST486_STATE State,
383 PFAST486_SEG_REG CachedDescriptor;
384 FAST486_GDT_ENTRY GdtEntry;
386 ASSERT(Segment < FAST486_NUM_SEG_REGS);
388 /* Get the cached descriptor */
389 CachedDescriptor = &State->SegmentRegs[Segment];
391 /* Check for protected mode */
392 if ((State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) && !State->Flags.Vm)
394 /* Make sure the GDT contains the entry */
395 if (GET_SEGMENT_INDEX(Selector) >= (State->Gdtr.Size + 1))
397 Fast486Exception(State, FAST486_EXCEPTION_GP);
402 if (!Fast486ReadLinearMemory(State,
404 + GET_SEGMENT_INDEX(Selector),
408 /* Exception occurred */
412 if (Segment == FAST486_REG_SS)
414 /* Loading the stack segment */
416 if (GET_SEGMENT_INDEX(Selector) == 0)
418 Fast486Exception(State, FAST486_EXCEPTION_GP);
422 if (!GdtEntry.SystemType)
424 /* This is a special descriptor */
425 Fast486Exception(State, FAST486_EXCEPTION_GP);
429 if (GdtEntry.Executable || !GdtEntry.ReadWrite)
431 Fast486Exception(State, FAST486_EXCEPTION_GP);
435 if ((GET_SEGMENT_RPL(Selector) != Fast486GetCurrentPrivLevel(State))
436 || (GET_SEGMENT_RPL(Selector) != GdtEntry.Dpl))
438 Fast486Exception(State, FAST486_EXCEPTION_GP);
442 if (!GdtEntry.Present)
444 Fast486Exception(State, FAST486_EXCEPTION_SS);
448 else if (Segment == FAST486_REG_CS)
450 /* Loading the code segment */
451 // TODO: NOT IMPLEMENTED
455 /* Loading a data segment */
457 if (!GdtEntry.SystemType)
459 /* This is a special descriptor */
460 Fast486Exception(State, FAST486_EXCEPTION_GP);
464 if ((GET_SEGMENT_RPL(Selector) > GdtEntry.Dpl)
465 && (Fast486GetCurrentPrivLevel(State) > GdtEntry.Dpl))
467 Fast486Exception(State, FAST486_EXCEPTION_GP);
471 if (!GdtEntry.Present)
473 Fast486Exception(State, FAST486_EXCEPTION_NP);
478 /* Update the cache entry */
479 CachedDescriptor->Selector = Selector;
480 CachedDescriptor->Base = GdtEntry.Base | (GdtEntry.BaseMid << 16) | (GdtEntry.BaseHigh << 24);
481 CachedDescriptor->Limit = GdtEntry.Limit | (GdtEntry.LimitHigh << 16);
482 CachedDescriptor->Accessed = GdtEntry.Accessed;
483 CachedDescriptor->ReadWrite = GdtEntry.ReadWrite;
484 CachedDescriptor->DirConf = GdtEntry.DirConf;
485 CachedDescriptor->Executable = GdtEntry.Executable;
486 CachedDescriptor->SystemType = GdtEntry.SystemType;
487 CachedDescriptor->Dpl = GdtEntry.Dpl;
488 CachedDescriptor->Present = GdtEntry.Present;
489 CachedDescriptor->Size = GdtEntry.Size;
491 /* Check for page granularity */
492 if (GdtEntry.Granularity) CachedDescriptor->Limit <<= 12;
496 /* Update the selector and base */
497 CachedDescriptor->Selector = Selector;
498 CachedDescriptor->Base = Selector << 4;
506 Fast486FetchByte(PFAST486_STATE State,
509 PFAST486_SEG_REG CachedDescriptor;
511 /* Get the cached descriptor of CS */
512 CachedDescriptor = &State->SegmentRegs[FAST486_REG_CS];
514 /* Read from memory */
515 if (!Fast486ReadMemory(State,
517 (CachedDescriptor->Size) ? State->InstPtr.Long
518 : State->InstPtr.LowWord,
523 /* Exception occurred during instruction fetch */
527 /* Advance the instruction pointer */
528 if (CachedDescriptor->Size) State->InstPtr.Long++;
529 else State->InstPtr.LowWord++;
536 Fast486FetchWord(PFAST486_STATE State,
539 PFAST486_SEG_REG CachedDescriptor;
541 /* Get the cached descriptor of CS */
542 CachedDescriptor = &State->SegmentRegs[FAST486_REG_CS];
544 /* Read from memory */
545 // FIXME: Fix byte order on big-endian machines
546 if (!Fast486ReadMemory(State,
548 (CachedDescriptor->Size) ? State->InstPtr.Long
549 : State->InstPtr.LowWord,
554 /* Exception occurred during instruction fetch */
558 /* Advance the instruction pointer */
559 if (CachedDescriptor->Size) State->InstPtr.Long += sizeof(USHORT);
560 else State->InstPtr.LowWord += sizeof(USHORT);
567 Fast486FetchDword(PFAST486_STATE State,
570 PFAST486_SEG_REG CachedDescriptor;
572 /* Get the cached descriptor of CS */
573 CachedDescriptor = &State->SegmentRegs[FAST486_REG_CS];
575 /* Read from memory */
576 // FIXME: Fix byte order on big-endian machines
577 if (!Fast486ReadMemory(State,
579 (CachedDescriptor->Size) ? State->InstPtr.Long
580 : State->InstPtr.LowWord,
585 /* Exception occurred during instruction fetch */
589 /* Advance the instruction pointer */
590 if (CachedDescriptor->Size) State->InstPtr.Long += sizeof(ULONG);
591 else State->InstPtr.LowWord += sizeof(ULONG);
598 Fast486GetIntVector(PFAST486_STATE State,
600 PFAST486_IDT_ENTRY IdtEntry)
604 /* Check for protected mode */
605 if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE)
607 /* Read from the IDT */
608 if (!Fast486ReadLinearMemory(State,
610 + Number * sizeof(*IdtEntry),
614 /* Exception occurred */
620 /* Read from the real-mode IVT */
622 /* Paging is always disabled in real mode */
623 State->MemReadCallback(State,
625 + Number * sizeof(FarPointer),
629 /* Fill a fake IDT entry */
630 IdtEntry->Offset = LOWORD(FarPointer);
631 IdtEntry->Selector = HIWORD(FarPointer);
633 IdtEntry->Type = FAST486_IDT_INT_GATE;
634 IdtEntry->Storage = FALSE;
636 IdtEntry->Present = TRUE;
637 IdtEntry->OffsetHigh = 0;
645 Fast486CalculateParity(UCHAR Number)
647 // See http://graphics.stanford.edu/~seander/bithacks.html#ParityLookupTable too...
648 return (0x9669 >> ((Number & 0x0F) ^ (Number >> 4))) & 1;
653 Fast486ParseModRegRm(PFAST486_STATE State,
655 PFAST486_MOD_REG_RM ModRegRm)
657 UCHAR ModRmByte, Mode, RegMem;
659 /* Fetch the MOD REG R/M byte */
660 if (!Fast486FetchByte(State, &ModRmByte))
662 /* Exception occurred */
666 /* Unpack the mode and R/M */
667 Mode = ModRmByte >> 6;
668 RegMem = ModRmByte & 0x07;
670 /* Set the register operand */
671 ModRegRm->Register = (ModRmByte >> 3) & 0x07;
674 if ((ModRmByte >> 6) == 3)
676 /* The second operand is also a register */
677 ModRegRm->Memory = FALSE;
678 ModRegRm->SecondRegister = RegMem;
684 /* The second operand is memory */
685 ModRegRm->Memory = TRUE;
689 if (RegMem == FAST486_REG_ESP)
692 ULONG Scale, Index, Base;
694 /* Fetch the SIB byte */
695 if (!Fast486FetchByte(State, &SibByte))
697 /* Exception occurred */
701 /* Unpack the scale, index and base */
702 Scale = 1 << (SibByte >> 6);
703 Index = (SibByte >> 3) & 0x07;
704 if (Index != FAST486_REG_ESP) Index = State->GeneralRegs[Index].Long;
706 Base = State->GeneralRegs[SibByte & 0x07].Long;
708 /* Calculate the address */
709 ModRegRm->MemoryAddress = Base + Index * Scale;
711 else if (RegMem == FAST486_REG_EBP)
713 if (Mode) ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBP].Long;
714 else ModRegRm->MemoryAddress = 0;
718 /* Get the base from the register */
719 ModRegRm->MemoryAddress = State->GeneralRegs[RegMem].Long;
722 /* Check if there is no segment override */
723 if (!(State->PrefixFlags & FAST486_PREFIX_SEG))
725 /* Check if the default segment should be SS */
726 if ((RegMem == FAST486_REG_EBP) && Mode)
728 /* Add a SS: prefix */
729 State->PrefixFlags |= FAST486_PREFIX_SEG;
730 State->SegmentOverride = FAST486_REG_SS;
739 if (!Fast486FetchByte(State, (PUCHAR)&Offset))
741 /* Exception occurred */
745 /* Add the signed offset to the address */
746 ModRegRm->MemoryAddress += (LONG)Offset;
748 else if ((Mode == 2) || ((Mode == 0) && (RegMem == FAST486_REG_EBP)))
752 /* Fetch the dword */
753 if (!Fast486FetchDword(State, (PULONG)&Offset))
755 /* Exception occurred */
759 /* Add the signed offset to the address */
760 ModRegRm->MemoryAddress += Offset;
765 /* Check the operand */
771 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBX].LowWord
772 + State->GeneralRegs[FAST486_REG_ESI].LowWord;
780 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBX].LowWord
781 + State->GeneralRegs[FAST486_REG_EDI].LowWord;
789 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBP].LowWord
790 + State->GeneralRegs[FAST486_REG_ESI].LowWord;
798 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBP].LowWord
799 + State->GeneralRegs[FAST486_REG_EDI].LowWord;
807 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_ESI].LowWord;
815 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EDI].LowWord;
825 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBP].LowWord;
829 /* [constant] (added later) */
830 ModRegRm->MemoryAddress = 0;
839 ModRegRm->MemoryAddress = State->GeneralRegs[FAST486_REG_EBX].LowWord;
845 /* Check if there is no segment override */
846 if (!(State->PrefixFlags & FAST486_PREFIX_SEG))
848 /* Check if the default segment should be SS */
849 if ((RegMem == 2) || (RegMem == 3) || ((RegMem == 6) && Mode))
851 /* Add a SS: prefix */
852 State->PrefixFlags |= FAST486_PREFIX_SEG;
853 State->SegmentOverride = FAST486_REG_SS;
862 if (!Fast486FetchByte(State, (PUCHAR)&Offset))
864 /* Exception occurred */
868 /* Add the signed offset to the address */
869 ModRegRm->MemoryAddress += (LONG)Offset;
871 else if ((Mode == 2) || ((Mode == 0) && (RegMem == 6)))
876 if (!Fast486FetchWord(State, (PUSHORT)&Offset))
878 /* Exception occurred */
882 /* Add the signed offset to the address */
883 ModRegRm->MemoryAddress += (LONG)Offset;
886 /* Clear the top 16 bits */
887 ModRegRm->MemoryAddress &= 0x0000FFFF;
895 Fast486ReadModrmByteOperands(PFAST486_STATE State,
896 PFAST486_MOD_REG_RM ModRegRm,
900 FAST486_SEG_REGS Segment = FAST486_REG_DS;
902 /* Get the register value */
903 if (ModRegRm->Register & 0x04)
906 *RegValue = State->GeneralRegs[ModRegRm->Register & 0x03].HighByte;
911 *RegValue = State->GeneralRegs[ModRegRm->Register & 0x03].LowByte;
914 if (!ModRegRm->Memory)
916 /* Get the second register value */
917 if (ModRegRm->SecondRegister & 0x04)
920 *RmValue = State->GeneralRegs[ModRegRm->SecondRegister & 0x03].HighByte;
925 *RmValue = State->GeneralRegs[ModRegRm->SecondRegister & 0x03].LowByte;
930 /* Check for the segment override */
931 if (State->PrefixFlags & FAST486_PREFIX_SEG)
933 /* Use the override segment instead */
934 Segment = State->SegmentOverride;
938 if (!Fast486ReadMemory(State,
940 ModRegRm->MemoryAddress,
945 /* Exception occurred */
955 Fast486ReadModrmWordOperands(PFAST486_STATE State,
956 PFAST486_MOD_REG_RM ModRegRm,
960 FAST486_SEG_REGS Segment = FAST486_REG_DS;
962 /* Get the register value */
963 *RegValue = State->GeneralRegs[ModRegRm->Register].LowWord;
965 if (!ModRegRm->Memory)
967 /* Get the second register value */
968 *RmValue = State->GeneralRegs[ModRegRm->SecondRegister].LowWord;
972 /* Check for the segment override */
973 if (State->PrefixFlags & FAST486_PREFIX_SEG)
975 /* Use the override segment instead */
976 Segment = State->SegmentOverride;
980 if (!Fast486ReadMemory(State,
982 ModRegRm->MemoryAddress,
987 /* Exception occurred */
997 Fast486ReadModrmDwordOperands(PFAST486_STATE State,
998 PFAST486_MOD_REG_RM ModRegRm,
1002 FAST486_SEG_REGS Segment = FAST486_REG_DS;
1004 /* Get the register value */
1005 *RegValue = State->GeneralRegs[ModRegRm->Register].Long;
1007 if (!ModRegRm->Memory)
1009 /* Get the second register value */
1010 *RmValue = State->GeneralRegs[ModRegRm->SecondRegister].Long;
1014 /* Check for the segment override */
1015 if (State->PrefixFlags & FAST486_PREFIX_SEG)
1017 /* Use the override segment instead */
1018 Segment = State->SegmentOverride;
1022 if (!Fast486ReadMemory(State,
1024 ModRegRm->MemoryAddress,
1029 /* Exception occurred */
1039 Fast486WriteModrmByteOperands(PFAST486_STATE State,
1040 PFAST486_MOD_REG_RM ModRegRm,
1041 BOOLEAN WriteRegister,
1044 FAST486_SEG_REGS Segment = FAST486_REG_DS;
1048 /* Store the value in the register */
1049 if (ModRegRm->Register & 0x04)
1051 /* AH, CH, DH, BH */
1052 State->GeneralRegs[ModRegRm->Register & 0x03].HighByte = Value;
1056 /* AL, CL, DL, BL */
1057 State->GeneralRegs[ModRegRm->Register & 0x03].LowByte = Value;
1062 if (!ModRegRm->Memory)
1064 /* Store the value in the second register */
1065 if (ModRegRm->SecondRegister & 0x04)
1067 /* AH, CH, DH, BH */
1068 State->GeneralRegs[ModRegRm->SecondRegister & 0x03].HighByte = Value;
1072 /* AL, CL, DL, BL */
1073 State->GeneralRegs[ModRegRm->SecondRegister & 0x03].LowByte = Value;
1078 /* Check for the segment override */
1079 if (State->PrefixFlags & FAST486_PREFIX_SEG)
1081 /* Use the override segment instead */
1082 Segment = State->SegmentOverride;
1086 if (!Fast486WriteMemory(State,
1088 ModRegRm->MemoryAddress,
1092 /* Exception occurred */
1103 Fast486WriteModrmWordOperands(PFAST486_STATE State,
1104 PFAST486_MOD_REG_RM ModRegRm,
1105 BOOLEAN WriteRegister,
1108 FAST486_SEG_REGS Segment = FAST486_REG_DS;
1112 /* Store the value in the register */
1113 State->GeneralRegs[ModRegRm->Register].LowWord = Value;
1117 if (!ModRegRm->Memory)
1119 /* Store the value in the second register */
1120 State->GeneralRegs[ModRegRm->SecondRegister].LowWord = Value;
1124 /* Check for the segment override */
1125 if (State->PrefixFlags & FAST486_PREFIX_SEG)
1127 /* Use the override segment instead */
1128 Segment = State->SegmentOverride;
1132 if (!Fast486WriteMemory(State,
1134 ModRegRm->MemoryAddress,
1138 /* Exception occurred */
1149 Fast486WriteModrmDwordOperands(PFAST486_STATE State,
1150 PFAST486_MOD_REG_RM ModRegRm,
1151 BOOLEAN WriteRegister,
1154 FAST486_SEG_REGS Segment = FAST486_REG_DS;
1158 /* Store the value in the register */
1159 State->GeneralRegs[ModRegRm->Register].Long = Value;
1163 if (!ModRegRm->Memory)
1165 /* Store the value in the second register */
1166 State->GeneralRegs[ModRegRm->SecondRegister].Long = Value;
1170 /* Check for the segment override */
1171 if (State->PrefixFlags & FAST486_PREFIX_SEG)
1173 /* Use the override segment instead */
1174 Segment = State->SegmentOverride;
1178 if (!Fast486WriteMemory(State,
1180 ModRegRm->MemoryAddress,
1184 /* Exception occurred */