Merge bootsplash and VGA ROM vbe structure definitions

Signed-off-by: Julian Pidancet <julian.pidancet@gmail.com>
diff --git a/src/bootsplash.c b/src/bootsplash.c
index 9c33b80..76b72c1 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -12,68 +12,10 @@
 #include "jpeg.h" // splash
 #include "biosvar.h" // SET_EBDA
 #include "paravirt.h" // romfile_find
+#include "vbe.h" // struct vbe_info
 #include "bmp.h"
 
 /****************************************************************
- * VESA structures
- ****************************************************************/
-
-struct vesa_info {
-    u32 vesa_signature;
-    u16 vesa_version;
-    struct segoff_s oem_string_ptr;
-    u8 capabilities[4];
-    struct segoff_s video_mode_ptr;
-    u16 total_memory;
-    u16 oem_software_rev;
-    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;
-
-#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;
-    u16 win_granularity;
-    u16 win_size;
-    u16 win_a_segment;
-    u16 win_b_segment;
-    u32 win_func_ptr;
-    u16 bytes_per_scanline;
-    u16 x_resolution;
-    u16 y_resolution;
-    u8 x_charsize;
-    u8 y_charsize;
-    u8 number_of_planes;
-    u8 bits_per_pixel;
-    u8 number_of_banks;
-    u8 memory_model;
-    u8 bank_size;
-    u8 number_of_image_pages;
-    u8 reserved_page;
-    u8 red_mask_size;
-    u8 red_mask_pos;
-    u8 green_mask_size;
-    u8 green_mask_pos;
-    u8 blue_mask_size;
-    u8 blue_mask_pos;
-    u8 reserved_mask_size;
-    u8 reserved_mask_pos;
-    u8 direct_color_mode_info;
-    void *phys_base_ptr;
-    u32 offscreen_mem_offset;
-    u16 offscreen_mem_size;
-    u8 reserved[206];
-} PACKED;
-
-
-/****************************************************************
  * Helper functions
  ****************************************************************/
 
@@ -108,11 +50,11 @@
 }
 
 static int
-find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info
+find_videomode(struct vbe_info *vesa_info, struct vbe_mode_info *mode_info
                , int width, int height, int bpp_req)
 {
     dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height);
-    u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode_ptr);
+    u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode);
     for (;; videomodes++) {
         u16 videomode = *videomodes;
         if (videomode == 0xffff) {
@@ -131,8 +73,8 @@
             dprintf(1, "get_mode failed.\n");
             continue;
         }
-        if (mode_info->x_resolution != width
-            || mode_info->y_resolution != height)
+        if (mode_info->xres != width
+            || mode_info->yres != height)
             continue;
         u8 depth = mode_info->bits_per_pixel;
         if (bpp_req == 0) {
@@ -169,32 +111,32 @@
     u8 *picture = NULL; /* data buff used to be flushed to the video buf */
     struct jpeg_decdata *jpeg = NULL;
     struct bmp_decdata *bmp = NULL;
-    struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
-    struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
+    struct vbe_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
+    struct vbe_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
     if (!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));
-    vesa_info->vesa_signature = VBE2_SIGNATURE;
+    memset(vesa_info, 0, sizeof(struct vbe_info));
+    vesa_info->signature = VBE2_SIGNATURE;
     struct bregs br;
     memset(&br, 0, sizeof(br));
     br.ax = 0x4f00;
     br.di = FLATPTR_TO_OFFSET(vesa_info);
     br.es = FLATPTR_TO_SEG(vesa_info);
     call16_int10(&br);
-    if (vesa_info->vesa_signature != VESA_SIGNATURE) {
+    if (vesa_info->signature != VESA_SIGNATURE) {
         dprintf(1,"No VBE2 found.\n");
         goto done;
     }
 
     /* Print some debugging information about our card. */
-    char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_name_ptr);
-    char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr);
+    char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_string);
+    char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_string);
     dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n",
-            vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
+            vesa_info->version>>8, vesa_info->version&0xff,
             vendor, product);
 
     int ret, width, height;
@@ -239,7 +181,7 @@
                     width, height, bpp_require);
         goto done;
     }
-    void *framebuffer = mode_info->phys_base_ptr;
+    void *framebuffer = (void *)mode_info->phys_base;
     int depth = mode_info->bits_per_pixel;
     dprintf(3, "mode: %04x\n", videomode);
     dprintf(3, "framebuffer: %p\n", framebuffer);
diff --git a/src/vbe.h b/src/vbe.h
new file mode 100644
index 0000000..bfcd6b4
--- /dev/null
+++ b/src/vbe.h
@@ -0,0 +1,157 @@
+#ifndef __VBE_H
+#define __VBE_H
+
+#include "types.h" // u8
+#include "farptr.h" // struct segoff_s
+
+#define VESA_SIGNATURE 0x41534556 // VESA
+#define VBE2_SIGNATURE 0x32454256 // VBE2
+
+struct vbe_info {
+    u32 signature;
+    u16 version;
+    struct segoff_s oem_string;
+    u8 capabilities[4];
+    struct segoff_s video_mode;
+    u16 total_memory;
+    u16 oem_revision;
+    struct segoff_s oem_vendor_string;
+    struct segoff_s oem_product_string;
+    struct segoff_s oem_revision_string;
+    u8 reserved[222];
+} PACKED;
+
+struct vbe_mode_info {
+    /* VBE */
+    u16 mode_attributes;
+    u8 winA_attributes;
+    u8 winB_attributes;
+    u16 win_granularity;
+    u16 win_size;
+    u16 winA_seg;
+    u16 winB_seg;
+    u32 win_func_ptr;
+    u16 bytes_per_scanline;
+    /* VBE 1.2 */
+    u16 xres;
+    u16 yres;
+    u8 xcharsize;
+    u8 ycharsize;
+    u8 planes;
+    u8 bits_per_pixel;
+    u8 banks;
+    u8 mem_model;
+    u8 bank_size;
+    u8 pages;
+    u8 reserved0;
+    /* Direct Color */
+    u8 red_size;
+    u8 red_pos;
+    u8 green_size;
+    u8 green_pos;
+    u8 blue_size;
+    u8 blue_pos;
+    u8 alpha_size;
+    u8 alpha_pos;
+    u8 directcolor_info;
+    /* VBE 2.0 */
+    u32 phys_base;
+    u32 reserved1;
+    u16 reserved2;
+    /* VBE 3.0 */
+    u16 linear_bytes_per_scanline;
+    u8 bank_pages;
+    u8 linear_pages;
+    u8 linear_red_size;
+    u8 linear_red_pos;
+    u8 linear_green_size;
+    u8 linear_green_pos;
+    u8 linear_blue_size;
+    u8 linear_blue_pos;
+    u8 linear_alpha_size;
+    u8 linear_alpha_pos;
+    u32 pixclock_max;
+    u8 reserved[189];
+} PACKED;
+
+struct vbe_crtc_info {
+    u16 horiz_total;
+    u16 horiz_sync_start;
+    u16 horiz_sync_end;
+    u16 vert_total;
+    u16 vert_sync_start;
+    u16 vert_sync_end;
+    u8 flags;
+    u32 pixclock;
+    u16 refresh_rate;
+    u8 reserved[40];
+} PACKED;
+
+/* VBE Return Status Info */
+/* AL */
+#define VBE_RETURN_STATUS_SUPPORTED                      0x4F
+#define VBE_RETURN_STATUS_UNSUPPORTED                    0x00
+/* AH */
+#define VBE_RETURN_STATUS_SUCCESSFULL                    0x00
+#define VBE_RETURN_STATUS_FAILED                         0x01
+#define VBE_RETURN_STATUS_NOT_SUPPORTED                  0x02
+#define VBE_RETURN_STATUS_INVALID                        0x03
+
+/* VBE Mode Numbers */
+
+#define VBE_MODE_VESA_DEFINED                            0x0100
+#define VBE_MODE_REFRESH_RATE_USE_CRTC                   0x0800
+#define VBE_MODE_LINEAR_FRAME_BUFFER                     0x4000
+#define VBE_MODE_PRESERVE_DISPLAY_MEMORY                 0x8000
+
+#define VBE_VESA_MODE_END_OF_LIST                        0xFFFF
+
+/* Capabilities */
+
+#define VBE_CAPABILITY_8BIT_DAC                          0x0001
+#define VBE_CAPABILITY_NOT_VGA_COMPATIBLE                0x0002
+#define VBE_CAPABILITY_RAMDAC_USE_BLANK_BIT              0x0004
+#define VBE_CAPABILITY_STEREOSCOPIC_SUPPORT              0x0008
+#define VBE_CAPABILITY_STEREO_VIA_VESA_EVC               0x0010
+
+/* Mode Attributes */
+
+#define VBE_MODE_ATTRIBUTE_SUPPORTED                     0x0001
+#define VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE  0x0002
+#define VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT              0x0004
+#define VBE_MODE_ATTRIBUTE_COLOR_MODE                    0x0008
+#define VBE_MODE_ATTRIBUTE_GRAPHICS_MODE                 0x0010
+#define VBE_MODE_ATTRIBUTE_NOT_VGA_COMPATIBLE            0x0020
+#define VBE_MODE_ATTRIBUTE_NO_VGA_COMPATIBLE_WINDOW      0x0040
+#define VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE      0x0080
+#define VBE_MODE_ATTRIBUTE_DOUBLE_SCAN_MODE              0x0100
+#define VBE_MODE_ATTRIBUTE_INTERLACE_MODE                0x0200
+#define VBE_MODE_ATTRIBUTE_HARDWARE_TRIPLE_BUFFER        0x0400
+#define VBE_MODE_ATTRIBUTE_HARDWARE_STEREOSCOPIC_DISPLAY 0x0800
+#define VBE_MODE_ATTRIBUTE_DUAL_DISPLAY_START_ADDRESS    0x1000
+
+#define VBE_MODE_ATTTRIBUTE_LFB_ONLY                     ( VBE_MODE_ATTRIBUTE_NO_VGA_COMPATIBLE_WINDOW | VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE )
+
+/* Window attributes */
+
+#define VBE_WINDOW_ATTRIBUTE_RELOCATABLE                 0x01
+#define VBE_WINDOW_ATTRIBUTE_READABLE                    0x02
+#define VBE_WINDOW_ATTRIBUTE_WRITEABLE                   0x04
+
+/* Memory model */
+
+#define VBE_MEMORYMODEL_TEXT_MODE                        0x00
+#define VBE_MEMORYMODEL_CGA_GRAPHICS                     0x01
+#define VBE_MEMORYMODEL_HERCULES_GRAPHICS                0x02
+#define VBE_MEMORYMODEL_PLANAR                           0x03
+#define VBE_MEMORYMODEL_PACKED_PIXEL                     0x04
+#define VBE_MEMORYMODEL_NON_CHAIN_4_256                  0x05
+#define VBE_MEMORYMODEL_DIRECT_COLOR                     0x06
+#define VBE_MEMORYMODEL_YUV                              0x07
+
+/* DirectColorModeInfo */
+
+#define VBE_DIRECTCOLOR_COLOR_RAMP_PROGRAMMABLE          0x01
+#define VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE          0x02
+
+#endif