summaryrefslogtreecommitdiff
path: root/util/vgabios/int1a.c
blob: bd9a24c9f85674e366890627f9a5c96562866082 (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
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
#include <stdio.h>
#include "test.h"
#include "pci-userspace.h"

#define DEBUG_INT1A

#define SUCCESSFUL              0x00
#define DEVICE_NOT_FOUND        0x86
#define BAD_REGISTER_NUMBER     0x87

void x86emu_dump_xregs(void);
extern int verbose;


int int1A_handler()
{
	PCITAG tag;
	pciVideoPtr pvp = NULL;

	if (verbose) {
		printf("\nint1a encountered.\n");
		//x86emu_dump_xregs();
	}

	switch (X86_AX) {
	case 0xb101:
		X86_EAX = 0x00;	/* no config space/special cycle support */
		X86_AL = 0x01;	/* config mechanism 1 */
		X86_EDX = 0x20494350;	/* " ICP" */
		X86_EBX = 0x0210;	/* Version 2.10 */
		X86_ECX &= 0xFF00;
		X86_ECX |= (pciNumBuses & 0xFF);	/* Max bus number in system */
		X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
#ifdef DEBUG_INT1A
		if (verbose)
			printf("PCI bios present.\n");
#endif
		return 1;
	case 0xb102:
		if (X86_DX == pvp->vendor_id && X86_CX == pvp->device_id && X86_ESI == 0) {
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
			X86_EBX = pciSlotBX(pvp);
		}
#ifdef SHOW_ALL_DEVICES
		else if ((pvp = xf86FindPciDeviceVendor(X86_EDX, X86_ECX, X86_ESI, pvp))) {
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
			X86_EBX = pciSlotBX(pvp);
		}
#endif
		else {
			X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x ebx=0x%x eflags=0x%x\n", X86_EAX, X86_EBX, X86_EFLAGS);
#endif
		return 1;
	case 0xb103:
#if 0
		if (X86_CL == pvp->interface &&
		    X86_CH == pvp->subclass &&
		    ((X86_ECX & 0xFFFF0000) >> 16) == pvp->class) {
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EBX = pciSlotBX(pvp);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		}
#else
		/* FIXME: dirty hack */
		if (0);
#endif
#ifdef SHOW_ALL_DEVICES
		else if ((pvp = FindPciClass(X86_CL, X86_CH,
					     (X86_ECX & 0xffff0000) >> 16,
					     X86_ESI, pvp))) {
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
			X86_EBX = pciSlotBX(pvp);
		}
#endif
		else {
			X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
#endif
		return 1;
	case 0xb108:
		if ((tag = findPci(X86_EBX))) {
			X86_CL = pciReadByte(tag, X86_EDI);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
#endif
		return 1;
	case 0xb109:
		if ((tag = findPci(X86_EBX))) {
			X86_CX = pciReadWord(tag, X86_EDI);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
#endif
		return 1;
	case 0xb10a:
		if ((tag = findPci(X86_EBX))) {
			X86_ECX = pciReadLong(tag, X86_EDI);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x ecx=0x%x eflags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS);
#endif
		return 1;
	case 0xb10b:
		if ((tag = findPci(X86_EBX))) {
			pciWriteByte(tag, X86_EDI, X86_CL);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
#endif
		return 1;
	case 0xb10c:
		if ((tag = findPci(X86_EBX))) {
			pciWriteWord(tag, X86_EDI, X86_CX);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
#endif
		return 1;
	case 0xb10d:
		if ((tag = findPci(X86_EBX))) {
			pciWriteLong(tag, X86_EDI, X86_ECX);
			X86_EAX = X86_AL | (SUCCESSFUL << 8);
			X86_EFLAGS &= ~((unsigned long) 0x01);	/* clear carry flag */
		} else {
			X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8);
			X86_EFLAGS |= ((unsigned long) 0x01);	/* set carry flag */
		}
#ifdef DEBUG_INT1A
		printf("eax=0x%x eflags=0x%x\n", X86_EAX, X86_EFLAGS);
#endif
		return 1;
	default:
		printf("int1a: subfunction not implemented.\n");
		return 0;
	}
}