blob: be53598b036ffdabae94fd2e4d3624344d0a558d [file] [log] [blame]
Li-Ta Lo81521262004-07-08 17:18:27 +00001/* $XFree86: xc/programs/Xserver/hw/xfree86/int10/helper_mem.c,v 1.21 2001/05/22 16:24:37 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#define _INT10_PRIVATE
8
9#define REG pInt
10#if 0
11typedef enum {
12 OPT_NOINT10,
13 OPT_INIT_PRIMARY,
14 OPT_BIOS_LOCATION
15} INT10Opts;
16
17static const OptionInfoRec INT10Options[] = {
18 {OPT_NOINT10, "NoINT10", OPTV_BOOLEAN, {0}, FALSE},
19 {OPT_INIT_PRIMARY, "InitPrimary", OPTV_BOOLEAN, {0}, FALSE},
20 {OPT_BIOS_LOCATION, "BiosLocation", OPTV_STRING, {0}, FALSE},
21 {-1, NULL, OPTV_NONE, {0}, FALSE},
22};
23#endif
24
25#ifdef DEBUG
26void dprint(unsigned long start, unsigned long size)
27{
28 int i, j;
29 char *c = (char *) start;
30
31 for (j = 0; j < (size >> 4); j++) {
32 char *d = c;
33 printf("\n0x%lx: ", (unsigned long) c);
34 for (i = 0; i < 16; i++)
35 printf("%2.2x ", (unsigned char) (*(c++)));
36 c = d;
37 for (i = 0; i < 16; i++) {
38 printf("%c", ((((u8) (*c)) > 32) && (((u8) (*c)) < 128)) ?
39 (unsigned char) (*(c)) : '.');
40 c++;
41 }
42 }
43 printf("\n");
44}
45#endif /* DEBUG */
46
47#if 0
48#ifndef _PC
49/*
50 * here we are really paranoid about faking a "real"
51 * BIOS. Most of this information was pulled from
52 * dosemu.
53 */
54void setup_int_vect(void)
55{
56 int i;
57
58 /* let the int vects point to the SYS_BIOS seg */
59 for (i = 0; i < 0x80; i++) {
60 MEM_WW(i << 2, 0);
61 MEM_WW((i << 2) + 2, SYS_BIOS >> 4);
62 }
63
64 reset_int_vect(current);
65 /* font tables default location (int 1F) */
66 MEM_WW(0x1f << 2, 0xfa6e);
67
68 /* int 11 default location (Get Equipment Configuration) */
69 MEM_WW(0x11 << 2, 0xf84d);
70 /* int 12 default location (Get Conventional Memory Size) */
71 MEM_WW(0x12 << 2, 0xf841);
72 /* int 15 default location (I/O System Extensions) */
73 MEM_WW(0x15 << 2, 0xf859);
74 /* int 1A default location (RTC, PCI and others) */
75 MEM_WW(0x1a << 2, 0xff6e);
76 /* int 05 default location (Bound Exceeded) */
77 MEM_WW(0x05 << 2, 0xff54);
78 /* int 08 default location (Double Fault) */
79 MEM_WW(0x08 << 2, 0xfea5);
80 /* int 13 default location (Disk) */
81 MEM_WW(0x13 << 2, 0xec59);
82 /* int 0E default location (Page Fault) */
83 MEM_WW(0x0e << 2, 0xef57);
84 /* int 17 default location (Parallel Port) */
85 MEM_WW(0x17 << 2, 0xefd2);
86 /* fdd table default location (int 1e) */
87 MEM_WW(0x1e << 2, 0xefc7);
88
89 /* Set Equipment flag to VGA */
90 i = MEM_RB(0x0410) & 0xCF;
91 MEM_WB(0x0410, i);
92 /* XXX Perhaps setup more of the BDA here. See also int42(0x00). */
93}
94#endif
95
96int setup_system_bios(void *base_addr)
97{
98 char *base = (char *) base_addr;
99
100 /*
101 * we trap the "industry standard entry points" to the BIOS
102 * and all other locations by filling them with "hlt"
103 * TODO: implement hlt-handler for these
104 */
105 memset(base, 0xf4, 0x10000);
106
107 /* set bios date */
108 strcpy(base + 0x0FFF5, "06/11/99");
109 /* set up eisa ident string */
110 strcpy(base + 0x0FFD9, "PCI_ISA");
111 /* write system model id for IBM-AT */
112 *((unsigned char *) (base + 0x0FFFE)) = 0xfc;
113
114 return 1;
115}
116
117void reset_int_vect(void)
118{
119 /*
120 * This table is normally located at 0xF000:0xF0A4. However, int 0x42,
121 * function 0 (Mode Set) expects it (or a copy) somewhere in the bottom
122 * 64kB. Note that because this data doesn't survive POST, int 0x42 should
123 * only be used during EGA/VGA BIOS initialisation.
124 */
125 static const u8 VideoParms[] = {
126 /* Timing for modes 0x00 & 0x01 */
127 0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c,
128 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
129 /* Timing for modes 0x02 & 0x03 */
130 0x71, 0x50, 0x5a, 0x0a, 0x1f, 0x06, 0x19, 0x1c,
131 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
132 /* Timing for modes 0x04, 0x05 & 0x06 */
133 0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70,
134 0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
135 /* Timing for mode 0x07 */
136 0x61, 0x50, 0x52, 0x0f, 0x19, 0x06, 0x19, 0x19,
137 0x02, 0x0d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
138 /* Display page lengths in little endian order */
139 0x00, 0x08, /* Modes 0x00 and 0x01 */
140 0x00, 0x10, /* Modes 0x02 and 0x03 */
141 0x00, 0x40, /* Modes 0x04 and 0x05 */
142 0x00, 0x40, /* Modes 0x06 and 0x07 */
143 /* Number of columns for each mode */
144 40, 40, 80, 80, 40, 40, 80, 80,
145 /* CGA Mode register value for each mode */
146 0x2c, 0x28, 0x2d, 0x29, 0x2a, 0x2e, 0x1e, 0x29,
147 /* Padding */
148 0x00, 0x00, 0x00, 0x00
149 };
150 int i;
151
152 for (i = 0; i < sizeof(VideoParms); i++)
153 MEM_WB(i + (0x1000 - sizeof(VideoParms)), VideoParms[i]);
154 MEM_WW(0x1d << 2, 0x1000 - sizeof(VideoParms));
155 MEM_WW((0x1d << 2) + 2, 0);
156
157 printf("SETUP INT\n");
158 MEM_WW(0x10 << 2, 0xf065);
159 MEM_WW((0x10 << 2) + 2, SYS_BIOS >> 4);
160 MEM_WW(0x42 << 2, 0xf065);
161 MEM_WW((0x42 << 2) + 2, SYS_BIOS >> 4);
162 MEM_WW(0x6D << 2, 0xf065);
163 MEM_WW((0x6D << 2) + 2, SYS_BIOS >> 4);
164}
165
166void set_return_trap(void)
167{
168 /*
169 * Here we set the exit condition: We return when we encounter
170 * 'hlt' (=0xf4), which we locate at address 0x600 in x86 memory.
171 */
172 MEM_WB(0x0600, 0xf4);
173
174 /*
175 * Allocate a segment for the stack
176 */
177 xf86Int10AllocPages(1, current->stackseg);
178}
179
180void *xf86HandleInt10Options(ScrnInfoPtr pScrn, int entityIndex)
181{
182 EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
183 OptionInfoPtr options = NULL;
184
185 if (pEnt->device) {
186 pointer configOptions = NULL;
187
188 /* Check if xf86CollectOptions() has already been called */
189 if (((pEnt->index < 0) ||
190 !xf86Screens[pEnt->index] ||
191 !(configOptions = xf86Screens[pEnt->index]->options)) &&
192 pEnt->device)
193 configOptions = pEnt->device->options;
194
195 if (configOptions) {
196 if (!(options = (OptionInfoPtr) xalloc(sizeof(INT10Options))))
197 return NULL;
198
199 (void) memcpy(options, INT10Options, sizeof(INT10Options));
200 xf86ProcessOptions(pScrn->scrnIndex, configOptions, options);
201 }
202 }
203 xfree(pEnt);
204
205 return options;
206}
207
208Bool int10skip(void *options)
209{
210 Bool noint10 = FALSE;
211
212 if (!options)
213 return FALSE;
214
215 xf86GetOptValBool(options, OPT_NOINT10, &noint10);
216 return noint10;
217}
218
219Bool int10_check_bios(int scrnIndex, int codeSeg, unsigned char *vbiosMem)
220{
221 int size;
222
223 if ((codeSeg & 0x1f) || /* Not 512-byte aligned otherwise */
224 ((codeSeg << 4) < V_BIOS) || ((codeSeg << 4) >= SYS_SIZE))
225 return FALSE;
226
227 if (xf86IsPc98())
228 return FALSE;
229
230 if ((*vbiosMem != 0x55) || (*(vbiosMem + 1) != 0xAA) || !*(vbiosMem + 2))
231 return FALSE;
232
233 size = *(vbiosMem + 2) * 512;
234
235 if ((size + (codeSeg << 4)) > SYS_SIZE)
236 return FALSE;
237
238 if (bios_checksum(vbiosMem, size))
239 xf86DrvMsg(scrnIndex, X_WARNING, "Bad V_BIOS checksum\n");
240
241 return TRUE;
242}
243
244Bool initPrimary(void *options)
245{
246 Bool initPrimary = FALSE;
247
248 if (!options)
249 return FALSE;
250
251 xf86GetOptValBool(options, OPT_INIT_PRIMARY, &initPrimary);
252 return initPrimary;
253}
254
255void xf86int10ParseBiosLocation(void *options, xf86int10BiosLocationPtr bios)
256{
257 char *s;
258 char *p;
259 char *str = NULL;
260
261 if (options)
262 str = xf86GetOptValString(options, OPT_BIOS_LOCATION);
263
264 bios->bus = BUS_NONE;
265 if (!str)
266 return;
267
268 s = xstrdup(str);
269 p = strtok(s, ":");
270 if (xf86NameCmp(p, "pci"))
271 bios->bus = BUS_PCI;
272 else if (xf86NameCmp(p, "primary"))
273 bios->bus = BUS_ISA;
274
275 xfree(s);
276
277 if (bios->bus == BUS_NONE)
278 return;
279
280 s = xstrdup(str);
281 p = strchr(s, ':');
282
283 switch (bios->bus) {
284 case BUS_ISA:
285 if (p)
286 bios->location.legacy = atoi(++p);
287 else
288 bios->location.legacy = 0;
289 break;
290 case BUS_PCI:
291 if (p) {
292 bios->location.pci.bus = atoi(++p);
293 if ((p = strchr(p, ':'))) {
294 bios->location.pci.dev = atoi(++p);
295 if ((p = strchr(p, ':'))) {
296 bios->location.pci.func = atoi(++p);
297 break;
298 }
299 }
300 }
301 /* fall through */
302 bios->bus = BUS_NONE;
303 break;
304 default:
305 break;
306 }
307 xfree(s);
308}
309
310
311#endif