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