1 /* $XFree86: xc/programs/Xserver/hw/xfree86/int10/helper_exec.c,v 1.16 2001/04/30 14:34:57 tsi Exp $ */
4 * execute BIOS int 10h calls in x86 real mode environment
5 * Copyright 1999 Egbert Eich
7 * Part of this is based on code taken from DOSEMU
8 * (C) Copyright 1992, ..., 1999 the "DOSEMU-Development-Team"
12 * To debug port accesses define PRINT_PORT.
13 * Note! You also have to comment out ioperm()
14 * in xf86EnableIO(). Otherwise we won't trap
22 int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
25 void x_outb(u16 port, u8 val);
26 void x_outw(u16 port, u16 val);
28 void x_outl(u16 port, u32 val);
30 /* general software interrupt handler */
31 u32 getIntVect(int num)
33 return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4);
39 MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
42 int run_bios_int(int num)
50 X86_CS = MEM_RW((num << 2) + 2);
51 X86_IP = MEM_RW(num << 2);
53 printf("%s: INT %x CS:IP = %x:%x\n", __FUNCTION__,
54 num, MEM_RW((num << 2) + 2), MEM_RW(num << 2));
59 int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
61 register int inc = d_f ? -1 : 1;
64 MEM_WB(dst, x_inb(port));
70 int port_rep_inw(u16 port, u32 base, int d_f, u32 count)
72 register int inc = d_f ? -2 : 2;
75 MEM_WW(dst, x_inw(port));
81 int port_rep_inl(u16 port, u32 base, int d_f, u32 count)
83 register int inc = d_f ? -4 : 4;
86 MEM_WL(dst, x_inl(port));
92 int port_rep_outb(u16 port, u32 base, int d_f, u32 count)
94 register int inc = d_f ? -1 : 1;
97 x_outb(port, MEM_RB(dst));
103 int port_rep_outw(u16 port, u32 base, int d_f, u32 count)
105 register int inc = d_f ? -2 : 2;
108 x_outw(port, MEM_RW(dst));
114 int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
116 register int inc = d_f ? -4 : 4;
119 x_outl(port, MEM_RL(dst));
131 printf("inb(0x%04x) = 0x%02x\n", port, val);
142 printf("inw(0x%04x) = 0x%04x\n", port, val);
152 printf("inl(0x%04x) = 0x%08x\n", port, val);
156 void x_outb(u16 port, u8 val)
158 printf("outb(0x%02x, 0x%04x)\n",
163 void x_outw(u16 port, u16 val)
165 printf("outw(0x%04x, 0x%04x)\n", val, port);
169 void x_outl(u16 port, u32 val)
171 printf("outl(0x%08x, 0x%04x)\n", val, port);
177 return (*current->mem->rb) (current, addr);
182 return (*current->mem->rw) (current, addr);
187 return (*current->mem->rl) (current, addr);
190 void Mem_wb(int addr, u8 val)
192 (*current->mem->wb) (current, addr, val);
195 void Mem_ww(int addr, u16 val)
197 (*current->mem->ww) (current, addr, val);
200 void Mem_wl(int addr, u32 val)
202 (*current->mem->wl) (current, addr, val);
205 void getsecs(unsigned long *sec, unsigned long *usec)
208 gettimeofday(&tv, 0);
213 #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
214 #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
216 u8 bios_checksum(u8 * start, int size)
226 * Lock/Unlock legacy VGA. Some Bioses try to be very clever and make
227 * an attempt to detect a legacy ISA card. If they find one they might
228 * act very strange: for example they might configure the card as a
229 * monochrome card. This might cause some drivers to choke.
230 * To avoid this we attempt legacy VGA by writing to all know VGA
231 * disable registers before we call the BIOS initialization and
232 * restore the original values afterwards. In beween we hold our
233 * breath. To get to a (possibly exising) ISA card need to disable
234 * our current PCI card.
237 * This is just for booting: we just want to catch pure
238 * legacy vga therefore we don't worry about mmio etc.
239 * This stuff should really go into vgaHW.c. However then
240 * the driver would have to load the vga-module prior to
244 LockLegacyVGA(int screenIndex,legacyVGAPtr vga)
246 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
247 vga->save_msr = inb(0x3CC);
248 vga->save_vse = inb(0x3C3);
249 vga->save_46e8 = inb(0x46e8);
250 vga->save_pos102 = inb(0x102);
251 outb(0x3C2, ~(u8)0x03 & vga->save_msr);
252 outb(0x3C3, ~(u8)0x01 & vga->save_vse);
253 outb(0x46e8, ~(u8)0x08 & vga->save_46e8);
254 outb(0x102, ~(u8)0x01 & vga->save_pos102);
255 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);
259 UnlockLegacyVGA(int screenIndex, legacyVGAPtr vga)
261 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
262 outb(0x102, vga->save_pos102);
263 outb(0x46e8, vga->save_46e8);
264 outb(0x3C3, vga->save_vse);
265 outb(0x3C2, vga->save_msr);
266 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);