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

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

Updated option/argument handling.
Corrected a few bugs.

File size: 7.2 KB
Line 
1/* $Id: d16init.c,v 1.3 1999-10-31 23:57:00 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 */
11
12/*******************************************************************************
13* Defined Constants *
14*******************************************************************************/
15#define INCL_16
16#define INCL_DOSFILEMGR
17#define INCL_DOSDEVICES
18#define INCL_DOSMISC
19#define INCL_DOSERRORS
20#define INCL_NOPMAPI
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <os2.h>
26#include <devhdr.h>
27#include <devcmd.h>
28#include <strat2.h>
29#include <reqpkt.h>
30#include <dhcalls.h>
31
32#include <string.h>
33#include <memory.h>
34
35#include "probkrnl.h"
36#include "dev1632.h"
37#include "dev16.h"
38
39/**
40 * init function - device 0.
41 * Does nothing else than setting the device_help variable and
42 * fill the request packet.
43 * @returns Status word.
44 * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
45 * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
46 * @remark pRpIn and pRpOut points to the same memory.
47 */
48USHORT _near dev0Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
49{
50 Device_Help = pRpIn->DevHlpEP;
51
52 pRpOut->BPBArray = NULL;
53 pRpOut->CodeEnd = (USHORT)&CODE16END;
54 pRpOut->DataEnd = (USHORT)&DATA16END;
55 pRpOut->Unit = 0;
56 pRpOut->rph.Status = STATUS_DONE;
57 return STATUS_DONE;
58}
59
60
61/**
62 * init function - device 1.
63 * We will send an IOCtl request to the elf$ (device 0) which will
64 * perform the Ring-0 initiation of the driver.
65 * @returns Status word.
66 * @param pRpIn Pointer to input request packet. Actually the same memory as pRpOut but another struct.
67 * @param pRpOut Pointer to output request packet. Actually the same memory as pRpIn but another struct.
68 * @remark pRpIn and pRpOut points to the same memory.
69 */
70USHORT _near dev1Init(PRPINITIN pRpIn, PRPINITOUT pRpOut)
71{
72 APIRET rc;
73 D16R0INITPARAM param;
74 D16R0INITDATA data = {0};
75 HFILE hDev0 = 0;
76 USHORT usAction = 0;
77 NPSZ npszErrMsg = NULL;
78
79 rc = ProbeKernel(pRpIn);
80 if (rc == NO_ERROR)
81 {
82 rc = DosOpen("\\dev\\elf$", &hDev0, &usAction, 0UL, FILE_NORMAL,
83 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
84 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
85 0UL);
86 if (rc == NO_ERROR)
87 {
88 param.pRpInitIn = pRpIn;
89 rc = DosDevIOCtl(&data, &param, D16_IOCTL_RING0INIT, D16_IOCTL_CAT, hDev0);
90 if (rc == NO_ERROR)
91 {
92 if (data.Status != STATUS_DONE)
93 npszErrMsg = "Ring-0 initiation failed\n\r";
94 else
95 {
96 /* FIXME quiet test! */
97 register NPSZ npsz = "Win32k.sys succesfully initiated!\n\r";
98 DosPutMessage(1, strlen(npsz)+1, npsz);
99 pRpOut->Status = data.Status;
100 }
101 }
102 else
103 npszErrMsg = "DosDevIOCtl failed.\n\r";
104 DosClose(hDev0);
105 }
106 else
107 npszErrMsg = "DosOpen failed.\n\r";
108 }
109 else
110 npszErrMsg = "ProbeKernel failed.\n\r";
111 pRpOut->BPBArray = NULL;
112 pRpOut->CodeEnd = (USHORT)&CODE16END;
113 pRpOut->DataEnd = (USHORT)&DATA16END;
114 pRpOut->Unit = 0;
115
116 if (npszErrMsg)
117 {
118 DosPutMessage(1, strlen(npszErrMsg) + 1, npszErrMsg);
119 return pRpOut->rph.Status = STATUS_DONE | STERR | ERROR_I24_QUIET_INIT_FAIL;
120 }
121
122 return pRpOut->rph.Status;
123}
124
125
126
127/**
128 * R0 16-bit initiation function.
129 * This gets TKSSBase, thunks parameters and calls R0 32-bit initiation function.
130 * @returns Status word.
131 * @param pRp Generic IO Control request packet.
132 */
133USHORT R0Init16(PRP_GENIOCTL pRp)
134{
135 USHORT usRc = STATUS_DONE;
136 APIRET rc;
137 PDOSTABLE pDT;
138 PDOSTABLE2 pDT2;
139
140 /* First we're to get the DosTable2 stuff. */
141 rc = DevHelp_GetDOSVar(9, 0, &pDT);
142 if (rc == NO_ERROR)
143 {
144 ULONG cPages;
145 char hLockParm[12] = {0};
146 ULONG ulLinParm;
147 char hLockData[12] = {0};
148 ULONG ulLinData;
149
150 pDT2 = (PDOSTABLE2)((char FAR *)pDT + pDT->cul*4 + 1);
151 TKSSBase16 = (ULONG)pDT2->pTKSSBase;
152 R0FlatCS16 = (USHORT)pDT2->R0FlatCS;
153 R0FlatDS16 = (USHORT)pDT2->R0FlatDS;
154 if (!DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket), &ulLinParm)
155 &&
156 !DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket), &ulLinData)
157 )
158 {
159 if (!(rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
160 ulLinParm, sizeof(D16R0INITPARAM),
161 (LIN)~0UL, SSToDS_16(&hLockParm[0]), &cPages))
162 &&
163 !DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
164 ulLinData, sizeof(D16R0INITDATA),
165 (LIN)~0UL, SSToDS_16(&hLockData[0]), &cPages)
166 )
167 { /* data and param is locked (do we need to lock the request packet too ?). */
168 /* create new 32-bit packet */
169 RP32INIT rp32init;
170
171 _fmemcpy(&rp32init, ((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn, sizeof(RPINITIN));
172 if (((PD16R0INITPARAM)pRp->ParmPacket)->pRpInitIn->InitArgs == NULL ||
173 !DevHelp_VirtToLin(SELECTOROF(rp32init.InitArgs), OFFSETOF(rp32init.InitArgs), (PLIN)&rp32init.InitArgs)
174 )
175 {
176 usRc = CallR0Init32(SSToDS_16(&rp32init));
177 }
178 else
179 usRc |= ERROR_I24_INVALID_PARAMETER;
180
181 ((PD16R0INITDATA)pRp->DataPacket)->Status = usRc;
182
183 /* finished - unlock data and parm */
184 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockParm[0]));
185 DevHelp_VMUnLock((LIN)SSToDS_16(&hLockData[0]));
186 }
187 else
188 usRc |= ERROR_I24_INVALID_PARAMETER;
189 }
190 else
191 usRc |= ERROR_I24_INVALID_PARAMETER;
192 }
193 else
194 usRc |= ERROR_I24_GEN_FAILURE;
195
196
197 #if 0
198 rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_WRITE | VMDHL_VERIFY,
199 &DATA32START,
200 (ULONG)(&end) - (ULONG)&DATA32START),
201 (void*)-1,
202 &lock[0],
203 &cPages);
204
205 rc = DevHelp_VMLock(VMDHL_LONG | VMDHL_VERIFY,
206 &CODE32START,
207 (ULONG)(&CODE32END) - (ULONG)&CODE32START),
208 (void*)-1,
209 &lock[0],
210 &cPages);
211 #endif
212
213 return usRc;
214}
Note: See TracBrowser for help on using the repository browser.