]>
Commit | Line | Data |
---|---|---|
c7de829c WD |
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: 80386 Assembler, TASM 4.0 or NASM | |
25 | ;* Environment: 32-bit Windows VxD | |
26 | ;* | |
27 | ;* Description: Low level assembly support for the PM library specific to | |
28 | ;* Windows VxDs. | |
29 | ;* | |
30 | ;**************************************************************************** | |
31 | ||
32 | IDEAL | |
33 | ||
34 | include "scitech.mac" ; Memory model macros | |
35 | ||
36 | header _pm ; Set up memory model | |
37 | ||
38 | begdataseg _pm | |
39 | ||
40 | cextern _PM_savedDS,USHORT | |
41 | ||
42 | enddataseg _pm | |
43 | ||
44 | P586 | |
45 | ||
46 | begcodeseg _pm ; Start of code segment | |
47 | ||
48 | ;---------------------------------------------------------------------------- | |
49 | ; void PM_segread(PMSREGS *sregs) | |
50 | ;---------------------------------------------------------------------------- | |
51 | ; Read the current value of all segment registers | |
52 | ;---------------------------------------------------------------------------- | |
53 | cprocstart PM_segread | |
54 | ||
55 | ARG sregs:DPTR | |
56 | ||
57 | enter_c | |
58 | ||
59 | mov ax,es | |
60 | _les _si,[sregs] | |
61 | mov [_ES _si],ax | |
62 | mov [_ES _si+2],cs | |
63 | mov [_ES _si+4],ss | |
64 | mov [_ES _si+6],ds | |
65 | mov [_ES _si+8],fs | |
66 | mov [_ES _si+10],gs | |
67 | ||
68 | leave_c | |
69 | ret | |
70 | ||
71 | cprocend | |
72 | ||
73 | ;---------------------------------------------------------------------------- | |
74 | ; int PM_int386x(int intno, PMREGS *in, PMREGS *out,PMSREGS *sregs) | |
75 | ;---------------------------------------------------------------------------- | |
76 | ; Issues a software interrupt in protected mode. This routine has been | |
77 | ; written to allow user programs to load CS and DS with different values | |
78 | ; other than the default. | |
79 | ;---------------------------------------------------------------------------- | |
80 | cprocstart PM_int386x | |
81 | ||
82 | ; Not used for VxDs | |
83 | ||
84 | ret | |
85 | ||
86 | cprocend | |
87 | ||
88 | ;---------------------------------------------------------------------------- | |
89 | ; void PM_saveDS(void) | |
90 | ;---------------------------------------------------------------------------- | |
91 | ; Save the value of DS into a section of the code segment, so that we can | |
92 | ; quickly load this value at a later date in the PM_loadDS() routine from | |
93 | ; inside interrupt handlers etc. The method to do this is different | |
94 | ; depending on the DOS extender being used. | |
95 | ;---------------------------------------------------------------------------- | |
96 | cprocstart PM_saveDS | |
97 | ||
98 | mov [_PM_savedDS],ds ; Store away in data segment | |
99 | ret | |
100 | ||
101 | cprocend | |
102 | ||
103 | ;---------------------------------------------------------------------------- | |
104 | ; void PM_loadDS(void) | |
105 | ;---------------------------------------------------------------------------- | |
106 | ; Routine to load the DS register with the default value for the current | |
107 | ; DOS extender. Only the DS register is loaded, not the ES register, so | |
108 | ; if you wish to call C code, you will need to also load the ES register | |
109 | ; in 32 bit protected mode. | |
110 | ;---------------------------------------------------------------------------- | |
111 | cprocstart PM_loadDS | |
112 | ||
113 | mov ds,[cs:_PM_savedDS] ; We can access the proper DS through CS | |
114 | ret | |
115 | ||
116 | cprocend | |
117 | ||
118 | ;---------------------------------------------------------------------------- | |
119 | ; void PM_setBankA(int bank) | |
120 | ;---------------------------------------------------------------------------- | |
121 | cprocstart PM_setBankA | |
122 | ||
123 | ; Not used for VxDs | |
124 | ||
125 | ret | |
126 | ||
127 | cprocend | |
128 | ||
129 | ;---------------------------------------------------------------------------- | |
130 | ; void PM_setBankAB(int bank) | |
131 | ;---------------------------------------------------------------------------- | |
132 | cprocstart PM_setBankAB | |
133 | ||
134 | ; Not used for VxDs | |
135 | ||
136 | ret | |
137 | ||
138 | cprocend | |
139 | ||
140 | ;---------------------------------------------------------------------------- | |
141 | ; void PM_setCRTStart(int x,int y,int waitVRT) | |
142 | ;---------------------------------------------------------------------------- | |
143 | cprocstart PM_setCRTStart | |
144 | ||
145 | ; Not used for VxDs | |
146 | ||
147 | ret | |
148 | ||
149 | cprocend | |
150 | ||
151 | ; Macro to delay briefly to ensure that enough time has elapsed between | |
152 | ; successive I/O accesses so that the device being accessed can respond | |
153 | ; to both accesses even on a very fast PC. | |
154 | ||
155 | ifdef USE_NASM | |
156 | %macro DELAY 0 | |
157 | jmp short $+2 | |
158 | jmp short $+2 | |
159 | jmp short $+2 | |
160 | %endmacro | |
161 | %macro IODELAYN 1 | |
162 | %rep %1 | |
163 | DELAY | |
164 | %endrep | |
165 | %endmacro | |
166 | else | |
167 | macro DELAY | |
168 | jmp short $+2 | |
169 | jmp short $+2 | |
170 | jmp short $+2 | |
171 | endm | |
172 | macro IODELAYN N | |
173 | rept N | |
174 | DELAY | |
175 | endm | |
176 | endm | |
177 | endif | |
178 | ||
179 | ;---------------------------------------------------------------------------- | |
180 | ; uchar _PM_readCMOS(int index) | |
181 | ;---------------------------------------------------------------------------- | |
182 | ; Read the value of a specific CMOS register. We do this with both | |
183 | ; normal interrupts and NMI disabled. | |
184 | ;---------------------------------------------------------------------------- | |
185 | cprocstart _PM_readCMOS | |
186 | ||
187 | ARG index:UINT | |
188 | ||
189 | push _bp | |
190 | mov _bp,_sp | |
191 | pushfd | |
192 | mov al,[BYTE index] | |
193 | or al,80h ; Add disable NMI flag | |
194 | cli | |
195 | out 70h,al | |
196 | IODELAYN 5 | |
197 | in al,71h | |
198 | mov ah,al | |
199 | xor al,al | |
200 | IODELAYN 5 | |
201 | out 70h,al ; Re-enable NMI | |
202 | mov al,ah ; Return value in AL | |
203 | popfd | |
204 | pop _bp | |
205 | ret | |
206 | ||
207 | cprocend | |
208 | ||
209 | ;---------------------------------------------------------------------------- | |
210 | ; void _PM_writeCMOS(int index,uchar value) | |
211 | ;---------------------------------------------------------------------------- | |
212 | ; Read the value of a specific CMOS register. We do this with both | |
213 | ; normal interrupts and NMI disabled. | |
214 | ;---------------------------------------------------------------------------- | |
215 | cprocstart _PM_writeCMOS | |
216 | ||
217 | ARG index:UINT, value:UCHAR | |
218 | ||
219 | push _bp | |
220 | mov _bp,_sp | |
221 | pushfd | |
222 | mov al,[BYTE index] | |
223 | or al,80h ; Add disable NMI flag | |
224 | cli | |
225 | out 70h,al | |
226 | IODELAYN 5 | |
227 | mov al,[value] | |
228 | out 71h,al | |
229 | xor al,al | |
230 | IODELAYN 5 | |
231 | out 70h,al ; Re-enable NMI | |
232 | popfd | |
233 | pop _bp | |
234 | ret | |
235 | ||
236 | cprocend | |
237 | ||
238 | ;---------------------------------------------------------------------------- | |
239 | ; double _ftol(double f) | |
240 | ;---------------------------------------------------------------------------- | |
241 | ; Calls to __ftol are generated by the Borland C++ compiler for code | |
242 | ; that needs to convert a floating point type to an integral type. | |
243 | ; | |
244 | ; Input: floating point number on the top of the '87. | |
245 | ; | |
246 | ; Output: a (signed or unsigned) long in EAX | |
247 | ; All other registers preserved. | |
248 | ;----------------------------------------------------------------------- | |
249 | cprocstart _ftol | |
250 | ||
251 | LOCAL temp1:WORD, temp2:QWORD = LocalSize | |
252 | ||
253 | push ebp | |
254 | mov ebp,esp | |
255 | sub esp,LocalSize | |
256 | ||
257 | fstcw [temp1] ; save the control word | |
258 | fwait | |
259 | mov al,[BYTE temp1+1] | |
260 | or [BYTE temp1+1],0Ch ; set rounding control to chop | |
261 | fldcw [temp1] | |
262 | fistp [temp2] ; convert to 64-bit integer | |
263 | mov [BYTE temp1+1],al | |
264 | fldcw [temp1] ; restore the control word | |
265 | mov eax,[DWORD temp2] ; return LS 32 bits | |
266 | mov edx,[DWORD temp2+4] ; MS 32 bits | |
267 | ||
268 | mov esp,ebp | |
269 | pop ebp | |
270 | ret | |
271 | ||
272 | cprocend | |
273 | ||
274 | ;---------------------------------------------------------------------------- | |
275 | ; _PM_getPDB - Return the Page Table Directory Base address | |
276 | ;---------------------------------------------------------------------------- | |
277 | cprocstart _PM_getPDB | |
278 | ||
279 | mov eax,cr3 | |
280 | and eax,0FFFFF000h | |
281 | ret | |
282 | ||
283 | cprocend | |
284 | ||
285 | ;---------------------------------------------------------------------------- | |
286 | ; Flush the Translation Lookaside buffer | |
287 | ;---------------------------------------------------------------------------- | |
288 | cprocstart PM_flushTLB | |
289 | ||
290 | wbinvd ; Flush the CPU cache | |
291 | mov eax,cr3 | |
292 | mov cr3,eax ; Flush the TLB | |
293 | ret | |
294 | ||
295 | cprocend | |
296 | ||
297 | endcodeseg _pm | |
298 | ||
299 | END ; End of module |