ReactOS 0.4.15-dev-8241-g63935f8
fast486.c File Reference
#include <windef.h>
#include <debug.h>
#include <fast486.h>
#include "common.h"
#include "opcodes.h"
#include "fpu.h"
Include dependency graph for fast486.c:

Go to the source code of this file.

Functions

static VOID FASTCALL Fast486MemReadCallback (PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
 
static VOID FASTCALL Fast486MemWriteCallback (PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
 
static VOID FASTCALL Fast486IoReadCallback (PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
 
static VOID FASTCALL Fast486IoWriteCallback (PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
 
static VOID FASTCALL Fast486BopCallback (PFAST486_STATE State, UCHAR BopCode)
 
static UCHAR FASTCALL Fast486IntAckCallback (PFAST486_STATE State)
 
static VOID FASTCALL Fast486FpuCallback (PFAST486_STATE State)
 
VOID NTAPI Fast486Initialize (PFAST486_STATE State, FAST486_MEM_READ_PROC MemReadCallback, FAST486_MEM_WRITE_PROC MemWriteCallback, FAST486_IO_READ_PROC IoReadCallback, FAST486_IO_WRITE_PROC IoWriteCallback, FAST486_BOP_PROC BopCallback, FAST486_INT_ACK_PROC IntAckCallback, FAST486_FPU_PROC FpuCallback, PULONG Tlb)
 
VOID NTAPI Fast486Reset (PFAST486_STATE State)
 
VOID NTAPI Fast486InterruptSignal (PFAST486_STATE State)
 
VOID NTAPI Fast486ExecuteAt (PFAST486_STATE State, USHORT Segment, ULONG Offset)
 
VOID NTAPI Fast486SetStack (PFAST486_STATE State, USHORT Segment, ULONG Offset)
 
VOID NTAPI Fast486SetSegment (PFAST486_STATE State, FAST486_SEG_REGS Segment, USHORT Selector)
 
VOID NTAPI Fast486Rewind (PFAST486_STATE State)
 

Function Documentation

◆ Fast486BopCallback()

static VOID FASTCALL Fast486BopCallback ( PFAST486_STATE  State,
UCHAR  BopCode 
)
static

Definition at line 76 of file fast486.c.

77{
80}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

Referenced by Fast486Initialize().

◆ Fast486ExecuteAt()

VOID NTAPI Fast486ExecuteAt ( PFAST486_STATE  State,
USHORT  Segment,
ULONG  Offset 
)

Definition at line 212 of file fast486.c.

213{
214 /* Load the new CS */
215 if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment))
216 {
217 /* An exception occurred, let the handler execute instead */
218 return;
219 }
220
221 /* Set the new IP */
222 State->InstPtr.Long = Offset;
223}
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PVOID Segment
Definition: exfuncs.h:1101

Referenced by CpuExecute(), and x86BiosCall().

◆ Fast486FpuCallback()

static VOID FASTCALL Fast486FpuCallback ( PFAST486_STATE  State)
static

Definition at line 94 of file fast486.c.

Referenced by Fast486Initialize().

◆ Fast486Initialize()

VOID NTAPI Fast486Initialize ( PFAST486_STATE  State,
FAST486_MEM_READ_PROC  MemReadCallback,
FAST486_MEM_WRITE_PROC  MemWriteCallback,
FAST486_IO_READ_PROC  IoReadCallback,
FAST486_IO_WRITE_PROC  IoWriteCallback,
FAST486_BOP_PROC  BopCallback,
FAST486_INT_ACK_PROC  IntAckCallback,
FAST486_FPU_PROC  FpuCallback,
PULONG  Tlb 
)

Definition at line 103 of file fast486.c.

112{
113 /* Set the callbacks (or use default ones if some are NULL) */
114 State->MemReadCallback = (MemReadCallback ? MemReadCallback : Fast486MemReadCallback );
115 State->MemWriteCallback = (MemWriteCallback ? MemWriteCallback : Fast486MemWriteCallback);
116 State->IoReadCallback = (IoReadCallback ? IoReadCallback : Fast486IoReadCallback );
117 State->IoWriteCallback = (IoWriteCallback ? IoWriteCallback : Fast486IoWriteCallback );
118 State->BopCallback = (BopCallback ? BopCallback : Fast486BopCallback );
119 State->IntAckCallback = (IntAckCallback ? IntAckCallback : Fast486IntAckCallback );
120 State->FpuCallback = (FpuCallback ? FpuCallback : Fast486FpuCallback );
121
122 /* Set the TLB (if given) */
123 State->Tlb = Tlb;
124
125 /* Reset the CPU */
127}
static VOID FASTCALL Fast486IoReadCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
Definition: fast486.c:54
static VOID FASTCALL Fast486MemReadCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: fast486.c:38
static VOID FASTCALL Fast486BopCallback(PFAST486_STATE State, UCHAR BopCode)
Definition: fast486.c:76
static VOID FASTCALL Fast486FpuCallback(PFAST486_STATE State)
Definition: fast486.c:94
static UCHAR FASTCALL Fast486IntAckCallback(PFAST486_STATE State)
Definition: fast486.c:84
static VOID FASTCALL Fast486MemWriteCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: fast486.c:46
VOID NTAPI Fast486Reset(PFAST486_STATE State)
Definition: fast486.c:131
static VOID FASTCALL Fast486IoWriteCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
Definition: fast486.c:65

Referenced by CpuInitialize(), and x86BiosCall().

◆ Fast486IntAckCallback()

static UCHAR FASTCALL Fast486IntAckCallback ( PFAST486_STATE  State)
static

Definition at line 84 of file fast486.c.

85{
87
88 /* Return something... defaulted to single-step interrupt */
89 return 0x01;
90}

Referenced by Fast486Initialize().

◆ Fast486InterruptSignal()

VOID NTAPI Fast486InterruptSignal ( PFAST486_STATE  State)

Definition at line 205 of file fast486.c.

206{
207 State->IntSignaled = TRUE;
208}
#define TRUE
Definition: types.h:120

Referenced by EmulatorInterruptSignal().

◆ Fast486IoReadCallback()

static VOID FASTCALL Fast486IoReadCallback ( PFAST486_STATE  State,
USHORT  Port,
PVOID  Buffer,
ULONG  DataCount,
UCHAR  DataSize 
)
static

Definition at line 54 of file fast486.c.

55{
59 UNREFERENCED_PARAMETER(DataCount);
61}
Definition: bufpool.h:45
CPPORT Port[4]
Definition: headless.c:35
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755

Referenced by Fast486Initialize().

◆ Fast486IoWriteCallback()

static VOID FASTCALL Fast486IoWriteCallback ( PFAST486_STATE  State,
USHORT  Port,
PVOID  Buffer,
ULONG  DataCount,
UCHAR  DataSize 
)
static

◆ Fast486MemReadCallback()

static VOID FASTCALL Fast486MemReadCallback ( PFAST486_STATE  State,
ULONG  Address,
PVOID  Buffer,
ULONG  Size 
)
static

Definition at line 38 of file fast486.c.

39{
42}
#define UlongToPtr(u)
Definition: config.h:106
static WCHAR Address[46]
Definition: ping.c:68
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by Fast486Initialize().

◆ Fast486MemWriteCallback()

static VOID FASTCALL Fast486MemWriteCallback ( PFAST486_STATE  State,
ULONG  Address,
PVOID  Buffer,
ULONG  Size 
)
static

Definition at line 46 of file fast486.c.

Referenced by Fast486Initialize().

◆ Fast486Reset()

VOID NTAPI Fast486Reset ( PFAST486_STATE  State)

Definition at line 131 of file fast486.c.

132{
133 FAST486_SEG_REGS i;
134
135 /* Save the callbacks and TLB */
136 FAST486_MEM_READ_PROC MemReadCallback = State->MemReadCallback;
137 FAST486_MEM_WRITE_PROC MemWriteCallback = State->MemWriteCallback;
138 FAST486_IO_READ_PROC IoReadCallback = State->IoReadCallback;
139 FAST486_IO_WRITE_PROC IoWriteCallback = State->IoWriteCallback;
140 FAST486_BOP_PROC BopCallback = State->BopCallback;
141 FAST486_INT_ACK_PROC IntAckCallback = State->IntAckCallback;
142 FAST486_FPU_PROC FpuCallback = State->FpuCallback;
143 PULONG Tlb = State->Tlb;
144
145 /* Clear the entire structure */
146 RtlZeroMemory(State, sizeof(*State));
147
148 /* Initialize the registers */
149 State->Flags.AlwaysSet = 1;
150 State->InstPtr.LowWord = 0xFFF0;
151
152 /* Set the CPL to 0 */
153 State->Cpl = 0;
154
155 /* Initialize segments */
156 for (i = 0; i < FAST486_NUM_SEG_REGS; i++)
157 {
158 State->SegmentRegs[i].Selector = 0;
159 State->SegmentRegs[i].Base = 0;
160 State->SegmentRegs[i].Limit = 0xFFFF;
161 State->SegmentRegs[i].Present = TRUE;
162 State->SegmentRegs[i].ReadWrite = TRUE;
163 State->SegmentRegs[i].Executable = FALSE;
164 State->SegmentRegs[i].DirConf = FALSE;
165 State->SegmentRegs[i].SystemType = 1; // Segment descriptor
166 State->SegmentRegs[i].Dpl = 0;
167 State->SegmentRegs[i].Size = FALSE; // 16-bit
168 }
169
170 /* Initialize the code segment */
171 State->SegmentRegs[FAST486_REG_CS].Executable = TRUE;
172 State->SegmentRegs[FAST486_REG_CS].Selector = 0xF000;
173 State->SegmentRegs[FAST486_REG_CS].Base = 0xFFFF0000;
174
175 /* Initialize the IDT */
176 State->Idtr.Size = 0x3FF;
177 State->Idtr.Address = 0;
178
179#ifndef FAST486_NO_FPU
180 /* Initialize CR0 */
181 State->ControlRegisters[FAST486_REG_CR0] |= FAST486_CR0_ET;
182
183 /* Initialize the FPU control and tag registers */
184 State->FpuControl.Value = FAST486_FPU_DEFAULT_CONTROL;
185 State->FpuStatus.Value = 0;
186 State->FpuTag = 0xFFFF;
187#endif
188
189 /* Restore the callbacks and TLB */
190 State->MemReadCallback = MemReadCallback;
191 State->MemWriteCallback = MemWriteCallback;
192 State->IoReadCallback = IoReadCallback;
193 State->IoWriteCallback = IoWriteCallback;
194 State->BopCallback = BopCallback;
195 State->IntAckCallback = IntAckCallback;
196 State->FpuCallback = FpuCallback;
197 State->Tlb = Tlb;
198
199 /* Flush the TLB */
200 Fast486FlushTlb(State);
201}
#define FALSE
Definition: types.h:117
#define FAST486_FPU_DEFAULT_CONTROL
Definition: fast486.h:105
#define FAST486_NUM_SEG_REGS
Definition: fast486.h:41
#define FAST486_CR0_ET
Definition: fast486.h:50
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by Fast486ExceptionWithErrorCode(), and Fast486Initialize().

◆ Fast486Rewind()

VOID NTAPI Fast486Rewind ( PFAST486_STATE  State)

Definition at line 252 of file fast486.c.

253{
254 /* This function is used when an instruction has been interrupted remotely */
255 State->PrefixFlags = 0;
256 State->InstPtr.Long = State->SavedInstPtr.Long;
257
258#ifndef FAST486_NO_PREFETCH
259 State->PrefetchValid = FALSE;
260#endif
261}

Referenced by CpuExceptionFilter().

◆ Fast486SetSegment()

VOID NTAPI Fast486SetSegment ( PFAST486_STATE  State,
FAST486_SEG_REGS  Segment,
USHORT  Selector 
)

Definition at line 242 of file fast486.c.

245{
246 /* Call the internal function */
247 Fast486LoadSegment(State, Segment, Selector);
248}

Referenced by setCS(), setDS(), setES(), setFS(), setGS(), and setSS().

◆ Fast486SetStack()

VOID NTAPI Fast486SetStack ( PFAST486_STATE  State,
USHORT  Segment,
ULONG  Offset 
)

Definition at line 227 of file fast486.c.

228{
229 /* Load the new SS */
230 if (!Fast486LoadSegment(State, FAST486_REG_SS, Segment))
231 {
232 /* An exception occurred, let the handler execute instead */
233 return;
234 }
235
236 /* Set the new SP */
237 State->GeneralRegs[FAST486_REG_ESP].Long = Offset;
238}

Referenced by setESP(), setSP(), and x86BiosCall().