source: trunk/src/win32k/dev16/d16init.c@ 6431

Last change on this file since 6431 was 6431, checked in by bird, 24 years ago

Added a newline.

File size: 9.4 KB
Line 
1/* $Id: d16init.c,v 1.12 2001-07-31 21:36:37 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 * completed. CodeEnd and DataEnd should not be set here.?
7 *
8 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
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 "devSegDf.h"
39#undef DATA16_INIT
40#define DATA16_INIT
41#undef CODE16_INIT
42#define CODE16_INIT
43#include "probkrnl.h"
44#include "dev1632.h"
45#include "dev16.h"
46#include "vprntf16.h"
47#include "log.h"
48#include "options.h"
49#include "errors.h"
50
51
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 */
61USHORT NEAR dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
62{
63 APIRET rc;
64 Device_Help = pRpIn->DevHlpEP;
65
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
74 pRpOut->BPBArray = NULL;
75 pRpOut->CodeEnd = (USHORT)&CODE16_INITSTART;
76 pRpOut->DataEnd = (USHORT)&DATA16_INITSTART;
77 pRpOut->Unit = 0;
78 pRpOut->rph.Status = STATUS_DONE;
79 return STATUS_DONE;
80}
81
82
83/**
84 * init function - device 1.
85 * We will send an IOCtl request to the elf$ (device 0) which will
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 */
92USHORT NEAR dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
93{
94 APIRET rc;
95 D16R0INITPARAM param;
96 D16R0INITDATA data = {0};
97 HFILE hDev0 = 0;
98 USHORT usAction = 0;
99 NPSZ npszErrMsg = NULL;
100 const char * npszErrMsg2 = NULL;
101
102 /*
103 * Probe kernel data.
104 */
105 rc = ProbeKernel(pRpIn);
106 if (rc == NO_ERROR)
107 {
108 /*
109 * Open and send a Ring-0 init packet to elf$.
110 * If this succeeds win32k$ init succeeds.
111 */
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);
116 if (rc == NO_ERROR)
117 {
118 param.pRpInitIn = pRpIn;
119 rc = DosDevIOCtl(&data, &param, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
120 if (rc == NO_ERROR)
121 {
122 if (data.usRcInit32 == NO_ERROR)
123 {
124 if (!options.fQuiet)
125 printf16("Win32k.sys successfully initiated!\n");
126 pRpOut->Status = pRpOut->rph.Status = STATUS_DONE;
127 }
128 else
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)
134 npszErrMsg2 =
135 GetErrorMsg(
136 data.usRcInit32
137 + ERROR_PROB_SYM_D32_FIRST
138 - ERROR_D32_FIRST
139 );
140 }
141 }
142 else
143 npszErrMsg = "Ring-0 init: DosDevIOCtl failed. rc=%d\n";
144 DosClose(hDev0);
145 }
146 else
147 npszErrMsg = "Ring-0 init: DosOpen failed. rc=%d\n";
148 }
149 else
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;
158 pRpOut->Unit = 0;
159
160 /*
161 * Any errors?, if so complain!
162 */
163 if (npszErrMsg)
164 {
165 printf16(npszErrMsg, rc);
166 if (npszErrMsg2)
167 printf16("%s\n", npszErrMsg2);
168 pRpOut->Status = pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_GEN_FAILURE;
169 }
170 printf16("\n");
171
172 /* Init is completed. */
173 fInitTime = FALSE;
174
175 /* successful return */
176 return pRpOut->rph.Status;
177}
178
179
180
181/**
182 * R0 16-bit initiation.
183 * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
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.
187 */
188USHORT NEAR R0Init16(PRP_GENIOCTL pRp)
189{
190 USHORT usRc = STATUS_DONE;
191 APIRET rc;
192
193 /* First we're to get the DosTable2 stuff. */
194 rc = initGetDosTableData();
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
203 /*
204 * Thunk the request packet and lock userdata.
205 */
206 if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
207 &&
208 !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
209 )
210 {
211 if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
212 ulLinParm, sizeof(D16R0INITPARAM),
213 (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
214 &&
215 !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
216 ulLinData, sizeof(D16R0INITDATA),
217 (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
218 )
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 */
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 )
230 { /* call 32-bit init routine and set 32 bit rc. */
231 usRc = CallR0Init32(SSToDS_16(&rp32init));
232 ((PD16R0INITDATA)pRp->DataPacket)->usRcInit32 = usRc;
233
234 /* set status to done (success). (R0Init32 RC is return as usRcInit32.) */
235 usRc = STATUS_DONE;
236 }
237 else
238 usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
239
240
241 /*
242 * finished - unlock data and parm;
243 */
244 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
245 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
246 }
247 else
248 usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
249 }
250 else
251 usRc |= STERR | ERROR_I24_INVALID_PARAMETER;
252 }
253 else
254 usRc |= STERR | ERROR_I24_GEN_FAILURE;
255
256 return usRc;
257}
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.
266 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
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!!!
270 * (Since this is init code not present after init...)
271 */
272USHORT NEAR initGetDosTableData(void)
273{
274 APIRET rc;
275 PDOSTABLE pDT;
276 PDOSTABLE2 pDT2;
277
278 if (TKSSBase16 != 0)
279 return NO_ERROR;
280 /*
281 _asm {
282 int 3;
283 }
284 */
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}
297
Note: See TracBrowser for help on using the repository browser.