ReactOS  0.4.14-dev-98-gb0d4763
common.h
Go to the documentation of this file.
1 /*
2  * Fast486 386/486 CPU Emulation Library
3  * common.h
4  *
5  * Copyright (C) 2015 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
6  *
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.
11  *
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.
16  *
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.
20  */
21 
22 #ifndef _COMMON_H_
23 #define _COMMON_H_
24 
25 #pragma once
26 
27 /* DEFINES ********************************************************************/
28 
29 #define SIGN_FLAG_BYTE 0x80
30 #define SIGN_FLAG_WORD 0x8000
31 #define SIGN_FLAG_LONG 0x80000000
32 #define REAL_MODE_FLAGS_MASK 0x57FD5
33 #define PROT_MODE_FLAGS_MASK 0x50DD5
34 
35 /* Block size for string operations */
36 #define STRING_BLOCK_SIZE 4096
37 
38 #define GET_SEGMENT_RPL(s) ((s) & 3u)
39 #define GET_SEGMENT_INDEX(s) ((s) & 0xFFF8u)
40 #define SEGMENT_TABLE_INDICATOR (1 << 2)
41 #define EXCEPTION_HAS_ERROR_CODE(x) (((x) == 8) || ((x) >= 10 && (x) <= 14))
42 
43 #define NO_LOCK_PREFIX()\
44 if (State->PrefixFlags & FAST486_PREFIX_LOCK)\
45 {\
46  Fast486Exception(State, FAST486_EXCEPTION_UD);\
47  return;\
48 }
49 
50 #define TOGGLE_OPSIZE(x)\
51  if (State->PrefixFlags & FAST486_PREFIX_OPSIZE) x = !x;
52 
53 #define TOGGLE_ADSIZE(x)\
54  if (State->PrefixFlags & FAST486_PREFIX_ADSIZE) x = !x;
55 
56 #define SWAP(x, y) { (x) ^= (y); (y) ^= (x); (x) ^= (y); }
57 
58 #define ALIGNMENT_CHECK(x, a) if (State->Flags.Ac \
59  && (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_AM)\
60  && (State->Cpl == 3)\
61  && (((x) % (a)) != 0))\
62 {\
63  Fast486Exception(State, FAST486_EXCEPTION_AC);\
64  return FALSE;\
65 }
66 
67 #define PAGE_ALIGN(x) ((x) & 0xFFFFF000)
68 #define PAGE_OFFSET(x) ((x) & 0x00000FFF)
69 #define GET_ADDR_PDE(x) ((x) >> 22)
70 #define GET_ADDR_PTE(x) (((x) >> 12) & 0x3FF)
71 #define INVALID_TLB_FIELD 0xFFFFFFFF
72 #define NUM_TLB_ENTRIES 0x100000
73 
74 typedef struct _FAST486_MOD_REG_RM
75 {
76  FAST486_GEN_REGS Register;
78  union
79  {
80  FAST486_GEN_REGS SecondRegister;
82  };
84 
86 {
91 
92 #include <pshpack1.h>
93 
94 typedef union _FAST486_PAGE_DIR
95 {
96  struct
97  {
105  ULONG Size : 1;
108  };
111 
112 C_ASSERT(sizeof(FAST486_PAGE_DIR) == sizeof(ULONG));
113 
114 typedef union _FAST486_PAGE_TABLE
115 {
116  struct
117  {
129  };
132 
133 C_ASSERT(sizeof(FAST486_PAGE_DIR) == sizeof(ULONG));
134 
135 #include <poppack.h>
136 
137 /* FUNCTIONS ******************************************************************/
138 
139 BOOLEAN
140 FASTCALL
142 (
143  PFAST486_STATE State,
144  FAST486_SEG_REGS SegmentReg,
145  ULONG Offset,
146  BOOLEAN InstFetch,
147  PVOID Buffer,
148  ULONG Size
149 );
150 
151 BOOLEAN
152 FASTCALL
154 (
155  PFAST486_STATE State,
156  FAST486_SEG_REGS SegmentReg,
157  ULONG Offset,
158  PVOID Buffer,
159  ULONG Size
160 );
161 
162 BOOLEAN
163 FASTCALL
165 (
166  PFAST486_STATE State,
167  UCHAR Number
168 );
169 
170 VOID
171 FASTCALL
173 (
174  PFAST486_STATE State,
175  FAST486_EXCEPTIONS ExceptionCode,
177 );
178 
179 BOOLEAN
180 FASTCALL
182 (
183  PFAST486_STATE State,
185  USHORT Selector
186 );
187 
188 BOOLEAN
189 FASTCALL
191 (
192  PFAST486_STATE State,
193  PFAST486_CALL_GATE Gate,
194  BOOLEAN Call
195 );
196 
197 /* INLINED FUNCTIONS **********************************************************/
198 
199 #include "common.inl"
200 
201 #endif // _COMMON_H_
202 
203 /* EOF */
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1782
VOID FASTCALL Fast486ExceptionWithErrorCode(PFAST486_STATE State, FAST486_EXCEPTIONS ExceptionCode, ULONG ErrorCode)
Definition: common.c:557
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
C_ASSERT(sizeof(FAST486_PAGE_DIR)==sizeof(ULONG))
Type
Definition: Type.h:6
BOOLEAN FASTCALL Fast486ReadMemory(PFAST486_STATE State, FAST486_SEG_REGS SegmentReg, ULONG Offset, BOOLEAN InstFetch, PVOID Buffer, ULONG Size)
Definition: common.c:36
BOOLEAN FASTCALL Fast486WriteMemory(PFAST486_STATE State, FAST486_SEG_REGS SegmentReg, ULONG Offset, PVOID Buffer, ULONG Size)
Definition: common.c:163
enum _FAST486_TASK_SWITCH_TYPE FAST486_TASK_SWITCH_TYPE
ULONG WriteThrough
Definition: common.h:101
BOOLEAN FASTCALL Fast486PerformInterrupt(PFAST486_STATE State, UCHAR Number)
Definition: common.c:533
ULONG Present
Definition: common.h:98
ULONG Accessed
Definition: common.h:103
_FAST486_TASK_SWITCH_TYPE
Definition: common.h:85
FAST486_GEN_REGS Register
Definition: common.h:76
#define FASTCALL
Definition: nt_native.h:50
ULONG TableAddress
Definition: common.h:107
BOOLEAN FASTCALL Fast486CallGate(PFAST486_STATE State, PFAST486_CALL_GATE Gate, BOOLEAN Call)
Definition: common.c:1116
struct _FAST486_MOD_REG_RM FAST486_MOD_REG_RM
enum _FAST486_TASK_SWITCH_TYPE * PFAST486_TASK_SWITCH_TYPE
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned char BOOLEAN
ULONG Writeable
Definition: common.h:99
ULONG AlwaysZero
Definition: common.h:104
Definition: bufpool.h:45
ULONG WriteThrough
Definition: common.h:121
struct _FAST486_MOD_REG_RM * PFAST486_MOD_REG_RM
union _FAST486_PAGE_TABLE FAST486_PAGE_TABLE
BOOLEAN FASTCALL Fast486TaskSwitch(PFAST486_STATE State, FAST486_TASK_SWITCH_TYPE Type, USHORT Selector)
Definition: common.c:624
FAST486_GEN_REGS SecondRegister
Definition: common.h:80
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
unsigned short USHORT
Definition: pedump.c:61
union _FAST486_PAGE_DIR * PFAST486_PAGE_DIR
ULONG Usermode
Definition: common.h:100
union _FAST486_PAGE_DIR FAST486_PAGE_DIR
unsigned int ULONG
Definition: retypes.h:1
ULONG MemoryAddress
Definition: common.h:81
union _FAST486_PAGE_TABLE * PFAST486_PAGE_TABLE
BOOLEAN Memory
Definition: common.h:77