Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / isvesa.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  any
26 *
27 * Description:  Test program to check the ability to allocate real mode
28 *               memory and to call real mode interrupt handlers such as
29 *               the VESA VBE BIOS from protected mode. Compile and link
30 *               with the appropriate command line for your DOS extender.
31 *
32 *               Functions tested:   PM_getVESABuf()
33 *                                   PM_mapRealPointer()
34 *                                   PM_int86x()
35 *
36 ****************************************************************************/
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include "pmapi.h"
42
43 /* SuperVGA information block */
44
45 #pragma pack(1)
46
47 typedef struct {
48     char    VESASignature[4];       /* 'VESA' 4 byte signature          */
49     short   VESAVersion;            /* VBE version number               */
50     ulong   OEMStringPtr;           /* Far pointer to OEM string        */
51     ulong   Capabilities;           /* Capabilities of video card       */
52     ulong   VideoModePtr;           /* Far pointer to supported modes   */
53     short   TotalMemory;            /* Number of 64kb memory blocks     */
54     char    reserved[236];          /* Pad to 256 byte block size       */
55     } VgaInfoBlock;
56
57 #pragma pack()
58
59 int main(void)
60 {
61     RMREGS          regs;
62     RMSREGS         sregs;
63     VgaInfoBlock    vgaInfo;
64     ushort          *mode;
65     uint            vgLen;
66     uchar           *vgPtr;
67     unsigned        r_vgseg,r_vgoff;
68
69     printf("Program running in ");
70     switch (PM_getModeType()) {
71         case PM_realMode:
72             printf("real mode.\n\n");
73             break;
74         case PM_286:
75             printf("16 bit protected mode.\n\n");
76             break;
77         case PM_386:
78             printf("32 bit protected mode.\n\n");
79             break;
80         }
81
82     /* Allocate a 256 byte block of real memory for communicating with
83      * the VESA BIOS.
84      */
85     if ((vgPtr = PM_getVESABuf(&vgLen,&r_vgseg,&r_vgoff)) == NULL) {
86         printf("Unable to allocate VESA memory buffer!\n");
87         exit(1);
88         }
89
90     /* Call the VESA VBE to see if it is out there */
91     regs.x.ax = 0x4F00;
92     regs.x.di = r_vgoff;
93     sregs.es = r_vgseg;
94     memcpy(vgPtr,"VBE2",4);
95     PM_int86x(0x10, &regs, &regs, &sregs);
96     memcpy(&vgaInfo,vgPtr,sizeof(VgaInfoBlock));
97     if (regs.x.ax == 0x4F && strncmp(vgaInfo.VESASignature,"VESA",4) == 0) {
98         printf("VESA VBE version %d.%d BIOS detected\n\n",
99             vgaInfo.VESAVersion >> 8, vgaInfo.VESAVersion & 0xF);
100         printf("Available video modes:\n");
101         mode = PM_mapRealPointer(vgaInfo.VideoModePtr >> 16, vgaInfo.VideoModePtr & 0xFFFF);
102         while (*mode != 0xFFFF) {
103             printf("    %04hXh (%08X)\n", *mode, (int)mode);
104             mode++;
105             }
106         }
107     else
108         printf("VESA VBE not found\n");
109     return 0;
110 }