--- qemu/roms/seabios/src/bootsplash.c 2018/04/24 18:27:36 1.1.1.1 +++ qemu/roms/seabios/src/bootsplash.c 2018/04/24 18:36:52 1.1.1.2 @@ -1,6 +1,7 @@ // Option rom scanning code. // // Copyright (C) 2009-2010 coresystems GmbH +// Copyright (C) 2010 Kevin O'Connor // // This file may be distributed under the terms of the GNU LGPLv3 license. @@ -9,33 +10,33 @@ #include "config.h" // CONFIG_* #include "util.h" // dprintf #include "jpeg.h" // splash +#include "biosvar.h" // SET_EBDA +#include "paravirt.h" // romfile_find -/**************************************************************** - * Definitions - ****************************************************************/ /**************************************************************** * VESA structures ****************************************************************/ -struct vesa_info -{ - u8 vesa_signature[4]; +struct vesa_info { + u32 vesa_signature; u16 vesa_version; - u32 oem_string_ptr; + struct segoff_s oem_string_ptr; u8 capabilities[4]; - u32 video_mode_ptr; + struct segoff_s video_mode_ptr; u16 total_memory; u16 oem_software_rev; - u32 oem_vendor_name_ptr; - u32 oem_product_name_ptr; - u32 oem_product_rev_ptr; + struct segoff_s oem_vendor_name_ptr; + struct segoff_s oem_product_name_ptr; + struct segoff_s oem_product_rev_ptr; u8 reserved[222]; u8 oem_data[256]; } PACKED; -struct vesa_mode_info -{ +#define VESA_SIGNATURE 0x41534556 // VESA +#define VBE2_SIGNATURE 0x32454256 // VBE2 + +struct vesa_mode_info { u16 mode_attributes; u8 win_a_attributes; u8 win_b_attributes; @@ -65,198 +66,193 @@ struct vesa_mode_info u8 reserved_mask_size; u8 reserved_mask_pos; u8 direct_color_mode_info; - u32 phys_base_ptr; + void *phys_base_ptr; u32 offscreen_mem_offset; u16 offscreen_mem_size; u8 reserved[206]; } PACKED; + /**************************************************************** * Helper functions ****************************************************************/ +// Call int10 vga handler. +static void +call16_int10(struct bregs *br) +{ + br->flags = F_IF; + start_preempt(); + call16_int(0x10, br); + finish_preempt(); +} + + /**************************************************************** * VGA text / graphics console ****************************************************************/ -static void enable_vga_text_console(void) + +void +enable_vga_console(void) { dprintf(1, "Turning on vga text mode console\n"); struct bregs br; /* Enable VGA text mode */ memset(&br, 0, sizeof(br)); - br.flags = F_IF; br.ax = 0x0003; - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); + call16_int10(&br); + + // Write to screen. + printf("SeaBIOS (version %s)\n\n", VERSION); +} - if (CONFIG_BOOTSPLASH) { - /* Switch back to start of the framebuffer - * (disable "double buffering") - */ +static int +find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info + , int width, int height) +{ + dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height); + u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode_ptr); + for (;; videomodes++) { + u16 videomode = *videomodes; + if (videomode == 0xffff) { + dprintf(1, "Unable to find vesa video mode dimensions %d/%d\n" + , width, height); + return -1; + } + struct bregs br; memset(&br, 0, sizeof(br)); - br.flags = F_IF; - br.ax = 0x4f07; - br.bl = 0x02; - br.ecx = 0; - - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); + br.ax = 0x4f01; + br.cx = (1 << 14) | videomode; + br.di = FLATPTR_TO_OFFSET(mode_info); + br.es = FLATPTR_TO_SEG(mode_info); + call16_int10(&br); + if (br.ax != 0x4f) { + dprintf(1, "get_mode failed.\n"); + continue; + } + if (mode_info->x_resolution != width + || mode_info->y_resolution != height) + continue; + u8 depth = mode_info->bits_per_pixel; + if (depth != 16 && depth != 24 && depth != 32) + continue; + return videomode; } - - // Write to screen. - printf("Starting SeaBIOS (version %s)\n\n", VERSION); } -void enable_vga_console(void) +static int BootsplashActive; + +void +enable_bootsplash(void) { - /* Needs coreboot support for CBFS */ - if (!CONFIG_BOOTSPLASH || !CONFIG_COREBOOT) { - enable_vga_text_console(); + if (!CONFIG_BOOTSPLASH) return; - } + dprintf(3, "Checking for bootsplash\n"); + u32 file = romfile_find("bootsplash.jpg"); + if (!file) + return; + int filesize = romfile_size(file); - struct bregs br; - struct vesa_info *vesa_info; - struct vesa_mode_info *mode_info; - struct jpeg_decdata *decdata; - - vesa_info = malloc_tmphigh(sizeof(*vesa_info)); - mode_info = malloc_tmphigh(sizeof(*mode_info)); - decdata = malloc_tmphigh(sizeof(*decdata)); + u8 *picture = NULL; + u8 *filedata = malloc_tmphigh(filesize); + struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info)); + struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info)); + struct jpeg_decdata *jpeg = jpeg_alloc(); + if (!filedata || !jpeg || !vesa_info || !mode_info) { + warn_noalloc(); + goto done; + } /* Check whether we have a VESA 2.0 compliant BIOS */ memset(vesa_info, 0, sizeof(struct vesa_info)); - memcpy(vesa_info, "VBE2", 4); - + vesa_info->vesa_signature = VBE2_SIGNATURE; + struct bregs br; memset(&br, 0, sizeof(br)); - br.flags = F_IF; br.ax = 0x4f00; br.di = FLATPTR_TO_OFFSET(vesa_info); br.es = FLATPTR_TO_SEG(vesa_info); - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); - - if(strcmp("VESA", (char *)vesa_info) != 0) { + call16_int10(&br); + if (vesa_info->vesa_signature != VESA_SIGNATURE) { dprintf(1,"No VBE2 found.\n"); - goto cleanup; + goto done; } /* Print some debugging information about our card. */ - char *vendor, *product; - vendor = (char *)(((vesa_info->oem_vendor_name_ptr & 0xffff0000) >> 12) | - (vesa_info->oem_vendor_name_ptr & 0xffff)); - - product = (char *)(((vesa_info->oem_product_name_ptr & 0xffff0000) >> 12) | - (vesa_info->oem_product_name_ptr & 0xffff)); - - dprintf(8, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n", - vesa_info->vesa_version>>8,vesa_info->vesa_version&0xff, - vendor, product); - - /* Get information about our graphics mode, like the - * framebuffer start address - */ - memset(&br, 0, sizeof(br)); - br.flags = F_IF; - br.ax = 0x4f01; - br.cx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE; - br.di = FLATPTR_TO_OFFSET(mode_info); - br.es = FLATPTR_TO_SEG(mode_info); - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); - if (br.ax != 0x4f) { - dprintf(1, "get_mode failed.\n"); - enable_vga_text_console(); - goto cleanup; - } - unsigned char *framebuffer = (unsigned char *) (mode_info->phys_base_ptr); - - /* Switch to graphics mode */ - memset(&br, 0, sizeof(br)); - br.flags = F_IF; - br.ax = 0x4f02; - br.bx = (1 << 14) | CONFIG_BOOTSPLASH_VESA_MODE; - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); - if (br.ax != 0x4f) { - dprintf(1, "set_mode failed.\n"); - enable_vga_text_console(); - goto cleanup; + char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr); + char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr); + dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n", + vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff, + vendor, product); + + // Parse jpeg and get image size. + dprintf(5, "Copying bootsplash.jpg\n"); + romfile_copy(file, filedata, filesize); + dprintf(5, "Decoding bootsplash.jpg\n"); + int ret = jpeg_decode(jpeg, filedata); + if (ret) { + dprintf(1, "jpeg_decode failed with return code %d...\n", ret); + goto done; } + int width, height; + jpeg_get_size(jpeg, &width, &height); - /* Switching Intel IGD to 1MB video memory will break this. Who cares. */ - int imagesize = CONFIG_BOOTSPLASH_X * CONFIG_BOOTSPLASH_Y * - (CONFIG_BOOTSPLASH_DEPTH / 8); - - /* We use "double buffering" to make things look nicer */ - framebuffer += imagesize; - - dprintf(9, "framebuffer: %x\n", (u32)framebuffer); - dprintf(9, "bytes per scanline: %d\n", mode_info->bytes_per_scanline); - dprintf(9, "bits per pixel: %d\n", mode_info->bits_per_pixel); - - /* Look for bootsplash.jpg in CBFS and decompress it... */ - int ret = 0; - unsigned char *jpeg = NULL; - - struct cbfs_file *file = cbfs_finddatafile("bootsplash.jpg"); - int filesize = 0; - - if (file) { - filesize = cbfs_datasize(file); - jpeg = malloc_tmphigh(filesize); - } else { - dprintf(1, "Could not find boot splash screen \"bootsplash.jpg\"\n"); + // Try to find a graphics mode with the corresponding dimensions. + int videomode = find_videomode(vesa_info, mode_info, width, height); + if (videomode < 0) + goto done; + void *framebuffer = mode_info->phys_base_ptr; + int depth = mode_info->bits_per_pixel; + dprintf(3, "mode: %04x\n", videomode); + dprintf(3, "framebuffer: %p\n", framebuffer); + dprintf(3, "bytes per scanline: %d\n", mode_info->bytes_per_scanline); + dprintf(3, "bits per pixel: %d\n", depth); + + // Allocate space for image and decompress it. + int imagesize = width * height * (depth / 8); + picture = malloc_tmphigh(imagesize); + if (!picture) { + warn_noalloc(); + goto done; } - if(jpeg) { - dprintf(9, "Copying boot splash screen...\n"); - cbfs_copyfile(file, jpeg, filesize); - dprintf(9, "Decompressing boot splash screen...\n"); - start_preempt(); - ret = jpeg_decode(jpeg, framebuffer, CONFIG_BOOTSPLASH_X, - CONFIG_BOOTSPLASH_Y, CONFIG_BOOTSPLASH_DEPTH, decdata); - finish_preempt(); - if (ret) - dprintf(1, "Failed with return code %x...\n", ret); - } else { - ret = -1; - } - free(jpeg); + dprintf(5, "Decompressing bootsplash.jpg\n"); + ret = jpeg_show(jpeg, picture, width, height, depth); if (ret) { - enable_vga_text_console(); - goto cleanup; + dprintf(1, "jpeg_show failed with return code %d...\n", ret); + goto done; } - /* Show the picture */ + /* Switch to graphics mode */ + dprintf(5, "Switching to graphics mode\n"); memset(&br, 0, sizeof(br)); - br.flags = F_IF; - br.ax = 0x4f07; - br.bl = 0x02; - br.ecx = imagesize; - start_preempt(); - call16_int(0x10, &br); - finish_preempt(); + br.ax = 0x4f02; + br.bx = (1 << 14) | videomode; + call16_int10(&br); if (br.ax != 0x4f) { - dprintf(1, "display_start failed.\n"); - enable_vga_text_console(); + dprintf(1, "set_mode failed.\n"); + goto done; } -cleanup: - free (vesa_info); - free (mode_info); - free (decdata); + /* Show the picture */ + dprintf(5, "Showing bootsplash.jpg\n"); + iomemcpy(framebuffer, picture, imagesize); + dprintf(5, "Bootsplash copy complete\n"); + BootsplashActive = 1; + +done: + free(filedata); + free(picture); + free(vesa_info); + free(mode_info); + free(jpeg); + return; } void disable_bootsplash(void) { - if (! CONFIG_BOOTSPLASH) + if (!CONFIG_BOOTSPLASH || !BootsplashActive) return; - enable_vga_text_console(); + BootsplashActive = 0; + enable_vga_console(); }