| 1 | /* $Id: d16strat.c,v 1.8 2000-02-25 18:15:02 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * d16strat.c - 16-bit strategy routine, device headers, device_helper (ptr)
|
|---|
| 4 | * and 16-bit IOClts.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 1999 knut st. osmundsen
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | /*******************************************************************************
|
|---|
| 13 | * Defined Constants *
|
|---|
| 14 | *******************************************************************************/
|
|---|
| 15 | #define INCL_DOSERRORS
|
|---|
| 16 | #define INCL_NOPMAPI
|
|---|
| 17 |
|
|---|
| 18 | /*******************************************************************************
|
|---|
| 19 | * Header Files *
|
|---|
| 20 | *******************************************************************************/
|
|---|
| 21 | #include <os2.h>
|
|---|
| 22 | #include <devhdr.h>
|
|---|
| 23 | #include <devcmd.h>
|
|---|
| 24 | #include <strat2.h>
|
|---|
| 25 | #include <reqpkt.h>
|
|---|
| 26 | #include <dhcalls.h>
|
|---|
| 27 |
|
|---|
| 28 | /* Note that C-library function are only allowed during init! */
|
|---|
| 29 |
|
|---|
| 30 | #include "dev1632.h"
|
|---|
| 31 | #include "dev16.h"
|
|---|
| 32 | #include "win32k.h"
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | /*******************************************************************************
|
|---|
| 36 | * Global Variables *
|
|---|
| 37 | *******************************************************************************/
|
|---|
| 38 | DDHDR aDevHdrs[2] = /* This is the first piece data in the driver!!!!!!! */
|
|---|
| 39 | {
|
|---|
| 40 | {
|
|---|
| 41 | (unsigned long)(void _far *)(&aDevHdrs[1]), /* NextHeader */
|
|---|
| 42 | DEVLEV_3 | DEV_30 | DEV_CHAR_DEV, /* SDevAtt */
|
|---|
| 43 | (unsigned short)(void _near *)strategyAsm0, /* StrategyEP */
|
|---|
| 44 | 0, /* InterruptEP */
|
|---|
| 45 | "elf$ ", /* DevName */
|
|---|
| 46 | 0, /* SDevProtCS */
|
|---|
| 47 | 0, /* SDevProtDS */
|
|---|
| 48 | 0, /* SDevRealCS */
|
|---|
| 49 | 0, /* SDevRealDS */
|
|---|
| 50 | DEV_16MB | DEV_IOCTL2 /* SDevCaps */
|
|---|
| 51 | },
|
|---|
| 52 | {
|
|---|
| 53 | ~0UL, /* NextHeader */
|
|---|
| 54 | DEVLEV_3 | DEV_30 | DEV_CHAR_DEV, /* SDevAtt */
|
|---|
| 55 | (unsigned short)(void _near *)strategyAsm1, /* StrategyEP */
|
|---|
| 56 | 0, /* InterruptEP */
|
|---|
| 57 | "win32k$ ", /* DevName */
|
|---|
| 58 | 0, /* SDevProtCS */
|
|---|
| 59 | 0, /* SDevProtDS */
|
|---|
| 60 | 0, /* SDevRealCS */
|
|---|
| 61 | 0, /* SDevRealDS */
|
|---|
| 62 | DEV_16MB | DEV_IOCTL2 /* SDevCaps */
|
|---|
| 63 | }
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | /*******************************************************************************
|
|---|
| 69 | * Internal Functions *
|
|---|
| 70 | *******************************************************************************/
|
|---|
| 71 | USHORT NEAR dev0GenIOCtl(PRP_GENIOCTL pRp);
|
|---|
| 72 | USHORT NEAR dev1GenIOCtl(PRP_GENIOCTL pRp);
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | /**
|
|---|
| 76 | * Strategy routine.
|
|---|
| 77 | * @returns Status word.
|
|---|
| 78 | * @param pRpH Pointer to request packed header. (Do not change the pointer!)
|
|---|
| 79 | * @parma usDev Device number.
|
|---|
| 80 | * @remark This function is called from the entrypoint in dev1st.asm
|
|---|
| 81 | */
|
|---|
| 82 | USHORT NEAR strategy(PRPH pRpH, unsigned short usDev)
|
|---|
| 83 | {
|
|---|
| 84 | switch (pRpH->Cmd)
|
|---|
| 85 | {
|
|---|
| 86 | case CMDInit: /* INIT command */
|
|---|
| 87 | if (fInitTime)
|
|---|
| 88 | {
|
|---|
| 89 | if (usDev == 0)
|
|---|
| 90 | return dev0Init((PRPINITIN)pRpH, (PRPINITOUT)pRpH);
|
|---|
| 91 | else
|
|---|
| 92 | return dev1Init((PRPINITIN)pRpH, (PRPINITOUT)pRpH);
|
|---|
| 93 | }
|
|---|
| 94 | break;
|
|---|
| 95 |
|
|---|
| 96 | case CMDGenIOCTL: /* Generic IOCTL */
|
|---|
| 97 | if (usDev == 0)
|
|---|
| 98 | return dev0GenIOCtl((PRP_GENIOCTL)pRpH);
|
|---|
| 99 | else
|
|---|
| 100 | return dev1GenIOCtl((PRP_GENIOCTL)pRpH);
|
|---|
| 101 |
|
|---|
| 102 | case CMDOpen: /* device open */
|
|---|
| 103 | case CMDClose: /* device close */
|
|---|
| 104 | case CMDDeInstall: /* De-Install driver */
|
|---|
| 105 | case CMDShutdown:
|
|---|
| 106 | return STATUS_DONE;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | return STATUS_DONE | STATUS_ERR_UNKCMD;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | extern char end;
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | * Generic I/O Control - device 0.
|
|---|
| 117 | * This will only handle the request for Ring-0 initiation.
|
|---|
| 118 | * @returns Status word.
|
|---|
| 119 | * @param pRp Request packet.
|
|---|
| 120 | */
|
|---|
| 121 | USHORT dev0GenIOCtl(PRP_GENIOCTL pRp)
|
|---|
| 122 | {
|
|---|
| 123 | USHORT rc;
|
|---|
| 124 |
|
|---|
| 125 | if (pRp->Category == D16_IOCTL_CAT)
|
|---|
| 126 | {
|
|---|
| 127 | switch (pRp->Function)
|
|---|
| 128 | {
|
|---|
| 129 | /*
|
|---|
| 130 | * This is the IOCtl which does the R0-initiation of the device driver.
|
|---|
| 131 | * Only available at init time...
|
|---|
| 132 | */
|
|---|
| 133 | case D16_IOCTL_RING0INIT:
|
|---|
| 134 | if (fInitTime)
|
|---|
| 135 | {
|
|---|
| 136 | rc = R0Init16(pRp);
|
|---|
| 137 | fInitTime = FALSE;
|
|---|
| 138 | return rc;
|
|---|
| 139 | }
|
|---|
| 140 | break;
|
|---|
| 141 |
|
|---|
| 142 | /*
|
|---|
| 143 | * This is the IOCtl collects info of the running kernel.
|
|---|
| 144 | * Only available at init time.
|
|---|
| 145 | *
|
|---|
| 146 | * Since this IOCtl is issued before R0-Init is done, we'll have to
|
|---|
| 147 | * init TKSSBase for both 16-bit and 32-bit code and be a bit carefull.
|
|---|
| 148 | */
|
|---|
| 149 | case D16_IOCTL_GETKRNLINFO:
|
|---|
| 150 | if (fInitTime)
|
|---|
| 151 | {
|
|---|
| 152 | ULONG ulLin;
|
|---|
| 153 | if (fInitTime && TKSSBase16 == 0)
|
|---|
| 154 | initGetDosTableData();
|
|---|
| 155 | if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
|
|---|
| 156 | &ulLin) != NO_ERROR)
|
|---|
| 157 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 158 | return CallGetKernelInfo32(ulLin);
|
|---|
| 159 | }
|
|---|
| 160 | break;
|
|---|
| 161 |
|
|---|
| 162 | /*
|
|---|
| 163 | * This is the IOCtl verifies the data in the ImportTab.
|
|---|
| 164 | * Only available at init time.
|
|---|
| 165 | *
|
|---|
| 166 | * Since this IOCtl is issued before R0-Init is done, we'll have to
|
|---|
| 167 | * init TKSSBase for both 16-bit and 32-bit code and be a bit carefull.
|
|---|
| 168 | */
|
|---|
| 169 | case D16_IOCTL_VERIFYIMPORTTAB:
|
|---|
| 170 | if (fInitTime)
|
|---|
| 171 | {
|
|---|
| 172 | if (TKSSBase16 == 0)
|
|---|
| 173 | initGetDosTableData();
|
|---|
| 174 | return CallVerifyImportTab32();
|
|---|
| 175 | }
|
|---|
| 176 | break;
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | else if (pRp->Category == IOCTL_W32K_K32 || pRp->Category == IOCTL_W32K_ELF)
|
|---|
| 180 | {
|
|---|
| 181 | RP32GENIOCTL rp32Init = {0};
|
|---|
| 182 | rp32Init.rph.Len = pRp->rph.Len;
|
|---|
| 183 | rp32Init.rph.Unit = pRp->rph.Unit;
|
|---|
| 184 | rp32Init.rph.Cmd = pRp->rph.Cmd;
|
|---|
| 185 | rp32Init.rph.Status = pRp->rph.Status;
|
|---|
| 186 | rp32Init.rph.Flags = pRp->rph.Flags;
|
|---|
| 187 | rp32Init.rph.Link = (ULONG)pRp->rph.Link;
|
|---|
| 188 | rp32Init.Category = pRp->Category;
|
|---|
| 189 | rp32Init.Function = pRp->Function;
|
|---|
| 190 | rp32Init.sfn = pRp->sfn;
|
|---|
| 191 | rp32Init.DataLen = pRp->DataLen;
|
|---|
| 192 | rp32Init.ParmLen = pRp->ParmLen;
|
|---|
| 193 |
|
|---|
| 194 | if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
|
|---|
| 195 | (PLIN)&rp32Init.DataPacket) != NO_ERROR)
|
|---|
| 196 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 197 | if (DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket),
|
|---|
| 198 | (PLIN)&rp32Init.ParmPacket) != NO_ERROR)
|
|---|
| 199 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 200 |
|
|---|
| 201 | if (pRp->Category == IOCTL_W32K_ELF)
|
|---|
| 202 | rc = CallElfIOCtl(SSToDS_16a(&rp32Init));
|
|---|
| 203 | else
|
|---|
| 204 | rc = CallWin32kIOCtl(SSToDS_16a(&rp32Init));
|
|---|
| 205 |
|
|---|
| 206 | return rc;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | /**
|
|---|
| 215 | * Generic I/O Control - device 0.
|
|---|
| 216 | * This will forward requests to 32-bit counterpart.
|
|---|
| 217 | * @returns Status word.
|
|---|
| 218 | * @param pRp Request packet.
|
|---|
| 219 | */
|
|---|
| 220 | USHORT dev1GenIOCtl(PRP_GENIOCTL pRp)
|
|---|
| 221 | {
|
|---|
| 222 | if (pRp->Category == IOCTL_W32K_K32 || pRp->Category == IOCTL_W32K_ELF)
|
|---|
| 223 | {
|
|---|
| 224 | USHORT rc;
|
|---|
| 225 | RP32GENIOCTL rp32Init = {0};
|
|---|
| 226 | rp32Init.rph.Len = pRp->rph.Len;
|
|---|
| 227 | rp32Init.rph.Unit = pRp->rph.Unit;
|
|---|
| 228 | rp32Init.rph.Cmd = pRp->rph.Cmd;
|
|---|
| 229 | rp32Init.rph.Status = pRp->rph.Status;
|
|---|
| 230 | rp32Init.rph.Flags = pRp->rph.Flags;
|
|---|
| 231 | rp32Init.rph.Link = (ULONG)pRp->rph.Link;
|
|---|
| 232 | rp32Init.Category = pRp->Category;
|
|---|
| 233 | rp32Init.Function = pRp->Function;
|
|---|
| 234 | rp32Init.sfn = pRp->sfn;
|
|---|
| 235 | rp32Init.DataLen = pRp->DataLen;
|
|---|
| 236 | rp32Init.ParmLen = pRp->ParmLen;
|
|---|
| 237 |
|
|---|
| 238 | if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
|
|---|
| 239 | (PLIN)&rp32Init.DataPacket) != NO_ERROR)
|
|---|
| 240 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 241 | if (DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket),
|
|---|
| 242 | (PLIN)&rp32Init.ParmPacket) != NO_ERROR)
|
|---|
| 243 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 244 |
|
|---|
| 245 | if (pRp->Category == IOCTL_W32K_ELF)
|
|---|
| 246 | rc = CallElfIOCtl(SSToDS_16a(&rp32Init));
|
|---|
| 247 | else
|
|---|
| 248 | rc = CallWin32kIOCtl(SSToDS_16a(&rp32Init));
|
|---|
| 249 |
|
|---|
| 250 | return rc;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|