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

Last change on this file since 4164 was 4164, checked in by bird, 25 years ago

Merged in the Grace branch. New Win32k!

File size: 8.6 KB
Line 
1/* $Id: d16init.c,v 1.7 2000-09-02 21:07: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-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
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
101 /*
102 * Probe kernel data.
103 */
104 rc = ProbeKernel(pRpIn);
105 if (rc == NO_ERROR)
106 {
107 /*
108 * Open and send a Ring-0 init packet to elf$.
109 * If this succeeds win32k$ init succeeds.
110 */
111 rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
112 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
113 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
114 0UL);
115 if (rc == NO_ERROR)
116 {
117 param.pRpInitIn = pRpIn;
118 rc = DosDevIOCtl(&data, &param, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
119 if (rc == NO_ERROR)
120 {
121 if ((rc = data.Status) == STATUS_DONE)
122 {
123 if (!options.fQuiet)
124 printf16("Win32k.sys succesfully initiated!\n");
125 pRpOut->Status = pRpOut->rph.Status = data.Status;
126 }
127 else
128 npszErrMsg = "Ring-0 initiation failed. rc=%d\n";
129 }
130 else
131 npszErrMsg = "Ring-0 init: DosDevIOCtl failed. rc=%d\n";
132 DosClose(hDev0);
133 }
134 else
135 npszErrMsg = "Ring-0 init: DosOpen failed. rc=%d\n";
136 }
137 else
138 npszErrMsg = ""; /* ProbeKrnl do its own complaining, but we need something here to indicate failure. */
139
140 /*
141 * Fill return data.
142 */
143 pRpOut->CodeEnd = (USHORT)&CODE16_INITSTART;
144 pRpOut->DataEnd = (USHORT)&DATA16_INITSTART;
145 pRpOut->BPBArray= NULL;
146 pRpOut->Unit = 0;
147
148 /*
149 * Any errors?, if so complain!
150 */
151 if (npszErrMsg)
152 {
153 printf16(npszErrMsg, rc);
154 pRpOut->Status = pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
155 }
156
157 /* Init is completed. */
158 fInitTime = FALSE;
159
160 /* successful return */
161 return pRpOut->rph.Status;
162}
163
164
165
166/**
167 * R0 16-bit initiation.
168 * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
169 * @returns Status word.
170 * @param pRp Generic IO Control request packet.
171 */
172USHORT NEAR R0Init16(PRP_GENIOCTL pRp)
173{
174 USHORT usRc = STATUS_DONE;
175 APIRET rc;
176
177 /* First we're to get the DosTable2 stuff. */
178 rc = initGetDosTableData();
179 if (rc == NO_ERROR)
180 {
181 ULONG cPages;
182 char hLockParm[12] = {0};
183 ULONG ulLinParm;
184 char hLockData[12] = {0};
185 ULONG ulLinData;
186
187 /*
188 * Thunk the request packet and lock userdata.
189 */
190 if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
191 &&
192 !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
193 )
194 {
195 if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
196 ulLinParm, sizeof(D16R0INITPARAM),
197 (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
198 &&
199 !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE,
200 ulLinData, sizeof(D16R0INITDATA),
201 (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
202 )
203 {
204 /*
205 * -data and param is locked (do we need to lock the request packet too ?).-
206 * Create new 32-bit init packet - Parameter pointer is thunked.
207 */
208 RP32INIT rp32init;
209
210 _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
211 if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
212 !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
213 )
214 {
215 usRc = CallR0Init32(SSToDS_16(&rp32init));
216 }
217 else
218 usRc |= ERROR_I24_INVALID_PARAMETER;
219
220 ((PD16R0INITDATA)pRp->DataPacket)->Status = usRc;
221
222 /*
223 * finished - unlock data and parm
224 */
225 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
226 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
227 }
228 else
229 usRc |= ERROR_I24_INVALID_PARAMETER;
230 }
231 else
232 usRc |= ERROR_I24_INVALID_PARAMETER;
233 }
234 else
235 usRc |= ERROR_I24_GEN_FAILURE;
236
237 return usRc;
238}
239
240
241
242/**
243 * Gets the data we need from the DosTables.
244 * This data is TKSSBase16, R0FlatCS16 and R0FlatDS16.
245 * @returns Same as DevHelp_GetDosVar.
246 * @status completely implemented.
247 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
248 * @remark If you are not sure if TKSSBase16 is set or not, call this.
249 * After R0Init16 is called TKSSBase16 _is_ set.
250 * IMPORTANT! This function must _not_ be called after the initiation of the second device driver!!!
251 * (Since this is init code not present after init...)
252 */
253USHORT NEAR initGetDosTableData(void)
254{
255 APIRET rc;
256 PDOSTABLE pDT;
257 PDOSTABLE2 pDT2;
258
259 if (TKSSBase16 != 0)
260 return NO_ERROR;
261 /*
262 _asm {
263 int 3;
264 }
265 */
266
267 /* First we're to get the DosTable2 stuff. */
268 rc = DevHelp_GetDOSVar(9, 0, &pDT);
269 if (rc == NO_ERROR)
270 {
271 pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
272 TKSSBase16 = (ULONG)pDT2->pTKSSBase;
273 R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
274 R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
275 }
276 return rc;
277}
Note: See TracBrowser for help on using the repository browser.