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
15 /****************************************************************
17 ****************************************************************/
23 struct segoff_s oem_string_ptr;
25 struct segoff_s video_mode_ptr;
28 struct segoff_s oem_vendor_name_ptr;
29 struct segoff_s oem_product_name_ptr;
30 struct segoff_s oem_product_rev_ptr;
45 u16 bytes_per_scanline;
55 u8 number_of_image_pages;
63 u8 reserved_mask_size;
65 u8 direct_color_mode_info;
67 u32 offscreen_mem_offset;
68 u16 offscreen_mem_size;
72 /****************************************************************
74 ****************************************************************/
76 /****************************************************************
77 * VGA text / graphics console
78 ****************************************************************/
79 static void enable_vga_text_console(void)
81 dprintf(1, "Turning on vga text mode console\n");
84 /* Enable VGA text mode */
85 memset(&br, 0, sizeof(br));
89 call16_int(0x10, &br);
93 printf("Starting SeaBIOS (version %s)\n\n", VERSION);
96 void enable_vga_console(void)
98 struct vesa_info *vesa_info = NULL;
99 struct vesa_mode_info *mode_info = NULL;
100 struct jpeg_decdata *decdata = NULL;
101 u8 *jpeg = NULL, *picture = NULL;
103 /* Needs coreboot support for CBFS */
104 if (!CONFIG_BOOTSPLASH || !CONFIG_COREBOOT)
106 struct cbfs_file *file = cbfs_finddatafile("bootsplash.jpg");
109 int filesize = cbfs_datasize(file);
111 int imagesize = (CONFIG_BOOTSPLASH_X * CONFIG_BOOTSPLASH_Y *
112 (CONFIG_BOOTSPLASH_DEPTH / 8));
113 jpeg = malloc_tmphigh(filesize);
114 picture = malloc_tmphigh(imagesize);
115 vesa_info = malloc_tmplow(sizeof(*vesa_info));
116 mode_info = malloc_tmplow(sizeof(*mode_info));
117 decdata = malloc_tmphigh(sizeof(*decdata));
118 if (!jpeg || !picture || !vesa_info || !mode_info || !decdata) {
123 /* Check whether we have a VESA 2.0 compliant BIOS */
124 memset(vesa_info, 0, sizeof(struct vesa_info));
125 memcpy(vesa_info, "VBE2", 4);
128 memset(&br, 0, sizeof(br));
131 br.di = FLATPTR_TO_OFFSET(vesa_info);
132 br.es = FLATPTR_TO_SEG(vesa_info);
134 call16_int(0x10, &br);
137 if (strcmp("VESA", (char *)vesa_info) != 0) {
138 dprintf(1,"No VBE2 found.\n");
142 /* Print some debugging information about our card. */
143 char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr);
144 char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr);
145 dprintf(8, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
146 vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
149 /* Get information about our graphics mode, like the
150 * framebuffer start address
152 memset(&br, 0, sizeof(br));
155 br.cx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE;
156 br.di = FLATPTR_TO_OFFSET(mode_info);
157 br.es = FLATPTR_TO_SEG(mode_info);
159 call16_int(0x10, &br);
162 dprintf(1, "get_mode failed.\n");
165 unsigned char *framebuffer = (unsigned char *) (mode_info->phys_base_ptr);
167 /* Switch to graphics mode */
168 memset(&br, 0, sizeof(br));
171 br.bx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE;
173 call16_int(0x10, &br);
176 dprintf(1, "set_mode failed.\n");
180 dprintf(8, "framebuffer: %x\n", (u32)framebuffer);
181 dprintf(8, "bytes per scanline: %d\n", mode_info->bytes_per_scanline);
182 dprintf(8, "bits per pixel: %d\n", mode_info->bits_per_pixel);
184 /* Look for bootsplash.jpg in CBFS and decompress it... */
185 dprintf(8, "Copying boot splash screen...\n");
186 cbfs_copyfile(file, jpeg, filesize);
187 dprintf(8, "Decompressing boot splash screen...\n");
188 int ret = jpeg_decode(jpeg, picture, CONFIG_BOOTSPLASH_X,
189 CONFIG_BOOTSPLASH_Y, CONFIG_BOOTSPLASH_DEPTH, decdata);
191 dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
195 /* Show the picture */
196 iomemcpy(framebuffer, picture, imagesize);
206 enable_vga_text_console();
211 disable_bootsplash(void)
213 if (! CONFIG_BOOTSPLASH)
215 enable_vga_text_console();