[eros-cvs] cvs commit: eros/src/base/sys/console cons_VESA.cxx

mhilsdale@eros.cs.jhu.edu mhilsdale@eros.cs.jhu.edu
Wed, 22 Aug 2001 19:10:51 -0400


mhilsdale    01/08/22 19:10:51

  Modified:    src/base/sys/arch/i486/mikeboot main.cxx vbe.c
               src/base/sys/console cons_VESA.cxx
  Log:
  Will now automatically choose a video mode number based on preferences and
  actual mode availability.  Once a mode is selected, console will use the
  information that was passed to it from the bootstrap.
  
  Thus, graphical console no longer depends on predefined VMware modes; will
  actually run on a real system as well as under different VMware configs.
  
  Outstanding issue: Will only use graphical console if system supports
  linear framebuffer; otherwise, text console is used instead.  Code can thus
  safely be run on (hopefully) any system.

Revision  Changes    Path
1.7       +3 -2      eros/src/base/sys/arch/i486/mikeboot/main.cxx

Index: main.cxx
===================================================================
RCS file: /cvs/eros/src/base/sys/arch/i486/mikeboot/main.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- main.cxx	2001/08/22 00:24:10	1.6
+++ main.cxx	2001/08/22 23:10:51	1.7
@@ -49,7 +49,7 @@
   int vidmode = GetDisplayMode();
   printf("Video mode is 0x%x\n", vidmode);
 
-  if(!InitVESA())
+  if(InitVESA())
     consoleMode = ChooseVESA();
 
   Interact(bi);
@@ -118,9 +118,10 @@
 
   printf("\nStarting kernel with bi=0x%08x\n", BOOT2PA(bi, BootInfo *)); 
 
+  /* Will set VESA mode, if available; otherwise, do nothing. */
   SetConsoleMode(bi, consoleMode);
 
-#if 0				/* set 1 to use text console */
+#if 0				/* set 1 to force text console */
   SetDisplayMode(vidmode);
   bi->useGraphicsFB = false;
 #endif



1.11      +76 -11    eros/src/base/sys/arch/i486/mikeboot/vbe.c

Index: vbe.c
===================================================================
RCS file: /cvs/eros/src/base/sys/arch/i486/mikeboot/vbe.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- vbe.c	2001/08/22 00:24:10	1.10
+++ vbe.c	2001/08/22 23:10:51	1.11
@@ -35,13 +35,25 @@
 #include "boot-asm.h"
 #include "debug.h"
 
-#define FB_PREF   0              /* Preference to use linear fb (1, default)
+/*************************************************************************/
+
+/* Preferences */
+/* =========== */
+
+#define FB_PREF   1              /* Preference to use linear fb (1, default)
 				  * or windowed fb (0)
 				  * NOTE: This is only a preference.  If the
 				  * prefered fb type is not available, the
 				  * other type will be used.
 				  */
 
+/* Mode Preferences */
+#define maxXpref   1024
+#define maxYpref   768
+#define maxBPPpref 32
+
+/*************************************************************************/
+
 #define MAX_MODES 29             /* Reasonable guess as to max number
 				  * of modes to expect.
 				  */
@@ -241,6 +253,7 @@
 #endif
 void     printVideoModes();
 void     getVideoModes();
+void     printCurrentModeInfo();
 void     getModeInfo(const uint16_t modeNumber);  /* uses assembly magic */
 uint8_t  setMode(const uint16_t modeNumber);      /* uses assembly magic */
 /* Issue: The entire #define mechanism is actually quite
@@ -320,7 +333,7 @@
   if(strcmp(sig,"VESA"))
     {
       printf("Failed!\n\n");
-      return 1;  /* no VESA support */
+      return 0;  /* no VESA support */
     }
   else
     printf("Successful!\n\n");
@@ -328,12 +341,26 @@
   VESAinit = 1; /* VESA is supported and initialized */
   environment = findEnvironment();
 
-  return 0;
+  return 1;
 }
 
 uint32_t
 ChooseVESA()
 {
+  uint8_t a;
+
+  struct {
+    uint16_t mode;
+    uint16_t x;
+    uint16_t y;
+    uint16_t bpp;
+  } best;
+
+  best.mode = 0;
+  best.x = 0;
+  best.y = 0;
+  best.bpp = 0;
+
   if(!VESAinit)
     {
       printf("ERROR: Either VESA was not initialized or is not supported.\nAborting....");
@@ -345,10 +372,46 @@
   /*printVbe3Info();
   waitkbd();*/
   /*testGraphics();*/
+
+  /* Find a suitable mode */
+  for(a = 0; a < numModesSupported; a++)
+    {
+      getModeInfo(modeList[a]);
+      if(modeInfoBlock.XResolution <= maxXpref && modeInfoBlock.XResolution >= best.x)
+	if(modeInfoBlock.YResolution <= maxYpref && modeInfoBlock.YResolution >= best.y)
+	  if(modeInfoBlock.BitsPerPixel <= maxBPPpref && modeInfoBlock.BitsPerPixel >= best.bpp)
+	    {
+	      best.mode = modeList[a];
+	      best.x = modeInfoBlock.XResolution;
+	      best.y = modeInfoBlock.YResolution;
+	      best.bpp = modeInfoBlock.BitsPerPixel;
+	    }
+    }
 
-  /* TODO: add generic mode-choosing logic here */
+  /* FIXME:
+   * If no linfb is available, don't use graphics mode since console doesn't support it. */
+  if(!modeAttributes.linfb)
+    return 0;
+
+  /* DEBUG info: */
+  /*
+  getModeInfo(best.mode);
+  printf("Desired video mode:\n");
+  printf("  X   : %d\n",maxXpref);
+  printf("  Y   : %d\n",maxYpref);
+  printf("  BPP : %d\n\n",maxBPPpref);
+  printf("Best video mode found:\n");
+  printf("  Mode: 0x%x\n",best.mode);
+  printf("  X   : %d\n",best.x);
+  printf("  Y   : %d\n",best.y);
+  printf("  BPP : %d\n\n",best.bpp);
+  printCurrentModeInfo();
+  waitkbd();
+  */
 
-  if(environment == VMWARE)
+  return best.mode;
+
+  /* if(environment == VMWARE)
     {
       setMode(VMWARE_MODE);
       return VMWARE_MODE;
@@ -357,7 +420,7 @@
     {
       AsmSetVgaMode(origMode);
       return origMode;
-    }
+    } */
 }
 
 void
@@ -446,7 +509,6 @@
   printf("OEM Product Name : %s\n", Vbe3InfoBlock.OEMProductNamePtr);
   printf("OEM Product Rev  : %s\n", Vbe3InfoBlock.OEMProductRevPtr);
 }
-#endif
 
 void
 printCapabilities()
@@ -486,6 +548,7 @@
   else
     printf("  No hardware stereoscopic signaling support.\n");
 }
+#endif
 
 void
 printModeAttr(uint16_t attrs)
@@ -629,7 +692,7 @@
 
   memset(&modeInfoBlock, 0, sizeof(modeInfoBlock));
 
-  printf("Getting mode information for mode 0x%x....\n", modeNumber);
+  /*printf("Getting mode information for mode 0x%x....\n", modeNumber);*/
 
   /* do assembly magic here */
   handleReturn(AsmGetVbeModeInfo(modeNumber, &modeInfoBlock));
@@ -1213,18 +1276,20 @@
   ConsoleInfo *ci;
 
   bi->consInfo = ci = BootAlloc(sizeof(ConsoleInfo), sizeof(uint32_t));
-  if(!VESAinit)
+  /* FIXME:
+   * mode == 0 check is here to handle case of windowed modes */
+  if(!VESAinit || mode == 0)
     return;
 
   bi->useGraphicsFB = 1;
-  
+
   getModeInfo(mode);  /* uses assembly magic */
 
   /* populate the ConsoleInfo struct */
   ci->len              = sizeof(ConsoleInfo);
   ci->videoMode        = mode;
   ci->frameBuffer      = modeInfoBlock.PhysBasePtr;
-  ci->Xlimit           = modeInfoBlock.XResolution; /*change?*/
+  ci->Xlimit           = modeInfoBlock.XResolution; /*chVange?*/
   ci->Ylimit           = modeInfoBlock.YResolution; /*change?*/
   ci->winSize          = modeInfoBlock.WinSize;
   ci->bytesPerScanLine = modeInfoBlock.BytesPerScanLine;



1.10      +35 -25    eros/src/base/sys/console/cons_VESA.cxx

Index: cons_VESA.cxx
===================================================================
RCS file: /cvs/eros/src/base/sys/console/cons_VESA.cxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- cons_VESA.cxx	2001/08/22 19:48:32	1.9
+++ cons_VESA.cxx	2001/08/22 23:10:51	1.10
@@ -38,23 +38,23 @@
 #include "oslogo.h"
 #include "logosm.h"
 
+
+#define CURSOR 177 /* hash */
+/*#define CURSOR 1 smiley*/
+#define cursor() Put(CURSOR, col, row)
+
+#ifdef OLD_SCREEN
 /*1024x768x32 = VMware mode 0x4022*/
 #define XRES 1024
 #define YRES 768
 #define BPP  32
 #define BPSL 6400
 #define BASE 0x40151C80;
-
-#define CURSOR 177
-/*#define CURSOR 1*/
-#define cursor() Put(CURSOR, col, row)
-
-#ifdef OLD_SCREEN
 static uint8_t *screen = (uint8_t *) PTOV(0xA0000u);
 
-#define PIX(x, y, c) (*((uint32_t *) (screen + ((uint32_t) (y) * BPSL + (x) * ((BPP + 7) / 8)))) = c)
+#define PIX(x, y, c) (*((uint32_t *) (screen + ((uint32_t) (y) * TheConsVESA.bpsl + (x) * ((TheConsVESA.bpp + 7) / 8)))) = c)
 #else
-#define PIX(x, y, c) (*((uint32_t *) (Machine::frameBuffer + ((uint32_t) (y) * BPSL + (x) * ((BPP + 7) / 8)))) = c)
+#define PIX(x, y, c) (*((uint32_t *) (Machine::frameBuffer + ((uint32_t) (y) * TheConsVESA.bpsl + (x) * ((TheConsVESA.bpp + 7) / 8)))) = c)
 #endif
 
 void drawHeader();
@@ -67,6 +67,13 @@
 struct ConsVESA: public Console {
   /*unsigned long offset;*/
 
+  /* screen information */
+  uint16_t xres;
+  uint16_t yres;
+  uint16_t bpp;
+  uint16_t bpsl;
+  /*uint16_t base;*/
+
   /* 1-based indexing */
   uint8_t col;
   uint8_t row;
@@ -106,19 +113,22 @@
 
   TheConsVESA.baseCol = 1;
   TheConsVESA.baseRow = 1;
-  TheConsVESA.maxCol = XRES/8;
-  TheConsVESA.maxRow = YRES/16;
+  TheConsVESA.maxCol = TheConsVESA.xres/8;
+  TheConsVESA.maxRow = TheConsVESA.yres/16;
 
   /* TheConsVESA.offset = 0; */
   TheConsVESA.col = TheConsVESA.baseCol;
   TheConsVESA.row = TheConsVESA.baseRow;
 
+  /* set the screen parameters */
 #ifdef OLD_SCREEN
-  /* Do something here to set the video mode?... */
-  screen = (unsigned char *) BASE;
-  /* mh: ...that works, for now. */
+  screen = (unsigned char *) TheConsVESA.base;
 #else
   Machine::frameBuffer = BootInfoPtr->consInfo->frameBuffer;
+  TheConsVESA.xres = BootInfoPtr->consInfo->Xlimit;
+  TheConsVESA.yres = BootInfoPtr->consInfo->Ylimit;
+  TheConsVESA.bpp = BootInfoPtr->consInfo->bpp;
+  TheConsVESA.bpsl = BootInfoPtr->consInfo->bytesPerScanLine;
 #endif
 
   TheConsVESA.Clear();
@@ -296,7 +306,7 @@
   animate();
 
   drawLogo(0,0);
-  drawLogo2(XRES-width2,0);
+  drawLogo2(TheConsVESA.xres-width2,0);
 
   /* Define new scren margins */
   TheConsVESA.baseRow = height/16 + 2;
@@ -308,7 +318,7 @@
 redrawLogos()
 {
   drawLogo(0,0);
-  drawLogo2(XRES-width2,0);
+  drawLogo2(TheConsVESA.xres-width2,0);
 }
 
 void
@@ -360,7 +370,7 @@
 #endif
 
   /* left -> right */
-  for (x = 0; x <= XRES - width; x++)
+  for (x = 0; x <= TheConsVESA.xres - width; x++)
     {
       drawLogo(x,0);
       if(x!=0)
@@ -373,40 +383,40 @@
     }
 
   /* top -> bottom */
-  for (y = 0; y <= YRES - height; y++)
+  for (y = 0; y <= TheConsVESA.yres - height; y++)
     {
-      drawLogo(XRES-width,y);
+      drawLogo(TheConsVESA.xres-width,y);
       if(y!=0)
 	{
 	  for(i = 0; i < width; i++)
 	    {
-	      PIX(i+(XRES-width), y-1, (uint32_t) 0);
+	      PIX(i+(TheConsVESA.xres-width), y-1, (uint32_t) 0);
 	    }
 	}
     }
 
   /* right -> left */
-  for (x = 0; x <= XRES - width; x++)
+  for (x = 0; x <= TheConsVESA.xres - width; x++)
     {
-      drawLogo(XRES-width-x,YRES-height);
+      drawLogo(TheConsVESA.xres-width-x,TheConsVESA.yres-height);
       if(x!=0)
 	{
 	  for(j = 0; j < height; j++)
 	    {
-	      PIX(XRES-(x), j+(YRES-height), (uint32_t) 0);
+	      PIX(TheConsVESA.xres-(x), j+(TheConsVESA.yres-height), (uint32_t) 0);
 	    }
 	}
     }
 
   /* bottom -> top */
-  for (y = 0; y <= YRES - height; y++)
+  for (y = 0; y <= TheConsVESA.yres - height; y++)
     {
-      drawLogo(0,YRES-height-y);
+      drawLogo(0,TheConsVESA.yres-height-y);
       if(y!=0)
 	{
 	  for(i = 0; i < width; i++)
 	    {
-	      PIX(i, YRES-(y), (uint32_t) 0);
+	      PIX(i, TheConsVESA.yres-(y), (uint32_t) 0);
 	    }
 	}
     }