-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathvideo.S
2007 lines (1703 loc) · 39.4 KB
/
video.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* video.S
*
* Display adapter & video mode setup, version 2.13 (14-May-99)
*
* Copyright (C) 1995 -- 1998 Martin Mares <mj@ucw.cz>
* Based on the original setup.S code (C) Linus Torvalds and Mats Anderson
*
* Rewritten to use GNU 'as' by Chris Noe <stiker@northlink.com> May 1999
*
* For further information, look at Documentation/svga.txt.
*
*/
#include <linux/config.h> /* for CONFIG_VIDEO_* */
/* Enable autodetection of SVGA adapters and modes. */
#undef CONFIG_VIDEO_SVGA
/* Enable autodetection of VESA modes */
#define CONFIG_VIDEO_VESA
/* Enable compacting of mode table */
#define CONFIG_VIDEO_COMPACT
/* Retain screen contents when switching modes */
#define CONFIG_VIDEO_RETAIN
/* Enable local mode list */
#undef CONFIG_VIDEO_LOCAL
/* Force 400 scan lines for standard modes (hack to fix bad BIOS behaviour */
#undef CONFIG_VIDEO_400_HACK
/* Hack that lets you force specific BIOS mode ID and specific dimensions */
#undef CONFIG_VIDEO_GFX_HACK
#define VIDEO_GFX_BIOS_AX 0x4f02 /* 800x600 on ThinkPad */
#define VIDEO_GFX_BIOS_BX 0x0102
#define VIDEO_GFX_DUMMY_RESOLUTION 0x6425 /* 100x37 */
/* This code uses an extended set of video mode numbers. These include:
* Aliases for standard modes
* NORMAL_VGA (-1)
* EXTENDED_VGA (-2)
* ASK_VGA (-3)
* Video modes numbered by menu position -- NOT RECOMMENDED because of lack
* of compatibility when extending the table. These are between 0x00 and 0xff.
*/
#define VIDEO_FIRST_MENU 0x0000
/* Standard BIOS video modes (BIOS number + 0x0100) */
#define VIDEO_FIRST_BIOS 0x0100
/* VESA BIOS video modes (VESA number + 0x0200) */
#define VIDEO_FIRST_VESA 0x0200
/* Video7 special modes (BIOS number + 0x0900) */
#define VIDEO_FIRST_V7 0x0900
/* Special video modes */
#define VIDEO_FIRST_SPECIAL 0x0f00
#define VIDEO_80x25 0x0f00
#define VIDEO_8POINT 0x0f01
#define VIDEO_80x43 0x0f02
#define VIDEO_80x28 0x0f03
#define VIDEO_CURRENT_MODE 0x0f04
#define VIDEO_80x30 0x0f05
#define VIDEO_80x34 0x0f06
#define VIDEO_80x60 0x0f07
#define VIDEO_GFX_HACK 0x0f08
#define VIDEO_LAST_SPECIAL 0x0f09
/* Video modes given by resolution */
#define VIDEO_FIRST_RESOLUTION 0x1000
/* The "recalculate timings" flag */
#define VIDEO_RECALC 0x8000
/* Positions of various video parameters passed to the kernel */
/* (see also include/linux/tty.h) */
#define PARAM_CURSOR_POS 0x00
#define PARAM_VIDEO_PAGE 0x04
#define PARAM_VIDEO_MODE 0x06
#define PARAM_VIDEO_COLS 0x07
#define PARAM_VIDEO_EGA_BX 0x0a
#define PARAM_VIDEO_LINES 0x0e
#define PARAM_HAVE_VGA 0x0f
#define PARAM_FONT_POINTS 0x10
#define PARAM_LFB_WIDTH 0x12
#define PARAM_LFB_HEIGHT 0x14
#define PARAM_LFB_DEPTH 0x16
#define PARAM_LFB_BASE 0x18
#define PARAM_LFB_SIZE 0x1c
#define PARAM_LFB_LINELENGTH 0x24
#define PARAM_LFB_COLORS 0x26
#define PARAM_VESAPM_SEG 0x2e
#define PARAM_VESAPM_OFF 0x30
#define PARAM_LFB_PAGES 0x32
#define PARAM_VESA_ATTRIB 0x34
/* Define DO_STORE according to CONFIG_VIDEO_RETAIN */
#ifdef CONFIG_VIDEO_RETAIN
#define DO_STORE call store_screen
#else
#define DO_STORE
#endif /* CONFIG_VIDEO_RETAIN */
# This is the main entry point called by setup.S
# %ds *must* be pointing to the bootsector
video: pushw %ds # We use different segments
pushw %ds # FS contains original DS
popw %fs
pushw %cs # DS is equal to CS
popw %ds
pushw %cs # ES is equal to CS
popw %es
xorw %ax, %ax
movw %ax, %gs # GS is zero
cld
call basic_detect # Basic adapter type testing (EGA/VGA/MDA/CGA)
#ifdef CONFIG_VIDEO_SELECT
movw %fs:(0x01fa), %ax # User selected video mode
cmpw $ASK_VGA, %ax # Bring up the menu
jz vid2
call mode_set # Set the mode
jc vid1
leaw badmdt, %si # Invalid mode ID
call prtstr
vid2: call mode_menu
vid1:
#ifdef CONFIG_VIDEO_RETAIN
call restore_screen # Restore screen contents
#endif /* CONFIG_VIDEO_RETAIN */
call store_edid
#endif /* CONFIG_VIDEO_SELECT */
call mode_params # Store mode parameters
popw %ds # Restore original DS
ret
# Detect if we have CGA, MDA, EGA or VGA and pass it to the kernel.
basic_detect:
movb $0, %fs:(PARAM_HAVE_VGA)
movb $0x12, %ah # Check EGA/VGA
movb $0x10, %bl
int $0x10
movw %bx, %fs:(PARAM_VIDEO_EGA_BX) # Identifies EGA to the kernel
cmpb $0x10, %bl # No, it's a CGA/MDA/HGA card.
je basret
incb adapter
movw $0x1a00, %ax # Check EGA or VGA?
int $0x10
cmpb $0x1a, %al # 1a means VGA...
jne basret # anything else is EGA.
incb %fs:(PARAM_HAVE_VGA) # We've detected a VGA
incb adapter
basret: ret
# Store the video mode parameters for later usage by the kernel.
# This is done by asking the BIOS except for the rows/columns
# parameters in the default 80x25 mode -- these are set directly,
# because some very obscure BIOSes supply insane values.
mode_params:
#ifdef CONFIG_VIDEO_SELECT
cmpb $0, graphic_mode
jnz mopar_gr
#endif
movb $0x03, %ah # Read cursor position
xorb %bh, %bh
int $0x10
movw %dx, %fs:(PARAM_CURSOR_POS)
movb $0x0f, %ah # Read page/mode/width
int $0x10
movw %bx, %fs:(PARAM_VIDEO_PAGE)
movw %ax, %fs:(PARAM_VIDEO_MODE) # Video mode and screen width
cmpb $0x7, %al # MDA/HGA => segment differs
jnz mopar0
movw $0xb000, video_segment
mopar0: movw %gs:(0x485), %ax # Font size
movw %ax, %fs:(PARAM_FONT_POINTS) # (valid only on EGA/VGA)
movw force_size, %ax # Forced size?
orw %ax, %ax
jz mopar1
movb %ah, %fs:(PARAM_VIDEO_COLS)
movb %al, %fs:(PARAM_VIDEO_LINES)
ret
mopar1: movb $25, %al
cmpb $0, adapter # If we are on CGA/MDA/HGA, the
jz mopar2 # screen must have 25 lines.
movb %gs:(0x484), %al # On EGA/VGA, use the EGA+ BIOS
incb %al # location of max lines.
mopar2: movb %al, %fs:(PARAM_VIDEO_LINES)
ret
#ifdef CONFIG_VIDEO_SELECT
# Fetching of VESA frame buffer parameters
mopar_gr:
leaw modelist+1024, %di
movb $0x23, %fs:(PARAM_HAVE_VGA)
movw 16(%di), %ax
movw %ax, %fs:(PARAM_LFB_LINELENGTH)
movw 18(%di), %ax
movw %ax, %fs:(PARAM_LFB_WIDTH)
movw 20(%di), %ax
movw %ax, %fs:(PARAM_LFB_HEIGHT)
movb 25(%di), %al
movb $0, %ah
movw %ax, %fs:(PARAM_LFB_DEPTH)
movb 29(%di), %al
movb $0, %ah
movw %ax, %fs:(PARAM_LFB_PAGES)
movl 40(%di), %eax
movl %eax, %fs:(PARAM_LFB_BASE)
movl 31(%di), %eax
movl %eax, %fs:(PARAM_LFB_COLORS)
movl 35(%di), %eax
movl %eax, %fs:(PARAM_LFB_COLORS+4)
movw 0(%di), %ax
movw %ax, %fs:(PARAM_VESA_ATTRIB)
# get video mem size
leaw modelist+1024, %di
movw $0x4f00, %ax
int $0x10
xorl %eax, %eax
movw 18(%di), %ax
movl %eax, %fs:(PARAM_LFB_SIZE)
# switching the DAC to 8-bit is for <= 8 bpp only
movw %fs:(PARAM_LFB_DEPTH), %ax
cmpw $8, %ax
jg dac_done
# get DAC switching capability
xorl %eax, %eax
movb 10(%di), %al
testb $1, %al
jz dac_set
# attempt to switch DAC to 8-bit
movw $0x4f08, %ax
movw $0x0800, %bx
int $0x10
cmpw $0x004f, %ax
jne dac_set
movb %bh, dac_size # store actual DAC size
dac_set:
# set color size to DAC size
movb dac_size, %al
movb %al, %fs:(PARAM_LFB_COLORS+0)
movb %al, %fs:(PARAM_LFB_COLORS+2)
movb %al, %fs:(PARAM_LFB_COLORS+4)
movb %al, %fs:(PARAM_LFB_COLORS+6)
# set color offsets to 0
movb $0, %fs:(PARAM_LFB_COLORS+1)
movb $0, %fs:(PARAM_LFB_COLORS+3)
movb $0, %fs:(PARAM_LFB_COLORS+5)
movb $0, %fs:(PARAM_LFB_COLORS+7)
dac_done:
# get protected mode interface informations
movw $0x4f0a, %ax
xorw %bx, %bx
xorw %di, %di
int $0x10
cmp $0x004f, %ax
jnz no_pm
movw %es, %fs:(PARAM_VESAPM_SEG)
movw %di, %fs:(PARAM_VESAPM_OFF)
no_pm: ret
# The video mode menu
mode_menu:
leaw keymsg, %si # "Return/Space/Timeout" message
call prtstr
call flush
nokey: call getkt
cmpb $0x0d, %al # ENTER ?
je listm # yes - manual mode selection
cmpb $0x20, %al # SPACE ?
je defmd1 # no - repeat
call beep
jmp nokey
defmd1: ret # No mode chosen? Default 80x25
listm: call mode_table # List mode table
listm0: leaw name_bann, %si # Print adapter name
call prtstr
movw card_name, %si
orw %si, %si
jnz an2
movb adapter, %al
leaw old_name, %si
orb %al, %al
jz an1
leaw ega_name, %si
decb %al
jz an1
leaw vga_name, %si
jmp an1
an2: call prtstr
leaw svga_name, %si
an1: call prtstr
leaw listhdr, %si # Table header
call prtstr
movb $0x30, %dl # DL holds mode number
leaw modelist, %si
lm1: cmpw $ASK_VGA, (%si) # End?
jz lm2
movb %dl, %al # Menu selection number
call prtchr
call prtsp2
lodsw
call prthw # Mode ID
call prtsp2
movb 0x1(%si), %al
call prtdec # Rows
movb $0x78, %al # the letter 'x'
call prtchr
lodsw
call prtdec # Columns
movb $0x0d, %al # New line
call prtchr
movb $0x0a, %al
call prtchr
incb %dl # Next character
cmpb $0x3a, %dl
jnz lm1
movb $0x61, %dl
jmp lm1
lm2: leaw prompt, %si # Mode prompt
call prtstr
leaw edit_buf, %di # Editor buffer
lm3: call getkey
cmpb $0x0d, %al # Enter?
jz lment
cmpb $0x08, %al # Backspace?
jz lmbs
cmpb $0x20, %al # Printable?
jc lm3
cmpw $edit_buf+4, %di # Enough space?
jz lm3
stosb
call prtchr
jmp lm3
lmbs: cmpw $edit_buf, %di # Backspace
jz lm3
decw %di
movb $0x08, %al
call prtchr
call prtspc
movb $0x08, %al
call prtchr
jmp lm3
lment: movb $0, (%di)
leaw crlft, %si
call prtstr
leaw edit_buf, %si
cmpb $0, (%si) # Empty string = default mode
jz lmdef
cmpb $0, 1(%si) # One character = menu selection
jz mnusel
cmpw $0x6373, (%si) # "scan" => mode scanning
jnz lmhx
cmpw $0x6e61, 2(%si)
jz lmscan
lmhx: xorw %bx, %bx # Else => mode ID in hex
lmhex: lodsb
orb %al, %al
jz lmuse1
subb $0x30, %al
jc lmbad
cmpb $10, %al
jc lmhx1
subb $7, %al
andb $0xdf, %al
cmpb $10, %al
jc lmbad
cmpb $16, %al
jnc lmbad
lmhx1: shlw $4, %bx
orb %al, %bl
jmp lmhex
lmuse1: movw %bx, %ax
jmp lmuse
mnusel: lodsb # Menu selection
xorb %ah, %ah
subb $0x30, %al
jc lmbad
cmpb $10, %al
jc lmuse
cmpb $0x61-0x30, %al
jc lmbad
subb $0x61-0x30-10, %al
cmpb $36, %al
jnc lmbad
lmuse: call mode_set
jc lmdef
lmbad: leaw unknt, %si
call prtstr
jmp lm2
lmscan: cmpb $0, adapter # Scanning only on EGA/VGA
jz lmbad
movw $0, mt_end # Scanning of modes is
movb $1, scanning # done as new autodetection.
call mode_table
jmp listm0
lmdef: ret
# Additional parts of mode_set... (relative jumps, you know)
setv7: # Video7 extended modes
DO_STORE
subb $VIDEO_FIRST_V7>>8, %bh
movw $0x6f05, %ax
int $0x10
stc
ret
_setrec: jmp setrec # Ugly...
_set_80x25: jmp set_80x25
# Aliases for backward compatibility.
setalias:
movw $VIDEO_80x25, %ax
incw %bx
jz mode_set
movb $VIDEO_8POINT-VIDEO_FIRST_SPECIAL, %al
incw %bx
jnz setbad # Fall-through!
# Setting of user mode (AX=mode ID) => CF=success
mode_set:
movw %ax, %fs:(0x01fa) # Store mode for use in acpi_wakeup.S
movw %ax, %bx
cmpb $0xff, %ah
jz setalias
testb $VIDEO_RECALC>>8, %ah
jnz _setrec
cmpb $VIDEO_FIRST_RESOLUTION>>8, %ah
jnc setres
cmpb $VIDEO_FIRST_SPECIAL>>8, %ah
jz setspc
cmpb $VIDEO_FIRST_V7>>8, %ah
jz setv7
cmpb $VIDEO_FIRST_VESA>>8, %ah
jnc check_vesa
orb %ah, %ah
jz setmenu
decb %ah
jz setbios
setbad: clc
movb $0, do_restore # The screen needn't be restored
ret
setvesa:
DO_STORE
subb $VIDEO_FIRST_VESA>>8, %bh
movw $0x4f02, %ax # VESA BIOS mode set call
int $0x10
cmpw $0x004f, %ax # AL=4f if implemented
jnz setbad # AH=0 if OK
stc
ret
setbios:
DO_STORE
int $0x10 # Standard BIOS mode set call
pushw %bx
movb $0x0f, %ah # Check if really set
int $0x10
popw %bx
cmpb %bl, %al
jnz setbad
stc
ret
setspc: xorb %bh, %bh # Set special mode
cmpb $VIDEO_LAST_SPECIAL-VIDEO_FIRST_SPECIAL, %bl
jnc setbad
addw %bx, %bx
jmp *spec_inits(%bx)
setmenu:
orb %al, %al # 80x25 is an exception
jz _set_80x25
pushw %bx # Set mode chosen from menu
call mode_table # Build the mode table
popw %ax
shlw $2, %ax
addw %ax, %si
cmpw %di, %si
jnc setbad
movw (%si), %ax # Fetch mode ID
_m_s: jmp mode_set
setres: pushw %bx # Set mode chosen by resolution
call mode_table
popw %bx
xchgb %bl, %bh
setr1: lodsw
cmpw $ASK_VGA, %ax # End of the list?
jz setbad
lodsw
cmpw %bx, %ax
jnz setr1
movw -4(%si), %ax # Fetch mode ID
jmp _m_s
check_vesa:
leaw modelist+1024, %di
subb $VIDEO_FIRST_VESA>>8, %bh
movw %bx, %cx # Get mode information structure
movw $0x4f01, %ax
int $0x10
addb $VIDEO_FIRST_VESA>>8, %bh
cmpw $0x004f, %ax
jnz setbad
movb (%di), %al # Check capabilities.
andb $0x19, %al
cmpb $0x09, %al
jz setvesa # This is a text mode
movb (%di), %al # Check capabilities.
andb $0x99, %al
cmpb $0x99, %al
jnz _setbad # Doh! No linear frame buffer.
subb $VIDEO_FIRST_VESA>>8, %bh
orw $0x4000, %bx # Use linear frame buffer
movw $0x4f02, %ax # VESA BIOS mode set call
int $0x10
cmpw $0x004f, %ax # AL=4f if implemented
jnz _setbad # AH=0 if OK
movb $1, graphic_mode # flag graphic mode
movb $0, do_restore # no screen restore
stc
ret
_setbad: jmp setbad # Ugly...
# Recalculate vertical display end registers -- this fixes various
# inconsistencies of extended modes on many adapters. Called when
# the VIDEO_RECALC flag is set in the mode ID.
setrec: subb $VIDEO_RECALC>>8, %ah # Set the base mode
call mode_set
jnc rct3
movw %gs:(0x485), %ax # Font size in pixels
movb %gs:(0x484), %bl # Number of rows
incb %bl
mulb %bl # Number of visible
decw %ax # scan lines - 1
movw $0x3d4, %dx
movw %ax, %bx
movb $0x12, %al # Lower 8 bits
movb %bl, %ah
outw %ax, %dx
movb $0x07, %al # Bits 8 and 9 in the overflow register
call inidx
xchgb %al, %ah
andb $0xbd, %ah
shrb %bh
jnc rct1
orb $0x02, %ah
rct1: shrb %bh
jnc rct2
orb $0x40, %ah
rct2: movb $0x07, %al
outw %ax, %dx
stc
rct3: ret
# Table of routines for setting of the special modes.
spec_inits:
.word set_80x25
.word set_8pixel
.word set_80x43
.word set_80x28
.word set_current
.word set_80x30
.word set_80x34
.word set_80x60
.word set_gfx
# Set the 80x25 mode. If already set, do nothing.
set_80x25:
movw $0x5019, force_size # Override possibly broken BIOS
use_80x25:
#ifdef CONFIG_VIDEO_400_HACK
movw $0x1202, %ax # Force 400 scan lines
movb $0x30, %bl
int $0x10
#else
movb $0x0f, %ah # Get current mode ID
int $0x10
cmpw $0x5007, %ax # Mode 7 (80x25 mono) is the only one available
jz st80 # on CGA/MDA/HGA and is also available on EGAM
cmpw $0x5003, %ax # Unknown mode, force 80x25 color
jnz force3
st80: cmpb $0, adapter # CGA/MDA/HGA => mode 3/7 is always 80x25
jz set80
movb %gs:(0x0484), %al # This is EGA+ -- beware of 80x50 etc.
orb %al, %al # Some buggy BIOS'es set 0 rows
jz set80
cmpb $24, %al # It's hopefully correct
jz set80
#endif /* CONFIG_VIDEO_400_HACK */
force3: DO_STORE
movw $0x0003, %ax # Forced set
int $0x10
set80: stc
ret
# Set the 80x50/80x43 8-pixel mode. Simple BIOS calls.
set_8pixel:
DO_STORE
call use_80x25 # The base is 80x25
set_8pt:
movw $0x1112, %ax # Use 8x8 font
xorb %bl, %bl
int $0x10
movw $0x1200, %ax # Use alternate print screen
movb $0x20, %bl
int $0x10
movw $0x1201, %ax # Turn off cursor emulation
movb $0x34, %bl
int $0x10
movb $0x01, %ah # Define cursor scan lines 6-7
movw $0x0607, %cx
int $0x10
set_current:
stc
ret
# Set the 80x28 mode. This mode works on all VGA's, because it's a standard
# 80x25 mode with 14-point fonts instead of 16-point.
set_80x28:
DO_STORE
call use_80x25 # The base is 80x25
set14: movw $0x1111, %ax # Use 9x14 font
xorb %bl, %bl
int $0x10
movb $0x01, %ah # Define cursor scan lines 11-12
movw $0x0b0c, %cx
int $0x10
stc
ret
# Set the 80x43 mode. This mode is works on all VGA's.
# It's a 350-scanline mode with 8-pixel font.
set_80x43:
DO_STORE
movw $0x1201, %ax # Set 350 scans
movb $0x30, %bl
int $0x10
movw $0x0003, %ax # Reset video mode
int $0x10
jmp set_8pt # Use 8-pixel font
# Set the 80x30 mode (all VGA's). 480 scanlines, 16-pixel font.
set_80x30:
call use_80x25 # Start with real 80x25
DO_STORE
movw $0x3cc, %dx # Get CRTC port
inb %dx, %al
movb $0xd4, %dl
rorb %al # Mono or color?
jc set48a
movb $0xb4, %dl
set48a: movw $0x0c11, %ax # Vertical sync end (also unlocks CR0-7)
call outidx
movw $0x0b06, %ax # Vertical total
call outidx
movw $0x3e07, %ax # (Vertical) overflow
call outidx
movw $0xea10, %ax # Vertical sync start
call outidx
movw $0xdf12, %ax # Vertical display end
call outidx
movw $0xe715, %ax # Vertical blank start
call outidx
movw $0x0416, %ax # Vertical blank end
call outidx
pushw %dx
movb $0xcc, %dl # Misc output register (read)
inb %dx, %al
movb $0xc2, %dl # (write)
andb $0x0d, %al # Preserve clock select bits and color bit
orb $0xe2, %al # Set correct sync polarity
outb %al, %dx
popw %dx
movw $0x501e, force_size
stc # That's all.
ret
# Set the 80x34 mode (all VGA's). 480 scans, 14-pixel font.
set_80x34:
call set_80x30 # Set 480 scans
call set14 # And 14-pt font
movw $0xdb12, %ax # VGA vertical display end
movw $0x5022, force_size
setvde: call outidx
stc
ret
# Set the 80x60 mode (all VGA's). 480 scans, 8-pixel font.
set_80x60:
call set_80x30 # Set 480 scans
call set_8pt # And 8-pt font
movw $0xdf12, %ax # VGA vertical display end
movw $0x503c, force_size
jmp setvde
# Special hack for ThinkPad graphics
set_gfx:
#ifdef CONFIG_VIDEO_GFX_HACK
movw $VIDEO_GFX_BIOS_AX, %ax
movw $VIDEO_GFX_BIOS_BX, %bx
int $0x10
movw $VIDEO_GFX_DUMMY_RESOLUTION, force_size
stc
#endif
ret
#ifdef CONFIG_VIDEO_RETAIN
# Store screen contents to temporary buffer.
store_screen:
cmpb $0, do_restore # Already stored?
jnz stsr
testb $CAN_USE_HEAP, loadflags # Have we space for storing?
jz stsr
pushw %ax
pushw %bx
pushw force_size # Don't force specific size
movw $0, force_size
call mode_params # Obtain params of current mode
popw force_size
movb %fs:(PARAM_VIDEO_LINES), %ah
movb %fs:(PARAM_VIDEO_COLS), %al
movw %ax, %bx # BX=dimensions
mulb %ah
movw %ax, %cx # CX=number of characters
addw %ax, %ax # Calculate image size
addw $modelist+1024+4, %ax
cmpw heap_end_ptr, %ax
jnc sts1 # Unfortunately, out of memory
movw %fs:(PARAM_CURSOR_POS), %ax # Store mode params
leaw modelist+1024, %di
stosw
movw %bx, %ax
stosw
pushw %ds # Store the screen
movw video_segment, %ds
xorw %si, %si
rep
movsw
popw %ds
incb do_restore # Screen will be restored later
sts1: popw %bx
popw %ax
stsr: ret
# Restore screen contents from temporary buffer.
restore_screen:
cmpb $0, do_restore # Has the screen been stored?
jz res1
call mode_params # Get parameters of current mode
movb %fs:(PARAM_VIDEO_LINES), %cl
movb %fs:(PARAM_VIDEO_COLS), %ch
leaw modelist+1024, %si # Screen buffer
lodsw # Set cursor position
movw %ax, %dx
cmpb %cl, %dh
jc res2
movb %cl, %dh
decb %dh
res2: cmpb %ch, %dl
jc res3
movb %ch, %dl
decb %dl
res3: movb $0x02, %ah
movb $0x00, %bh
int $0x10
lodsw # Display size
movb %ah, %dl # DL=number of lines
movb $0, %ah # BX=phys. length of orig. line
movw %ax, %bx
cmpb %cl, %dl # Too many?
jc res4
pushw %ax
movb %dl, %al
subb %cl, %al
mulb %bl
addw %ax, %si
addw %ax, %si
popw %ax
movb %cl, %dl
res4: cmpb %ch, %al # Too wide?
jc res5
movb %ch, %al # AX=width of src. line
res5: movb $0, %cl
xchgb %ch, %cl
movw %cx, %bp # BP=width of dest. line
pushw %es
movw video_segment, %es
xorw %di, %di # Move the data
addw %bx, %bx # Convert BX and BP to _bytes_
addw %bp, %bp
res6: pushw %si
pushw %di
movw %ax, %cx
rep
movsw
popw %di
popw %si
addw %bp, %di
addw %bx, %si
decb %dl
jnz res6
popw %es # Done
res1: ret
#endif /* CONFIG_VIDEO_RETAIN */
# Write to indexed VGA register (AL=index, AH=data, DX=index reg. port)
outidx: outb %al, %dx
pushw %ax
movb %ah, %al
incw %dx
outb %al, %dx
decw %dx
popw %ax
ret
# Build the table of video modes (stored after the setup.S code at the
# `modelist' label. Each video mode record looks like:
# .word MODE-ID (our special mode ID (see above))
# .byte rows (number of rows)
# .byte columns (number of columns)
# Returns address of the end of the table in DI, the end is marked
# with a ASK_VGA ID.
mode_table:
movw mt_end, %di # Already filled?
orw %di, %di
jnz mtab1x
leaw modelist, %di # Store standard modes:
movl $VIDEO_80x25 + 0x50190000, %eax # The 80x25 mode (ALL)
stosl
movb adapter, %al # CGA/MDA/HGA -- no more modes
orb %al, %al
jz mtabe
decb %al
jnz mtabv
movl $VIDEO_8POINT + 0x502b0000, %eax # The 80x43 EGA mode
stosl
jmp mtabe
mtab1x: jmp mtab1
mtabv: leaw vga_modes, %si # All modes for std VGA
movw $vga_modes_end-vga_modes, %cx
rep # I'm unable to use movsw as I don't know how to store a half
movsb # of the expression above to cx without using explicit shr.
cmpb $0, scanning # Mode scan requested?
jz mscan1
call mode_scan
mscan1:
#ifdef CONFIG_VIDEO_LOCAL
call local_modes
#endif /* CONFIG_VIDEO_LOCAL */
#ifdef CONFIG_VIDEO_VESA
call vesa_modes # Detect VESA VGA modes
#endif /* CONFIG_VIDEO_VESA */
#ifdef CONFIG_VIDEO_SVGA
cmpb $0, scanning # Bypass when scanning
jnz mscan2
call svga_modes # Detect SVGA cards & modes
mscan2:
#endif /* CONFIG_VIDEO_SVGA */
mtabe:
#ifdef CONFIG_VIDEO_COMPACT
leaw modelist, %si
movw %di, %dx
movw %si, %di
cmt1: cmpw %dx, %si # Scan all modes
jz cmt2
leaw modelist, %bx # Find in previous entries
movw 2(%si), %cx
cmt3: cmpw %bx, %si
jz cmt4
cmpw 2(%bx), %cx # Found => don't copy this entry
jz cmt5
addw $4, %bx
jmp cmt3
cmt4: movsl # Copy entry
jmp cmt1
cmt5: addw $4, %si # Skip entry
jmp cmt1
cmt2:
#endif /* CONFIG_VIDEO_COMPACT */
movw $ASK_VGA, (%di) # End marker
movw %di, mt_end
mtab1: leaw modelist, %si # SI=mode list, DI=list end
ret0: ret