Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / qnx / _mtrrqnx.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:    NASM
25 ;* Environment: QNX
26 ;*
27 ;* Description: Assembler support routines for the Memory Type Range Register
28 ;*              (MTRR) module for QNX.
29 ;*
30 ;****************************************************************************
31
32         IDEAL
33
34 include "scitech.mac"           ; Memory model macros
35
36 header      _mtrrqnx                ; Set up memory model
37
38 begdataseg  _mtrrqnx                ; Start of code segment
39
40 ifdef   USE_NASM
41 %define R0_FLUSH_TLB    0
42 %define R0_SAVE_CR4     1
43 %define R0_RESTORE_CR4  2
44 %define R0_READ_MSR     3
45 %define R0_WRITE_MSR    4
46 else
47 R0_FLUSH_TLB        EQU 0
48 R0_SAVE_CR4         EQU 1
49 R0_RESTORE_CR4      EQU 2
50 R0_READ_MSR         EQU 3
51 R0_WRITE_MSR        EQU 4
52 endif
53
54 cpublic _PM_R0
55 _PM_R0_service      dd  0
56 _PM_R0_reg          dd  0
57 _PM_R0_eax          dd  0
58 _PM_R0_edx          dd  0
59
60 enddataseg  _mtrrqnx                ; Start of code segment
61
62 begcodeseg  _mtrrqnx                ; Start of code segment
63
64 P586
65
66 ;----------------------------------------------------------------------------
67 ; ulong _MTRR_disableInt(void);
68 ;----------------------------------------------------------------------------
69 ; Return processor interrupt status and disable interrupts.
70 ;----------------------------------------------------------------------------
71 cprocstart  _MTRR_disableInt
72
73         pushfd                  ; Put flag word on stack
74 ;       cli                     ; Disable interrupts!
75         pop     eax             ; deposit flag word in return register
76         ret
77
78 cprocend
79
80 ;----------------------------------------------------------------------------
81 ; void _MTRR_restoreInt(ulong ps);
82 ;----------------------------------------------------------------------------
83 ; Restore processor interrupt status.
84 ;----------------------------------------------------------------------------
85 cprocstart  _MTRR_restoreInt
86
87         ARG     ps:ULONG
88
89         push    ebp
90         mov     ebp,esp         ; Set up stack frame
91         push    [ULONG ps]
92         popfd                   ; Restore processor status (and interrupts)
93         pop     ebp
94         ret
95
96 cprocend
97
98 ;----------------------------------------------------------------------------
99 ; uchar _MTRR_getCx86(uchar reg);
100 ;----------------------------------------------------------------------------
101 ; Read a Cyrix CPU indexed register
102 ;----------------------------------------------------------------------------
103 cprocstart  _MTRR_getCx86
104
105         ARG     reg:UCHAR
106
107         enter_c
108         mov     al,[reg]
109         out     22h,al
110         in      al,23h
111         leave_c
112         ret
113
114 cprocend
115
116 ;----------------------------------------------------------------------------
117 ; uchar _MTRR_setCx86(uchar reg,uchar val);
118 ;----------------------------------------------------------------------------
119 ; Write a Cyrix CPU indexed register
120 ;----------------------------------------------------------------------------
121 cprocstart  _MTRR_setCx86
122
123         ARG     reg:UCHAR, val:UCHAR
124
125         enter_c
126         mov     al,[reg]
127         out     22h,al
128         mov     al,[val]
129         out     23h,al
130         leave_c
131         ret
132
133 cprocend
134
135 ;----------------------------------------------------------------------------
136 ; ulong _PM_ring0_isr(void);
137 ;----------------------------------------------------------------------------
138 ; Ring 0 clock interrupt handler that we use to execute the MTRR support
139 ; code.
140 ;----------------------------------------------------------------------------
141 cprocnear   _PM_ring0_isr
142
143 ;--------------------------------------------------------
144 ; void PM_flushTLB(void);
145 ;--------------------------------------------------------
146         pushad
147         cmp     [DWORD _PM_R0_service],R0_FLUSH_TLB
148         jne     @@1
149         wbinvd                  ; Flush the CPU cache
150         mov     eax,cr3         
151         mov     cr3,eax         ; Flush the TLB
152         jmp     @@Exit
153
154 ;--------------------------------------------------------
155 ; ulong _MTRR_saveCR4(void);
156 ;--------------------------------------------------------
157 @@1:    cmp     [DWORD _PM_R0_service],R0_SAVE_CR4
158         jne     @@2
159
160 ; Save value of CR4 and clear Page Global Enable (bit 7)
161
162         mov     ebx,cr4
163         mov     eax,ebx
164         and     al,7Fh
165         mov     cr4,eax
166
167 ; Disable and flush caches
168
169         mov     eax,cr0
170         or      eax,40000000h
171         wbinvd
172         mov     cr0,eax
173         wbinvd
174
175 ; Return value from CR4
176
177         mov     [_PM_R0_reg],ebx
178         jmp     @@Exit
179
180 ;--------------------------------------------------------
181 ; void _MTRR_restoreCR4(ulong cr4Val)
182 ;--------------------------------------------------------
183 @@2:    cmp     [DWORD _PM_R0_service],R0_RESTORE_CR4
184         jne     @@3
185
186         mov     eax,cr0
187         and     eax,0BFFFFFFFh
188         mov     cr0,eax
189         mov     eax,[_PM_R0_reg]
190         mov     cr4,eax
191         jmp     @@Exit
192
193 ;--------------------------------------------------------
194 ; void _MTRR_readMSR(int reg, ulong FAR *eax, ulong FAR *edx);
195 ;--------------------------------------------------------
196 @@3:    cmp     [DWORD _PM_R0_service],R0_READ_MSR
197         jne     @@4
198
199         mov     ecx,[_PM_R0_reg]
200         rdmsr
201         mov     [_PM_R0_eax],eax
202         mov     [_PM_R0_edx],edx
203         jmp     @@Exit
204
205 ;--------------------------------------------------------
206 ; void _MTRR_writeMSR(int reg, ulong eax, ulong edx);
207 ;--------------------------------------------------------
208 @@4:    cmp     [DWORD _PM_R0_service],R0_WRITE_MSR
209         jne     @@Exit
210
211         mov     ecx,[_PM_R0_reg]
212         mov     eax,[_PM_R0_eax]
213         mov     edx,[_PM_R0_edx]
214         wrmsr
215         jmp     @@Exit
216
217 @@Exit: mov     [DWORD _PM_R0_service],-1
218         popad
219         mov     eax,0
220         retf
221
222 cprocend
223
224 endcodeseg  _mtrrqnx
225
226         END                     ; End of module