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
17 static 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},
26 void dprint(unsigned long start, unsigned long size)
29 char *c = (char *) start;
31 for (j = 0; j < (size >> 4); j++) {
33 printf("\n0x%lx: ", (unsigned long) c);
34 for (i = 0; i < 16; i++)
35 printf("%2.2x ", (unsigned char) (*(c++)));
37 for (i = 0; i < 16; i++) {
38 printf("%c", ((((u8) (*c)) > 32) && (((u8) (*c)) < 128)) ?
39 (unsigned char) (*(c)) : '.');
50 * here we are really paranoid about faking a "real"
51 * BIOS. Most of this information was pulled from
54 void setup_int_vect(void)
58 /* let the int vects point to the SYS_BIOS seg */
59 for (i = 0; i < 0x80; i++) {
61 MEM_WW((i << 2) + 2, SYS_BIOS >> 4);
64 reset_int_vect(current);
65 /* font tables default location (int 1F) */
66 MEM_WW(0x1f << 2, 0xfa6e);
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);
89 /* Set Equipment flag to VGA */
90 i = MEM_RB(0x0410) & 0xCF;
92 /* XXX Perhaps setup more of the BDA here. See also int42(0x00). */
96 int setup_system_bios(void *base_addr)
98 char *base = (char *) base_addr;
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
105 memset(base, 0xf4, 0x10000);
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;
117 void reset_int_vect(void)
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.
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,
148 0x00, 0x00, 0x00, 0x00
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);
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);
166 void set_return_trap(void)
169 * Here we set the exit condition: We return when we encounter
170 * 'hlt' (=0xf4), which we locate at address 0x600 in x86 memory.
172 MEM_WB(0x0600, 0xf4);
175 * Allocate a segment for the stack
177 xf86Int10AllocPages(1, current->stackseg);
180 void *xf86HandleInt10Options(ScrnInfoPtr pScrn, int entityIndex)
182 EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
183 OptionInfoPtr options = NULL;
186 pointer configOptions = NULL;
188 /* Check if xf86CollectOptions() has already been called */
189 if (((pEnt->index < 0) ||
190 !xf86Screens[pEnt->index] ||
191 !(configOptions = xf86Screens[pEnt->index]->options)) &&
193 configOptions = pEnt->device->options;
196 if (!(options = (OptionInfoPtr) xalloc(sizeof(INT10Options))))
199 (void) memcpy(options, INT10Options, sizeof(INT10Options));
200 xf86ProcessOptions(pScrn->scrnIndex, configOptions, options);
208 Bool int10skip(void *options)
210 Bool noint10 = FALSE;
215 xf86GetOptValBool(options, OPT_NOINT10, &noint10);
219 Bool int10_check_bios(int scrnIndex, int codeSeg, unsigned char *vbiosMem)
223 if ((codeSeg & 0x1f) || /* Not 512-byte aligned otherwise */
224 ((codeSeg << 4) < V_BIOS) || ((codeSeg << 4) >= SYS_SIZE))
230 if ((*vbiosMem != 0x55) || (*(vbiosMem + 1) != 0xAA) || !*(vbiosMem + 2))
233 size = *(vbiosMem + 2) * 512;
235 if ((size + (codeSeg << 4)) > SYS_SIZE)
238 if (bios_checksum(vbiosMem, size))
239 xf86DrvMsg(scrnIndex, X_WARNING, "Bad V_BIOS checksum\n");
244 Bool initPrimary(void *options)
246 Bool initPrimary = FALSE;
251 xf86GetOptValBool(options, OPT_INIT_PRIMARY, &initPrimary);
255 void xf86int10ParseBiosLocation(void *options, xf86int10BiosLocationPtr bios)
262 str = xf86GetOptValString(options, OPT_BIOS_LOCATION);
264 bios->bus = BUS_NONE;
270 if (xf86NameCmp(p, "pci"))
272 else if (xf86NameCmp(p, "primary"))
277 if (bios->bus == BUS_NONE)
286 bios->location.legacy = atoi(++p);
288 bios->location.legacy = 0;
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);
302 bios->bus = BUS_NONE;