Li-Ta Lo | 8152126 | 2004-07-08 17:18:27 +0000 | [diff] [blame] | 1 | /* $XFree86: xc/programs/Xserver/hw/xfree86/int10/helper_exec.c,v 1.16 2001/04/30 14:34:57 tsi Exp $ */ |
| 2 | /* |
| 3 | * XFree86 int10 module |
| 4 | * execute BIOS int 10h calls in x86 real mode environment |
| 5 | * Copyright 1999 Egbert Eich |
| 6 | * |
| 7 | * Part of this is based on code taken from DOSEMU |
| 8 | * (C) Copyright 1992, ..., 1999 the "DOSEMU-Development-Team" |
| 9 | */ |
| 10 | |
| 11 | /* |
| 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 |
| 15 | * on PIO. |
| 16 | */ |
| 17 | #include <x86emu.h> |
| 18 | #include "test.h" |
| 19 | #include <asm/io.h> |
| 20 | #include <sys/time.h> |
| 21 | |
| 22 | int port_rep_inb(u16 port, u32 base, int d_f, u32 count); |
| 23 | u8 x_inb(u16 port); |
| 24 | u16 x_inw(u16 port); |
| 25 | void x_outb(u16 port, u8 val); |
| 26 | void x_outw(u16 port, u16 val); |
| 27 | u32 x_inl(u16 port); |
| 28 | void x_outl(u16 port, u32 val); |
| 29 | |
| 30 | /* general software interrupt handler */ |
| 31 | u32 getIntVect(int num) |
| 32 | { |
| 33 | return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4); |
| 34 | } |
| 35 | |
| 36 | void pushw(u16 val) |
| 37 | { |
| 38 | X86_ESP -= 2; |
| 39 | MEM_WW(((u32) X86_SS << 4) + X86_SP, val); |
| 40 | } |
| 41 | |
| 42 | int run_bios_int(int num) |
| 43 | { |
| 44 | u32 eflags; |
| 45 | |
| 46 | eflags = X86_EFLAGS; |
| 47 | pushw(eflags); |
| 48 | pushw(X86_CS); |
| 49 | pushw(X86_IP); |
| 50 | X86_CS = MEM_RW((num << 2) + 2); |
| 51 | X86_IP = MEM_RW(num << 2); |
| 52 | |
| 53 | //printf("%s: INT %x CS:IP = %x:%x\n", __FUNCTION__, |
| 54 | // num, MEM_RW((num << 2) + 2), MEM_RW(num << 2)); |
| 55 | |
| 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | int port_rep_inb(u16 port, u32 base, int d_f, u32 count) |
| 60 | { |
| 61 | register int inc = d_f ? -1 : 1; |
| 62 | u32 dst = base; |
| 63 | while (count--) { |
| 64 | MEM_WB(dst, x_inb(port)); |
| 65 | dst += inc; |
| 66 | } |
| 67 | return dst - base; |
| 68 | } |
| 69 | |
| 70 | int port_rep_inw(u16 port, u32 base, int d_f, u32 count) |
| 71 | { |
| 72 | register int inc = d_f ? -2 : 2; |
| 73 | u32 dst = base; |
| 74 | while (count--) { |
| 75 | MEM_WW(dst, x_inw(port)); |
| 76 | dst += inc; |
| 77 | } |
| 78 | return dst - base; |
| 79 | } |
| 80 | |
| 81 | int port_rep_inl(u16 port, u32 base, int d_f, u32 count) |
| 82 | { |
| 83 | register int inc = d_f ? -4 : 4; |
| 84 | u32 dst = base; |
| 85 | while (count--) { |
| 86 | MEM_WL(dst, x_inl(port)); |
| 87 | dst += inc; |
| 88 | } |
| 89 | return dst - base; |
| 90 | } |
| 91 | |
| 92 | int port_rep_outb(u16 port, u32 base, int d_f, u32 count) |
| 93 | { |
| 94 | register int inc = d_f ? -1 : 1; |
| 95 | u32 dst = base; |
| 96 | while (count--) { |
| 97 | x_outb(port, MEM_RB(dst)); |
| 98 | dst += inc; |
| 99 | } |
| 100 | return dst - base; |
| 101 | } |
| 102 | |
| 103 | int port_rep_outw(u16 port, u32 base, int d_f, u32 count) |
| 104 | { |
| 105 | register int inc = d_f ? -2 : 2; |
| 106 | u32 dst = base; |
| 107 | while (count--) { |
| 108 | x_outw(port, MEM_RW(dst)); |
| 109 | dst += inc; |
| 110 | } |
| 111 | return dst - base; |
| 112 | } |
| 113 | |
| 114 | int port_rep_outl(u16 port, u32 base, int d_f, u32 count) |
| 115 | { |
| 116 | register int inc = d_f ? -4 : 4; |
| 117 | u32 dst = base; |
| 118 | while (count--) { |
| 119 | x_outl(port, MEM_RL(dst)); |
| 120 | dst += inc; |
| 121 | } |
| 122 | return dst - base; |
| 123 | } |
| 124 | |
| 125 | u8 x_inb(u16 port) |
| 126 | { |
| 127 | u8 val; |
| 128 | |
| 129 | val = inb(port); |
| 130 | |
| 131 | //printf("inb(0x%04x) = 0x%02x\n", port, val); |
| 132 | |
| 133 | return val; |
| 134 | } |
| 135 | |
| 136 | u16 x_inw(u16 port) |
| 137 | { |
| 138 | u16 val; |
| 139 | |
| 140 | val = inw(port); |
| 141 | |
| 142 | //printf("inw(0x%04x) = 0x%04x\n", port, val); |
| 143 | return val; |
| 144 | } |
| 145 | |
| 146 | u32 x_inl(u16 port) |
| 147 | { |
| 148 | u32 val; |
| 149 | |
| 150 | val = inl(port); |
| 151 | |
| 152 | //printf("inl(0x%04x) = 0x%08x\n", port, val); |
| 153 | return val; |
| 154 | } |
| 155 | |
| 156 | void x_outb(u16 port, u8 val) |
| 157 | { |
| 158 | //printf("outb(0x%02x, 0x%04x)\n", val, port); |
| 159 | outb(val, port); |
| 160 | } |
| 161 | |
| 162 | void x_outw(u16 port, u16 val) |
| 163 | { |
| 164 | //printf("outw(0x%04x, 0x%04x)\n", val, port); |
| 165 | outw(val, port); |
| 166 | } |
| 167 | |
| 168 | void x_outl(u16 port, u32 val) |
| 169 | { |
| 170 | //printf("outl(0x%08x, 0x%04x)\n", val, port); |
| 171 | outl(val, port); |
| 172 | } |
| 173 | |
| 174 | u8 Mem_rb(int addr) |
| 175 | { |
| 176 | return (*current->mem->rb) (current, addr); |
| 177 | } |
| 178 | |
| 179 | u16 Mem_rw(int addr) |
| 180 | { |
| 181 | return (*current->mem->rw) (current, addr); |
| 182 | } |
| 183 | |
| 184 | u32 Mem_rl(int addr) |
| 185 | { |
| 186 | return (*current->mem->rl) (current, addr); |
| 187 | } |
| 188 | |
| 189 | void Mem_wb(int addr, u8 val) |
| 190 | { |
| 191 | (*current->mem->wb) (current, addr, val); |
| 192 | } |
| 193 | |
| 194 | void Mem_ww(int addr, u16 val) |
| 195 | { |
| 196 | (*current->mem->ww) (current, addr, val); |
| 197 | } |
| 198 | |
| 199 | void Mem_wl(int addr, u32 val) |
| 200 | { |
| 201 | (*current->mem->wl) (current, addr, val); |
| 202 | } |
| 203 | |
| 204 | void getsecs(unsigned long *sec, unsigned long *usec) |
| 205 | { |
| 206 | struct timeval tv; |
| 207 | gettimeofday(&tv, 0); |
| 208 | *sec = tv.tv_sec; |
| 209 | *usec = tv.tv_usec; |
| 210 | } |
| 211 | |
| 212 | #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00) |
| 213 | #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff) |
| 214 | |
| 215 | u8 bios_checksum(u8 * start, int size) |
| 216 | { |
| 217 | u8 sum = 0; |
| 218 | |
| 219 | while (size-- > 0) |
| 220 | sum += *start++; |
| 221 | return sum; |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Lock/Unlock legacy VGA. Some Bioses try to be very clever and make |
| 226 | * an attempt to detect a legacy ISA card. If they find one they might |
| 227 | * act very strange: for example they might configure the card as a |
| 228 | * monochrome card. This might cause some drivers to choke. |
| 229 | * To avoid this we attempt legacy VGA by writing to all know VGA |
| 230 | * disable registers before we call the BIOS initialization and |
| 231 | * restore the original values afterwards. In beween we hold our |
| 232 | * breath. To get to a (possibly exising) ISA card need to disable |
| 233 | * our current PCI card. |
| 234 | */ |
| 235 | /* |
| 236 | * This is just for booting: we just want to catch pure |
| 237 | * legacy vga therefore we don't worry about mmio etc. |
| 238 | * This stuff should really go into vgaHW.c. However then |
| 239 | * the driver would have to load the vga-module prior to |
| 240 | * doing int10. |
| 241 | */ |
| 242 | /*void |
| 243 | LockLegacyVGA(int screenIndex,legacyVGAPtr vga) |
| 244 | { |
| 245 | xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]); |
| 246 | vga->save_msr = inb(0x3CC); |
| 247 | vga->save_vse = inb(0x3C3); |
| 248 | vga->save_46e8 = inb(0x46e8); |
| 249 | vga->save_pos102 = inb(0x102); |
| 250 | outb(0x3C2, ~(u8)0x03 & vga->save_msr); |
| 251 | outb(0x3C3, ~(u8)0x01 & vga->save_vse); |
| 252 | outb(0x46e8, ~(u8)0x08 & vga->save_46e8); |
| 253 | outb(0x102, ~(u8)0x01 & vga->save_pos102); |
| 254 | xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]); |
| 255 | } |
| 256 | |
| 257 | void |
| 258 | UnlockLegacyVGA(int screenIndex, legacyVGAPtr vga) |
| 259 | { |
| 260 | xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]); |
| 261 | outb(0x102, vga->save_pos102); |
| 262 | outb(0x46e8, vga->save_46e8); |
| 263 | outb(0x3C3, vga->save_vse); |
| 264 | outb(0x3C2, vga->save_msr); |
| 265 | xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]); |
| 266 | } |
| 267 | */ |