summaryrefslogtreecommitdiffstats
path: root/private/mvdm/sim32
diff options
context:
space:
mode:
authorAdam <you@example.com>2020-05-17 05:51:50 +0200
committerAdam <you@example.com>2020-05-17 05:51:50 +0200
commite611b132f9b8abe35b362e5870b74bce94a1e58e (patch)
treea5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/mvdm/sim32
downloadNT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst
NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip
Diffstat (limited to 'private/mvdm/sim32')
-rw-r--r--private/mvdm/sim32/b.cmd2
-rw-r--r--private/mvdm/sim32/makefile6
-rw-r--r--private/mvdm/sim32/sim32.c367
-rw-r--r--private/mvdm/sim32/sim32.h122
-rw-r--r--private/mvdm/sim32/sources61
5 files changed, 558 insertions, 0 deletions
diff --git a/private/mvdm/sim32/b.cmd b/private/mvdm/sim32/b.cmd
new file mode 100644
index 000000000..58c1a1323
--- /dev/null
+++ b/private/mvdm/sim32/b.cmd
@@ -0,0 +1,2 @@
+@build -esfc -386 sim32
+@if exist c:\nt\bin\*.* if exist obj\i386\sim32.exe copy obj\i386\sim32.exe c:\nt\bin
diff --git a/private/mvdm/sim32/makefile b/private/mvdm/sim32/makefile
new file mode 100644
index 000000000..6ee4f43fa
--- /dev/null
+++ b/private/mvdm/sim32/makefile
@@ -0,0 +1,6 @@
+#
+# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
+# file to this component. This file merely indirects to the real make file
+# that is shared by all the components of NT OS/2
+#
+!INCLUDE $(NTMAKEENV)\makefile.def
diff --git a/private/mvdm/sim32/sim32.c b/private/mvdm/sim32/sim32.c
new file mode 100644
index 000000000..6028c6a83
--- /dev/null
+++ b/private/mvdm/sim32/sim32.c
@@ -0,0 +1,367 @@
+#include <nt.h>
+#include <ntddtx.h>
+#include <malloc.h>
+
+#include "sim32.h"
+
+UCHAR TransmitPkt[MAXSIZE];
+UCHAR ReceivePkt[MAXSIZE];
+
+HANDLE DeviceHandle;
+IO_STATUS_BLOCK IoStatusBlock;
+NTSTATUS Status;
+
+
+/*****************************************************************************
+*
+* Sim32GetVDMMemory
+*
+* This routine gets 'Size' bytes from WOW VDM starting at address
+* specified by 'Address'. These bytes are returned to the caller in
+* the Buffer (which is owned by the caller).
+*
+*****************************************************************************/
+
+
+USHORT Sim32GetVDMMemory (IN ULONG Address,
+ IN USHORT Size,
+ IN OUT PVOID Buffer)
+
+{
+ if (Size < MAXSIZE-11) {
+ TransmitPkt[0] = SOH;
+ TransmitPkt[1] = GETMEM;
+ TransmitPkt[2] = 11;
+ TransmitPkt[3] = 0;
+ TransmitPkt[4] = (UCHAR) FIRSTBYTE(Address);
+ TransmitPkt[5] = (UCHAR) SECONDBYTE(Address);
+ TransmitPkt[6] = (UCHAR) THIRDBYTE(Address);
+ TransmitPkt[7] = (UCHAR) FOURTHBYTE(Address);
+ TransmitPkt[8] = (UCHAR) FIRSTBYTE(Size);
+ TransmitPkt[9] = (UCHAR) SECONDBYTE(Size);
+ TransmitPkt[10] = EOT;
+
+ if (!Xceive((USHORT)(Size+5), 11)) {
+ DbgPrint ("Sim32GetVDMMemory.....BAD Memory \a\n");
+ return (BAD);
+ }
+
+ RtlMoveMemory(Buffer, &ReceivePkt[4], Size);
+
+ return(GOOD);
+
+ }
+ else {
+ DbgPrint ("Bad Packet Size %d\n", Size);
+ return (BADSIZE);
+ }
+}
+
+
+/*****************************************************************************
+*
+* Sim32SetVDMMemory
+*
+* This routine sets 'Size' bytes in WOW VDM starting at address
+* specified by 'Address' to the values in Buffer.
+*
+*****************************************************************************/
+
+
+USHORT Sim32SetVDMMemory (IN ULONG Address,
+ IN USHORT Size,
+ IN OUT PVOID Buffer)
+{
+ if (Size < MAXSIZE-11) {
+ TransmitPkt[0] = SOH;
+ TransmitPkt[1] = SETMEM;
+ TransmitPkt[2] = (UCHAR) (Size+11);
+ TransmitPkt[3] = 0;
+ TransmitPkt[4] = (UCHAR) FIRSTBYTE(Address);
+ TransmitPkt[5] = (UCHAR) SECONDBYTE(Address);
+ TransmitPkt[6] = (UCHAR) THIRDBYTE(Address);
+ TransmitPkt[7] = (UCHAR) FOURTHBYTE(Address);
+ TransmitPkt[8] = (UCHAR) FIRSTBYTE(Size);
+ TransmitPkt[9] = (UCHAR) SECONDBYTE(Size);
+ TransmitPkt[10+Size] = EOT;
+
+ RtlMoveMemory(&TransmitPkt[10], Buffer, Size);
+
+ if (!Xceive(7, (USHORT)(Size+11))) {
+ DbgPrint ("Sim32SetVDMMemory... could not set : \a\n");
+ return (BAD);
+ }
+
+ return(GOOD);
+
+ }
+ else {
+ DbgPrint ("Bad Packet Size %d\n", Size);
+ return (BADSIZE);
+ }
+}
+
+
+
+/*****************************************************************************
+*
+* Sim32GetVDMPSZPointer
+*
+* This routine returns a pointer to a null terminated string in the WOW
+* VDM at the specified address.
+*
+* This routine does the following,
+* allocates a sufficient size buffer,
+* gets the string from SIM16,
+* copies the string into buffer,
+* returns a pointer to the buffer.
+*
+*****************************************************************************/
+
+
+PSZ Sim32GetVDMPSZPointer (IN ULONG Address)
+{
+ USHORT Size;
+ PSZ Ptr;
+
+
+ TransmitPkt[0] = SOH;
+ TransmitPkt[1] = PSZLEN;
+ TransmitPkt[2] = 9;
+ TransmitPkt[3] = 0;
+ TransmitPkt[4] = (UCHAR) FIRSTBYTE(Address);
+ TransmitPkt[5] = (UCHAR) SECONDBYTE(Address);
+ TransmitPkt[6] = (UCHAR) THIRDBYTE(Address);
+ TransmitPkt[7] = (UCHAR) FOURTHBYTE(Address);
+ TransmitPkt[8] = EOT;
+
+ if (!Xceive(7, 9)) {
+ DbgPrint ("Sim32GetVDMPSZPointer.....Attempt to get PSZ length failed \a\a\n");
+ return NULL;
+ }
+
+ Size = *(PUSHORT)(ReceivePkt+4);
+
+
+ //
+ // allocate buffer to copy string into
+ //
+
+ Ptr = (PSZ) malloc(Size);
+
+ if (!Ptr) {
+ DbgPrint ("Sim32GetVDMPSZPointer..., malloc failed \a\a\n");
+ }
+
+
+ //
+ // get null terminated string
+ //
+
+ if (Size < MAXSIZE-11) {
+ TransmitPkt[1] = GETMEM;
+ TransmitPkt[2] = 11;
+ TransmitPkt[3] = 0;
+ TransmitPkt[8] = (UCHAR) FIRSTBYTE(Size);
+ TransmitPkt[9] = (UCHAR) SECONDBYTE(Size);
+ TransmitPkt[10] = EOT;
+
+ if (!Xceive((USHORT)(Size+5), 11)) {
+ DbgPrint ("Sim32GetVDMPSZPointer.....Unsuccessful \a\a\n");
+ return NULL;
+ }
+
+ RtlMoveMemory(Ptr, &ReceivePkt[4], Size);
+ } else {
+ DbgPrint ("Sim32GetVDMPSZPointer.....Size of the string too big Size = %d\a\a\n", Size);
+ return NULL;
+ }
+
+ return Ptr;
+
+}
+
+
+
+/*****************************************************************************
+*
+* Sim32FreeVDMPointer
+*
+* This routine frees the buffer which was allocated earlier.
+*
+*****************************************************************************/
+
+
+VOID Sim32FreeVDMPointer (PVOID Ptr)
+{
+ free (Ptr);
+}
+
+
+
+/*****************************************************************************
+*
+* Sim32SendSim16
+*
+* This routine specifies the stack of the WOW VDM task and asks the
+* WOW 16 to make that task run.
+*
+*****************************************************************************/
+
+
+USHORT Sim32SendSim16 (IN OUT ULONG *WOWStack)
+{
+ static USHORT fInit = 0;
+
+ if (fInit) {
+ TransmitPkt[0] = SOH;
+ TransmitPkt[1] = WAKEUP;
+ TransmitPkt[2] = 9;
+ TransmitPkt[3] = 0;
+ TransmitPkt[4] = (UCHAR) FIRSTBYTE(*WOWStack);
+ TransmitPkt[5] = (UCHAR) SECONDBYTE(*WOWStack);
+ TransmitPkt[6] = (UCHAR) THIRDBYTE(*WOWStack);
+ TransmitPkt[7] = (UCHAR) FOURTHBYTE(*WOWStack);
+ TransmitPkt[8] = EOT;
+
+ if (!Xceive(9, 9)) {
+ return (BAD);
+ }
+
+ *WOWStack = *(PULONG)(ReceivePkt+4);
+
+ return(GOOD);
+ }
+ else {
+ Initialize(9);
+ *WOWStack = *(PULONG)(ReceivePkt+4);
+ fInit = 1;
+ return (GOOD);
+ }
+}
+
+
+/*****************************************************************************
+*
+* Xceive
+*
+* This routine transmits a packet and waits for the data from the remote
+* side to come. When this routine returns, the ReceivePkt has the data
+* sent by the remote machine.
+*
+*****************************************************************************/
+
+
+USHORT Xceive(IN USHORT Length_In, IN USHORT Length_Out)
+{
+ BOOLEAN Done = FALSE;
+ USHORT i = 0;
+
+ while ((i < MAXTRY) && (!Done)) {
+
+ Status = NtDeviceIoControlFile(
+ DeviceHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ IOCTL_TRNXT_XCEIVE,
+ TransmitPkt,
+ (ULONG) Length_Out,
+ ReceivePkt,
+ (ULONG) Length_In
+ );
+
+ //
+ // check error condition
+ // if no error, then
+ //
+
+ if (ReceivePkt[0] == SOH) {
+ if (ReceivePkt[1] != NAK) {
+ i = *(PUSHORT)(ReceivePkt+2);
+ if (ReceivePkt[(--i)] == EOT) {
+ Done = TRUE;
+ }
+ else {
+ DbgPrint ("EOT is missing from the packet, *ERROR*, Do Not Proceed Further !\a\a\n");
+ }
+ }
+ else {
+ DbgPrint ("It is a NAK packet, *ERROR*, Do Not Proceed Further !\a\a\n");
+ }
+ }
+ else {
+ DbgPrint ("SOH is missing from the packet, *ERROR*, Do Not Proceed Further !\a\a\n");
+ }
+
+ if (!Done) {
+ i++;
+ DbgPrint ("\nSTOP STOP STOP !!!\a\a\a\a\a\n");
+ }
+ }
+
+ if (Done) {
+ return (GOOD);
+ }
+ else {
+ return (BAD);
+ }
+
+}
+
+void Initialize (IN USHORT Length_In)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+
+ STRING DeviceName;
+ USHORT j;
+ char TestPkt[] = "WOW 32 Simulator on NT\n\r";
+
+ RtlInitString(&DeviceName, "\\Device\\Serial1");
+
+ //
+ // set attributes
+ //
+
+ ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
+ ObjectAttributes.RootDirectory = NULL;
+ ObjectAttributes.ObjectName = &DeviceName;
+ ObjectAttributes.Attributes = OBJ_INHERIT;
+ ObjectAttributes.SecuriAR) SECONDBYTE(Size);
+ TransmitPkt[10] = EOT;
+
+ if (!Xceive((USHORT)(Size+5), 11)) {
+ DbgPrint ("Sim32GetVDMPSZPointer.....Unsuccessful \a\a\n");
+ return NULL;
+ }
+
+ RtlMoveMemory(Ptr, &ReceivePkt[4], Size);
+ } else {
+ DbgPrint ("Sim32GetVDMPSZPointer.....Size of the string too big Size = %d\a\a\n", Size);
+ return NULL;
+ }
+
+ return Ptr;
+
+}
+
+
+
+/*****************************************************************************
+*
+* Sim32FreeVDMPointer
+*
+* This routine frees the buffer which was allocated earlier.
+*
+*****************************************************************************/
+
+
+VOID Sim32FreeVDMPointer (PVOID Ptr)
+{
+ free (Ptr);
+}
+
+
+
+/******************************
diff --git a/private/mvdm/sim32/sim32.h b/private/mvdm/sim32/sim32.h
new file mode 100644
index 000000000..589fb2fc0
--- /dev/null
+++ b/private/mvdm/sim32/sim32.h
@@ -0,0 +1,122 @@
+/* SIM v1.0
+ *
+ * SIM32.H
+ * SIM32 constants and prototypes
+ *
+ * History
+ * Created 05-Feb-91 by Chandan Chauhan and Jeff Parsons
+ */
+
+
+/* Public function prototypes
+ *
+ * These functions are true pascal functions in the 16-bit case,
+ * but conform to the default convention (cdecl) for the 32-bit case.
+ */
+#ifndef FAR
+#define FAR
+#endif
+#ifndef PASCAL
+#define PASCAL
+#endif
+
+USHORT FAR PASCAL Sim32SendSim16(PULONG);
+USHORT FAR PASCAL Sim32GetVDMMemory(ULONG, USHORT, PVOID);
+USHORT FAR PASCAL Sim32SetVDMMemory(ULONG, USHORT, PVOID);
+PSZ FAR PASCAL Sim32GetVDMPSZPointer(ULONG);
+VOID FAR PASCAL Sim32FreeVDMPointer(PVOID);
+
+/* Private function prototypes
+ */
+VOID Initialize();
+USHORT Xceive(IN USHORT, IN USHORT);
+
+
+/* Simulator replacement macros
+ */
+#define SENDVDM(pvp) WOW32Receive()
+#define RECEIVEVDM(pvp) Sim32SendSim16(pvp)
+
+#ifdef ALLOCA
+#define GETPTR(vp,cb,p) ((p=alloca(cb))?Sim32GetVDMMemory(vp, (USHORT)(cb), p):FALSE)
+#define GETARGPTR(vp,cb,p) if (p=alloca(cb)) { Sim32GetVDMMemory(vp+OFFSETOF(VDMFRAME,bArgs), (USHORT)(cb), p)
+#ifdef WIN_16
+#define EQNULL
+#define GETPSZPTR(vp,pcb,p) if (vp) if (p=alloca(*pcb=128)) Sim32GetVDMMemory(vp, (USHORT)*pcb, p); else goto Error
+#define FREEPSZPTR(p)
+#else
+#define EQNULL = NULL
+#define GETPSZPTR(vp,pcb,p) if (vp) if (!(p=Sim32GetVDMPSZPointer(vp))) goto Error
+#define FREEPSZPTR(p) if (p) Sim32FreeVDMPointer(p)
+#endif
+#define FLUSHPTR(vp,cb,p) Sim32SetVDMMemory(vp, (USHORT)(cb), p)
+#define FREEPTR(p)
+#define FREEARGPTR(p) ;}
+#else
+#define EQNULL = NULL
+#define GETPTR(vp,cb,p) ((p=malloc(cb))?Sim32GetVDMMemory(vp, (USHORT)(cb), p):FALSE)
+#define GETARGPTR(vp,cb,p) if (p=malloc(cb)) { Sim32GetVDMMemory(vp+OFFSETOF(VDMFRAME,bArgs), (USHORT)(cb), p)
+#ifdef WIN_16
+#define GETPSZPTR(vp,pcb,p) if (vp) if (p=malloc(*pcb=128)) Sim32GetVDMMemory(vp, (USHORT)*pcb, p); else goto Error
+#define FREEPSZPTR(p) if (p) free(p)
+#else
+#define GETPSZPTR(vp,pcb,p) if (vp) if (!(p=Sim32GetVDMPSZPointer(vp))) goto Error
+#define FREEPSZPTR(p) if (p) Sim32FreeVDMPointer(p)
+#endif
+#define FLUSHPTR(vp,cb,p) Sim32SetVDMMemory(vp, (USHORT)(cb), p)
+#ifndef DEBUG
+#define FREEPTR(p) free(p)
+#define FREEARGPTR(p) free(p);}
+#else
+#define FREEPTR(p) free(p); p=NULL
+#define FREEARGPTR(p) free(p); p=NULL;}
+#endif
+#endif
+
+#define GETOPTPTR(vp,cb,p) if (vp) if (p=malloc(cb)) Sim32GetVDMMemory(vp, (USHORT)(cb), p); else goto Error
+#define GETVDMPTR(vp,cb,p) if (p=malloc(cb)) Sim32GetVDMMemory(vp, (USHORT)(cb), p); else goto Error
+#define ALLOCVDMPTR(vp,cb,p) if (!(p=malloc(cb))) goto Error
+#define FLUSHVDMPTR(vp,cb,p) Sim32SetVDMMemory(vp, (USHORT)(cb), p)
+#ifndef DEBUG
+#define FREEVDMPTR(p) if (p) free(p)
+#else
+#define FREEVDMPTR(p) if (p) {free(p); p=NULL;}
+#endif
+
+#define GETVDMMEMORY(vp,cb,p) Sim32GetVDMMemory(vp, (USHORT)(cb), p)
+#define SETVDMMEMORY(vp,cb,p) Sim32SetVDMMemory(vp, (USHORT)(cb), p)
+
+
+#ifdef SIM_32 // BUGBUG -- Use the macros in nt header files
+#undef FIRSTBYTE
+#undef SECONDBYTE
+#undef THIRDBYTE
+#undef FOURTHBYTE
+#endif
+
+#define FIRSTBYTE(VALUE) (VALUE & LO_MASK)
+#define SECONDBYTE(VALUE) ((VALUE >> 8) & LO_MASK)
+#define THIRDBYTE(VALUE) ((VALUE >> 16) & LO_MASK)
+#define FOURTHBYTE(VALUE) ((VALUE >> 24) & LO_MASK)
+#define LO_MASK 0x000000FF
+
+#define MAXSIZE 1024 // maximum buffer size
+#define MAXTRY 10 // for Transport
+
+
+/* Packet Codes
+ */
+#define SOH 1 // start of header ie Pkt
+#define EOT 4 // end of transmission
+#define ToWOW32 1
+#define GETMEM 2
+#define SETMEM 3
+#define WAKEUP 4
+#define RESP 5
+#define ACK 6
+#define NAK 7
+#define PSZLEN 8
+
+#define GOOD 1
+#define BAD 0
+#define BADSIZE 2
diff --git a/private/mvdm/sim32/sources b/private/mvdm/sim32/sources
new file mode 100644
index 000000000..a3fdd8e0e
--- /dev/null
+++ b/private/mvdm/sim32/sources
@@ -0,0 +1,61 @@
+!IF 0
+*****************************************************************************
+Copyright (c) 1989, 1990 Microsoft Corporation
+
+Module Name: SOURCES for QuickApp
+
+Abstract:
+ This file specifies the target component being built and the list of
+ sources files needed to build that component. Also specifies optional
+ compiler switches and libraries that are unique for the component being
+ built.
+
+Author: various
+
+Revision History: 11/20/89 - kengr - Add testsmem shared memory test.
+ 01/15/90 - kengr - Make includes and libs relative.
+ 02/08/90 - kengr - Add testlog to include path.
+ 04/11/90 - kengr - Add tldebug to includes and libs.
+ 04/18/90 - danl - modify for BUILD procedure.
+
+*****************************************************************************
+!ENDIF
+
+#------------------------------------------------
+# INFO FOR CREATING LIBRARY
+#------------------------------------------------
+
+TARGETNAME=sim32
+TARGETPATH=obj
+TARGETTYPE=LIBRARY
+
+#------------------------------------------------
+# INCLUDE PATH
+#------------------------------------------------
+
+INCLUDES=.\;
+
+#------------------------------------------------
+# SOURCE FILES (used to make library)
+# (Currently there are no files listed.)
+#------------------------------------------------
+
+SOURCES=
+
+
+#------------------------------------------------
+# FLAGS
+#------------------------------------------------
+
+WARNING_LEVEL=-W1
+UMLIBS=
+#------------------------------------------------
+# EXECUTABLES
+#------------------------------------------------
+
+UMTEST=sim32
+
+#------------------------------------------------
+# LIBRARIES created by the SOURCES= line (above)
+# (currently commented out - not used)
+#------------------------------------------------