Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 253554 | Differences between
and this patch

Collapse All | Expand All

(-)grub-1.96.orig/915resolution/915resolution.c (+891 lines)
Line 0 Link Here
1
/* 915resolution - Utility to change vbemodes on the intel
2
 * integrated video chipset */
3
4
/* Copied from 915 resolution created by steve tomjenovic
5
 * 915 resolution was in the public domain.
6
 * 
7
 * All I have done, was make the above program run within 
8
 * the grub2 environment.  
9
 *
10
 * Some of the checks are still commented, as I did not find
11
 * easy replacement for memmem.
12
 *
13
 * Slightly edited by Nathan Coulson (conathan@gmail.com)
14
 */
15
16
/*
17
 *  GRUB  --  GRand Unified Bootloader
18
 *  Copyright (C) 2003,2007  Free Software Foundation, Inc.
19
 *  Copyright (C) 2003  NIIBE Yutaka <gniibe@m17n.org>
20
 *
21
 *  GRUB is free software: you can redistribute it and/or modify
22
 *  it under the terms of the GNU General Public License as published by
23
 *  the Free Software Foundation, either version 3 of the License, or
24
 *  (at your option) any later version.
25
 *
26
 *  GRUB is distributed in the hope that it will be useful,
27
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 *  GNU General Public License for more details.
30
 *
31
 *  You should have received a copy of the GNU General Public License
32
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
33
 */
34
35
#include <grub/types.h>
36
#include <grub/misc.h>
37
#include <grub/mm.h>
38
#include <grub/err.h>
39
#include <grub/dl.h>
40
#include <grub/normal.h>
41
#include <grub/i386/io.h>
42
43
#define NEW(a) ((a *)(grub_malloc(sizeof(a))))
44
#define FREE(a) (grub_free(a))
45
46
#define VBIOS_START         0xc0000
47
#define VBIOS_SIZE          0x10000
48
49
#define FALSE 0
50
#define TRUE 1
51
52
#define MODE_TABLE_OFFSET_845G 617
53
54
#define VERSION "0.5.3-grub2-1"
55
56
#define ATI_SIGNATURE1 "ATI MOBILITY RADEON"
57
#define ATI_SIGNATURE2 "ATI Technologies Inc"
58
#define NVIDIA_SIGNATURE "NVIDIA Corp"
59
#define INTEL_SIGNATURE "Intel Corp"
60
61
typedef unsigned char * address;
62
typedef unsigned char byte;
63
typedef unsigned short word;
64
typedef unsigned char boolean;
65
typedef unsigned int cardinal;
66
67
typedef enum {
68
    CT_UNKWN, CT_830, CT_845G, CT_855GM, CT_865G, CT_915G, CT_915GM, CT_945G, CT_945GM, CT_945GME,
69
    CT_946GZ, CT_G965, CT_Q965
70
} chipset_type;
71
72
char * chipset_type_names[] = {
73
    "UNKNOWN", "830",  "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",
74
    "946GZ",   "G965", "Q965"
75
};
76
77
typedef enum {
78
    BT_UNKWN, BT_1, BT_2, BT_3
79
} bios_type;
80
81
char * bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
82
83
int freqs[] = { 60, 75, 85 };
84
85
typedef struct {
86
    byte mode;
87
    byte bits_per_pixel;
88
    word resolution;
89
    byte unknown;
90
} __attribute__((packed)) vbios_mode;
91
92
typedef struct {
93
    byte unknow1[2];
94
    byte x1;
95
    byte x_total;
96
    byte x2;
97
    byte y1;
98
    byte y_total;
99
    byte y2;
100
} __attribute__((packed)) vbios_resolution_type1;
101
102
typedef struct {
103
    unsigned long clock;
104
105
    word x1;
106
    word htotal;
107
    word x2;
108
    word hblank;
109
    word hsyncstart;
110
    word hsyncend;
111
    word y1;
112
    word vtotal;
113
    word y2;
114
    word vblank;
115
    word vsyncstart;
116
    word vsyncend;
117
} __attribute__((packed)) vbios_modeline_type2;
118
119
typedef struct {
120
    byte xchars;
121
    byte ychars;
122
    byte unknown[4];
123
124
    vbios_modeline_type2 modelines[];
125
} __attribute__((packed)) vbios_resolution_type2;
126
127
typedef struct {
128
    unsigned long clock;
129
130
    word x1;
131
    word htotal;
132
    word x2;
133
    word hblank;
134
    word hsyncstart;
135
    word hsyncend;
136
137
    word y1;
138
    word vtotal;
139
    word y2;
140
    word vblank;
141
    word vsyncstart;
142
    word vsyncend;
143
144
    word timing_h;
145
    word timing_v;
146
147
    byte unknown[6];
148
} __attribute__((packed)) vbios_modeline_type3;
149
150
typedef struct {
151
    unsigned char unknown[6];
152
153
    vbios_modeline_type3 modelines[];
154
} __attribute__((packed)) vbios_resolution_type3;
155
156
typedef struct {
157
    cardinal chipset_id;
158
    chipset_type chipset;
159
    bios_type bios;
160
    
161
    int bios_fd;
162
    address bios_ptr;
163
164
    vbios_mode * mode_table;
165
    cardinal mode_table_size;
166
    byte b1, b2;
167
168
    boolean unlocked;
169
} vbios_map;
170
171
172
cardinal get_chipset_id(void) {
173
    grub_outl(0x80000000, 0xcf8);
174
    return grub_inl(0xcfc);
175
}
176
177
chipset_type get_chipset(cardinal id) {
178
    chipset_type type;
179
    
180
    switch (id) {
181
    case 0x35758086:
182
        type = CT_830;
183
        break;
184
185
    case 0x25608086:
186
        type = CT_845G;
187
        break;
188
        
189
    case 0x35808086:
190
        type = CT_855GM;
191
        break;
192
        
193
    case 0x25708086:
194
        type = CT_865G;
195
        break;
196
197
    case 0x25808086:
198
	type = CT_915G;
199
	break;
200
201
    case 0x25908086:
202
        type = CT_915GM;
203
        break;
204
205
    case 0x27708086:
206
        type = CT_945G;
207
        break;
208
209
    case 0x27a08086:
210
        type = CT_945GM;
211
        break;
212
213
    case 0x27ac8086:
214
        type = CT_945GME;
215
        break;
216
217
    case 0x29708086:
218
        type = CT_946GZ;
219
        break;
220
221
    case 0x29a08086:
222
	type = CT_G965;
223
	break;
224
225
    case 0x29908086:
226
        type = CT_Q965;
227
        break;
228
229
    default:
230
        type = CT_UNKWN;
231
        break;
232
    }
233
234
    return type;
235
}
236
237
vbios_resolution_type1 * map_type1_resolution(vbios_map * map, word res) {
238
    vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res)); 
239
    return ptr;
240
}
241
242
vbios_resolution_type2 * map_type2_resolution(vbios_map * map, word res) {
243
    vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res)); 
244
    return ptr;
245
}
246
247
vbios_resolution_type3 * map_type3_resolution(vbios_map * map, word res) {
248
    vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res)); 
249
    return ptr;
250
}
251
252
boolean detect_bios_type(vbios_map * map, boolean modeline, int entry_size) {
253
    int i;
254
    short int r1, r2;
255
    
256
    r1 = r2 = 32000;
257
258
    for (i=0; i < map->mode_table_size; i++) {
259
        if (map->mode_table[i].resolution <= r1) {
260
            r1 = map->mode_table[i].resolution;
261
    	}
262
        else {
263
            if (map->mode_table[i].resolution <= r2) {
264
            	r2 = map->mode_table[i].resolution;
265
            }
266
    	}
267
268
        /*printf("r1 = %d  r2 = %d\n", r1, r2);*/
269
    }
270
271
    return (r2-r1-6) % entry_size == 0;
272
}
273
274
void close_vbios(vbios_map * map);
275
276
vbios_map * open_vbios(chipset_type forced_chipset) {
277
    int z;
278
    vbios_map * map = NEW(vbios_map);
279
    for(z=0; z<sizeof(vbios_map); z++) ((char*)map)[z]=0;
280
    /*
281
     * Determine chipset
282
     */
283
284
    if (forced_chipset == CT_UNKWN) {
285
        map->chipset_id = get_chipset_id();
286
        map->chipset = get_chipset(map->chipset_id);
287
    }
288
    else if (forced_chipset != CT_UNKWN) {
289
        map->chipset = forced_chipset;
290
    }
291
    else {
292
        map->chipset = CT_915GM;
293
    }
294
    
295
    /*
296
     *  Map the video bios to memory
297
     */
298
299
    map->bios_ptr=(char*)VBIOS_START;
300
301
    /*
302
     * check if we have ATI Radeon
303
     */
304
    
305
    /*if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||
306
        memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {
307
        grub_printf(stderr, "ATI chipset detected.  915resolution only works with Intel 800/900 series graphic chipsets.\n");
308
        return 0;
309
    }*/
310
311
    /*
312
     * check if we have NVIDIA
313
     */
314
    
315
    /*if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {
316
        grub_printf("NVIDIA chipset detected.  915resolution only works with Intel 800/900 series graphic chipsets.\n");
317
        return 0;
318
    }*/
319
320
    /*
321
     * check if we have Intel
322
     */
323
    
324
    /*if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
325
        grub_printf( "Intel chipset detected.  However, 915resolution was unable to determine the chipset type.\n");
326
327
        grub_printf("Chipset Id: %x\n", map->chipset_id);
328
329
        grub_printf("Please report this problem to stomljen@yahoo.com\n");
330
331
        close_vbios(map);
332
        return 0;
333
    }*/
334
335
    /*
336
     * check for others
337
     */
338
339
    if (map->chipset == CT_UNKWN) {
340
        grub_printf("Unknown chipset type and unrecognized bios.\n");
341
        
342
        grub_printf("915resolution only works with Intel 800/900 series graphic chipsets.\n");
343
344
        grub_printf("Chipset Id: %x\n", map->chipset_id);
345
        close_vbios(map);
346
        return 0;
347
    }
348
349
    /*
350
     * Figure out where the mode table is 
351
     */
352
353
    {
354
        address p = map->bios_ptr + 16;
355
        address limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
356
        
357
        while (p < limit && map->mode_table == 0) {
358
            vbios_mode * mode_ptr = (vbios_mode *) p;
359
            
360
            if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
361
                ((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
362
                map->mode_table = mode_ptr;
363
            }
364
            
365
            p++;
366
        }
367
368
        if (map->mode_table == 0) {
369
            grub_printf("Unable to locate the mode table.\n");
370
            grub_printf("Please run the program 'dump_bios' as root and\n");
371
            grub_printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
372
            grub_printf("Chipset: %s\n", chipset_type_names[map->chipset]);
373
            close_vbios(map);
374
            return 0;
375
        }
376
    }
377
378
    /*
379
     * Determine size of mode table
380
     */
381
    
382
    {
383
        vbios_mode * mode_ptr = map->mode_table;
384
        
385
        while (mode_ptr->mode != 0xff) {
386
            map->mode_table_size++;
387
            mode_ptr++;
388
        }
389
    }
390
391
    /*
392
     * Figure out what type of bios we have
393
     *  order of detection is important
394
     */
395
396
    if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3))) {
397
        map->bios = BT_3;
398
    }
399
    else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2))) {
400
        map->bios = BT_2;
401
    }
402
    else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1))) {
403
        map->bios = BT_1;
404
    }
405
    else {
406
        grub_printf("Unable to determine bios type.\n");
407
        grub_printf("Please run the program 'dump_bios' as root and\n");
408
        grub_printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
409
410
        grub_printf("Chipset: %s\n", chipset_type_names[map->chipset]);
411
        grub_printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
412
413
        grub_printf("Mode Table Entries: %u\n", map->mode_table_size);
414
        return 0;
415
    }
416
417
    return map;
418
}
419
420
void close_vbios(vbios_map * map) {
421
    FREE(map);
422
}
423
424
void unlock_vbios(vbios_map * map) {
425
426
    map->unlocked = TRUE;
427
    
428
    switch (map->chipset) {
429
    case CT_UNKWN:
430
        break;
431
    case CT_830:
432
    case CT_855GM:
433
        grub_outl(0x8000005a, 0xcf8);
434
        map->b1 = grub_inb(0xcfe);
435
        
436
        grub_outl(0x8000005a, 0xcf8);
437
        grub_outb(0x33, 0xcfe);
438
        break;
439
    case CT_845G:
440
    case CT_865G:
441
    case CT_915G:
442
    case CT_915GM:
443
    case CT_945G:
444
    case CT_945GM:
445
    case CT_945GME:
446
    case CT_946GZ:
447
    case CT_G965:
448
    case CT_Q965:
449
        grub_outl(0x80000090, 0xcf8);
450
        map->b1 = grub_inb(0xcfd);
451
        map->b2 = grub_inb(0xcfe);
452
        grub_outl(0x80000090, 0xcf8);
453
        grub_outb(0x33, 0xcfd);
454
        grub_outb(0x33, 0xcfe);
455
        break;
456
    }
457
458
#if DEBUG
459
    {
460
        cardinal t = grub_inl(0xcfc);
461
        grub_printf("unlock PAM: (0x%08x)\n", t);
462
    }
463
#endif
464
}
465
466
void relock_vbios(vbios_map * map) {
467
468
    map->unlocked = FALSE;
469
    
470
    switch (map->chipset) {
471
    case CT_UNKWN:
472
        break;
473
    case CT_830:
474
    case CT_855GM:
475
        grub_outl(0x8000005a, 0xcf8);
476
        grub_outb(map->b1, 0xcfe);
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_G965:
487
    case CT_Q965:
488
        grub_outl(0x80000090, 0xcf8);
489
        grub_outb(map->b1, 0xcfd);
490
        grub_outb(map->b2, 0xcfe);
491
        break;
492
    }
493
494
#if DEBUG
495
    {
496
        cardinal t = inl(0xcfc);
497
        grub_printf("relock PAM: (0x%08x)\n", t);
498
    }
499
#endif
500
}
501
502
        
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
void list_modes(vbios_map *map, cardinal raw) {
524
    cardinal i, x, y;
525
526
    for (i=0; i < map->mode_table_size; i++) {
527
        switch(map->bios) {
528
        case BT_1:
529
            {
530
                vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
531
                
532
                x = ((((cardinal) res->x2) & 0xf0) << 4) | res->x1;
533
                y = ((((cardinal) res->y2) & 0xf0) << 4) | res->y1;
534
                
535
                if (x != 0 && y != 0) {
536
                    grub_printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
537
                }
538
539
		if (raw)
540
		{
541
                    grub_printf("Mode %02x (raw) :\n\t%02x %02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n", map->mode_table[i].mode, res->unknow1[0],res->unknow1[1], res->x1,res->x_total,res->x2,res->y1,res->y_total,res->y2);
542
		}
543
544
            }
545
            break;
546
        case BT_2:
547
            {
548
                vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
549
                
550
                x = res->modelines[0].x1+1;
551
                y = res->modelines[0].y1+1;
552
553
                if (x != 0 && y != 0) {
554
                    grub_printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
555
                }
556
            }
557
            break;
558
        case BT_3:
559
            {
560
                vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
561
                
562
                x = res->modelines[0].x1+1;
563
                y = res->modelines[0].y1+1;
564
                
565
                if (x != 0 && y != 0) {
566
                    grub_printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);
567
                }
568
            }
569
            break;
570
        case BT_UNKWN:
571
            break;
572
        }
573
    }
574
}
575
576
577
578
579
580
static void gtf_timings(int x, int y, int freq,
581
        unsigned long *clock,
582
        word *hsyncstart, word *hsyncend, word *hblank,
583
        word *vsyncstart, word *vsyncend, word *vblank)
584
{
585
    int hbl, vbl, vfreq;
586
587
    vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;
588
    vfreq = vbl * freq;
589
    hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /
590
            (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);
591
592
    *vsyncstart = y;
593
    *vsyncend = y + 3;
594
    *vblank = vbl - 1;
595
    *hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
596
    *hsyncend = x + hbl / 2 - 1;
597
    *hblank = x + hbl - 1;
598
    *clock = (x + hbl) * vfreq / 1000;
599
}
600
601
void set_mode(vbios_map * map, cardinal mode, cardinal x, cardinal y, cardinal bp, cardinal htotal, cardinal vtotal) {
602
    int xprev, yprev;
603
    cardinal i, j;
604
605
    for (i=0; i < map->mode_table_size; i++) {
606
        if (map->mode_table[i].mode == mode) {
607
            switch(map->bios) {
608
            case BT_1:
609
                {
610
                    vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
611
                    
612
                    if (bp) {
613
                        map->mode_table[i].bits_per_pixel = bp;
614
                    }
615
                    
616
                    res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
617
                    res->x1 = (x & 0xff);
618
                    
619
                    res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
620
                    res->y1 = (y & 0xff);
621
		    if (htotal)
622
			res->x_total = ((htotal-x) & 0xff);
623
624
		    if (vtotal)
625
			res->y_total = ((vtotal-y) & 0xff);
626
                }
627
                break;
628
            case BT_2:
629
                {
630
                    vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
631
632
                    res->xchars = x / 8;
633
                    res->ychars = y / 16 - 1;
634
                    xprev = res->modelines[0].x1;
635
                    yprev = res->modelines[0].y1;
636
637
                    for(j=0; j < 3; j++) {
638
                        vbios_modeline_type2 * modeline = &res->modelines[j];
639
                        
640
                        if (modeline->x1 == xprev && modeline->y1 == yprev) {
641
                            modeline->x1 = modeline->x2 = x-1;
642
                            modeline->y1 = modeline->y2 = y-1;
643
644
                            gtf_timings(x, y, freqs[j], &modeline->clock,
645
                                    &modeline->hsyncstart, &modeline->hsyncend,
646
                                    &modeline->hblank, &modeline->vsyncstart,
647
                                    &modeline->vsyncend, &modeline->vblank);
648
649
                            if (htotal)
650
                                modeline->htotal = htotal;
651
                            else
652
                                modeline->htotal = modeline->hblank;
653
654
                            if (vtotal)
655
                                modeline->vtotal = vtotal;
656
                            else
657
                                modeline->vtotal = modeline->vblank;
658
                        }
659
                    }
660
                }
661
                break;
662
            case BT_3:
663
                {
664
                    vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
665
                    
666
                    xprev = res->modelines[0].x1;
667
                    yprev = res->modelines[0].y1;
668
669
                    for (j=0; j < 3; j++) {
670
                        vbios_modeline_type3 * modeline = &res->modelines[j];
671
                        
672
                        if (modeline->x1 == xprev && modeline->y1 == yprev) {
673
                            modeline->x1 = modeline->x2 = x-1;
674
                            modeline->y1 = modeline->y2 = y-1;
675
                            
676
                            gtf_timings(x, y, freqs[j], &modeline->clock,
677
                                    &modeline->hsyncstart, &modeline->hsyncend,
678
                                    &modeline->hblank, &modeline->vsyncstart,
679
                                    &modeline->vsyncend, &modeline->vblank);
680
                            if (htotal)
681
                                modeline->htotal = htotal;
682
                            else
683
                                modeline->htotal = modeline->hblank;
684
                            if (vtotal)
685
                                modeline->vtotal = vtotal;
686
                            else
687
                                modeline->vtotal = modeline->vblank;
688
689
                            modeline->timing_h   = y-1;
690
                            modeline->timing_v   = x-1;
691
                        }
692
                    }
693
                }
694
                break;
695
            case BT_UNKWN:
696
                break;
697
            }
698
        }
699
    }
700
}   
701
702
void display_map_info(vbios_map * map) {
703
    grub_printf("Chipset: %s\n", chipset_type_names[map->chipset]);
704
    grub_printf("BIOS: %s\n", bios_type_names[map->bios]);
705
706
    grub_printf("Mode Table Offset: $C0000 + $%x\n", ((cardinal)map->mode_table) - ((cardinal)map->bios_ptr));
707
    grub_printf("Mode Table Entries: %u\n", map->mode_table_size);
708
}
709
710
711
int parse_args(int argc, char *argv[], chipset_type *forced_chipset, cardinal *list, cardinal *mode, cardinal *x, cardinal *y, cardinal *bp, cardinal *raw, cardinal *htotal, cardinal *vtotal) {
712
    cardinal index = 0;
713
714
    *list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;
715
716
    *forced_chipset = CT_UNKWN;
717
    
718
719
    if ((argc > index) && !grub_strcmp(argv[index], "-c")) {
720
        index++;
721
722
        if(argc<=index) {
723
            return 0;
724
        }
725
        
726
        if (!grub_strcmp(argv[index], "845")) {
727
            *forced_chipset = CT_845G;
728
        }
729
        else if (!grub_strcmp(argv[index], "855")) {
730
            *forced_chipset = CT_855GM;
731
        }
732
        else if (!grub_strcmp(argv[index], "865")) {
733
            *forced_chipset = CT_865G;
734
        }
735
        else if (!grub_strcmp(argv[index], "915G")) {
736
            *forced_chipset = CT_915G;
737
        }
738
        else if (!grub_strcmp(argv[index], "915GM")) {
739
            *forced_chipset = CT_915GM;
740
        }
741
        else if (!grub_strcmp(argv[index], "945G")) {
742
            *forced_chipset = CT_945G;
743
        }
744
        else if (!grub_strcmp(argv[index], "945GM")) {
745
            *forced_chipset = CT_945GM;
746
        }
747
        else if (!grub_strcmp(argv[index], "945GME")) {
748
            *forced_chipset = CT_945GME;
749
        }
750
        else if (!grub_strcmp(argv[index], "946GZ")) {
751
            *forced_chipset = CT_946GZ;
752
        }
753
        else if (!grub_strcmp(argv[index], "G965")) {
754
            *forced_chipset = CT_G965;
755
        }
756
        else if (!grub_strcmp(argv[index], "Q965")) {
757
            *forced_chipset = CT_Q965;
758
        }
759
        else {
760
            *forced_chipset = CT_UNKWN;
761
        }
762
        
763
        index++;
764
        
765
        if (argc<=index) {
766
            return 0;
767
        }
768
    }
769
770
    if ((argc > index) && !grub_strcmp(argv[index], "-l")) {
771
        *list = 1;
772
        index++;
773
774
        if(argc<=index) {
775
            return 0;
776
        }
777
    }
778
    
779
    if ((argc > index) && !grub_strcmp(argv[index], "-r")) {
780
        *raw = 1;
781
        index++;
782
783
        if(argc<=index) {
784
            return 0;
785
        }
786
    }
787
    
788
    if (argc-index < 3 || argc-index > 6) {
789
        return -1;
790
    }
791
792
    *mode = (cardinal) grub_strtoul(argv[index], NULL, 16);
793
    *x = (cardinal)grub_strtoul(argv[index+1], NULL, 10);
794
    *y = (cardinal)grub_strtoul(argv[index+2], NULL, 10);
795
796
797
    if (argc-index > 3) {
798
        *bp = (cardinal)grub_strtoul(argv[index+3], NULL, 10);
799
    }
800
    else {
801
        *bp = 0;
802
    }
803
    
804
    if (argc-index > 4) {
805
        *htotal = (cardinal)grub_strtoul(argv[index+4], NULL, 10);
806
    }
807
    else {
808
        *htotal = 0;
809
    }
810
811
    if (argc-index > 5) {
812
        *vtotal = (cardinal)grub_strtoul(argv[index+5], NULL, 10);
813
    }
814
    else {
815
        *vtotal = 0;
816
    }
817
    
818
    return 0;
819
}
820
821
void usage() {
822
    grub_printf("Usage: 915resolution [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n");
823
    grub_printf("  Set the resolution to XxY for a video mode\n");
824
    grub_printf("  Bits per pixel are optional.  htotal/vtotal settings are additionally optional.\n");
825
    grub_printf("  Options:\n");
826
    grub_printf("    -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");
827
    grub_printf("    -l display the modes found in the video BIOS\n");
828
    grub_printf("    -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");
829
}
830
831
static grub_err_t
832
grub_cmd_915resolution (struct grub_arg_list *state ,
833
		int argc ,
834
		char **argv )
835
{
836
    vbios_map * map;
837
    cardinal list, mode, x, y, bp, raw, htotal, vtotal;
838
    chipset_type forced_chipset;
839
    
840
    grub_printf("Intel 800/900 Series VBIOS Hack : version %s\n\n", VERSION);
841
842
    if (parse_args(argc, argv, &forced_chipset, &list, &mode, &x, &y, &bp, &raw, &htotal, &vtotal) == -1) {
843
        usage();
844
        return 2;
845
    }
846
847
    map = open_vbios(forced_chipset);
848
    display_map_info(map);
849
850
    grub_printf("\n");
851
852
    if (list) {
853
        list_modes(map, raw);
854
    }
855
856
    if (mode!=0 && x!=0 && y!=0) {
857
          unlock_vbios(map);
858
859
        set_mode(map, mode, x, y, bp, htotal, vtotal);
860
861
          relock_vbios(map);
862
        
863
        grub_printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);
864
        
865
        if (list) {
866
            list_modes(map, raw);
867
        }
868
    }
869
870
    close_vbios(map);
871
    
872
    return 0;
873
}
874
875
876
877
878
879
880
881
GRUB_MOD_INIT(915resolution)
882
{
883
  (void)mod;			/* To stop warning. */
884
  grub_register_command ("915resolution", grub_cmd_915resolution, GRUB_COMMAND_FLAG_BOTH,
885
			 "915resolution", "Intel VBE editor", 0);
886
}
887
888
GRUB_MOD_FINI(915resolution)
889
{
890
  grub_unregister_command ("915resolution");
891
}
(-)grub-1.96.orig/conf/common.rmk (-1 / +6 lines)
Lines 232-238 Link Here
232
	cmp.mod cat.mod help.mod font.mod search.mod		\
232
	cmp.mod cat.mod help.mod font.mod search.mod		\
233
	loopback.mod configfile.mod echo.mod			\
233
	loopback.mod configfile.mod echo.mod			\
234
	terminfo.mod test.mod blocklist.mod hexdump.mod		\
234
	terminfo.mod test.mod blocklist.mod hexdump.mod		\
235
	read.mod
235
	read.mod 915resolution.mod
236
236
237
# For hello.mod.
237
# For hello.mod.
238
hello_mod_SOURCES = hello/hello.c
238
hello_mod_SOURCES = hello/hello.c
Lines 331-333 Link Here
331
read_mod_SOURCES = commands/read.c
331
read_mod_SOURCES = commands/read.c
332
read_mod_CFLAGS = $(COMMON_CFLAGS)
332
read_mod_CFLAGS = $(COMMON_CFLAGS)
333
read_mod_LDFLAGS = $(COMMON_LDFLAGS)
333
read_mod_LDFLAGS = $(COMMON_LDFLAGS)
334
335
# For 915resolution.mod.
336
915resolution_mod_SOURCES = 915resolution/915resolution.c
337
915resolution_mod_CFLAGS = $(COMMON_CFLAGS)
338
915resolution_mod_LDFLAGS = $(COMMON_LDFLAGS)

Return to bug 253554