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 u16 video_segment
;
22 static void store_cursor_position(void)
24 struct biosregs ireg
, oreg
;
28 intcall(0x10, &ireg
, &oreg
);
30 boot_params
.screen_info
.orig_x
= oreg
.dl
;
31 boot_params
.screen_info
.orig_y
= oreg
.dh
;
34 boot_params
.screen_info
.flags
|= VIDEO_FLAGS_NOCURSOR
;
36 if ((oreg
.ch
& 0x1f) > (oreg
.cl
& 0x1f))
37 boot_params
.screen_info
.flags
|= VIDEO_FLAGS_NOCURSOR
;
40 static void store_video_mode(void)
42 struct biosregs ireg
, oreg
;
44 /* N.B.: the saving of the video page here is a bit silly,
45 since we pretty much assume page 0 everywhere. */
48 intcall(0x10, &ireg
, &oreg
);
50 /* Not all BIOSes are clean with respect to the top bit */
51 boot_params
.screen_info
.orig_video_mode
= oreg
.al
& 0x7f;
52 boot_params
.screen_info
.orig_video_page
= oreg
.bh
;
56 * Store the video mode parameters for later usage by the kernel.
57 * This is done by asking the BIOS except for the rows/columns
58 * parameters in the default 80x25 mode -- these are set directly,
59 * because some very obscure BIOSes supply insane values.
61 static void store_mode_params(void)
66 /* For graphics mode, it is up to the mode-setting driver
67 (currently only video-vesa.c) to store the parameters */
71 store_cursor_position();
74 if (boot_params
.screen_info
.orig_video_mode
== 0x07) {
75 /* MDA, HGC, or VGA in monochrome mode */
76 video_segment
= 0xb000;
78 /* CGA, EGA, VGA and so forth */
79 video_segment
= 0xb800;
83 font_size
= rdfs16(0x485); /* Font size, BIOS area */
84 boot_params
.screen_info
.orig_video_points
= font_size
;
87 y
= (adapter
== ADAPTER_CGA
) ? 25 : rdfs8(0x484)+1;
94 boot_params
.screen_info
.orig_video_cols
= x
;
95 boot_params
.screen_info
.orig_video_lines
= y
;
98 static unsigned int get_entry(void)
113 } else if ((key
>= '0' && key
<= '9') ||
114 (key
>= 'A' && key
<= 'Z') ||
115 (key
>= 'a' && key
<= 'z')) {
116 if (len
< sizeof entry_buf
) {
117 entry_buf
[len
++] = key
;
121 } while (key
!= '\r');
125 return VIDEO_CURRENT_MODE
; /* Default */
128 for (i
= 0; i
< len
; i
++) {
130 key
= entry_buf
[i
] | 0x20;
131 v
+= (key
> '9') ? key
-'a'+10 : key
-'0';
137 static void display_menu(void)
139 struct card_info
*card
;
140 struct mode_info
*mi
;
148 for (card
= video_cards
; card
< video_cards_end
; card
++)
149 nmodes
+= card
->nmodes
;
155 for (col
= 0; col
< modes_per_line
; col
++)
156 puts("Mode: Resolution: Type: ");
161 for (card
= video_cards
; card
< video_cards_end
; card
++) {
163 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
165 int visible
= mi
->x
&& mi
->y
;
166 u16 mode_id
= mi
->mode
? mi
->mode
:
170 continue; /* Hidden mode */
173 sprintf(resbuf
, "%dx%d", mi
->y
, mi
->depth
);
175 sprintf(resbuf
, "%d", mi
->y
);
177 printf("%c %03X %4dx%-7s %-6s",
178 ch
, mode_id
, mi
->x
, resbuf
, card
->card_name
);
180 if (col
>= modes_per_line
) {
187 else if (ch
== 'z' || ch
== ' ')
188 ch
= ' '; /* Out of keys... */
197 #define H(x) ((x)-'a'+10)
198 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
200 static unsigned int mode_menu(void)
205 puts("Press <ENTER> to see video modes available, "
206 "<SPACE> to continue, or wait 30 sec\n");
210 key
= getchar_timeout();
211 if (key
== ' ' || key
== 0)
212 return VIDEO_CURRENT_MODE
; /* Default */
215 putchar('\a'); /* Beep! */
222 puts("Enter a video mode or \"scan\" to scan for "
223 "additional modes: ");
232 /* Save screen content to the heap */
233 static struct saved_screen
{
239 static void save_screen(void)
241 /* Should be called after store_mode_params() */
242 saved
.x
= boot_params
.screen_info
.orig_video_cols
;
243 saved
.y
= boot_params
.screen_info
.orig_video_lines
;
244 saved
.curx
= boot_params
.screen_info
.orig_x
;
245 saved
.cury
= boot_params
.screen_info
.orig_y
;
247 if (!heap_free(saved
.x
*saved
.y
*sizeof(u16
)+512))
248 return; /* Not enough heap to save the screen */
250 saved
.data
= GET_HEAP(u16
, saved
.x
*saved
.y
);
252 set_fs(video_segment
);
253 copy_from_fs(saved
.data
, 0, saved
.x
*saved
.y
*sizeof(u16
));
256 static void restore_screen(void)
258 /* Should be called after store_mode_params() */
259 int xs
= boot_params
.screen_info
.orig_video_cols
;
260 int ys
= boot_params
.screen_info
.orig_video_lines
;
263 u16
*src
= saved
.data
;
264 struct biosregs ireg
;
267 return; /* Can't restore onto a graphic mode */
270 return; /* No saved screen contents */
272 /* Restore screen contents */
274 set_fs(video_segment
);
275 for (y
= 0; y
< ys
; y
++) {
279 int copy
= (xs
< saved
.x
) ? xs
: saved
.x
;
280 copy_to_fs(dst
, src
, copy
*sizeof(u16
));
281 dst
+= copy
*sizeof(u16
);
283 npad
= (xs
< saved
.x
) ? 0 : xs
-saved
.x
;
288 /* Writes "npad" blank characters to
289 video_segment:dst and advances dst */
290 asm volatile("pushw %%es ; "
297 : "+D" (dst
), "+c" (npad
)
298 : "bdS" (video_segment
),
302 /* Restore cursor position */
303 if (saved
.curx
>= xs
)
305 if (saved
.cury
>= ys
)
309 ireg
.ah
= 0x02; /* Set cursor position */
310 ireg
.dh
= saved
.cury
;
311 ireg
.dl
= saved
.curx
;
312 intcall(0x10, &ireg
, NULL
);
314 store_cursor_position();
319 u16 mode
= boot_params
.hdr
.vid_mode
;
334 printf("Undefined video mode number: %x\n", mode
);
337 boot_params
.hdr
.vid_mode
= mode
;