]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/src/v86bios/int.c
* Patch by Thomas Frieden, 13 Nov 2002:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / src / v86bios / int.c
1 /*
2  * Copyright 1999 Egbert Eich
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the authors not be used in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific, written prior permission.  The authors makes no representations
11  * about the suitability of this software for any purpose.  It is provided
12  * "as is" without express or implied warranty.
13  *
14  * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22 #include "debug.h"
23 #if defined(__alpha__) || defined (__ia64__)
24 #include <sys/io.h>
25 #endif
26
27 #include "v86bios.h"
28 #include "AsmMacros.h"
29 #include "pci.h"
30
31 static int int1A_handler(struct regs86 *regs);
32 static int int42_handler(int num, struct regs86 *regs);
33
34 int
35 int_handler(int num, struct regs86 *regs)
36 {
37     switch (num) {
38     case 0x10:
39     case 0x42:
40         return (int42_handler(num,regs));
41     case 0x1A:
42         return (int1A_handler(regs));
43     default:
44         return 0;
45     }
46     return 0;
47 }
48
49 static int
50 int42_handler(int num,struct regs86 *regs)
51 {
52     unsigned char c;
53     CARD32 val;
54
55     i_printf("int 0x%x: ax:0x%lx bx:0x%lx cx:0x%lx dx:0x%lx\n",num,
56            regs->eax,regs->ebx, regs->ecx, regs->edx);
57     
58     /*
59      * video bios has modified these -
60      * leave it to the video bios to do this
61      */
62
63     val = getIntVect(num);
64     if (val != 0xF000F065) 
65       return 0;
66     
67     if ((regs->ebx & 0xff) == 0x32) {
68         switch (regs->eax & 0xFFFF) {
69         case 0x1200:
70             i_printf("enabling video\n");
71             c = inb(0x3cc);
72             c |= 0x02;
73             outb(0x3c2,c);
74             return 1;
75         case 0x1201:
76             i_printf("disabling video\n");
77             c = inb(0x3cc);
78             c &= ~0x02;
79             outb(0x3c2,c);
80             return 1;
81         default:
82         }
83     }
84     if (num == 0x42)
85         return 1;
86     else
87         return 0;
88 }
89
90 #define SUCCESSFUL              0x00
91 #define DEVICE_NOT_FOUND        0x86
92 #define BAD_REGISTER_NUMBER     0x87
93
94 static int
95 int1A_handler(struct regs86 *regs)
96 {
97     CARD32 Slot;
98     PciStructPtr pPci;
99
100     if (! CurrentPci) return 0; /* oops */
101
102     i_printf("int 0x1a: ax=0x%lx bx=0x%lx cx=0x%lx dx=0x%lx di=0x%lx"
103          " si=0x%lx\n", regs->eax,regs->ebx,regs->ecx,regs->edx,
104          regs->edi,regs->esi);
105     switch (regs->eax & 0xFFFF) {
106     case 0xb101:
107         regs->eax  &= 0xFF00;   /* no config space/special cycle support */
108         regs->edx = 0x20494350; /* " ICP" */
109         regs->ebx  = 0x0210;    /* Version 2.10 */
110         regs->ecx  &= 0xFF00;
111         regs->ecx |= (pciMaxBus & 0xFF);   /* Max bus number in system */
112         regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
113         i_printf("ax=0x%lx dx=0x%lx bx=0x%lx cx=0x%lx flags=0x%lx\n",
114                  regs->eax,regs->edx,regs->ebx,regs->ecx,regs->eflags);
115         return 1;
116     case 0xb102:
117         if (((regs->edx & 0xFFFF) == CurrentPci->VendorID) &&
118             ((regs->ecx & 0xFFFF) == CurrentPci->DeviceID) &&
119             (regs->esi == 0)) {
120             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
121             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
122             regs->ebx = pciSlotBX(CurrentPci);
123         }
124         else if (Config.ShowAllDev &&
125              (pPci = findPciDevice(regs->edx,regs->ecx,regs->esi)) != NULL) {
126             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
127             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
128             regs->ebx = pciSlotBX(pPci);
129         } else  {
130             regs->eax = (regs->eax & 0x00FF) | (DEVICE_NOT_FOUND << 8);
131             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
132         }
133         i_printf("ax=0x%lx bx=0x%lx flags=0x%lx\n",
134                  regs->eax,regs->ebx,regs->eflags);
135         return 1;
136     case 0xb103:
137         if (((regs->ecx & 0xFF) == CurrentPci->Interface) &&
138             (((regs->ecx & 0xFF00) >> 8) == CurrentPci->SubClass) &&
139             (((regs->ecx & 0xFFFF0000) >> 16) == CurrentPci->BaseClass) && 
140             ((regs->esi & 0xff) == 0)) {
141             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
142             regs->ebx = pciSlotBX(CurrentPci);
143             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
144         }
145         else if (Config.ShowAllDev
146              && (pPci = findPciClass(regs->ecx & 0xFF, (regs->ecx & 0xff00) >> 8,
147                          (regs->ecx & 0xffff0000) >> 16, regs->esi)) != NULL) {
148             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
149             regs->ebx = pciSlotBX(pPci);
150             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
151         } else {
152             regs->eax = (regs->eax & 0x00FF) | (DEVICE_NOT_FOUND << 8);
153             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
154         }
155         i_printf("ax=0x%lx flags=0x%lx\n",regs->eax,regs->eflags);
156         return 1;
157     case 0xb108:
158         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
159         if ((Slot = findPci(regs->ebx))) {
160             regs->ecx &= 0xFFFFFF00;
161             regs->ecx |= PciRead8(regs->edi,Slot);
162             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
163             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
164         } else {
165             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
166             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
167         }
168         i_printf("ax=0x%lx cx=0x%lx flags=0x%lx\n",
169                  regs->eax,regs->ecx,regs->eflags);
170         return 1;
171     case 0xb109:
172         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
173         if ((Slot = findPci(regs->ebx))) {
174             regs->ecx &= 0xFFFF0000;
175             regs->ecx |= PciRead16(regs->edi,Slot);
176             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
177             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
178         } else {
179             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
180             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
181         }
182         i_printf("ax=0x%lx cx=0x%lx flags=0x%lx\n",
183                  regs->eax,regs->ecx,regs->eflags);
184         return 1;
185     case 0xb10a:
186         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
187         if ((Slot = findPci(regs->ebx))) {
188             regs->ecx &= 0;
189             regs->ecx |= PciRead32(regs->edi,Slot);
190             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
191             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
192         } else {
193             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
194             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
195         }
196         i_printf("ax=0x%lx cx=0x%lx flags=0x%lx\n",
197                  regs->eax,regs->ecx,regs->eflags);
198         return 1;
199     case 0xb10b:
200         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
201         if ((Slot = findPci(regs->ebx))) {
202             PciWrite8(regs->edi,(CARD8)regs->ecx,Slot);
203             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
204             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
205         } else {
206             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
207             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
208         }
209         i_printf("ax=0x%lx flags=0x%lx\n", regs->eax,regs->eflags);
210         return 1;
211     case 0xb10c:
212         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
213         if ((Slot = findPci(regs->ebx))) {
214             PciWrite16(regs->edi,(CARD16)regs->ecx,Slot);
215             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
216             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
217         } else {
218             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
219             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
220         }
221         i_printf("ax=0x%lx flags=0x%lx\n", regs->eax,regs->eflags);
222         return 1;
223     case 0xb10d:
224         i_printf("Slot=0x%x\n",CurrentPci->Slot.l);
225         if ((Slot = findPci(regs->ebx))) {
226             PciWrite32(regs->edi,(CARD32)regs->ecx,Slot);
227             regs->eax = (regs->eax & 0x00FF) | (SUCCESSFUL << 8);
228             regs->eflags &= ~((unsigned long)0x01); /* clear carry flag */
229         } else {
230             regs->eax = (regs->eax & 0x00FF) | (BAD_REGISTER_NUMBER << 8);
231             regs->eflags |= ((unsigned long)0x01); /* set carry flag */
232         }
233         i_printf("ax=0x%lx flags=0x%lx\n", regs->eax,regs->eflags);
234         return 1;
235     default:
236         return 0;
237     }
238 }