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
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/SuperProbe/OS_Mach.c,v 3.5 1997/03/07 00:28:57 hohndel Exp $ */
/*
* (c) Copyright 1993,1994 by Robert V. Baron
* <Robert.Baron@ernst.mach.cs.cmu.edu>
*
* 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
* ROBERT V. BARON 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 Robert V. Baron shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Robert V. Baron.
*
*/
/* $XConsortium: OS_Mach.c /main/5 1996/02/21 17:11:12 kaleb $ */
#include "Probe.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
/* These can be Mach 2.5 or 3.0 headers */
#include <mach.h>
#include <mach_error.h>
#include <mach/message.h>
#ifdef MACH_PORT_NULL
#define MACH3 /* they must have been 3.0 headers beckerd@cs.unc.edu */
#endif
#undef task_self
static int IOPL_fd = -1;
/*
* OpenVideo --
*
* Enable access to the installed video hardware. For Mach, we disable
* IO protection, since this is currently the only way to access any
* IO registers.
*/
int screen_addr;
int OpenVideo()
{
int ret;
#define C /*Bios_Base*/ 0xc0000
#define S 0x40000
if ((IOPL_fd = open("/dev/iopl", O_RDWR, 0)) < 0) {
fprintf(stderr, "Failed to open /dev/iopl\n");
return -1;
}
#define KERN_SUCESS 0
if (KERN_SUCESS != vm_allocate(task_self(), &screen_addr, S, TRUE)) {
fprintf(stderr, "Failed vmallocate %x\n", S);
close(IOPL_fd);
return -1;
}
if (mmap(screen_addr+C, S, 3, 1, IOPL_fd, C) < 0) {
fprintf(stderr, "Failed to mmap %x bytes at %x\n", S, C);
vm_deallocate(task_self(), screen_addr, S);
close(IOPL_fd);
return -1;
}
return(IOPL_fd);
}
/*
* CloseVideo --
*
* Disable access to the video hardware. For Mach, we re-enable
* IO protection.
*/
void CloseVideo()
{
if (KERN_SUCESS != vm_deallocate(task_self(), screen_addr, S)) {
fprintf(stderr, "Failed vmdeallocate %x\n", S);
}
close(IOPL_fd);
}
/*
* MapVGA --
*
* Map the VGA memory window (0xA0000-0xAFFFF) as read/write memory for
* the process for use in probing memory.
*/
Byte *MapVGA()
{
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;
{
return;
}
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;
{
Word tmp;
Byte *Base = (Byte *)(screen_addr + Bios_Base + Offset);
#ifdef DEBUG
{int i;
fprintf(stderr, "ReadBIOS(Offset %x, Buffer %x, Len %x) .. ",
Offset, Buffer, Len);
for (i=0;i<Len;i++)
fprintf(stderr," [%c](%x)|", *(Base+i), *(Base+i));
fprintf(stderr,"\n");
}
#endif
bcopy(Base, Buffer, Len);
return (Len);
}
/*
* EnableIOPort --
*
* Enable access to 'NumPorts' IO ports listed in array 'Ports'. For Mach,
* we've disabled IO protections so this is a no-op.
*/
/*ARGSUSED*/
int EnableIOPorts(NumPorts, Ports)
CONST int NumPorts;
CONST Word *Ports;
{
return(0);
}
/*
* DisableIOPort --
*
* Disable access to 'NumPorts' IO ports listed in array 'Ports'. For Mach,
* we've disabled IO protections so this is a no-op.
*/
/*ARGSUSED*/
int DisableIOPorts(NumPorts, Port)
CONST int NumPorts;
CONST Word *Port;
{
return(0);
}
/*
* ShortSleep --
*
* Sleep for the number of milliseconds specified in 'Delay'.
*/
void ShortSleep(Delay)
int Delay;
{
#ifdef MACH3
struct trial {
mach_msg_header_t h;
mach_msg_type_t t;
int d;
} msg_rcv;
mach_port_t my_port;
#else
/* This does Mach 2.5 IPC */
struct trial {
msg_header_t h;
msg_type_t t;
int d;
} msg_rcv;
port_t my_port;
#endif
kern_return_t error;
int ret;
if ((error = port_allocate(task_self(), &my_port)) != KERN_SUCCESS) {
printf("ShortSleep: port_allocate failed with %d: %s\n",
error, mach_error_string(error));
return;
}
#ifdef MACH3
msg_rcv.h.msgh_size = sizeof(msg_rcv);
if ((ret = msg_receive(&msg_rcv.h, MACH_RCV_TIMEOUT, Delay)) != MACH_RCV_TIMED_OUT) {
#else
if ((ret = msg_receive(&msg_rcv.h, RCV_TIMEOUT, Delay)) != RCV_TIMED_OUT) {
msg_rcv.h.msg_local_port = my_port;
#endif
mach_error("ShortSleep: msg_receive returned ", ret);
return;
}
if ((error = port_deallocate(task_self(), my_port)) != KERN_SUCCESS) {
printf("ShortSleep: port_deallocate failed with %d: %s\n",
error, mach_error_string(error));
return;
}
}
|