From 81c27b5b19d822c25132392fbeadf430df050221 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Fri, 29 Nov 2013 03:00:59 +0000 Subject: [PATCH] [FAST486] Start implementing the FPU. Stubplement the FPU opcode handlers. svn path=/branches/ntvdm/; revision=61141 --- include/reactos/libs/fast486/fast486.h | 54 +++++++++++++ lib/fast486/CMakeLists.txt | 3 +- lib/fast486/fpu.c | 100 +++++++++++++++++++++++++ lib/fast486/fpu.h | 55 ++++++++++++++ lib/fast486/opcodes.c | 17 +++-- 5 files changed, 220 insertions(+), 9 deletions(-) create mode 100644 lib/fast486/fpu.c create mode 100644 lib/fast486/fpu.h diff --git a/include/reactos/libs/fast486/fast486.h b/include/reactos/libs/fast486/fast486.h index 3a7a608544d..ffeccf3ff0a 100644 --- a/include/reactos/libs/fast486/fast486.h +++ b/include/reactos/libs/fast486/fast486.h @@ -34,6 +34,7 @@ #define FAST486_NUM_SEG_REGS 6 #define FAST486_NUM_CTRL_REGS 3 #define FAST486_NUM_DBG_REGS 6 +#define FAST486_NUM_FPU_REGS 8 #define FAST486_CR0_PE (1 << 0) #define FAST486_CR0_MP (1 << 1) @@ -376,6 +377,55 @@ typedef struct _FAST486_TSS ULONG IopbOffset; } FAST486_TSS, *PFAST486_TSS; +typedef struct _FAST486_FPU_DATA_REG +{ + ULONGLONG Mantissa; + USHORT Exponent; +} FAST486_FPU_DATA_REG, *PFAST486_FPU_DATA_REG; + +typedef union _FAST486_FPU_STATUS_REG +{ + USHORT Value; + + struct + { + ULONG Ie : 1; + ULONG De : 1; + ULONG Ze : 1; + ULONG Oe : 1; + ULONG Ue : 1; + ULONG Pe : 1; + ULONG Sf : 1; + ULONG Es : 1; + ULONG Code0 : 1; + ULONG Code1 : 1; + ULONG Code2 : 1; + ULONG Top : 3; + ULONG Code3 : 1; + ULONG Busy : 1; + }; +} FAST486_FPU_STATUS_REG, *PFAST486_FPU_STATUS_REG; + +typedef union _FAST486_FPU_CONTROL_REG +{ + USHORT Value; + + struct + { + ULONG Im : 1; + ULONG Dm : 1; + ULONG Zm : 1; + ULONG Om : 1; + ULONG Um : 1; + ULONG Pm : 1; + ULONG Reserved : 2; + ULONG Pc : 2; + ULONG Rc : 2; + ULONG Inf : 1; + // ULONG Reserved1 : 3; + }; +} FAST486_FPU_CONTROL_REG, *PFAST486_FPU_CONTROL_REG; + struct _FAST486_STATE { FAST486_MEM_READ_PROC MemReadCallback; @@ -399,6 +449,10 @@ struct _FAST486_STATE FAST486_INT_STATUS IntStatus; UCHAR PendingIntNum; PULONG Tlb; + FAST486_FPU_DATA_REG FpuRegisters[FAST486_NUM_FPU_REGS]; + FAST486_FPU_STATUS_REG FpuStatus; + FAST486_FPU_CONTROL_REG FpuControl; + USHORT FpuTag; }; /* FUNCTIONS ******************************************************************/ diff --git a/lib/fast486/CMakeLists.txt b/lib/fast486/CMakeLists.txt index a25d370ddf9..2fbdb31586f 100644 --- a/lib/fast486/CMakeLists.txt +++ b/lib/fast486/CMakeLists.txt @@ -6,6 +6,7 @@ list(APPEND SOURCE opcodes.c opgroups.c extraops.c - common.c) + common.c + fpu.c) add_library(fast486 ${SOURCE}) diff --git a/lib/fast486/fpu.c b/lib/fast486/fpu.c new file mode 100644 index 00000000000..f071c38812a --- /dev/null +++ b/lib/fast486/fpu.c @@ -0,0 +1,100 @@ +/* + * Fast486 386/486 CPU Emulation Library + * fpu.c + * + * Copyright (C) 2013 Aleksandar Andrejevic + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/* INCLUDES *******************************************************************/ + +#include + +// #define NDEBUG +#include + +#include +#include "common.h" +#include "opcodes.h" +#include "fpu.h" + +/* PUBLIC FUNCTIONS ***********************************************************/ + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD8) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD9) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDA) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDB) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDC) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDD) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDF) +{ + // TODO: NOT IMPLEMENTED + UNIMPLEMENTED; + Fast486Exception(State, FAST486_EXCEPTION_UD); + return FALSE; +} + +/* EOF */ diff --git a/lib/fast486/fpu.h b/lib/fast486/fpu.h new file mode 100644 index 00000000000..370aab3975b --- /dev/null +++ b/lib/fast486/fpu.h @@ -0,0 +1,55 @@ +/* + * Fast486 386/486 CPU Emulation Library + * fpu.h + * + * Copyright (C) 2013 Aleksandar Andrejevic + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _FPU_H_ +#define _FPU_H_ + +#pragma once + +/* DEFINES ********************************************************************/ + +enum +{ + FPU_SINGLE_PRECISION = 0, + FPU_DOUBLE_PRECISION = 2, + FPU_DOUBLE_EXT_PRECISION = 3 +}; + +enum +{ + FPU_TAG_VALID = 0, + FPU_TAG_ZERO = 1, + FPU_TAG_SPECIAL = 2, + FPU_TAG_EMPTY = 3 +}; + +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD8); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeD9); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDA); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDB); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDC); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDD); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDE); +FAST486_OPCODE_HANDLER(Fast486FpuOpcodeDF); + +#endif // _FPU_H_ + +/* EOF */ diff --git a/lib/fast486/opcodes.c b/lib/fast486/opcodes.c index 52970d4439e..1d6016067a4 100644 --- a/lib/fast486/opcodes.c +++ b/lib/fast486/opcodes.c @@ -31,6 +31,7 @@ #include "opgroups.h" #include "extraops.h" #include "common.h" +#include "fpu.h" /* PUBLIC VARIABLES ***********************************************************/ @@ -253,14 +254,14 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] = Fast486OpcodeAad, Fast486OpcodeSalc, Fast486OpcodeXlat, - NULL, // TODO: OPCODE 0xD8 NOT SUPPORTED - NULL, // TODO: OPCODE 0xD9 NOT SUPPORTED - NULL, // TODO: OPCODE 0xDA NOT SUPPORTED - NULL, // TODO: OPCODE 0xDB NOT SUPPORTED - NULL, // TODO: OPCODE 0xDC NOT SUPPORTED - NULL, // TODO: OPCODE 0xDD NOT SUPPORTED - NULL, // TODO: OPCODE 0xDE NOT SUPPORTED - NULL, // TODO: OPCODE 0xDF NOT SUPPORTED + Fast486FpuOpcodeD8, + Fast486FpuOpcodeD9, + Fast486FpuOpcodeDA, + Fast486FpuOpcodeDB, + Fast486FpuOpcodeDC, + Fast486FpuOpcodeDD, + Fast486FpuOpcodeDE, + Fast486FpuOpcodeDF, Fast486OpcodeLoop, Fast486OpcodeLoop, Fast486OpcodeLoop, -- 2.17.1