1 | /* $Id: d16init.c,v 1.6 2000-02-25 18:15:02 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 | /*******************************************************************************
|
---|
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 |
|
---|
38 | #include "probkrnl.h"
|
---|
39 | #include "dev1632.h"
|
---|
40 | #include "dev16.h"
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * init function - device 0.
|
---|
44 | * Does nothing else than setting the device_help variable and
|
---|
45 | * fill the request packet.
|
---|
46 | * @returns Status word.
|
---|
47 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
---|
48 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
---|
49 | * @remark pRpIn and pRpOut points to the same memory.
|
---|
50 | */
|
---|
51 | USHORT NEAR dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
---|
52 | {
|
---|
53 | Device_Help = pRpIn->DevHlpEP;
|
---|
54 |
|
---|
55 | pRpOut->BPBArray = NULL;
|
---|
56 | pRpOut->CodeEnd = (USHORT)&CODE16END;
|
---|
57 | pRpOut->DataEnd = (USHORT)&DATA16END;
|
---|
58 | pRpOut->Unit = 0;
|
---|
59 | pRpOut->rph.Status = STATUS_DONE;
|
---|
60 | return STATUS_DONE;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * init function - device 1.
|
---|
66 | * We will send an IOCtl request to the elf$ (device 0) which will
|
---|
67 | * perform the Ring-0 initiation of the driver.
|
---|
68 | * @returns Status word.
|
---|
69 | * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
|
---|
70 | * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
|
---|
71 | * @remark pRpIn and pRpOut points to the same memory.
|
---|
72 | */
|
---|
73 | USHORT NEAR dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
|
---|
74 | {
|
---|
75 | APIRET rc;
|
---|
76 | D16R0INITPARAM param;
|
---|
77 | D16R0INITDATA data = {0};
|
---|
78 | HFILE hDev0 = 0;
|
---|
79 | USHORT usAction = 0;
|
---|
80 | NPSZ npszErrMsg = NULL;
|
---|
81 |
|
---|
82 | rc = ProbeKernel(pRpIn);
|
---|
83 | if (rc == NO_ERROR)
|
---|
84 | {
|
---|
85 | rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
|
---|
86 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
87 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
|
---|
88 | 0UL);
|
---|
89 | if (rc == NO_ERROR)
|
---|
90 | {
|
---|
91 | param.pRpInitIn = pRpIn;
|
---|
92 | rc = DosDevIOCtl(&data, ¶m, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
|
---|
93 | if (rc == NO_ERROR)
|
---|
94 | {
|
---|
95 | if (data.Status != STATUS_DONE)
|
---|
96 | npszErrMsg = "Ring-0 initiation failed\n\r";
|
---|
97 | else
|
---|
98 | {
|
---|
99 | /* FIXME quiet test! */
|
---|
100 | register NPSZ npsz = "Win32k.sys succesfully initiated!\n\r";
|
---|
101 | DosPutMessage(1, strlen(npsz)+1, npsz);
|
---|
102 | pRpOut->Status = data.Status;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | else
|
---|
106 | {
|
---|
107 | APIRET rc2 = rc;
|
---|
108 | NPSZ npsz;
|
---|
109 | /*0123456789012345678901234567890 1*/
|
---|
110 | npszErrMsg = "DosDevIOCtl failed. rc= \n\r";
|
---|
111 |
|
---|
112 | npsz = &npszErrMsg[29];
|
---|
113 | do
|
---|
114 | {
|
---|
115 | *npsz-- = (char)((rc2 % 10) + '0');
|
---|
116 | rc2 = rc2/10;
|
---|
117 | } while (rc2 > 0);
|
---|
118 | }
|
---|
119 |
|
---|
120 | DosClose(hDev0);
|
---|
121 | }
|
---|
122 | else
|
---|
123 | npszErrMsg = "DosOpen failed.\n\r";
|
---|
124 | }
|
---|
125 | else
|
---|
126 | npszErrMsg = "ProbeKernel failed.\n\r";
|
---|
127 | pRpOut->BPBArray = NULL;
|
---|
128 | pRpOut->CodeEnd = (USHORT)&CODE16END;
|
---|
129 | pRpOut->DataEnd = (USHORT)&DATA16END;
|
---|
130 | pRpOut->Unit = 0;
|
---|
131 |
|
---|
132 | if (npszErrMsg)
|
---|
133 | {
|
---|
134 | DosPutMessage(1, strlen(npszErrMsg) + 1, npszErrMsg);
|
---|
135 | return pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
|
---|
136 | }
|
---|
137 |
|
---|
138 | return pRpOut->rph.Status;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * R0 16-bit initiation function.
|
---|
145 | * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
|
---|
146 | * @returns Status word.
|
---|
147 | * @param pRp Generic IO Control request packet.
|
---|
148 | */
|
---|
149 | USHORT NEAR R0Init16(PRP_GENIOCTL pRp)
|
---|
150 | {
|
---|
151 | USHORT usRc = STATUS_DONE;
|
---|
152 | APIRET rc;
|
---|
153 |
|
---|
154 | /* First we're to get the DosTable2 stuff. */
|
---|
155 | rc = initGetDosTableData();
|
---|
156 | if (rc == NO_ERROR)
|
---|
157 | {
|
---|
158 | ULONG cPages;
|
---|
159 | char hLockParm[12] = {0};
|
---|
160 | ULONG ulLinParm;
|
---|
161 | char hLockData[12] = {0};
|
---|
162 | ULONG ulLinData;
|
---|
163 |
|
---|
164 | if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
|
---|
165 | &&
|
---|
166 | !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
|
---|
167 | )
|
---|
168 | {
|
---|
169 | if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
|
---|
170 | ulLinParm, sizeof(D16R0INITPARAM),
|
---|
171 | (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
|
---|
172 | &&
|
---|
173 | !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
|
---|
174 | ulLinData, sizeof(D16R0INITDATA),
|
---|
175 | (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
|
---|
176 | )
|
---|
177 | { /* data and param is locked (do we need to lock the request packet too ?). */
|
---|
178 | /* create new 32-bit packet */
|
---|
179 | RP32INIT rp32init;
|
---|
180 |
|
---|
181 | _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
|
---|
182 | if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
|
---|
183 | !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
|
---|
184 | )
|
---|
185 | {
|
---|
186 | usRc = CallR0Init32(SSToDS_16(&rp32init));
|
---|
187 | }
|
---|
188 | else
|
---|
189 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
---|
190 |
|
---|
191 | ((PD16R0INITDATA)pRp->DataPacket)->Status = usRc;
|
---|
192 |
|
---|
193 | /* finished - unlock data and parm */
|
---|
194 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
|
---|
195 | DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
|
---|
196 | }
|
---|
197 | else
|
---|
198 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
---|
199 | }
|
---|
200 | else
|
---|
201 | usRc |= ERROR_I24_INVALID_PARAMETER;
|
---|
202 | }
|
---|
203 | else
|
---|
204 | usRc |= ERROR_I24_GEN_FAILURE;
|
---|
205 |
|
---|
206 |
|
---|
207 | #if 0
|
---|
208 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
|
---|
209 | &DATA32START,
|
---|
210 | (ULONG)(&end) - (ULONG)&DATA32START),
|
---|
211 | (void*)-1,
|
---|
212 | &lock[0],
|
---|
213 | &cPages);
|
---|
214 |
|
---|
215 | rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_VERIFY,
|
---|
216 | &CODE32START,
|
---|
217 | (ULONG)(&CODE32END) - (ULONG)&CODE32START),
|
---|
218 | (void*)-1,
|
---|
219 | &lock[0],
|
---|
220 | &cPages);
|
---|
221 | #endif
|
---|
222 |
|
---|
223 | return usRc;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 | /**
|
---|
229 | * Gets the data we need from the DosTables.
|
---|
230 | * This data is TKSSBase16, R0FlatCS16 and R0FlatDS16.
|
---|
231 | * @returns Same as DevHelp_GetDosVar.
|
---|
232 | * @status completely implemented.
|
---|
233 | * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
234 | * @remark If you are not sure if TKSSBase16 is set or not, call this.
|
---|
235 | * After R0Init16 is called TKSSBase16 _is_ set.
|
---|
236 | * IMPORTANT! This function must _not_ be called after the initiation of the second device driver!!!
|
---|
237 | */
|
---|
238 | USHORT NEAR initGetDosTableData(void)
|
---|
239 | {
|
---|
240 | APIRET rc;
|
---|
241 | PDOSTABLE pDT;
|
---|
242 | PDOSTABLE2 pDT2;
|
---|
243 |
|
---|
244 | if (TKSSBase16 != 0)
|
---|
245 | return NO_ERROR;
|
---|
246 |
|
---|
247 | /* First we're to get the DosTable2 stuff. */
|
---|
248 | rc = DevHelp_GetDOSVar(9, 0, &pDT);
|
---|
249 | if (rc == NO_ERROR)
|
---|
250 | {
|
---|
251 | pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
|
---|
252 | TKSSBase16 = (ULONG)pDT2->pTKSSBase;
|
---|
253 | R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
|
---|
254 | R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
|
---|
255 | }
|
---|
256 | return rc;
|
---|
257 | }
|
---|