| 1 | /* $Id: d16init.c,v 1.2 1999-10-27 02:02:53 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * d16init - init routines for both drivers.
|
|---|
| 4 | *
|
|---|
| 5 | * IMPORTANT! Code and data defined here will be discarded after init is
|
|---|
| 6 | * compleated. CodeEnd and DataEnd should not be set here.?
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright (c) 1999 knut st. osmundsen
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /*******************************************************************************
|
|---|
| 13 | * Defined Constants *
|
|---|
| 14 | *******************************************************************************/
|
|---|
| 15 | #define INCL_16
|
|---|
| 16 | #define INCL_DOSFILEMGR
|
|---|
| 17 | #define INCL_DOSDEVICES
|
|---|
| 18 | #define INCL_DOSMISC
|
|---|
| 19 | #define INCL_DOSERRORS
|
|---|
| 20 | #define INCL_NOPMAPI
|
|---|
| 21 |
|
|---|
| 22 | /*******************************************************************************
|
|---|
| 23 | * Header Files *
|
|---|
| 24 | *******************************************************************************/
|
|---|
| 25 | #include <os2.h>
|
|---|
| 26 | #include <devhdr.h>
|
|---|
| 27 | #include <devcmd.h>
|
|---|
| 28 | #include <strat2.h>
|
|---|
| 29 | #include <reqpkt.h>
|
|---|
| 30 | #include <dhcalls.h>
|
|---|
| 31 |
|
|---|
| 32 | #include <string.h>
|
|---|
| 33 | #include <memory.h>
|
|---|
| 34 |
|
|---|
| 35 | #include "probkrnl.h"
|
|---|
| 36 | #include "dev1632.h"
|
|---|
| 37 | #include "dev16.h"
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * init function - device 0.
|
|---|
| 41 | * Does nothing else than setting the device_help variable and
|
|---|
| 42 | * fill the request packet.
|
|---|
| 43 | * @returns Status word.
|
|---|
| 44 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
|---|
| 45 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
|---|
| 46 | * @remark pRpIn and pRpOut points to the same memory.
|
|---|
| 47 | */
|
|---|
| 48 | USHORT _near dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
|---|
| 49 | {
|
|---|
| 50 | Device_Help = pRpIn->DevHlpEP;
|
|---|
| 51 |
|
|---|
| 52 | pRpOut->BPBArray = NULL;
|
|---|
| 53 | pRpOut->CodeEnd = (USHORT)&CODE16END;
|
|---|
| 54 | pRpOut->DataEnd = (USHORT)&DATA16END;
|
|---|
| 55 | pRpOut->Unit = 0;
|
|---|
| 56 | pRpOut->rph.Status = STATUS_DONE;
|
|---|
| 57 | return STATUS_DONE;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | /**
|
|---|
| 62 | * init function - device 1.
|
|---|
| 63 | * We will send an IOCtl request to the elf$ (device 0) which will
|
|---|
| 64 | * perform the Ring-0 initiation of the driver.
|
|---|
| 65 | * @returns Status word.
|
|---|
| 66 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
|---|
| 67 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
|---|
| 68 | * @remark pRpIn and pRpOut points to the same memory.
|
|---|
| 69 | */
|
|---|
| 70 | USHORT _near dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
|---|
| 71 | {
|
|---|
| 72 | APIRET rc;
|
|---|
| 73 | D16R0INITPARAM param;
|
|---|
| 74 | D16R0INITDATA data = {0};
|
|---|
| 75 | HFILE hDev0 = 0;
|
|---|
| 76 | USHORT usAction = 0;
|
|---|
| 77 | NPSZ npszErrMsg = NULL;
|
|---|
| 78 |
|
|---|
| 79 | rc = ProbeKernel(pRpIn);
|
|---|
| 80 | if (rc == NO_ERROR)
|
|---|
| 81 | {
|
|---|
| 82 | rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
|---|
| 83 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
|---|
| 84 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
|---|
| 85 | 0UL);
|
|---|
| 86 | if (rc == NO_ERROR)
|
|---|
| 87 | {
|
|---|
| 88 | param.pRpInitIn = pRpIn;
|
|---|
| 89 | rc = DosDevIOCtl(&data, ¶m, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
|
|---|
| 90 | if (rc == NO_ERROR)
|
|---|
| 91 | {
|
|---|
| 92 | if (data.Status != STATUS_DONE)
|
|---|
| 93 | npszErrMsg = "Ring-0 initiation failed\n\r";
|
|---|
| 94 | else
|
|---|
| 95 | {
|
|---|
| 96 | register NPSZ npsz = "Win32k.sys succesfully initiated!\n\r";
|
|---|
| 97 | DosPutMessage(1, strlen(npsz)+1, npsz);
|
|---|
| 98 | pRpOut->Status = data.Status;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | else
|
|---|
| 102 | npszErrMsg = "DosDevIOCtl failed.\n\r";
|
|---|
| 103 | DosClose(hDev0);
|
|---|
| 104 | }
|
|---|
| 105 | else
|
|---|
| 106 | npszErrMsg = "DosOpen failed.\n\r";
|
|---|
| 107 | }
|
|---|
| 108 | else
|
|---|
| 109 | npszErrMsg = "ProbeKernel failed.\n\r";
|
|---|
| 110 | pRpOut->BPBArray = NULL;
|
|---|
| 111 | pRpOut->CodeEnd = (USHORT)&CODE16END;
|
|---|
| 112 | pRpOut->DataEnd = (USHORT)&DATA16END;
|
|---|
| 113 | pRpOut->Unit = 0;
|
|---|
| 114 |
|
|---|
| 115 | if (npszErrMsg)
|
|---|
| 116 | {
|
|---|
| 117 | DosPutMessage(1, strlen(npszErrMsg) + 1, npszErrMsg);
|
|---|
| 118 | return pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | return pRpOut->rph.Status;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | /**
|
|---|
| 127 | * R0 16-bit initiation function.
|
|---|
| 128 | * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
|
|---|
| 129 | * @returns Status word.
|
|---|
| 130 | * @param pRp Generic IO Control request packet.
|
|---|
| 131 | */
|
|---|
| 132 | USHORT R0Init16(PRP_GENIOCTL pRp)
|
|---|
| 133 | {
|
|---|
| 134 | USHORT usRc = STATUS_DONE;
|
|---|
| 135 | APIRET rc;
|
|---|
| 136 | PDOSTABLE pDT;
|
|---|
| 137 | PDOSTABLE2 pDT2;
|
|---|
| 138 |
|
|---|
| 139 | /* First we're to get the DosTable2 stuff. */
|
|---|
| 140 | rc = DevHelp_GetDOSVar(9, 0, &pDT);
|
|---|
| 141 | if (rc == NO_ERROR)
|
|---|
| 142 | {
|
|---|
| 143 | ULONG cPages;
|
|---|
| 144 | char hLockParm[12] = {0};
|
|---|
| 145 | ULONG ulLinParm;
|
|---|
| 146 | char hLockData[12] = {0};
|
|---|
| 147 | ULONG ulLinData;
|
|---|
| 148 |
|
|---|
| 149 | pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
|
|---|
| 150 | TKSSBase16 = (ULONG)pDT2->pTKSSBase;
|
|---|
| 151 | R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
|
|---|
| 152 | R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
|
|---|
| 153 | if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
|
|---|
| 154 | &&
|
|---|
| 155 | !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
|
|---|
| 156 | )
|
|---|
| 157 | {
|
|---|
| 158 | if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 159 | ulLinParm, sizeof(D16R0INITPARAM),
|
|---|
| 160 | (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
|
|---|
| 161 | &&
|
|---|
| 162 | !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 163 | ulLinData, sizeof(D16R0INITDATA),
|
|---|
| 164 | (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
|
|---|
| 165 | )
|
|---|
| 166 | { /* data and param is locked (do we need to lock the request packet too ?). */
|
|---|
| 167 | /* create new 32-bit packet */
|
|---|
| 168 | RP32INIT rp32init;
|
|---|
| 169 |
|
|---|
| 170 | _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
|
|---|
| 171 | if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
|
|---|
| 172 | !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
|
|---|
| 173 | )
|
|---|
| 174 | {
|
|---|
| 175 | usRc = CallR0Init32(SSToDS_16(&rp32init));
|
|---|
| 176 | }
|
|---|
| 177 | else
|
|---|
| 178 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 179 |
|
|---|
| 180 | ((PD16R0INITDATA)pRp->DataPacket)->Status = usRc;
|
|---|
| 181 |
|
|---|
| 182 | /* finished - unlock data and parm */
|
|---|
| 183 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
|
|---|
| 184 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
|
|---|
| 185 | }
|
|---|
| 186 | else
|
|---|
| 187 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 188 | }
|
|---|
| 189 | else
|
|---|
| 190 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 191 | }
|
|---|
| 192 | else
|
|---|
| 193 | usRc |= ERROR_I24_GEN_FAILURE;
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | #if 0
|
|---|
| 197 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 198 | &DATA32START,
|
|---|
| 199 | (ULONG)(&end) - (ULONG)&DATA32START),
|
|---|
| 200 | (void*)-1,
|
|---|
| 201 | &lock[0],
|
|---|
| 202 | &cPages);
|
|---|
| 203 |
|
|---|
| 204 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_VERIFY,
|
|---|
| 205 | &CODE32START,
|
|---|
| 206 | (ULONG)(&CODE32END) - (ULONG)&CODE32START),
|
|---|
| 207 | (void*)-1,
|
|---|
| 208 | &lock[0],
|
|---|
| 209 | &cPages);
|
|---|
| 210 | #endif
|
|---|
| 211 |
|
|---|
| 212 | return usRc;
|
|---|
| 213 | }
|
|---|