Hi...

I started making a motherboard independant version of svgalib for alpha
AXP. The problem of current implementations is that you have to compile a
new version for each motherboard type and that newer motherboards like the
164LX and 164UX don't work properly.
Well.. my implementation is still in it's beginnings and the patch I
applied now to this mail is not even a bit cleaned up. It's just the
current q&d state of the art.
As far as my understanding of Alpha AXP architecture is, there are
different types of memory access:

a) Sparse memory. This is a quite old type of memory access. The
framebuffer of a graphics device is not mapped at a single position but
cut into several pieces, like patches.

b) Dense Memory. This allows a "linear framebuffer access". This dense
memory can be accessed in 8/16/32/64 bit accesses on some machines but
only in 32/64 bit aligned accesses on others

Now, there are different kinds of motherboards:

a) Some have only Sparse Memory Architecture. Afaik, this are only "Jensen
   Boards"
b) Some have both, allowing Dense memory access in 8bit accesses as well
   (164LX, Multia)
c) Some have both, allowing Dense memory access only in 32/64 bit accesses
   (164UX)
d) Some (EV6) have only dense memory and only allow 32/64 bit aligned
   access. (dp264)

At the current time only type b) is tested and maybe a) works. c) and d)
still need to be worked on, but that ought to be trivial. (Well I thought,
the whole concept of alpha memory architecture is trivial when I started)

Some of my code is "stolen" from glibc and XFree. Just to mention it.

Regards,
        Stefan Reinauer([EMAIL PROTECTED])           

--
SuSE GmbH                                       Can you afford *NOT*
Schanz�ckerstr. 10                                     to use Linux?
D-90443 N�rnberg                        
Germany                                                 AlphaPowered
--- Makefile
+++ Makefile    1999/02/18 10:02:39
@@ -200,7 +200,7 @@
        @$(INSTALL_DATA) staticlib/libvgagl.a $(libdir)/libvgagl.a
        @chmod a+r $(libdir)/libvgagl.a
 
-installutils: textutils lrmi
+installutils: textutils 
        @if [ ! -d $(bindir) ]; then \
                echo No $(bindir) directory, creating it.; \
                mkdir $(bindir); \
@@ -227,7 +227,6 @@
        @echo "savetextmode:     Script that saves textmode information used by 
'textmode'."
        @cp utils/savetextmode $(bindir)
        @echo "mode3:       Restore textmode by setting VESA mode 3."
-       @cp lrmi-0.5m/mode3 $(bindir)
        @echo "Installing keymap utilities in $(bindir):"
        @echo "svgakeymap:       Perl script that generates scancode conversion maps."
        @cp utils/svgakeymap $(bindir)
@@ -421,7 +420,8 @@
        @rm -f sharedlib/DISTRIBUTION
        (cd $(dir $@); \
         $(MAKE) -f $(srcdir)/src/Makefile $(notdir $@) \
-               srcdir="$(srcdir)" DLLFLAGS="$(DLLFLAGS)" \
+               srcdir="$(srcdir)" DLLFLAGS="$(DLLFLAGS)"; \
+       ln -sf libvga.so.$(VERSION) libvga.so \
        )
 
 endif  # a.out
@@ -429,7 +429,8 @@
 sharedlib/libvgagl.a sharedlib/libvgagl.so.$(VERSION): $(SHAREDDIRS)
        (cd $(dir $@); \
         $(MAKE) -f $(srcdir)/gl/Makefile $(notdir $@) \
-               srcdir="$(srcdir)" DLLFLAGS="$(DLLFLAGS)" \
+               srcdir="$(srcdir)" DLLFLAGS="$(DLLFLAGS)"; \
+       ln -sf libvgagl.so.$(VERSION) libvgagl.so \
        )
 
 demoprogs: $(PREDEMO) $(DEMODIRS)
--- Makefile.cfg
+++ Makefile.cfg        1999/02/18 14:12:02
@@ -85,7 +85,7 @@
 ONE_MAP = y
 
 # Uncomment this if you want to compile and install the static libs.
-# INSTALLSTATICLIB = installstaticlib
+INSTALLSTATICLIB = installstaticlib
 
 # Comment this out if you don't want to install the shared libs.
 # If you do not install the shared nor the static libs, 'make static'
@@ -143,7 +143,10 @@
 INCLUDE_APM_DRIVER = y
 INCLUDE_NV3_DRIVER = y
 INCLUDE_ET6000_DRIVER = y
-INCLUDE_VESA_DRIVER = y
+
+# This doesn't work for non-intel platforms
+# INCLUDE_VESA_DRIVER = y
+
 INCLUDE_MX_DRIVER = y
 INCLUDE_PARADISE_DRIVER = y
 #
@@ -240,7 +243,8 @@
 INCLUDES = -I$(srcdir)/include -I.
 OPTIMIZE = -fomit-frame-pointer -O2 -fno-strength-reduce -pipe
 # OPTIMIZE = -g -O2 -fno-strength-reduce -pipe
-CFLAGS   = $(WARN) $(DLLFLAGS) $(INCLUDES) $(OPTIMIZE) $(DEFINES)
+# CFLAGS   = $(WARN) $(DLLFLAGS) $(INCLUDES) $(OPTIMIZE) $(DEFINES)
+CFLAGS= $(DLLFLAGS) $(INCLUDES) $(DEFINES) -g 
 # ELF doesn't like -N. It is beneficial for small tools with a.out
 ifeq (a.out, $(TARGET_FORMAT))
        LDFLAGS   = -N -s
--- demos/Makefile
+++ demos/Makefile      1999/02/17 16:20:18
@@ -28,7 +28,7 @@
 
 # Determine what library (static or shared) we will be linking programs with
 ifdef INSTALLSHAREDLIB
-  LIBS = -lvgagl -lvga
+  LIBS = -L../sharedlib -lvgagl -lvga
 endif
 ifndef LIBS
   LIBS    = ../staticlib/libvgagl.a ../staticlib/libvga.a -lm
@@ -43,17 +43,17 @@
 
 .c:
        $(CC) $(CFLAGS) $(LDFLAGS) -o $* $*.c $(LIBS)
-       chown 0 $*
+       chown root $*
        chmod 4755 $*
 
 testaccel: testaccel.c
        $(CC) $(CFLAGS) $(LDFLAGS) -o testaccel testaccel.c $(LIBS) -lm
-       chown 0 testaccel
+       chown root testaccel
        chmod 4755 testaccel
 
 accel: accel.c
        $(CC) $(CFLAGS) $(LDFLAGS) -o accel accel.c $(LIBS) -lm
-       chown 0 accel
+       chown root accel
        chmod 4755 accel
 
 clean: cleanbin
@@ -61,6 +61,11 @@
 
 cleanbin:
        rm -f $(PROGS)
+
+install:
+       mkdir -p /usr/lib/vga/demos
+       cp -a $(PROGS) /usr/lib/vga/demos
+       chown root.root /usr/lib/vga/demos/*
 
 #
 # No dependencies required here.
--- demos/printftest.c
+++ demos/printftest.c  1999/02/18 15:59:44
@@ -45,13 +45,17 @@
 #else
     vga_init();
     vgamode = vga_getdefaultmode();
-    if (vgamode == -1)
+    if (vgamode == -1) {
+       printf ("vga_getdefaultmode() is lame on this host. Falling back to 
+standard\n");
        vgamode = G320x200x256;
+    }
 
     if (!vga_hasmode(vgamode)) {
        printf("Mode not available.\n");
        exit(1);
     }
+
+    printf ("now changeing mode\n");
 
     vga_setmode(vgamode);
     gl_setcontextvga(vgamode);
--- demos/vgatest.c
+++ demos/vgatest.c     1999/03/01 12:15:37
@@ -43,7 +43,6 @@
     vga_drawline(xmax, 0, xmax, ymax);
     vga_drawline(xmax, ymax, 0, ymax);
     vga_drawline(0, ymax, 0, 0);
-
     for (i = 0; i <= 15; i++) {
        vga_setegacolor(i);
        vga_drawline(10 + i * 5, 10, 90 + i * 5, 90);
@@ -52,9 +51,7 @@
        vga_setegacolor(i);
        vga_drawline(90 + i * 5, 10, 10 + i * 5, 90);
     }
-
     vga_screenon();
-
     ys = 100;
     yw = (ymax - 100) / 4;
     switch (vga_getcolors()) {
@@ -155,7 +152,6 @@
     int i, high;
 
     vga_init();                        /* Initialize. */
-
     mode = -1;
 #if 0                          /* Prompt is more useful. */
     mode = vga_getdefaultmode();
@@ -246,9 +242,9 @@
            exit(-1);
        }
     }
-    if (vga_hasmode(mode))
+    if (vga_hasmode(mode)) {
        testmode(mode);
-    else {
+   } else {
        printf("Error: Video mode not supported by driver\n");
        exit(-1);
     }
--- gl/Makefile
+++ gl/Makefile 1999/02/17 16:20:18
@@ -26,7 +26,7 @@
 
 libvgagl.so.$(VERSION): $(MODULES)
        $(CC) -s -shared -Wl,-soname,libvgagl.so.$(MAJOR_VER) -o 
libvgagl.so.$(VERSION) \
-         $(MODULES)
+         $(MODULES) -lc
 
 libvgagl.a: $(MODULES)
        rm -f libvgagl.a
--- src/Makefile
+++ src/Makefile        1999/02/17 16:20:18
@@ -26,7 +26,7 @@
           vgapal.o vgacol.o vgamodesel.o vgamisc.o \
          vgadump.o vgaconvplanar.o vgaaccel.o \
          timing.o vgaregs.o interface.o accel.o \
-         vgabgpage.o vgabgvt.o vgapci.o
+         vgabgpage.o vgabgvt.o vgapci.o alphabus.o
 MOUSE   = mouse/mouse.o
 KEYBOARD = keyboard/keyboard.o
 JOYSTICK = joystick/joystick.o
@@ -324,7 +324,7 @@
 # These rules are for ELF only.
 libvga.so.$(VERSION): $(ALLOBJS)
        $(CC) -s -shared -Wl,-soname,libvga.so.$(MAJOR_VER) \
-         -o libvga.so.$(VERSION) $(ALLOBJS) -lm
+         -o libvga.so.$(VERSION) $(ALLOBJS) -lm -lc
 
 $(sharedlibdir)/libvga.so.$(VERSION): libvga.so.$(VERSION)
        $(INSTALL_PROGRAM) $< $(sharedlibdir)/$<
--- src/alphabus.c
+++ src/alphabus.c      1999/03/01 13:59:49
@@ -0,0 +1,795 @@
+/* Copyright (C) 1992, 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library  (from axp libc-960906).
+Contributed by David Mosberger.
+
+It has been changed for use with svgalib by Stefan Reinauer <[EMAIL PROTECTED]>
+
+*/
+
+/* I/O access is restricted to ISA port space (ports 0..65535).
+Modern devices hopefully are sane enough not to put any performance
+critical registers in i/o space.
+
+On the first call to ioperm() or _sethae(), the entire (E)ISA port
+space is mapped into the virtual address space at address io.base.
+mprotect() calls are then used to enable/disable access to ports.  Per
+page, there are PAGE_SIZE>>IO_SHIFT I/O ports (e.g., 256 ports on a
+Low Cost Alpha based system using 8KB pages).
+
+Keep in mind that this code should be able to run in a 32bit address
+space.  It is therefore unreasonable to expect mmap'ing the entire
+sparse address space would work (e.g., the Low Cost Alpha chip has an
+I/O address space that's 512MB large!).  */
+
+#define Bool int
+#define FALSE 0
+#define TRUE 1
+#ifdef __alpha__
+
+#include "gnu-stabs.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <asm/page.h>
+#include <asm/system.h>
+
+#define PATH_ALPHA_SYSTYPE     "/etc/alpha_systype"
+#define PATH_CPUINFO           "/proc/cpuinfo"
+
+#define MAX_PORT       0x10000
+#define vuip           volatile unsigned int *
+
+#define JENSEN_IO_BASE         (0xfffffc0300000000UL)
+#define JENSEN_SPARSE_MEM      (0xfffffc0200000000UL)
+
+/*
+ * With respect to the I/O architecture, APECS and LCA are identical,
+ * so the following defines apply to LCA as well.
+ */
+#define APECS_IO_BASE          (0xfffffc01c0000000UL)
+#define APECS_SPARSE_MEM       (0xfffffc0200000000UL)
+#define APECS_DENSE_MEM                (0xfffffc0300000000UL)
+
+#define CIA_IO_BASE            (0xfffffc8580000000UL)
+#define CIA_SPARSE_MEM         (0xfffffc8000000000UL)
+#define CIA_DENSE_MEM          (0xfffffc8600000000UL)
+
+enum {
+  IOSYS_JENSEN = 0, IOSYS_APECS = 1, IOSYS_CIA = 2
+} iosys_t;
+
+struct ioswtch {
+  void         (*sethae)(unsigned long addr);
+  void         (*outb)(unsigned char b, unsigned long port);
+  void         (*outw)(unsigned short b, unsigned long port);
+  void         (*outl)(unsigned int b, unsigned long port);
+  unsigned int (*inb)(unsigned long port);
+  unsigned int (*inw)(unsigned long port);
+  unsigned int (*inl)(unsigned long port);
+};
+
+static struct platform {
+  const char   *name;
+  int          io_sys;
+  int          hae_shift;
+  unsigned long        bus_memory_base;
+  unsigned long        sparse_bus_memory_base;
+} platform[] = {
+  {"Alcor",    IOSYS_CIA,      5, CIA_DENSE_MEM,       CIA_SPARSE_MEM},
+  {"Avanti",   IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"Cabriolet",        IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"EB164",    IOSYS_CIA,      5, CIA_DENSE_MEM,       CIA_SPARSE_MEM},
+  {"EB64+",    IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"EB66",     IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"EB66P",    IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"Jensen",   IOSYS_JENSEN,   7, 0,                   JENSEN_SPARSE_MEM},
+  {"Mikasa",   IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"Mustang",  IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+  {"Ruffian",  IOSYS_CIA,      5, CIA_DENSE_MEM,       CIA_SPARSE_MEM},
+  {"Noname",   IOSYS_APECS,    5, APECS_DENSE_MEM,     APECS_SPARSE_MEM},
+};
+
+static struct {
+  struct hae {
+    unsigned long      cache;
+    unsigned long *    reg;
+  } hae;
+  unsigned long                base;
+  struct ioswtch *     swp;
+  int                  sys;
+  int                  hae_shift;
+  unsigned long                bus_memory_base;
+  unsigned long                sparse_bus_memory_base;
+} io;
+
+extern void __sethae (unsigned long);  /* we can't use asm/io.h */
+
+static __inline__ unsigned long
+port_to_cpu_addr (unsigned long port, int iosys, int size)
+{
+  if (iosys == IOSYS_JENSEN)
+    return (port << 7) + ((size - 1) << 5) + io.base;
+  else
+    return (port << 5) + ((size - 1) << 3) + io.base;
+}
+
+static __inline__ void
+inline_sethae (unsigned long addr, int iosys)
+{
+  if (iosys == IOSYS_JENSEN)
+    {
+      /* hae on the Jensen is bits 31:25 shifted right */
+      addr >>= 25;
+      if (addr != io.hae.cache)
+       {
+//       __sethae (addr);
+         sethae(addr);
+         io.hae.cache = addr;
+       }
+    }
+  else
+    {
+      unsigned long msb;
+
+      /* no need to set hae if msb is 0: */
+      msb = addr & 0xf8000000;
+      if (msb && msb != io.hae.cache)
+       {
+//       __sethae (msb);
+         sethae (msb);
+         io.hae.cache = msb;
+       }
+    }
+}
+
+
+static __inline__ void
+inline_outb (unsigned char b, unsigned long port, int iosys)
+{
+  unsigned int w;
+  unsigned long addr = port_to_cpu_addr (port, iosys, 1);
+
+  inline_sethae (0, iosys);
+  __asm__ ("insbl %2,%1,%0" : "r=" (w) : "ri" (port & 0x3), "r" (b));
+  *(vuip)addr = w;
+  mb ();
+}
+
+
+static __inline__ void
+inline_outw (unsigned short b, unsigned long port, int iosys)
+{
+  unsigned int w;
+  unsigned long addr = port_to_cpu_addr (port, iosys, 2);
+
+  inline_sethae (0, iosys);
+  __asm__ ("inswl %2,%1,%0" : "r=" (w) : "ri" (port & 0x3), "r" (b));
+  *(vuip)addr = w;
+  mb ();
+}
+
+
+static __inline__ void
+inline_outl (unsigned int b, unsigned long port, int iosys)
+{
+  unsigned long addr = port_to_cpu_addr (port, iosys, 4);
+
+  if (port >= MAX_PORT)
+    return;
+
+  inline_sethae (0, iosys);
+  *(vuip)addr = b;
+  mb ();
+}
+
+
+static __inline__ unsigned int
+inline_inb (unsigned long port, int iosys)
+{
+  unsigned long result, addr = port_to_cpu_addr (port, iosys, 1);
+
+  inline_sethae (0, iosys);
+  result = *(vuip) addr;
+  result >>= (port & 3) * 8;
+  return 0xffUL & result;
+}
+
+
+static __inline__ unsigned int
+inline_inw (unsigned long port, int iosys)
+{
+  unsigned long result, addr = port_to_cpu_addr (port, iosys, 2);
+
+  inline_sethae (0, iosys);
+  result = *(vuip) addr;
+  result >>= (port & 3) * 8;
+  return 0xffffUL & result;
+}
+
+
+static __inline__ unsigned int
+inline_inl (unsigned long port, int iosys)
+{
+  unsigned long addr = port_to_cpu_addr (port, iosys, 4);
+
+  inline_sethae (0, iosys);
+  return *(vuip) addr;
+}
+
+
+#define DCL_SETHAE(name, iosys)                        \
+static void                                            \
+name##_sethae (unsigned long addr)                     \
+{                                                      \
+  inline_sethae (addr, IOSYS_##iosys);                 \
+}
+
+#define DCL_OUT(name, func, type, iosys)               \
+static void                                            \
+name##_##func (unsigned type b, unsigned long addr)    \
+{                                                      \
+  inline_##func (b, addr, IOSYS_##iosys);              \
+}
+
+
+#define DCL_IN(name, func, iosys)                      \
+static unsigned int                                    \
+name##_##func (unsigned long addr)                     \
+{                                                      \
+  return inline_##func (addr, IOSYS_##iosys);          \
+}
+
+
+DCL_SETHAE(jensen, JENSEN)
+DCL_OUT(jensen, outb, char,  JENSEN)
+DCL_OUT(jensen, outw, short, JENSEN)
+DCL_OUT(jensen, outl, int,   JENSEN)
+DCL_IN(jensen, inb, JENSEN)
+DCL_IN(jensen, inw, JENSEN)
+DCL_IN(jensen, inl, JENSEN)
+
+/* The APECS functions are also used for CIA since they are
+   identical.  */
+
+DCL_SETHAE(apecs, APECS)
+DCL_OUT(apecs, outb, char,  APECS)
+DCL_OUT(apecs, outw, short, APECS)
+DCL_OUT(apecs, outl, int,   APECS)
+DCL_IN(apecs, inb, APECS)
+DCL_IN(apecs, inw, APECS)
+DCL_IN(apecs, inl, APECS)
+
+struct ioswtch ioswtch[] = {
+  {
+    jensen_sethae,
+    jensen_outb, jensen_outw, jensen_outl,
+    jensen_inb, jensen_inw, jensen_inl
+  },
+  {
+    apecs_sethae,
+    apecs_outb, apecs_outw, apecs_outl,
+    apecs_inb, apecs_inw, apecs_inl
+  }
+};
+
+
+/*
+ * Initialize I/O system.  To determine what I/O system we're dealing
+ * with, we first try to read the value of symlink PATH_ALPHA_SYSTYPE,
+ * if that fails, we lookup the "system type" field in /proc/cpuinfo.
+ * If that fails as well, we give up.
+ */
+
+int init_iosys (void)
+{
+  char systype[256];
+  int i, n;
+
+  n = readlink(PATH_ALPHA_SYSTYPE, systype, sizeof(systype) - 1);
+  if (n > 0)
+    {
+      systype[n] = '\0';
+    }
+  else
+    {
+      FILE * fp;
+
+      fp = fopen (PATH_CPUINFO, "r");
+      if (!fp)
+       return -1;
+      while ((n = fscanf (fp, "system type : %256[^\n]\n", systype))
+            != EOF)
+       {
+         if (n == 1)
+           break;
+         else
+           fgets (systype, 256, fp);
+       }
+      fclose(fp);
+
+      if (n == EOF)
+       {
+         /* this can happen if the format of /proc/cpuinfo changes...  */
+         fprintf(stderr,
+                 "ioperm.init_iosys(): Unable to determine system type.\n"
+                 "\t(May need " PATH_ALPHA_SYSTYPE " symlink?)\n");
+         errno = ENODEV;
+         return -1;
+       }
+    }
+
+  /* translate systype name into i/o system: */
+  for (i = 0; i < sizeof (platform) / sizeof (platform[0]); ++i)
+    {
+      if (strcmp (platform[i].name, systype) == 0)
+       {
+         io.hae_shift = platform[i].hae_shift;
+         io.bus_memory_base = platform[i].bus_memory_base;
+         io.sparse_bus_memory_base = platform[i].sparse_bus_memory_base;
+         io.sys = platform[i].io_sys;
+         if (io.sys == IOSYS_JENSEN)
+           io.swp = &ioswtch[0];
+         else
+           io.swp = &ioswtch[1];
+         return 0;
+       }
+    }
+
+  printf ("ALARM! ALARM!\n");
+  /* systype is not a known platform name... */
+  errno = EINVAL;
+  return -1;
+}
+
+
+int
+_ioperm (unsigned long from, unsigned long num, int turn_on)
+{
+  unsigned long addr, len;
+  int prot;
+
+  if (!io.swp && init_iosys () < 0)
+    return -1;
+
+  /* this test isn't as silly as it may look like; consider overflows! */
+  if (from >= MAX_PORT || from + num > MAX_PORT)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (turn_on)
+    {
+      if (!io.base)
+       {
+         unsigned long base;
+         int fd;
+
+         io.hae.reg   = 0;             /* not used in user-level */
+         io.hae.cache = 0;
+
+//       __sethae (io.hae.cache);      /* synchronize with hw */
+         sethae (io.hae.cache);
+
+         fd = open ("/dev/mem", O_RDWR);
+         if (fd < 0)
+           return fd;
+
+         switch (io.sys)
+           {
+           case IOSYS_JENSEN:  base = JENSEN_IO_BASE; break;
+           case IOSYS_APECS:   base = APECS_IO_BASE; break;
+           case IOSYS_CIA:     base = CIA_IO_BASE; break;
+           default:
+             errno = ENODEV;
+             return -1;
+           }
+         addr  = port_to_cpu_addr (from, io.sys, 1);
+         addr &= PAGE_MASK;
+         len = port_to_cpu_addr (MAX_PORT, io.sys, 1) - addr;
+         io.base =
+           (unsigned long) mmap (0, len, PROT_NONE, MAP_SHARED, fd, base);
+       //    (unsigned long) __mmap (0, len, PROT_NONE, MAP_SHARED, fd, base);
+
+         close (fd);
+         if ((long) io.base == -1)
+           return -1;
+       }
+      prot = PROT_READ | PROT_WRITE;
+    }
+  else
+    {
+      if (!io.base)
+       return 0;       /* never was turned on... */
+
+      /* turnoff access to relevant pages: */
+      prot = PROT_NONE;
+    }
+  addr  = port_to_cpu_addr (from, io.sys, 1);
+  addr &= PAGE_MASK;
+  len = port_to_cpu_addr (from + num, io.sys, 1) - addr;
+  return mprotect ((void *) addr, len, prot);
+}
+
+
+int
+_iopl (unsigned int level)
+{
+    if (level > 3)
+      {
+       errno = EINVAL;
+       return -1;
+      }
+    if (level)
+      {
+       return _ioperm (0, MAX_PORT, 1);
+      }
+    return 0;
+}
+
+
+void
+_sethae (unsigned long addr)
+{
+  if (!io.swp && init_iosys () < 0)
+    return;
+
+  io.swp->sethae (addr);
+}
+
+
+void
+_outb (unsigned char b, unsigned long port)
+{
+  if (port >= MAX_PORT)
+    return;
+
+  io.swp->outb (b, port);
+}
+
+
+void
+_outw (unsigned short b, unsigned long port)
+{
+  if (port >= MAX_PORT)
+    return;
+
+  io.swp->outw (b, port);
+}
+
+
+void
+_outl (unsigned int b, unsigned long port)
+{
+  if (port >= MAX_PORT)
+    return;
+
+  io.swp->outl (b, port);
+}
+
+
+unsigned int
+_inb (unsigned long port)
+{
+  return io.swp->inb (port);
+}
+
+
+unsigned int
+_inw (unsigned long port)
+{
+  return io.swp->inw (port);
+}
+
+
+unsigned int
+_inl (unsigned long port)
+{
+  return io.swp->inl (port);
+}
+
+
+unsigned long
+_bus_base(void)
+{
+  if (!io.swp && init_iosys () < 0)
+    return -1;
+  return io.bus_memory_base;
+}
+
+unsigned long
+_bus_base_sparse(void)
+{
+  if (!io.swp && init_iosys () < 0)
+    return -1;
+  return io.sparse_bus_memory_base;
+}
+
+int
+_hae_shift(void)
+{
+  if (!io.swp && init_iosys () < 0)
+    return -1;
+  return io.hae_shift;
+}
+
+weak_alias (_sethae, sethae);
+weak_alias (_ioperm, ioperm);
+weak_alias (_iopl, iopl);
+weak_alias (_inb, inb);
+weak_alias (_inw, inw);
+weak_alias (_inl, inl);
+weak_alias (_outb, outb);
+weak_alias (_outw, outw);
+weak_alias (_outl, outl);
+weak_alias (_bus_base, bus_base);
+weak_alias (_bus_base_sparse, bus_base_sparse);
+weak_alias (_hae_shift, hae_shift);
+
+/*
+ * Now, this part of the file is stolen from XFree86. Responsible is
+ *                                     Stefan Reinauer <[EMAIL PROTECTED]>
+ *
+ * Copyright 1992 by Orest Zborowski <[EMAIL PROTECTED]>
+ * Copyright 1993 by David Wexelblat <[EMAIL PROTECTED]>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
+ * the software without specific, written prior permission.  Orest Zborowski
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose.  It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/*
+ * The Jensen lacks dense memory, thus we have to address the bus via
+ * the sparse addressing scheme.
+ *
+ * Martin Ostermann ([EMAIL PROTECTED]) - Apr.-Sep. 1996
+ */
+
+#ifdef TEST_JENSEN_CODE /* define to test the Sparse addressing on a non-Jensen */
+#define SPARSE (5)
+#define isJensen (1)
+#else
+#define isJensen (!_bus_base())
+#define SPARSE (7)
+#endif
+
+#define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base())
+#define JENSEN_SHIFT(x) (isJensen ? ((long)x<<SPARSE) : (long)x)
+#else
+#define BUS_BASE 0
+#define JENSEN_SHIFT(x) (x)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section                                            */
+/***************************************************************************/
+
+char *MapVidMem(char *Base, unsigned long Size)
+{
+       char *base;
+       int fd;
+
+       if ((fd = open("/dev/mem", O_RDWR)) < 0)
+       {
+               printf("MapVidMem: failed to open /dev/mem (%s)\n",
+                          strerror(errno));
+       }
+
+       base = (char *)mmap((caddr_t)0, JENSEN_SHIFT(Size),
+                            PROT_READ|PROT_WRITE,
+                            MAP_SHARED, fd,
+                            (off_t)(JENSEN_SHIFT((off_t)Base) + BUS_BASE));
+       close(fd);
+       if ((long)base == -1)
+       {
+               printf("MapVidMem: Could not mmap framebuffer (%s)\n",
+                          strerror(errno));
+       }
+       return base;
+}
+
+void UnMapVidMem(char *Base, unsigned long Size)
+{
+    munmap((caddr_t)JENSEN_SHIFT(Base), JENSEN_SHIFT(Size));
+}
+
+/***************************************************************************/
+/* I/O Permissions section                                                 */
+/***************************************************************************/
+
+/*
+ * Linux handles regular (<= 0x3ff) ports with the TSS I/O bitmap, and
+ * extended ports with the iopl() system call.
+ *
+ * For testing, it's useful to enable only the ports we need, but for
+ * production purposes, it's faster to enable all ports.
+ */
+
+static Bool InitDone = FALSE;
+
+static int SparseShift = 5; /* default to all but JENSEN */
+
+char *MapVidMemSparse(char *Base, unsigned long Size)
+{
+       char *base;
+       int fd;
+
+       if (!_bus_base()) SparseShift = 7; /* Uh, oh, JENSEN... */
+
+       Size <<= SparseShift;
+       Base = (char *)((unsigned long)Base << SparseShift);
+
+       if ((fd = open("/dev/mem", O_RDWR)) < 0)
+       {
+               printf("MapVidMem: failed to open /dev/mem (%s)\n",
+                          strerror(errno));
+       }
+
+       base = (char *)mmap((caddr_t)0, Size,
+                            PROT_READ | PROT_WRITE,
+                            MAP_SHARED, fd,
+                            (off_t)Base + _bus_base_sparse());
+       close(fd);
+       if ((long)base == -1)
+       {
+               printf("MapVidMem: Could not mmap framebuffer (%s)\n",
+                          strerror(errno));
+       }
+       return base;
+}
+
+void UnMapVidMemSparse(char *Base, unsigned long Size)
+{
+       Size <<= SparseShift;
+       munmap((caddr_t)Base, Size);
+}
+
+#define vuip    volatile unsigned int *
+
+extern void sethae(unsigned long hae);
+
+int ReadSparse8(char *Base, unsigned long Offset)
+{
+    unsigned long result, shift;
+    unsigned long msb = 0;
+
+    shift = (Offset & 0x3) * 8;
+    if (SparseShift != 7) { /* if not JENSEN, we may need HAE */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000UL;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    result = *(vuip) ((unsigned long)Base + (Offset << SparseShift));    
+    if (msb)
+      sethae(0);
+    result >>= shift;
+
+    return 0xffUL & result;
+}
+
+int ReadSparse16(char *Base, unsigned long Offset)
+{
+    unsigned long result, shift;
+    unsigned long msb = 0;
+
+    shift = (Offset & 0x2) * 8;
+    if (SparseShift != 7) { /* if not JENSEN, we may need HAE */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000UL;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    result = *(vuip)((unsigned long)Base+(Offset<<SparseShift)+(1<<(SparseShift-2)));
+    if (msb)
+      sethae(0);
+    result >>= shift;
+    return 0xffffUL & result;
+}
+
+int ReadSparse32(char *Base, unsigned long Offset)
+{
+    unsigned long result;
+    unsigned long msb = 0;
+
+    if (SparseShift != 7) { /* if not JENSEN, we may need HAE */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000UL;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    result = *(vuip)((unsigned long)Base+(Offset<<SparseShift)+(3<<(SparseShift-2)));
+    if (msb)
+      sethae(0);
+    return result;
+}
+
+void WriteSparse8(int Value, char *Base, unsigned long Offset)
+{
+    unsigned long msb = 0;
+    unsigned int b = Value & 0xffU;
+
+    if (SparseShift != 7) { /* not JENSEN */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    *(vuip) ((unsigned long)Base + (Offset << SparseShift)) = b * 0x01010101;
+
+    if (msb)
+      sethae(0);
+}
+
+void WriteSparse16(int Value, char *Base, unsigned long Offset)
+{
+    unsigned long msb = 0;
+    unsigned int w = Value & 0xffffU;
+
+    if (SparseShift != 7) { /* not JENSEN */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    *(vuip)((unsigned long)Base+(Offset<<SparseShift)+(1<<(SparseShift-2))) =
+      w * 0x00010001;
+    if (msb)
+      sethae(0);
+}
+
+void WriteSparse32(int Value, char *Base, unsigned long Offset)
+{
+    unsigned long msb = 0;
+
+    if (SparseShift != 7) { /* not JENSEN */
+      if (Offset >= (1UL << 24)) {
+        msb = Offset & 0xf8000000;
+        Offset -= msb;
+        if (msb) {
+         sethae(msb);
+        }
+      }
+    }
+    *(vuip)((unsigned long)Base+(Offset<<SparseShift)+(3<<(SparseShift-2))) = Value;
+    if (msb)
+      sethae(0);
+}
--- src/alphabus.h
+++ src/alphabus.h      1999/02/18 13:24:03
@@ -0,0 +1,50 @@
+extern int init_iosys(void);
+
+int
+_ioperm (unsigned long from, unsigned long num, int turn_on);
+
+int
+_iopl (unsigned int level);
+void
+_sethae (unsigned long addr);
+void
+_outb (unsigned char b, unsigned long port);
+void
+_outw (unsigned short b, unsigned long port);
+void
+_outl (unsigned int b, unsigned long port);
+unsigned int
+_inb (unsigned long port);
+unsigned int
+_inw (unsigned long port);
+unsigned int
+_inl (unsigned long port);
+unsigned long
+_bus_base(void);
+unsigned long
+_bus_base_sparse(void);
+
+#ifdef __alpha__
+#define BUS_BASE (isJensen ? _bus_base_sparse() : _bus_base())
+#define JENSEN_SHIFT(x) (isJensen ? ((long)x<<SPARSE) : (long)x)
+#else
+#define BUS_BASE 0
+#define JENSEN_SHIFT(x) (x)
+#endif
+
+/***************************************************************************/
+/* Video Memory Mapping section                                            */
+/***************************************************************************/
+
+extern char *MapVidMem(char *Base, unsigned long Size);
+extern void UnMapVidMem(char *Base, unsigned long Size);
+extern char *MapVidMemSparse(char *Base, unsigned long Size);
+extern void UnMapVidMemSparse(char *Base, unsigned long Size);
+extern void sethae(unsigned long hae);
+
+extern int ReadSparse8(char *Base, unsigned long Offset);
+extern int ReadSparse16(char *Base, unsigned long Offset);
+extern int ReadSparse32(char *Base, unsigned long Offset);
+extern void WriteSparse8(int Value, char *Base, unsigned long Offset);
+extern void WriteSparse16(int Value, char *Base, unsigned long Offset);
+extern void WriteSparse32(int Value, char *Base, unsigned long Offset);
--- src/apm.c
+++ src/apm.c   1999/02/17 16:20:18
@@ -25,6 +25,11 @@
 #include <string.h>            /* for memset */
 #include <sys/mman.h>          /* mmap */
 #include <unistd.h>
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/ati.c
+++ src/ati.c   1999/02/17 16:20:18
@@ -32,6 +32,10 @@
 #include <fcntl.h>
 #include <unistd.h>
 
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/chips.c
+++ src/chips.c 1999/02/17 16:20:18
@@ -87,6 +87,11 @@
 #include <sys/mman.h>          /* mmap */
 #include <unistd.h>            /* iopl() */
 #include <signal.h>            /* sigprocmask */
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/et4000.c
+++ src/et4000.c        1999/02/17 16:20:18
@@ -177,9 +177,11 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <string.h>
-#ifdef USEGLIBC
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
 #include <sys/io.h>
 #endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/et6000.c
+++ src/et6000.c        1999/02/17 16:20:18
@@ -9,6 +9,11 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <asm/page.h>
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/gnu-stabs.h
+++ src/gnu-stabs.h     1999/02/17 19:24:49
@@ -0,0 +1,148 @@
+/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#ifndef        __GNU_STABS_H
+
+#define        __GNU_STABS_H   1
+
+/* We will figure it out later. H.J. */
+#if !defined(__PIC__) && !defined(__pic__)
+#ifndef        HAVE_GNU_LD
+#define HAVE_GNU_LD
+#endif
+#endif
+
+#if defined(HAVE_GNU_LD) && !defined(__ELF__)
+
+/* Alias a function:
+       function_alias(creat, _creat, int, (file, mode),
+                      DEFUN(creat, (file, mode),
+                            CONST char *file AND int mode))
+   Yes, this is very repetitive.  Nothing you can do about it, so shut up.  */
+#define        function_alias(name, _name, type, args, defun) \
+  symbol_alias (_name, name);
+
+#define function_alias_void(name, _name, args, defun) \
+  symbol_alias (_name, name);
+
+/* Make references to ALIAS refer to SYMBOL.  */
+#ifdef __STDC__
+#define        symbol_alias(symbol, alias)     \
+  asm(".stabs \"" "_" #alias "\",11,0,0,0\n"\
+      ".stabs \"" "_" #symbol "\",1,0,0,0")
+#else
+/* Your assembler better grok this right!  */
+#define        symbol_alias(symbol, alias)     \
+  asm(".stabs \"_/**/alias\",11,0,0,0\n.stabs \"_/**/symbol\",1,0,0,0")
+#endif
+
+/* Issue a warning message from the linker whenever SYMBOL is referenced.  */
+#ifdef __STDC__
+#define        warn_references(symbol, msg)    \
+  asm(".stabs \"" msg "\",30,0,0,0\n"  \
+      ".stabs \"_" #symbol "\",1,0,0,0")
+#else
+#define        warn_references(symbol, msg)    \
+  asm(".stabs msg,30,0,0,0\n.stabs \"_/**/symbol\",1,0,0,0")
+#endif
+
+#ifdef __STDC__
+#define        stub_warning(name) \
+  warn_references(name, \
+                 "warning: " #name " is not implemented and will always fail")
+#else
+#define        stub_warning(name) \
+  warn_references(name, \
+                 "warning: name is not implemented and will always fail")
+#endif
+
+#ifdef __STDC__
+#define        text_set_element(set, symbol)   \
+  asm(".stabs \"_" #set "\",23,0,0,_" #symbol)
+#define        data_set_element(set, symbol)   \
+  asm(".stabs \"_" #set "\",25,0,0,_" #symbol)
+#else
+#define        text_set_element(set, symbol)   \
+  asm(".stabs \"_/**/set\",23,0,0,_/**/symbol")
+#define        data_set_element(set, symbol)   \
+  asm(".stabs \"_/**/set\",25,0,0,_/**/symbol")
+#endif
+
+#else  /* No GNU stabs.  */
+
+#define        function_alias(name, _name, type, args, defun) \
+  type defun { return _name args; }
+
+#define function_alias_void(name, _name, args, defun) \
+  void defun { _name args; }
+
+#endif /* GNU stabs.  */
+
+#ifdef __ELF__
+
+/* Alias macros for ELF */
+#define elf_alias(name1, name2) \
+  __asm__(".globl " #name2 "; " #name2 "=" #name1)
+#define weak_alias(name1, name2) \
+  __asm__(".weak " #name2 "; " #name2 "=" #name1)
+#define weak_symbol(name) \
+  __asm__(".weak " #name)
+
+/* Make SYMBOL, which is in the text segment, an element of SET.  */
+#if 1
+#define text_set_element(set, symbol)  _elf_text_set_element(set, symbol)
+#else
+#define text_set_element(set, symbol)
+#endif
+
+/* Make SYMBOL, which is in the data segment, an element of SET.  */
+#define data_set_element(set, symbol)  _elf_data_set_element(set, symbol)
+/* Make SYMBOL, which is in the bss segment, an element of SET.  */
+#define bss_set_element(set, symbol)   _elf_data_set_element(set, symbol)
+
+/* These are all done the same way in ELF.
+   There is a new section created for each set.  */
+#define _elf_text_set_element(set, symbol) \
+  static const void *const __elf_set_##set##_element_##symbol##__ \
+    __attribute__ ((section (#set))) = &(symbol)
+
+#define _elf_data_set_element(set, symbol) \
+  static const void *__elf_set_##set##_element_##symbol##__ \
+    __attribute__ ((section (#set))) = &(symbol)
+
+/* Define SET as a symbol set.  This may be required (it is in a.out) to
+   be able to use the set's contents.  */
+#define symbol_set_define(set) symbol_set_declare(set)
+
+/* Declare SET for use in this module, if defined in another module.  */
+#define symbol_set_declare(set) \
+  extern void *const __start_##set, *const __stop_##set;
+
+/* Return a pointer (void *const *) to the first element of SET.  */
+#define symbol_set_first_element(set)  (&__start_##set)
+
+/* Return true iff PTR (a void *const *) has been incremented
+   past the last element in SET.  */
+#define symbol_set_end_p(set, ptr)     ((ptr) >= &__stop_##set)
+
+#define link_warning(msg) static const char __evoke_link_warning__[] \
+       __attribute__ ((section (".gnu.warning"))) = msg;
+
+#endif
+
+#endif /* gnu-stabs.h  */
--- src/gvga6400.c
+++ src/gvga6400.c      1999/02/17 16:20:18
@@ -178,7 +178,31 @@
     int result = 0;
     int address;
 
+    /*  Ensure that this open gets a file descriptor greater
+     *  than 2, else problems can occur with stdio functions
+     *  under certain strange conditions:  */
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)) {
+        perror("/dev/null");
+        exit(1);
+    }
     mem_fd = open("/dev/mem", O_RDONLY);
+    if (mem_fd == -1) {
+        perror("/dev/mem");
+        exit(-1);
+    }
+    /*  Ensure this file is closed if we were ever to exec something else...  */
+    if (fcntl(mem_fd, F_SETFD, 1) == -1) {
+        perror("fcntl");
+        exit(-1);
+    }
 
     /* Changed to use valloc(). */
     if ((vga_bios = valloc(4096)) == NULL) {
--- src/libvga.h
+++ src/libvga.h        1999/02/26 14:09:04
@@ -6,7 +6,7 @@
 
 #ifndef _LIBVGA_H
 #define _LIBVGA_H
-
+#include <stdio.h>
 #include <string.h>
 #ifdef USEGLIBC
 #include <sys/io.h>
@@ -74,10 +74,8 @@
 
 /* Shorthands for internal variables and functions */
 #define CI     __svgalib_cur_info
-#ifdef __alpha__
-#define SM     __svgalib_sparse_mem
-#endif
 #define GM     __svgalib_graph_mem
+#define SM     __svgalib_sparse_mem
 #define CM     __svgalib_cur_mode
 #define VMEM   __svgalib_videomemoryused
 #define DREP   __svgalib_driver_report
@@ -97,35 +95,10 @@
 #ifdef __alpha__
 #include <asm/io.h>
 #include <linux/autoconf.h>
-#if defined(CONFIG_ALPHA_JENSEN)
-#define DENSE_MEM_BASE  EISA_MEM
-#define SPARSE_MEM_BASE EISA_MEM
-#define MEM_SHIFT       7
-#define MEM_TYPE_BYTE   0x00
-#define MEM_TYPE_WORD   0x20
-#define MEM_TYPE_LONG   0x60
-#elif defined(CONFIG_ALPHA_CABRIOLET)
-#define DENSE_MEM_BASE  APECS_DENSE_MEM
-#define SPARSE_MEM_BASE APECS_SPARSE_MEM
-#define MEM_SHIFT       5
-#define MEM_TYPE_BYTE   0x00
-#define MEM_TYPE_WORD   0x08
-#define MEM_TYPE_LONG   0x18
-#elif defined(CONFIG_ALPHA_NONAME)
-#define DENSE_MEM_BASE  LCA_DENSE_MEM
-#define SPARSE_MEM_BASE LCA_SPARSE_MEM
-#define MEM_SHIFT       5
-#define MEM_TYPE_BYTE   0x00
-#define MEM_TYPE_WORD   0x08
-#define MEM_TYPE_LONG   0x18
 #endif
-#define SPARSE_GRAPH_BASE (SPARSE_MEM_BASE + (0xA0000 << MEM_SHIFT))
-#define GRAPH_BASE (DENSE_MEM_BASE + 0xA0000)  /* this is wrong for */
-#define FONT_BASE  (DENSE_MEM_BASE + 0xA0000)  /* jensen type hardware */
-#else
+
 #define GRAPH_BASE 0xA0000
 #define FONT_BASE  0xA0000
-#endif
 #define GRAPH_SIZE 0x10000
 #define FONT_SIZE  (0x2000 * 4) /* 2.0.x kernel can use 2 512 char. fonts */
 #define GPLANE16   G640x350x16
@@ -149,10 +122,9 @@
 extern int CM;                 /* current video mode       */
 extern struct info infotable[];
 extern int SCREENON;           /* screen visible if != 0 */
-extern unsigned long __svgalib_graph_base;
 extern unsigned char *GM;      /* graphics memory frame */
 #ifdef __alpha__
-extern unsigned char *SM;      /* sparse graphics memory frame */
+extern unsigned char *SM;
 #endif
 extern int MODEX;              /* TRUE after vga_setmodeX() */
 extern int MODEFLAGS;          /* copy of flags of current modeinfo->flags */
@@ -208,10 +180,9 @@
 
 #ifdef __alpha__
 
-#include <asm/io.h>
-
 static __inline__ void port_out(int value, int port)
 {
+//     printf ("port_out: val=0x%x port=0x%x\n",value,port);
     _outb(value, port);
 }
 
@@ -220,6 +191,11 @@
     _outw(value, port);
 }
 
+static __inline__ void port_outl(int value, int port)
+{
+    _outl(value, port);
+}
+
 static __inline__ int port_in(int port)
 {
     return _inb(port);
@@ -230,33 +206,26 @@
     return _inw(port);
 }
 
-#undef inb
-#undef inw
-#undef outb
-#undef outw
+static __inline__ int port_inl(int port)
+{
+    return _inl(port);
+} 
 
 extern unsigned long vga_readb(unsigned long base, unsigned long off);
 extern unsigned long vga_readw(unsigned long base, unsigned long off);
+extern unsigned long vga_readl(unsigned long base, unsigned long off);
 extern void vga_writeb(unsigned char b, unsigned long base, unsigned long off);
 extern void vga_writew(unsigned short b, unsigned long base, unsigned long off);
+extern void vga_writel(unsigned int b, unsigned long base, unsigned long off);
 
-#define gr_readb(off)          (vga_readb((unsigned long)SM, (off)))
-#define gr_readw(off)          (vga_readw((unsigned long)SM, (off)))
-
-#if defined(CONFIG_ALPHA_JENSEN)
-#define gr_readl(off)          (vga_readl((unsigned long)SM, (off)))
-#else
-#define gr_readl(off)          (*(((unsigned int*)GM)+(off)))
-#endif
-
-#define gr_writeb(v,off)       (vga_writeb((v), (unsigned long)SM, (off)))
-#define gr_writew(v,off)       (vga_writew((v), (unsigned long)SM, (off)))
-
-#if defined(CONFIG_ALPHA_JENSEN)
-#define gr_writel(v,off)       (vga_writel((v), (unsigned long)SM, (off)))
-#else
-#define gr_writel(v,off)       (*(((unsigned int*)GM)+(off)) = (v))
-#endif
+/* This may not work on JENSEN! We need to switch using the glibc bus-stuff */
+#define gr_readb(off)          (vga_readb((unsigned long)GM, (off)))
+#define gr_readw(off)          (vga_readw((unsigned long)GM, (off)))
+#define gr_readl(off)          (vga_readl((unsigned long)GM, (off)))
+
+#define gr_writeb(v,off)       (vga_writeb((v), (unsigned long)GM, (off)))
+#define gr_writew(v,off)       (vga_writew((v), (unsigned long)GM, (off)))
+#define gr_writel(v,off)       (vga_writel((v), (unsigned long)GM, (off)))
 
 #else
 
@@ -311,7 +280,6 @@
 #define gr_writeb(v,off)       (GM[(off)] = (v))
 #define gr_writew(v,off)       (*(unsigned short*)((GM)+(off)) = (v))
 #define gr_writel(v,off)       (*(unsigned long*)((GM)+(off)) = (v))
-
 
 #endif
 
--- src/lrmi.c
+++ src/lrmi.c  1999/02/17 16:20:18
@@ -12,8 +12,9 @@
 
 #include <stdio.h>
 #include <string.h>
+#ifdef __i386__
 #include <asm/vm86.h>
-
+#endif
 #ifdef USE_LIBC_VM86
 #include <sys/vm86.h>
 #endif
--- src/mach32.c
+++ src/mach32.c        1999/02/17 16:20:18
@@ -150,7 +150,8 @@
 #include <time.h>
 #include <sys/types.h>
 #include <sys/mman.h>
-#ifdef USEGLIBC
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
 #include <sys/io.h>
 #endif
 
@@ -514,6 +515,7 @@
 };
 
 #ifdef FAST_MEMCPY
+#ifdef __i386__
 /* This memcpy is immediately derived from memset as given in speedtest.c in this
    same svgalib package written by Harm Hanemaayer */
 
@@ -553,6 +555,9 @@
 #else
 #define fast_memcpy memcpy
 #endif
+#else
+#define fast_memcpy memcpy
+#endif
 
 static inline int max(int a, int b)
 {
@@ -1523,9 +1528,18 @@
            /*  Ensure that this fopen gets a file descriptor greater
             *  than 2, else problems can occur with stdio functions
             *  under certain strange conditions:  */
-           if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY);
-           if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
-           if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
+            if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)){
+             /* perror("/dev/null"); */
+             exit(1);
+            }
+            if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+             /* perror("/dev/null"); */
+             exit(1);
+            }
+            if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+             /* perror("/dev/null"); */
+             exit(1);
+            }
            fd = fopen(eeprom_fname, "wb");
            if (fd == NULL) {
              writerr:
@@ -3087,7 +3101,7 @@
                else
                    *push(1) = CMD_CPY + i;     /* Nope, copy instead of move.. */
                *push(1) = j;   /* The destination mode. */
-#ifdef 1
+#if 1
                printf("Redefining mode %d to %d:%dx%dx%d\n", i, j,
                       infotable[i].xdim, infotable[i].ydim, infotable[i].colors);
 #endif
@@ -3873,7 +3887,7 @@
            outw(MULTI_FUNC_CNTL, 0x7ff & (h - 1));
            data = va_arg(params, unsigned char *);
            outw(CMD, 0x53B1);
-#ifdef __alpha__
+#ifndef __i386__
            printf("mach32_ACCEL_PUTIMAGE: not done yet\n");
 #else
            if (infotable[CM].bytesperpixel == 2) {
@@ -4004,12 +4018,16 @@
            if (flag & ACCEL_END) {
                count -= 2;
            }
+#ifndef __i386__
+           printf("svgalib: ACCEL_POLYLINE not implemented yet.\n");
+#else
            if (count > 0)
                asm("cld\n"
                    "movw $0xfeee, %%dx\n"
                    "rep\n"
                    "outsw\n": : "S"(data), "c"(count): "%dx"
                );
+#endif
            if (flag & ACCEL_END) {
                checkqueue(3);
                outw(LINEDRAW_OPT, mach32_polyfill);
--- src/mach64.c
+++ src/mach64.c        1999/02/17 16:20:18
@@ -55,6 +55,10 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/mouse/mouse.c
+++ src/mouse/mouse.c   1999/02/26 14:45:45
@@ -7,6 +7,7 @@
 #include <vga.h>
 #include "vgamouse.h"
 #include "../libvga.h"
+#include <stdio.h>
 
 void (*__svgalib_mouse_eventhandler) (int, int, int, int, int, int, int) = NULL;
 
@@ -44,8 +45,18 @@
     currentinthandler = NULL;
 
     /* Initialize mouse device. */
+    if (m_type == MOUSE_UNCONFIGURED) {
+      fprintf(stderr,
+             "Warning: you have not yet configured your mouse type. If you have no 
+mouse,\n"
+             "setting the type to none' in " SVGALIB_CONFIG_FILE " will get rid of 
+this\n"
+             "annoying message.\n");
+      return -1;
+    }
     if (m_type == MOUSE_NONE || m_type < MOUSE_MICROSOFT || m_type > MOUSE_IMPS2)
        return -1;
+
+    if (m_type < MOUSE_MICROSOFT || m_type > MOUSE_IMPS2)
+       return -1;
     if (ms_init())
        return -1;
 
@@ -356,6 +367,7 @@
 
 void mouse_getposition_6d(int *x, int *y, int *z, int *rx, int *ry, int *rz)
 {
+
     if (wantcaps) {
         /* Return the mouse capabilities */
         *x = mouse_caps.key;
--- src/mouse/ms.c
+++ src/mouse/ms.c      1999/02/26 15:04:00
@@ -18,7 +18,6 @@
  */
 
 /* This file is included by mouse.c. */
-
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -422,6 +421,22 @@
     if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
     if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
 
+    /*  Ensure that the open will get a file descriptor greater
+     *  than 2, else problems can occur with stdio functions
+     *  under certain strange conditions:  */
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+
     /* Set the proper wheel delta */
     if(m_wheel_steps)
         m_wheel_delta = (360 / m_wheel_steps);
@@ -597,7 +612,6 @@
        return -1;
 
   again:
-
     if (m_fdmode == 1) {
        /* We don't want to wait, set NDELAY mode. */
        fcntl(__svgalib_mouse_fd, F_SETFL, O_RDONLY | O_NDELAY );
@@ -622,7 +636,6 @@
 #ifdef DEBUG
     printf("#bytes in buffer: %d\n", nu_bytes);
 #endif
-
   handle_packets:
 
     /* Handle packets in buffer. */
--- src/mouse/vgamouse.h
+++ src/mouse/vgamouse.h        1999/02/17 16:20:18
@@ -21,6 +21,7 @@
 #define MOUSE_NONE 9           /* Some special number for a non supported/existing 
mouse */
 #define MOUSE_INTELLIMOUSE 10
 #define MOUSE_IMPS2 11
+#define MOUSE_UNCONFIGURED 12
 
 #define MOUSE_ORIENTATION_VERTICAL 0
 #define MOUSE_ORIENTATION_HORIZONTAL 1
--- src/mx.c
+++ src/mx.c    1999/02/17 16:20:18
@@ -198,7 +198,7 @@
     return SVGADRV;
 }
 
-#ifdef 0
+#if 0
 static unsigned comp_lmn(unsigned clock) ;
 #endif
 /* Set a mode */
@@ -581,7 +581,7 @@
     return 0;
 }
 
-#ifdef 0   /* the computation works, but I don't know the limits */
+#if 0   /* the computation works, but I don't know the limits */
 #define WITHIN(v,c1,c2) (((v) >= (c1)) && ((v) <= (c2)))
 
 static unsigned
--- src/paradise.c
+++ src/paradise.c      1999/02/17 16:20:18
@@ -40,6 +40,7 @@
 {
 }
 
+#ifdef __i386__
 void inline _outb(unsigned port,unsigned value)
 {
 #ifdef DEBUG
@@ -47,6 +48,7 @@
 #endif
 outb(port,value);
 }
+#endif
 
 /* Fill in chipset specific mode information */
 
--- src/s3.c
+++ src/s3.c    1999/02/17 16:20:18
@@ -89,9 +89,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>            /* iopl() */
-#ifdef USEGLIBC
-#include <sys/io.h>             /* glibc iopl() */
+
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
 #endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/tvga8900.c
+++ src/tvga8900.c      1999/02/17 16:20:18
@@ -22,6 +22,11 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/vesa.c
+++ src/vesa.c  1999/02/17 16:20:18
@@ -7,6 +7,11 @@
 #include <string.h>            /* for memset */
 #include <sys/mman.h>          /* mmap */
 #include <unistd.h>
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
--- src/vga.c
+++ src/vga.c   1999/03/01 15:02:07
@@ -12,6 +12,7 @@
 
 /* The code is a bit of a mess; also note that the drawing functions */
 /* are not speed optimized (the gl functions are much faster). */
+
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
@@ -29,14 +30,17 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include <ctype.h>
-#ifdef USEGLIBC
+
+#if defined __GLIBC__ && __GLIBC__ >= 2
 #include <sys/io.h>
 #endif
+
 #include "vga.h"
 #include "libvga.h"
 #include "driver.h"
 #include "mouse/vgamouse.h"
 #include "keyboard/vgakeyboard.h"
+#include "alphabus.h"
 
 #ifdef BACKGROUND
 #include "vgabg.h"
@@ -185,7 +189,6 @@
 
 #define MAX_MODES (sizeof(infotable) / sizeof(struct info))
 
-unsigned long __svgalib_graph_base = GRAPH_BASE;
 
 unsigned char __svgalib_novga = 0;     /* Does not have VGA circuitry on board */
 unsigned char __svgalib_vesatext = 0;
@@ -327,6 +330,7 @@
 
 /* Dummy buffer for mmapping grahics memory; points to 64K VGA framebuffer. */
 unsigned char *__svgalib_graph_mem;
+
 /* Exported variable (read-only) is shadowed from internal variable, for */
 /* better shared library performance. */
 unsigned char *graph_mem;
@@ -357,12 +361,9 @@
 void *__svgalib_physaddr;
 int __svgalib_linear_memory_size;
 
-
 #ifdef __alpha__
-
 /* same as graph mem, but mapped through sparse memory: */
 unsigned char *__svgalib_sparse_mem;
-
 #endif
 
 static unsigned char *graph_buf = NULL;                /* saves graphics data during 
flip */
@@ -384,8 +385,7 @@
 static void (*__svgalib_setpage) (int);        /* gives little faster vga_setpage() 
*/
 static void (*__svgalib_setrdpage) (int);
 static void (*__svgalib_setwrpage) (int);
-#endif
-#ifdef BACKGROUND
+#else
 void (*__svgalib_setpage) (int);       /* gives little faster vga_setpage() */
 void (*__svgalib_setrdpage) (int);
 void (*__svgalib_setwrpage) (int);
@@ -522,7 +522,7 @@
 /* chips       chips & technologies*/
 /* et6000       Tseng ET6000 */         /* DS */
 
-/*#define DEBUG */
+/* #define DEBUG */
 
 /* Debug config file parsing.. */
 /*#define DEBUG_CONF */
@@ -574,8 +574,9 @@
     ioctl(0, TCGETS, &cur_termio);
     cur_termio.c_lflag &= ~ISIG;
     ioctl(0, TCSETSW, &cur_termio);
-}
 
+//    iopl(0); // SR
+}
 
 static void enable_interrupt(void)
 {
@@ -586,6 +587,9 @@
     ioctl(0, TCGETS, &cur_termio);
     cur_termio.c_lflag |= ISIG;
     ioctl(0, TCSETSW, &cur_termio);
+
+//    iopl(3); //SR
+
 }
 
 /* The following is rather messy and inelegant. The only solution I can */
@@ -617,15 +621,31 @@
     /*  Ensure that the open will get a file descriptor greater
      *  than 2, else problems can occur with stdio functions
      *  under certain strange conditions:  */
-    if (fcntl(0,F_GETFD) < 0) open("/dev/null", O_RDONLY);
-    if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
-    if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
+    if ((fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
+    if ((fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
+    if ((fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1)){
+      /* perror("/dev/null"); */
+      exit(1);
+    }
 
     if (__svgalib_mem_fd < 0)
        if ((__svgalib_mem_fd = open("/dev/mem", O_RDWR)) < 0) {
            printf("svgalib: Cannot open /dev/mem.\n");
            exit(1);
        }
+
+    /*  Ensure this file is closed if we ever exec something else...  */
+    if (fcntl(__svgalib_mem_fd, F_SETFD, 1) == -1) {
+       perror("fcntl");
+       exit(-1);
+    }
+
 #ifdef BACKGROUND
 #if BACKGROUND == 1
 
@@ -642,6 +662,12 @@
                  __svgalib_processnumber);
              exit(-1);
             }
+        /*  Ensure this file is closed if we ever exec something else...  */
+        if (fcntl(__svgalib_mem_fd, F_SETFD, 1) == -1)
+           {
+            perror("fcntl");
+            exit(-1);
+           }
        }
 #endif
 #endif
@@ -680,6 +706,21 @@
     if (fcntl(1,F_GETFD) < 0) open("/dev/null", O_WRONLY);
     if (fcntl(2,F_GETFD) < 0) open("/dev/null", O_WRONLY);
 
+    /*  The code below assumes file descriptors 0, 1, and 2
+     *  are already open; make sure that's true.  */
+    if ( (fcntl(0,F_GETFD) == -1) && (open("/dev/null", O_RDONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ( (fcntl(1,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+    if ( (fcntl(2,F_GETFD) == -1) && (open("/dev/null", O_WRONLY) == -1) ) {
+       perror("/dev/null");
+       exit(1);
+    }
+
     /*
      * Now, it would be great if we could use /dev/tty and see what it is connected 
to.
      * Alas, we cannot find out reliably what VC /dev/tty is bound to. Thus we parse
@@ -698,16 +739,18 @@
         return;                 /* perfect */
     }
 
-    if ((__svgalib_tty_fd = open("/dev/console", O_RDWR)) < 0) {
-        printf("svgalib: can't open /dev/console \n");
+    if ((__svgalib_tty_fd = open("/dev/tty0", O_RDWR)) < 0) {
+        printf("svgalib: can't open /dev/tty0 \n");
         exit(1);
     }
     if (ioctl(__svgalib_tty_fd, VT_OPENQRY, &svgalib_vc) < 0)
         goto error;
     if (svgalib_vc <= 0)
         goto error;
+
     sprintf(fname, "/dev/tty%d", svgalib_vc);
     close(__svgalib_tty_fd);
+
     /* change our control terminal: */
     setsid();
     /* We must use RDWR to allow for output... */
@@ -758,9 +801,14 @@
     /* If IOPERM is set, assume permissions have already been obtained */
     /* by a calling (exec-ing) process, e.g. ioperm(1). */
 
+
     if (getenv("IOPERM") == NULL)
 #ifdef __alpha__
+#if 1
        if (ioperm(0x0000, 0x10000, 1)) {
+#else
+       if (!iopl(3)) {
+#endif
            printf("svgalib: Cannot get I/O permissions.\n");
            exit(1);
        }
@@ -770,7 +818,6 @@
            exit(1);
        }
 #endif
-
     /* Open /dev/mem (also needs supervisor rights; ioperm(1) can be */
     /* used together with a special group that has r/w access on */
     /* /dev/mem to facilitate this). */
@@ -796,17 +843,14 @@
     }
 }
 
-
 void __svgalib_delay(void)
 {
     int i;
-    for (i = 0; i < 10; i++);
+    for (i = 0; i < 100; i++);
 }
 
 /* The Xfree server uses a slow copy, may help us too ... */
 #if defined(CONFIG_ALPHA_JENSEN)
-extern unsigned long vga_readl(unsigned long base, unsigned long off);
-extern void vga_writel(unsigned long b, unsigned long base, unsigned long off);
 static void slowcpy_from_sm(unsigned char *dest, unsigned char *src, unsigned bytes)
 {
     long i;
@@ -1427,36 +1471,16 @@
 }
 
 #endif
-#if BACKGROUND == 2
-
-#endif
 #endif
 
 
 static void __vga_mmap(void)
 {
-#ifdef LINEAR_DEBUG
-    printf("__vga_mmap() called, 
__svgalib_graph_base=0x%08lx\n",__svgalib_graph_base);
-#endif
-#if 0
-    /* This may waste 64K; mmap can probably do better by now. */
-    /* valloc allocates aligned on page boundary */
-    if ((__svgalib_graph_mem = valloc(GRAPH_SIZE)) == NULL) {
-       printf("svgalib: allocation error \n");
-       exit(1);
-    }
-    __svgalib_graph_mem = (unsigned char *) mmap(
-                                                   (caddr_t) GM,
-                                                   GRAPH_SIZE,
-                                                 PROT_READ | PROT_WRITE,
-                                                 MAP_SHARED | MAP_FIXED,
-                                                   __svgalib_mem_fd,
-                                                   __svgalib_graph_base
-       );
-#endif
-#if 1
-    /* This assumes pl10+. */
-    /* Still seems to waste 64K, so don't bother. */
+#ifdef __alpha__
+    GM = (unsigned char *)MapVidMem ((char *)GRAPH_BASE, GRAPH_SIZE);
+    SM = (unsigned char *)MapVidMemSparse ((char *)GRAPH_BASE, GRAPH_SIZE);
+#else /* __alpha__ */
+
 #ifndef BACKGROUND
     GM = (unsigned char *) mmap(
                                   (caddr_t) 0,
@@ -1464,9 +1488,10 @@
                                   PROT_READ | PROT_WRITE,
                                   MAP_SHARED,
                                   __svgalib_mem_fd,
-                                  __svgalib_graph_base
+                                  GRAPH_BASE
        );
-#endif
+#endif /* !BACKGROUND */
+
 #ifdef BACKGROUND
 #if BACKGROUND == 1
     if ((__svgalib_graph_mem = valloc(GRAPH_SIZE)) == NULL) {
@@ -1480,10 +1505,10 @@
                                   PROT_READ | PROT_WRITE,
                                   MAP_SHARED,
                                   __svgalib_mem_fd,
-                                  __svgalib_graph_base
+                                  GRAPH_BASE
        );
     __svgalib_map_virtual_screen(1000000); /* Video page */
-#endif 
+#endif /* BACKGROUND == 1 */
 #if BACKGROUND == 2
     GM = (unsigned char *) mmap(
                                   (caddr_t) 0,
@@ -1491,23 +1516,13 @@
                                   PROT_READ | PROT_WRITE,
                                   MAP_SHARED,
                                   __svgalib_mem_fd,
-                                  __svgalib_graph_base
+                                  GRAPH_BASE
        );
     __svgalib_graph_mem_orginal=GM;
-#endif
-#endif
+#endif /* BACKGROUND == 2 */
+#endif /* BACKGROUND */
 
-#ifdef __alpha__
-    SM = (unsigned char *) mmap(
-                                  (caddr_t) 0,
-                                  GRAPH_SIZE << MEM_SHIFT,
-                                  PROT_READ | PROT_WRITE,
-                                  MAP_SHARED,
-                                  __svgalib_mem_fd,
-                                  SPARSE_GRAPH_BASE
-       );
-#endif
-#endif
+#endif /* __alpha__ */
     graph_mem = __svgalib_graph_mem;   /* Exported variable. */
 }
 
@@ -1533,7 +1548,7 @@
 {
     int i;
     struct sigaction siga;
-
+    
     __svgalib_open_devconsole();
     if (__svgalib_tty_fd < 0) {
        exit(1);
@@ -1571,7 +1586,7 @@
 
     disable_interrupt();       /* Is reenabled later by set_texttermio */
 
-    __svgalib_getchipset();            /* make sure a chipset has been selected */
+    __svgalib_getchipset();    /* make sure a chipset has been selected */
     chipset_unlock();
 
     /* disable text output to console */
@@ -1646,6 +1661,7 @@
         slowcpy_from_sm(font_buf1, SM, FONT_SIZE);
 #else
         slowcpy(font_buf1, GM, FONT_SIZE);
+#warning "Does Slowcopy work?"
 #endif
 
         /* save font data in plane 3 */
@@ -2357,7 +2373,7 @@
     }
 
 #ifdef BACKGROUND
-    __svgalib_is_vt_switching_needed();
+       __svgalib_is_vt_switching_needed();
 #endif
     return 0;
 }
@@ -3189,7 +3205,7 @@
 static char *conf_mousenames[] =
 {
   "Microsoft", "MouseSystems", "MMSeries", "Logitech", "Busmouse", "PS2",
-    "MouseMan", "gpm", "Spaceball", "none", "IntelliMouse", "IMPS2", NULL};
+    "MouseMan", "gpm", "Spaceball", "none", "IntelliMouse", "IMPS2", "unconfigured", 
+NULL};
 
 static int check_digit(char *ptr, char *digits)
 {
@@ -3763,7 +3779,26 @@
 
 int vga_init(void)
 {
-    int retval = 0;
+    int retval = -1;
+    
+    /*
+     * Make sure we know where our stdout/stderr are going
+     *  (based on code by Kevin Vajk)
+     */
+
+    init_iosys();
+
+    if(fcntl(0, F_GETFD)<0)
+       if(open("/dev/null", O_RDWR, 0)<0)
+               goto bail;
+    if(fcntl(1, F_GETFD)<0)
+       if(open("/dev/null", O_RDWR, 0)<0)
+               goto bail;
+    if(fcntl(2, F_GETFD)<0)
+       if(open("/dev/null", O_RDWR, 0)<0)
+               goto bail;
+               
+    retval = 0;
 
     __svgalib_open_devconsole();
     if (__svgalib_tty_fd < 0) {
@@ -3777,6 +3812,7 @@
     }
     /* Michael: I assume this is a misunderstanding, when svgalib was developed,
        there were no saved uids, thus setting effective uid sufficed... */
+bail:
     if ( __svgalib_security_revokeallprivs == 1 ) {
        setuid(getuid());  
        setgid(getgid());
@@ -3787,118 +3823,51 @@
 }
 
 #ifdef __alpha__
-
-#define vuip   volatile unsigned int *
-
-extern void sethae(unsigned long hae);
-
-static struct hae hae;
-
-
-int iopl(int level)
-{
-    return 0;
-}
-
 unsigned long vga_readb(unsigned long base, unsigned long off)
 {
-    unsigned long result, shift;
-#if !defined(CONFIG_ALPHA_JENSEN)
-    unsigned long msb;
-#endif
-
-    shift = (off & 0x3) * 8;
-#if !defined(CONFIG_ALPHA_JENSEN)
-    if (off >= (1UL << 24)) {
-       msb = off & 0xf8000000;
-       off -= msb;
-       if (msb && msb != hae.cache) {
-           sethae(msb);
-       }
-    }
-#endif
-    result = *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_BYTE);
-    result >>= shift;
-    return 0xffUL & result;
+       if (GM==NULL)
+               return (unsigned long)ReadSparse8((char *)base,off);
+       else
+               return (((volatile unsigned char *)base)[(off)]);
 }
 
 unsigned long vga_readw(unsigned long base, unsigned long off)
 {
-    unsigned long result, shift;
-#if !defined(CONFIG_ALPHA_JENSEN)
-    unsigned long msb;
-#endif
-
-    shift = (off & 0x3) * 8;
-#if !defined(CONFIG_ALPHA_JENSEN)
-    if (off >= (1UL << 24)) {
-       msb = off & 0xf8000000;
-       off -= msb;
-       if (msb && msb != hae.cache) {
-           sethae(msb);
-       }
-    }
-#endif
-    result = *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_WORD);
-    result >>= shift;
-    return 0xffffUL & result;
+       if (GM==NULL)
+               return (unsigned long)ReadSparse16((char *)base,off);
+       else
+               return (*(volatile unsigned short*)((base)+(off)));
 }
 
-#if defined(CONFIG_ALPHA_JENSEN)
 unsigned long vga_readl(unsigned long base, unsigned long off)
 {
-    unsigned long result;
-    result = *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_LONG);
-    return 0xffffffffUL & result;
+       if (GM==NULL)
+               return (unsigned long)ReadSparse32((char *)base,off);
+       else
+               return (*(volatile unsigned long*)((base)+(off)));
 }
-#endif
 
 void vga_writeb(unsigned char b, unsigned long base, unsigned long off)
 {
-#if !defined(CONFIG_ALPHA_JENSEN)
-    unsigned long msb;
-    unsigned int w;
-
-    if (off >= (1UL << 24)) {
-       msb = off & 0xf8000000;
-       off -= msb;
-       if (msb && msb != hae.cache) {
-           sethae(msb);
-       }
-    }
-  asm("insbl %2,%1,%0": "r="(w):"ri"(off & 0x3), "r"(b));
-    *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_BYTE) = w;
-#else
-    *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_BYTE) = b * 0x01010101;
-#endif
+       if (GM==NULL)
+               WriteSparse8((int)b,(char *)base,off);
+       else
+               ((char *)base)[(off)] = (b);
 }
 
 void vga_writew(unsigned short b, unsigned long base, unsigned long off)
 {
-#if !defined(CONFIG_ALPHA_JENSEN)
-    unsigned long msb;
-    unsigned int w;
-
-    if (off >= (1UL << 24)) {
-       msb = off & 0xf8000000;
-       off -= msb;
-       if (msb && msb != hae.cache) {
-           sethae(msb);
-       }
-    }
-  asm("inswl %2,%1,%0": "r="(w):"ri"(off & 0x3), "r"(b));
-    *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_WORD) = w;
-#else
-    *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_WORD) = b * 0x00010001;
-#endif
+       if (GM==NULL)
+               WriteSparse16((int)b,(char *)base,off);
+       else
+               (*(unsigned short*)((base)+(off)) = (b));
 }
 
-#if defined(CONFIG_ALPHA_JENSEN)
-void vga_writel(unsigned long b, unsigned long base, unsigned long off)
+void vga_writel(unsigned int b, unsigned long base, unsigned long off)
 {
-    *(vuip) ((off << MEM_SHIFT) + base + MEM_TYPE_LONG) = b;
+       if (GM=NULL)
+               WriteSparse32((int)b,(char *)base,off);
+       else
+               (*(unsigned long*)((base)+(off)) = (b));
 }
-
-#endif
-
 #endif
--- src/vgadraw.c
+++ src/vgadraw.c       1999/02/26 10:41:30
@@ -113,7 +113,7 @@
        return vga_drawscansegment(colors, 0, line, CI.xdim);
 }
 
-
+#if 0
 #if defined(CONFIG_ALPHA_JENSEN)
 
 #define vuip    volatile unsigned int *
@@ -160,6 +160,10 @@
 #define VM      GM
 
 #endif
+#endif
+
+#define MEMCPY memcpy
+#define VM     GM
 
 #ifdef BACKGROUND
 
@@ -247,7 +251,7 @@
            /* make k the index of the last byte to write */
            k--;
 
-#if defined(CONFIG_ALPHA_JENSEN)
+#if 0 /* defined(CONFIG_ALPHA_JENSEN) */
            address = SM + (offset << 7);
 #else
            address = GM + offset;
@@ -383,6 +387,7 @@
            port_out(0x0F, SEQ_D);
 
 #if defined(CONFIG_ALPHA_JENSEN)
+#warning huhu
            MEMCPY(SM + ((y * CI.xdim + x) << 4), colors, length);
 #else
            MEMCPY(GM + (y * CI.xdim + x) / 8, colors, length);
--- src/vgaline.c
+++ src/vgaline.c       1999/03/01 12:17:08
@@ -37,8 +37,7 @@
        while (x != x2) {
 #ifndef BACKGROUND
            vga_drawpixel(x, y);
-#endif
-#ifdef BACKGROUND
+#else
             __svgalib_fast_drawpixel(x, y);
 #endif
 
@@ -54,8 +53,7 @@
        while (y != y2) {
 #ifndef BACKGROUND
            vga_drawpixel(x, y);
-#endif
-#ifdef BACKGROUND
+#else
             __svgalib_fast_drawpixel(x, y);
 #endif
 
@@ -67,13 +65,12 @@
            d += ax;
        }
     }
+
 #ifndef BACKGROUND
     vga_drawpixel(x, y);
-#endif
-#ifdef BACKGROUND
+#else
     __svgalib_fast_drawpixel(x, y);
     __svgalib_is_vt_switching_needed();
 #endif
-
     return 0;
 }
--- src/vgapci.c
+++ src/vgapci.c        1999/02/17 16:20:18
@@ -1,6 +1,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#if defined __GLIBC__ && __GLIBC__ >= 2
+#include <sys/io.h>
+#endif
+
 #include "libvga.h"
 
 
--- src/vgapix.c
+++ src/vgapix.c        1999/03/01 14:41:53
@@ -156,14 +156,14 @@
 
 #ifndef BACKGROUND
 int vga_drawpixel(int x, int y)
-#endif
-#ifdef BACKGROUND
+#else
 int __svgalib_fast_drawpixel(int x, int y)
 #endif
 {
     unsigned long offset;
     int c;
 
+
 #ifdef BACKGROUND    
     if (!vga_oktowrite())
         {
@@ -189,6 +189,7 @@
            }
          else
            {
+
             if (1<<(x&3)==1) vga_setpage(0);
             if (1<<(x&3)==2) vga_setpage(1);
             if (1<<(x&3)==4) vga_setpage(2);
@@ -201,14 +202,15 @@
 
        return 0;
     }
+
+
     switch (__svgalib_cur_info.bytesperpixel) {
     case 0:                    /* Must be 2 or 16 color mode. */
        /* set up video page */
        offset = y * CI.xbytes + (x >> 3);
 #ifndef BACKGROUND
        vga_setpage(offset >> 16);
-#endif
-#ifdef BACKGROUND
+#else
         __svgalib_fast_setpage(offset >> 16);
 #endif
        offset &= 0xffff;
@@ -218,11 +220,11 @@
        port_out(0x80 >> (x & 7), GRA_D);
 
        /* read into latch and write dummy back */
+
        read_write(offset);
        break;
     case 1:
        offset = y * CI.xbytes + x;
-
        /* select segment */
 #ifndef BACKGROUND
        vga_setpage(offset >> 16);
@@ -268,8 +270,7 @@
            gr_writeb(c, 0xffff);
 #ifndef BACKGROUND
            vga_setpage((offset >> 16) + 1);
-#endif
-#ifdef  BACKGROUND
+#else
             __svgalib_fast_setpage((offset >> 16)+1);        
 #endif
            gr_writew(c >> 8, 0);
@@ -309,8 +310,7 @@
 
 #ifndef BACKGROUND
 int vga_getpixel(int x, int y)
-#endif
-#ifdef BACKGROUND
+#else
 int __svgalib_fast_getpixel(int x, int y)
 #endif
 {
@@ -321,6 +321,7 @@
     int tmp;
 #endif 
 
+
     if (MODEX) {
 #ifdef BACKGROUND
        if (vga_oktowrite())
@@ -472,8 +473,7 @@
     }
 #ifdef BACKGROUND
     return(pix);
-#endif
-#ifndef BACKGROUND
+#else
     return 0;
 #endif
 }
--- threeDKit/Makefile
+++ threeDKit/Makefile  1999/02/17 16:20:18
@@ -26,7 +26,7 @@
 
 # Determine what library (static or shared) we will be linking programs with
 ifdef INSTALLSHAREDLIB
-  LIBS = -lm -lvgagl -lvga
+  LIBS = -L../sharedlib -lm -lvgagl -lvga
 endif
 ifndef LIBS
   LIBS    = -lm ../staticlib/libvgagl.a ../staticlib/libvga.a
--- utils/Makefile
+++ utils/Makefile      1999/02/17 16:20:18
@@ -16,7 +16,7 @@
 CFLAGS = $(WARN) $(OPTIMIZE) -I../include
 #Use the next one for the Alpha/AXP if you need it
 #LDFLAGS = -L../staticlib 
-LIBS = -lvga -lm
+LIBS = -L../sharedlib -lvga -lm
 
 #----------------------------------------------------------------------
 # Rules Section
@@ -50,7 +50,7 @@
        make .depend
 
 install:
-       $(INSTALLPROG) $(UTILPROGS) $(UTILINSTALLDIR)
+       $(INSTALL_PROGRAM) $(UTILPROGS) runx textmode savetextmode $(bindir)
 
 .depend:
        gcc -MM $(patsubst %.o,$(srcdir)/utils/%.c,$(OBJECTS)) >.depend
--- utils/runx
+++ utils/runx  1999/02/17 16:20:18
@@ -5,8 +5,11 @@
 # running X, and 'textmode' after. This will restore the textmode registers
 # and the VGA palette in addition to the VGA font.
 
-echo Saving font in /tmp/fontdata
-restorefont -w /tmp/fontdata
+TMPDIR=/tmp/${0##*/}.$$
+mkdir $TMPDIR || exit
+trap "rm -rf $TMPDIR" 0 1 2 3 7 13 15
+echo Saving font in $TMPDIR/fontdata
+restorefont -w $TMPDIR/fontdata
 startx
-echo Restoring font from /tmp/fontdata
-restorefont -r /tmp/fontdata
+echo Restoring font from $TMPDIR/fontdata
+restorefont -r $TMPDIR/fontdata
--- utils/savetextmode
+++ utils/savetextmode  1999/02/17 16:20:18
@@ -1,4 +1,14 @@
 #!/bin/sh
-rm -f /etc/vga/textregs /etc/vga/fontdata
-restoretextmode -w /etc/vga/textregs
-restorefont -w /etc/vga/fontdata
+set -o noclobber
+tmpfnt=/tmp/fontdata
+tmptxt=/tmp/textregs
+rm -f $tmpfnt $tmptxt
+if test -e $tmpfnt -o -e $tmptxt ; then
+       echo "$0: $tmpfnt and/or $tmptxt exists" 1>&2
+       exit 1
+fi
+echo Saving font in $tmpfnt
+echo Saving text in $tmptxt
+restoretextmode -w /dev/stdout > $tmptxt
+restorefont     -w /dev/stdout > $tmpfnt
+
--- utils/textmode
+++ utils/textmode      1999/02/17 16:20:18
@@ -1,4 +1,4 @@
 #!/bin/sh
 restoretextmode -r /etc/vga/textregs
-restorefont -r /etc/vga/fontdata
+restorefont     -r /tmp/fontdata
 restorepalette

Reply via email to