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
17 #include <x86emu/x86emu.h>
18 #include "helper_exec.h"
25 int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
28 void x_outb(u16 port, u8 val);
29 void x_outw(u16 port, u16 val);
31 void x_outl(u16 port, u32 val);
33 /* general software interrupt handler */
34 u32 getIntVect(int num)
36 return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4);
42 MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
45 int run_bios_int(int num)
53 X86_CS = MEM_RW((num << 2) + 2);
54 X86_IP = MEM_RW(num << 2);
56 printf("%s: INT %x CS:IP = %x:%x\n", __FUNCTION__,
57 num, MEM_RW((num << 2) + 2), MEM_RW(num << 2));
62 int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
64 register int inc = d_f ? -1 : 1;
67 MEM_WB(dst, x_inb(port));
73 int port_rep_inw(u16 port, u32 base, int d_f, u32 count)
75 register int inc = d_f ? -2 : 2;
78 MEM_WW(dst, x_inw(port));
84 int port_rep_inl(u16 port, u32 base, int d_f, u32 count)
86 register int inc = d_f ? -4 : 4;
89 MEM_WL(dst, x_inl(port));
95 int port_rep_outb(u16 port, u32 base, int d_f, u32 count)
97 register int inc = d_f ? -1 : 1;
100 x_outb(port, MEM_RB(dst));
106 int port_rep_outw(u16 port, u32 base, int d_f, u32 count)
108 register int inc = d_f ? -2 : 2;
111 x_outw(port, MEM_RW(dst));
117 int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
119 register int inc = d_f ? -4 : 4;
122 x_outl(port, MEM_RL(dst));
134 printf("inb(0x%04x) = 0x%02x\n", port, val);
145 printf("inw(0x%04x) = 0x%04x\n", port, val);
155 printf("inl(0x%04x) = 0x%08x\n", port, val);
159 void x_outb(u16 port, u8 val)
161 printf("outb(0x%02x, 0x%04x)\n",
166 void x_outw(u16 port, u16 val)
168 printf("outw(0x%04x, 0x%04x)\n", val, port);
172 void x_outl(u16 port, u32 val)
174 printf("outl(0x%08x, 0x%04x)\n", val, port);
180 return (*current->mem->rb) (current, addr);
185 return (*current->mem->rw) (current, addr);
190 return (*current->mem->rl) (current, addr);
193 void Mem_wb(int addr, u8 val)
195 (*current->mem->wb) (current, addr, val);
198 void Mem_ww(int addr, u16 val)
200 (*current->mem->ww) (current, addr, val);
203 void Mem_wl(int addr, u32 val)
205 (*current->mem->wl) (current, addr, val);
208 void getsecs(unsigned long *sec, unsigned long *usec)
211 gettimeofday(&tv, 0);
216 #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
217 #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
219 u8 bios_checksum(u8 * start, int size)
229 * Lock/Unlock legacy VGA. Some Bioses try to be very clever and make
230 * an attempt to detect a legacy ISA card. If they find one they might
231 * act very strange: for example they might configure the card as a
232 * monochrome card. This might cause some drivers to choke.
233 * To avoid this we attempt legacy VGA by writing to all know VGA
234 * disable registers before we call the BIOS initialization and
235 * restore the original values afterwards. In beween we hold our
236 * breath. To get to a (possibly exising) ISA card need to disable
237 * our current PCI card.
240 * This is just for booting: we just want to catch pure
241 * legacy vga therefore we don't worry about mmio etc.
242 * This stuff should really go into vgaHW.c. However then
243 * the driver would have to load the vga-module prior to
247 LockLegacyVGA(int screenIndex,legacyVGAPtr vga)
249 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
250 vga->save_msr = inb(0x3CC);
251 vga->save_vse = inb(0x3C3);
252 vga->save_46e8 = inb(0x46e8);
253 vga->save_pos102 = inb(0x102);
254 outb(0x3C2, ~(u8)0x03 & vga->save_msr);
255 outb(0x3C3, ~(u8)0x01 & vga->save_vse);
256 outb(0x46e8, ~(u8)0x08 & vga->save_46e8);
257 outb(0x102, ~(u8)0x01 & vga->save_pos102);
258 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);
262 UnlockLegacyVGA(int screenIndex, legacyVGAPtr vga)
264 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
265 outb(0x102, vga->save_pos102);
266 outb(0x46e8, vga->save_46e8);
267 outb(0x3C3, vga->save_vse);
268 outb(0x3C2, vga->save_msr);
269 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);