source: trunk/src/win32k/dev16/d16strat.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.5 KB
Line 
1/* $Id: d16strat.c,v 1.6 2000-02-21 04:45:45 bird Exp $
2 *
3 * d16strat.c - 16-bit strategy routine, device headers, device_helper (ptr)
4 * and 16-bit IOClts.
5 *
6 * Copyright (c) 1999 knut st. osmundsen
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*******************************************************************************
13* Defined Constants *
14*******************************************************************************/
15#define INCL_DOSERRORS
16#define INCL_NOPMAPI
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <os2.h>
22#include <devhdr.h>
23#include <devcmd.h>
24#include <strat2.h>
25#include <reqpkt.h>
26#include <dhcalls.h>
27
28/* Note that C-library function are only allowed during init! */
29
30#include "dev1632.h"
31#include "dev16.h"
32#include "win32k.h"
33
34
35/*******************************************************************************
36* Global Variables *
37*******************************************************************************/
38DDHDR aDevHdrs[2] = /* This is the first piece data in the driver!!!!!!! */
39{
40 {
41 (unsigned long)(void _far *)(&aDevHdrs[1]), /* NextHeader */
42 DEVLEV_3 | DEV_30 | DEV_CHAR_DEV, /* SDevAtt */
43 (unsigned short)(void _near *)strategyAsm0, /* StrategyEP */
44 0, /* InterruptEP */
45 "elf$ ", /* DevName */
46 0, /* SDevProtCS */
47 0, /* SDevProtDS */
48 0, /* SDevRealCS */
49 0, /* SDevRealDS */
50 DEV_16MB | DEV_IOCTL2 /* SDevCaps */
51 },
52 {
53 ~0UL, /* NextHeader */
54 DEVLEV_3 | DEV_30 | DEV_CHAR_DEV, /* SDevAtt */
55 (unsigned short)(void _near *)strategyAsm1, /* StrategyEP */
56 0, /* InterruptEP */
57 "win32k$ ", /* DevName */
58 0, /* SDevProtCS */
59 0, /* SDevProtDS */
60 0, /* SDevRealCS */
61 0, /* SDevRealDS */
62 DEV_16MB | DEV_IOCTL2 /* SDevCaps */
63 }
64};
65
66/* Note: All global variables must be initialized! *
67 * Uninitialized variables ends up in DATA32. */
68PFN Device_Help = NULL;
69ULONG TKSSBase16 = 0;
70USHORT R0FlatCS16 = 0;
71USHORT R0FlatDS16 = 0;
72BOOL fInitTime = TRUE;
73
74
75/*******************************************************************************
76* Internal Functions *
77*******************************************************************************/
78USHORT NEAR dev0GenIOCtl(PRP_GENIOCTL pRp);
79USHORT NEAR dev1GenIOCtl(PRP_GENIOCTL pRp);
80
81
82/**
83 * Strategy routine.
84 * @returns Status word.
85 * @param pRpH Pointer to request packed header. (Do not change the pointer!)
86 * @parma usDev Device number.
87 * @remark This function is called from the entrypoint in dev1st.asm
88 */
89USHORT NEAR strategy(PRPH pRpH, unsigned short usDev)
90{
91 switch (pRpH->Cmd)
92 {
93 case CMDInit: /* INIT command */
94 if (fInitTime)
95 {
96 if (usDev == 0)
97 return dev0Init((PRPINITIN)pRpH, (PRPINITOUT)pRpH);
98 else
99 return dev1Init((PRPINITIN)pRpH, (PRPINITOUT)pRpH);
100 }
101 break;
102
103 case CMDGenIOCTL: /* Generic IOCTL */
104 if (usDev == 0)
105 return dev0GenIOCtl((PRP_GENIOCTL)pRpH);
106 else
107 return dev1GenIOCtl((PRP_GENIOCTL)pRpH);
108
109 case CMDOpen: /* device open */
110 case CMDClose: /* device close */
111 case CMDDeInstall: /* De-Install driver */
112 case CMDShutdown:
113 return STATUS_DONE;
114 }
115
116 return STATUS_DONE | STATUS_ERR_UNKCMD;
117}
118
119extern char end;
120
121
122/**
123 * Generic I/O Control - device 0.
124 * This will only handle the request for Ring-0 initiation.
125 * @returns Status word.
126 * @param pRp Request packet.
127 */
128USHORT dev0GenIOCtl(PRP_GENIOCTL pRp)
129{
130 USHORT rc;
131 if (pRp->Category == D16_IOCTL_CAT)
132 {
133 switch (pRp->Function)
134 {
135 case D16_IOCTL_RING0INIT:
136 if (fInitTime)
137 {
138 rc = R0Init16(pRp);
139 fInitTime = FALSE;
140 return rc;
141 }
142 break;
143
144 case D16_IOCTL_GETKRNLOTES:
145 {
146 ULONG ulLin;
147 if (fInitTime && TKSSBase16 == 0)
148 initGetDosTableData();
149 if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
150 &ulLin) != NO_ERROR)
151 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
152 return CallGetOTEs32(ulLin);
153 }
154
155 case D16_IOCTL_VERIFYPROCTAB:
156 if (fInitTime)
157 {
158 if (TKSSBase16 == 0)
159 initGetDosTableData();
160 return CallVerifyImportTab32();
161 }
162 break;
163 }
164 }
165 else if (pRp->Category == IOCTL_W32K_K32 || pRp->Category == IOCTL_W32K_ELF)
166 {
167 RP32GENIOCTL rp32Init = {0};
168 rp32Init.rph.Len = pRp->rph.Len;
169 rp32Init.rph.Unit = pRp->rph.Unit;
170 rp32Init.rph.Cmd = pRp->rph.Cmd;
171 rp32Init.rph.Status = pRp->rph.Status;
172 rp32Init.rph.Flags = pRp->rph.Flags;
173 rp32Init.rph.Link = (ULONG)pRp->rph.Link;
174 rp32Init.Category = pRp->Category;
175 rp32Init.Function = pRp->Function;
176 rp32Init.sfn = pRp->sfn;
177 rp32Init.DataLen = pRp->DataLen;
178 rp32Init.ParmLen = pRp->ParmLen;
179
180 if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
181 (PLIN)&rp32Init.DataPacket) != NO_ERROR)
182 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
183 if (DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket),
184 (PLIN)&rp32Init.ParmPacket) != NO_ERROR)
185 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
186
187 if (pRp->Category == IOCTL_W32K_ELF)
188 rc = CallElfIOCtl(SSToDS_16a(&rp32Init));
189 else
190 rc = CallWin32kIOCtl(SSToDS_16a(&rp32Init));
191
192 return rc;
193 }
194
195
196 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
197}
198
199
200/**
201 * Generic I/O Control - device 0.
202 * This will forward requests to 32-bit counterpart.
203 * @returns Status word.
204 * @param pRp Request packet.
205 */
206USHORT dev1GenIOCtl(PRP_GENIOCTL pRp)
207{
208 if (pRp->Category == IOCTL_W32K_K32 || pRp->Category == IOCTL_W32K_ELF)
209 {
210 USHORT rc;
211 RP32GENIOCTL rp32Init = {0};
212 rp32Init.rph.Len = pRp->rph.Len;
213 rp32Init.rph.Unit = pRp->rph.Unit;
214 rp32Init.rph.Cmd = pRp->rph.Cmd;
215 rp32Init.rph.Status = pRp->rph.Status;
216 rp32Init.rph.Flags = pRp->rph.Flags;
217 rp32Init.rph.Link = (ULONG)pRp->rph.Link;
218 rp32Init.Category = pRp->Category;
219 rp32Init.Function = pRp->Function;
220 rp32Init.sfn = pRp->sfn;
221 rp32Init.DataLen = pRp->DataLen;
222 rp32Init.ParmLen = pRp->ParmLen;
223
224 if (DevHelp_VirtToLin(SELECTOROF(pRp->DataPacket), OFFSETOF(pRp->DataPacket),
225 (PLIN)&rp32Init.DataPacket) != NO_ERROR)
226 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
227 if (DevHelp_VirtToLin(SELECTOROF(pRp->ParmPacket), OFFSETOF(pRp->ParmPacket),
228 (PLIN)&rp32Init.ParmPacket) != NO_ERROR)
229 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
230
231 if (pRp->Category == IOCTL_W32K_ELF)
232 rc = CallElfIOCtl(SSToDS_16a(&rp32Init));
233 else
234 rc = CallWin32kIOCtl(SSToDS_16a(&rp32Init));
235
236 return rc;
237 }
238
239 return STATUS_DONE | STERR | ERROR_I24_INVALID_PARAMETER;
240}
241
Note: See TracBrowser for help on using the repository browser.