summaryrefslogtreecommitdiff
path: root/nviolog.c
blob: 47975a8a6747b889e865fc45fe6e0d96204c2d00 (plain)
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
#include <stdint.h>
#include <stdio.h>

#include "x86emu.h"
#include "xf86include/xf86int10.h"

#define __BUILDIO(bwl,bw,type) \
static inline void out##bwl##_local(unsigned long port, unsigned type value) {        __asm__ __volatile__("out" #bwl " %" #bw "0, %w1" : : "a"(value), "Nd"(port)); \
}\
static inline unsigned type in##bwl##_local(unsigned long port) { \
        unsigned type value; \
        __asm__ __volatile__("in" #bwl " %w1, %" #bw "0" : "=a"(value) : "Nd"(port)); \
        return value; \
}\

__BUILDIO(b,b,char)
__BUILDIO(w,w,short)
__BUILDIO(l,,int)

static int address = 0;

CARD8
x_inb_l(CARD16 port)
{
	CARD8 val;
	val = inb_local(port);
	fprintf(stderr, "%04x:%04x	R8  port: %04x data: %02x\n", M.x86.R_CS, M.x86.R_IP - 1, port, val);
	return val;
}

CARD16
x_inw_l(CARD16 port)
{
	static int bottom = -1;
	CARD16 val;
	val = inw_local(port);
	fprintf(stderr, "%04x:%04x	R16 port: %04x data: %04x\n", M.x86.R_CS, M.x86.R_IP - 1, port, val);
	if (address) {
		if (bottom >= 0) {
			if (port == 0x3d2) {
				fprintf(stderr, "					   Address 0x%08x read  0x%08x\n", address, val << 16 | bottom);
				address = 0;
			}
			bottom = -1;
		}
		if (port == 0x3d0)
			bottom = val;
	}
	return val;
}

CARD32
x_inl_l(CARD16 port)
{
	CARD32 val;
	val = inl_local(port);
	fprintf(stderr, "%04x:%04x	R32 port: %04x data: %08x\n", M.x86.R_CS, M.x86.R_IP - 1, port, (unsigned int)val);
	if (address && (port == 0x3d0 || port == 0xe80c)) {
		fprintf(stderr, "					   Address 0x%08x read  0x%08x\n", address, (unsigned int)val);
		address = 0;
	}
	return val;
}

void
x_outb_l(CARD16 port, CARD8 val)
{
	fprintf(stderr, "%04x:%04x	W8  port: %04x data: %02x\n", M.x86.R_CS, M.x86.R_IP - 1, port, val);
        outb_local(port, val);
}

void
x_outw_l(CARD16 port, CARD16 val)
{
	static int top = -1;
	fprintf(stderr, "%04x:%04x	W16 port: %04x data: %04x\n", M.x86.R_CS, M.x86.R_IP - 1, port, val);
	if (!address) {
		if (top >= 0) {
			if (port == 0x3d0) {
				address = top | val;
				fprintf(stderr, "Select address %08x\n", address);
			}
			top = -1;
		}
		if (port == 0x3d2)
			top = val << 16;
	} else {
		if (top >= 0) {	// top is actually bottom here...
			if (port == 0x3d2) {
				fprintf(stderr, "					   Address 0x%08x write 0x%08x\n", address, val << 16 | top);
				address = 0;
			}
			top = -1;
		}
		if (port == 0x3d0)
			top = val;
	}
        outw_local(port, val);
}

void x_outl_l(CARD16 port, CARD32 val)
{
	fprintf(stderr, "%04x:%04x	W32 port: %04x data: %08x\n", M.x86.R_CS, M.x86.R_IP - 1, port, (unsigned int)val);
	if (port == 0x3d0 || port == 0xe808 || port == 0xe80c) {
		if (!address) {
			address = val;
			fprintf(stderr, "Select address %08x\n", address);
		} else {
			fprintf(stderr, "					   Address 0x%08x write 0x%08x\n", address, (int)val);
			address = 0;
		}
	}
	outl_local(port, val);
}

void log_nv_io() {
	X86EMU_pioFuncs pioFuncs = {
		(&x_inb_l),
		(&x_inw_l),
		(&x_inl_l),
		(&x_outb_l),
		(&x_outw_l),
		(&x_outl_l)
	};
	
	X86EMU_setupPioFuncs(&pioFuncs);
}