1 | ␊ |
2 | /* Copied from 915 resolution created by steve tomljenovic␊ |
3 | *␊ |
4 | * This code is based on the techniques used in :␊ |
5 | *␊ |
6 | * - 855patch. Many thanks to Christian Zietz (czietz gmx net)␊ |
7 | * for demonstrating how to shadow the VBIOS into system RAM␊ |
8 | * and then modify it.␊ |
9 | *␊ |
10 | * - 1280patch by Andrew Tipton (andrewtipton null li).␊ |
11 | *␊ |
12 | * - 855resolution by Alain Poirier␊ |
13 | *␊ |
14 | * This source code is into the public domain.␊ |
15 | */␊ |
16 | ␊ |
17 | #include "libsaio.h"␊ |
18 | #include "autoresolution.h"␊ |
19 | #include "nvidia_resolution.h"␊ |
20 | #include "ati_resolution.h"␊ |
21 | #include "gma_resolution.h"␊ |
22 | #include "../boot2/graphics.h"␊ |
23 | ␊ |
24 | char * chipsetTypeNames[] = {␊ |
25 | ␉"UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",␊ |
26 | ␉"946GZ", "955X", "G965", "Q965", "965GM", "975X",␊ |
27 | ␉"P35", "X48", "B43", "Q45", "P45", "GM45", "G41", "G31", "G45", "500"␊ |
28 | };␊ |
29 | ␊ |
30 | uint32_t getChipsetId(void)␊ |
31 | {␊ |
32 | ␉outl(0xcf8, 0x80000000);␊ |
33 | ␉return inl(0xcfc);␊ |
34 | }␊ |
35 | ␊ |
36 | chipsetType getChipset(uint32_t id)␊ |
37 | {␊ |
38 | ␉chipsetType type;␊ |
39 | ␉␊ |
40 | ␉switch (id)␊ |
41 | ␉{␊ |
42 | ␉␉case 0x35758086:␊ |
43 | ␉␉␉type = CT_830;␊ |
44 | ␉␉␉break;␊ |
45 | ␉␉␊ |
46 | ␉␉case 0x25608086:␊ |
47 | ␉␉␉type = CT_845G;␊ |
48 | ␉␉␉break;␊ |
49 | ␉␉␉␉␊ |
50 | ␉␉case 0x35808086:␊ |
51 | ␉␉␉type = CT_855GM;␊ |
52 | ␉␉␉break;␊ |
53 | ␉␉␉␉␊ |
54 | ␉␉case 0x25708086:␊ |
55 | ␉␉␉type = CT_865G;␊ |
56 | ␉␉␉break;␊ |
57 | ␉␉␊ |
58 | ␉␉case 0x25808086:␊ |
59 | ␉␉␉type = CT_915G;␊ |
60 | ␉␉␉break;␊ |
61 | ␉␉␉␊ |
62 | ␉␉case 0x25908086:␊ |
63 | ␉␉␉type = CT_915GM;␊ |
64 | ␉␉␉break;␊ |
65 | ␉␉␉␊ |
66 | ␉␉case 0x27708086:␊ |
67 | ␉␉␉type = CT_945G;␊ |
68 | ␉␉␉break;␊ |
69 | ␉␉␉␊ |
70 | ␉␉case 0x27748086:␊ |
71 | ␉␉␉type = CT_955X;␊ |
72 | ␉␉␉break;␊ |
73 | ␉␉␉␊ |
74 | ␉␉case 0x277c8086:␊ |
75 | ␉␉␉type = CT_975X;␊ |
76 | ␉␉␉break;␊ |
77 | ␉␉␊ |
78 | ␉␉case 0x27a08086:␊ |
79 | ␉␉␉type = CT_945GM;␊ |
80 | ␉␉␉break;␊ |
81 | ␉␉␉␊ |
82 | ␉␉case 0x27ac8086:␊ |
83 | ␉␉␉type = CT_945GME;␊ |
84 | ␉␉␉break;␊ |
85 | ␉␉␉␊ |
86 | ␉␉case 0x29708086:␊ |
87 | ␉␉␉type = CT_946GZ;␊ |
88 | ␉␉␉break;␊ |
89 | ␉␉␉␊ |
90 | ␉␉case 0x29a08086:␊ |
91 | ␉␉␉type = CT_G965;␊ |
92 | ␉␉␉break;␊ |
93 | ␉␉␉␊ |
94 | ␉␉case 0x29908086:␊ |
95 | ␉␉␉type = CT_Q965;␊ |
96 | ␉␉␉break;␊ |
97 | ␉␉␉␊ |
98 | ␉␉case 0x2a008086:␊ |
99 | ␉␉␉type = CT_965GM;␊ |
100 | ␉␉␉break;␊ |
101 | ␉␉␉␊ |
102 | ␉␉case 0x29e08086:␊ |
103 | ␉␉␉type = CT_X48;␊ |
104 | ␉␉␉break;␉␉␉␊ |
105 | ␉␉␉␊ |
106 | ␉␉case 0x2a408086:␊ |
107 | ␉␉␉type = CT_GM45;␊ |
108 | ␉␉␉break;␊ |
109 | ␉␉␉␊ |
110 | ␉␉case 0x2e108086:␊ |
111 | ␉␉case 0X2e908086:␊ |
112 | ␉␉␉type = CT_B43;␊ |
113 | ␉␉␉break;␊ |
114 | ␉␉␉␊ |
115 | ␉␉case 0x2e208086:␊ |
116 | ␉␉␉type = CT_P45;␊ |
117 | ␉␉␉break;␊ |
118 | ␉␉␉␊ |
119 | ␉␉case 0x2e308086:␊ |
120 | ␉␉␉type = CT_G41;␊ |
121 | ␉␉␉break;␊ |
122 | ␉␉␉␊ |
123 | ␉␉case 0x29c08086:␊ |
124 | ␉␉␉type = CT_G31;␊ |
125 | ␉␉␉break;␊ |
126 | ␉␉␉␊ |
127 | ␉␉case 0x29208086:␊ |
128 | ␉␉␉type = CT_G45;␊ |
129 | ␉␉␉break;␊ |
130 | ␉␉␉␊ |
131 | ␉␉case 0x81008086:␊ |
132 | ␉␉␉type = CT_500;␊ |
133 | ␉␉␉break;␊ |
134 | ␉␉␉␊ |
135 | ␉␉default:␊ |
136 | ␉␉␉type = CT_UNKWN;␊ |
137 | ␉␉␉break;␊ |
138 | ␉}␊ |
139 | ␉return type;␊ |
140 | }␊ |
141 | ␊ |
142 | ␊ |
143 | void gtfTimings(uint32_t x, uint32_t y, uint32_t freq,␊ |
144 | ␉␉␉␉ uint32_t *clock,␊ |
145 | ␉␉␉␉ uint16_t *hSyncStart, uint16_t *hSyncEnd, uint16_t *hBlank,␊ |
146 | ␉␉␉␉ uint16_t *vSyncStart, uint16_t *vSyncEnd, uint16_t *vBlank)␊ |
147 | {␊ |
148 | ␉uint32_t hbl, vbl, vfreq;␊ |
149 | ␉␊ |
150 | ␉vbl = y + (y+1)/(20000/(11*freq) - 1) + 1;␊ |
151 | ␉␊ |
152 | ␉vfreq = vbl * freq;␊ |
153 | ␉hbl = 16 * (int)(x * (30 - 300000 / vfreq) /␊ |
154 | ␉␉␉␉␉ + (70 + 300000 / vfreq) / 16 + 0);␊ |
155 | ␉␊ |
156 | ␉*vSyncStart = y;␊ |
157 | ␉*vSyncEnd = y + 3;␊ |
158 | ␉*vBlank = vbl;␉␊ |
159 | ␉*hSyncStart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 ;␉␊ |
160 | ␉*hSyncEnd = x + hbl / 2;␉␊ |
161 | ␉*hBlank = x + hbl;␉␊ |
162 | ␉*clock = (x + hbl) * vfreq / 1000;␊ |
163 | }␊ |
164 | ␊ |
165 | ␊ |
166 | void getAspectRatio(sAspect* aspect, uint32_t x, uint32_t y)␊ |
167 | {␊ |
168 | ␉if ((y * 16 / 9) == x)␊ |
169 | ␉{␊ |
170 | ␉␉aspect->width = 16;␊ |
171 | ␉␉aspect->height = 9;␊ |
172 | ␉}␊ |
173 | ␉else if ((y * 16 / 10) == x)␊ |
174 | ␉{␊ |
175 | ␉␉aspect->width = 16;␊ |
176 | ␉␉aspect->height = 10;␊ |
177 | ␉}␊ |
178 | ␉else if ((y * 5 / 4) == x)␊ |
179 | ␉{␊ |
180 | ␉␉aspect->width = 5;␊ |
181 | ␉␉aspect->height = 4;␊ |
182 | ␉}␊ |
183 | ␉else if ((y * 15 / 9) == x)␊ |
184 | ␉{␊ |
185 | ␉␉aspect->width = 15;␊ |
186 | ␉␉aspect->height = 9;␊ |
187 | ␉}␊ |
188 | ␉else␊ |
189 | ␉{␊ |
190 | ␉␉aspect->width = 4;␊ |
191 | ␉␉aspect->height = 3;␊ |
192 | ␉}␊ |
193 | ␉PRINT("Aspect Ratio is %d/%d\n", aspect->width, aspect->height);␊ |
194 | }␊ |
195 | ␊ |
196 | ␊ |
197 | /*␊ |
198 | * initialize the mode tables chain␊ |
199 | * tablesCount represents the number of VESA tables in the vBios␊ |
200 | * return value is a pointer to the first table␊ |
201 | */␊ |
202 | sModeTable * intializeTables(vBiosMap * map, int tablesCount) {␊ |
203 | ␉map->modeTables = (sModeTable *)malloc(sizeof(sModeTable));␊ |
204 | ␉sModeTable * table = map->modeTables;␊ |
205 | ␉␊ |
206 | ␉PRINT("Creating %d Mode Tables\n", tablesCount);␊ |
207 | ␉␊ |
208 | ␉int i = tablesCount;␊ |
209 | ␉while ( i != 0 )␊ |
210 | ␉{␉␉␊ |
211 | ␉␉table->id = tablesCount - i;␊ |
212 | ␉␉PRINT("New table with id : %d\n", table->id);␊ |
213 | ␉␉␊ |
214 | ␉␉// opening the chain if it's the first table␊ |
215 | ␉␉if (i == tablesCount)␊ |
216 | ␉␉␉table->prev = NULL;␊ |
217 | ␉␉else // attache the table to the chain␊ |
218 | ␉␉␉table->prev = table; ␊ |
219 | ␉␉␊ |
220 | ␉␉//if there is more than one table, alloc the next one␊ |
221 | ␉␉if (i > 1)␊ |
222 | ␉␉{␊ |
223 | ␉␉␉table->next = (sModeTable *)malloc(sizeof(sModeTable));␊ |
224 | ␉␉␉table = table->next;␊ |
225 | ␉␉}␊ |
226 | ␉␉else // no more table, close the chain␊ |
227 | ␉␉␉table->next = NULL;␊ |
228 | ␉␉␊ |
229 | ␉␉i--;␊ |
230 | ␉}␊ |
231 | ␉␊ |
232 | ␉return map->modeTables;␊ |
233 | }␊ |
234 | ␊ |
235 | ␊ |
236 | void closeVbios(vBiosMap * map);␊ |
237 | ␊ |
238 | vBiosMap * openVbios(chipsetType forcedChipset)␊ |
239 | {␊ |
240 | ␉uint32_t z;␊ |
241 | ␉vBiosMap * map = NEW(vBiosMap);␊ |
242 | ␉␊ |
243 | ␉for(z = 0; z < sizeof(vBiosMap); z++)␊ |
244 | ␉␉((char*)map)[z] = 0;␊ |
245 | ␉␊ |
246 | ␉/*␊ |
247 | ␉ * Determine chipset␊ |
248 | ␉ */␊ |
249 | ␉␊ |
250 | ␉if (forcedChipset == CT_UNKWN)␊ |
251 | ␉{␊ |
252 | ␉␉map->chipsetId = getChipsetId();␊ |
253 | ␉␉map->chipset = getChipset(map->chipsetId);␊ |
254 | ␉␉PRINT("Chipset is %s (pci id 0x%x)\n",chipsetTypeNames[map->chipset], map->chipsetId);␊ |
255 | ␉}␊ |
256 | ␉else if (forcedChipset != CT_UNKWN)␊ |
257 | ␉{␊ |
258 | ␉␉map->chipset = forcedChipset;␊ |
259 | ␉}␊ |
260 | ␉else␊ |
261 | ␉{␊ |
262 | ␉␉map->chipset = CT_915GM;␊ |
263 | ␉}␊ |
264 | ␉ ␊ |
265 | ␉/*␊ |
266 | ␉ * Map the video bios to memory␊ |
267 | ␉ */␊ |
268 | ␉␊ |
269 | ␉map->biosPtr=(uint8_t*)VBIOS_START;␊ |
270 | ␉␊ |
271 | ␉/*␊ |
272 | ␉ * Common initialisation␊ |
273 | ␉ */␊ |
274 | ␉␊ |
275 | ␉map->hasSwitched = false;␊ |
276 | ␉␊ |
277 | ␉/*␊ |
278 | ␉ * check if we have ATI Radeon and open atombios␊ |
279 | ␉ */␊ |
280 | ␉atiBiosTables atiTables;␊ |
281 | ␉␊ |
282 | ␉atiTables.base = map->biosPtr;␊ |
283 | ␉atiTables.atomRomHeader = (atomRomHeader *) (map->biosPtr + *(uint16_t *) (map->biosPtr + OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER)); ␊ |
284 | ␉␊ |
285 | ␉if (strcmp ((char *) atiTables.atomRomHeader->firmWareSignature, "ATOM") == 0)␊ |
286 | ␉{␊ |
287 | ␉␉map->bios = BT_ATI_1;␊ |
288 | ␉␉PRINT("We have an AtomBios Card\n");␊ |
289 | ␉␉return openAtiVbios(map, atiTables);␊ |
290 | ␉}␊ |
291 | ␊ |
292 | ␊ |
293 | ␉/*␊ |
294 | ␉ * check if we have NVidia␊ |
295 | ␉ */␊ |
296 | ␉if (map->bios != BT_ATI_1)␊ |
297 | ␉{␊ |
298 | ␉␉int i = 0;␊ |
299 | ␉␉while (i < 512) // we don't need to look through the whole bios, just the first 512 bytes␊ |
300 | ␉␉{␊ |
301 | ␉␉␉if ((map->biosPtr[i] == 'N') ␊ |
302 | ␉␉␉␉&& (map->biosPtr[i+1] == 'V') ␊ |
303 | ␉␉␉␉&& (map->biosPtr[i+2] == 'I') ␊ |
304 | ␉␉␉␉&& (map->biosPtr[i+3] == 'D')) ␊ |
305 | ␉␉␉{␊ |
306 | ␉␉␉␉map->bios = BT_NVDA;␊ |
307 | ␉␉␉␉PRINT("We have an NVIDIA Card\n");␊ |
308 | ␉␉␉␉return openNvidiaVbios(map);␊ |
309 | ␉␉␉␉break;␊ |
310 | ␉␉␉}␊ |
311 | ␉␉␉i++;␊ |
312 | ␉␉}␊ |
313 | ␉}␊ |
314 | ␉␊ |
315 | ␉/*␊ |
316 | ␉ * check if we have Intel␊ |
317 | ␉ */␊ |
318 | ␉ ␊ |
319 | ␉if ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA))␊ |
320 | ␉{␊ |
321 | ␉␉int i = 0;␊ |
322 | ␉␉while (i < VBIOS_SIZE)␊ |
323 | ␉␉{␊ |
324 | ␉␉␉if ((map->biosPtr[i] == 'I') ␊ |
325 | ␉␉␉␉&& (map->biosPtr[i+1] == 'n') ␊ |
326 | ␉␉␉␉&& (map->biosPtr[i+2] == 't') ␊ |
327 | ␉␉␉␉&& (map->biosPtr[i+3] == 'e') ␊ |
328 | ␉␉␉␉&& (map->biosPtr[i+4] == 'l')) ␊ |
329 | ␉␉␉{␊ |
330 | ␉␉␉␉map->bios = BT_1;␊ |
331 | ␉␉␉␉PRINT("We have an Intel Card\n");␊ |
332 | ␉␉␉␉saveVbios(map);␊ |
333 | ␉␉␉␉return openIntelVbios(map);␊ |
334 | ␉␉␉␉break;␊ |
335 | ␉␉␉}␊ |
336 | ␉␉␉i++;␊ |
337 | ␉␉}␊ |
338 | ␉}␊ |
339 | ␉␊ |
340 | ␉/*␊ |
341 | ␉ * Unidentified Chipset␊ |
342 | ␉ */␊ |
343 | ␉␊ |
344 | ␉if ( (map->chipset == CT_UNKWN) || ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA) && (map->bios != BT_1)) )␊ |
345 | ␉{␊ |
346 | ␉␉PRINT("Unknown chipset type and unrecognized bios.\n");␊ |
347 | ␉␉␊ |
348 | ␉␉PRINT("autoresolution only works with Intel 800/900 series graphic chipsets.\n");␊ |
349 | ␉␉␊ |
350 | ␉␉PRINT("Chipset Id: %x\n", map->chipsetId);␊ |
351 | ␉␉closeVbios(map);␊ |
352 | ␉␉return 0;␊ |
353 | ␉}␊ |
354 | ␊ |
355 | ␉/*␊ |
356 | ␉ * Should never get there ␊ |
357 | ␉ */␊ |
358 | ␉return 0;␊ |
359 | }␊ |
360 | ␊ |
361 | void closeVbios(vBiosMap * map)␊ |
362 | {␊ |
363 | ␉PRINT("Closing VBios\n");␊ |
364 | ␉//make sure to turn autoResolution off␊ |
365 | ␉if (gAutoResolution == TRUE)␊ |
366 | ␉␉gAutoResolution = FALSE;␊ |
367 | ␉␊ |
368 | ␉// if we saved the vBios, free the copy␊ |
369 | ␉if (map->biosBackupPtr != NULL)␊ |
370 | ␉{␊ |
371 | ␉␉PRINT("Freeing biosBackupPtr\t");␊ |
372 | ␉␉FREE(map->biosBackupPtr);␊ |
373 | ␉␉PRINT("[OK]\n");␊ |
374 | ␉}␊ |
375 | ␉␊ |
376 | ␉// free table backups if any␊ |
377 | ␉sModeTable * table = map->modeTables;␊ |
378 | ␉while (table != NULL)␊ |
379 | ␉{␉␉␊ |
380 | ␉␉if (table->backup != NULL)␊ |
381 | ␉␉{␊ |
382 | ␉␉␉PRINT("Table #%d : Freeing backup\t", table->id);␊ |
383 | ␉␉␉FREE(table->backup);␊ |
384 | ␉␉␉PRINT("[OK]\n");␊ |
385 | ␉␉}␊ |
386 | ␉␉␊ |
387 | ␉␉if (table != NULL)␊ |
388 | ␉␉{ ␊ |
389 | ␉␉␉PRINT("Table #%d : Freeing\t\t", table->id);␊ |
390 | ␉␉␉FREE(table);␊ |
391 | ␉␉␉PRINT("[OK]\n");␊ |
392 | ␉␉}␊ |
393 | ␉␉␊ |
394 | ␉␉if (table->next == NULL)␊ |
395 | ␉␉␉break;␊ |
396 | ␉␉␊ |
397 | ␉␉table = table->next;␊ |
398 | ␉}␊ |
399 | ␉␊ |
400 | ␉PRINT("Freeing map\t\t\t");␊ |
401 | ␉FREE(map);␊ |
402 | ␉PRINT("[OK]\n");␊ |
403 | }␊ |
404 | ␊ |
405 | void unlockVbios(vBiosMap * map)␊ |
406 | {␊ |
407 | ␊ |
408 | ␉map->unlocked = TRUE;␊ |
409 | ␉ ␊ |
410 | ␉switch (map->chipset)␊ |
411 | ␉{␊ |
412 | ␉␉case CT_UNKWN:␊ |
413 | ␉␉␉break;␊ |
414 | ␉␉case CT_830:␊ |
415 | ␉␉case CT_855GM:␊ |
416 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
417 | ␉␉␉map->b1 = inb(0xcfe);␊ |
418 | ␉␉␉␉␊ |
419 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
420 | ␉␉␉outb(0xcfe, 0x33);␊ |
421 | ␉␉␉break;␊ |
422 | ␉␉case CT_845G:␊ |
423 | ␉␉case CT_865G:␊ |
424 | ␉␉case CT_915G:␊ |
425 | ␉␉case CT_915GM:␊ |
426 | ␉␉case CT_945G:␊ |
427 | ␉␉case CT_945GM:␊ |
428 | ␉␉case CT_945GME:␊ |
429 | ␉␉case CT_946GZ:␊ |
430 | ␉␉case CT_955X:␊ |
431 | ␉␉case CT_G965:␊ |
432 | ␉␉case CT_Q965:␊ |
433 | ␉␉case CT_965GM:␊ |
434 | ␉␉case CT_975X:␊ |
435 | ␉␉case CT_P35:␊ |
436 | ␉␉case CT_X48:␊ |
437 | ␉␉case CT_B43:␊ |
438 | ␉␉case CT_Q45:␊ |
439 | ␉␉case CT_P45:␊ |
440 | ␉␉case CT_GM45:␊ |
441 | ␉␉case CT_G41:␊ |
442 | ␉␉case CT_G31:␊ |
443 | ␉␉case CT_G45:␊ |
444 | ␉␉case CT_500:␊ |
445 | ␊ |
446 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
447 | ␉␉␉map->b1 = inb(0xcfd);␊ |
448 | ␉␉␉map->b2 = inb(0xcfe);␊ |
449 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
450 | ␉␉␉outb(0xcfd, 0x33);␊ |
451 | ␉␉␉outb(0xcfe, 0x33);␊ |
452 | ␉␉break;␊ |
453 | ␉}␊ |
454 | ␉␊ |
455 | ␉#if DEBUG␊ |
456 | ␉{␊ |
457 | ␉␉uint32_t t = inl(0xcfc);␊ |
458 | ␉␉PRINT("unlock PAM: (0x%08x)\n", t);␊ |
459 | ␉}␊ |
460 | #endif␊ |
461 | }␊ |
462 | ␊ |
463 | void relockVbios(vBiosMap * map)␊ |
464 | {␊ |
465 | ␊ |
466 | ␉map->unlocked = FALSE;␊ |
467 | ␉␊ |
468 | ␉switch (map->chipset)␊ |
469 | ␉{␊ |
470 | ␉␉case CT_UNKWN:␊ |
471 | ␉␉␉break;␊ |
472 | ␉␉case CT_830:␊ |
473 | ␉␉case CT_855GM:␊ |
474 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
475 | ␉␉␉outb(0xcfe, map->b1);␊ |
476 | ␉␉␉break;␊ |
477 | ␉␉case CT_845G:␊ |
478 | ␉␉case CT_865G:␊ |
479 | ␉␉case CT_915G:␊ |
480 | ␉␉case CT_915GM:␊ |
481 | ␉␉case CT_945G:␊ |
482 | ␉␉case CT_945GM:␊ |
483 | ␉␉case CT_945GME:␊ |
484 | ␉␉case CT_946GZ:␊ |
485 | ␉␉case CT_955X:␊ |
486 | ␉␉case CT_G965:␊ |
487 | ␉␉case CT_Q965:␊ |
488 | ␉␉case CT_965GM:␊ |
489 | ␉␉case CT_975X:␊ |
490 | ␉␉case CT_P35:␊ |
491 | ␉␉case CT_X48:␊ |
492 | ␉␉case CT_B43:␊ |
493 | ␉␉case CT_Q45:␊ |
494 | ␉␉case CT_P45:␊ |
495 | ␉␉case CT_GM45:␊ |
496 | ␉␉case CT_G41:␊ |
497 | ␉␉case CT_G31:␊ |
498 | ␉␉case CT_G45:␊ |
499 | ␉␉case CT_500:␊ |
500 | ␉␉␉␊ |
501 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
502 | ␉␉␉outb(0xcfd, map->b1);␊ |
503 | ␉␉␉outb(0xcfe, map->b2);␊ |
504 | ␉␉␉break;␊ |
505 | ␉}␊ |
506 | ␉␊ |
507 | ␉#if DEBUG␊ |
508 | ␉{␊ |
509 | uint32_t t = inl(0xcfc);␊ |
510 | ␉␉PRINT("relock PAM: (0x%08x)\n", t);␊ |
511 | ␉}␊ |
512 | ␉#endif␊ |
513 | }␊ |
514 | ␊ |
515 | /*␊ |
516 | * saveVbios - save the entire vBios in case the patch has to be removed␊ |
517 | */␊ |
518 | void saveVbios(vBiosMap * map)␊ |
519 | {␊ |
520 | ␉map->biosBackupPtr = malloc(VBIOS_SIZE);␊ |
521 | ␉bcopy((const uint8_t *)0xC0000, map->biosBackupPtr, VBIOS_SIZE);␊ |
522 | }␊ |
523 | ␊ |
524 | /*␊ |
525 | * restoreVbios - restore the vBios backup or table backups if any␊ |
526 | */␊ |
527 | void restoreVbios(vBiosMap * map)␊ |
528 | {␊ |
529 | ␉if ((map->bios == BT_ATI_1) || (map->bios == BT_ATI_2) || (map->bios == BT_NVDA))␊ |
530 | ␉{␊ |
531 | ␉␉restoreTables(map, map->modeTables);␊ |
532 | ␉}␊ |
533 | ␉else␊ |
534 | ␉{␊ |
535 | ␉␉unlockVbios(map);␊ |
536 | ␉␉bcopy(map->biosBackupPtr,(uint8_t *)0xC0000, VBIOS_SIZE);␊ |
537 | ␉␉relockVbios(map);␊ |
538 | ␉}␊ |
539 | }␊ |
540 | ␊ |
541 | /*␊ |
542 | * saveTables - save the tables in case the patch has to be removed␊ |
543 | */␊ |
544 | void saveTables(sModeTable * table)␊ |
545 | {␊ |
546 | ␉while (table != NULL)␊ |
547 | ␉{␊ |
548 | ␉␉table->backup = (uint8_t *)malloc(table->size);␊ |
549 | ␉␉bcopy((const uint8_t *)table->pointer, table->backup, table->size);␊ |
550 | ␉␉table = table->next;␊ |
551 | ␉}␊ |
552 | }␊ |
553 | ␊ |
554 | /*␊ |
555 | * restoreTables - restore tables backup ␊ |
556 | */␊ |
557 | void restoreTables(vBiosMap * map, sModeTable * table)␊ |
558 | {␊ |
559 | ␉unlockVbios(map);␊ |
560 | ␉while (table != NULL)␊ |
561 | ␉{␊ |
562 | ␉␉bcopy(table->backup, (uint8_t *)table->pointer, table->size);␊ |
563 | ␉␉table = table->next;␊ |
564 | ␉}␊ |
565 | ␉relockVbios(map);␊ |
566 | }␊ |
567 | ␊ |
568 | /*␊ |
569 | * patchVbios - call the vendor specific function to patch the VESA tables␊ |
570 | * x & y are horizontal and vertical dimensions respectively, in pixels␊ |
571 | * for GMA and ATI, only first mode in Table is patched␊ |
572 | *␊ |
573 | * each vendor specific function have the same form :␊ |
574 | * bool vendorSetMode_type(sModeTable * table, uint8_t index, uint32_t * x, uint32_t * y);␊ |
575 | * where 'table' is the VESA table to patch, 'index' is the index of the mode in table,␊ |
576 | * 'x' & 'y' are pointer to the target resolution and return the next resolution in table.␊ |
577 | */␊ |
578 | void patchVbios(vBiosMap * map, uint32_t x, uint32_t y, uint32_t bp, uint32_t hTotal, uint32_t vTotal)␊ |
579 | {␊ |
580 | ␉uint32_t i = 0;␊ |
581 | ␉␊ |
582 | ␉sModeTable * table = map->modeTables;␊ |
583 | ␉␊ |
584 | ␉// save the target resolution for future use␊ |
585 | ␉map->currentX = x;␊ |
586 | ␉map->currentY = y;␊ |
587 | ␉␊ |
588 | ␉unlockVbios(map);␊ |
589 | ␉␊ |
590 | ␉// Get the aspect ratio for the requested mode␊ |
591 | ␉getAspectRatio(&map->aspectRatio, x, y);␊ |
592 | ␉␊ |
593 | ␉i = 0;␊ |
594 | ␉␊ |
595 | ␉// Call the vendor specific function for each available VESA Table␊ |
596 | ␉table = map->modeTables;␊ |
597 | ␉while (table != NULL)␊ |
598 | ␉{␊ |
599 | ␉␉//reset resolution value before treating a new table␊ |
600 | ␉␉x = map->currentX;␊ |
601 | ␉␉y = map->currentY;␊ |
602 | ␉␉␊ |
603 | ␉␉PRINT("Patching Table #%d : \n", table->id);␊ |
604 | ␉␉␊ |
605 | ␉␉map->setMode(table, i, &x, &y);␊ |
606 | #ifdef AUTORES_DEBUG␊ |
607 | ␉␉getc();␊ |
608 | #endif␊ |
609 | ␊ |
610 | ␉␉table = table->next;␊ |
611 | ␉}␊ |
612 | ␉␊ |
613 | ␉relockVbios(map);␊ |
614 | ␉return;␊ |
615 | } |