From 675c38e1b90eee72adcf5e62821f446809600c08 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Thu, 22 Aug 2013 22:54:59 +0000 Subject: [PATCH] [SOFT386] Halfplement Soft386ExecutionControl. svn path=/branches/ntvdm/; revision=59795 --- lib/soft386/CMakeLists.txt | 1 + lib/soft386/opcodes.c | 28 ++++++++++++++++++++++++++++ lib/soft386/opcodes.h | 22 ++++++++++++++++++++++ lib/soft386/soft386.c | 28 ++++++++++++++++++++++++++-- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 lib/soft386/opcodes.c create mode 100644 lib/soft386/opcodes.h diff --git a/lib/soft386/CMakeLists.txt b/lib/soft386/CMakeLists.txt index 2ae818ee9ee..2c065d7f490 100644 --- a/lib/soft386/CMakeLists.txt +++ b/lib/soft386/CMakeLists.txt @@ -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 index 00000000000..8ff4ed217f9 --- /dev/null +++ b/lib/soft386/opcodes.c @@ -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 + */ + +/* INCLUDES *******************************************************************/ + +// #define WIN32_NO_STATUS +// #define _INC_WINDOWS +#include + +#include +#include "opcodes.h" +#include "common.h" + +// #define NDEBUG +#include + +/* 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 index 00000000000..9377e29f0b5 --- /dev/null +++ b/lib/soft386/opcodes.h @@ -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 + */ + +#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_ diff --git a/lib/soft386/soft386.c b/lib/soft386/soft386.c index 040508a4aaa..4f74158cdaa 100644 --- a/lib/soft386/soft386.c +++ b/lib/soft386/soft386.c @@ -14,6 +14,7 @@ #include #include "common.h" +#include "opcodes.h" // #define NDEBUG #include @@ -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 ***********************************************************/