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 static void store_video_mode(void)
34 struct biosregs ireg
, oreg
;
36 /* N.B.: the saving of the video page here is a bit silly,
37 since we pretty much assume page 0 everywhere. */
40 intcall(0x10, &ireg
, &oreg
);
42 /* Not all BIOSes are clean with respect to the top bit */
43 boot_params
.screen_info
.orig_video_mode
= oreg
.al
& 0x7f;
44 boot_params
.screen_info
.orig_video_page
= oreg
.bh
;
48 * Store the video mode parameters for later usage by the kernel.
49 * This is done by asking the BIOS except for the rows/columns
50 * parameters in the default 80x25 mode -- these are set directly,
51 * because some very obscure BIOSes supply insane values.
53 static void store_mode_params(void)
58 /* For graphics mode, it is up to the mode-setting driver
59 (currently only video-vesa.c) to store the parameters */
63 store_cursor_position();
66 if (boot_params
.screen_info
.orig_video_mode
== 0x07) {
67 /* MDA, HGC, or VGA in monochrome mode */
68 video_segment
= 0xb000;
70 /* CGA, EGA, VGA and so forth */
71 video_segment
= 0xb800;
75 font_size
= rdfs16(0x485); /* Font size, BIOS area */
76 boot_params
.screen_info
.orig_video_points
= font_size
;
79 y
= (adapter
== ADAPTER_CGA
) ? 25 : rdfs8(0x484)+1;
86 boot_params
.screen_info
.orig_video_cols
= x
;
87 boot_params
.screen_info
.orig_video_lines
= y
;
90 static unsigned int get_entry(void)
105 } else if ((key
>= '0' && key
<= '9') ||
106 (key
>= 'A' && key
<= 'Z') ||
107 (key
>= 'a' && key
<= 'z')) {
108 if (len
< sizeof entry_buf
) {
109 entry_buf
[len
++] = key
;
113 } while (key
!= '\r');
117 return VIDEO_CURRENT_MODE
; /* Default */
120 for (i
= 0; i
< len
; i
++) {
122 key
= entry_buf
[i
] | 0x20;
123 v
+= (key
> '9') ? key
-'a'+10 : key
-'0';
129 static void display_menu(void)
131 struct card_info
*card
;
132 struct mode_info
*mi
;
140 for (card
= video_cards
; card
< video_cards_end
; card
++)
141 nmodes
+= card
->nmodes
;
147 for (col
= 0; col
< modes_per_line
; col
++)
148 puts("Mode: Resolution: Type: ");
153 for (card
= video_cards
; card
< video_cards_end
; card
++) {
155 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
157 int visible
= mi
->x
&& mi
->y
;
158 u16 mode_id
= mi
->mode
? mi
->mode
:
162 continue; /* Hidden mode */
165 sprintf(resbuf
, "%dx%d", mi
->y
, mi
->depth
);
167 sprintf(resbuf
, "%d", mi
->y
);
169 printf("%c %03X %4dx%-7s %-6s",
170 ch
, mode_id
, mi
->x
, resbuf
, card
->card_name
);
172 if (col
>= modes_per_line
) {
179 else if (ch
== 'z' || ch
== ' ')
180 ch
= ' '; /* Out of keys... */
189 #define H(x) ((x)-'a'+10)
190 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
192 static unsigned int mode_menu(void)
197 puts("Press <ENTER> to see video modes available, "
198 "<SPACE> to continue, or wait 30 sec\n");
202 key
= getchar_timeout();
203 if (key
== ' ' || key
== 0)
204 return VIDEO_CURRENT_MODE
; /* Default */
207 putchar('\a'); /* Beep! */
214 puts("Enter a video mode or \"scan\" to scan for "
215 "additional modes: ");
224 /* Save screen content to the heap */
225 static struct saved_screen
{
231 static void save_screen(void)
233 /* Should be called after store_mode_params() */
234 saved
.x
= boot_params
.screen_info
.orig_video_cols
;
235 saved
.y
= boot_params
.screen_info
.orig_video_lines
;
236 saved
.curx
= boot_params
.screen_info
.orig_x
;
237 saved
.cury
= boot_params
.screen_info
.orig_y
;
239 if (!heap_free(saved
.x
*saved
.y
*sizeof(u16
)+512))
240 return; /* Not enough heap to save the screen */
242 saved
.data
= GET_HEAP(u16
, saved
.x
*saved
.y
);
244 set_fs(video_segment
);
245 copy_from_fs(saved
.data
, 0, saved
.x
*saved
.y
*sizeof(u16
));
248 static void restore_screen(void)
250 /* Should be called after store_mode_params() */
251 int xs
= boot_params
.screen_info
.orig_video_cols
;
252 int ys
= boot_params
.screen_info
.orig_video_lines
;
255 u16
*src
= saved
.data
;
256 struct biosregs ireg
;
259 return; /* Can't restore onto a graphic mode */
262 return; /* No saved screen contents */
264 /* Restore screen contents */
266 set_fs(video_segment
);
267 for (y
= 0; y
< ys
; y
++) {
271 int copy
= (xs
< saved
.x
) ? xs
: saved
.x
;
272 copy_to_fs(dst
, src
, copy
*sizeof(u16
));
273 dst
+= copy
*sizeof(u16
);
275 npad
= (xs
< saved
.x
) ? 0 : xs
-saved
.x
;
280 /* Writes "npad" blank characters to
281 video_segment:dst and advances dst */
282 asm volatile("pushw %%es ; "
289 : "+D" (dst
), "+c" (npad
)
290 : "bdS" (video_segment
),
294 /* Restore cursor position */
296 ireg
.ah
= 0x02; /* Set cursor position */
297 ireg
.dh
= saved
.cury
;
298 ireg
.dl
= saved
.curx
;
299 intcall(0x10, &ireg
, NULL
);
304 u16 mode
= boot_params
.hdr
.vid_mode
;
319 printf("Undefined video mode number: %x\n", mode
);
322 boot_params
.hdr
.vid_mode
= mode
;