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 * ----------------------------------------------------------------------- */
16 #include <uapi/asm/boot.h>
22 static u16 video_segment;
24 static void store_cursor_position(void)
26 struct biosregs ireg, oreg;
30 intcall(0x10, &ireg, &oreg);
32 boot_params.screen_info.orig_x = oreg.dl;
33 boot_params.screen_info.orig_y = oreg.dh;
36 boot_params.screen_info.flags |= VIDEO_FLAGS_NOCURSOR;
38 if ((oreg.ch & 0x1f) > (oreg.cl & 0x1f))
39 boot_params.screen_info.flags |= VIDEO_FLAGS_NOCURSOR;
42 static void store_video_mode(void)
44 struct biosregs ireg, oreg;
46 /* N.B.: the saving of the video page here is a bit silly,
47 since we pretty much assume page 0 everywhere. */
50 intcall(0x10, &ireg, &oreg);
52 /* Not all BIOSes are clean with respect to the top bit */
53 boot_params.screen_info.orig_video_mode = oreg.al & 0x7f;
54 boot_params.screen_info.orig_video_page = oreg.bh;
58 * Store the video mode parameters for later usage by the kernel.
59 * This is done by asking the BIOS except for the rows/columns
60 * parameters in the default 80x25 mode -- these are set directly,
61 * because some very obscure BIOSes supply insane values.
63 static void store_mode_params(void)
68 /* For graphics mode, it is up to the mode-setting driver
69 (currently only video-vesa.c) to store the parameters */
73 store_cursor_position();
76 if (boot_params.screen_info.orig_video_mode == 0x07) {
77 /* MDA, HGC, or VGA in monochrome mode */
78 video_segment = 0xb000;
80 /* CGA, EGA, VGA and so forth */
81 video_segment = 0xb800;
85 font_size = rdfs16(0x485); /* Font size, BIOS area */
86 boot_params.screen_info.orig_video_points = font_size;
89 y = (adapter == ADAPTER_CGA) ? 25 : rdfs8(0x484)+1;
96 boot_params.screen_info.orig_video_cols = x;
97 boot_params.screen_info.orig_video_lines = y;
100 static unsigned int get_entry(void)
115 } else if ((key >= '0' && key <= '9') ||
116 (key >= 'A' && key <= 'Z') ||
117 (key >= 'a' && key <= 'z')) {
118 if (len < sizeof(entry_buf)) {
119 entry_buf[len++] = key;
123 } while (key != '\r');
127 return VIDEO_CURRENT_MODE; /* Default */
130 for (i = 0; i < len; i++) {
132 key = entry_buf[i] | 0x20;
133 v += (key > '9') ? key-'a'+10 : key-'0';
139 static void display_menu(void)
141 struct card_info *card;
142 struct mode_info *mi;
150 for (card = video_cards; card < video_cards_end; card++)
151 nmodes += card->nmodes;
157 for (col = 0; col < modes_per_line; col++)
158 puts("Mode: Resolution: Type: ");
163 for (card = video_cards; card < video_cards_end; card++) {
165 for (i = 0; i < card->nmodes; i++, mi++) {
167 int visible = mi->x && mi->y;
168 u16 mode_id = mi->mode ? mi->mode :
172 continue; /* Hidden mode */
175 sprintf(resbuf, "%dx%d", mi->y, mi->depth);
177 sprintf(resbuf, "%d", mi->y);
179 printf("%c %03X %4dx%-7s %-6s",
180 ch, mode_id, mi->x, resbuf, card->card_name);
182 if (col >= modes_per_line) {
189 else if (ch == 'z' || ch == ' ')
190 ch = ' '; /* Out of keys... */
199 #define H(x) ((x)-'a'+10)
200 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
202 static unsigned int mode_menu(void)
207 puts("Press <ENTER> to see video modes available, "
208 "<SPACE> to continue, or wait 30 sec\n");
212 key = getchar_timeout();
213 if (key == ' ' || key == 0)
214 return VIDEO_CURRENT_MODE; /* Default */
217 putchar('\a'); /* Beep! */
224 puts("Enter a video mode or \"scan\" to scan for "
225 "additional modes: ");
234 /* Save screen content to the heap */
235 static struct saved_screen {
241 static void save_screen(void)
243 /* Should be called after store_mode_params() */
244 saved.x = boot_params.screen_info.orig_video_cols;
245 saved.y = boot_params.screen_info.orig_video_lines;
246 saved.curx = boot_params.screen_info.orig_x;
247 saved.cury = boot_params.screen_info.orig_y;
249 if (!heap_free(saved.x*saved.y*sizeof(u16)+512))
250 return; /* Not enough heap to save the screen */
252 saved.data = GET_HEAP(u16, saved.x*saved.y);
254 set_fs(video_segment);
255 copy_from_fs(saved.data, 0, saved.x*saved.y*sizeof(u16));
258 static void restore_screen(void)
260 /* Should be called after store_mode_params() */
261 int xs = boot_params.screen_info.orig_video_cols;
262 int ys = boot_params.screen_info.orig_video_lines;
265 u16 *src = saved.data;
266 struct biosregs ireg;
269 return; /* Can't restore onto a graphic mode */
272 return; /* No saved screen contents */
274 /* Restore screen contents */
276 set_fs(video_segment);
277 for (y = 0; y < ys; y++) {
281 int copy = (xs < saved.x) ? xs : saved.x;
282 copy_to_fs(dst, src, copy*sizeof(u16));
283 dst += copy*sizeof(u16);
285 npad = (xs < saved.x) ? 0 : xs-saved.x;
290 /* Writes "npad" blank characters to
291 video_segment:dst and advances dst */
292 asm volatile("pushw %%es ; "
299 : "+D" (dst), "+c" (npad)
300 : "bdS" (video_segment),
304 /* Restore cursor position */
305 if (saved.curx >= xs)
307 if (saved.cury >= ys)
311 ireg.ah = 0x02; /* Set cursor position */
312 ireg.dh = saved.cury;
313 ireg.dl = saved.curx;
314 intcall(0x10, &ireg, NULL);
316 store_cursor_position();
321 u16 mode = boot_params.hdr.vid_mode;
336 printf("Undefined video mode number: %x\n", mode);
339 boot_params.hdr.vid_mode = mode;