| 1 | /* $Id: d16init.c,v 1.1 1999-09-06 02:19:55 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 "dev1632.h"
|
|---|
| 36 | #include "dev16.h"
|
|---|
| 37 |
|
|---|
| 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 win32i$ (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 = DosOpen("\\dev\\win32i$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
|---|
| 80 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
|---|
| 81 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
|---|
| 82 | 0UL);
|
|---|
| 83 | if (rc == NO_ERROR)
|
|---|
| 84 | {
|
|---|
| 85 | param.pRpInitIn = pRpIn;
|
|---|
| 86 | rc = DosDevIOCtl(&data, ¶m, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
|
|---|
| 87 | /* _asm int 3; */
|
|---|
| 88 | if (rc == NO_ERROR)
|
|---|
| 89 | {
|
|---|
| 90 | if (data.Status != STATUS_DONE)
|
|---|
| 91 | npszErrMsg = "Ring-0 initiation failed\n\r";
|
|---|
| 92 | else
|
|---|
| 93 | {
|
|---|
| 94 | register NPSZ npsz = "Test.sys succesfully initiated!\n\r";
|
|---|
| 95 | DosPutMessage(1, strlen(npsz)+1, npsz);
|
|---|
| 96 | pRpOut->Status = data.Status;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | else
|
|---|
| 100 | npszErrMsg = "DosDevIOCtl failed\n\r";
|
|---|
| 101 | DosClose(hDev0);
|
|---|
| 102 | }
|
|---|
| 103 | else
|
|---|
| 104 | npszErrMsg = "DosOpen failed\n\r";
|
|---|
| 105 |
|
|---|
| 106 | pRpOut->BPBArray = NULL;
|
|---|
| 107 | pRpOut->CodeEnd = (USHORT)&CODE16END;
|
|---|
| 108 | pRpOut->DataEnd = (USHORT)&DATA16END;
|
|---|
| 109 | pRpOut->Unit = 0;
|
|---|
| 110 |
|
|---|
| 111 | if (npszErrMsg)
|
|---|
| 112 | {
|
|---|
| 113 | DosPutMessage(1, strlen(npszErrMsg) + 1, npszErrMsg);
|
|---|
| 114 | return pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | return pRpOut->rph.Status;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | /**
|
|---|
| 123 | * R0 16-bit initiation function.
|
|---|
| 124 | * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
|
|---|
| 125 | * @returns Status word.
|
|---|
| 126 | * @param pRp Generic IO Control request packet.
|
|---|
| 127 | */
|
|---|
| 128 | USHORT R0Init16(PRP_GENIOCTL pRp)
|
|---|
| 129 | {
|
|---|
| 130 | USHORT usRc = STATUS_DONE;
|
|---|
| 131 | APIRET rc;
|
|---|
| 132 | PDOSTABLE pDT;
|
|---|
| 133 | PDOSTABLE2 pDT2;
|
|---|
| 134 |
|
|---|
| 135 | /* First we're to get the DosTable2 stuff. */
|
|---|
| 136 | rc = DevHelp_GetDOSVar(9, 0, &pDT);
|
|---|
| 137 | if (rc == NO_ERROR)
|
|---|
| 138 | {
|
|---|
| 139 | ULONG cPages;
|
|---|
| 140 | char hLockParm[12] = {0};
|
|---|
| 141 | ULONG ulLinParm;
|
|---|
| 142 | char hLockData[12] = {0};
|
|---|
| 143 | ULONG ulLinData;
|
|---|
| 144 |
|
|---|
| 145 | pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
|
|---|
| 146 | TKSSBase16 = pDT2->TKSSBase;
|
|---|
| 147 | R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
|
|---|
| 148 | R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
|
|---|
| 149 | if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
|
|---|
| 150 | &&
|
|---|
| 151 | !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
|
|---|
| 152 | )
|
|---|
| 153 | {
|
|---|
| 154 | if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 155 | ulLinParm, sizeof(D16R0INITPARAM),
|
|---|
| 156 | (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
|
|---|
| 157 | &&
|
|---|
| 158 | !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 159 | ulLinData, sizeof(D16R0INITDATA),
|
|---|
| 160 | (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
|
|---|
| 161 | )
|
|---|
| 162 | { /* data and param is locked (do we need to lock the request packet too ?). */
|
|---|
| 163 | /* create new 32-bit packet */
|
|---|
| 164 | RP32INIT rp32init;
|
|---|
| 165 |
|
|---|
| 166 | _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
|
|---|
| 167 | if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
|
|---|
| 168 | !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
|
|---|
| 169 | )
|
|---|
| 170 | {
|
|---|
| 171 | /*_asm int 3;*/
|
|---|
| 172 | usRc = CallR0Init32(SSToDS_16(&rp32init));
|
|---|
| 173 | /*_asm int 3;*/
|
|---|
| 174 | }
|
|---|
| 175 | else
|
|---|
| 176 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 177 |
|
|---|
| 178 | ((PD16R0INITDATA)pRp->DataPacket)->Status = usRc;
|
|---|
| 179 |
|
|---|
| 180 | /* finished - unlock data and parm */
|
|---|
| 181 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
|
|---|
| 182 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
|
|---|
| 183 | }
|
|---|
| 184 | else
|
|---|
| 185 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 186 | }
|
|---|
| 187 | else
|
|---|
| 188 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
|---|
| 189 | }
|
|---|
| 190 | else
|
|---|
| 191 | usRc |= ERROR_I24_GEN_FAILURE;
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | #if 0
|
|---|
| 195 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
|---|
| 196 | &DATA32START,
|
|---|
| 197 | (ULONG)(&end) - (ULONG)&DATA32START),
|
|---|
| 198 | (void*)-1,
|
|---|
| 199 | &lock[0],
|
|---|
| 200 | &cPages);
|
|---|
| 201 |
|
|---|
| 202 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_VERIFY,
|
|---|
| 203 | &CODE32START,
|
|---|
| 204 | (ULONG)(&CODE32END) - (ULONG)&CODE32START),
|
|---|
| 205 | (void*)-1,
|
|---|
| 206 | &lock[0],
|
|---|
| 207 | &cPages);
|
|---|
| 208 | #endif
|
|---|
| 209 |
|
|---|
| 210 | return usRc;
|
|---|
| 211 | }
|
|---|