From 1143eab8a54dd78aa42ccefeba78f2e77cee86fd Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Wed, 28 Aug 2013 17:52:21 +0000 Subject: [PATCH] [SOFT386] Implement short conditional jump opcodes. svn path=/branches/ntvdm/; revision=59856 --- lib/soft386/opcodes.c | 124 ++++++++++++++++++++++++++++++++++++------ lib/soft386/opcodes.h | 8 +++ 2 files changed, 116 insertions(+), 16 deletions(-) diff --git a/lib/soft386/opcodes.c b/lib/soft386/opcodes.c index 6a9331a6670..3460e03abe4 100644 --- a/lib/soft386/opcodes.c +++ b/lib/soft386/opcodes.c @@ -136,22 +136,22 @@ Soft386OpcodeHandlers[SOFT386_NUM_OPCODE_HANDLERS] = NULL, // TODO: OPCODE 0x6D NOT SUPPORTED NULL, // TODO: OPCODE 0x6E NOT SUPPORTED NULL, // TODO: OPCODE 0x6F NOT SUPPORTED - NULL, // TODO: OPCODE 0x70 NOT SUPPORTED - NULL, // TODO: OPCODE 0x71 NOT SUPPORTED - NULL, // TODO: OPCODE 0x72 NOT SUPPORTED - NULL, // TODO: OPCODE 0x73 NOT SUPPORTED - NULL, // TODO: OPCODE 0x74 NOT SUPPORTED - NULL, // TODO: OPCODE 0x75 NOT SUPPORTED - NULL, // TODO: OPCODE 0x76 NOT SUPPORTED - NULL, // TODO: OPCODE 0x77 NOT SUPPORTED - NULL, // TODO: OPCODE 0x78 NOT SUPPORTED - NULL, // TODO: OPCODE 0x79 NOT SUPPORTED - NULL, // TODO: OPCODE 0x7A NOT SUPPORTED - NULL, // TODO: OPCODE 0x7B NOT SUPPORTED - NULL, // TODO: OPCODE 0x7C NOT SUPPORTED - NULL, // TODO: OPCODE 0x7D NOT SUPPORTED - NULL, // TODO: OPCODE 0x7E NOT SUPPORTED - NULL, // TODO: OPCODE 0x7F NOT SUPPORTED + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, + Soft386OpcodeShortConditionalJmp, NULL, // TODO: OPCODE 0x80 NOT SUPPORTED NULL, // TODO: OPCODE 0x81 NOT SUPPORTED NULL, // TODO: OPCODE 0x82 NOT SUPPORTED @@ -648,3 +648,95 @@ Soft386OpcodeExchangeEax(PSOFT386_STATE State, UCHAR Opcode) return TRUE; } + +BOOLEAN +FASTCALL +Soft386OpcodeShortConditionalJmp(PSOFT386_STATE State, UCHAR Opcode) +{ + BOOLEAN Jump = FALSE; + CHAR Offset = 0; + + /* Make sure this is the right instruction */ + ASSERT((Opcode & 0xF0) == 0x70); + + /* Fetch the offset */ + if (!Soft386FetchByte(State, (PUCHAR)&Offset)) + { + /* An exception occurred */ + return FALSE; + } + + switch ((Opcode & 0x0F) >> 1) + { + /* JO / JNO */ + case 0: + { + Jump = State->Flags.Of; + break; + } + + /* JC / JNC */ + case 1: + { + Jump = State->Flags.Cf; + break; + } + + /* JZ / JNZ */ + case 2: + { + Jump = State->Flags.Zf; + break; + } + + /* JBE / JNBE */ + case 3: + { + Jump = State->Flags.Cf || State->Flags.Zf; + break; + } + + /* JS / JNS */ + case 4: + { + Jump = State->Flags.Sf; + break; + } + + /* JP / JNP */ + case 5: + { + Jump = State->Flags.Pf; + break; + } + + /* JL / JNL */ + case 6: + { + Jump = State->Flags.Sf != State->Flags.Of; + break; + } + + /* JLE / JNLE */ + case 7: + { + Jump = (State->Flags.Sf != State->Flags.Of) || State->Flags.Zf; + break; + } + } + + if ((Opcode & 0xF0) & 1) + { + /* Invert the result */ + Jump = !Jump; + } + + if (Jump) + { + /* Move the instruction pointer */ + State->InstPtr.Long += Offset; + } + + /* Return success */ + return TRUE; +} diff --git a/lib/soft386/opcodes.h b/lib/soft386/opcodes.h index 17688735f08..663fd4fbbda 100644 --- a/lib/soft386/opcodes.h +++ b/lib/soft386/opcodes.h @@ -79,4 +79,12 @@ Soft386OpcodeExchangeEax UCHAR Opcode ); +BOOLEAN +FASTCALL +Soft386OpcodeShortConditionalJmp +( + PSOFT386_STATE State, + UCHAR Opcode +); + #endif // _OPCODES_H_