1 // Initialize the VGA console and possibly show a boot splash image.
3 // Copyright (C) 2009-2010 coresystems GmbH
4 // Copyright (C) 2010 Kevin O'Connor <kevin@koconnor.net>
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "bregs.h" // struct bregs
9 #include "config.h" // CONFIG_*
10 #include "farptr.h" // FLATPTR_TO_SEG
11 #include "malloc.h" // free
12 #include "output.h" // dprintf
13 #include "romfile.h" // romfile_loadfile
14 #include "stacks.h" // call16_int
15 #include "std/vbe.h" // struct vbe_info
16 #include "string.h" // memset
17 #include "util.h" // enable_bootsplash
20 /****************************************************************
22 ****************************************************************/
24 // Call int10 vga handler.
26 call16_int10(struct bregs *br)
35 /****************************************************************
36 * VGA text / graphics console
37 ****************************************************************/
40 enable_vga_console(void)
42 dprintf(1, "Turning on vga text mode console\n");
45 /* Enable VGA text mode */
46 memset(&br, 0, sizeof(br));
51 printf("SeaBIOS (version %s)\n", VERSION);
56 find_videomode(struct vbe_info *vesa_info, struct vbe_mode_info *mode_info
57 , int width, int height, int bpp_req)
59 dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height);
60 u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode);
61 for (;; videomodes++) {
62 u16 videomode = *videomodes;
63 if (videomode == 0xffff) {
64 dprintf(1, "Unable to find vesa video mode dimensions %d/%d\n"
69 memset(&br, 0, sizeof(br));
72 br.di = FLATPTR_TO_OFFSET(mode_info);
73 br.es = FLATPTR_TO_SEG(mode_info);
76 dprintf(1, "get_mode failed.\n");
79 if (mode_info->xres != width
80 || mode_info->yres != height)
82 u8 depth = mode_info->bits_per_pixel;
84 if (depth != 16 && depth != 24 && depth != 32)
94 static int BootsplashActive;
97 enable_bootsplash(void)
99 if (!CONFIG_BOOTSPLASH)
101 /* splash picture can be bmp or jpeg file */
102 dprintf(3, "Checking for bootsplash\n");
103 u8 type = 0; /* 0 means jpg, 1 means bmp, default is 0=jpg */
105 u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize);
107 filedata = romfile_loadfile("bootsplash.bmp", &filesize);
112 dprintf(3, "start showing bootsplash\n");
114 u8 *picture = NULL; /* data buff used to be flushed to the video buf */
115 struct jpeg_decdata *jpeg = NULL;
116 struct bmp_decdata *bmp = NULL;
117 struct vbe_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
118 struct vbe_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
119 if (!vesa_info || !mode_info) {
124 /* Check whether we have a VESA 2.0 compliant BIOS */
125 memset(vesa_info, 0, sizeof(struct vbe_info));
126 vesa_info->signature = VBE2_SIGNATURE;
128 memset(&br, 0, sizeof(br));
130 br.di = FLATPTR_TO_OFFSET(vesa_info);
131 br.es = FLATPTR_TO_SEG(vesa_info);
133 if (vesa_info->signature != VESA_SIGNATURE) {
134 dprintf(1,"No VBE2 found.\n");
138 /* Print some debugging information about our card. */
139 char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_string);
140 char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_string);
141 dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
142 vesa_info->version>>8, vesa_info->version&0xff,
145 int ret, width, height;
153 /* Parse jpeg and get image size. */
154 dprintf(5, "Decoding bootsplash.jpg\n");
155 ret = jpeg_decode(jpeg, filedata);
157 dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
160 jpeg_get_size(jpeg, &width, &height);
167 /* Parse bmp and get image size. */
168 dprintf(5, "Decoding bootsplash.bmp\n");
169 ret = bmp_decode(bmp, filedata, filesize);
171 dprintf(1, "bmp_decode failed with return code %d...\n", ret);
174 bmp_get_size(bmp, &width, &height);
177 /* jpeg would use 16 or 24 bpp video mode, BMP use 24bpp mode only */
179 // Try to find a graphics mode with the corresponding dimensions.
180 int videomode = find_videomode(vesa_info, mode_info, width, height,
183 dprintf(1, "failed to find a videomode with %dx%d %dbpp (0=any).\n",
184 width, height, bpp_require);
187 void *framebuffer = (void *)mode_info->phys_base;
188 int depth = mode_info->bits_per_pixel;
189 dprintf(3, "mode: %04x\n", videomode);
190 dprintf(3, "framebuffer: %p\n", framebuffer);
191 dprintf(3, "bytes per scanline: %d\n", mode_info->bytes_per_scanline);
192 dprintf(3, "bits per pixel: %d\n", depth);
194 // Allocate space for image and decompress it.
195 int imagesize = height * mode_info->bytes_per_scanline;
196 picture = malloc_tmphigh(imagesize);
203 dprintf(5, "Decompressing bootsplash.jpg\n");
204 ret = jpeg_show(jpeg, picture, width, height, depth,
205 mode_info->bytes_per_scanline);
207 dprintf(1, "jpeg_show failed with return code %d...\n", ret);
211 dprintf(5, "Decompressing bootsplash.bmp\n");
212 ret = bmp_show(bmp, picture, width, height, depth,
213 mode_info->bytes_per_scanline);
215 dprintf(1, "bmp_show failed with return code %d...\n", ret);
220 /* Switch to graphics mode */
221 dprintf(5, "Switching to graphics mode\n");
222 memset(&br, 0, sizeof(br));
224 br.bx = videomode | VBE_MODE_LINEAR_FRAME_BUFFER;
227 dprintf(1, "set_mode failed.\n");
231 /* Show the picture */
232 dprintf(5, "Showing bootsplash picture\n");
233 iomemcpy(framebuffer, picture, imagesize);
234 dprintf(5, "Bootsplash copy complete\n");
235 BootsplashActive = 1;
248 disable_bootsplash(void)
250 if (!CONFIG_BOOTSPLASH || !BootsplashActive)
252 BootsplashActive = 0;
253 enable_vga_console();