blob: 4d6aae5a7c4a6095401983db87e0f74ae05ebecf [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 */
Luc Verhaegene6e899d2009-05-27 11:39:16 +000017#include <sys/io.h>
Li-Ta Lo81521262004-07-08 17:18:27 +000018#include <sys/time.h>
Luc Verhaegene6e899d2009-05-27 11:39:16 +000019#include <stdio.h>
Stefan Reinauer850e7d42015-09-28 13:12:04 -070020#include <stdtypes.h>
21#include <x86emu/x86emu.h>
22#include "helper_exec.h"
23#include "testbios.h"
Li-Ta Lo81521262004-07-08 17:18:27 +000024
25/* general software interrupt handler */
26u32 getIntVect(int num)
27{
28 return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4);
29}
30
31void pushw(u16 val)
32{
33 X86_ESP -= 2;
34 MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
35}
36
37int run_bios_int(int num)
38{
39 u32 eflags;
40
41 eflags = X86_EFLAGS;
42 pushw(eflags);
43 pushw(X86_CS);
44 pushw(X86_IP);
45 X86_CS = MEM_RW((num << 2) + 2);
46 X86_IP = MEM_RW(num << 2);
47
Li-Ta Lo8b0356c2005-01-11 03:18:39 +000048 printf("%s: INT %x CS:IP = %x:%x\n", __FUNCTION__,
49 num, MEM_RW((num << 2) + 2), MEM_RW(num << 2));
Li-Ta Lo81521262004-07-08 17:18:27 +000050
51 return 1;
52}
53
Stefan Reinauer850e7d42015-09-28 13:12:04 -070054#if 0
55
Li-Ta Lo81521262004-07-08 17:18:27 +000056int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
57{
58 register int inc = d_f ? -1 : 1;
59 u32 dst = base;
60 while (count--) {
61 MEM_WB(dst, x_inb(port));
62 dst += inc;
63 }
64 return dst - base;
65}
66
67int port_rep_inw(u16 port, u32 base, int d_f, u32 count)
68{
69 register int inc = d_f ? -2 : 2;
70 u32 dst = base;
71 while (count--) {
72 MEM_WW(dst, x_inw(port));
73 dst += inc;
74 }
75 return dst - base;
76}
77
78int port_rep_inl(u16 port, u32 base, int d_f, u32 count)
79{
80 register int inc = d_f ? -4 : 4;
81 u32 dst = base;
82 while (count--) {
83 MEM_WL(dst, x_inl(port));
84 dst += inc;
85 }
86 return dst - base;
87}
88
89int port_rep_outb(u16 port, u32 base, int d_f, u32 count)
90{
91 register int inc = d_f ? -1 : 1;
92 u32 dst = base;
93 while (count--) {
94 x_outb(port, MEM_RB(dst));
95 dst += inc;
96 }
97 return dst - base;
98}
99
100int port_rep_outw(u16 port, u32 base, int d_f, u32 count)
101{
102 register int inc = d_f ? -2 : 2;
103 u32 dst = base;
104 while (count--) {
105 x_outw(port, MEM_RW(dst));
106 dst += inc;
107 }
108 return dst - base;
109}
110
111int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
112{
113 register int inc = d_f ? -4 : 4;
114 u32 dst = base;
115 while (count--) {
116 x_outl(port, MEM_RL(dst));
117 dst += inc;
118 }
119 return dst - base;
120}
121
Stefan Reinauer850e7d42015-09-28 13:12:04 -0700122#endif
123
Li-Ta Lo81521262004-07-08 17:18:27 +0000124u8 x_inb(u16 port)
125{
126 u8 val;
127
128 val = inb(port);
129
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000130 printf("inb(0x%04x) = 0x%02x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000131
132 return val;
133}
134
135u16 x_inw(u16 port)
136{
137 u16 val;
138
139 val = inw(port);
140
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000141 printf("inw(0x%04x) = 0x%04x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000142 return val;
143}
144
145u32 x_inl(u16 port)
146{
147 u32 val;
148
149 val = inl(port);
150
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000151 printf("inl(0x%04x) = 0x%08x\n", port, val);
Li-Ta Lo81521262004-07-08 17:18:27 +0000152 return val;
153}
154
155void x_outb(u16 port, u8 val)
156{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000157 printf("outb(0x%02x, 0x%04x)\n",
158 val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000159 outb(val, port);
160}
161
162void x_outw(u16 port, u16 val)
163{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000164 printf("outw(0x%04x, 0x%04x)\n", val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000165 outw(val, port);
166}
167
168void x_outl(u16 port, u32 val)
169{
Li-Ta Lo8b0356c2005-01-11 03:18:39 +0000170 printf("outl(0x%08x, 0x%04x)\n", val, port);
Li-Ta Lo81521262004-07-08 17:18:27 +0000171 outl(val, port);
172}
173
Stefan Reinauer850e7d42015-09-28 13:12:04 -0700174#if 0
Li-Ta Lo81521262004-07-08 17:18:27 +0000175u8 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}
Stefan Reinauer850e7d42015-09-28 13:12:04 -0700204#endif
Li-Ta Lo81521262004-07-08 17:18:27 +0000205
206void getsecs(unsigned long *sec, unsigned long *usec)
207{
208 struct timeval tv;
209 gettimeofday(&tv, 0);
210 *sec = tv.tv_sec;
211 *usec = tv.tv_usec;
212}
213
214#define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
215#define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
216
217u8 bios_checksum(u8 * start, int size)
218{
219 u8 sum = 0;
220
221 while (size-- > 0)
222 sum += *start++;
223 return sum;
224}
225
226/*
227 * Lock/Unlock legacy VGA. Some Bioses try to be very clever and make
228 * an attempt to detect a legacy ISA card. If they find one they might
229 * act very strange: for example they might configure the card as a
230 * monochrome card. This might cause some drivers to choke.
231 * To avoid this we attempt legacy VGA by writing to all know VGA
232 * disable registers before we call the BIOS initialization and
233 * restore the original values afterwards. In beween we hold our
234 * breath. To get to a (possibly exising) ISA card need to disable
235 * our current PCI card.
236 */
237/*
238 * This is just for booting: we just want to catch pure
239 * legacy vga therefore we don't worry about mmio etc.
240 * This stuff should really go into vgaHW.c. However then
241 * the driver would have to load the vga-module prior to
242 * doing int10.
243 */
244/*void
245LockLegacyVGA(int screenIndex,legacyVGAPtr vga)
246{
247 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
248 vga->save_msr = inb(0x3CC);
249 vga->save_vse = inb(0x3C3);
250 vga->save_46e8 = inb(0x46e8);
251 vga->save_pos102 = inb(0x102);
252 outb(0x3C2, ~(u8)0x03 & vga->save_msr);
253 outb(0x3C3, ~(u8)0x01 & vga->save_vse);
254 outb(0x46e8, ~(u8)0x08 & vga->save_46e8);
255 outb(0x102, ~(u8)0x01 & vga->save_pos102);
256 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);
257}
258
259void
260UnlockLegacyVGA(int screenIndex, legacyVGAPtr vga)
261{
262 xf86SetCurrentAccess(FALSE, xf86Screens[screenIndex]);
263 outb(0x102, vga->save_pos102);
264 outb(0x46e8, vga->save_46e8);
265 outb(0x3C3, vga->save_vse);
266 outb(0x3C2, vga->save_msr);
267 xf86SetCurrentAccess(TRUE, xf86Screens[screenIndex]);
268}
269*/