1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
10 * ----------------------------------------------------------------------- */
20 static void store_cursor_position(void)
22 struct biosregs ireg
, oreg
;
26 intcall(0x10, &ireg
, &oreg
);
28 boot_params
.screen_info
.orig_x
= oreg
.dl
;
29 boot_params
.screen_info
.orig_y
= oreg
.dh
;
32 boot_params
.screen_info
.flags
|= VIDEO_FLAGS_NOCURSOR
;
34 if ((oreg
.ch
& 0x1f) > (oreg
.cl
& 0x1f))
35 boot_params
.screen_info
.flags
|= VIDEO_FLAGS_NOCURSOR
;
38 static void store_video_mode(void)
40 struct biosregs ireg
, oreg
;
42 /* N.B.: the saving of the video page here is a bit silly,
43 since we pretty much assume page 0 everywhere. */
46 intcall(0x10, &ireg
, &oreg
);
48 /* Not all BIOSes are clean with respect to the top bit */
49 boot_params
.screen_info
.orig_video_mode
= oreg
.al
& 0x7f;
50 boot_params
.screen_info
.orig_video_page
= oreg
.bh
;
54 * Store the video mode parameters for later usage by the kernel.
55 * This is done by asking the BIOS except for the rows/columns
56 * parameters in the default 80x25 mode -- these are set directly,
57 * because some very obscure BIOSes supply insane values.
59 static void store_mode_params(void)
64 /* For graphics mode, it is up to the mode-setting driver
65 (currently only video-vesa.c) to store the parameters */
69 store_cursor_position();
72 if (boot_params
.screen_info
.orig_video_mode
== 0x07) {
73 /* MDA, HGC, or VGA in monochrome mode */
74 video_segment
= 0xb000;
76 /* CGA, EGA, VGA and so forth */
77 video_segment
= 0xb800;
81 font_size
= rdfs16(0x485); /* Font size, BIOS area */
82 boot_params
.screen_info
.orig_video_points
= font_size
;
85 y
= (adapter
== ADAPTER_CGA
) ? 25 : rdfs8(0x484)+1;
92 boot_params
.screen_info
.orig_video_cols
= x
;
93 boot_params
.screen_info
.orig_video_lines
= y
;
96 static unsigned int get_entry(void)
111 } else if ((key
>= '0' && key
<= '9') ||
112 (key
>= 'A' && key
<= 'Z') ||
113 (key
>= 'a' && key
<= 'z')) {
114 if (len
< sizeof entry_buf
) {
115 entry_buf
[len
++] = key
;
119 } while (key
!= '\r');
123 return VIDEO_CURRENT_MODE
; /* Default */
126 for (i
= 0; i
< len
; i
++) {
128 key
= entry_buf
[i
] | 0x20;
129 v
+= (key
> '9') ? key
-'a'+10 : key
-'0';
135 static void display_menu(void)
137 struct card_info
*card
;
138 struct mode_info
*mi
;
146 for (card
= video_cards
; card
< video_cards_end
; card
++)
147 nmodes
+= card
->nmodes
;
153 for (col
= 0; col
< modes_per_line
; col
++)
154 puts("Mode: Resolution: Type: ");
159 for (card
= video_cards
; card
< video_cards_end
; card
++) {
161 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
163 int visible
= mi
->x
&& mi
->y
;
164 u16 mode_id
= mi
->mode
? mi
->mode
:
168 continue; /* Hidden mode */
171 sprintf(resbuf
, "%dx%d", mi
->y
, mi
->depth
);
173 sprintf(resbuf
, "%d", mi
->y
);
175 printf("%c %03X %4dx%-7s %-6s",
176 ch
, mode_id
, mi
->x
, resbuf
, card
->card_name
);
178 if (col
>= modes_per_line
) {
185 else if (ch
== 'z' || ch
== ' ')
186 ch
= ' '; /* Out of keys... */
195 #define H(x) ((x)-'a'+10)
196 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
198 static unsigned int mode_menu(void)
203 puts("Press <ENTER> to see video modes available, "
204 "<SPACE> to continue, or wait 30 sec\n");
208 key
= getchar_timeout();
209 if (key
== ' ' || key
== 0)
210 return VIDEO_CURRENT_MODE
; /* Default */
213 putchar('\a'); /* Beep! */
220 puts("Enter a video mode or \"scan\" to scan for "
221 "additional modes: ");
230 /* Save screen content to the heap */
231 static struct saved_screen
{
237 static void save_screen(void)
239 /* Should be called after store_mode_params() */
240 saved
.x
= boot_params
.screen_info
.orig_video_cols
;
241 saved
.y
= boot_params
.screen_info
.orig_video_lines
;
242 saved
.curx
= boot_params
.screen_info
.orig_x
;
243 saved
.cury
= boot_params
.screen_info
.orig_y
;
245 if (!heap_free(saved
.x
*saved
.y
*sizeof(u16
)+512))
246 return; /* Not enough heap to save the screen */
248 saved
.data
= GET_HEAP(u16
, saved
.x
*saved
.y
);
250 set_fs(video_segment
);
251 copy_from_fs(saved
.data
, 0, saved
.x
*saved
.y
*sizeof(u16
));
254 static void restore_screen(void)
256 /* Should be called after store_mode_params() */
257 int xs
= boot_params
.screen_info
.orig_video_cols
;
258 int ys
= boot_params
.screen_info
.orig_video_lines
;
261 u16
*src
= saved
.data
;
262 struct biosregs ireg
;
265 return; /* Can't restore onto a graphic mode */
268 return; /* No saved screen contents */
270 /* Restore screen contents */
272 set_fs(video_segment
);
273 for (y
= 0; y
< ys
; y
++) {
277 int copy
= (xs
< saved
.x
) ? xs
: saved
.x
;
278 copy_to_fs(dst
, src
, copy
*sizeof(u16
));
279 dst
+= copy
*sizeof(u16
);
281 npad
= (xs
< saved
.x
) ? 0 : xs
-saved
.x
;
286 /* Writes "npad" blank characters to
287 video_segment:dst and advances dst */
288 asm volatile("pushw %%es ; "
295 : "+D" (dst
), "+c" (npad
)
296 : "bdS" (video_segment
),
300 /* Restore cursor position */
301 if (saved
.curx
>= xs
)
303 if (saved
.cury
>= ys
)
307 ireg
.ah
= 0x02; /* Set cursor position */
308 ireg
.dh
= saved
.cury
;
309 ireg
.dl
= saved
.curx
;
310 intcall(0x10, &ireg
, NULL
);
312 store_cursor_position();
317 u16 mode
= boot_params
.hdr
.vid_mode
;
332 printf("Undefined video mode number: %x\n", mode
);
335 boot_params
.hdr
.vid_mode
= mode
;