View | Details | Raw Unified | Return to bug 15300
Collapse All | Expand All

(-)a/hw/xfree86/int10/helper_exec.c (-1 / +80 lines)
Lines 19-24 Link Here
19
#endif
19
#endif
20
20
21
#include <unistd.h>
21
#include <unistd.h>
22
#include <sys/types.h>
23
#include <signal.h>
22
24
23
#include <X11/Xos.h>
25
#include <X11/Xos.h>
24
#include "xf86.h"
26
#include "xf86.h"
Lines 203-208 stack_trace(xf86Int10InfoPtr pInt) Link Here
203
	xf86ErrorFVerb(3, "\n");
205
	xf86ErrorFVerb(3, "\n");
204
}
206
}
205
207
208
enum port_action_e {
209
	PORT_ACTION_PERMIT,
210
	PORT_ACTION_WARN,
211
	PORT_ACTION_BAIL,
212
	PORT_ACTION_MAX
213
};
214
215
static const struct port_range {
216
	CARD16 start, end;
217
	enum port_action_e access;
218
} port_range_table[] = {
219
	// NOTE: port ranges are non overlapping and sorted
220
	{ 0x00, 0x1f, PORT_ACTION_BAIL },	// DMA
221
	{ 0x20, 0x21, PORT_ACTION_BAIL },	// PIC
222
	{ 0x40, 0x47, PORT_ACTION_BAIL },	// PIT 1&2
223
	{ 0x50, 0x53, PORT_ACTION_BAIL },
224
	{ 0x70, 0x77, PORT_ACTION_BAIL },	// CMOS/RTC
225
	{ 0x81, 0x8f, PORT_ACTION_BAIL },	// DIAG REGS
226
	{ 0xa0, 0xa1, PORT_ACTION_BAIL },	// PIC2
227
	{ 0xc0, 0xdf, PORT_ACTION_BAIL },	// DMA
228
};
229
#define ARRAY_SIZE(X) (sizeof((X)) / (sizeof(*(X))))
230
#define ARRAY_END(X)  (&((X)[ARRAY_SIZE(X)]))
231
232
static void assert_port_access_allowed (CARD16 port, CARD16 width)
233
{
234
	CARD16 access_start, access_end;
235
	const struct port_range *pr, *pr_start, *pr_end;
236
237
	access_start = port;
238
	access_end = port + width - 1;
239
240
	// TODO: if the list gets too long we should do a binary search
241
	//        or convert the port list to a bitmap representation
242
	pr_start = port_range_table;
243
	pr_end   = ARRAY_END(port_range_table);
244
245
	for (pr = pr_start; pr < pr_end; pr++) {
246
		if (access_end < pr->start)
247
			continue;
248
		if (access_start > pr->end)
249
			break;
250
251
		// we are in the pr range now
252
		switch (pr->access) {
253
		default:
254
			continue;
255
		case PORT_ACTION_BAIL:
256
		case PORT_ACTION_WARN:
257
			break;
258
		}
259
260
		ErrorF("Emulator asked to make a suspect %saccess to "
261
				"port %u (0x%04x)%s\n",
262
				(width == 1) ? "byte " :
263
				(width == 2) ? "word " :
264
				(width == 4) ? "long " : "",
265
				port, port,
266
				(pr->access == PORT_ACTION_BAIL)
267
				? "; terminating." : "ignoring.");
268
269
		if (pr->access == PORT_ACTION_BAIL)
270
			kill(getpid(), SIGSEGV);
271
	}
272
}
273
206
int
274
int
207
port_rep_inb(xf86Int10InfoPtr pInt,
275
port_rep_inb(xf86Int10InfoPtr pInt,
208
	     CARD16 port, CARD32 base, int d_f, CARD32 count)
276
	     CARD16 port, CARD32 base, int d_f, CARD32 count)
Lines 328-333 x_inb(CARD16 port) Link Here
328
	}
396
	}
329
#endif /* __NOT_YET__ */
397
#endif /* __NOT_YET__ */
330
    } else {
398
    } else {
399
	assert_port_access_allowed (port, sizeof(val));
400
331
	if (!pciCfg1inb(port, &val))
401
	if (!pciCfg1inb(port, &val))
332
	    val = inb(Int10Current->ioBase + port);
402
	    val = inb(Int10Current->ioBase + port);
333
#ifdef PRINT_PORT
403
#ifdef PRINT_PORT
Lines 352-357 x_inw(CARD16 port) Link Here
352
	X_GETTIMEOFDAY(&tv);
422
	X_GETTIMEOFDAY(&tv);
353
	val = (CARD16)(tv.tv_usec / 3);
423
	val = (CARD16)(tv.tv_usec / 3);
354
    } else {
424
    } else {
425
	assert_port_access_allowed (port, sizeof(val));
426
355
	if (!pciCfg1inw(port, &val))
427
	if (!pciCfg1inw(port, &val))
356
	    val = inw(Int10Current->ioBase + port);
428
	    val = inw(Int10Current->ioBase + port);
357
    }
429
    }
Lines 390-395 x_outb(CARD16 port, CARD8 val) Link Here
390
#ifdef PRINT_PORT
462
#ifdef PRINT_PORT
391
	ErrorF(" outb(%#x, %2.2x)\n", port, val);
463
	ErrorF(" outb(%#x, %2.2x)\n", port, val);
392
#endif
464
#endif
465
	assert_port_access_allowed (port, sizeof(val));
466
393
	if (!pciCfg1outb(port, val))
467
	if (!pciCfg1outb(port, val))
394
	    outb(Int10Current->ioBase + port, val);
468
	    outb(Int10Current->ioBase + port, val);
395
    }
469
    }
Lines 402-407 x_outw(CARD16 port, CARD16 val) Link Here
402
    ErrorF(" outw(%#x, %4.4x)\n", port, val);
476
    ErrorF(" outw(%#x, %4.4x)\n", port, val);
403
#endif
477
#endif
404
478
479
    assert_port_access_allowed (port, sizeof(val));
480
405
    if (!pciCfg1outw(port, val))
481
    if (!pciCfg1outw(port, val))
406
	outw(Int10Current->ioBase + port, val);
482
	outw(Int10Current->ioBase + port, val);
407
}
483
}
Lines 411-416 x_inl(CARD16 port) Link Here
411
{
487
{
412
    CARD32 val;
488
    CARD32 val;
413
489
490
    assert_port_access_allowed (port, sizeof(val));
491
414
    if (!pciCfg1in(port, &val))
492
    if (!pciCfg1in(port, &val))
415
	val = inl(Int10Current->ioBase + port);
493
	val = inl(Int10Current->ioBase + port);
416
494
Lines 427-432 x_outl(CARD16 port, CARD32 val) Link Here
427
    ErrorF(" outl(%#x, %8.8x)\n", port, val);
505
    ErrorF(" outl(%#x, %8.8x)\n", port, val);
428
#endif
506
#endif
429
507
508
    assert_port_access_allowed (port, sizeof(val));
509
430
    if (!pciCfg1out(port, val))
510
    if (!pciCfg1out(port, val))
431
	outl(Int10Current->ioBase + port, val);
511
	outl(Int10Current->ioBase + port, val);
432
}
512
}
433
- 

Return to bug 15300