1 // Option rom scanning code.
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 "farptr.h" // FLATPTR_TO_SEG
10 #include "config.h" // CONFIG_*
11 #include "util.h" // dprintf
12 #include "jpeg.h" // splash
13 #include "biosvar.h" // SET_EBDA
14 #include "paravirt.h" // romfile_find
17 /****************************************************************
19 ****************************************************************/
24 struct segoff_s oem_string_ptr;
26 struct segoff_s video_mode_ptr;
29 struct segoff_s oem_vendor_name_ptr;
30 struct segoff_s oem_product_name_ptr;
31 struct segoff_s oem_product_rev_ptr;
36 #define VESA_SIGNATURE 0x41534556 // VESA
37 #define VBE2_SIGNATURE 0x32454256 // VBE2
39 struct vesa_mode_info {
48 u16 bytes_per_scanline;
58 u8 number_of_image_pages;
66 u8 reserved_mask_size;
68 u8 direct_color_mode_info;
70 u32 offscreen_mem_offset;
71 u16 offscreen_mem_size;
76 /****************************************************************
78 ****************************************************************/
80 // Call int10 vga handler.
82 call16_int10(struct bregs *br)
91 /****************************************************************
92 * VGA text / graphics console
93 ****************************************************************/
96 enable_vga_console(void)
98 dprintf(1, "Turning on vga text mode console\n");
101 /* Enable VGA text mode */
102 memset(&br, 0, sizeof(br));
107 printf("SeaBIOS (version %s)\n\n", VERSION);
111 find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info
112 , int width, int height)
114 dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height);
115 u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode_ptr);
116 for (;; videomodes++) {
117 u16 videomode = *videomodes;
118 if (videomode == 0xffff) {
119 dprintf(1, "Unable to find vesa video mode dimensions %d/%d\n"
124 memset(&br, 0, sizeof(br));
126 br.cx = (1 << 14) | videomode;
127 br.di = FLATPTR_TO_OFFSET(mode_info);
128 br.es = FLATPTR_TO_SEG(mode_info);
131 dprintf(1, "get_mode failed.\n");
134 if (mode_info->x_resolution != width
135 || mode_info->y_resolution != height)
137 u8 depth = mode_info->bits_per_pixel;
138 if (depth != 16 && depth != 24 && depth != 32)
144 static int BootsplashActive;
147 enable_bootsplash(void)
149 if (!CONFIG_BOOTSPLASH)
151 dprintf(3, "Checking for bootsplash\n");
153 u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize);
158 struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
159 struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
160 struct jpeg_decdata *jpeg = jpeg_alloc();
161 if (!jpeg || !vesa_info || !mode_info) {
166 /* Check whether we have a VESA 2.0 compliant BIOS */
167 memset(vesa_info, 0, sizeof(struct vesa_info));
168 vesa_info->vesa_signature = VBE2_SIGNATURE;
170 memset(&br, 0, sizeof(br));
172 br.di = FLATPTR_TO_OFFSET(vesa_info);
173 br.es = FLATPTR_TO_SEG(vesa_info);
175 if (vesa_info->vesa_signature != VESA_SIGNATURE) {
176 dprintf(1,"No VBE2 found.\n");
180 /* Print some debugging information about our card. */
181 char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr);
182 char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr);
183 dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
184 vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
187 // Parse jpeg and get image size.
188 dprintf(5, "Decoding bootsplash.jpg\n");
189 int ret = jpeg_decode(jpeg, filedata);
191 dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
195 jpeg_get_size(jpeg, &width, &height);
197 // Try to find a graphics mode with the corresponding dimensions.
198 int videomode = find_videomode(vesa_info, mode_info, width, height);
201 void *framebuffer = mode_info->phys_base_ptr;
202 int depth = mode_info->bits_per_pixel;
203 dprintf(3, "mode: %04x\n", videomode);
204 dprintf(3, "framebuffer: %p\n", framebuffer);
205 dprintf(3, "bytes per scanline: %d\n", mode_info->bytes_per_scanline);
206 dprintf(3, "bits per pixel: %d\n", depth);
208 // Allocate space for image and decompress it.
209 int imagesize = width * height * (depth / 8);
210 picture = malloc_tmphigh(imagesize);
215 dprintf(5, "Decompressing bootsplash.jpg\n");
216 ret = jpeg_show(jpeg, picture, width, height, depth);
218 dprintf(1, "jpeg_show failed with return code %d...\n", ret);
222 /* Switch to graphics mode */
223 dprintf(5, "Switching to graphics mode\n");
224 memset(&br, 0, sizeof(br));
226 br.bx = (1 << 14) | videomode;
229 dprintf(1, "set_mode failed.\n");
233 /* Show the picture */
234 dprintf(5, "Showing bootsplash.jpg\n");
235 iomemcpy(framebuffer, picture, imagesize);
236 dprintf(5, "Bootsplash copy complete\n");
237 BootsplashActive = 1;
249 disable_bootsplash(void)
251 if (!CONFIG_BOOTSPLASH || !BootsplashActive)
253 BootsplashActive = 0;
254 enable_vga_console();