Modules/VESA - Allowed #if-ing out VM8086 use
authorJohn Hodge <[email protected]>
Thu, 26 Dec 2013 08:47:18 +0000 (16:47 +0800)
committerJohn Hodge <[email protected]>
Thu, 26 Dec 2013 08:47:18 +0000 (16:47 +0800)
KernelLand/Modules/Display/VESA/common.h
KernelLand/Modules/Display/VESA/main.c
KernelLand/Modules/Display/VESA/vbe.h [new file with mode: 0644]

index c81fe1a..94fd8e2 100644 (file)
@@ -1,15 +1,28 @@
 /**
+ * Acess2 Kernel VBE Driver
+ * - By John Hodge (thePowersGang)
+ *
+ * common.h
+ * - Driver-internal definitions
  */
 #ifndef _COMMON_H_
 #define _COMMON_H_
 
-// === TYPES ===
-typedef struct sFarPtr
-{
-       Uint16  ofs;
-       Uint16  seg;
-}      tFarPtr;
+#include "vbe.h"
+
+/**
+ * \name Mode Flags
+ * \{
+ */
+#define        FLAG_LFB        0x01    //!< Framebuffer is a linear framebufer
+#define FLAG_POPULATED 0x02    //!< Mode information is populated
+#define FLAG_VALID     0x04    //!< Mode is valid (usable)
+#define FLAG_GRAPHICS  0x08    //!< Graphics mode
+/**
+ * \}
+ */
 
+// === TYPES ===
 typedef struct sVesa_Mode
 {
        Uint16  code;
@@ -19,65 +32,4 @@ typedef struct sVesa_Mode
        Uint32  fbSize;
        Uint32  framebuffer;
 }      tVesa_Mode;
-
-typedef struct sVesa_CallModeInfo
-{
-       /**
-        * 0 : Mode is supported
-        * 1 : Optional information avaliable (Xres onwards)
-        * 2 : BIOS Output Supported
-        * 3 : Colour Mode?
-        * 4 : Graphics mode?
-        * -- VBE v2.0+
-        * 5 : Mode is not VGA compatible
-        * 6 : Bank switched mode supported
-        * 7 : Linear framebuffer mode supported
-        * 8 : Double-scan mode avaliable
-        */
-       Uint16  attributes;
-       /**
-        * 0 : Window exists
-        * 1 : Window is readable
-        * 2 : Window is writable
-        */
-       Uint8   winA,winB;
-       Uint16  granularity;
-       Uint16  winsize;
-       Uint16  segmentA, segmentB;
-       tFarPtr realFctPtr;
-       Uint16  pitch;  // Bytes per scanline
-
-       Uint16  Xres, Yres;
-       Uint8   Wchar, Ychar, planes, bpp, banks;
-       Uint8   memory_model, bank_size, image_pages;
-       Uint8   reserved0;
-
-       // -- VBE v1.2+
-       Uint8   red_mask, red_position;
-       Uint8   green_mask, green_position;
-       Uint8   blue_mask, blue_position;
-       Uint8   rsv_mask, rsv_position;
-       Uint8   directcolor_attributes;
-
-       // -- VBE v2.0+
-       Uint32  physbase;
-       Uint32  offscreen_ptr;  // Start of offscreen memory
-       Uint16  offscreen_size_kb;      // Size of offscreen memory
-       
-       // -- VBE v3.0
-       Uint16  lfb_pitch;
-       Uint8   image_count_banked;
-       Uint8   image_count_lfb;
-}      tVesa_CallModeInfo;
-
-typedef struct sVesa_CallInfo
-{
-       char            signature[4];           // == "VESA"
-       Uint16  Version;        // == 0x0300 for Vesa 3.0
-       tFarPtr OEMString;      // isa vbeFarPtr
-       Uint8   Capabilities[4];        
-       tFarPtr VideoModes;     // isa vbeParPtr
-       Uint16  TotalMemory;    // as # of 64KB blocks
-}      tVesa_CallInfo;
-
 #endif
index 51c80e1..3422d0e 100644 (file)
@@ -15,9 +15,7 @@
 #include <timers.h>\r
 \r
 // === CONSTANTS ===\r
-#define        FLAG_LFB        0x1\r
-#define FLAG_POPULATED 0x2\r
-#define FLAG_VALID     0x4\r
+#define USE_BIOS       1\r
 #define VESA_DEFAULT_FRAMEBUFFER       (KERNEL_BASE|0xA0000)\r
 #define BLINKING_CURSOR        0\r
 #if BLINKING_CURSOR\r
@@ -83,8 +81,6 @@ bool  gbVesa_DisableBIOSCalls;        // Disables calls to the BIOS
 // === CODE ===\r
 int Vesa_Install(char **Arguments)\r
 {\r
-        int    rv;\r
-\r
        for( int i = 0; Arguments && Arguments[i]; i ++ )\r
        {\r
                if( strcmp(Arguments[i], "nobios") == 0 )\r
@@ -96,13 +92,15 @@ int Vesa_Install(char **Arguments)
                }\r
        }\r
 \r
+       #if USE_BIOS\r
        if( !gbVesa_DisableBIOSCalls )\r
        {\r
                gpVesa_BiosState = VM8086_Init();\r
                \r
-               if( (rv = VBE_int_GetModeList()) )\r
-                       return rv;\r
+               int rv = VBE_int_GetModeList();\r
+               if(rv)  return rv;\r
        }\r
+       #endif\r
                \r
        #if BLINKING_CURSOR\r
        // Create blink timer\r
@@ -116,6 +114,7 @@ int Vesa_Install(char **Arguments)
        return MODULE_ERR_OK;\r
 }\r
 \r
+#if USE_BIOS\r
 int VBE_int_GetModeList(void)\r
 {\r
        tVesa_CallInfo  *info;\r
@@ -174,6 +173,7 @@ int VBE_int_GetModeInfo(Uint16 Code, tFarPtr *BufPtr)
        }\r
        return 0;\r
 }\r
+#endif\r
 \r
 \r
 void VBE_int_FillMode_Int(tVesa_Mode *Mode, const tVesa_CallModeInfo *vbeinfo)\r
@@ -220,8 +220,9 @@ void VBE_int_FillMode_Int(tVesa_Mode *Mode, const tVesa_CallModeInfo *vbeinfo)
        S_LOG(*vbeinfo, image_count_lfb, "%i");\r
        LOG("}");\r
        #endif\r
-\r
+       \r
        Mode->flags = FLAG_POPULATED;\r
+       // Check if this mode is supported by hardware\r
        if( !(vbeinfo->attributes & 1) )\r
        {\r
                #if DEBUG\r
@@ -245,7 +246,7 @@ void VBE_int_FillMode_Int(tVesa_Mode *Mode, const tVesa_CallModeInfo *vbeinfo)
                Mode->bpp = 0;\r
                return ;\r
        case 0x90:\r
-               Mode->flags |= FLAG_LFB;\r
+               Mode->flags |= FLAG_LFB|FLAG_GRAPHICS;\r
                Mode->framebuffer = vbeinfo->physbase;\r
                Mode->fbSize = vbeinfo->Yres*vbeinfo->pitch;\r
                break;\r
@@ -271,6 +272,7 @@ void VBE_int_SetBootMode(Uint16 ModeID, const void *ModeInfo)
 \r
 void Vesa_int_FillModeList(void)\r
 {\r
+       #if USE_BIOS\r
        if( !gbVesaModesChecked && !gbVesa_DisableBIOSCalls )\r
        {\r
                tVesa_CallModeInfo      *modeinfo;\r
@@ -288,6 +290,7 @@ void Vesa_int_FillModeList(void)
                \r
                gbVesaModesChecked = 1;\r
        }\r
+       #endif\r
 }\r
 \r
 /**\r
@@ -295,35 +298,43 @@ void Vesa_int_FillModeList(void)
  */\r
 size_t Vesa_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer, Uint Flags)\r
 {\r
-       // Framebuffer modes - just pass on\r
-       if( gpVesaCurMode->flags & FLAG_LFB )\r
-               return DrvUtil_Video_WriteLFB(&gVesa_BufInfo, Offset, Length, Buffer);\r
-       \r
-       // EGA text mode translation\r
-       switch( gVesa_BufInfo.BufferFormat )\r
+       switch( gpVesaCurMode->flags & (FLAG_LFB|FLAG_GRAPHICS) )\r
        {\r
-       case VIDEO_BUFFMT_TEXT: {\r
-                int    num = Length / sizeof(tVT_Char);\r
-                int    ofs = Offset / sizeof(tVT_Char);\r
-                int    i = 0;\r
-               const tVT_Char  *chars = Buffer;\r
-               Uint16  word;\r
-               \r
-               for( ; num--; i ++, ofs ++)\r
+       case 0:\r
+               // EGA text mode translation\r
+               switch( gVesa_BufInfo.BufferFormat )\r
                {\r
-                       word = VBE_int_GetWord( &chars[i] );\r
-                       ((Uint16*)gVesa_BufInfo.Framebuffer)[ ofs ] = word;\r
+               case VIDEO_BUFFMT_TEXT: {\r
+                        int    num = Length / sizeof(tVT_Char);\r
+                        int    ofs = Offset / sizeof(tVT_Char);\r
+                        int    i = 0;\r
+                       const tVT_Char  *chars = Buffer;\r
+                       \r
+                       for( ; num--; i ++, ofs ++)\r
+                       {\r
+                               Uint16  word = VBE_int_GetWord( &chars[i] );\r
+                               ((Uint16*)gVesa_BufInfo.Framebuffer)[ ofs ] = word;\r
+                       }\r
+                       \r
+                       return Length; }\r
+               case VIDEO_BUFFMT_2DSTREAM:\r
+                       return DrvUtil_Video_2DStream(NULL, Buffer, Length,\r
+                               &gVBE_Text2DFunctions, sizeof(gVBE_Text2DFunctions));\r
+               default:\r
+                       Log_Warning("VBE", "TODO: Alternate modes in EGA text mode");\r
+                       return 0;\r
                }\r
-               \r
-               return Length; }\r
-       case VIDEO_BUFFMT_2DSTREAM:\r
-               return DrvUtil_Video_2DStream(NULL, Buffer, Length,\r
-                       &gVBE_Text2DFunctions, sizeof(gVBE_Text2DFunctions));\r
+               return 0;\r
+       case FLAG_LFB|FLAG_GRAPHICS:\r
+               // Framebuffer modes - use DrvUtil Video\r
+               return DrvUtil_Video_WriteLFB(&gVesa_BufInfo, Offset, Length, Buffer);\r
        default:\r
-               Log_Warning("VBE", "TODO: Alternate modes in EGA text mode");\r
+               Log_Warning("VBE", "TODO: _Write %s%s",\r
+                       (gpVesaCurMode->flags & FLAG_LFB ? "FLAG_LFB" : ""),\r
+                       (gpVesaCurMode->flags & FLAG_GRAPHICS ? "FLAG_GRAPHICS" : "")\r
+                       );\r
                return 0;\r
        }\r
-\r
 }\r
 \r
 const char *csaVESA_IOCtls[] = {DRV_IOCTLNAMES, DRV_VIDEO_IOCTLNAMES, NULL};\r
@@ -394,7 +405,8 @@ int Vesa_Int_SetMode(int mode)
        #endif\r
        \r
        Mutex_Acquire( &glVesa_Lock );\r
-       \r
+\r
+       #if USE_BIOS\r
        if( gbVesa_DisableBIOSCalls )\r
        {\r
                ASSERT(mode == -1);\r
@@ -413,6 +425,9 @@ int Vesa_Int_SetMode(int mode)
 \r
                LOG("Out: AX = %04x", gpVesa_BiosState->AX);\r
        }\r
+       #else\r
+       ASSERT(mode == -1);\r
+       #endif\r
        \r
        // Map Framebuffer\r
        if( gpVesaCurMode )\r
diff --git a/KernelLand/Modules/Display/VESA/vbe.h b/KernelLand/Modules/Display/VESA/vbe.h
new file mode 100644 (file)
index 0000000..ace7496
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Acess2 Kernel VBE Driver
+ * - By John Hodge (thePowersGang)
+ *
+ * vbe.h
+ * - Definitions for VBE structures
+ */
+#ifndef _VBE_H_
+#define _VBE_H_
+
+typedef struct sFarPtr
+{
+       Uint16  ofs;
+       Uint16  seg;
+}      tFarPtr;
+
+typedef struct sVesa_CallModeInfo
+{
+       /**
+        * 0 : Mode is supported
+        * 1 : Optional information avaliable (Xres onwards)
+        * 2 : BIOS Output Supported
+        * 3 : Colour Mode?
+        * 4 : Graphics mode?
+        * -- VBE v2.0+
+        * 5 : Mode is not VGA compatible
+        * 6 : Bank switched mode supported
+        * 7 : Linear framebuffer mode supported
+        * 8 : Double-scan mode avaliable
+        */
+       Uint16  attributes;
+       /**
+        * 0 : Window exists
+        * 1 : Window is readable
+        * 2 : Window is writable
+        */
+       Uint8   winA,winB;
+       Uint16  granularity;
+       Uint16  winsize;
+       Uint16  segmentA, segmentB;
+       tFarPtr realFctPtr;
+       Uint16  pitch;  // Bytes per scanline
+
+       Uint16  Xres, Yres;
+       Uint8   Wchar, Ychar, planes, bpp, banks;
+       Uint8   memory_model, bank_size, image_pages;
+       Uint8   reserved0;
+
+       // -- VBE v1.2+
+       Uint8   red_mask, red_position;
+       Uint8   green_mask, green_position;
+       Uint8   blue_mask, blue_position;
+       Uint8   rsv_mask, rsv_position;
+       Uint8   directcolor_attributes;
+
+       // -- VBE v2.0+
+       Uint32  physbase;
+       Uint32  offscreen_ptr;  // Start of offscreen memory
+       Uint16  offscreen_size_kb;      // Size of offscreen memory
+       
+       // -- VBE v3.0
+       Uint16  lfb_pitch;
+       Uint8   image_count_banked;
+       Uint8   image_count_lfb;
+} PACKED       tVesa_CallModeInfo;
+
+typedef struct sVesa_CallInfo
+{
+       char            signature[4];           // == "VESA"
+       Uint16  Version;        // == 0x0300 for Vesa 3.0
+       tFarPtr OEMString;      // isa vbeFarPtr
+       Uint8   Capabilities[4];        
+       tFarPtr VideoModes;     // isa vbeParPtr
+       Uint16  TotalMemory;    // as # of 64KB blocks
+} PACKED       tVesa_CallInfo;
+
+
+#endif
+

UCC git Repository :: git.ucc.asn.au