blob: 8d18798c40aa62ea984f351ccf1a87f4d64839dd [file] [log] [blame]
Li-Ta Lo81521262004-07-08 17:18:27 +00001/* $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
22int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
23u8 x_inb(u16 port);
24u16 x_inw(u16 port);
25void x_outb(u16 port, u8 val);
26void x_outw(u16 port, u16 val);
27u32 x_inl(u16 port);
28void x_outl(u16 port, u32 val);
29
30/* general software interrupt handler */
31u32 getIntVect(int num)
32{
33 return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4);
34}
35
36void pushw(u16 val)
37{
38 X86_ESP -= 2;
39 MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
40}
41
42int 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
Li-Ta Lo8b0356c2005-01-11 03:18:39 +000053 printf("%s: INT %x CS:IP = %x:%x\n", __FUNCTION__,
54 num, MEM_RW((num << 2) + 2), MEM_RW(num << 2));
Li-Ta Lo81521262004-07-08 17:18:27 +000055
56 return 1;
57}
58
59int 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
70int 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
81int 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
92int 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
103int 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
114int 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
125u8 x_inb(u16 port)
126{
127 u8 val;
128
129 val = inb(port);
130
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000131 printf("inb(0x%04x) = 0x%02x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000132
133 return val;
134}
135
136u16 x_inw(u16 port)
137{
138 u16 val;
139
140 val = inw(port);
141
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000142 printf("inw(0x%04x) = 0x%04x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000143 return val;
144}
145
146u32 x_inl(u16 port)
147{
148 u32 val;
149
150 val = inl(port);
151
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000152 printf("inl(0x%04x) = 0x%08x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000153 return val;
154}
155
156void x_outb(u16 port, u8 val)
157{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000158 printf("outb(0x%02x, 0x%04x)\n",
159 val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000160 outb(val, port);
161}
162
163void x_outw(u16 port, u16 val)
164{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000165 printf("outw(0x%04x, 0x%04x)\n", val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000166 outw(val, port);
167}
168
169void x_outl(u16 port, u32 val)
170{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000171 printf("outl(0x%08x, 0x%04x)\n", val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000172 outl(val, port);
173}
174
175u8 Mem_rb(int addr)
176{
177 return (*current->mem->rb) (current, addr);
178}
179
180u16 Mem_rw(int addr)
181{
182 return (*current->mem->rw) (current, addr);
183}
184
185u32 Mem_rl(int addr)
186{
187 return (*current->mem->rl) (current, addr);
188}
189
190void Mem_wb(int addr, u8 val)
191{
192 (*current->mem->wb) (current, addr, val);
193}
194
195void Mem_ww(int addr, u16 val)
196{
197 (*current->mem->ww) (current, addr, val);
198}
199
200void Mem_wl(int addr, u32 val)
201{
202 (*current->mem->wl) (current, addr, val);
203}
204
205void getsecs(unsigned long *sec, unsigned long *usec)
206{
207 struct timeval tv;
208 gettimeofday(&tv, 0);
209 *sec = tv.tv_sec;
210 *usec = tv.tv_usec;
211}
212
213#define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
214#define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
215
216u8 bios_checksum(u8 * start, int size)
217{
218 u8 sum = 0;
219
220 while (size-- > 0)
221 sum += *start++;
222 return sum;
223}
224
225/*
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.
235 */
236/*
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
241 * doing int10.
242 */
243/*void
244LockLegacyVGA(int screenIndex,legacyVGAPtr vga)
245{
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]);
256}
257
258void
259UnlockLegacyVGA(int screenIndex, legacyVGAPtr vga)
260{
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]);
267}
268*/