1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
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
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.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: 32-bit DOS
27 * Description: Main C module for the VFlat framebuffer routines. The page
28 * fault handler is always installed to handle up to a 4Mb
29 * framebuffer with a window size of 4Kb or 64Kb in size.
31 ****************************************************************************/
37 /*-------------------------------------------------------------------------*/
38 /* DOS4G/W, PMODE/W and CauseWay support. */
39 /*-------------------------------------------------------------------------*/
43 #define VFLAT_START_ADDR 0xF0000000U
44 #define VFLAT_END_ADDR 0xF03FFFFFU
45 #define VFLAT_LIMIT (VFLAT_END_ADDR - VFLAT_START_ADDR)
46 #define PAGE_PRESENT 1
47 #define PAGE_NOTPRESENT 0
51 PRIVATE ibool installed = false;
52 PRIVATE ibool haveDPMI = false;
53 PUBLIC ibool _ASMAPI VF_haveCauseWay = false;
54 PUBLIC uchar * _ASMAPI VF_zeroPtr = NULL;
56 /* Low level assembler code */
58 int _ASMAPI InitPaging(void);
59 void _ASMAPI ClosePaging(void);
60 void _ASMAPI MapPhysical2Linear(ulong pAddr, ulong lAddr, int pages, int flags);
61 void _ASMAPI InstallFaultHandler(ulong baseAddr,int bankSize);
62 void _ASMAPI RemoveFaultHandler(void);
63 void _ASMAPI InstallBankFunc(int codeLen,void *bankFunc);
65 void * _ASMAPI VF_malloc(uint size)
66 { return PM_malloc(size); }
68 void _ASMAPI VF_free(void *p)
71 PRIVATE ibool CheckDPMI(void)
72 /****************************************************************************
75 * Returns: True if we are running under DPMI
77 ****************************************************************************/
84 /* Check if we are running under DPMI in which case we will not be
85 * able to install our page fault handlers. We can however use the
86 * DVA.386 or VFLATD.386 virtual device drivers if they are present.
89 PM_int386(0x31,®s,®s);
90 if (!regs.x.cflag && (regs.e.edi & 8))
91 return (haveDPMI = true);
95 ibool PMAPI VF_available(void)
96 /****************************************************************************
98 * Function: VF_available
99 * Returns: True if virtual buffer is available, false if not.
101 ****************************************************************************/
104 VF_zeroPtr = PM_mapPhysicalAddr(0,0xFFFFFFFF,true);
108 /* Standard DOS4GW, PMODE/W and Causeway */
109 if (InitPaging() == -1)
115 void * PMAPI InitDPMI(ulong baseAddr,int bankSize,int codeLen,void *bankFunc)
116 /****************************************************************************
118 * Function: InitDOS4GW
119 * Parameters: baseAddr - Base address of framebuffer bank window
120 * bankSize - Physical size of banks in Kb (4 or 64)
121 * codeLen - Length of 32 bit bank switch function
122 * bankFunc - Pointer to protected mode bank function
123 * Returns: Near pointer to virtual framebuffer, or NULL on failure.
125 * Description: Installs the virtual linear framebuffer handling for
126 * DPMI environments. This requires the DVA.386 or VFLATD.386
127 * virtual device drivers to be installed and functioning.
129 ****************************************************************************/
138 void * PMAPI InitDOS4GW(ulong baseAddr,int bankSize,int codeLen,void *bankFunc)
139 /****************************************************************************
141 * Function: InitDOS4GW
142 * Parameters: baseAddr - Base address of framebuffer bank window
143 * bankSize - Physical size of banks in Kb (4 or 64)
144 * codeLen - Length of 32 bit bank switch function
145 * bankFunc - Pointer to protected mode bank function
146 * Returns: Near pointer to virtual framebuffer, or NULL on failure.
148 * Description: Installs the virtual linear framebuffer handling for
149 * the DOS4GW extender.
151 ****************************************************************************/
155 if (InitPaging() == -1)
156 return NULL; /* Cannot do hardware paging! */
158 /* Map 4MB of video memory into linear address space (read/write) */
159 if (bankSize == 64) {
160 for (i = 0; i < 64; i++) {
161 MapPhysical2Linear(baseAddr,VFLAT_START_ADDR+(i<<16),16,
162 PAGE_WRITE | PAGE_NOTPRESENT);
166 for (i = 0; i < 1024; i++) {
167 MapPhysical2Linear(baseAddr,VFLAT_START_ADDR+(i<<12),1,
168 PAGE_WRITE | PAGE_NOTPRESENT);
172 /* Install our page fault handler and banks switch function */
173 InstallFaultHandler(baseAddr,bankSize);
174 InstallBankFunc(codeLen,bankFunc);
176 return (void*)VFLAT_START_ADDR;
179 void * PMAPI VF_init(ulong baseAddr,int bankSize,int codeLen,void *bankFunc)
180 /****************************************************************************
183 * Parameters: baseAddr - Base address of framebuffer bank window
184 * bankSize - Physical size of banks in Kb (4 or 64)
185 * codeLen - Length of 32 bit bank switch function
186 * bankFunc - Pointer to protected mode bank function
187 * Returns: Near pointer to virtual framebuffer, or NULL on failure.
189 * Description: Installs the virtual linear framebuffer handling.
191 ****************************************************************************/
194 return (void*)VFLAT_START_ADDR;
196 return NULL; /* Bank function is too large! */
198 VF_zeroPtr = PM_mapPhysicalAddr(0,0xFFFFFFFF,true);
200 return InitDPMI(baseAddr,bankSize,codeLen,bankFunc);
201 return InitDOS4GW(baseAddr,bankSize,codeLen,bankFunc);
204 void PMAPI VF_exit(void)
205 /****************************************************************************
209 * Description: Closes down the virtual framebuffer services and
210 * restores the previous page fault handler.
212 ****************************************************************************/
219 /* Standard DOS4GW and PMODE/W support */
220 RemoveFaultHandler();
227 /*-------------------------------------------------------------------------*/
228 /* Support mapped out for other compilers. */
229 /*-------------------------------------------------------------------------*/
233 ibool PMAPI VF_available(void)
238 void * PMAPI VF_init(ulong baseAddr,int bankSize,int codeLen,void *bankFunc)
247 void PMAPI VF_exit(void)