1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * This file is part of the Linux kernel, and is made available under
7 * the terms of the GNU General Public License version 2.
9 * ----------------------------------------------------------------------- */
19 static void store_cursor_position(void)
27 : "=d" (curpos), "+a" (ax), "+b" (bx)
28 : : "ecx", "esi", "edi");
30 boot_params.screen_info.orig_x = curpos;
31 boot_params.screen_info.orig_y = curpos >> 8;
34 static void store_video_mode(void)
38 /* N.B.: the saving of the video page here is a bit silly,
39 since we pretty much assume page 0 everywhere. */
42 : "+a" (ax), "=b" (page)
43 : : "ecx", "edx", "esi", "edi");
45 /* Not all BIOSes are clean with respect to the top bit */
46 boot_params.screen_info.orig_video_mode = ax & 0x7f;
47 boot_params.screen_info.orig_video_page = page >> 8;
51 * Store the video mode parameters for later usage by the kernel.
52 * This is done by asking the BIOS except for the rows/columns
53 * parameters in the default 80x25 mode -- these are set directly,
54 * because some very obscure BIOSes supply insane values.
56 static void store_mode_params(void)
61 /* For graphics mode, it is up to the mode-setting driver
62 (currently only video-vesa.c) to store the parameters */
66 store_cursor_position();
69 if (boot_params.screen_info.orig_video_mode == 0x07) {
70 /* MDA, HGC, or VGA in monochrome mode */
71 video_segment = 0xb000;
73 /* CGA, EGA, VGA and so forth */
74 video_segment = 0xb800;
78 font_size = rdfs16(0x485); /* Font size, BIOS area */
79 boot_params.screen_info.orig_video_points = font_size;
82 y = (adapter == ADAPTER_CGA) ? 25 : rdfs8(0x484)+1;
89 boot_params.screen_info.orig_video_cols = x;
90 boot_params.screen_info.orig_video_lines = y;
93 static unsigned int get_entry(void)
108 } else if ((key >= '0' && key <= '9') ||
109 (key >= 'A' && key <= 'Z') ||
110 (key >= 'a' && key <= 'z')) {
111 if (len < sizeof entry_buf) {
112 entry_buf[len++] = key;
116 } while (key != '\r');
120 return VIDEO_CURRENT_MODE; /* Default */
123 for (i = 0; i < len; i++) {
125 key = entry_buf[i] | 0x20;
126 v += (key > '9') ? key-'a'+10 : key-'0';
132 static void display_menu(void)
134 struct card_info *card;
135 struct mode_info *mi;
143 for (card = video_cards; card < video_cards_end; card++)
144 nmodes += card->nmodes;
150 for (col = 0; col < modes_per_line; col++)
151 puts("Mode: Resolution: Type: ");
156 for (card = video_cards; card < video_cards_end; card++) {
158 for (i = 0; i < card->nmodes; i++, mi++) {
160 int visible = mi->x && mi->y;
161 u16 mode_id = mi->mode ? mi->mode :
165 continue; /* Hidden mode */
168 sprintf(resbuf, "%dx%d", mi->y, mi->depth);
170 sprintf(resbuf, "%d", mi->y);
172 printf("%c %03X %4dx%-7s %-6s",
173 ch, mode_id, mi->x, resbuf, card->card_name);
175 if (col >= modes_per_line) {
182 else if (ch == 'z' || ch == ' ')
183 ch = ' '; /* Out of keys... */
192 #define H(x) ((x)-'a'+10)
193 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
195 static unsigned int mode_menu(void)
200 puts("Press <ENTER> to see video modes available, "
201 "<SPACE> to continue, or wait 30 sec\n");
205 key = getchar_timeout();
206 if (key == ' ' || key == 0)
207 return VIDEO_CURRENT_MODE; /* Default */
210 putchar('\a'); /* Beep! */
217 puts("Enter a video mode or \"scan\" to scan for "
218 "additional modes: ");
227 #ifdef CONFIG_VIDEO_RETAIN
228 /* Save screen content to the heap */
229 struct saved_screen {
235 static void save_screen(void)
237 /* Should be called after store_mode_params() */
238 saved.x = boot_params.screen_info.orig_video_cols;
239 saved.y = boot_params.screen_info.orig_video_lines;
240 saved.curx = boot_params.screen_info.orig_x;
241 saved.cury = boot_params.screen_info.orig_y;
243 if (!heap_free(saved.x*saved.y*sizeof(u16)+512))
244 return; /* Not enough heap to save the screen */
246 saved.data = GET_HEAP(u16, saved.x*saved.y);
248 set_fs(video_segment);
249 copy_from_fs(saved.data, 0, saved.x*saved.y*sizeof(u16));
252 static void restore_screen(void)
254 /* Should be called after store_mode_params() */
255 int xs = boot_params.screen_info.orig_video_cols;
256 int ys = boot_params.screen_info.orig_video_lines;
259 u16 *src = saved.data;
263 return; /* Can't restore onto a graphic mode */
266 return; /* No saved screen contents */
268 /* Restore screen contents */
270 set_fs(video_segment);
271 for (y = 0; y < ys; y++) {
275 int copy = (xs < saved.x) ? xs : saved.x;
276 copy_to_fs(dst, src, copy*sizeof(u16));
277 dst += copy*sizeof(u16);
279 npad = (xs < saved.x) ? 0 : xs-saved.x;
284 /* Writes "npad" blank characters to
285 video_segment:dst and advances dst */
286 asm volatile("pushw %%es ; "
293 : "+D" (dst), "+c" (npad)
294 : "bdS" (video_segment),
298 /* Restore cursor position */
299 ax = 0x0200; /* Set cursor position */
300 bx = 0; /* Page number (<< 8) */
301 dx = (saved.cury << 8)+saved.curx;
303 : "+a" (ax), "+b" (bx), "+d" (dx)
304 : : "ecx", "esi", "edi");
307 #define save_screen() ((void)0)
308 #define restore_screen() ((void)0)
313 u16 mode = boot_params.hdr.vid_mode;
328 printf("Undefined video mode number: %x\n", mode);
331 boot_params.hdr.vid_mode = mode;