Author: hbelusca
Date: Wed Feb 26 01:03:14 2014
New Revision: 62331
URL:
http://svn.reactos.org/svn/reactos?rev=62331&view=rev
Log:
[NTVDM]
- Reduce the size of the trampoline needed to perform 32 ---> 16 bit callbacks.
- Fix some comments, improve DPRINTs.
Modified:
branches/ntvdm/subsystems/ntvdm/callback.c
branches/ntvdm/subsystems/ntvdm/callback.h
Modified: branches/ntvdm/subsystems/ntvdm/callback.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/callback…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/callback.c [iso-8859-1] Wed Feb 26 01:03:14 2014
@@ -33,9 +33,15 @@
#define BOP(num) LOBYTE(EMULATOR_BOP), HIBYTE(EMULATOR_BOP), (num)
-#define UnSimulate16 MAKELONG(EMULATOR_BOP, BOP_UNSIMULATE) //
BOP(BOP_UNSIMULATE)
-
-#define CALL16_TRAMPOLINE_SIZE (2 * sizeof(ULONGLONG))
+#define UnSimulate16(trap) \
+do { \
+ *(PUSHORT)(trap) = EMULATOR_BOP; \
+ (trap) += sizeof(USHORT); \
+ *(trap) = BOP_UNSIMULATE; \
+} while(0)
+// #define UnSimulate16 MAKELONG(EMULATOR_BOP, BOP_UNSIMULATE) //
BOP(BOP_UNSIMULATE)
+
+#define CALL16_TRAMPOLINE_SIZE (1 * sizeof(ULONGLONG))
#define INT16_TRAMPOLINE_SIZE (1 * sizeof(ULONGLONG))
/* 16-bit generic interrupt code for calling a 32-bit interrupt handler */
@@ -97,7 +103,7 @@
setCS(Segment);
setIP(Offset);
- DPRINT("Call16(0x%04X, 0x%04X)\n", Segment, Offset);
+ DPRINT("Call16(%04X:%04X)\n", Segment, Offset);
/* Start CPU simulation */
EmulatorSimulate();
@@ -146,23 +152,21 @@
UCHAR OldTrampoline[CALL16_TRAMPOLINE_SIZE];
/* Save the old trampoline */
- // RtlCopyMemory(OldTrampoline, TrampolineBase, sizeof(OldTrampoline));
((PULONGLONG)&OldTrampoline)[0] = ((PULONGLONG)TrampolineBase)[0];
- ((PULONGLONG)&OldTrampoline)[1] = ((PULONGLONG)TrampolineBase)[1];
-
- /* Build the generic entry-point for 32-bit calls */
+
+ DPRINT1("RunCallback16(0x%p)\n", FarPtr);
+
+ /* Build the generic entry-point for 16-bit far calls */
*Trampoline++ = 0x9A; // Call far seg:off
*(PULONG)Trampoline = FarPtr;
Trampoline += sizeof(ULONG);
- *(PULONG)Trampoline = UnSimulate16;
+ UnSimulate16(Trampoline);
/* Perform the call */
Call16(HIWORD(Context->TrampolineFarPtr),
LOWORD(Context->TrampolineFarPtr));
/* Restore the old trampoline */
- // RtlCopyMemory(TrampolineBase, OldTrampoline, sizeof(OldTrampoline));
- ((PULONGLONG)TrampolineBase)[1] = ((PULONGLONG)&OldTrampoline)[1];
((PULONGLONG)TrampolineBase)[0] = ((PULONGLONG)&OldTrampoline)[0];
}
@@ -228,10 +232,9 @@
DPRINT("Int32Call(0x%X)\n", IntNumber);
/* Save the old trampoline */
- // RtlCopyMemory(OldTrampoline, TrampolineBase, sizeof(OldTrampoline));
((PULONGLONG)&OldTrampoline)[0] = ((PULONGLONG)TrampolineBase)[0];
- /* Build the generic entry-point for 32-bit calls */
+ /* Build the generic entry-point for 16-bit calls */
if (IntNumber == 0x03)
{
/* We are redefining for INT 03h */
@@ -244,14 +247,13 @@
*Trampoline++ = 0xCD; // Call INT XXh
*Trampoline++ = IntNumber;
}
- *(PULONG)Trampoline = UnSimulate16;
+ UnSimulate16(Trampoline);
/* Perform the call */
Call16(HIWORD(Context->TrampolineFarPtr),
LOWORD(Context->TrampolineFarPtr));
/* Restore the old trampoline */
- // RtlCopyMemory(TrampolineBase, OldTrampoline, sizeof(OldTrampoline));
((PULONGLONG)TrampolineBase)[0] = ((PULONGLONG)&OldTrampoline)[0];
}
@@ -269,7 +271,7 @@
DPRINT1("Unhandled 32-bit interrupt: 0x%02X, AX = 0x%04X\n", IntNum,
getAX());
}
-VOID WINAPI ControlBop(LPWORD Stack)
+static VOID WINAPI ControlBop(LPWORD Stack)
{
/* Get the Function Number and skip it */
BYTE FuncNum = *(PBYTE)SEG_OFF_TO_PTR(getCS(), getIP());
Modified: branches/ntvdm/subsystems/ntvdm/callback.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/callback…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/callback.h [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/callback.h [iso-8859-1] Wed Feb 26 01:03:14 2014
@@ -36,7 +36,26 @@
IN USHORT Segment,
IN USHORT Offset);
-VOID WINAPI Int32Dispatch(LPWORD Stack);
+VOID
+Call16(IN USHORT Segment,
+ IN USHORT Offset);
+
+ULONG
+RegisterCallback16(IN ULONG FarPtr,
+ IN LPBYTE CallbackCode,
+ IN SIZE_T CallbackSize,
+ OUT PSIZE_T CodeSize OPTIONAL);
+
+VOID
+RunCallback16(IN PCALLBACK16 Context,
+ IN ULONG FarPtr);
+
+ULONG
+RegisterInt16(IN ULONG FarPtr,
+ IN BYTE IntNumber,
+ IN LPBYTE CallbackCode,
+ IN SIZE_T CallbackSize,
+ OUT PSIZE_T CodeSize OPTIONAL);
ULONG
RegisterInt32(IN ULONG FarPtr,
@@ -48,6 +67,7 @@
Int32Call(IN PCALLBACK16 Context,
IN BYTE IntNumber);
+VOID WINAPI Int32Dispatch(LPWORD Stack);
VOID InitializeCallbacks(VOID);
#endif // _CALLBACK_H_