[SOFT386]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 22 Aug 2013 22:54:59 +0000 (22:54 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 22 Aug 2013 22:54:59 +0000 (22:54 +0000)
Halfplement Soft386ExecutionControl.

svn path=/branches/ntvdm/; revision=59795

lib/soft386/CMakeLists.txt
lib/soft386/opcodes.c [new file with mode: 0644]
lib/soft386/opcodes.h [new file with mode: 0644]
lib/soft386/soft386.c

index 2ae818e..2c065d7 100644 (file)
@@ -2,6 +2,7 @@ include_directories(${REACTOS_SOURCE_DIR}/include/reactos/libs/soft386)
 
 list(APPEND SOURCE
     soft386.c
+    opcodes.c
     common.c)
 
 add_library(soft386 ${SOURCE})
diff --git a/lib/soft386/opcodes.c b/lib/soft386/opcodes.c
new file mode 100644 (file)
index 0000000..8ff4ed2
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * COPYRIGHT:       GPL - See COPYING in the top level directory
+ * PROJECT:         386/486 CPU Emulation Library
+ * FILE:            opcodes.c
+ * PURPOSE:         Opcode handlers.
+ * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ */
+
+/* INCLUDES *******************************************************************/
+
+// #define WIN32_NO_STATUS
+// #define _INC_WINDOWS
+#include <windef.h>
+
+#include <soft386.h>
+#include "opcodes.h"
+#include "common.h"
+
+// #define NDEBUG
+#include <debug.h>
+
+/* PUBLIC VARIABLES ***********************************************************/
+
+SOFT386_OPCODE_HANDLER_PROC
+Soft386OpcodeHandlers[SOFT386_NUM_OPCODE_HANDLERS] =
+{
+    NULL
+};
diff --git a/lib/soft386/opcodes.h b/lib/soft386/opcodes.h
new file mode 100644 (file)
index 0000000..9377e29
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * COPYRIGHT:       GPL - See COPYING in the top level directory
+ * PROJECT:         386/486 CPU Emulation Library
+ * FILE:            opcodes.h
+ * PURPOSE:         Opcode handlers. (header file)
+ * PROGRAMMERS:     Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ */
+
+#ifndef _OPCODES_H_
+#define _OPCODES_H_
+
+/* DEFINES ********************************************************************/
+
+#define SOFT386_NUM_OPCODE_HANDLERS 256
+
+typedef BOOLEAN (__fastcall *SOFT386_OPCODE_HANDLER_PROC)(PSOFT386_STATE);
+
+extern
+SOFT386_OPCODE_HANDLER_PROC
+Soft386OpcodeHandlers[SOFT386_NUM_OPCODE_HANDLERS];
+
+#endif // _OPCODES_H_
index 040508a..4f74158 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <soft386.h>
 #include "common.h"
+#include "opcodes.h"
 
 // #define NDEBUG
 #include <debug.h>
@@ -36,8 +37,31 @@ VOID
 NTAPI
 Soft386ExecutionControl(PSOFT386_STATE State, INT Command)
 {
-    // TODO: NOT IMPLEMENTED!!!
-    UNIMPLEMENTED;
+    BYTE Opcode;
+    INT ProcedureCallCount = 0;
+
+    /* Main execution loop */
+    do
+    {
+        /* Perform an instruction fetch */
+        if (!Soft386FetchByte(State, &Opcode)) continue;
+
+        // TODO: Check for CALL/RET to update ProcedureCallCount.
+
+        if (Soft386OpcodeHandlers[Opcode] != NULL)
+        {
+            /* Call the opcode handler */
+            Soft386OpcodeHandlers[Opcode](State);
+        }
+        else
+        {
+            /* This is not a valid opcode */
+            Soft386Exception(State, SOFT386_EXCEPTION_UD);
+        }
+    }
+    while ((Command == SOFT386_CONTINUE)
+           || (Command == SOFT386_STEP_OVER && ProcedureCallCount > 0)
+           || (Command == SOFT386_STEP_OUT && ProcedureCallCount >= 0));
 }
 
 /* PUBLIC FUNCTIONS ***********************************************************/