]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/src/pm/common/_mtrr.asm
* Patch by Thomas Frieden, 13 Nov 2002:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / src / pm / common / _mtrr.asm
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: 16/32 bit Ring 0 device driver
26 ;*
27 ;* Description: Assembler support routines for the Memory Type Range Register
28 ;*              (MTRR) module.
29 ;*
30 ;****************************************************************************
31
32         IDEAL
33
34 include "scitech.mac"           ; Memory model macros
35
36 header      _mtrr               ; Set up memory model
37
38 begdataseg  _mtrr
39
40 ifdef   DOS4GW
41     cextern _PM_haveCauseWay,UINT
42 endif
43
44 enddataseg  _mtrr
45
46 begcodeseg  _mtrr               ; Start of code segment
47
48 P586
49
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
58
59 ; Are we running under CauseWay?
60
61 ifdef   DOS4GW
62         enter_c
63         mov     ax,cs
64         and     eax,3
65         xor     eax,3
66         jnz     @@Exit
67
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.
70
71         mov     eax,1
72         cmp     [UINT _PM_haveCauseWay],0
73         jnz     @@Exit
74 @@Fail: xor     eax,eax
75 @@Exit: leave_c
76         ret
77 else
78 ifdef __SMX32__
79         mov     eax,1                   ; SMX is ring 0!
80         ret
81 else
82 ifdef __VXD__
83         mov     eax,1                   ; VxD is ring 0!
84         ret
85 else
86 ifdef __NT_DRIVER__
87         mov     eax,1                   ; NT/W2K is ring 0!
88         ret
89 else
90 else
91         xor     eax,eax                 ; Assume ring 3 for 32-bit DOS
92         ret
93 endif
94 endif
95 endif
96 endif
97
98 cprocend
99
100 ;----------------------------------------------------------------------------
101 ; ulong _MTRR_disableInt(void);
102 ;----------------------------------------------------------------------------
103 ; Return processor interrupt status and disable interrupts.
104 ;----------------------------------------------------------------------------
105 cprocstart  _MTRR_disableInt
106
107         pushfd                  ; Put flag word on stack
108         cli                     ; Disable interrupts!
109         pop     eax             ; deposit flag word in return register
110         ret
111
112 cprocend
113
114 ;----------------------------------------------------------------------------
115 ; void _MTRR_restoreInt(ulong ps);
116 ;----------------------------------------------------------------------------
117 ; Restore processor interrupt status.
118 ;----------------------------------------------------------------------------
119 cprocstart  _MTRR_restoreInt
120
121         ARG     ps:ULONG
122
123         push    ebp
124         mov     ebp,esp         ; Set up stack frame
125         mov     ecx,[ps]
126         test    ecx,200h        ; SMP safe interrupt flag restore!
127         jz      @@1
128         sti
129 @@1:    pop     ebp
130         ret
131
132 cprocend
133
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
141
142         enter_c
143
144 ; Save value of CR4 and clear Page Global Enable (bit 7)
145
146         mov     ebx,cr4
147         mov     eax,ebx
148         and     al,7Fh
149         mov     cr4,eax
150
151 ; Disable and flush caches
152
153         mov     eax,cr0
154         or      eax,40000000h
155         wbinvd
156         mov     cr0,eax
157         wbinvd
158
159 ; Return value from CR4
160
161         mov     eax,ebx
162         leave_c
163         ret
164
165 cprocend
166
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
174
175         ARG     cr4Val:ULONG
176
177         enter_c
178
179 ; Enable caches
180
181         mov     eax,cr0
182         and     eax,0BFFFFFFFh
183         mov     cr0,eax
184         mov     eax,[cr4Val]
185         mov     cr4,eax
186         leave_c
187         ret
188
189 cprocend
190
191 ;----------------------------------------------------------------------------
192 ; uchar _MTRR_getCx86(uchar reg);
193 ;----------------------------------------------------------------------------
194 ; Read a Cyrix CPU indexed register
195 ;----------------------------------------------------------------------------
196 cprocstart  _MTRR_getCx86
197
198         ARG     reg:UCHAR
199
200         enter_c
201         mov     al,[reg]
202         out     22h,al
203         in      al,23h
204         leave_c
205         ret
206
207 cprocend
208
209 ;----------------------------------------------------------------------------
210 ; uchar _MTRR_setCx86(uchar reg,uchar val);
211 ;----------------------------------------------------------------------------
212 ; Write a Cyrix CPU indexed register
213 ;----------------------------------------------------------------------------
214 cprocstart  _MTRR_setCx86
215
216         ARG     reg:UCHAR, val:UCHAR
217
218         enter_c
219         mov     al,[reg]
220         out     22h,al
221         mov     al,[val]
222         out     23h,al
223         leave_c
224         ret
225
226 cprocend
227
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
235
236         ARG     reg:ULONG, v_eax:DPTR, v_edx:DPTR
237
238         enter_c
239         mov     ecx,[reg]
240         rdmsr
241         mov     ebx,[v_eax]
242         mov     [ebx],eax
243         mov     ebx,[v_edx]
244         mov     [ebx],edx
245         leave_c
246         ret
247
248 cprocend
249
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
257
258         ARG     reg:ULONG, v_eax:ULONG, v_edx:ULONG
259
260         enter_c
261         mov     ecx,[reg]
262         mov     eax,[v_eax]
263         mov     edx,[v_edx]
264         wrmsr
265         leave_c
266         ret
267
268 cprocend
269
270 endcodeseg  _mtrr
271
272         END                     ; End of module