1 /* $XFree86: xc/programs/Xserver/hw/xfree86/int10/helper_mem.c,v 1.21 2001/05/22 16:24:37 tsi Exp $ */
4 * execute BIOS int 10h calls in x86 real mode environment
5 * Copyright 1999 Egbert Eich
19 static const OptionInfoRec INT10Options[] = {
20 {OPT_NOINT10, "NoINT10", OPTV_BOOLEAN, {0}, FALSE},
21 {OPT_INIT_PRIMARY, "InitPrimary", OPTV_BOOLEAN, {0}, FALSE},
22 {OPT_BIOS_LOCATION, "BiosLocation", OPTV_STRING, {0}, FALSE},
23 {-1, NULL, OPTV_NONE, {0}, FALSE},
28 void dprint(unsigned long start, unsigned long size)
31 char *c = (char *) start;
33 for (j = 0; j < (size >> 4); j++) {
35 printf("\n0x%lx: ", (unsigned long) c);
36 for (i = 0; i < 16; i++)
37 printf("%2.2x ", (unsigned char) (*(c++)));
39 for (i = 0; i < 16; i++) {
40 printf("%c", ((((unsigned char) (*c)) > 32) && (((unsigned char) (*c)) < 128)) ?
41 (unsigned char) (*(c)) : '.');
52 * here we are really paranoid about faking a "real"
53 * BIOS. Most of this information was pulled from
56 void setup_int_vect(void)
60 /* let the int vects point to the SYS_BIOS seg */
61 for (i = 0; i < 0x80; i++) {
63 MEM_WW((i << 2) + 2, SYS_BIOS >> 4);
66 reset_int_vect(current);
67 /* font tables default location (int 1F) */
68 MEM_WW(0x1f << 2, 0xfa6e);
70 /* int 11 default location (Get Equipment Configuration) */
71 MEM_WW(0x11 << 2, 0xf84d);
72 /* int 12 default location (Get Conventional Memory Size) */
73 MEM_WW(0x12 << 2, 0xf841);
74 /* int 15 default location (I/O System Extensions) */
75 MEM_WW(0x15 << 2, 0xf859);
76 /* int 1A default location (RTC, PCI and others) */
77 MEM_WW(0x1a << 2, 0xff6e);
78 /* int 05 default location (Bound Exceeded) */
79 MEM_WW(0x05 << 2, 0xff54);
80 /* int 08 default location (Double Fault) */
81 MEM_WW(0x08 << 2, 0xfea5);
82 /* int 13 default location (Disk) */
83 MEM_WW(0x13 << 2, 0xec59);
84 /* int 0E default location (Page Fault) */
85 MEM_WW(0x0e << 2, 0xef57);
86 /* int 17 default location (Parallel Port) */
87 MEM_WW(0x17 << 2, 0xefd2);
88 /* fdd table default location (int 1e) */
89 MEM_WW(0x1e << 2, 0xefc7);
91 /* Set Equipment flag to VGA */
92 i = MEM_RB(0x0410) & 0xCF;
94 /* XXX Perhaps setup more of the BDA here. See also int42(0x00). */
98 int setup_system_bios(void *base_addr)
100 char *base = (char *) base_addr;
103 * we trap the "industry standard entry points" to the BIOS
104 * and all other locations by filling them with "hlt"
105 * TODO: implement hlt-handler for these
107 memset(base, 0xf4, 0x10000);
110 strcpy(base + 0x0FFF5, "06/11/99");
111 /* set up eisa ident string */
112 strcpy(base + 0x0FFD9, "PCI_ISA");
113 /* write system model id for IBM-AT */
114 *((unsigned char *) (base + 0x0FFFE)) = 0xfc;
119 void reset_int_vect(void)
122 * This table is normally located at 0xF000:0xF0A4. However, int 0x42,
123 * function 0 (Mode Set) expects it (or a copy) somewhere in the bottom
124 * 64kB. Note that because this data doesn't survive POST, int 0x42 should
125 * only be used during EGA/VGA BIOS initialisation.
127 static const unsigned char VideoParms[] = {
128 /* Timing for modes 0x00 & 0x01 */
129 0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c,
130 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
131 /* Timing for modes 0x02 & 0x03 */
132 0x71, 0x50, 0x5a, 0x0a, 0x1f, 0x06, 0x19, 0x1c,
133 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
134 /* Timing for modes 0x04, 0x05 & 0x06 */
135 0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70,
136 0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00,
137 /* Timing for mode 0x07 */
138 0x61, 0x50, 0x52, 0x0f, 0x19, 0x06, 0x19, 0x19,
139 0x02, 0x0d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00,
140 /* Display page lengths in little endian order */
141 0x00, 0x08, /* Modes 0x00 and 0x01 */
142 0x00, 0x10, /* Modes 0x02 and 0x03 */
143 0x00, 0x40, /* Modes 0x04 and 0x05 */
144 0x00, 0x40, /* Modes 0x06 and 0x07 */
145 /* Number of columns for each mode */
146 40, 40, 80, 80, 40, 40, 80, 80,
147 /* CGA Mode register value for each mode */
148 0x2c, 0x28, 0x2d, 0x29, 0x2a, 0x2e, 0x1e, 0x29,
150 0x00, 0x00, 0x00, 0x00
154 for (i = 0; i < sizeof(VideoParms); i++)
155 MEM_WB(i + (0x1000 - sizeof(VideoParms)), VideoParms[i]);
156 MEM_WW(0x1d << 2, 0x1000 - sizeof(VideoParms));
157 MEM_WW((0x1d << 2) + 2, 0);
159 printf("SETUP INT\n");
160 MEM_WW(0x10 << 2, 0xf065);
161 MEM_WW((0x10 << 2) + 2, SYS_BIOS >> 4);
162 MEM_WW(0x42 << 2, 0xf065);
163 MEM_WW((0x42 << 2) + 2, SYS_BIOS >> 4);
164 MEM_WW(0x6D << 2, 0xf065);
165 MEM_WW((0x6D << 2) + 2, SYS_BIOS >> 4);
168 void set_return_trap(void)
171 * Here we set the exit condition: We return when we encounter
172 * 'hlt' (=0xf4), which we locate at address 0x600 in x86 memory.
174 MEM_WB(0x0600, 0xf4);
177 * Allocate a segment for the stack
179 xf86Int10AllocPages(1, current->stackseg);
182 void *xf86HandleInt10Options(ScrnInfoPtr pScrn, int entityIndex)
184 EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
185 OptionInfoPtr options = NULL;
188 pointer configOptions = NULL;
190 /* Check if xf86CollectOptions() has already been called */
191 if (((pEnt->index < 0) ||
192 !xf86Screens[pEnt->index] ||
193 !(configOptions = xf86Screens[pEnt->index]->options)) &&
195 configOptions = pEnt->device->options;
198 if (!(options = (OptionInfoPtr) xalloc(sizeof(INT10Options))))
201 (void) memcpy(options, INT10Options, sizeof(INT10Options));
202 xf86ProcessOptions(pScrn->scrnIndex, configOptions, options);
210 Bool int10skip(void *options)
212 Bool noint10 = FALSE;
217 xf86GetOptValBool(options, OPT_NOINT10, &noint10);
221 Bool int10_check_bios(int scrnIndex, int codeSeg, unsigned char *vbiosMem)
225 if ((codeSeg & 0x1f) || /* Not 512-byte aligned otherwise */
226 ((codeSeg << 4) < V_BIOS) || ((codeSeg << 4) >= SYS_SIZE))
232 if ((*vbiosMem != 0x55) || (*(vbiosMem + 1) != 0xAA) || !*(vbiosMem + 2))
235 size = *(vbiosMem + 2) * 512;
237 if ((size + (codeSeg << 4)) > SYS_SIZE)
240 if (bios_checksum(vbiosMem, size))
241 xf86DrvMsg(scrnIndex, X_WARNING, "Bad V_BIOS checksum\n");
246 Bool initPrimary(void *options)
248 Bool initPrimary = FALSE;
253 xf86GetOptValBool(options, OPT_INIT_PRIMARY, &initPrimary);
257 void xf86int10ParseBiosLocation(void *options, xf86int10BiosLocationPtr bios)
264 str = xf86GetOptValString(options, OPT_BIOS_LOCATION);
266 bios->bus = BUS_NONE;
272 if (xf86NameCmp(p, "pci"))
274 else if (xf86NameCmp(p, "primary"))
279 if (bios->bus == BUS_NONE)
288 bios->location.legacy = atoi(++p);
290 bios->location.legacy = 0;
294 bios->location.pci.bus = atoi(++p);
295 if ((p = strchr(p, ':'))) {
296 bios->location.pci.dev = atoi(++p);
297 if ((p = strchr(p, ':'))) {
298 bios->location.pci.func = atoi(++p);
304 bios->bus = BUS_NONE;