1 | /* Copied from 915 resolution created by steve tomljenovic␊ |
2 | *␊ |
3 | * This code is based on the techniques used in :␊ |
4 | *␊ |
5 | * - 855patch. Many thanks to Christian Zietz (czietz gmx net)␊ |
6 | * for demonstrating how to shadow the VBIOS into system RAM␊ |
7 | * and then modify it.␊ |
8 | *␊ |
9 | * - 1280patch by Andrew Tipton (andrewtipton null li).␊ |
10 | *␊ |
11 | * - 855resolution by Alain Poirier␊ |
12 | *␊ |
13 | * This source code is into the public domain.␊ |
14 | */␊ |
15 | ␊ |
16 | //#include "libsaio.h"␊ |
17 | //#include "autoresolution.h" - included on *_resolution.h␊ |
18 | //#include "boot.h"␊ |
19 | //#include "gui.h"␊ |
20 | #include "nvidia_resolution.h"␊ |
21 | #include "ati_resolution.h"␊ |
22 | #include "gma_resolution.h"␊ |
23 | #include "../boot2/graphics.h" //Azi:reminder␊ |
24 | ␊ |
25 | char * chipsetTypeNames[] = {␊ |
26 | ␉"UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",␊ |
27 | ␉"946GZ", "955X", "G965", "Q965", "965GM", "975X",␊ |
28 | ␉"P35", "X48", "B43", "Q45", "P45", "GM45", "G41", "G31", "G45", "500"␊ |
29 | };␊ |
30 | ␊ |
31 | uint32_t getChipsetId(void)␊ |
32 | {␊ |
33 | ␉outl(0xcf8, 0x80000000);␊ |
34 | ␉return inl(0xcfc);␊ |
35 | }␊ |
36 | ␊ |
37 | chipsetType getChipset(uint32_t id)␊ |
38 | {␊ |
39 | ␉chipsetType type;␊ |
40 | ␉␊ |
41 | ␉switch (id)␊ |
42 | ␉{␊ |
43 | ␉␉case 0x35758086:␊ |
44 | ␉␉␉type = CT_830;␊ |
45 | ␉␉␉break;␊ |
46 | ␉␉␊ |
47 | ␉␉case 0x25608086:␊ |
48 | ␉␉␉type = CT_845G;␊ |
49 | ␉␉␉break;␊ |
50 | ␉␉␉␉␊ |
51 | ␉␉case 0x35808086:␊ |
52 | ␉␉␉type = CT_855GM;␊ |
53 | ␉␉␉break;␊ |
54 | ␉␉␉␉␊ |
55 | ␉␉case 0x25708086:␊ |
56 | ␉␉␉type = CT_865G;␊ |
57 | ␉␉␉break;␊ |
58 | ␉␉␊ |
59 | ␉␉case 0x25808086:␊ |
60 | ␉␉␉type = CT_915G;␊ |
61 | ␉␉␉break;␊ |
62 | ␉␉␉␊ |
63 | ␉␉case 0x25908086:␊ |
64 | ␉␉␉type = CT_915GM;␊ |
65 | ␉␉␉break;␊ |
66 | ␉␉␉␊ |
67 | ␉␉case 0x27708086:␊ |
68 | ␉␉␉type = CT_945G;␊ |
69 | ␉␉␉break;␊ |
70 | ␉␉␉␊ |
71 | ␉␉case 0x27748086:␊ |
72 | ␉␉␉type = CT_955X;␊ |
73 | ␉␉␉break;␊ |
74 | ␉␉␉␊ |
75 | ␉␉case 0x277c8086:␊ |
76 | ␉␉␉type = CT_975X;␊ |
77 | ␉␉␉break;␊ |
78 | ␉␉␊ |
79 | ␉␉case 0x27a08086:␊ |
80 | ␉␉␉type = CT_945GM;␊ |
81 | ␉␉␉break;␊ |
82 | ␉␉␉␊ |
83 | ␉␉case 0x27ac8086:␊ |
84 | ␉␉␉type = CT_945GME;␊ |
85 | ␉␉␉break;␊ |
86 | ␉␉␉␊ |
87 | ␉␉case 0x29708086:␊ |
88 | ␉␉␉type = CT_946GZ;␊ |
89 | ␉␉␉break;␊ |
90 | ␉␉␉␊ |
91 | ␉␉case 0x29a08086:␊ |
92 | ␉␉␉type = CT_G965;␊ |
93 | ␉␉␉break;␊ |
94 | ␉␉␉␊ |
95 | ␉␉case 0x29908086:␊ |
96 | ␉␉␉type = CT_Q965;␊ |
97 | ␉␉␉break;␊ |
98 | ␉␉␉␊ |
99 | ␉␉case 0x2a008086:␊ |
100 | ␉␉␉type = CT_965GM;␊ |
101 | ␉␉␉break;␊ |
102 | ␉␉␉␊ |
103 | ␉␉case 0x29e08086:␊ |
104 | ␉␉␉type = CT_X48;␊ |
105 | ␉␉␉break;␉␉␉␊ |
106 | ␉␉␉␊ |
107 | ␉␉case 0x2a408086:␊ |
108 | ␉␉␉type = CT_GM45;␊ |
109 | ␉␉␉break;␊ |
110 | ␉␉␉␊ |
111 | ␉␉case 0x2e108086:␊ |
112 | ␉␉case 0X2e908086:␊ |
113 | ␉␉␉type = CT_B43;␊ |
114 | ␉␉␉break;␊ |
115 | ␉␉␉␊ |
116 | ␉␉case 0x2e208086:␊ |
117 | ␉␉␉type = CT_P45;␊ |
118 | ␉␉␉break;␊ |
119 | ␉␉␉␊ |
120 | ␉␉case 0x2e308086:␊ |
121 | ␉␉␉type = CT_G41;␊ |
122 | ␉␉␉break;␊ |
123 | ␉␉␉␊ |
124 | ␉␉case 0x29c08086:␊ |
125 | ␉␉␉type = CT_G31;␊ |
126 | ␉␉␉break;␊ |
127 | ␉␉␉␊ |
128 | ␉␉case 0x29208086:␊ |
129 | ␉␉␉type = CT_G45;␊ |
130 | ␉␉␉break;␊ |
131 | ␉␉␉␊ |
132 | ␉␉case 0x81008086:␊ |
133 | ␉␉␉type = CT_500;␊ |
134 | ␉␉␉break;␊ |
135 | ␉␉␉␊ |
136 | ␉␉default:␊ |
137 | ␉␉␉type = CT_UNKWN;␊ |
138 | ␉␉␉break;␊ |
139 | ␉}␊ |
140 | ␉return type;␊ |
141 | }␊ |
142 | ␊ |
143 | ␊ |
144 | void gtfTimings(uint32_t x, uint32_t y, uint32_t freq,␊ |
145 | ␉␉␉␉ uint32_t *clock,␊ |
146 | ␉␉␉␉ uint16_t *hSyncStart, uint16_t *hSyncEnd, uint16_t *hBlank,␊ |
147 | ␉␉␉␉ uint16_t *vSyncStart, uint16_t *vSyncEnd, uint16_t *vBlank)␊ |
148 | {␊ |
149 | ␉uint32_t hbl, vbl, vfreq;␊ |
150 | ␉␊ |
151 | ␉vbl = y + (y+1)/(20000/(11*freq) - 1) + 1;␊ |
152 | ␉␊ |
153 | ␉vfreq = vbl * freq;␊ |
154 | ␉hbl = 16 * (int)(x * (30 - 300000 / vfreq) /␊ |
155 | ␉␉␉␉␉ + (70 + 300000 / vfreq) / 16 + 0);␊ |
156 | ␉␊ |
157 | ␉*vSyncStart = y;␊ |
158 | ␉*vSyncEnd = y + 3;␊ |
159 | ␉*vBlank = vbl;␉␊ |
160 | ␉*hSyncStart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 ;␉␊ |
161 | ␉*hSyncEnd = x + hbl / 2;␉␊ |
162 | ␉*hBlank = x + hbl;␉␊ |
163 | ␉*clock = (x + hbl) * vfreq / 1000;␊ |
164 | }␊ |
165 | ␊ |
166 | ␊ |
167 | void getAspectRatio(sAspect* aspect, uint32_t x, uint32_t y)␊ |
168 | {␊ |
169 | ␉if ((y * 16 / 9) == x)␊ |
170 | ␉{␊ |
171 | ␉␉aspect->width = 16;␊ |
172 | ␉␉aspect->height = 9;␊ |
173 | ␉}␊ |
174 | ␉else if ((y * 16 / 10) == x)␊ |
175 | ␉{␊ |
176 | ␉␉aspect->width = 16;␊ |
177 | ␉␉aspect->height = 10;␊ |
178 | ␉}␊ |
179 | ␉else if ((y * 5 / 4) == x)␊ |
180 | ␉{␊ |
181 | ␉␉aspect->width = 5;␊ |
182 | ␉␉aspect->height = 4;␊ |
183 | ␉}␊ |
184 | ␉else if ((y * 15 / 9) == x)␊ |
185 | ␉{␊ |
186 | ␉␉aspect->width = 15;␊ |
187 | ␉␉aspect->height = 9;␊ |
188 | ␉}␊ |
189 | ␉else␊ |
190 | ␉{␊ |
191 | ␉␉aspect->width = 4;␊ |
192 | ␉␉aspect->height = 3;␊ |
193 | ␉}␊ |
194 | ␉PRINT("Aspect Ratio is %d/%d\n", aspect->width, aspect->height);␊ |
195 | }␊ |
196 | ␊ |
197 | ␊ |
198 | /*␊ |
199 | * initialize the mode tables chain␊ |
200 | * tablesCount represents the number of VESA tables in the vBios␊ |
201 | * return value is a pointer to the first table␊ |
202 | */␊ |
203 | sModeTable * intializeTables(vBiosMap * map, int tablesCount) {␊ |
204 | ␉map->modeTables = (sModeTable *)malloc(sizeof(sModeTable));␊ |
205 | ␉sModeTable * table = map->modeTables;␊ |
206 | ␉␊ |
207 | ␉PRINT("Creating %d Mode Tables\n", tablesCount);␊ |
208 | ␉␊ |
209 | ␉int i = tablesCount;␊ |
210 | ␉while ( i != 0 )␊ |
211 | ␉{␉␉␊ |
212 | ␉␉table->id = tablesCount - i;␊ |
213 | ␉␉PRINT("New table with id: %d\n", table->id);␊ |
214 | ␉␉␊ |
215 | ␉␉// opening the chain if it's the first table␊ |
216 | ␉␉if (i == tablesCount)␊ |
217 | ␉␉␉table->prev = NULL;␊ |
218 | ␉␉else // attache the table to the chain␊ |
219 | ␉␉␉table->prev = table; ␊ |
220 | ␉␉␊ |
221 | ␉␉//if there is more than one table, alloc the next one␊ |
222 | ␉␉if (i > 1)␊ |
223 | ␉␉{␊ |
224 | ␉␉␉table->next = (sModeTable *)malloc(sizeof(sModeTable));␊ |
225 | ␉␉␉table = table->next;␊ |
226 | ␉␉}␊ |
227 | ␉␉else // no more table, close the chain␊ |
228 | ␉␉␉table->next = NULL;␊ |
229 | ␉␉␊ |
230 | ␉␉i--;␊ |
231 | ␉}␊ |
232 | ␉␊ |
233 | ␉return map->modeTables;␊ |
234 | }␊ |
235 | ␊ |
236 | ␊ |
237 | //void closeVbios(vBiosMap * map); azi: dup - declared on header␊ |
238 | ␊ |
239 | vBiosMap * openVbios(chipsetType forcedChipset)␊ |
240 | {␊ |
241 | ␉uint32_t z;␊ |
242 | ␉vBiosMap * map = NEW(vBiosMap);␊ |
243 | ␉␊ |
244 | ␉for(z = 0; z < sizeof(vBiosMap); z++)␊ |
245 | ␉␉((char*)map)[z] = 0;␊ |
246 | ␉␊ |
247 | ␉/*␊ |
248 | ␉ * Determine chipset␊ |
249 | ␉ */␊ |
250 | ␉␊ |
251 | ␉if (forcedChipset == CT_UNKWN)␊ |
252 | ␉{␊ |
253 | ␉␉map->chipsetId = getChipsetId();␊ |
254 | ␉␉map->chipset = getChipset(map->chipsetId);␊ |
255 | ␉␉PRINT("Chipset is %s (pci id 0x%x)\n",chipsetTypeNames[map->chipset], map->chipsetId);␊ |
256 | ␉}␊ |
257 | ␉else if (forcedChipset != CT_UNKWN)␊ |
258 | ␉{␊ |
259 | ␉␉map->chipset = forcedChipset;␊ |
260 | ␉}␊ |
261 | ␉else␊ |
262 | ␉{␊ |
263 | ␉␉map->chipset = CT_915GM;␊ |
264 | ␉}␊ |
265 | ␉ ␊ |
266 | ␉/*␊ |
267 | ␉ * Map the video bios to memory␊ |
268 | ␉ */␊ |
269 | ␉␊ |
270 | ␉map->biosPtr=(uint8_t*)VBIOS_START;␊ |
271 | ␉␊ |
272 | ␉/*␊ |
273 | ␉ * Common initialisation␊ |
274 | ␉ */␊ |
275 | ␉␊ |
276 | //␉map->hasSwitched = false;␊ |
277 | ␉␊ |
278 | ␉/*␊ |
279 | ␉ * check if we have ATI Radeon and open atombios␊ |
280 | ␉ */␊ |
281 | ␉atiBiosTables atiTables;␊ |
282 | ␉␊ |
283 | ␉atiTables.base = map->biosPtr;␊ |
284 | ␉atiTables.atomRomHeader = (atomRomHeader *) (map->biosPtr + *(uint16_t *) (map->biosPtr + OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER)); ␊ |
285 | ␉␊ |
286 | ␉if (strcmp ((char *) atiTables.atomRomHeader->firmWareSignature, "ATOM") == 0)␊ |
287 | ␉{␊ |
288 | ␉␉map->bios = BT_ATI_1;␊ |
289 | ␉␉PRINT("We have an AtomBios Card\n");␊ |
290 | ␉␉return openAtiVbios(map, atiTables);␊ |
291 | ␉}␊ |
292 | ␊ |
293 | ␊ |
294 | ␉/*␊ |
295 | ␉ * check if we have NVidia␊ |
296 | ␉ */␊ |
297 | ␉if (map->bios != BT_ATI_1)␊ |
298 | ␉{␊ |
299 | ␉␉int i = 0;␊ |
300 | ␉␉while (i < 512) // we don't need to look through the whole bios, just the first 512 bytes␊ |
301 | ␉␉{␊ |
302 | ␉␉␉if ((map->biosPtr[i] == 'N') ␊ |
303 | ␉␉␉␉&& (map->biosPtr[i+1] == 'V') ␊ |
304 | ␉␉␉␉&& (map->biosPtr[i+2] == 'I') ␊ |
305 | ␉␉␉␉&& (map->biosPtr[i+3] == 'D')) ␊ |
306 | ␉␉␉{␊ |
307 | ␉␉␉␉map->bios = BT_NVDA;␊ |
308 | ␉␉␉␉PRINT("We have an NVIDIA Card\n");␊ |
309 | ␉␉␉␉return openNvidiaVbios(map);␊ |
310 | ␉␉␉␉break;␊ |
311 | ␉␉␉}␊ |
312 | ␉␉␉i++;␊ |
313 | ␉␉}␊ |
314 | ␉}␊ |
315 | ␉␊ |
316 | ␉/*␊ |
317 | ␉ * check if we have Intel␊ |
318 | ␉ */␊ |
319 | ␉ ␊ |
320 | ␉if ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA))␊ |
321 | ␉{␊ |
322 | ␉␉int i = 0;␊ |
323 | ␉␉while (i < VBIOS_SIZE)␊ |
324 | ␉␉{␊ |
325 | ␉␉␉if ((map->biosPtr[i] == 'I') ␊ |
326 | ␉␉␉␉&& (map->biosPtr[i+1] == 'n') ␊ |
327 | ␉␉␉␉&& (map->biosPtr[i+2] == 't') ␊ |
328 | ␉␉␉␉&& (map->biosPtr[i+3] == 'e') ␊ |
329 | ␉␉␉␉&& (map->biosPtr[i+4] == 'l')) ␊ |
330 | ␉␉␉{␊ |
331 | ␉␉␉␉map->bios = BT_1;␊ |
332 | ␉␉␉␉PRINT("We have an Intel Card\n");␊ |
333 | ␉␉␉␉saveVbios(map);␊ |
334 | ␉␉␉␉return openIntelVbios(map);␊ |
335 | ␉␉␉␉break;␊ |
336 | ␉␉␉}␊ |
337 | ␉␉␉i++;␊ |
338 | ␉␉}␊ |
339 | ␉}␊ |
340 | ␉␊ |
341 | ␉/*␊ |
342 | ␉ * Unidentified Chipset␊ |
343 | ␉ */␊ |
344 | ␉␊ |
345 | ␉if ( (map->chipset == CT_UNKWN) || ((map->bios != BT_ATI_1) && (map->bios != BT_NVDA) && (map->bios != BT_1)) )␊ |
346 | ␉{␊ |
347 | ␉␉PRINT("Unknown chipset type and unrecognized bios.\n");␊ |
348 | ␉␉␊ |
349 | ␉␉PRINT("autoresolution only works with Intel 800/900 series graphic chipsets.\n"); //Azi:reminder␊ |
350 | ␉␉␊ |
351 | ␉␉PRINT("Chipset Id: %x\n", map->chipsetId);␊ |
352 | ␉␉closeVbios(map);␊ |
353 | ␉␉return 0;␊ |
354 | ␉}␊ |
355 | ␊ |
356 | ␉/*␊ |
357 | ␉ * Should never get there ␊ |
358 | ␉ */␊ |
359 | ␉return 0;␊ |
360 | }␊ |
361 | ␊ |
362 | void closeVbios(vBiosMap * map)␊ |
363 | {␊ |
364 | ␉PRINT("Closing VBios\n");␊ |
365 | ␉//make sure to turn autoResolution off␊ |
366 | ␉if (gAutoResolution == true)␊ |
367 | ␉␉gAutoResolution = false;␊ |
368 | ␉␊ |
369 | ␉// if we saved the vBios, free the copy␊ |
370 | ␉if (map->biosBackupPtr != NULL)␊ |
371 | ␉{␊ |
372 | ␉␉PRINT("Freeing biosBackupPtr\t");␊ |
373 | ␉␉FREE(map->biosBackupPtr);␊ |
374 | ␉␉PRINT("[OK]\n");␊ |
375 | ␉}␊ |
376 | ␉␊ |
377 | ␉// free table backups if any␊ |
378 | ␉sModeTable * table = map->modeTables;␊ |
379 | ␉while (table != NULL)␊ |
380 | ␉{␉␉␊ |
381 | ␉␉if (table->backup != NULL)␊ |
382 | ␉␉{␊ |
383 | ␉␉␉PRINT("Table #%d: Freeing backup\t", table->id);␊ |
384 | ␉␉␉FREE(table->backup);␊ |
385 | ␉␉␉PRINT("[OK]\n");␊ |
386 | ␉␉}␊ |
387 | ␉␉␊ |
388 | ␉␉if (table != NULL)␊ |
389 | ␉␉{ ␊ |
390 | ␉␉␉PRINT("Table #%d: Freeing\t\t", table->id);␊ |
391 | ␉␉␉FREE(table);␊ |
392 | ␉␉␉PRINT("[OK]\n");␊ |
393 | ␉␉}␊ |
394 | ␉␉␊ |
395 | ␉␉if (table->next == NULL)␊ |
396 | ␉␉␉break;␊ |
397 | ␉␉␊ |
398 | ␉␉table = table->next;␊ |
399 | ␉}␊ |
400 | ␉␊ |
401 | ␉PRINT("Freeing map\t\t\t");␊ |
402 | ␉FREE(map);␊ |
403 | ␉PRINT("[OK]\n");␊ |
404 | }␊ |
405 | ␊ |
406 | void unlockVbios(vBiosMap * map)␊ |
407 | {␊ |
408 | ␊ |
409 | ␉map->unlocked = true;␊ |
410 | ␉ ␊ |
411 | ␉switch (map->chipset)␊ |
412 | ␉{␊ |
413 | ␉␉case CT_UNKWN:␊ |
414 | ␉␉␉break;␊ |
415 | ␉␉case CT_830:␊ |
416 | ␉␉case CT_855GM:␊ |
417 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
418 | ␉␉␉map->b1 = inb(0xcfe);␊ |
419 | ␉␉␉␉␊ |
420 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
421 | ␉␉␉outb(0xcfe, 0x33);␊ |
422 | ␉␉␉break;␊ |
423 | ␉␉case CT_845G:␊ |
424 | ␉␉case CT_865G:␊ |
425 | ␉␉case CT_915G:␊ |
426 | ␉␉case CT_915GM:␊ |
427 | ␉␉case CT_945G:␊ |
428 | ␉␉case CT_945GM:␊ |
429 | ␉␉case CT_945GME:␊ |
430 | ␉␉case CT_946GZ:␊ |
431 | ␉␉case CT_955X:␊ |
432 | ␉␉case CT_G965:␊ |
433 | ␉␉case CT_Q965:␊ |
434 | ␉␉case CT_965GM:␊ |
435 | ␉␉case CT_975X:␊ |
436 | ␉␉case CT_P35:␊ |
437 | ␉␉case CT_X48:␊ |
438 | ␉␉case CT_B43:␊ |
439 | ␉␉case CT_Q45:␊ |
440 | ␉␉case CT_P45:␊ |
441 | ␉␉case CT_GM45:␊ |
442 | ␉␉case CT_G41:␊ |
443 | ␉␉case CT_G31:␊ |
444 | ␉␉case CT_G45:␊ |
445 | ␉␉case CT_500:␊ |
446 | ␊ |
447 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
448 | ␉␉␉map->b1 = inb(0xcfd);␊ |
449 | ␉␉␉map->b2 = inb(0xcfe);␊ |
450 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
451 | ␉␉␉outb(0xcfd, 0x33);␊ |
452 | ␉␉␉outb(0xcfe, 0x33);␊ |
453 | ␉␉break;␊ |
454 | ␉}␊ |
455 | ␉␊ |
456 | ␉#if DEBUG␊ |
457 | ␉{␊ |
458 | ␉␉uint32_t t = inl(0xcfc);␊ |
459 | ␉␉PRINT("unlock PAM: (0x%08x)\n", t);␊ |
460 | ␉}␊ |
461 | #endif␊ |
462 | }␊ |
463 | ␊ |
464 | void relockVbios(vBiosMap * map)␊ |
465 | {␊ |
466 | ␊ |
467 | ␉map->unlocked = false;␊ |
468 | ␉␊ |
469 | ␉switch (map->chipset)␊ |
470 | ␉{␊ |
471 | ␉␉case CT_UNKWN:␊ |
472 | ␉␉␉break;␊ |
473 | ␉␉case CT_830:␊ |
474 | ␉␉case CT_855GM:␊ |
475 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
476 | ␉␉␉outb(0xcfe, map->b1);␊ |
477 | ␉␉␉break;␊ |
478 | ␉␉case CT_845G:␊ |
479 | ␉␉case CT_865G:␊ |
480 | ␉␉case CT_915G:␊ |
481 | ␉␉case CT_915GM:␊ |
482 | ␉␉case CT_945G:␊ |
483 | ␉␉case CT_945GM:␊ |
484 | ␉␉case CT_945GME:␊ |
485 | ␉␉case CT_946GZ:␊ |
486 | ␉␉case CT_955X:␊ |
487 | ␉␉case CT_G965:␊ |
488 | ␉␉case CT_Q965:␊ |
489 | ␉␉case CT_965GM:␊ |
490 | ␉␉case CT_975X:␊ |
491 | ␉␉case CT_P35:␊ |
492 | ␉␉case CT_X48:␊ |
493 | ␉␉case CT_B43:␊ |
494 | ␉␉case CT_Q45:␊ |
495 | ␉␉case CT_P45:␊ |
496 | ␉␉case CT_GM45:␊ |
497 | ␉␉case CT_G41:␊ |
498 | ␉␉case CT_G31:␊ |
499 | ␉␉case CT_G45:␊ |
500 | ␉␉case CT_500:␊ |
501 | ␉␉␉␊ |
502 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
503 | ␉␉␉outb(0xcfd, map->b1);␊ |
504 | ␉␉␉outb(0xcfe, map->b2);␊ |
505 | ␉␉␉break;␊ |
506 | ␉}␊ |
507 | ␉␊ |
508 | ␉#if DEBUG␊ |
509 | ␉{␊ |
510 | uint32_t t = inl(0xcfc);␊ |
511 | ␉␉PRINT("relock PAM: (0x%08x)\n", t);␊ |
512 | ␉}␊ |
513 | ␉#endif␊ |
514 | }␊ |
515 | ␊ |
516 | /*␊ |
517 | * saveVbios - save the entire vBios in case the patch has to be removed␊ |
518 | * Azi: only on Intel??␊ |
519 | */␊ |
520 | void saveVbios(vBiosMap * map)␊ |
521 | {␊ |
522 | ␉map->biosBackupPtr = malloc(VBIOS_SIZE);␊ |
523 | ␉bcopy((const uint8_t *)0xC0000, map->biosBackupPtr, VBIOS_SIZE);␊ |
524 | }␊ |
525 | ␊ |
526 | /*␊ |
527 | * restoreVbios - restore the vBios backup or table backups if any␊ |
528 | */␊ |
529 | void restoreVbios(vBiosMap * map)␊ |
530 | {␊ |
531 | ␉if ((map->bios == BT_ATI_1) || (map->bios == BT_ATI_2) || (map->bios == BT_NVDA))␊ |
532 | ␉{␊ |
533 | ␉␉restoreTables(map, map->modeTables);␊ |
534 | ␉}␊ |
535 | ␉else␊ |
536 | ␉{␊ |
537 | ␉␉unlockVbios(map);␊ |
538 | ␉␉bcopy(map->biosBackupPtr,(uint8_t *)0xC0000, VBIOS_SIZE);␊ |
539 | ␉␉relockVbios(map);␊ |
540 | ␉}␊ |
541 | }␊ |
542 | ␊ |
543 | /*␊ |
544 | * saveTables - save the tables in case the patch has to be removed␊ |
545 | */␊ |
546 | void saveTables(sModeTable * table)␊ |
547 | {␊ |
548 | ␉while (table != NULL)␊ |
549 | ␉{␊ |
550 | ␉␉table->backup = (uint8_t *)malloc(table->size);␊ |
551 | ␉␉bcopy((const uint8_t *)table->pointer, table->backup, table->size);␊ |
552 | ␉␉table = table->next;␊ |
553 | ␉}␊ |
554 | }␊ |
555 | ␊ |
556 | /*␊ |
557 | * restoreTables - restore tables backup ␊ |
558 | */␊ |
559 | void restoreTables(vBiosMap * map, sModeTable * table)␊ |
560 | {␊ |
561 | ␉unlockVbios(map);␊ |
562 | ␉while (table != NULL)␊ |
563 | ␉{␊ |
564 | ␉␉bcopy(table->backup, (uint8_t *)table->pointer, table->size);␊ |
565 | ␉␉table = table->next;␊ |
566 | //␉␉verbose("Table/s restored...\n");␊ |
567 | ␉}␊ |
568 | ␉relockVbios(map);␊ |
569 | }␊ |
570 | ␊ |
571 | /*␊ |
572 | * patchVbios - call the vendor specific function to patch the VESA tables␊ |
573 | * x & y are horizontal and vertical dimensions respectively, in pixels␊ |
574 | * for GMA and ATI, only first mode in Table is patched␊ |
575 | *␊ |
576 | * each vendor specific function have the same form :␊ |
577 | * bool vendorSetMode_type(sModeTable * table, uint8_t index, uint32_t * x, uint32_t * y);␊ |
578 | * where 'table' is the VESA table to patch, 'index' is the index of the mode in table,␊ |
579 | * 'x' & 'y' are pointer to the target resolution and return the next resolution in table.␊ |
580 | */␊ |
581 | void patchVbios(vBiosMap * map, uint32_t x, uint32_t y, uint32_t bp, uint32_t hTotal, uint32_t vTotal)␊ |
582 | {␊ |
583 | ␉uint32_t i = 0;␊ |
584 | ␉␊ |
585 | ␉sModeTable * table = map->modeTables;␊ |
586 | ␉␊ |
587 | ␉// save the target resolution for future use␊ |
588 | ␉map->currentX = x;␊ |
589 | ␉map->currentY = y;␊ |
590 | ␉␊ |
591 | ␉unlockVbios(map);␊ |
592 | ␉␊ |
593 | ␉// Get the aspect ratio for the requested mode␊ |
594 | ␉getAspectRatio(&map->aspectRatio, x, y);␊ |
595 | ␉␊ |
596 | ␉i = 0;␊ |
597 | ␉␊ |
598 | ␉// Call the vendor specific function for each available VESA Table␊ |
599 | ␉table = map->modeTables;␊ |
600 | ␉while (table != NULL)␊ |
601 | ␉{␊ |
602 | ␉␉//reset resolution value before treating a new table␊ |
603 | ␉␉x = map->currentX;␊ |
604 | ␉␉y = map->currentY;␊ |
605 | ␉␉␊ |
606 | ␉␉PRINT("Patching Table #%d: \n", table->id);␊ |
607 | ␉␉␊ |
608 | ␉␉map->setMode(table, i, &x, &y);␊ |
609 | #ifdef AUTORES_DEBUG␊ |
610 | ␉␉pause();␊ |
611 | #endif␊ |
612 | ␊ |
613 | ␉␉table = table->next;␊ |
614 | ␉}␊ |
615 | ␉␊ |
616 | ␉relockVbios(map);␊ |
617 | ␉return;␊ |
618 | }␊ |
619 | /*␊ |
620 | void patchRes()␊ |
621 | {␊ |
622 | //␉UInt32 paramsAR[4];␊ |
623 | ␉paramsAR[3] = 0;␊ |
624 | ␊ |
625 | ␉// Open the VBios and store VBios or Tables␊ |
626 | ␉map = openVbios(CT_UNKWN);␊ |
627 | ␊ |
628 | ␉//Get Resolution from Graphics Mode key...␊ |
629 | ␉int count = getNumberArrayFromProperty(kGraphicsModeKey, paramsAR, 4);␊ |
630 | ␊ |
631 | ␉// ... or EDID.␊ |
632 | ␉if (count < 3)␊ |
633 | ␉{␊ |
634 | ␉␉getResolution(paramsAR);␊ |
635 | ␉␉// check the DEBUG stuff... also on TEXT MODE (this is not printing).␊ |
636 | ␉␉PRINT("Resolution: %dx%d (EDID)\n",paramsAR[0], paramsAR[1]);␊ |
637 | ␉}␊ |
638 | ␉else␊ |
639 | ␉{␊ |
640 | ␉␉PRINT("Resolution: %dx%d (Graphics Mode key)\n",paramsAR[0], paramsAR[1]);␊ |
641 | ␊ |
642 | ␉␉if ( paramsAR[2] == 256 ) paramsAR[2] = 8;␊ |
643 | ␉␉if ( paramsAR[2] == 555 ) paramsAR[2] = 16;␊ |
644 | ␉␉if ( paramsAR[2] == 888 ) paramsAR[2] = 32;␊ |
645 | ␉}␊ |
646 | ␊ |
647 | ␉// If using GUI, patch the video bios with the extracted resolution,␊ |
648 | ␉// before initGui.␊ |
649 | ␊ |
650 | ␉// perfom the actual VBIOS patching␊ |
651 | ␉if (paramsAR[0] != 0 && paramsAR[1] != 0)␊ |
652 | ␉{␊ |
653 | ␉␉patchVbios(map, paramsAR[0], paramsAR[1], paramsAR[2], 0, 0);␊ |
654 | ␉}␊ |
655 | ␊ |
656 | ␉closeVbios(map);␊ |
657 | ␉//Azi: gAutoResolution was just set to false on closeVbios().␊ |
658 | ␉gAutoResolution = true;␊ |
659 | ␊ |
660 | ␉if (bootArgs->Video.v_display == VGA_TEXT_MODE)␊ |
661 | ␉{␊ |
662 | ␉␉gui.screen.width = paramsAR[0];␊ |
663 | ␉␉gui.screen.height = paramsAR[1];␊ |
664 | ␉}␊ |
665 | ␊ |
666 | ␉// If the patch is working properly, we're done. If not and it's just a matter␊ |
667 | ␉// of wrong resolution, we can try reapply the patch; see "case kF2Key:", options.c.␊ |
668 | ␊ |
669 | ␉// The patch works properly but we're not using GUI; keep Vbios open and patch/close␊ |
670 | ␉// on drawBootGraphics().␊ |
671 | ␉// ??????Don't forget we´re maybe using this to get correct resolution after login,␊ |
672 | ␉// despite having qe/ci or not...!!!!␊ |
673 | }␊ |
674 | ␊ |
675 | void reloadRes()␊ |
676 | {␊ |
677 | //␉UInt32 paramsAR[4];␊ |
678 | ␉paramsAR[3] = 0;␊ |
679 | ␉␊ |
680 | ␉map = openVbios(CT_UNKWN);␊ |
681 | ␉// Has the target Resolution Changed ?␊ |
682 | ␉int count = getNumberArrayFromProperty(kGraphicsModeKey, paramsAR, 4);␊ |
683 | ␉␊ |
684 | ␉if ( count < 3 ) // why this? we are implicitly trying to change the resolution␊ |
685 | ␉// at boot prompt, using Graphics Mode flag...␊ |
686 | ␉{␊ |
687 | ␉␉getResolution(paramsAR);␊ |
688 | ␉}␊ |
689 | ␉else␊ |
690 | ␉{␊ |
691 | ␉␉if ( paramsAR[2] == 256 ) paramsAR[2] = 8;␊ |
692 | ␉␉if ( paramsAR[2] == 555 ) paramsAR[2] = 16;␊ |
693 | ␉␉if ( paramsAR[2] == 888 ) paramsAR[2] = 32;␊ |
694 | ␉}␊ |
695 | ␊ |
696 | ␉// user changed resolution...␊ |
697 | ␉if ((paramsAR[0] != 0) && (paramsAR[1] != 0) &&␊ |
698 | ␉␉(paramsAR[0] != map->currentX) && (paramsAR[1] != map->currentY))␊ |
699 | ␉{␊ |
700 | ␉␉//Azi: same shit as "case kTabKey:" - check␊ |
701 | ␉␉// Go back to TEXT mode while we change the mode␊ |
702 | ␉␉if (bootArgs->Video.v_display == GRAPHICS_MODE)␊ |
703 | ␉␉{␊ |
704 | ␉␉␉CursorState cursorState;␊ |
705 | ␊ |
706 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␊ |
707 | ␊ |
708 | ␉␉␉setCursorPosition(0, 0, 0);␊ |
709 | ␉␉␉clearScreenRows(0, kScreenLastRow);␊ |
710 | ␉␉␉changeCursor( 0, 0, kCursorTypeHidden, &cursorState );␊ |
711 | ␊ |
712 | ␉␉␉// Reapply patch␊ |
713 | ␉␉␉patchVbios(map, paramsAR[0], paramsAR[1], paramsAR[2], 0, 0);␊ |
714 | ␊ |
715 | ␉␉␉if (useGUI && (gui.initialised == true))␊ |
716 | ␉␉␉␉initGUI();␊ |
717 | ␉␉␉// Make sure all values are set␊ |
718 | ␉␉␉if (bootArgs->Video.v_display != GRAPHICS_MODE)␊ |
719 | ␉␉␉␉bootArgs->Video.v_display = GRAPHICS_MODE;␊ |
720 | ␊ |
721 | ␉␉␉if (!useGUI)␊ |
722 | ␉␉␉␉useGUI = true;␊ |
723 | ␊ |
724 | ␉␉␉// redraw the background buffer␊ |
725 | ␉␉␉drawBackground();␊ |
726 | ␉␉␉gui.devicelist.draw = true;␊ |
727 | ␉␉␉gui.redraw = true;␊ |
728 | ␉␉␉␊ |
729 | ␉␉␉if (showBootBanner)␊ |
730 | ␉␉␉{␊ |
731 | ␉␉␉␉// Display banner and show hardware info.␊ |
732 | ␉␉␉␉gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024);␊ |
733 | ␉␉␉}␊ |
734 | ␊ |
735 | ␉␉␉// redraw background␊ |
736 | ␉␉␉memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels,␊ |
737 | ␉␉␉␉ gui.backbuffer->width * gui.backbuffer->height * 4);␊ |
738 | ␊ |
739 | ␉␉␉nextRow = kMenuTopRow;␊ |
740 | ␉␉␉showPrompt = true;␊ |
741 | ␊ |
742 | ␉␉␉if (gDeviceCount)␊ |
743 | ␉␉␉{␊ |
744 | ␉␉␉␉showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems );␊ |
745 | ␉␉␉␉nextRow += min( gDeviceCount, kMenuMaxItems ) + 3;␊ |
746 | ␉␉␉}␊ |
747 | ␊ |
748 | ␉␉␉// Show the boot prompt.␊ |
749 | ␉␉␉showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot);␊ |
750 | ␉␉␉showBootPrompt( nextRow, showPrompt );␊ |
751 | ␊ |
752 | ␉␉␉// this is used to avoid resetting the incorrect mode while quiting the boot menu␊ |
753 | //␉␉␉␉␉␉map->hasSwitched = true;␊ |
754 | ␉␉}␊ |
755 | ␉}␊ |
756 | ␉␉␊ |
757 | ␉closeVbios(map);␊ |
758 | ␉//Azi: gAutoResolution was just set to false on closeVbios.␊ |
759 | ␉gAutoResolution = true;␊ |
760 | }*/␊ |
761 | |