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

Last change on this file since 2836 was 2836, checked in by bird, 26 years ago

ProbKrnl and code for importing krnl symbols has been enhanched.
Now we'll lock 32-bit segments into memory too.
And some other fixes...

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