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: 16/32 bit Ring 0 device driver
27 ;* Description: Assembler support routines for the Memory Type Range Register
30 ;****************************************************************************
34 include "scitech.mac" ; Memory model macros
36 header _mtrr ; Set up memory model
41 cextern _PM_haveCauseWay,UINT
46 begcodeseg _mtrr ; Start of code segment
50 ;----------------------------------------------------------------------------
51 ; ibool _MTRR_isRing0(void);
52 ;----------------------------------------------------------------------------
53 ; Checks to see if we are running at ring 0. This check is only relevant
54 ; for 32-bit DOS4GW and compatible programs. If we are not running under
55 ; DOS4GW, then we simply assume we are a ring 0 device driver.
56 ;----------------------------------------------------------------------------
57 cprocnear _MTRR_isRing0
59 ; Are we running under CauseWay?
68 ; CauseWay runs the apps at ring 3, but implements support for specific
69 ; ring 0 instructions that we need to get stuff done under real DOS.
72 cmp [UINT _PM_haveCauseWay],0
79 mov eax,1 ; SMX is ring 0!
83 mov eax,1 ; VxD is ring 0!
87 mov eax,1 ; NT/W2K is ring 0!
91 xor eax,eax ; Assume ring 3 for 32-bit DOS
100 ;----------------------------------------------------------------------------
101 ; ulong _MTRR_disableInt(void);
102 ;----------------------------------------------------------------------------
103 ; Return processor interrupt status and disable interrupts.
104 ;----------------------------------------------------------------------------
105 cprocstart _MTRR_disableInt
107 pushfd ; Put flag word on stack
108 cli ; Disable interrupts!
109 pop eax ; deposit flag word in return register
114 ;----------------------------------------------------------------------------
115 ; void _MTRR_restoreInt(ulong ps);
116 ;----------------------------------------------------------------------------
117 ; Restore processor interrupt status.
118 ;----------------------------------------------------------------------------
119 cprocstart _MTRR_restoreInt
124 mov ebp,esp ; Set up stack frame
126 test ecx,200h ; SMP safe interrupt flag restore!
134 ;----------------------------------------------------------------------------
135 ; ulong _MTRR_saveCR4(void);
136 ;----------------------------------------------------------------------------
137 ; Save the value of CR4 and clear the Page Global Enable (bit 7). We also
138 ; disable and flush the caches.
139 ;----------------------------------------------------------------------------
140 cprocstart _MTRR_saveCR4
144 ; Save value of CR4 and clear Page Global Enable (bit 7)
151 ; Disable and flush caches
159 ; Return value from CR4
167 ;----------------------------------------------------------------------------
168 ; void _MTRR_restoreCR4(ulong cr4Val)
169 ;----------------------------------------------------------------------------
170 ; Save the value of CR4 and clear the Page Global Enable (bit 7). We also
171 ; disable and flush the caches.
172 ;----------------------------------------------------------------------------
173 cprocstart _MTRR_restoreCR4
191 ;----------------------------------------------------------------------------
192 ; uchar _MTRR_getCx86(uchar reg);
193 ;----------------------------------------------------------------------------
194 ; Read a Cyrix CPU indexed register
195 ;----------------------------------------------------------------------------
196 cprocstart _MTRR_getCx86
209 ;----------------------------------------------------------------------------
210 ; uchar _MTRR_setCx86(uchar reg,uchar val);
211 ;----------------------------------------------------------------------------
212 ; Write a Cyrix CPU indexed register
213 ;----------------------------------------------------------------------------
214 cprocstart _MTRR_setCx86
216 ARG reg:UCHAR, val:UCHAR
228 ;----------------------------------------------------------------------------
229 ; void _MTRR_readMSR(uong reg, ulong FAR *eax, ulong FAR *edx);
230 ;----------------------------------------------------------------------------
231 ; Writes the specific Machine Status Register used on the newer Intel
232 ; Pentium Pro and Pentium II motherboards.
233 ;----------------------------------------------------------------------------
234 cprocnear _MTRR_readMSR
236 ARG reg:ULONG, v_eax:DPTR, v_edx:DPTR
250 ;----------------------------------------------------------------------------
251 ; void _MTRR_writeMSR(uong reg, ulong eax, ulong edx);
252 ;----------------------------------------------------------------------------
253 ; Writes the specific Machine Status Register used on the newer Intel
254 ; Pentium Pro and Pentium II motherboards.
255 ;----------------------------------------------------------------------------
256 cprocnear _MTRR_writeMSR
258 ARG reg:ULONG, v_eax:ULONG, v_edx:ULONG