[FAST486]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 19 Oct 2014 14:46:02 +0000 (14:46 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 19 Oct 2014 14:46:02 +0000 (14:46 +0000)
Implement the HLT instruction.
Remove the IdleCallback, since it's unused and probably won't be used.
(The load reduction will be implemented in NTVDM instead.)

svn path=/trunk/; revision=64823

reactos/include/reactos/libs/fast486/fast486.h
reactos/lib/fast486/fast486.c
reactos/lib/fast486/opcodes.c
reactos/subsystems/ntvdm/cpu/cpu.c

index d88f127..2606a35 100644 (file)
@@ -207,13 +207,6 @@ VOID
     UCHAR DataSize
 );
 
-typedef
-VOID
-(NTAPI *FAST486_IDLE_PROC)
-(
-    PFAST486_STATE State
-);
-
 typedef
 VOID
 (NTAPI *FAST486_BOP_PROC)
@@ -474,7 +467,6 @@ struct _FAST486_STATE
     FAST486_MEM_WRITE_PROC MemWriteCallback;
     FAST486_IO_READ_PROC IoReadCallback;
     FAST486_IO_WRITE_PROC IoWriteCallback;
-    FAST486_IDLE_PROC IdleCallback;
     FAST486_BOP_PROC BopCallback;
     FAST486_INT_ACK_PROC IntAckCallback;
     FAST486_REG GeneralRegs[FAST486_NUM_GEN_REGS];
@@ -490,6 +482,7 @@ struct _FAST486_STATE
     ULONG ExceptionCount;
     ULONG PrefixFlags;
     FAST486_SEG_REGS SegmentOverride;
+    BOOLEAN Halted;
     FAST486_INT_STATUS IntStatus;
     UCHAR PendingIntNum;
     PULONG Tlb;
@@ -510,7 +503,6 @@ Fast486Initialize(PFAST486_STATE         State,
                   FAST486_MEM_WRITE_PROC MemWriteCallback,
                   FAST486_IO_READ_PROC   IoReadCallback,
                   FAST486_IO_WRITE_PROC  IoWriteCallback,
-                  FAST486_IDLE_PROC      IdleCallback,
                   FAST486_BOP_PROC       BopCallback,
                   FAST486_INT_ACK_PROC   IntAckCallback,
                   PULONG                 Tlb);
index 21b2384..7725c9b 100644 (file)
@@ -55,28 +55,31 @@ Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command)
     do
     {
 NextInst:
-        /* Check if this is a new instruction */
-        if (State->PrefixFlags == 0) State->SavedInstPtr = State->InstPtr;
-
-        /* Perform an instruction fetch */
-        if (!Fast486FetchByte(State, &Opcode))
+        if (!State->Halted)
         {
-            /* Exception occurred */
-            State->PrefixFlags = 0;
-            continue;
-        }
+            /* Check if this is a new instruction */
+            if (State->PrefixFlags == 0) State->SavedInstPtr = State->InstPtr;
 
-        // TODO: Check for CALL/RET to update ProcedureCallCount.
+            /* Perform an instruction fetch */
+            if (!Fast486FetchByte(State, &Opcode))
+            {
+                /* Exception occurred */
+                State->PrefixFlags = 0;
+                continue;
+            }
 
-        /* Call the opcode handler */
-        CurrentHandler = Fast486OpcodeHandlers[Opcode];
-        CurrentHandler(State, Opcode);
+            // TODO: Check for CALL/RET to update ProcedureCallCount.
 
-        /* If this is a prefix, go to the next instruction immediately */
-        if (CurrentHandler == Fast486OpcodePrefix) goto NextInst;
+            /* Call the opcode handler */
+            CurrentHandler = Fast486OpcodeHandlers[Opcode];
+            CurrentHandler(State, Opcode);
 
-        /* A non-prefix opcode has been executed, reset the prefix flags */
-        State->PrefixFlags = 0;
+            /* If this is a prefix, go to the next instruction immediately */
+            if (CurrentHandler == Fast486OpcodePrefix) goto NextInst;
+
+            /* A non-prefix opcode has been executed, reset the prefix flags */
+            State->PrefixFlags = 0;
+        }
 
         /*
          * Check if there is an interrupt to execute, or a hardware interrupt signal
@@ -84,6 +87,9 @@ NextInst:
          */
         if (State->Flags.Tf)
         {
+            /* No longer halted */
+            State->Halted = FALSE;
+
             /* Perform the interrupt */
             Fast486PerformInterrupt(State, 0x01);
 
@@ -163,13 +169,6 @@ Fast486IoWriteCallback(PFAST486_STATE State, ULONG Port, PVOID Buffer, ULONG Dat
     UNREFERENCED_PARAMETER(DataSize);
 }
 
-static VOID
-NTAPI
-Fast486IdleCallback(PFAST486_STATE State)
-{
-    UNREFERENCED_PARAMETER(State);
-}
-
 static VOID
 NTAPI
 Fast486BopCallback(PFAST486_STATE State, UCHAR BopCode)
@@ -197,7 +196,6 @@ Fast486Initialize(PFAST486_STATE         State,
                   FAST486_MEM_WRITE_PROC MemWriteCallback,
                   FAST486_IO_READ_PROC   IoReadCallback,
                   FAST486_IO_WRITE_PROC  IoWriteCallback,
-                  FAST486_IDLE_PROC      IdleCallback,
                   FAST486_BOP_PROC       BopCallback,
                   FAST486_INT_ACK_PROC   IntAckCallback,
                   PULONG                 Tlb)
@@ -207,7 +205,6 @@ Fast486Initialize(PFAST486_STATE         State,
     State->MemWriteCallback = (MemWriteCallback ? MemWriteCallback : Fast486MemWriteCallback);
     State->IoReadCallback   = (IoReadCallback   ? IoReadCallback   : Fast486IoReadCallback  );
     State->IoWriteCallback  = (IoWriteCallback  ? IoWriteCallback  : Fast486IoWriteCallback );
-    State->IdleCallback     = (IdleCallback     ? IdleCallback     : Fast486IdleCallback    );
     State->BopCallback      = (BopCallback      ? BopCallback      : Fast486BopCallback     );
     State->IntAckCallback   = (IntAckCallback   ? IntAckCallback   : Fast486IntAckCallback  );
 
@@ -229,7 +226,6 @@ Fast486Reset(PFAST486_STATE State)
     FAST486_MEM_WRITE_PROC MemWriteCallback = State->MemWriteCallback;
     FAST486_IO_READ_PROC   IoReadCallback   = State->IoReadCallback;
     FAST486_IO_WRITE_PROC  IoWriteCallback  = State->IoWriteCallback;
-    FAST486_IDLE_PROC      IdleCallback     = State->IdleCallback;
     FAST486_BOP_PROC       BopCallback      = State->BopCallback;
     FAST486_INT_ACK_PROC   IntAckCallback   = State->IntAckCallback;
     PULONG                 Tlb              = State->Tlb;
@@ -283,7 +279,6 @@ Fast486Reset(PFAST486_STATE State)
     State->MemWriteCallback = MemWriteCallback;
     State->IoReadCallback   = IoReadCallback;
     State->IoWriteCallback  = IoWriteCallback;
-    State->IdleCallback     = IdleCallback;
     State->BopCallback      = BopCallback;
     State->IntAckCallback   = IntAckCallback;
     State->Tlb              = Tlb;
index a719988..cadbd54 100644 (file)
@@ -574,12 +574,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeNop)
 {
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
-    {
-        /* Idle cycle */
-        State->IdleCallback(State);
-    }
-
     return TRUE;
 }
 
@@ -895,7 +889,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeHalt)
     }
 
     /* Halt */
-    // TODO: Halt the CPU until an interrupt occurs, using IdleCallback if needed.
+    State->Halted = TRUE;
 
     /* Return success */
     return TRUE;
index d9c3940..7b56e08 100644 (file)
@@ -163,7 +163,6 @@ BOOLEAN CpuInitialize(VOID)
                       EmulatorWriteMemory,
                       EmulatorReadIo,
                       EmulatorWriteIo,
-                      NULL,
                       EmulatorBiosOperation,
                       EmulatorIntAcknowledge,
                       NULL /* TODO: Use a TLB */);