Commit 8f634a65 authored by Keith Packard's avatar Keith Packard
Browse files

Add VGA BIOS modes to Tiny-X Xvesa server

parent f16d5d68
XCOMM $XConsortium: Imakefile /main/10 1996/12/02 10:20:33 lehors $
XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/trident/Imakefile,v 1.4 2000/09/15 07:25:12 keithp Exp $
XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/trident/Imakefile,v 1.5 2000/09/19 23:49:55 keithp Exp $
KDRIVE=..
#include "../Kdrive.tmpl"
......@@ -7,7 +7,7 @@ SRCS = trident.c tridentdraw.c tridentcurs.c tridentstub.c
OBJS = trident.o tridentdraw.o tridentcurs.o tridentstub.o
DEFINES = -DVESA
DEFINES = -DVESA /* -DUSE_PCI*/
INCLUDES = -I. $(KDINCS) -I$(KDRIVE)/fbdev -I$(KDRIVE)/vesa
......
......@@ -21,7 +21,7 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $XFree86: xc/programs/Xserver/hw/kdrive/trident/trident.c,v 1.12 2000/09/27 20:46:36 keithp Exp $ */
/* $XFree86: xc/programs/Xserver/hw/kdrive/trident/trident.c,v 1.13 2000/10/11 06:04:40 keithp Exp $ */
#include "trident.h"
#define extern
......@@ -33,14 +33,32 @@
Bool
tridentCardInit (KdCardInfo *card)
{
int k;
char *pixels;
int k;
char *pixels;
TridentCardInfo *tridentc;
CARD8 r39;
tridentc = (TridentCardInfo *) xalloc (sizeof (TridentCardInfo));
if (!tridentc)
return FALSE;
iopl (3);
tridentc->cop_base = (CARD8 *) KdMapDevice (TRIDENT_COP_BASE(card),
TRIDENT_COP_SIZE(card));
tridentc->cop = (Cop *) (tridentc->cop_base + TRIDENT_COP_OFF(card));
tridentc->mmio = FALSE;
r39 = tridentReadIndex (tridentc, 0x3d4, 0x39);
if (r39 & 1)
{
tridentc->mmio = TRUE;
r39 = tridentReadIndex (tridentc, 0x3d4, 0x39);
if ((r39 & 1) == 0)
{
ErrorF ("Trident: inconsisent IO mapping values\n");
return FALSE;
}
}
#ifdef VESA
if (!vesaInitialize (card, &tridentc->vesa))
#else
......@@ -51,11 +69,6 @@ tridentCardInit (KdCardInfo *card)
return FALSE;
}
iopl (3);
tridentc->cop_base = (CARD8 *) KdMapDevice (TRIDENT_COP_BASE(card),
TRIDENT_COP_SIZE(card));
tridentc->cop = (Cop *) (tridentc->cop_base + TRIDENT_COP_OFF(card));
tridentc->mmio = FALSE;
#ifdef USE_PCI
tridentc->window = (CARD32 *) (tridentc->cop_base + 0x10000);
#else
......@@ -92,15 +105,32 @@ tridentScreenInit (KdScreenInfo *screen)
if (tridents->vesa.mapping != VESA_LINEAR)
screen->dumb = TRUE;
tridents->screen = tridents->vesa.fb;
memory = tridents->vesa.fb_size;
#else
tridents->screen = tridentc->fb.fb;
memory = (2048 + 512) * 1024;
#endif
screen_size = screen->fb[0].byteStride * screen->height;
memory = (2048 + 512) * 1024;
if (tridents->screen && memory >= screen_size + 2048)
{
memory -= 2048;
tridents->cursor_base = tridents->screen + memory - 2048;
}
else
tridents->cursor_base = 0;
memory -= screen_size;
#if 0
if (memory > screen->fb[0].byteStride)
{
screen->off_screen = tridents->screen + screen_size;
screen->off_screen_size = memory - screen_size;
}
else
{
screen->off_screen = 0;
screen->off_screen_size = 0;
}
#endif
screen->driver = tridents;
return TRUE;
}
......
......@@ -21,7 +21,7 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $XFree86: xc/programs/Xserver/hw/kdrive/trident/trident.h,v 1.6 2000/09/15 07:25:12 keithp Exp $ */
/* $XFree86: xc/programs/Xserver/hw/kdrive/trident/trident.h,v 1.7 2000/10/11 06:04:40 keithp Exp $ */
#ifndef _TRIDENT_H_
#define _TRIDENT_H_
......@@ -34,7 +34,6 @@
/*
* offset from ioport beginning
*/
#define USE_PCI
#ifdef USE_PCI
#define TRIDENT_COP_BASE(c) (c->attr.address[1])
......@@ -219,6 +218,8 @@ typedef struct _tridentScreenInfo {
#endif
CARD8 *cursor_base;
CARD8 *screen;
CARD8 *off_screen;
int off_screen_size;
TridentCursor cursor;
} TridentScreenInfo;
......
XCOMM $XFree86$
XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/vesa/Imakefile,v 1.2 2000/09/03 05:11:22 keithp Exp $
KDRIVE=..
#include "../Kdrive.tmpl"
SRCS = vesa.c vesainit.c vbe.c
SRCS = vesa.c vesainit.c vbe.c vga.c vm86.c
OBJS = vesa.o vesainit.o vbe.o
OBJS = vesa.o vesainit.o vbe.o vga.o vm86.o
INCLUDES = -I. $(KDINCS)
......
.\" $XFree86$
.\" $XFree86: xc/programs/Xserver/hw/kdrive/vesa/Xvesa.man,v 1.2 2000/09/03 05:11:22 keithp Exp $
.TH Xvesa 1
.SH NAME
Xvesa \- VESA VBE tiny X server
......@@ -11,10 +11,13 @@ Xvesa \- VESA VBE tiny X server
is a generic X server for Linux on the x86 platform.
.B Xvesa
doesn't know about any particular hardware, and sets the video mode by
running the video BIOS in VM86 mode.
running the video BIOS in VM86 mode.
.B Xvesa
therefore runs untrusted code with full priviledges, and is one of the
most insecure X servers available.
.B Xvesa
uses both standard VGA BIOS modes and any modes advertised by a VESA 2.0
BIOS if available.
.B Run at your own risk.
.SH OPTIONS
In addition to the normal tiny-X server's options (to be described in
......@@ -28,9 +31,9 @@ specifies the VESA video mode to use. If mode
is not supported by your BIOS and hardware,
.B Xvesa
will fail, hang your system, or make your monitor explode; you are on
your own. This option is ignored if the
your own. This option overrides any
.B -screen
option was used.
options.
.TP 8
.B -listmodes
tells the server to list all supported video modes. If
......@@ -55,8 +58,11 @@ don't use a linear framebuffer even if one is available. You don't
want to use this option.
.TP 8
.B -swaprgb
pass RGB values in the order that works on my machine. Use this if
pass RGB values in the order that works on broken BIOSes. Use this if
the colours are wrong in PseudoColor modes.
.TP 8
.B -verbose
emit diagnostic messages during BIOS initialization and teardown.
.SH KEYBOARD
Xvesa handles the keyboard in the same manner as the
.B Xfbdev
......@@ -69,10 +75,17 @@ assumed to be buggy. Allowing your users to run
is a major security hole. Allowing yourself to run
.B Xvesa
is probably a mistake.
.B Xvesa
records the current BIOS mode when it starts and restores that mode on
termination; if the video card has been reprogrammed by another application,
the display will almost certainly be trashed. The alternative of saving and
restoring the complete video card state has proven unreliable on most video
cards.
.SH SEE ALSO
X(1), Xserver(1), xdm(1), xinit(1), Xfbdev(1).
.SH AUTHORS
The tiny-X server was written by Keith Packard, and the VESA driver
was added by Juliusz Chroboczek who didn't realise what he was doing
until it was too late. Tiny-X uses code from XFree86, which in turn
is based on the Sample Implementation.
is based on the Sample Implementation. Keith Packard then added support for
standard VGA BIOS modes and is especially proud of 320x200 16 color mode.
This diff is collapsed.
......@@ -28,56 +28,6 @@ THE SOFTWARE.
#define VBE_WINDOW_READ 2
#define VBE_WINDOW_WRITE 4
#ifndef U8
#define U8 unsigned char
#define U16 unsigned short
#define U32 unsigned int
#endif
/* The whole addressable memory */
#define SYSMEM_BASE 0x00000
#define SYSMEM_SIZE 0x100000
/* Interrupt vectors and BIOS data area */
/* This is allocated privately from /dev/mem */
#define MAGICMEM_BASE 0x00000
#define MAGICMEM_SIZE 0x01000
/* The low memory, allocated privately from /dev/zero */
/* 64KB should be enough for anyone, as they used to say */
#define LOMEM_BASE 0x10000
#define LOMEM_SIZE 0x10000
/* The video memory and BIOS ROM, allocated shared from /dev/mem */
#define HIMEM_BASE 0xA0000
#define HIMEM_SIZE (SYSMEM_BASE + SYSMEM_SIZE - HIMEM_BASE)
/* The BIOS ROM */
#define ROM_BASE 0xC0000
#define ROM_SIZE 0x30000
#define STACK_SIZE 0x1000
#define POINTER_SEGMENT(ptr) (((unsigned int)ptr)>>4)
#define POINTER_OFFSET(ptr) (((unsigned int)ptr)&0x000F)
#define MAKE_POINTER(seg, off) (((((unsigned int)(seg))<<4) + (unsigned int)(off)))
#define MAKE_POINTER_1(lw) MAKE_POINTER(((lw)&0xFFFF0000)/0x10000, (lw)&0xFFFF)
#define ALLOC_FAIL ((U32)-1)
typedef struct _VbeInfoRec {
int devmem, devzero;
void *magicMem, *loMem, *hiMem;
U32 brk;
struct vm86_struct vms;
U32 ret_code, stack_base, vib_base, vmib_base, statebuffer_base, palette_scratch_base;
U8 palette_format;
int palette_wait;
int windowA_offset;
int windowB_offset;
int last_window;
int vga_palette;
} VbeInfoRec, *VbeInfoPtr;
typedef struct _VbeInfoBlock {
U8 VbeSignature[4]; /* VBE Signature */
U16 VbeVersion; /* VBE Version */
......@@ -134,6 +84,15 @@ typedef struct _VbeModeInfoBlock {
U8 Reserved2[206]; /* remainder of ModeInfoBlock */
} __attribute__((packed)) VbeModeInfoBlock;
typedef struct _VbeInfoRec {
U8 palette_format;
int palette_wait;
int windowA_offset;
int windowB_offset;
int window_size;
int last_window;
VbeModeInfoBlock vmib;
} VbeInfoRec, *VbeInfoPtr;
typedef struct _SupVbeInfoBlock {
U8 SupVbeSignature[7]; /* Supplemental VBE Signature */
......@@ -147,32 +106,58 @@ typedef struct _SupVbeInfoBlock {
U8 Reserved[221]; /* Reserved */
} __attribute__((packed)) SupVbeInfoBlock;
VbeInfoPtr VbeSetup(void);
void VbeCleanup(VbeInfoPtr vi);
VbeInfoBlock *VbeGetInfo(VbeInfoPtr vi);
VbeModeInfoBlock *VbeGetModeInfo(VbeInfoPtr vi, int mode);
int VbeSetMode(VbeInfoPtr vi, int mode, int linear);
int VbeGetMode(VbeInfoPtr vi, int *mode);
int VbeSetupStateBuffer(VbeInfoPtr vi);
int VbeSaveState(VbeInfoPtr vi);
int VbeRestoreState(VbeInfoPtr vi);
void *VbeMapFramebuffer(VbeInfoPtr vi, VbeModeInfoBlock *vmib);
int VbeUnmapFrambuffer(VbeInfoPtr vi, VbeModeInfoBlock *vmib, void *fb);
int VbeSetPalette(VbeInfoPtr vi, int first, int number, U8 *entries);
int VbeSetPaletteOptions(VbeInfoPtr vi, U8 bits, int wait);
void *VbeSetWindow(VbeInfoPtr vi, int offset, int purpose, int *size_return);
int VbeReportInfo(VbeInfoPtr, VbeInfoBlock *);
int VbeReportModeInfo(VbeInfoPtr, U16 mode, VbeModeInfoBlock *);
int VbeDoInterrupt(VbeInfoPtr, int num);
int VbeDoInterrupt10(VbeInfoPtr vi);
int VbeIsMemory(VbeInfoPtr vi, U32 i);
U8 VbeMemory(VbeInfoPtr, U32);
U16 VbeMemoryW(VbeInfoPtr, U32);
U32 VbeMemoryL(VbeInfoPtr, U32);
void VbeWriteMemory(VbeInfoPtr, U32, U8);
void VbeWriteMemoryW(VbeInfoPtr, U32, U16);
void VbeWriteMemoryL(VbeInfoPtr, U32, U32);
int VbeAllocateMemory(VbeInfoPtr, int);
void VbeDebug(VbeInfoPtr vi);
int
VbeGetVib (Vm86InfoPtr vi, VbeInfoBlock *vib);
int
VbeGetVmib (Vm86InfoPtr vi, int mode, VbeModeInfoBlock *vmib);
void
VbeReportInfo (Vm86InfoPtr vi);
int
VbeGetNmode (Vm86InfoPtr vi);
int
VbeGetModes (Vm86InfoPtr vi, VesaModePtr modes, int nmode);
int
VbeGetModeInfo(Vm86InfoPtr vi, int m, VesaModePtr mode);
VbeInfoPtr
VbeInit (Vm86InfoPtr vi);
int
VbeSetMode (Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, int linear);
int
VbeGetMode(Vm86InfoPtr vi, int *mode);
void *
VbeMapFramebuffer(Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, int *size);
void
VbeUnmapFramebuffer(Vm86InfoPtr vi, VbeInfoPtr vbe, int mode, void *fb);
int
VbeSetPalette(Vm86InfoPtr vi, VbeInfoPtr vbe, int first, int number, U8 *entries);
int
VbeGetPalette(Vm86InfoPtr vi, VbeInfoPtr vbe, int first, int number, U8 *entries);
int
VbeSetPaletteOptions(Vm86InfoPtr vi, VbeInfoPtr vbe, U8 bits, int wait);
void *
VbeSetWindow(Vm86InfoPtr vi, VbeInfoPtr vbe, int offset, int purpose, int *size_return);
int
VbeReportVib(Vm86InfoPtr vi, VbeInfoBlock *vib);
int
VbeReportModeInfo(Vm86InfoPtr vi, U16 mode, VbeModeInfoBlock *vmib);
int
VbeDoInterrupt10(Vm86InfoPtr vi);
#endif
This diff is collapsed.
......@@ -25,54 +25,127 @@ THE SOFTWARE.
#define _VESA_H_
#include "kdrive.h"
#include <sys/vm86.h>
#include "vbe.h"
#include "vm86.h"
#define VESA_TEXT_SAVE (64*1024)
#define MODE_SUPPORTED 0x01
#define MODE_COLOUR 0x08
#define MODE_GRAPHICS 0x10
#define MODE_VGA 0x20
#define MODE_LINEAR 0x80
#define MODE_DIRECT 0x1
#define MEMORY_TEXT 0
#define MEMORY_CGA 1
#define MEMORY_HERCULES 2
#define MEMORY_PLANAR 3
#define MEMORY_PSEUDO 4
#define MEMORY_NONCHAIN 5
#define MEMORY_DIRECT 6
#define MEMORY_YUV 7
typedef struct _VesaMode {
int mode;
VbeModeInfoBlock vmib;
int mode; /* mode number */
int vbe; /* a VBE mode */
int ModeAttributes; /* mode attributes */
int NumberOfPlanes; /* number of memory planes */
int BitsPerPixel; /* bits per pixel */
int MemoryModel; /* memory model type */
int RedMaskSize; /* size of direct color red mask in bits */
int RedFieldPosition; /* bit position of lsb of red mask */
int GreenMaskSize; /* size of direct color green mask in bits */
int GreenFieldPosition; /* bit position of lsb of green mask */
int BlueMaskSize; /* size of direct color blue mask in bits */
int BlueFieldPosition; /* bit position of lsb of blue mask */
int RsvdMaskSize; /* size of direct color reserved mask bits*/
int RsvdFieldPosition; /* bit position of lsb of reserved mask */
int DirectColorModeInfo; /* direct color mode attributes */
int XResolution; /* horizontal resolution */
int YResolution; /* vertical resolution */
int BytesPerScanLine; /* bytes per scan line */
} VesaModeRec, *VesaModePtr;
#include "vbe.h"
#include "vga.h"
typedef struct _VesaCardPriv {
VbeInfoPtr vi;
VbeInfoBlock *vib;
int vbe;
Vm86InfoPtr vi;
VesaModePtr modes;
int nmode;
char text[VESA_TEXT_SAVE];
int nmode;
int vga_palette;
int old_vbe_mode;
int old_vga_mode;
VbeInfoPtr vbeInfo;
char text[VESA_TEXT_SAVE];
} VesaCardPrivRec, *VesaCardPrivPtr;
#define VESA_LINEAR 0
#define VESA_WINDOWED 1
#define VESA_PLANAR 2
#define VESA_MONO 3
typedef struct _VesaScreenPriv {
VesaModePtr mode;
Bool shadow;
Bool rotate;
int mapping;
int origDepth;
void *fb;
void *fb;
int fb_size;
} VesaScreenPrivRec, *VesaScreenPrivPtr;
extern int vesa_video_mode;
extern Bool vesa_force_mode;
Bool vesaListModes(void);
Bool vesaInitialize(KdCardInfo *card, VesaCardPrivPtr priv);
Bool vesaCardInit(KdCardInfo *card);
Bool vesaInitialize (KdCardInfo *card, VesaCardPrivPtr priv);
Bool vesaScreenInitialize (KdScreenInfo *screen, VesaScreenPrivPtr pscr);
Bool vesaScreenInit(KdScreenInfo *screen);
Bool vesaInitScreen(ScreenPtr pScreen);
Bool vesaEnable(ScreenPtr pScreen);
void vesaDisable(ScreenPtr pScreen);
void vesaPreserve(KdCardInfo *card);
void vesaRestore(KdCardInfo *card);
void vesaCardFini(KdCardInfo *card);
void vesaScreenFini(KdScreenInfo *screen);
void vesaPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
void vesaGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
int vesaProcessArgument (int argc, char **argv, int i);
void
vesaListModes(void);
Bool
vesaInitialize(KdCardInfo *card, VesaCardPrivPtr priv);
Bool
vesaCardInit(KdCardInfo *card);
Bool
vesaInitialize (KdCardInfo *card, VesaCardPrivPtr priv);
Bool
vesaScreenInitialize (KdScreenInfo *screen, VesaScreenPrivPtr pscr);
Bool
vesaScreenInit(KdScreenInfo *screen);
Bool
vesaInitScreen(ScreenPtr pScreen);
Bool
vesaEnable(ScreenPtr pScreen);
void
vesaDisable(ScreenPtr pScreen);
void
vesaPreserve(KdCardInfo *card);
void
vesaRestore(KdCardInfo *card);
void
vesaCardFini(KdCardInfo *card);
void
vesaScreenFini(KdScreenInfo *screen);
void
vesaPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
void
vesaGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
int
vesaProcessArgument (int argc, char **argv, int i);
#endif _VESA_H_
......@@ -23,7 +23,7 @@ THE SOFTWARE.
#include "vesa.h"
KdCardFuncs vesaFuncs = {
const KdCardFuncs vesaFuncs = {
vesaCardInit, /* cardinit */
vesaScreenInit, /* scrinit */
vesaInitScreen, /* initScreen */
......
/*
* $XFree86$
*
* Copyright 2000 Keith Packard, member of The XFree86 Project, Inc.
*
* 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 name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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.
*/
#include "vesa.h"
static const VesaModeRec vgaModes[] = {
{
6, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
1, 1, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
640, 200, 80,
},
{
0xd, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
4, 4, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
320, 200, 40,
},
{
0xe, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
4, 4, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
640, 200, 80,
},
{
0x10, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
4, 4, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
640, 350, 80,
},
{
0x11, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_LINEAR,
1, 1, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
640, 480, 80,
},
{
0x12, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR,
4, 4, MEMORY_PLANAR,
0, 0, 0, 0, 0, 0, 0, 0, 0,
640, 480, 80,
},
{
0x13, 0,
MODE_SUPPORTED | MODE_GRAPHICS | MODE_VGA | MODE_COLOUR | MODE_LINEAR,
8, 8, MEMORY_PSEUDO,
0, 0, 0, 0, 0, 0, 0, 0, 0,
320, 200, 320,
},
};
#define NUM_VGA_MODE (sizeof vgaModes / sizeof vgaModes[0])
int
VgaGetNmode (Vm86InfoPtr vi)
{
return NUM_VGA_MODE;
}
int
VgaGetModes (Vm86InfoPtr vi, VesaModePtr mode, int nmode)
{
if (nmode > NUM_VGA_MODE)
nmode = NUM_VGA_MODE;
memcpy (mode, vgaModes, nmode * sizeof (VesaModeRec));
return nmode;
}
int