2 * Fast486 386/486 CPU Emulation Library
5 * Copyright (C) 2013 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 /* DEFINES ********************************************************************/
29 #define SIGN_FLAG_BYTE 0x80
30 #define SIGN_FLAG_WORD 0x8000
31 #define SIGN_FLAG_LONG 0x80000000
32 #define REAL_MODE_FLAGS_MASK 0x17FD5
33 #define PROT_MODE_FLAGS_MASK 0x10DD5
35 /* Block size for string operations */
36 #define STRING_BLOCK_SIZE 4096
38 #define GET_SEGMENT_RPL(s) ((s) & 3)
39 #define GET_SEGMENT_INDEX(s) ((s) & 0xFFF8)
40 #define EXCEPTION_HAS_ERROR_CODE(x) (((x) == 8) || ((x) >= 10 && (x) <= 14))
42 #define NO_LOCK_PREFIX() if (State->PrefixFlags & FAST486_PREFIX_LOCK)\
44 Fast486Exception(State, FAST486_EXCEPTION_UD);\
47 #define TOGGLE_OPSIZE(x) if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)\
51 #define TOGGLE_ADSIZE(x) if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)\
55 #define SWAP(x, y) { (x) ^= (y); (y) ^= (x); (x) ^= (y); }
57 #define PAGE_ALIGN(x) ((x) & 0xFFFFF000)
58 #define PAGE_OFFSET(x) ((x) & 0x00000FFF)
61 #define PAGE_SIZE 4096
64 typedef struct _FAST486_MOD_REG_RM
66 FAST486_GEN_REGS Register
;
70 FAST486_GEN_REGS SecondRegister
;
73 } FAST486_MOD_REG_RM
, *PFAST486_MOD_REG_RM
;
77 typedef union _FAST486_PAGE_DIR
84 ULONG WriteThrough
: 1;
90 ULONG TableAddress
: 20;
93 } FAST486_PAGE_DIR
, *PFAST486_PAGE_DIR
;
95 typedef union _FAST486_PAGE_TABLE
102 ULONG WriteThrough
: 1;
106 ULONG AlwaysZero
: 1;
112 } FAST486_PAGE_TABLE
, *PFAST486_PAGE_TABLE
;
116 /* FUNCTIONS ******************************************************************/
121 PFAST486_STATE State
,
122 FAST486_SEG_REGS SegmentReg
,
132 PFAST486_STATE State
,
133 FAST486_SEG_REGS SegmentReg
,
140 Fast486InterruptInternal
142 PFAST486_STATE State
,
143 USHORT SegmentSelector
,
145 BOOLEAN InterruptGate
150 Fast486ExceptionWithErrorCode
152 PFAST486_STATE State
,
153 FAST486_EXCEPTIONS ExceptionCode
,
157 /* INLINED FUNCTIONS **********************************************************/
159 /* static */ FORCEINLINE
161 Fast486GetCurrentPrivLevel(PFAST486_STATE State
)
163 return GET_SEGMENT_RPL(State
->SegmentRegs
[FAST486_REG_CS
].Selector
);
166 #include "common.inl"