ReactOS  0.4.14-dev-114-gc8cbd56
callback.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "callback.h"
#include "cpu.h"
#include "bop.h"
#include <isvbop.h>
Include dependency graph for callback.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID InitializeContextEx (IN PCALLBACK16 Context, IN ULONG TrampolineSize, IN USHORT Segment, IN USHORT Offset)
 
VOID InitializeContext (IN PCALLBACK16 Context, IN USHORT Segment, IN USHORT Offset)
 
VOID Call16 (IN USHORT Segment, IN USHORT Offset)
 
VOID RunCallback16 (IN PCALLBACK16 Context, IN ULONG FarPtr)
 
ULONG RegisterCallback16 (IN ULONG FarPtr, IN LPBYTE CallbackCode, IN SIZE_T CallbackSize, OUT PSIZE_T CodeSize OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 22 of file callback.c.

Function Documentation

◆ Call16()

VOID Call16 ( IN USHORT  Segment,
IN USHORT  Offset 
)

Definition at line 71 of file callback.c.

73 {
74  /* Save CS:IP */
75  USHORT OrgCS = getCS();
76  USHORT OrgIP = getIP();
77 
78  /* Set the new CS:IP */
79  setCS(Segment);
80  setIP(Offset);
81 
82  DPRINT("Call16(%04X:%04X)\n", Segment, Offset);
83 
84  /* Start CPU simulation */
85  CpuSimulate();
86 
87  /* Restore CS:IP */
88  setCS(OrgCS);
89  setIP(OrgIP);
90 }
VOID WINAPI setIP(USHORT)
Definition: registers.c:471
VOID CpuSimulate(VOID)
Definition: cpu.c:167
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PVOID Segment
Definition: exfuncs.h:893
USHORT WINAPI getIP(VOID)
Definition: registers.c:464
VOID WINAPI setCS(USHORT)
Definition: registers.c:487
unsigned short USHORT
Definition: pedump.c:61
USHORT WINAPI getCS(VOID)
Definition: registers.c:480

Referenced by Int32Call(), and RunCallback16().

◆ InitializeContext()

VOID InitializeContext ( IN PCALLBACK16  Context,
IN USHORT  Segment,
IN USHORT  Offset 
)

Definition at line 60 of file callback.c.

63 {
66  Segment,
67  Offset);
68 }
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PVOID Segment
Definition: exfuncs.h:893
VOID InitializeContextEx(IN PCALLBACK16 Context, IN ULONG TrampolineSize, IN USHORT Segment, IN USHORT Offset)
Definition: callback.c:48
#define TRAMPOLINE_SIZE
Definition: callback.h:24

Referenced by DosBootsectorInitialize(), DosKRNLInitialize(), DosMouseInitialize(), DosStart(), InitializeBiosInt32(), and KsCreateDefaultAllocatorEx().

◆ InitializeContextEx()

VOID InitializeContextEx ( IN PCALLBACK16  Context,
IN ULONG  TrampolineSize,
IN USHORT  Segment,
IN USHORT  Offset 
)

Definition at line 48 of file callback.c.

52 {
53  Context->TrampolineFarPtr = MAKELONG(Offset, Segment);
54  Context->TrampolineSize = max(TRAMPOLINE_SIZE, TrampolineSize);
55  Context->Segment = Segment;
56  Context->NextOffset = Offset + Context->TrampolineSize;
57 }
#define max(a, b)
Definition: svc.c:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define MAKELONG(a, b)
Definition: typedefs.h:248
_Inout_ PVOID Segment
Definition: exfuncs.h:893
#define TRAMPOLINE_SIZE
Definition: callback.h:24

Referenced by InitializeContext().

◆ RegisterCallback16()

ULONG RegisterCallback16 ( IN ULONG  FarPtr,
IN LPBYTE  CallbackCode,
IN SIZE_T  CallbackSize,
OUT PSIZE_T CodeSize  OPTIONAL 
)

Definition at line 120 of file callback.c.

124 {
125  LPBYTE CodeStart = (LPBYTE)FAR_POINTER(FarPtr);
126  LPBYTE Code = CodeStart;
127 
128  SIZE_T OurCodeSize = CallbackSize;
129 
130  if (CallbackCode == NULL) CallbackSize = 0;
131 
132  if (CallbackCode)
133  {
134  /* 16-bit interrupt code */
135  RtlCopyMemory(Code, CallbackCode, CallbackSize);
136  Code += CallbackSize;
137  }
138 
139  /* Return the real size of the code if needed */
140  if (CodeSize) *CodeSize = OurCodeSize; // == (ULONG_PTR)Code - (ULONG_PTR)CodeStart;
141 
142  // /* Return the entry-point address for 32-bit calls */
143  // return (ULONG_PTR)(CodeStart + CallbackSize);
144  return OurCodeSize;
145 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define FAR_POINTER(x)
Definition: emulator.h:31
#define Code
Definition: deflate.h:80
ULONG_PTR SIZE_T
Definition: typedefs.h:78

Referenced by RegisterInt16().

◆ RunCallback16()

VOID RunCallback16 ( IN PCALLBACK16  Context,
IN ULONG  FarPtr 
)

Definition at line 93 of file callback.c.

95 {
96  PUCHAR TrampolineBase = (PUCHAR)FAR_POINTER(Context->TrampolineFarPtr);
97  PUCHAR Trampoline = TrampolineBase;
98  UCHAR OldTrampoline[TRAMPOLINE_SIZE];
99 
100  /* Save the old trampoline */
101  ((PULONGLONG)&OldTrampoline)[0] = ((PULONGLONG)TrampolineBase)[0];
102 
103  DPRINT("RunCallback16(0x%p)\n", FarPtr);
104 
105  /* Build the generic entry-point for 16-bit far calls */
106  *Trampoline++ = 0x9A; // Call far seg:off
107  *(PULONG)Trampoline = FarPtr;
108  Trampoline += sizeof(ULONG);
109  UnSimulate16(Trampoline);
110 
111  /* Perform the call */
112  Call16(HIWORD(Context->TrampolineFarPtr),
113  LOWORD(Context->TrampolineFarPtr));
114 
115  /* Restore the old trampoline */
116  ((PULONGLONG)TrampolineBase)[0] = ((PULONGLONG)&OldTrampoline)[0];
117 }
unsigned char * PUCHAR
Definition: retypes.h:3
void DPRINT(...)
Definition: polytest.cpp:61
#define FAR_POINTER(x)
Definition: emulator.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int * PULONG
Definition: retypes.h:1
#define UnSimulate16(trap)
Definition: callback.h:16
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
#define TRAMPOLINE_SIZE
Definition: callback.h:24
VOID Call16(IN USHORT Segment, IN USHORT Offset)
Definition: callback.c:71
#define LOWORD(l)
Definition: pedump.c:82

Referenced by BiosMouseIrq(), CallMouseUserHandlers(), DosCallDriver(), and InitRomRange().