[6431] | 1 | /* $Id: d16init.c,v 1.12 2001-07-31 21:36:37 bird Exp $
|
---|
[847] | 2 | *
|
---|
| 3 | * d16init - init routines for both drivers.
|
---|
| 4 | *
|
---|
| 5 | * IMPORTANT! Code and data defined here will be discarded after init is
|
---|
[6431] | 6 | * completed. CodeEnd and DataEnd should not be set here.?
|
---|
[847] | 7 | *
|
---|
[4164] | 8 | * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[847] | 9 | *
|
---|
[1678] | 10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 11 | *
|
---|
[847] | 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 |
|
---|
[2898] | 24 |
|
---|
[847] | 25 | /*******************************************************************************
|
---|
| 26 | * Header Files *
|
---|
| 27 | *******************************************************************************/
|
---|
| 28 | #include <os2.h>
|
---|
| 29 | #include <devhdr.h>
|
---|
| 30 | #include <devcmd.h>
|
---|
| 31 | #include <strat2.h>
|
---|
| 32 | #include <reqpkt.h>
|
---|
| 33 | #include <dhcalls.h>
|
---|
| 34 |
|
---|
| 35 | #include <string.h>
|
---|
| 36 | #include <memory.h>
|
---|
| 37 |
|
---|
[4164] | 38 | #include "devSegDf.h"
|
---|
| 39 | #undef DATA16_INIT
|
---|
| 40 | #define DATA16_INIT
|
---|
| 41 | #undef CODE16_INIT
|
---|
| 42 | #define CODE16_INIT
|
---|
[1467] | 43 | #include "probkrnl.h"
|
---|
[847] | 44 | #include "dev1632.h"
|
---|
| 45 | #include "dev16.h"
|
---|
[4164] | 46 | #include "vprntf16.h"
|
---|
| 47 | #include "log.h"
|
---|
| 48 | #include "options.h"
|
---|
[4185] | 49 | #include "errors.h"
|
---|
[847] | 50 |
|
---|
[4164] | 51 |
|
---|
[847] | 52 | /**
|
---|
| 53 | * init function - device 0.
|
---|
| 54 | * Does nothing else than setting the device_help variable and
|
---|
| 55 | * fill the request packet.
|
---|
| 56 | * @returns Status word.
|
---|
| 57 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
---|
| 58 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
---|
| 59 | * @remark pRpIn and pRpOut points to the same memory.
|
---|
| 60 | */
|
---|
[2836] | 61 | USHORT NEAR dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
---|
[847] | 62 | {
|
---|
[4164] | 63 | APIRET rc;
|
---|
[847] | 64 | Device_Help = pRpIn->DevHlpEP;
|
---|
| 65 |
|
---|
[4164] | 66 | /*
|
---|
| 67 | * Does this work at Ring-3 (inittime)?
|
---|
| 68 | * If this work we could be saved from throuble!
|
---|
| 69 | */
|
---|
| 70 | rc = initGetDosTableData();
|
---|
| 71 | if (rc != NO_ERROR)
|
---|
| 72 | printf16("win32k - elf$: initGetDosTableData failed with rc=%d\n", rc);
|
---|
| 73 |
|
---|
[847] | 74 | pRpOut->BPBArray = NULL;
|
---|
[4164] | 75 | pRpOut->CodeEnd = (USHORT)&CODE16_INITSTART;
|
---|
| 76 | pRpOut->DataEnd = (USHORT)&DATA16_INITSTART;
|
---|
[847] | 77 | pRpOut->Unit = 0;
|
---|
| 78 | pRpOut->rph.Status = STATUS_DONE;
|
---|
| 79 | return STATUS_DONE;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
| 84 | * init function - device 1.
|
---|
[1467] | 85 | * We will send an IOCtl request to the elf$ (device 0) which will
|
---|
[847] | 86 | * perform the Ring-0 initiation of the driver.
|
---|
| 87 | * @returns Status word.
|
---|
| 88 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
---|
| 89 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
---|
| 90 | * @remark pRpIn and pRpOut points to the same memory.
|
---|
| 91 | */
|
---|
[2836] | 92 | USHORT NEAR dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
---|
[847] | 93 | {
|
---|
| 94 | APIRET rc;
|
---|
| 95 | D16R0INITPARAM param;
|
---|
| 96 | D16R0INITDATA data = {0};
|
---|
| 97 | HFILE hDev0 = 0;
|
---|
| 98 | USHORT usAction = 0;
|
---|
| 99 | NPSZ npszErrMsg = NULL;
|
---|
[5283] | 100 | const char * npszErrMsg2 = NULL;
|
---|
[847] | 101 |
|
---|
[4164] | 102 | /*
|
---|
| 103 | * Probe kernel data.
|
---|
| 104 | */
|
---|
[1467] | 105 | rc = ProbeKernel(pRpIn);
|
---|
[847] | 106 | if (rc == NO_ERROR)
|
---|
| 107 | {
|
---|
[4164] | 108 | /*
|
---|
| 109 | * Open and send a Ring-0 init packet to elf$.
|
---|
| 110 | * If this succeeds win32k$ init succeeds.
|
---|
| 111 | */
|
---|
[1467] | 112 | rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
---|
| 113 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
| 114 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
---|
| 115 | 0UL);
|
---|
[847] | 116 | if (rc == NO_ERROR)
|
---|
| 117 | {
|
---|
[1467] | 118 | param.pRpInitIn = pRpIn;
|
---|
| 119 | rc = DosDevIOCtl(&data, ¶m, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
|
---|
| 120 | if (rc == NO_ERROR)
|
---|
[847] | 121 | {
|
---|
[4185] | 122 | if (data.usRcInit32 == NO_ERROR)
|
---|
[1467] | 123 | {
|
---|
[4164] | 124 | if (!options.fQuiet)
|
---|
[5480] | 125 | printf16("Win32k.sys successfully initiated!\n");
|
---|
[4185] | 126 | pRpOut->Status = pRpOut->rph.Status = STATUS_DONE;
|
---|
[1467] | 127 | }
|
---|
[4164] | 128 | else
|
---|
[4185] | 129 | {
|
---|
| 130 | /* set correct error message and rc */
|
---|
| 131 | rc = data.usRcInit32;
|
---|
| 132 | npszErrMsg = "Ring-0 initiation failed. rc=%x\n";
|
---|
| 133 | if (rc >= ERROR_D32_FIRST && rc <= ERROR_D32_LAST)
|
---|
[5480] | 134 | npszErrMsg2 =
|
---|
[5283] | 135 | GetErrorMsg(
|
---|
[5480] | 136 | data.usRcInit32
|
---|
| 137 | + ERROR_PROB_SYM_D32_FIRST
|
---|
[5283] | 138 | - ERROR_D32_FIRST
|
---|
| 139 | );
|
---|
[4185] | 140 | }
|
---|
[847] | 141 | }
|
---|
[1467] | 142 | else
|
---|
[4164] | 143 | npszErrMsg = "Ring-0 init: DosDevIOCtl failed. rc=%d\n";
|
---|
[1467] | 144 | DosClose(hDev0);
|
---|
[847] | 145 | }
|
---|
| 146 | else
|
---|
[4164] | 147 | npszErrMsg = "Ring-0 init: DosOpen failed. rc=%d\n";
|
---|
[847] | 148 | }
|
---|
| 149 | else
|
---|
[4164] | 150 | npszErrMsg = ""; /* ProbeKrnl do its own complaining, but we need something here to indicate failure. */
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * Fill return data.
|
---|
| 154 | */
|
---|
| 155 | pRpOut->CodeEnd = (USHORT)&CODE16_INITSTART;
|
---|
| 156 | pRpOut->DataEnd = (USHORT)&DATA16_INITSTART;
|
---|
| 157 | pRpOut->BPBArray= NULL;
|
---|
[847] | 158 | pRpOut->Unit = 0;
|
---|
| 159 |
|
---|
[4164] | 160 | /*
|
---|
| 161 | * Any errors?, if so complain!
|
---|
| 162 | */
|
---|
[847] | 163 | if (npszErrMsg)
|
---|
| 164 | {
|
---|
[4164] | 165 | printf16(npszErrMsg, rc);
|
---|
[4185] | 166 | if (npszErrMsg2)
|
---|
| 167 | printf16("%s\n", npszErrMsg2);
|
---|
| 168 | pRpOut->Status = pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_GEN_FAILURE;
|
---|
[847] | 169 | }
|
---|
[6431] | 170 | printf16("\n");
|
---|
[847] | 171 |
|
---|
[4164] | 172 | /* Init is completed. */
|
---|
| 173 | fInitTime = FALSE;
|
---|
| 174 |
|
---|
| 175 | /* successful return */
|
---|
[847] | 176 | return pRpOut->rph.Status;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 | /**
|
---|
[4164] | 182 | * R0 16-bit initiation.
|
---|
[847] | 183 | * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
|
---|
[4185] | 184 | * @returns Status word. We don't fail on R0Init32 but forwards the result
|
---|
| 185 | * using the usRcInit32.
|
---|
| 186 | * @param pRp Generic IO Control request packet.
|
---|
[847] | 187 | */
|
---|
[4164] | 188 | USHORT NEAR R0Init16(PRP_GENIOCTL pRp)
|
---|
[847] | 189 | {
|
---|
| 190 | USHORT usRc = STATUS_DONE;
|
---|
| 191 | APIRET rc;
|
---|
| 192 |
|
---|
| 193 | /* First we're to get the DosTable2 stuff. */
|
---|
[2836] | 194 | rc = initGetDosTableData();
|
---|
[847] | 195 | if (rc == NO_ERROR)
|
---|
| 196 | {
|
---|
| 197 | ULONG cPages;
|
---|
| 198 | char hLockParm[12] = {0};
|
---|
| 199 | ULONG ulLinParm;
|
---|
| 200 | char hLockData[12] = {0};
|
---|
| 201 | ULONG ulLinData;
|
---|
| 202 |
|
---|
[4164] | 203 | /*
|
---|
| 204 | * Thunk the request packet and lock userdata.
|
---|
| 205 | */
|
---|
[847] | 206 | if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
|
---|
| 207 | &&
|
---|
| 208 | !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
|
---|
| 209 | )
|
---|
| 210 | {
|
---|
[2836] | 211 | if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
|
---|
[847] | 212 | ulLinParm, sizeof(D16R0INITPARAM),
|
---|
| 213 | (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
|
---|
| 214 | &&
|
---|
[2836] | 215 | !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
|
---|
[847] | 216 | ulLinData, sizeof(D16R0INITDATA),
|
---|
| 217 | (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
|
---|
| 218 | )
|
---|
[4164] | 219 | {
|
---|
| 220 | /*
|
---|
| 221 | * -data and param is locked (do we need to lock the request packet too ?).-
|
---|
| 222 | * Create new 32-bit init packet - Parameter pointer is thunked.
|
---|
| 223 | */
|
---|
[847] | 224 | RP32INIT rp32init;
|
---|
| 225 |
|
---|
| 226 | _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
|
---|
| 227 | if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
|
---|
| 228 | !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
|
---|
| 229 | )
|
---|
[4185] | 230 | { /* call 32-bit init routine and set 32 bit rc. */
|
---|
[847] | 231 | usRc = CallR0Init32(SSToDS_16(&rp32init));
|
---|
[4185] | 232 | ((PD16R0INITDATA)pRp->DataPacket)->usRcInit32 = usRc;
|
---|
| 233 |
|
---|
| 234 | /* set status to done (success). (R0Init32 RC is return as usRcInit32.) */
|
---|
| 235 | usRc = STATUS_DONE;
|
---|
[847] | 236 | }
|
---|
| 237 | else
|
---|
[4185] | 238 | usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
|
---|
[847] | 239 |
|
---|
| 240 |
|
---|
[4164] | 241 | /*
|
---|
[4185] | 242 | * finished - unlock data and parm;
|
---|
[4164] | 243 | */
|
---|
[847] | 244 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
|
---|
| 245 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
|
---|
| 246 | }
|
---|
| 247 | else
|
---|
[4185] | 248 | usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
|
---|
[847] | 249 | }
|
---|
| 250 | else
|
---|
[4185] | 251 | usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
|
---|
[847] | 252 | }
|
---|
| 253 | else
|
---|
[4185] | 254 | usRc |= STERR | ERROR_I24_GEN_FAILURE;
|
---|
[847] | 255 |
|
---|
| 256 | return usRc;
|
---|
| 257 | }
|
---|
[2836] | 258 |
|
---|
| 259 |
|
---|
| 260 |
|
---|
| 261 | /**
|
---|
| 262 | * Gets the data we need from the DosTables.
|
---|
| 263 | * This data is TKSSBase16, R0FlatCS16 and R0FlatDS16.
|
---|
| 264 | * @returns Same as DevHelp_GetDosVar.
|
---|
| 265 | * @status completely implemented.
|
---|
[4787] | 266 | * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
[2836] | 267 | * @remark If you are not sure if TKSSBase16 is set or not, call this.
|
---|
| 268 | * After R0Init16 is called TKSSBase16 _is_ set.
|
---|
| 269 | * IMPORTANT! This function must _not_ be called after the initiation of the second device driver!!!
|
---|
[4164] | 270 | * (Since this is init code not present after init...)
|
---|
[2836] | 271 | */
|
---|
[4164] | 272 | USHORT NEAR initGetDosTableData(void)
|
---|
[2836] | 273 | {
|
---|
| 274 | APIRET rc;
|
---|
| 275 | PDOSTABLE pDT;
|
---|
| 276 | PDOSTABLE2 pDT2;
|
---|
| 277 |
|
---|
| 278 | if (TKSSBase16 != 0)
|
---|
| 279 | return NO_ERROR;
|
---|
[4164] | 280 | /*
|
---|
| 281 | _asm {
|
---|
| 282 | int 3;
|
---|
| 283 | }
|
---|
| 284 | */
|
---|
[2836] | 285 |
|
---|
| 286 | /* First we're to get the DosTable2 stuff. */
|
---|
| 287 | rc = DevHelp_GetDOSVar(9, 0, &pDT);
|
---|
| 288 | if (rc == NO_ERROR)
|
---|
| 289 | {
|
---|
| 290 | pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
|
---|
| 291 | TKSSBase16 = (ULONG)pDT2->pTKSSBase;
|
---|
| 292 | R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
|
---|
| 293 | R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
|
---|
| 294 | }
|
---|
| 295 | return rc;
|
---|
| 296 | }
|
---|
[5283] | 297 |
|
---|