2 * Fast486 386/486 CPU Emulation Library
5 * Copyright (C) 2015 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.
22 /* INCLUDES *******************************************************************/
32 /* PUBLIC FUNCTIONS ***********************************************************/
35 Fast486ReadMemory(PFAST486_STATE State
,
36 FAST486_SEG_REGS SegmentReg
,
43 PFAST486_SEG_REG CachedDescriptor
;
45 ASSERT(SegmentReg
< FAST486_NUM_SEG_REGS
);
47 /* Get the cached descriptor */
48 CachedDescriptor
= &State
->SegmentRegs
[SegmentReg
];
50 if (InstFetch
|| !CachedDescriptor
->DirConf
)
52 if ((Offset
+ Size
- 1) > CachedDescriptor
->Limit
)
54 /* Read beyond limit */
55 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
61 if (Offset
< CachedDescriptor
->Limit
)
63 /* Read beyond limit */
64 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
69 /* Check for protected mode */
70 if (State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PE
)
72 /* Privilege checks */
74 if (!CachedDescriptor
->Present
)
76 Fast486Exception(State
, FAST486_EXCEPTION_NP
);
80 if ((!InstFetch
&& (CachedDescriptor
->Rpl
> CachedDescriptor
->Dpl
))
81 || (Fast486GetCurrentPrivLevel(State
) > CachedDescriptor
->Dpl
))
83 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
89 if (!CachedDescriptor
->Executable
)
91 /* Data segment not executable */
92 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
98 if (CachedDescriptor
->Executable
&& (!CachedDescriptor
->ReadWrite
))
100 /* Code segment not readable */
101 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
107 /* Find the linear address */
108 LinearAddress
= CachedDescriptor
->Base
+ Offset
;
110 #ifndef FAST486_NO_PREFETCH
111 if (InstFetch
&& ((Offset
+ FAST486_CACHE_SIZE
- 1) <= CachedDescriptor
->Limit
))
113 State
->PrefetchAddress
= LinearAddress
;
115 if ((State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PG
)
116 && (PAGE_OFFSET(State
->PrefetchAddress
) > (FAST486_PAGE_SIZE
- FAST486_CACHE_SIZE
)))
118 /* We mustn't prefetch across a page boundary */
119 State
->PrefetchAddress
= PAGE_ALIGN(State
->PrefetchAddress
)
120 | (FAST486_PAGE_SIZE
- FAST486_CACHE_SIZE
);
122 if ((LinearAddress
- State
->PrefetchAddress
+ Size
) >= FAST486_CACHE_SIZE
)
124 /* We can't prefetch without possibly violating page permissions */
125 State
->PrefetchValid
= FALSE
;
126 return Fast486ReadLinearMemory(State
, LinearAddress
, Buffer
, Size
);
131 if (Fast486ReadLinearMemory(State
,
132 State
->PrefetchAddress
,
133 State
->PrefetchCache
,
136 State
->PrefetchValid
= TRUE
;
138 RtlMoveMemory(Buffer
,
139 &State
->PrefetchCache
[LinearAddress
- State
->PrefetchAddress
],
145 State
->PrefetchValid
= FALSE
;
152 /* Read from the linear address */
153 return Fast486ReadLinearMemory(State
, LinearAddress
, Buffer
, Size
);
158 Fast486WriteMemory(PFAST486_STATE State
,
159 FAST486_SEG_REGS SegmentReg
,
165 PFAST486_SEG_REG CachedDescriptor
;
167 ASSERT(SegmentReg
< FAST486_NUM_SEG_REGS
);
169 /* Get the cached descriptor */
170 CachedDescriptor
= &State
->SegmentRegs
[SegmentReg
];
172 if (!CachedDescriptor
->DirConf
)
174 if ((Offset
+ Size
- 1) > CachedDescriptor
->Limit
)
176 /* Write beyond limit */
177 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
183 if (Offset
< CachedDescriptor
->Limit
)
185 /* Read beyond limit */
186 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
191 /* Check for protected mode */
192 if (State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PE
)
194 /* Privilege checks */
196 if (!CachedDescriptor
->Present
)
198 Fast486Exception(State
, FAST486_EXCEPTION_NP
);
202 if ((CachedDescriptor
->Rpl
> CachedDescriptor
->Dpl
)
203 || (Fast486GetCurrentPrivLevel(State
) > CachedDescriptor
->Dpl
))
205 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
209 if (CachedDescriptor
->Executable
)
211 /* Code segment not writable */
212 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
215 else if (!CachedDescriptor
->ReadWrite
)
217 /* Data segment not writeable */
218 Fast486Exception(State
, FAST486_EXCEPTION_GP
);
223 /* Find the linear address */
224 LinearAddress
= CachedDescriptor
->Base
+ Offset
;
226 #ifndef FAST486_NO_PREFETCH
227 if (State
->PrefetchValid
228 && (LinearAddress
>= State
->PrefetchAddress
)
229 && ((LinearAddress
+ Size
) <= (State
->PrefetchAddress
+ FAST486_CACHE_SIZE
)))
231 /* Update the prefetch */
232 RtlMoveMemory(&State
->PrefetchCache
[LinearAddress
- State
->PrefetchAddress
],
234 min(Size
, FAST486_CACHE_SIZE
+ State
->PrefetchAddress
- LinearAddress
));
238 /* Write to the linear address */
239 return Fast486WriteLinearMemory(State
, LinearAddress
, Buffer
, Size
);
242 static inline BOOLEAN
244 Fast486GetIntVector(PFAST486_STATE State
,
246 PFAST486_IDT_ENTRY IdtEntry
)
248 /* Check for protected mode */
249 if (State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PE
)
251 /* Read from the IDT */
252 if (!Fast486ReadLinearMemory(State
,
254 + Number
* sizeof(*IdtEntry
),
258 /* Exception occurred */
264 /* Read from the real-mode IVT */
267 /* Paging is always disabled in real mode */
268 State
->MemReadCallback(State
,
270 + Number
* sizeof(FarPointer
),
274 /* Fill a fake IDT entry */
275 IdtEntry
->Offset
= LOWORD(FarPointer
);
276 IdtEntry
->Selector
= HIWORD(FarPointer
);
278 IdtEntry
->Type
= FAST486_IDT_INT_GATE
;
279 IdtEntry
->Storage
= FALSE
;
281 IdtEntry
->Present
= TRUE
;
282 IdtEntry
->OffsetHigh
= 0;
288 static inline BOOLEAN
290 Fast486InterruptInternal(PFAST486_STATE State
,
291 PFAST486_IDT_ENTRY IdtEntry
,
292 BOOLEAN PushErrorCode
,
295 USHORT SegmentSelector
= IdtEntry
->Selector
;
296 ULONG Offset
= MAKELONG(IdtEntry
->Offset
, IdtEntry
->OffsetHigh
);
297 ULONG GateType
= IdtEntry
->Type
;
298 BOOLEAN GateSize
= (GateType
== FAST486_IDT_INT_GATE_32
) ||
299 (GateType
== FAST486_IDT_TRAP_GATE_32
);
301 BOOLEAN Success
= FALSE
;
302 ULONG OldPrefixFlags
= State
->PrefixFlags
;
304 /* Check for protected mode */
305 if (State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PE
)
308 USHORT OldSs
= State
->SegmentRegs
[FAST486_REG_SS
].Selector
;
309 ULONG OldEsp
= State
->GeneralRegs
[FAST486_REG_ESP
].Long
;
311 if (GateType
== FAST486_TASK_GATE_SIGNATURE
)
314 return Fast486TaskSwitch(State
, FAST486_TASK_CALL
, IdtEntry
->Selector
);
317 if (GateSize
!= (State
->SegmentRegs
[FAST486_REG_CS
].Size
))
319 /* The gate size doesn't match the current operand size, so set the OPSIZE flag. */
320 State
->PrefixFlags
|= FAST486_PREFIX_OPSIZE
;
323 /* Check if the interrupt handler is more privileged or if we're in V86 mode */
324 if ((Fast486GetCurrentPrivLevel(State
) > GET_SEGMENT_RPL(SegmentSelector
))
328 if (!Fast486ReadLinearMemory(State
,
333 /* Exception occurred */
337 /* Switch to the new privilege level */
338 State
->Cpl
= GET_SEGMENT_RPL(SegmentSelector
);
342 /* Clear the VM flag */
343 State
->Flags
.Vm
= FALSE
;
345 /* Push GS, FS, DS and ES */
346 if (!Fast486StackPush(State
, State
->SegmentRegs
[FAST486_REG_GS
].Selector
)) goto Cleanup
;
347 if (!Fast486StackPush(State
, State
->SegmentRegs
[FAST486_REG_FS
].Selector
)) goto Cleanup
;
348 if (!Fast486StackPush(State
, State
->SegmentRegs
[FAST486_REG_DS
].Selector
)) goto Cleanup
;
349 if (!Fast486StackPush(State
, State
->SegmentRegs
[FAST486_REG_ES
].Selector
)) goto Cleanup
;
351 /* Now load them with NULL selectors, since they are useless in protected mode */
352 if (!Fast486LoadSegment(State
, FAST486_REG_GS
, 0)) goto Cleanup
;
353 if (!Fast486LoadSegment(State
, FAST486_REG_FS
, 0)) goto Cleanup
;
354 if (!Fast486LoadSegment(State
, FAST486_REG_DS
, 0)) goto Cleanup
;
355 if (!Fast486LoadSegment(State
, FAST486_REG_ES
, 0)) goto Cleanup
;
358 /* Check the new (higher) privilege level */
363 if (!Fast486LoadSegment(State
, FAST486_REG_SS
, Tss
.Ss0
))
365 /* Exception occurred */
368 State
->GeneralRegs
[FAST486_REG_ESP
].Long
= Tss
.Esp0
;
375 if (!Fast486LoadSegment(State
, FAST486_REG_SS
, Tss
.Ss1
))
377 /* Exception occurred */
380 State
->GeneralRegs
[FAST486_REG_ESP
].Long
= Tss
.Esp1
;
387 if (!Fast486LoadSegment(State
, FAST486_REG_SS
, Tss
.Ss2
))
389 /* Exception occurred */
392 State
->GeneralRegs
[FAST486_REG_ESP
].Long
= Tss
.Esp2
;
399 /* Should never reach here! */
404 /* Push SS selector */
405 if (!Fast486StackPush(State
, OldSs
)) goto Cleanup
;
407 /* Push stack pointer */
408 if (!Fast486StackPush(State
, OldEsp
)) goto Cleanup
;
413 if (State
->SegmentRegs
[FAST486_REG_CS
].Size
)
415 /* Set OPSIZE, because INT always pushes 16-bit values in real mode */
416 State
->PrefixFlags
|= FAST486_PREFIX_OPSIZE
;
421 if (!Fast486StackPush(State
, State
->Flags
.Long
)) goto Cleanup
;
423 /* Push CS selector */
424 if (!Fast486StackPush(State
, State
->SegmentRegs
[FAST486_REG_CS
].Selector
)) goto Cleanup
;
426 /* Push the instruction pointer */
427 if (!Fast486StackPush(State
, State
->InstPtr
.Long
)) goto Cleanup
;
431 /* Push the error code */
432 if (!Fast486StackPush(State
, ErrorCode
))
434 /* An exception occurred */
439 if ((GateType
== FAST486_IDT_INT_GATE
) || (GateType
== FAST486_IDT_INT_GATE_32
))
441 /* Disable interrupts after a jump to an interrupt gate handler */
442 State
->Flags
.If
= FALSE
;
446 if (!Fast486LoadSegment(State
, FAST486_REG_CS
, SegmentSelector
))
448 /* An exception occurred during the jump */
454 /* 32-bit code segment, use EIP */
455 State
->InstPtr
.Long
= Offset
;
459 /* 16-bit code segment, use IP */
460 State
->InstPtr
.LowWord
= LOWORD(Offset
);
466 /* Restore the prefix flags */
467 State
->PrefixFlags
= OldPrefixFlags
;
474 Fast486PerformInterrupt(PFAST486_STATE State
,
477 FAST486_IDT_ENTRY IdtEntry
;
479 /* Get the interrupt vector */
480 if (!Fast486GetIntVector(State
, Number
, &IdtEntry
))
482 /* Exception occurred */
486 /* Perform the interrupt */
487 if (!Fast486InterruptInternal(State
, &IdtEntry
, FALSE
, 0))
489 /* Exception occurred */
498 Fast486ExceptionWithErrorCode(PFAST486_STATE State
,
499 FAST486_EXCEPTIONS ExceptionCode
,
502 FAST486_IDT_ENTRY IdtEntry
;
504 /* Increment the exception count */
505 State
->ExceptionCount
++;
507 /* Check if the exception occurred more than once */
508 if (State
->ExceptionCount
> 1)
510 /* Then this is a double fault */
511 ExceptionCode
= FAST486_EXCEPTION_DF
;
514 /* Check if this is a triple fault */
515 if (State
->ExceptionCount
== 3)
517 DPRINT("Fast486ExceptionWithErrorCode(%04X:%08X) -- Triple fault\n",
518 State
->SegmentRegs
[FAST486_REG_CS
].Selector
,
519 State
->InstPtr
.Long
);
526 /* Clear the prefix flags */
527 State
->PrefixFlags
= 0;
529 /* Restore the IP to the saved IP */
530 State
->InstPtr
= State
->SavedInstPtr
;
532 /* Get the interrupt vector */
533 if (!Fast486GetIntVector(State
, ExceptionCode
, &IdtEntry
))
536 * If this function failed, that means Fast486Exception
537 * was called again, so just return in this case.
542 /* Perform the interrupt */
543 if (!Fast486InterruptInternal(State
,
545 EXCEPTION_HAS_ERROR_CODE(ExceptionCode
)
546 && (State
->ControlRegisters
[FAST486_REG_CR0
] & FAST486_CR0_PE
),
550 * If this function failed, that means Fast486Exception
551 * was called again, so just return in this case.
556 /* Reset the exception count */
557 State
->ExceptionCount
= 0;
562 Fast486TaskSwitch(PFAST486_STATE State
, FAST486_TASK_SWITCH_TYPE Type
, USHORT Selector
)
568 FAST486_SYSTEM_DESCRIPTOR NewTssDescriptor
;
570 /* Read the old TSS */
571 if (!Fast486ReadLinearMemory(State
,
576 /* Exception occurred */
580 /* If this is a task return, use the linked previous selector */
581 if (Type
== FAST486_TASK_RETURN
) Selector
= LOWORD(OldTss
.Link
);
583 /* Make sure the entry exists in the GDT (not LDT!) */
584 if ((GET_SEGMENT_INDEX(Selector
) == 0)
585 || (Selector
& SEGMENT_TABLE_INDICATOR
)
586 || GET_SEGMENT_INDEX(Selector
) >= (State
->Gdtr
.Size
+ 1u))
588 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, Selector
);
592 /* Get the TSS descriptor from the GDT */
593 if (!Fast486ReadLinearMemory(State
,
594 State
->Gdtr
.Address
+ GET_SEGMENT_INDEX(Selector
),
596 sizeof(NewTssDescriptor
)))
598 /* Exception occurred */
602 if (!NewTssDescriptor
.Present
)
604 /* Incoming task TSS not present */
605 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_NP
, Selector
);
609 /* Calculate the linear address of the new TSS */
610 NewTssAddress
= NewTssDescriptor
.Base
;
611 NewTssAddress
|= NewTssDescriptor
.BaseMid
<< 16;
612 NewTssAddress
|= NewTssDescriptor
.BaseHigh
<< 24;
614 /* Calculate the limit of the new TSS */
615 NewTssLimit
= NewTssDescriptor
.Limit
| (NewTssDescriptor
.LimitHigh
<< 16);
617 if (NewTssDescriptor
.Granularity
)
620 NewTssLimit
|= 0x00000FFF;
623 if (NewTssLimit
< sizeof(FAST486_TSS
))
625 /* TSS limit too small */
626 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, Selector
);
631 * The incoming task shouldn't be busy if we're executing it as a
632 * new task, and it should be busy if we're returning to it.
634 if (((NewTssDescriptor
.Signature
!= FAST486_TSS_SIGNATURE
)
635 || (Type
== FAST486_TASK_RETURN
))
636 && ((NewTssDescriptor
.Signature
!= FAST486_BUSY_TSS_SIGNATURE
)
637 || (Type
!= FAST486_TASK_RETURN
)))
639 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_GP
, Selector
);
643 /* Read the new TSS */
644 if (!Fast486ReadLinearMemory(State
,
649 /* Exception occurred */
653 if (Type
!= FAST486_TASK_CALL
)
655 /* Clear the busy bit of the outgoing task */
656 FAST486_SYSTEM_DESCRIPTOR OldTssDescriptor
;
658 if (!Fast486ReadLinearMemory(State
,
660 + GET_SEGMENT_INDEX(State
->TaskReg
.Selector
),
662 sizeof(OldTssDescriptor
)))
664 /* Exception occurred */
668 OldTssDescriptor
.Signature
= FAST486_TSS_SIGNATURE
;
670 if (!Fast486WriteLinearMemory(State
,
672 + GET_SEGMENT_INDEX(State
->TaskReg
.Selector
),
674 sizeof(OldTssDescriptor
)))
676 /* Exception occurred */
683 NewTss
.Link
= State
->TaskReg
.Selector
;
686 /* Save the current task into the TSS */
687 OldTss
.Cr3
= State
->ControlRegisters
[FAST486_REG_CR3
];
688 OldTss
.Eip
= State
->InstPtr
.Long
;
689 OldTss
.Eflags
= State
->Flags
.Long
;
690 OldTss
.Eax
= State
->GeneralRegs
[FAST486_REG_EAX
].Long
;
691 OldTss
.Ecx
= State
->GeneralRegs
[FAST486_REG_ECX
].Long
;
692 OldTss
.Edx
= State
->GeneralRegs
[FAST486_REG_EDX
].Long
;
693 OldTss
.Ebx
= State
->GeneralRegs
[FAST486_REG_EBX
].Long
;
694 OldTss
.Esp
= State
->GeneralRegs
[FAST486_REG_ESP
].Long
;
695 OldTss
.Ebp
= State
->GeneralRegs
[FAST486_REG_EBP
].Long
;
696 OldTss
.Esi
= State
->GeneralRegs
[FAST486_REG_ESI
].Long
;
697 OldTss
.Edi
= State
->GeneralRegs
[FAST486_REG_EDI
].Long
;
698 OldTss
.Es
= State
->SegmentRegs
[FAST486_REG_ES
].Selector
;
699 OldTss
.Cs
= State
->SegmentRegs
[FAST486_REG_CS
].Selector
;
700 OldTss
.Ss
= State
->SegmentRegs
[FAST486_REG_SS
].Selector
;
701 OldTss
.Ds
= State
->SegmentRegs
[FAST486_REG_DS
].Selector
;
702 OldTss
.Fs
= State
->SegmentRegs
[FAST486_REG_FS
].Selector
;
703 OldTss
.Gs
= State
->SegmentRegs
[FAST486_REG_GS
].Selector
;
704 OldTss
.Ldtr
= State
->Ldtr
.Selector
;
706 /* Write back the old TSS */
707 if (!Fast486WriteLinearMemory(State
,
712 /* Exception occurred */
716 /* Mark the new task as busy */
717 NewTssDescriptor
.Signature
= FAST486_BUSY_TSS_SIGNATURE
;
719 /* Write back the new TSS descriptor */
720 if (!Fast486WriteLinearMemory(State
,
721 State
->Gdtr
.Address
+ GET_SEGMENT_INDEX(Selector
),
723 sizeof(NewTssDescriptor
)))
725 /* Exception occurred */
729 /* Set the task switch bit */
730 State
->ControlRegisters
[FAST486_REG_CR0
] |= FAST486_CR0_TS
;
732 /* Load the task register with the new values */
733 State
->TaskReg
.Selector
= Selector
;
734 State
->TaskReg
.Base
= NewTssAddress
;
735 State
->TaskReg
.Limit
= NewTssLimit
;
737 /* Change the page directory */
738 State
->ControlRegisters
[FAST486_REG_CR3
] = NewTss
.Cr3
;
741 if (State
->Tlb
) RtlZeroMemory(State
->Tlb
, NUM_TLB_ENTRIES
* sizeof(ULONG
));
744 State
->Cpl
= GET_SEGMENT_RPL(NewTss
.Cs
);
746 #ifndef FAST486_NO_PREFETCH
747 /* Context switching invalidates the prefetch */
748 State
->PrefetchValid
= FALSE
;
752 State
->Cpl
= GET_SEGMENT_RPL(NewTss
.Cs
);
754 /* Load the registers */
755 State
->InstPtr
.Long
= State
->SavedInstPtr
.Long
= NewTss
.Eip
;
756 State
->Flags
.Long
= NewTss
.Eflags
;
757 State
->GeneralRegs
[FAST486_REG_EAX
].Long
= NewTss
.Eax
;
758 State
->GeneralRegs
[FAST486_REG_ECX
].Long
= NewTss
.Ecx
;
759 State
->GeneralRegs
[FAST486_REG_EDX
].Long
= NewTss
.Edx
;
760 State
->GeneralRegs
[FAST486_REG_EBX
].Long
= NewTss
.Ebx
;
761 State
->GeneralRegs
[FAST486_REG_ESP
].Long
= NewTss
.Esp
;
762 State
->GeneralRegs
[FAST486_REG_EBP
].Long
= NewTss
.Ebp
;
763 State
->GeneralRegs
[FAST486_REG_ESI
].Long
= NewTss
.Esi
;
764 State
->GeneralRegs
[FAST486_REG_EDI
].Long
= NewTss
.Edi
;
766 /* Set the NT flag if nesting */
767 if (Type
== FAST486_TASK_CALL
) State
->Flags
.Nt
= TRUE
;
769 if (GET_SEGMENT_INDEX(NewTss
.Ldtr
) != 0)
772 FAST486_SYSTEM_DESCRIPTOR GdtEntry
;
774 if (NewTss
.Ldtr
& SEGMENT_TABLE_INDICATOR
)
776 /* This selector doesn't point to the GDT */
777 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, NewTss
.Ldtr
);
781 if (!Fast486ReadDescriptorEntry(State
,
784 (PFAST486_GDT_ENTRY
)&GdtEntry
))
786 /* Exception occurred */
792 /* Invalid selector */
793 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, NewTss
.Ldtr
);
797 if (GdtEntry
.Signature
!= FAST486_LDT_SIGNATURE
)
799 /* This is not an LDT descriptor */
800 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, NewTss
.Ldtr
);
804 if (!GdtEntry
.Present
)
806 Fast486ExceptionWithErrorCode(State
, FAST486_EXCEPTION_TS
, NewTss
.Ldtr
);
810 /* Update the LDTR */
811 State
->Ldtr
.Selector
= NewTss
.Ldtr
;
812 State
->Ldtr
.Base
= GdtEntry
.Base
| (GdtEntry
.BaseMid
<< 16) | (GdtEntry
.BaseHigh
<< 24);
813 State
->Ldtr
.Limit
= GdtEntry
.Limit
| (GdtEntry
.LimitHigh
<< 16);
815 if (GdtEntry
.Granularity
)
817 State
->Ldtr
.Limit
<<= 12;
818 State
->Ldtr
.Limit
|= 0x00000FFF;
823 /* The LDT of this task is empty */
824 RtlZeroMemory(&State
->Ldtr
, sizeof(State
->Ldtr
));
827 /* Load the new segments */
828 if (!Fast486LoadSegmentInternal(State
,
831 FAST486_EXCEPTION_TS
))
836 if (!Fast486LoadSegmentInternal(State
,
839 FAST486_EXCEPTION_TS
))
844 if (!Fast486LoadSegmentInternal(State
,
847 FAST486_EXCEPTION_TS
))
852 if (!Fast486LoadSegmentInternal(State
,
855 FAST486_EXCEPTION_TS
))
860 if (!Fast486LoadSegmentInternal(State
,
863 FAST486_EXCEPTION_TS
))
868 if (!Fast486LoadSegmentInternal(State
,
871 FAST486_EXCEPTION_TS
))