source: trunk/src/opengl/glide/swlibs/pcilib/fxphrlap.c

Last change on this file was 2887, checked in by sandervl, 26 years ago

Created swlibs dir

File size: 6.9 KB
Line 
1/*
2** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
3** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
4** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
5** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
6** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
7** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
8** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
9** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
10**
11** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
12** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
13** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
14** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
15** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
16** THE UNITED STATES.
17**
18** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
19*/
20
21#include <stdlib.h>
22#include <i86.h>
23#include <dos.h>
24#include <pharlap.h>
25#include <hw386.h>
26#include <fxpci.h>
27#include <pcilib.h>
28#include "fxphrlap.h"
29
30#define PHARLAP_INTERRUPT 0x21
31#define PHARLAP_UNSPECIFIED_ERROR 1
32
33static char pciIdent[] = "@#% fxPCI for PHARLAP";
34
35FxBool pciInitializeDDio(void)
36{
37 if (pciIdent[0]);
38 return(FXTRUE);
39}
40
41/*
42** pciPhrlapGetSegmentLinearBase (_dx_tolinear)
43*/
44int pciPhrlapGetSegmentLinearBase( USHORT selector, ULONG* lin_addrp )
45{
46 union REGS r;
47
48 /*
49 ** Phar Lap 2508h - Get Segment Linear Base Address
50 */
51 r.w.ax = 0x2508;
52
53 /*
54 ** BX segment selector
55 */
56 r.w.bx = (unsigned short) selector;
57 int386( PHARLAP_INTERRUPT, &r, &r );
58
59 if ( r.w.cflag )
60 {
61 return PHARLAP_UNSPECIFIED_ERROR;
62 }
63
64 else
65 {
66 /*
67 ** ECX linear base address of segment
68 */
69 *lin_addrp = (ULONG) r.x.ecx;
70 return 0;
71 }
72}
73
74/*
75** pciPhrlapMapPhysMemEndSegment (_dx_map_phys)
76*/
77int pciPhrlapMapPhysMemEndSegment( USHORT selector, ULONG phys_addr, ULONG page_cnt, ULONG* offsetp )
78{
79 union REGS r;
80 struct SREGS sr;
81
82 /*
83 ** Phar Lap 250ah - Map Physical Memory at End of Segment
84 */
85 r.w.ax = 0x250a;
86
87 /*
88 ** ES segment selector in the LDT of segment to modify
89 ** EBX physical base address of memory to map, must be a multiple of four kilobytes
90 ** ECX number of physical 4-KB memory pages to map
91 */
92 r.x.ebx = (unsigned int) phys_addr;
93 r.x.ecx = (unsigned int) page_cnt;
94 segread( &sr );
95 sr.es = selector;
96 int386x( PHARLAP_INTERRUPT, &r, &r, &sr );
97
98 if ( r.w.cflag )
99 {
100 /*
101 ** EAX error code
102 */
103 return r.x.eax;
104 }
105
106 else
107 {
108 /*
109 ** EAX offset in segment of mapped memory
110 */
111 *offsetp = (ULONG) r.x.eax;
112 return 0;
113 }
114}
115
116/*
117** pciPhrlapGetConfigInfo (_dx_config_inf)
118*/
119void pciPhrlapGetConfigInfo( CONFIG_INF* configp, UCHAR* swf_namep )
120{
121 union REGS r;
122
123 /*
124 ** Phar Lap 2526h - Get Configuration Information
125 */
126 r.w.ax = 0x2526;
127
128 /*
129 ** EBX 512 byte configuration buffer
130 ** ECX 256 byte buffer for name and path of 386 | VMM swap file
131 */
132 r.x.ebx = (unsigned int) configp;
133 r.x.ecx = (unsigned int) swf_namep;
134 int386( PHARLAP_INTERRUPT, &r, &r );
135}
136
137/*
138** pciPhrlapReadPageTableEntry (_dx_rd_ptinfn)
139*/
140int pciPhrlapReadPageTableEntry( ULONG linadr, ULONG* ptep, ULONG* ptinfp )
141{
142 union REGS r;
143
144 /*
145 ** Phar Lap 252bh/9 - Read Page Table Entry and Associated Information
146 */
147 r.w.ax = 0x252b;
148 r.h.bh = 0x9;
149 r.h.bl = 0x0; /* select linear */
150
151 /*
152 ** ECX linear address to read PTE for
153 */
154 r.x.ecx = linadr;
155 int386( PHARLAP_INTERRUPT, &r, &r );
156
157 if ( r.w.cflag )
158 {
159 /*
160 ** EAX error code
161 */
162 return r.x.eax;
163 }
164
165 else
166 {
167 /*
168 ** EAX page table entry
169 ** EBX additional page table information
170 */
171 *ptep = (ULONG) r.x.eax;
172 *ptinfp = (ULONG) r.x.ebx;
173 return 0;
174 }
175}
176
177/*
178** pciPhrlapWritePageTableEntry (_dx_wr_ptinfn)
179*/
180int pciPhrlapWritePageTableEntry( ULONG linadr, ULONG pte, ULONG ptinf )
181{
182 union REGS r;
183
184 /*
185 ** Phar Lap 252bh/10 - Write Page Table Entry and Associated Information
186 */
187 r.w.ax = 0x252b;
188 r.h.bh = 0xa;
189 r.h.bl = 0x0; /* select linear */
190
191 /*
192 ** ECX linear address to read PTE for
193 ** ESI page table entry
194 ** EDI additional page table information
195 */
196 r.x.ecx = linadr;
197 r.x.esi = pte;
198 r.x.edi = ptinf;
199
200 int386( PHARLAP_INTERRUPT, &r, &r );
201
202 if ( r.w.cflag )
203 {
204 /*
205 ** EAX error code
206 */
207 return r.x.eax;
208 }
209
210 else
211 {
212 return 0;
213 }
214}
215
216FX_EXPORT FxBool FX_CSTYLE
217pciMapPhysicalToLinear( FxU32 *linear_addr, FxU32 physical_addr,
218 FxU32 *length )
219{
220 CONFIG_INF config; /* information about Phar Lap environment */
221 ULONG DevPageCount; /* page count of device memory */
222 ULONG LinBase; /* linear base address of ds segment */
223 ULONG pDev; /* linear ptr where device is mapped */
224 UINT DevSize; /* page-aligned size of device memory */
225 ULONG pDevPage; /* linear scan ptr thru device pages */
226 ULONG pte; /* page table entry */
227 ULONG pti; /* page table info */
228
229 if ( !pciLibraryInitialized ) {
230 pciErrorCode = PCI_ERR_NOTOPEN;
231 return FXFALSE;
232 }
233
234 pciPhrlapGetConfigInfo( &config, (UCHAR*) &config );
235 DevPageCount = ((ULONG) *length) >> 12; /* 4 KB pages */
236 if ( pciPhrlapMapPhysMemEndSegment( config.c_ds_sel, physical_addr, DevPageCount, (ULONG*) linear_addr ) != 0 )
237 {
238 pciErrorCode = PCI_ERR_PHARLAP;
239 return FXFALSE;
240 }
241 /* This is per TNT DOS-Extender SDK 8.0 Release Notes */
242 /* pciPhrlapReadPageTableEntry & pciPhrlapWritePageTableEntry are not
243 supported under DPMI. */
244 /* xxx PE_PCD is supposed to be set by the DPMI map device in memory call--
245 do we need to use DPMI's versions of these or are we ok?
246 There doesn't seem to be corresponding calls for DPMI */
247 if ( !config.c_dpmif )
248 {
249 if ( pciPhrlapGetSegmentLinearBase( config.c_ds_sel, &LinBase ) != 0 )
250 {
251 pciErrorCode = PCI_ERR_PHARLAP;
252 return FXFALSE;
253 }
254 pDev = *linear_addr + LinBase;
255 DevSize = (UINT) *length;
256 /* Touch every page 0x1000 = 4 KB pages */
257 for ( pDevPage = pDev; pDevPage - pDev < DevSize; pDevPage += 0x1000 )
258 {
259 if ( pciPhrlapReadPageTableEntry( pDevPage, &pte, &pti ) != 0 )
260 {
261 pciErrorCode = PCI_ERR_PHARLAP;
262 return FXFALSE;
263 }
264 pte |= PE_PCD;
265 if ( pciPhrlapWritePageTableEntry( pDevPage, pte, pti ) != 0 )
266 {
267 pciErrorCode = PCI_ERR_PHARLAP;
268 return FXFALSE;
269 }
270 }
271 }
272}
273
274
275void pciUnmapPhysicalDD( FxU32 linear_addr, FxU32 length )
276{
277 return;
278}
279
280FX_EXPORT FxBool FX_CSTYLE
281pciClose( void )
282{
283 if ( !pciLibraryInitialized ) {
284 pciErrorCode = PCI_ERR_NOTOPEN2;
285 return FXFALSE;
286 }
287 pciLibraryInitialized = FXFALSE;
288 return FXTRUE;
289}
Note: See TracBrowser for help on using the repository browser.