ULONG DirConf : 1;
ULONG Executable : 1;
ULONG SystemType : 1;
+ ULONG Rpl : 2;
ULONG Dpl : 2;
ULONG Present : 1;
ULONG Size : 1;
return FALSE;
}
- if ((!InstFetch && (GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl))
+ if ((!InstFetch && (CachedDescriptor->Rpl > CachedDescriptor->Dpl))
|| (Fast486GetCurrentPrivLevel(State) > CachedDescriptor->Dpl))
{
Fast486Exception(State, FAST486_EXCEPTION_GP);
return FALSE;
}
- if ((GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl)
+ if ((CachedDescriptor->Rpl > CachedDescriptor->Dpl)
|| (Fast486GetCurrentPrivLevel(State) > CachedDescriptor->Dpl))
{
Fast486Exception(State, FAST486_EXCEPTION_GP);
Fast486InterruptInternal(PFAST486_STATE State,
USHORT SegmentSelector,
ULONG Offset,
- BOOLEAN InterruptGate)
+ ULONG GateType)
{
+ BOOLEAN GateSize = (GateType == FAST486_IDT_INT_GATE_32)
+ || (GateType == FAST486_IDT_TRAP_GATE_32);
+
/* Check for protected mode */
if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE)
{
FAST486_TSS Tss;
USHORT OldSs = State->SegmentRegs[FAST486_REG_SS].Selector;
ULONG OldEsp = State->GeneralRegs[FAST486_REG_ESP].Long;
+
+ if (GateSize != (State->SegmentRegs[FAST486_REG_CS].Size))
+ {
+ /*
+ * The gate size doesn't match the current operand size, so toggle
+ * the OPSIZE flag.
+ */
+ State->PrefixFlags ^= FAST486_PREFIX_OPSIZE;
+ }
/* Check if the interrupt handler is more privileged */
if (Fast486GetCurrentPrivLevel(State) > GET_SEGMENT_RPL(SegmentSelector))
/* Push the instruction pointer */
if (!Fast486StackPush(State, State->InstPtr.Long)) return FALSE;
- if (InterruptGate)
+ if ((GateType == FAST486_IDT_INT_GATE) || (GateType == FAST486_IDT_INT_GATE_32))
{
/* Disable interrupts after a jump to an interrupt gate handler */
State->Flags.If = FALSE;
return FALSE;
}
- if (State->SegmentRegs[FAST486_REG_CS].Size)
+ if (GateSize)
{
/* 32-bit code segment, use EIP */
State->InstPtr.Long = Offset;
PFAST486_STATE State,
USHORT SegmentSelector,
ULONG Offset,
- BOOLEAN InterruptGate
+ ULONG GateType
);
VOID
{
/* Loading a data segment */
- if (!GdtEntry.SystemType)
+ if (GET_SEGMENT_INDEX(Selector) != 0)
{
- /* This is a special descriptor */
- Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, Selector);
- return FALSE;
- }
+ if (!GdtEntry.SystemType)
+ {
+ /* This is a special descriptor */
+ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, Selector);
+ return FALSE;
+ }
- if ((GET_SEGMENT_RPL(Selector) > GdtEntry.Dpl)
- || (Fast486GetCurrentPrivLevel(State) > GdtEntry.Dpl))
- {
- Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, Selector);
- return FALSE;
- }
+ if ((GET_SEGMENT_RPL(Selector) > GdtEntry.Dpl)
+ || (Fast486GetCurrentPrivLevel(State) > GdtEntry.Dpl))
+ {
+ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, Selector);
+ return FALSE;
+ }
- if (!GdtEntry.Present)
+ if (!GdtEntry.Present)
+ {
+ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_NP, Selector);
+ return FALSE;
+ }
+ }
+ else
{
- Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_NP, Selector);
- return FALSE;
+ /* This is a NULL selector */
+ RtlZeroMemory(&GdtEntry, sizeof(GdtEntry));
}
}
CachedDescriptor->DirConf = GdtEntry.DirConf;
CachedDescriptor->Executable = GdtEntry.Executable;
CachedDescriptor->SystemType = GdtEntry.SystemType;
+ CachedDescriptor->Rpl = GET_SEGMENT_RPL(Selector);
CachedDescriptor->Dpl = GdtEntry.Dpl;
CachedDescriptor->Present = GdtEntry.Present;
CachedDescriptor->Size = GdtEntry.Size;
}
else
{
- USHORT Data;
+ SHORT Data;
- if (!Fast486FetchWord(State, &Data))
+ if (!Fast486FetchWord(State, (PUSHORT)&Data))
{
/* Exception occurred */
return FALSE;
FAST486_OPCODE_HANDLER(Fast486OpcodePushByteImm)
{
- UCHAR Data;
+ CHAR Data;
/* Make sure this is the right instruction */
ASSERT(Opcode == 0x6A);
- if (!Fast486FetchByte(State, &Data))
+ if (!Fast486FetchByte(State, (PUCHAR)&Data))
{
/* Exception occurred */
return FALSE;
{
UCHAR TableReg[6];
FAST486_MOD_REG_RM ModRegRm;
- BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
+ BOOLEAN OperandSize, AddressSize;
FAST486_SEG_REGS Segment = FAST486_REG_DS;
+ OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
+
NO_LOCK_PREFIX();
+ TOGGLE_OPSIZE(OperandSize);
TOGGLE_ADSIZE(AddressSize);
if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
State->Gdtr.Size = *((PUSHORT)TableReg);
State->Gdtr.Address = *((PULONG)&TableReg[sizeof(USHORT)]);
+ /* In 16-bit mode the highest byte is masked out */
+ if (!OperandSize) State->Gdtr.Address &= 0x00FFFFFF;
+
return TRUE;
}
State->Idtr.Size = *((PUSHORT)TableReg);
State->Idtr.Address = *((PULONG)&TableReg[sizeof(USHORT)]);
+ /* In 16-bit mode the highest byte is masked out */
+ if (!OperandSize) State->Idtr.Address &= 0x00FFFFFF;
+
return TRUE;
}
/* Set the final zero */
*(DestBuffer++) = 0;
+ /* Store the special program name tag */
+ *(DestBuffer++) = LOWORD(DOS_PROGRAM_NAME_TAG);
+ *(DestBuffer++) = HIWORD(DOS_PROGRAM_NAME_TAG);
+
/* Copy the program name after the environment block */
strcpy(DestBuffer, ProgramName);
#define DOS_DIR_LENGTH 64
#define NUM_DRIVES ('Z' - 'A' + 1)
#define DOS_CHAR_ATTRIBUTE 0x07
+#define DOS_PROGRAM_NAME_TAG 0x0001
enum DOS_ALLOC_STRATEGY
{