aboutsummaryrefslogtreecommitdiffstats
path: root/int10/i10_int.c
blob: 99a009d0a97f9cf0c3c02bb752905713eb7d474e (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * Copyright 1999 Egbert Eich
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the authors not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  The authors makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */
#if defined(__alpha__) || defined (__ia64__)
#include <sys/io.h>
#endif

#include "v86bios.h"
#include "AsmMacros.h"
#include "pci.h"

static int int1A_handler(struct regs86 *regs);
static int int42_handler(int num, struct regs86 *regs);

int
int_handler(int num, struct regs86 *regs)
{
	switch (num) {
	case 0x10:
	case 0x42:
		return (int42_handler(num,regs));
	case 0x1A:
		return (int1A_handler(regs));
	default:
		return 0;
	}
	return 0;
}

static int
int42_handler(int num,struct regs86 *regs)
{
	unsigned char c;
	CARD32 val;

	/*
	 * video bios has modified these -
	 * leave it to the video bios to do this
	 */

	val = getIntVect(num);
	if (val != 0xF000F065) 
	  return 0;
	
	if ((regs->ebx & 0xff) == 0x32) {
		switch (regs->eax & 0xFFFF) {
		case 0x1200:
			c = inb(0x3cc);
			c |= 0x02;
			outb(0x3c2,c);
			return 1;
		case 0x1201:
			c = inb(0x3cc);
			c &= ~0x02;
			outb(0x3c2,c);
			return 1;
		}
	}
	if (num == 0x42)
		return 1;
	else
		return 0;
}

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

static int
int1A_handler(struct regs86 *regs)
{
	CARD32 Slot;
//	PciStructPtr pPci;

	if (! CurrentPci) return 0; /* oops */

	switch (regs->eax & 0xFFFF) {
	case 0xb101:
		regs->eax  &= 0xFF00;   /* no config space/special cycle support */
		regs->edx = 0x20494350; /* " ICP" */
		regs->ebx  = 0x0210;    /* Version 2.10 */
		regs->ecx  &= 0xFF00;
		regs->ecx |= (pciMaxBus & 0xFF);   /* Max bus number in system */
		regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		return 1;
	case 0xb102:
		if (((regs->edx & 0xFFFF) == CurrentPci->VendorID) &&
			((regs->ecx & 0xFFFF) == CurrentPci->DeviceID) &&
			(regs->esi == 0)) {
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
			regs->ebx = pciSlotBX(CurrentPci);
		} else  {
			regs->eax = (regs->eax & 0x00FF) | (DEVICE_NOT_FOUND << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb103:
		if (((regs->ecx & 0xFF) == CurrentPci->Interface) &&
			(((regs->ecx & 0xFF00) >> 8) == CurrentPci->SubClass) &&
			(((regs->ecx & 0xFFFF0000) >> 16) == CurrentPci->BaseClass) && 
			((regs->esi & 0xff) == 0)) {
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->ebx = pciSlotBX(CurrentPci);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (DEVICE_NOT_FOUND << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb108:
		if ((Slot = findPci(regs->ebx))) {
			regs->ecx &= 0xFFFFFF00;
			regs->ecx |= PciRead8(regs->edi,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb109:
		if ((Slot = findPci(regs->ebx))) {
			regs->ecx &= 0xFFFF0000;
			regs->ecx |= PciRead16(regs->edi,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb10a:
		if ((Slot = findPci(regs->ebx))) {
			regs->ecx &= 0;
			regs->ecx |= PciRead32(regs->edi,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb10b:
		if ((Slot = findPci(regs->ebx))) {
			PciWrite8(regs->edi,(CARD8)regs->ecx,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb10c:
		if ((Slot = findPci(regs->ebx))) {
			PciWrite16(regs->edi,(CARD16)regs->ecx,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	case 0xb10d:
		if ((Slot = findPci(regs->ebx))) {
			PciWrite32(regs->edi,(CARD32)regs->ecx,Slot);
			regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
			regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
		} else {
			regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
			regs->eflags |= ((unsigned long)0x01); /* set carry flag */
		}
		return 1;
	default:
		return 0;
	}
}