t132: Add monotonic_timer.c to rmodules_arm
[coreboot.git] / util / vgabios / helper_exec.c
blob73100d96f3c90346ae2c76932fcbe438cf6e68db
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
7 * Part of this is based on code taken from DOSEMU
8 * (C) Copyright 1992, ..., 1999 the "DOSEMU-Development-Team"
9 */
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.
17 #include <x86emu/x86emu.h>
18 #include "helper_exec.h"
19 #include "test.h"
20 #include <sys/io.h>
21 #include <sys/time.h>
22 #include <stdio.h>
25 int port_rep_inb(u16 port, u32 base, int d_f, u32 count);
26 u8 x_inb(u16 port);
27 u16 x_inw(u16 port);
28 void x_outb(u16 port, u8 val);
29 void x_outw(u16 port, u16 val);
30 u32 x_inl(u16 port);
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);
39 void pushw(u16 val)
41 X86_ESP -= 2;
42 MEM_WW(((u32) X86_SS << 4) + X86_SP, val);
45 int run_bios_int(int num)
47 u32 eflags;
49 eflags = X86_EFLAGS;
50 pushw(eflags);
51 pushw(X86_CS);
52 pushw(X86_IP);
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));
59 return 1;
62 int port_rep_inb(u16 port, u32 base, int d_f, u32 count)
64 register int inc = d_f ? -1 : 1;
65 u32 dst = base;
66 while (count--) {
67 MEM_WB(dst, x_inb(port));
68 dst += inc;
70 return dst - base;
73 int port_rep_inw(u16 port, u32 base, int d_f, u32 count)
75 register int inc = d_f ? -2 : 2;
76 u32 dst = base;
77 while (count--) {
78 MEM_WW(dst, x_inw(port));
79 dst += inc;
81 return dst - base;
84 int port_rep_inl(u16 port, u32 base, int d_f, u32 count)
86 register int inc = d_f ? -4 : 4;
87 u32 dst = base;
88 while (count--) {
89 MEM_WL(dst, x_inl(port));
90 dst += inc;
92 return dst - base;
95 int port_rep_outb(u16 port, u32 base, int d_f, u32 count)
97 register int inc = d_f ? -1 : 1;
98 u32 dst = base;
99 while (count--) {
100 x_outb(port, MEM_RB(dst));
101 dst += inc;
103 return dst - base;
106 int port_rep_outw(u16 port, u32 base, int d_f, u32 count)
108 register int inc = d_f ? -2 : 2;
109 u32 dst = base;
110 while (count--) {
111 x_outw(port, MEM_RW(dst));
112 dst += inc;
114 return dst - base;
117 int port_rep_outl(u16 port, u32 base, int d_f, u32 count)
119 register int inc = d_f ? -4 : 4;
120 u32 dst = base;
121 while (count--) {
122 x_outl(port, MEM_RL(dst));
123 dst += inc;
125 return dst - base;
128 u8 x_inb(u16 port)
130 u8 val;
132 val = inb(port);
134 printf("inb(0x%04x) = 0x%02x\n", port, val);
136 return val;
139 u16 x_inw(u16 port)
141 u16 val;
143 val = inw(port);
145 printf("inw(0x%04x) = 0x%04x\n", port, val);
146 return val;
149 u32 x_inl(u16 port)
151 u32 val;
153 val = inl(port);
155 printf("inl(0x%04x) = 0x%08x\n", port, val);
156 return val;
159 void x_outb(u16 port, u8 val)
161 printf("outb(0x%02x, 0x%04x)\n",
162 val, port);
163 outb(val, port);
166 void x_outw(u16 port, u16 val)
168 printf("outw(0x%04x, 0x%04x)\n", val, port);
169 outw(val, port);
172 void x_outl(u16 port, u32 val)
174 printf("outl(0x%08x, 0x%04x)\n", val, port);
175 outl(val, port);
178 u8 Mem_rb(int addr)
180 return (*current->mem->rb) (current, addr);
183 u16 Mem_rw(int addr)
185 return (*current->mem->rw) (current, addr);
188 u32 Mem_rl(int 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)
210 struct timeval tv;
211 gettimeofday(&tv, 0);
212 *sec = tv.tv_sec;
213 *usec = tv.tv_usec;
216 #define TAG(Cfg1Addr) (Cfg1Addr & 0xffff00)
217 #define OFFSET(Cfg1Addr) (Cfg1Addr & 0xff)
219 u8 bios_checksum(u8 * start, int size)
221 u8 sum = 0;
223 while (size-- > 0)
224 sum += *start++;
225 return sum;
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
244 * doing int10.
246 /*void
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]);
261 void
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]);