]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/x86/boot/video.c
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 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/video.c
21 static void store_cursor_position(void)
29 : "=d" (curpos
), "+a" (ax
), "+b" (bx
)
30 : : "ecx", "esi", "edi");
32 boot_params
.screen_info
.orig_x
= curpos
;
33 boot_params
.screen_info
.orig_y
= curpos
>> 8;
36 static void store_video_mode(void)
40 /* N.B.: the saving of the video page here is a bit silly,
41 since we pretty much assume page 0 everywhere. */
44 : "+a" (ax
), "=b" (page
)
45 : : "ecx", "edx", "esi", "edi");
47 /* Not all BIOSes are clean with respect to the top bit */
48 boot_params
.screen_info
.orig_video_mode
= ax
& 0x7f;
49 boot_params
.screen_info
.orig_video_page
= page
>> 8;
53 * Store the video mode parameters for later usage by the kernel.
54 * This is done by asking the BIOS except for the rows/columns
55 * parameters in the default 80x25 mode -- these are set directly,
56 * because some very obscure BIOSes supply insane values.
58 static void store_mode_params(void)
63 /* For graphics mode, it is up to the mode-setting driver
64 (currently only video-vesa.c) to store the parameters */
68 store_cursor_position();
71 if (boot_params
.screen_info
.orig_video_mode
== 0x07) {
72 /* MDA, HGC, or VGA in monochrome mode */
73 video_segment
= 0xb000;
75 /* CGA, EGA, VGA and so forth */
76 video_segment
= 0xb800;
80 font_size
= rdfs16(0x485); /* Font size, BIOS area */
81 boot_params
.screen_info
.orig_video_points
= font_size
;
84 y
= (adapter
== ADAPTER_CGA
) ? 25 : rdfs8(0x484)+1;
91 boot_params
.screen_info
.orig_video_cols
= x
;
92 boot_params
.screen_info
.orig_video_lines
= y
;
95 static unsigned int get_entry(void)
110 } else if ((key
>= '0' && key
<= '9') ||
111 (key
>= 'A' && key
<= 'Z') ||
112 (key
>= 'a' && key
<= 'z')) {
113 if (len
< sizeof entry_buf
) {
114 entry_buf
[len
++] = key
;
118 } while (key
!= '\r');
122 return VIDEO_CURRENT_MODE
; /* Default */
125 for (i
= 0; i
< len
; i
++) {
127 key
= entry_buf
[i
] | 0x20;
128 v
+= (key
> '9') ? key
-'a'+10 : key
-'0';
134 static void display_menu(void)
136 struct card_info
*card
;
137 struct mode_info
*mi
;
145 for (card
= video_cards
; card
< video_cards_end
; card
++)
146 nmodes
+= card
->nmodes
;
152 for (col
= 0; col
< modes_per_line
; col
++)
153 puts("Mode: Resolution: Type: ");
158 for (card
= video_cards
; card
< video_cards_end
; card
++) {
160 for (i
= 0; i
< card
->nmodes
; i
++, mi
++) {
162 int visible
= mi
->x
&& mi
->y
;
163 u16 mode_id
= mi
->mode
? mi
->mode
:
167 continue; /* Hidden mode */
170 sprintf(resbuf
, "%dx%d", mi
->y
, mi
->depth
);
172 sprintf(resbuf
, "%d", mi
->y
);
174 printf("%c %03X %4dx%-7s %-6s",
175 ch
, mode_id
, mi
->x
, resbuf
, card
->card_name
);
177 if (col
>= modes_per_line
) {
184 else if (ch
== 'z' || ch
== ' ')
185 ch
= ' '; /* Out of keys... */
194 #define H(x) ((x)-'a'+10)
195 #define SCAN ((H('s')<<12)+(H('c')<<8)+(H('a')<<4)+H('n'))
197 static unsigned int mode_menu(void)
202 puts("Press <ENTER> to see video modes available, "
203 "<SPACE> to continue, or wait 30 sec\n");
207 key
= getchar_timeout();
208 if (key
== ' ' || key
== 0)
209 return VIDEO_CURRENT_MODE
; /* Default */
212 putchar('\a'); /* Beep! */
219 puts("Enter a video mode or \"scan\" to scan for "
220 "additional modes: ");
229 #ifdef CONFIG_VIDEO_RETAIN
230 /* Save screen content to the heap */
231 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
;
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 ax
= 0x0200; /* Set cursor position */
302 bx
= 0; /* Page number (<< 8) */
303 dx
= (saved
.cury
<< 8)+saved
.curx
;
305 : "+a" (ax
), "+b" (bx
), "+d" (dx
)
306 : : "ecx", "esi", "edi");
309 #define save_screen() ((void)0)
310 #define restore_screen() ((void)0)
315 u16 mode
= boot_params
.hdr
.vid_mode
;
330 printf("Undefined video mode number: %x\n", mode
);
333 boot_params
.hdr
.vid_mode
= mode
;