1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/* $XConsortium: OS_Os2.c /main/7 1996/10/27 11:46:26 kaleb $ */
/*
* (c) Copyright 1994 by Holger Veit
* <Holger.Veit@gmd.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Holger Veit shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Holger Veit.
*
*/
/* $XFree86: xc/programs/Xserver/hw/xfree86/SuperProbe/OS_Os2.c,v 3.8 1997/03/10 10:11:39 hohndel Exp $ */
#include "Probe.h"
#define INCL_32
#define INCL_DOS
#include <os2.h>
#define UNUSED (Byte*)0xffffffffl
HFILE consFd = -1;
ULONG action;
char *videoDrvPath = "/dev/pmap$";
char *ioDrvPath = "/dev/fastio$";
Byte* videoAddr = UNUSED;
ULONG videoSize = 0x10000;
int ioenabled = FALSE;
static void sorry()
{
fprintf(stderr,
"Didn't find a properly installed XF86SUP.SYS at your system\n");
fprintf(stderr,"Please install it before retrying\n");
}
/*
* OpenVideo --
*
* Enable access to the installed video hardware. For OS/2, we take
* advantage of the driver xf86sup.sys which was specifically written
* for XFree86/OS2.
*
* At this point we also try to weed out systems with outdated EMX code.
*/
int OpenVideo()
{
ULONG rc;
HMODULE hmod;
char name[CCHMAXPATH];
char fail[9];
if (DosOpen((PSZ)videoDrvPath, (PHFILE)&consFd, (PULONG)&action,
(ULONG)0, FILE_SYSTEM, FILE_OPEN,
OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
(ULONG)0) != 0) {
sorry();
exit(2);
}
/* check for correct EMX */
if (_emx_rev < 50) {
fputs ("This program requires emx.dll revision 50 (0.9c) "
"or later.\n", stderr);
rc = DosLoadModule (fail, sizeof (fail), "emx", &hmod);
if (rc == 0) {
rc = DosQueryModuleName (hmod, sizeof (name), name);
if (rc == 0)
fprintf (stderr, "Please delete or update `%s'.\n", name);
DosFreeModule (hmod);
}
exit (2);
}
return 1;
}
/* this structure is used as a parameter packet for the direct access
* to physical memory
*/
typedef struct {
ULONG addr; /* PHYSADDR for map, VIRTADDR for unmap */
ULONG size;
} DIOParPkt;
/* this structure is used as a return value for the direct access ioctl
* to physical memory
*/
typedef struct {
ULONG addr;
USHORT sel;
} DIODtaPkt;
static Byte* UnmapPhys(Byte* addr,ULONG size)
{
DIOParPkt par;
ULONG plen;
par.addr = (ULONG)addr;
par.size = size;
plen = sizeof(par);
if (consFd != -1)
DosDevIOCtl(consFd, (ULONG)0x76, (ULONG)0x45,
(PVOID)&par, (ULONG)plen, (PULONG)&plen,
NULL, 0, NULL);
return UNUSED; /* no error */
}
/*
* CloseVideo --
*
* Disable access to the video hardware.
*/
void CloseVideo()
{
if (videoAddr != UNUSED)
videoAddr = UnmapPhys(videoAddr,videoSize);
DosClose(consFd);
}
/*
* MapVGA --
*
* Map the VGA memory window (0xA0000-0xAFFFF) as read/write memory for
* the process for use in probing memory.
*/
Byte *MapVGA()
{
DIOParPkt par;
ULONG plen;
DIODtaPkt dta;
ULONG dlen;
par.addr = 0xa0000l;
par.size = videoSize;
plen = sizeof(par);
if (consFd != -1 &&
DosDevIOCtl(consFd, (ULONG)0x76, (ULONG)0x44,
(PVOID)&par, (ULONG)plen, (PULONG)&plen,
(PVOID)&dta, (ULONG)6, (PULONG)&dlen) == 0) {
if (dlen==6) {
videoAddr = (Byte*)dta.addr;
return videoAddr;
}
} else {
fprintf(stderr, "%s: Failed to map framebuffer\n", MyName);
return (Byte*)0;
}
}
Byte *MapMem(address,size)
unsigned long address;
unsigned long size;
{
return((Byte*)0);
}
/*
* UnMapVGA --
*
* Unmap the VGA memory window.
*/
void UnMapVGA(base)
Byte *base;
{
UnmapPhys(videoAddr,videoSize);
}
void UnMapMem(base,size)
Byte *base;
unsigned long size;
{
return;
}
/*
* ReadBIOS --
*
* Read 'Len' bytes from the video BIOS at address 'Bios_Base'+'Offset' into
* buffer 'Buffer'.
*/
int ReadBIOS(Offset, Buffer, Len)
unsigned Offset;
Byte *Buffer;
int Len;
{
struct {
ULONG cmd;
ULONG phys;
USHORT len;
} par;
UCHAR *dta;
ULONG plen,dlen;
int i;
par.cmd = 0;
par.phys = (ULONG)Bios_Base+(Offset & 0xffff8000);
par.len = (Offset & 0x7fff) + Len;
plen = sizeof(par);
dta = (UCHAR*)malloc(par.len);
dlen = Len;
if (DosDevIOCtl(consFd, (ULONG)0x76, (ULONG)0x64,
(PVOID)&par, (ULONG)plen, (PULONG)&plen,
(PVOID)dta, (ULONG)dlen, (PULONG)&dlen)) {
fprintf(stderr, "%s: BIOS map failed, addr=%lx\n",
MyName, Bios_Base+Offset);
return -1;
}
/*
* Sanity check...
*/
if ((Offset & 0x7fff) != 0 &&
(dta[0] != 0x55 || dta[1] != 0xaa)) {
fprintf(stderr,
"%s: BIOS sanity check failed, addr=%x\n",
MyName, Bios_Base+Offset);
return -1;
}
memcpy(Buffer,dta + (Offset & 0x7fff), Len);
free(dta);
return(Len);
}
/*
* EnableIOPort --
*
* Enable access to 'NumPorts' IO ports listed in array 'Ports'.
*/
USHORT callgate[3] = {0,0,0};
/*ARGSUSED*/
int EnableIOPorts(NumPorts, Ports)
CONST int NumPorts;
CONST Word *Ports;
{
HFILE hfd;
ULONG dlen;
/* no need to call multiple times */
if (ioenabled) return 0;
if (DosOpen((PSZ)ioDrvPath, (PHFILE)&hfd, (PULONG)&action,
(ULONG)0, FILE_SYSTEM, FILE_OPEN,
OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT|OPEN_ACCESS_READONLY,
(ULONG)0) != 0) {
sorry();
return -1;
}
callgate[0] = callgate[1] = 0;
if (DosDevIOCtl(hfd, (ULONG)0x76, (ULONG)0x64,
NULL, 0, NULL,
(ULONG*)&callgate[2], sizeof(USHORT), &dlen) != 0) {
sorry();
DosClose(hfd);
return -1;
}
asm volatile ("movl $13,%%ebx;.byte 0xff,0x1d;.long _callgate"
: /*no outputs */
: /*no inputs */
: "eax","ebx","ecx","edx","cc");
ioenabled = TRUE;
return 0;
}
/*
* DisableIOPort --
*
* Disable access to 'NumPorts' IO ports listed in array 'Ports'.
* This is a no op here: I/O access is implicitly enabled for this
* process through a special library.
*/
/*ARGSUSED*/
int DisableIOPorts(NumPorts, Ports)
CONST int NumPorts;
CONST Word *Ports;
{
return(0);
}
/*
* ShortSleep --
*
* Sleep for the number of milliseconds specified in 'Delay'.
*
*/
void ShortSleep(Delay)
int Delay;
{
DosSleep(Delay ? Delay : 1);
}
|