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 ;* ========================================================================
24 ;* Language: 80386 Assembler, TASM 4.0 or NASM
25 ;* Environment: 32-bit Windows VxD
27 ;* Description: Low level assembly support for the PM library specific to
30 ;****************************************************************************
34 include "scitech.mac" ; Memory model macros
36 header _pm ; Set up memory model
40 cextern _PM_savedDS,USHORT
46 begcodeseg _pm ; Start of code segment
48 ;----------------------------------------------------------------------------
49 ; void PM_segread(PMSREGS *sregs)
50 ;----------------------------------------------------------------------------
51 ; Read the current value of all segment registers
52 ;----------------------------------------------------------------------------
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 ;----------------------------------------------------------------------------
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 ;----------------------------------------------------------------------------
98 mov [_PM_savedDS],ds ; Store away in data segment
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 ;----------------------------------------------------------------------------
113 mov ds,[cs:_PM_savedDS] ; We can access the proper DS through CS
118 ;----------------------------------------------------------------------------
119 ; void PM_setBankA(int bank)
120 ;----------------------------------------------------------------------------
121 cprocstart PM_setBankA
129 ;----------------------------------------------------------------------------
130 ; void PM_setBankAB(int bank)
131 ;----------------------------------------------------------------------------
132 cprocstart PM_setBankAB
140 ;----------------------------------------------------------------------------
141 ; void PM_setCRTStart(int x,int y,int waitVRT)
142 ;----------------------------------------------------------------------------
143 cprocstart PM_setCRTStart
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.
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
193 or al,80h ; Add disable NMI flag
201 out 70h,al ; Re-enable NMI
202 mov al,ah ; Return value in AL
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
217 ARG index:UINT, value:UCHAR
223 or al,80h ; Add disable NMI flag
231 out 70h,al ; Re-enable NMI
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.
244 ; Input: floating point number on the top of the '87.
246 ; Output: a (signed or unsigned) long in EAX
247 ; All other registers preserved.
248 ;-----------------------------------------------------------------------
251 LOCAL temp1:WORD, temp2:QWORD = LocalSize
257 fstcw [temp1] ; save the control word
259 mov al,[BYTE temp1+1]
260 or [BYTE temp1+1],0Ch ; set rounding control to chop
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
274 ;----------------------------------------------------------------------------
275 ; _PM_getPDB - Return the Page Table Directory Base address
276 ;----------------------------------------------------------------------------
277 cprocstart _PM_getPDB
285 ;----------------------------------------------------------------------------
286 ; Flush the Translation Lookaside buffer
287 ;----------------------------------------------------------------------------
288 cprocstart PM_flushTLB
290 wbinvd ; Flush the CPU cache
292 mov cr3,eax ; Flush the TLB