Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / tests / callreal.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 call a real mode
28 *               procedure. We simply copy a terribly simple assembly
29 *               language routine into a real mode block that we allocate,
30 *               and then attempt to call the routine and verify that it
31 *               was successful.
32 *
33 *               Functions tested:   PM_allocRealSeg()
34 *                                   PM_freeRealSeg()
35 *                                   PM_callRealMode()
36 *
37 ****************************************************************************/
38
39 #include <stdlib.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include "pmapi.h"
43
44 /* Block of real mode code we will eventually call */
45
46 static unsigned char realModeCode[] = {
47     0x93,           /*  xchg    ax,bx   */
48     0x87, 0xCA,     /*  xchg    cx,dx   */
49     0xCB            /*  retf            */
50     };
51
52 int main(void)
53 {
54     RMREGS          regs;
55     RMSREGS         sregs;
56     uchar           *p;
57     unsigned        r_seg,r_off;
58
59     printf("Program running in ");
60     switch (PM_getModeType()) {
61         case PM_realMode:
62             printf("real mode.\n\n");
63             break;
64         case PM_286:
65             printf("16 bit protected mode.\n\n");
66             break;
67         case PM_386:
68             printf("32 bit protected mode.\n\n");
69             break;
70         }
71
72     /* Allocate a the block of real mode memory */
73     if ((p = PM_allocRealSeg(sizeof(realModeCode), &r_seg, &r_off)) == NULL) {
74         printf("Unable to allocate real mode memory!\n");
75         exit(1);
76         }
77
78     /* Copy the real mode code */
79     memcpy(p,realModeCode,sizeof(realModeCode));
80
81     /* Now call the real mode code */
82     regs.x.ax = 1;
83     regs.x.bx = 2;
84     regs.x.cx = 3;
85     regs.x.dx = 4;
86     regs.x.si = 5;
87     regs.x.di = 6;
88     sregs.es = 7;
89     sregs.ds = 8;
90     PM_callRealMode(r_seg,r_off,&regs,&sregs);
91     if (regs.x.ax != 2 || regs.x.bx != 1 || regs.x.cx != 4 || regs.x.dx != 3
92             || regs.x.si != 5 || regs.x.di != 6 || sregs.es != 7
93             || sregs.ds != 8) {
94         printf("Real mode call failed!\n");
95         printf("\n");
96         printf("ax = %04X, bx = %04X, cx = %04X, dx = %04X\n",
97             regs.x.ax,regs.x.bx,regs.x.cx,regs.x.dx);
98         printf("si = %04X, di = %04X, es = %04X, ds = %04X\n",
99             regs.x.si,regs.x.di,sregs.es,sregs.ds);
100         }
101     else
102         printf("Real mode call succeeded!\n");
103
104     /* Free the memory we allocated */
105     PM_freeRealSeg(p);
106     return 0;
107 }