1 |
27 |
unneback |
#ifndef CYGONCE_HAL_ARCH_INC
|
2 |
|
|
#define CYGONCE_HAL_ARCH_INC
|
3 |
|
|
##=============================================================================
|
4 |
|
|
##
|
5 |
|
|
## arch.inc
|
6 |
|
|
##
|
7 |
|
|
## i386 assembler header file
|
8 |
|
|
##
|
9 |
|
|
##=============================================================================
|
10 |
|
|
#####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
## -------------------------------------------
|
12 |
|
|
## This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
14 |
|
|
##
|
15 |
|
|
## eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
## the terms of the GNU General Public License as published by the Free
|
17 |
|
|
## Software Foundation; either version 2 or (at your option) any later version.
|
18 |
|
|
##
|
19 |
|
|
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
20 |
|
|
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
21 |
|
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
22 |
|
|
## for more details.
|
23 |
|
|
##
|
24 |
|
|
## You should have received a copy of the GNU General Public License along
|
25 |
|
|
## with eCos; if not, write to the Free Software Foundation, Inc.,
|
26 |
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
27 |
|
|
##
|
28 |
|
|
## As a special exception, if other files instantiate templates or use macros
|
29 |
|
|
## or inline functions from this file, or you compile this file and link it
|
30 |
|
|
## with other works to produce a work based on this file, this file does not
|
31 |
|
|
## by itself cause the resulting work to be covered by the GNU General Public
|
32 |
|
|
## License. However the source code for this file must still be made available
|
33 |
|
|
## in accordance with section (3) of the GNU General Public License.
|
34 |
|
|
##
|
35 |
|
|
## This exception does not invalidate any other reasons why a work based on
|
36 |
|
|
## this file might be covered by the GNU General Public License.
|
37 |
|
|
##
|
38 |
|
|
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
39 |
|
|
## at http://sources.redhat.com/ecos/ecos-license/
|
40 |
|
|
## -------------------------------------------
|
41 |
|
|
#####ECOSGPLCOPYRIGHTEND####
|
42 |
|
|
##=============================================================================
|
43 |
|
|
#######DESCRIPTIONBEGIN####
|
44 |
|
|
##
|
45 |
|
|
## Author(s): nickg
|
46 |
|
|
## Contributors: nickg, pjo
|
47 |
|
|
## Date: 1999-10-15
|
48 |
|
|
## Purpose: Architecture definitions.
|
49 |
|
|
## Description: This file contains various definitions and macros that are
|
50 |
|
|
## useful for writing assembly code for the i386 CPU family.
|
51 |
|
|
## Usage:
|
52 |
|
|
## #include
|
53 |
|
|
## ...
|
54 |
|
|
##
|
55 |
|
|
##
|
56 |
|
|
######DESCRIPTIONEND####
|
57 |
|
|
##
|
58 |
|
|
##=============================================================================
|
59 |
|
|
|
60 |
|
|
#include
|
61 |
|
|
|
62 |
|
|
#include
|
63 |
|
|
|
64 |
|
|
##-----------------------------------------------------------------------------
|
65 |
|
|
## CPU specific macros. These provide a common assembler interface to
|
66 |
|
|
## operations that may have CPU specific implementations on different
|
67 |
|
|
## variants of the architecture.
|
68 |
|
|
|
69 |
|
|
#ifndef CYGPKG_HAL_I386_CPU_INIT_DEFINED
|
70 |
|
|
# Initialize CPU
|
71 |
|
|
.macro hal_cpu_init
|
72 |
|
|
.endm
|
73 |
|
|
#endif /* !CYGPKG_HAL_I386_CPU_INIT_DEFINED */
|
74 |
|
|
|
75 |
|
|
##-----------------------------------------------------------------------------
|
76 |
|
|
|
77 |
|
|
#ifndef CYGPKG_HAL_I386_INTC_DEFINED
|
78 |
|
|
|
79 |
|
|
#ifndef CYGPKG_HAL_I386_INTC_INIT_DEFINED
|
80 |
|
|
# initialize all interrupts to disabled
|
81 |
|
|
.macro hal_intc_init
|
82 |
|
|
.endm
|
83 |
|
|
#endif
|
84 |
|
|
|
85 |
|
|
.macro hal_intc_decode vnum
|
86 |
|
|
.endm
|
87 |
|
|
|
88 |
|
|
#endif
|
89 |
|
|
|
90 |
|
|
#------------------------------------------------------------------------------
|
91 |
|
|
# SMP support
|
92 |
|
|
|
93 |
|
|
#ifdef CYGPKG_HAL_SMP_SUPPORT
|
94 |
|
|
|
95 |
|
|
.macro hal_smp_init
|
96 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
|
97 |
|
|
movl $0,cyg_hal_smp_vsr_sync_flag
|
98 |
|
|
#endif
|
99 |
|
|
.endm
|
100 |
|
|
|
101 |
|
|
// Put CPU number in register
|
102 |
|
|
.macro hal_smp_cpu reg
|
103 |
|
|
movl cyg_hal_smp_local_apic,\reg
|
104 |
|
|
movl 0x20(\reg),\reg
|
105 |
|
|
shrl $24,\reg
|
106 |
|
|
.endm
|
107 |
|
|
|
108 |
|
|
#else
|
109 |
|
|
|
110 |
|
|
.macro hal_smp_init
|
111 |
|
|
.endm
|
112 |
|
|
|
113 |
|
|
.macro hal_smp_cpu reg
|
114 |
|
|
movl $0,\reg
|
115 |
|
|
.endm
|
116 |
|
|
|
117 |
|
|
#endif
|
118 |
|
|
|
119 |
|
|
#------------------------------------------------------------------------------
|
120 |
|
|
# Stack switching macros
|
121 |
|
|
|
122 |
|
|
#ifndef CYG_HAL_I386_INTSTACK_MACROS_DEFINED
|
123 |
|
|
|
124 |
|
|
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
|
125 |
|
|
|
126 |
|
|
#ifdef CYGPKG_HAL_SMP_SUPPORT
|
127 |
|
|
|
128 |
|
|
.macro hal_init_istack reg
|
129 |
|
|
hal_smp_cpu %ebx
|
130 |
|
|
movl $__interrupt_stack_vector,%ecx
|
131 |
|
|
movl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,%eax
|
132 |
|
|
imull %ebx,%eax
|
133 |
|
|
addl $__interrupt_stack_first,%eax
|
134 |
|
|
movl %eax,0(%ecx,%ebx,4)
|
135 |
|
|
movl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,\reg
|
136 |
|
|
addl %eax,\reg
|
137 |
|
|
.endm
|
138 |
|
|
|
139 |
|
|
.macro hal_load_istack reg
|
140 |
|
|
hal_load_istack_base \reg
|
141 |
|
|
addl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,\reg
|
142 |
|
|
.endm
|
143 |
|
|
|
144 |
|
|
.macro hal_load_istack_base reg
|
145 |
|
|
hal_smp_cpu \reg
|
146 |
|
|
movl $__interrupt_stack_vector,%eax
|
147 |
|
|
movl 0(%eax,\reg,4),\reg
|
148 |
|
|
.endm
|
149 |
|
|
|
150 |
|
|
#else // CYGPKG_HAL_SMP_SUPPORT
|
151 |
|
|
.macro hal_init_istack reg,tr
|
152 |
|
|
movl $__interrupt_stack,\reg // Load interrupt stack
|
153 |
|
|
.endm
|
154 |
|
|
|
155 |
|
|
.macro hal_load_istack reg
|
156 |
|
|
movl $__interrupt_stack,\reg // Load interrupt stack
|
157 |
|
|
.endm
|
158 |
|
|
|
159 |
|
|
.macro hal_load_istack_base reg
|
160 |
|
|
movl $__interrupt_stack_base,\reg // Load interrupt stack base
|
161 |
|
|
.endm
|
162 |
|
|
|
163 |
|
|
#endif // CYGPKG_HAL_SMP_SUPPORT
|
164 |
|
|
|
165 |
|
|
.macro hal_to_intstack
|
166 |
|
|
hal_load_istack_base %ebx // EBX = stack base
|
167 |
|
|
movl %ebx,%eax
|
168 |
|
|
addl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,%eax
|
169 |
|
|
cmpl %ebx,%ebp # compare SP with istack base
|
170 |
|
|
jb 1f # if sp < istack base, switch
|
171 |
|
|
cmpl %eax,%ebp # compare SP with istack top
|
172 |
|
|
jbe 2f # if sp < istack top, dont switch
|
173 |
|
|
1:
|
174 |
|
|
movl %eax,%esp # move on to new stack
|
175 |
|
|
2:
|
176 |
|
|
pushl %ebp # Save old SP on new stack
|
177 |
|
|
.endm
|
178 |
|
|
|
179 |
|
|
.macro hal_from_intstack
|
180 |
|
|
popl %esp # pop old SP from stack
|
181 |
|
|
.endm
|
182 |
|
|
|
183 |
|
|
#define CYG_HAL_I386_INTSTACK_MACROS_DEFINED
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
#else // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
|
187 |
|
|
|
188 |
|
|
.macro hal_init_istack reg
|
189 |
|
|
.endm
|
190 |
|
|
|
191 |
|
|
.macro hal_load_istack_base reg
|
192 |
|
|
.endm
|
193 |
|
|
|
194 |
|
|
.macro hal_load_istack reg
|
195 |
|
|
.endm
|
196 |
|
|
|
197 |
|
|
.macro hal_to_intstack
|
198 |
|
|
.endm
|
199 |
|
|
|
200 |
|
|
.macro hal_from_intstack
|
201 |
|
|
.endm
|
202 |
|
|
|
203 |
|
|
#define CYG_HAL_I386_INTSTACK_MACROS_DEFINED
|
204 |
|
|
|
205 |
|
|
#endif // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
|
206 |
|
|
|
207 |
|
|
#endif // CYG_HAL_I386_INTSTACK_MACROS_DEFINED
|
208 |
|
|
|
209 |
|
|
#------------------------------------------------------------------------------
|
210 |
|
|
# FPU macros.
|
211 |
|
|
|
212 |
|
|
#ifndef CYGPKG_HAL_I386_FPU_DEFINED
|
213 |
|
|
|
214 |
|
|
#ifdef CYGHWR_HAL_I386_FPU
|
215 |
|
|
|
216 |
|
|
#define CYGPKG_HAL_I386_FPU_DEFINED
|
217 |
|
|
|
218 |
|
|
.macro hal_fpu_init
|
219 |
|
|
# Tell the CPU to use the math hardware.
|
220 |
|
|
movl %cr0, %eax
|
221 |
|
|
orl $0x32, %eax # Set MP, ET, NE bits
|
222 |
|
|
andl $~0x8, %eax # And clear TS bit
|
223 |
|
|
movl %eax, %cr0
|
224 |
|
|
|
225 |
|
|
finit # and initialize...
|
226 |
|
|
|
227 |
|
|
## Enable floating point exceptions. Bit mask:
|
228 |
|
|
## 1 - invalid operation
|
229 |
|
|
## 2 - denormalized operand
|
230 |
|
|
## 4 - zero divide
|
231 |
|
|
## 8 - overflow
|
232 |
|
|
## 16 - underflow
|
233 |
|
|
## 32 - precision
|
234 |
|
|
pushl $0 # space for CW
|
235 |
|
|
fstcw 0(%esp) # store FPCW to stack
|
236 |
|
|
movl 0(%esp),%eax # get into EAX
|
237 |
|
|
andb $(~0x04),%al # allow only zero divide exceptions
|
238 |
|
|
movl %eax,0(%esp) # put back into memory
|
239 |
|
|
fldcw 0(%esp) # reload
|
240 |
|
|
addl $4,%esp # pop value
|
241 |
|
|
|
242 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
243 |
|
|
# set CR4.OSFXSR to safely use stmxcsr/ldmxcsr
|
244 |
|
|
movl %cr4, %eax
|
245 |
|
|
orl $0x200, %eax
|
246 |
|
|
movl %eax, %cr4
|
247 |
|
|
|
248 |
|
|
## Enable SIMD exceptions. Bit mask:
|
249 |
|
|
## 0x0080 - invalid operation
|
250 |
|
|
## 0x0100 - denormalized operand
|
251 |
|
|
## 0x0200 - zero divide
|
252 |
|
|
## 0x0400 - overflow
|
253 |
|
|
## 0x0800 - underflow
|
254 |
|
|
## 0x1000 - precision
|
255 |
|
|
pushl $0 # space for MXCSR
|
256 |
|
|
stmxcsr 0(%esp) # store MXCSR to stack
|
257 |
|
|
movl 0(%esp),%eax # get into EAX
|
258 |
|
|
andw $(~0x0200),%ax # allow only zero divide exceptions
|
259 |
|
|
movl %eax,0(%esp) # put back into memory
|
260 |
|
|
ldmxcsr 0(%esp) # reload
|
261 |
|
|
addl $4,%esp # pop value
|
262 |
|
|
#endif
|
263 |
|
|
|
264 |
|
|
#ifdef CYGHWR_HAL_I386_FPU_SWITCH_LAZY
|
265 |
|
|
# Tell the CPU to generate an FPU unavailable exception
|
266 |
|
|
# when the FPU is first used.
|
267 |
|
|
movl %cr0, %eax
|
268 |
|
|
orl $0x8, %eax
|
269 |
|
|
movl %eax, %cr0
|
270 |
|
|
# Plant a pointer to the FPU switch VSR into slot 7
|
271 |
|
|
# of the VSR table.
|
272 |
|
|
movl $__fpu_switch_vsr,%eax
|
273 |
|
|
movl %eax,(hal_vsr_table+7*4)
|
274 |
|
|
# Now create an FPU context on the stack so that we can take
|
275 |
|
|
# FPU-using interrupts and exceptions before the machine starts
|
276 |
|
|
# up.
|
277 |
|
|
subl $i386reg_fpucontext_size,%esp
|
278 |
|
|
movl $0,i386reg_fpucontext_valid(%esp)
|
279 |
|
|
hal_smp_cpu %ebx # get CPU id
|
280 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
281 |
|
|
movl %esp,0(%ecx,%ebx,4) # save in table[cpu] entry
|
282 |
|
|
#endif
|
283 |
|
|
.endm
|
284 |
|
|
|
285 |
|
|
.macro hal_fpu_cpu_init
|
286 |
|
|
# Tell the CPU to use the math hardware.
|
287 |
|
|
movl %cr0, %eax
|
288 |
|
|
orl $0x32, %eax # Set MP, ET, NE bits
|
289 |
|
|
andl $~0x8, %eax # And clear TS bit
|
290 |
|
|
movl %eax, %cr0
|
291 |
|
|
|
292 |
|
|
finit # and initialize...
|
293 |
|
|
|
294 |
|
|
## Enable floating point exceptions. Bit mask:
|
295 |
|
|
## 1 - invalid operation
|
296 |
|
|
## 2 - denormalized operand
|
297 |
|
|
## 4 - zero divide
|
298 |
|
|
## 8 - overflow
|
299 |
|
|
## 16 - underflow
|
300 |
|
|
## 32 - precision
|
301 |
|
|
pushl $0 # space for CW
|
302 |
|
|
fstcw 0(%esp) # store FPCW to stack
|
303 |
|
|
movl 0(%esp),%eax # get into EAX
|
304 |
|
|
andb $(~0x04),%al # allow only zero divide exceptions
|
305 |
|
|
movl %eax,0(%esp) # put back into memory
|
306 |
|
|
fldcw 0(%esp) # reload
|
307 |
|
|
addl $4,%esp # pop value
|
308 |
|
|
|
309 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
310 |
|
|
# set CR4.OSFXSR to safely use stmxcsr/ldmxcsr
|
311 |
|
|
movl %cr4, %eax
|
312 |
|
|
orl $0x200, %eax
|
313 |
|
|
movl %eax, %cr4
|
314 |
|
|
|
315 |
|
|
## Enable SIMD exceptions. Bit mask:
|
316 |
|
|
## 0x0080 - invalid operation
|
317 |
|
|
## 0x0100 - denormalized operand
|
318 |
|
|
## 0x0200 - zero divide
|
319 |
|
|
## 0x0400 - overflow
|
320 |
|
|
## 0x0800 - underflow
|
321 |
|
|
## 0x1000 - precision
|
322 |
|
|
pushl $0 # space for MXCSR
|
323 |
|
|
stmxcsr 0(%esp) # store MXCSR to stack
|
324 |
|
|
movl 0(%esp),%eax # get into EAX
|
325 |
|
|
andw $(~0x0200),%ax # allow only zero divide exceptions
|
326 |
|
|
movl %eax,0(%esp) # put back into memory
|
327 |
|
|
ldmxcsr 0(%esp) # reload
|
328 |
|
|
addl $4,%esp # pop value
|
329 |
|
|
#endif
|
330 |
|
|
|
331 |
|
|
#ifdef CYGHWR_HAL_I386_FPU_SWITCH_LAZY
|
332 |
|
|
# Tell the CPU to generate an FPU unavailable exception
|
333 |
|
|
# when the FPU is first used.
|
334 |
|
|
movl %cr0, %eax
|
335 |
|
|
orl $0x8, %eax
|
336 |
|
|
movl %eax, %cr0
|
337 |
|
|
# Now create an FPU context on the stack so that we can take
|
338 |
|
|
# FPU-using interrupts and exceptions before the kernel starts
|
339 |
|
|
# up.
|
340 |
|
|
subl $i386reg_fpucontext_size,%esp
|
341 |
|
|
movl $0,i386reg_fpucontext_valid(%esp)
|
342 |
|
|
hal_smp_cpu %ebx # get CPU id
|
343 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
344 |
|
|
movl %esp,0(%ecx,%ebx,4) # save in table[cpu] entry
|
345 |
|
|
#endif
|
346 |
|
|
|
347 |
|
|
.endm
|
348 |
|
|
|
349 |
|
|
#ifndef CYGHWR_HAL_I386_FPU_SWITCH_LAZY
|
350 |
|
|
|
351 |
|
|
# Non-lazy CPU state switching. We simply switch the entire
|
352 |
|
|
# FPU state on every context switch, interrupt or exception.
|
353 |
|
|
|
354 |
|
|
# ------------------------------------------------------------
|
355 |
|
|
# Context switch handling
|
356 |
|
|
|
357 |
|
|
.macro hal_fpu_push_ctx
|
358 |
|
|
subl $i386reg_fpstate_size,%esp # make space
|
359 |
|
|
fnsave i386reg_fpstate(%esp) # save FPU state
|
360 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
361 |
|
|
# Save SIMD state.
|
362 |
|
|
|
363 |
|
|
# FIXME. This is awfully inefficient. Need to use FXSAVE to
|
364 |
|
|
# save FPU and SIMD at same time. FXSAVE requires a 16 byte
|
365 |
|
|
# alignment and does not have an implicit finit as does FSAVE.
|
366 |
|
|
|
367 |
|
|
stmxcsr i386reg_simd_mxcsr(%esp)
|
368 |
|
|
movups %xmm0,i386reg_simd_xmm0(%esp)
|
369 |
|
|
movups %xmm1,i386reg_simd_xmm1(%esp)
|
370 |
|
|
movups %xmm2,i386reg_simd_xmm2(%esp)
|
371 |
|
|
movups %xmm3,i386reg_simd_xmm3(%esp)
|
372 |
|
|
movups %xmm4,i386reg_simd_xmm4(%esp)
|
373 |
|
|
movups %xmm5,i386reg_simd_xmm5(%esp)
|
374 |
|
|
movups %xmm6,i386reg_simd_xmm6(%esp)
|
375 |
|
|
movups %xmm7,i386reg_simd_xmm7(%esp)
|
376 |
|
|
#endif
|
377 |
|
|
movl $1,i386reg_fpstate_valid(%esp) # indicate it is valid
|
378 |
|
|
.endm
|
379 |
|
|
|
380 |
|
|
.macro hal_fpu_pop_ctx
|
381 |
|
|
btl $0,i386reg_fpstate_valid(%esp) # check ls bit of valid flag
|
382 |
|
|
jc 1f # if set, restore state
|
383 |
|
|
finit # otherwise init FPU
|
384 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
385 |
|
|
# FIXME. Anything needed here?
|
386 |
|
|
#endif
|
387 |
|
|
jmp 2f # and skip restore
|
388 |
|
|
1:
|
389 |
|
|
frstor i386reg_fpstate(%esp) # restore FPU state
|
390 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
391 |
|
|
# Restore SIMD state.
|
392 |
|
|
|
393 |
|
|
# FIXME. This is awfully inefficient. Need to use FXRSTOR to
|
394 |
|
|
# restore FPU and SIMD at same time. FXRSTOR requires a 16 byte
|
395 |
|
|
# alignment.
|
396 |
|
|
|
397 |
|
|
movups i386reg_simd_xmm0(%esp),%xmm0
|
398 |
|
|
movups i386reg_simd_xmm1(%esp),%xmm1
|
399 |
|
|
movups i386reg_simd_xmm2(%esp),%xmm2
|
400 |
|
|
movups i386reg_simd_xmm3(%esp),%xmm3
|
401 |
|
|
movups i386reg_simd_xmm4(%esp),%xmm4
|
402 |
|
|
movups i386reg_simd_xmm5(%esp),%xmm5
|
403 |
|
|
movups i386reg_simd_xmm6(%esp),%xmm6
|
404 |
|
|
movups i386reg_simd_xmm7(%esp),%xmm7
|
405 |
|
|
ldmxcsr i386reg_simd_mxcsr(%esp)
|
406 |
|
|
#endif
|
407 |
|
|
2:
|
408 |
|
|
addl $i386reg_fpstate_size,%esp # pop space used
|
409 |
|
|
.endm
|
410 |
|
|
|
411 |
|
|
# ------------------------------------------------------------
|
412 |
|
|
# Interrupt and exception handling
|
413 |
|
|
|
414 |
|
|
# In this configuration, the interrupt and exception code behaves in
|
415 |
|
|
# exactly the same way as the context switch code.
|
416 |
|
|
|
417 |
|
|
.macro hal_fpu_push_int
|
418 |
|
|
hal_fpu_push_ctx
|
419 |
|
|
.endm
|
420 |
|
|
|
421 |
|
|
.macro hal_fpu_push_int_annex
|
422 |
|
|
.endm
|
423 |
|
|
|
424 |
|
|
.macro hal_fpu_pop_int_annex
|
425 |
|
|
.endm
|
426 |
|
|
|
427 |
|
|
.macro hal_fpu_pop_int
|
428 |
|
|
hal_fpu_pop_ctx
|
429 |
|
|
.endm
|
430 |
|
|
|
431 |
|
|
.macro hal_fpu_push_exc
|
432 |
|
|
hal_fpu_push_ctx
|
433 |
|
|
.endm
|
434 |
|
|
|
435 |
|
|
.macro hal_fpu_push_exc_annex
|
436 |
|
|
.endm
|
437 |
|
|
|
438 |
|
|
.macro hal_fpu_pop_exc_annex
|
439 |
|
|
.endm
|
440 |
|
|
|
441 |
|
|
.macro hal_fpu_pop_exc
|
442 |
|
|
hal_fpu_pop_ctx
|
443 |
|
|
.endm
|
444 |
|
|
|
445 |
|
|
#else // CYGHWR_HAL_I386_FPU_SWITCH_LAZY
|
446 |
|
|
|
447 |
|
|
# Lazy CPU state switching. We defer CPU state switching until the new
|
448 |
|
|
# thread actually uses the FPU. This state switch is handled by
|
449 |
|
|
# __fpu_switch_vsr in vectors.S.
|
450 |
|
|
|
451 |
|
|
.extern cyg_hal_fpustate_owner
|
452 |
|
|
.extern cyg_hal_fpustate_current
|
453 |
|
|
|
454 |
|
|
# ------------------------------------------------------------
|
455 |
|
|
# Context switch handling
|
456 |
|
|
|
457 |
|
|
# On context switch we simply stack a pointer to this
|
458 |
|
|
# threads FPU context save area.
|
459 |
|
|
|
460 |
|
|
.macro hal_fpu_push_ctx
|
461 |
|
|
hal_smp_cpu %ebx # Get CPU id
|
462 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
463 |
|
|
pushl 0(%ecx,%ebx,4) # push table[cpu] entry
|
464 |
|
|
.endm
|
465 |
|
|
|
466 |
|
|
# We do nothing here but set the CR0:TS bit to force
|
467 |
|
|
# an exception when the FPU is next used and pop the
|
468 |
|
|
# FPU save area pointer into the static variable.
|
469 |
|
|
|
470 |
|
|
.macro hal_fpu_pop_ctx
|
471 |
|
|
movl %cr0, %ecx # get CR0
|
472 |
|
|
orl $0x8, %ecx # set TS bit
|
473 |
|
|
movl %ecx, %cr0 # restore CR0
|
474 |
|
|
hal_smp_cpu %ebx # get CPU id
|
475 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
476 |
|
|
popl 0(%ecx,%ebx,4) # pop table[cpu] entry
|
477 |
|
|
.endm
|
478 |
|
|
|
479 |
|
|
# ------------------------------------------------------------
|
480 |
|
|
# Interrupt handling
|
481 |
|
|
|
482 |
|
|
# On entry to an interrupt we save the current threads FPU context
|
483 |
|
|
# pointer and set the CR0:TS bit to trap any FP operations in the
|
484 |
|
|
# interrupt.
|
485 |
|
|
|
486 |
|
|
.macro hal_fpu_push_int
|
487 |
|
|
hal_smp_cpu %ebx # get CPU id
|
488 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
489 |
|
|
pushl 0(%ecx,%ebx,4) # push table[cpu] entry
|
490 |
|
|
# ensure that CR0:TS bit is set
|
491 |
|
|
movl %cr0, %ecx # get CR0
|
492 |
|
|
orl $0x8, %ecx # set TS bit
|
493 |
|
|
movl %ecx, %cr0 # restore CR0
|
494 |
|
|
.endm
|
495 |
|
|
|
496 |
|
|
# The following is called after we transfer to the interrupt
|
497 |
|
|
# stack. We make space here for the FPU state of the interrupt
|
498 |
|
|
# handler to be saved in case we get nested interrupts that use FP.
|
499 |
|
|
|
500 |
|
|
.macro hal_fpu_push_int_annex
|
501 |
|
|
subl $i386reg_fpucontext_size,%esp
|
502 |
|
|
movl $0,i386reg_fpucontext_valid(%esp)
|
503 |
|
|
hal_smp_cpu %ebx # get CPU id
|
504 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
505 |
|
|
movl %esp,0(%ecx,%ebx,4) # save in table[cpu] entry
|
506 |
|
|
.endm
|
507 |
|
|
|
508 |
|
|
# This is invoked just before any transfer back to the thread stack.
|
509 |
|
|
# We check whether we are the FPU state owner, and if so, abdicate.
|
510 |
|
|
# There is no need to save the state, the next thread will load its
|
511 |
|
|
# own state over the top of it.
|
512 |
|
|
|
513 |
|
|
.macro hal_fpu_pop_int_annex
|
514 |
|
|
hal_smp_cpu %ebx # get CPU id
|
515 |
|
|
movl $cyg_hal_fpustate_owner,%ecx # current state table
|
516 |
|
|
cmpl 0(%ecx,%ebx,4),%esp # are we FPU owner?
|
517 |
|
|
jne 1f # if not, then just continue
|
518 |
|
|
movl $0,0(%ecx,%ebx,4) # no one owns FPU now
|
519 |
|
|
# ensure that CR0:TS bit is set to force a reload of
|
520 |
|
|
# the previous FPU state
|
521 |
|
|
movl %cr0, %ecx # get CR0
|
522 |
|
|
orl $0x8, %ecx # set TS bit
|
523 |
|
|
movl %ecx, %cr0 # restore CR0
|
524 |
|
|
1:
|
525 |
|
|
addl $i386reg_fpucontext_size,%esp # pop FPU save area
|
526 |
|
|
.endm
|
527 |
|
|
|
528 |
|
|
# Final return from interrupt handling. Just pull the current
|
529 |
|
|
# FPU context off the stack.
|
530 |
|
|
.macro hal_fpu_pop_int
|
531 |
|
|
hal_smp_cpu %ebx # get CPU id
|
532 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
533 |
|
|
popl 0(%ecx,%ebx,4) # pop table[cpu] entry
|
534 |
|
|
.endm
|
535 |
|
|
|
536 |
|
|
# ------------------------------------------------------------
|
537 |
|
|
# Exception handling
|
538 |
|
|
|
539 |
|
|
# Whenever we take an exception, we save the current FPU state away
|
540 |
|
|
# into its save area. This way, if we are going to end up in GDB, the
|
541 |
|
|
# whole machine state is saved in memory.
|
542 |
|
|
|
543 |
|
|
.macro hal_fpu_push_exc
|
544 |
|
|
hal_smp_cpu %ebx # get CPU id
|
545 |
|
|
movl $cyg_hal_fpustate_current,%ecx # current state table
|
546 |
|
|
pushl 0(%ecx,%ebx,4) # push table[cpu] entry
|
547 |
|
|
movl $cyg_hal_fpustate_owner,%ecx # current owner table
|
548 |
|
|
movl 0(%ecx,%ebx,4),%eax # EAX = FPU state owner
|
549 |
|
|
cmpl $0,%eax # test it
|
550 |
|
|
je 1f # skip if zero
|
551 |
|
|
fnsave i386reg_fpucontext_state(%eax) # save state
|
552 |
|
|
#ifdef CYGHWR_HAL_I386_PENTIUM_SSE
|
553 |
|
|
# Save SIMD state.
|
554 |
|
|
|
555 |
|
|
# FIXME. This is awfully inefficient. Need to use FXSAVE to
|
556 |
|
|
# save FPU and SIMD at same time. FXSAVE requires a 16 byte
|
557 |
|
|
# alignment and does not have an implicit finit as does FSAVE.
|
558 |
|
|
|
559 |
|
|
stmxcsr i386reg_simd_mxcsr(%eax)
|
560 |
|
|
movups %xmm0,i386reg_simd_xmm0(%eax)
|
561 |
|
|
movups %xmm1,i386reg_simd_xmm1(%eax)
|
562 |
|
|
movups %xmm2,i386reg_simd_xmm2(%eax)
|
563 |
|
|
movups %xmm3,i386reg_simd_xmm3(%eax)
|
564 |
|
|
movups %xmm4,i386reg_simd_xmm4(%eax)
|
565 |
|
|
movups %xmm5,i386reg_simd_xmm5(%eax)
|
566 |
|
|
movups %xmm6,i386reg_simd_xmm6(%eax)
|
567 |
|
|
movups %xmm7,i386reg_simd_xmm7(%eax)
|
568 |
|
|
#endif
|
569 |
|
|
movl $1,i386reg_fpucontext_valid(%eax) # set valid
|
570 |
|
|
movl $0,0(%ecx,%ebx,4) # zero owner pointer
|
571 |
|
|
1:
|
572 |
|
|
.endm
|
573 |
|
|
|
574 |
|
|
# The rest of the exception macros behave exactly like the
|
575 |
|
|
# interrupt ones.
|
576 |
|
|
|
577 |
|
|
.macro hal_fpu_push_exc_annex
|
578 |
|
|
hal_fpu_push_int_annex
|
579 |
|
|
.endm
|
580 |
|
|
|
581 |
|
|
.macro hal_fpu_pop_exc_annex
|
582 |
|
|
hal_fpu_pop_int_annex
|
583 |
|
|
.endm
|
584 |
|
|
|
585 |
|
|
.macro hal_fpu_pop_exc
|
586 |
|
|
hal_fpu_pop_int
|
587 |
|
|
.endm
|
588 |
|
|
|
589 |
|
|
#endif // CYGHWR_HAL_I386_FPU_SWITCH_LAZY
|
590 |
|
|
|
591 |
|
|
#else /* !CYGHWR_HAL_I386_FPU */
|
592 |
|
|
|
593 |
|
|
# Non-FP macros.
|
594 |
|
|
|
595 |
|
|
.macro hal_fpu_init
|
596 |
|
|
.endm
|
597 |
|
|
|
598 |
|
|
.macro hal_fpu_cpu_init
|
599 |
|
|
.endm
|
600 |
|
|
|
601 |
|
|
.macro hal_fpu_push_ctx
|
602 |
|
|
.endm
|
603 |
|
|
|
604 |
|
|
.macro hal_fpu_pop_ctx
|
605 |
|
|
.endm
|
606 |
|
|
|
607 |
|
|
.macro hal_fpu_push_int
|
608 |
|
|
.endm
|
609 |
|
|
|
610 |
|
|
.macro hal_fpu_push_int_annex
|
611 |
|
|
.endm
|
612 |
|
|
|
613 |
|
|
.macro hal_fpu_pop_int_annex
|
614 |
|
|
.endm
|
615 |
|
|
|
616 |
|
|
.macro hal_fpu_pop_int
|
617 |
|
|
.endm
|
618 |
|
|
|
619 |
|
|
.macro hal_fpu_push_exc
|
620 |
|
|
.endm
|
621 |
|
|
|
622 |
|
|
.macro hal_fpu_push_exc_annex
|
623 |
|
|
.endm
|
624 |
|
|
|
625 |
|
|
.macro hal_fpu_pop_exc_annex
|
626 |
|
|
.endm
|
627 |
|
|
|
628 |
|
|
.macro hal_fpu_pop_exc
|
629 |
|
|
.endm
|
630 |
|
|
|
631 |
|
|
#endif
|
632 |
|
|
|
633 |
|
|
#endif
|
634 |
|
|
|
635 |
|
|
#------------------------------------------------------------------------------
|
636 |
|
|
# MMU macros.
|
637 |
|
|
|
638 |
|
|
#ifndef CYGPKG_HAL_I386_MMU_DEFINED
|
639 |
|
|
|
640 |
|
|
#define CYGPKG_HAL_I386_MMU_DEFINED
|
641 |
|
|
|
642 |
|
|
.macro hal_mmu_init
|
643 |
|
|
.endm
|
644 |
|
|
|
645 |
|
|
#endif
|
646 |
|
|
|
647 |
|
|
#------------------------------------------------------------------------------
|
648 |
|
|
# A20 gate enable
|
649 |
|
|
|
650 |
|
|
#define K_RDWR 0x60
|
651 |
|
|
#define K_STATUS 0x64
|
652 |
|
|
#define K_CMD 0x64
|
653 |
|
|
#define K_OBUF_FUL 0x01
|
654 |
|
|
#define K_IBUF_FUL 0x02
|
655 |
|
|
#define KC_CMD_WIN 0xD0
|
656 |
|
|
#define KC_CMD_WOUT 0xD1
|
657 |
|
|
#define KB_A20 0xDF
|
658 |
|
|
|
659 |
|
|
.macro hal_a20_enable
|
660 |
|
|
// Enable A20 so that addresses at 1MB don't wrap around back to 0.
|
661 |
|
|
1: inb $K_STATUS, %al
|
662 |
|
|
testb $K_IBUF_FUL, %al
|
663 |
|
|
jnz 1b
|
664 |
|
|
|
665 |
|
|
2: inb $K_STATUS, %al
|
666 |
|
|
testb $K_OBUF_FUL, %al
|
667 |
|
|
jz 3f
|
668 |
|
|
inb $K_RDWR, %al
|
669 |
|
|
jmp 2b
|
670 |
|
|
|
671 |
|
|
3: movb $KC_CMD_WOUT, %al
|
672 |
|
|
outb %al, $K_CMD
|
673 |
|
|
1: inb $K_STATUS, %al
|
674 |
|
|
testb $K_IBUF_FUL, %al
|
675 |
|
|
jnz 1b
|
676 |
|
|
|
677 |
|
|
movb $KB_A20, %al
|
678 |
|
|
outb %al, $K_RDWR
|
679 |
|
|
1: inb $K_STATUS, %al
|
680 |
|
|
testb $K_IBUF_FUL, %al
|
681 |
|
|
jnz 1b
|
682 |
|
|
.endm
|
683 |
|
|
|
684 |
|
|
#------------------------------------------------------------------------------
|
685 |
|
|
# MEMC macros.
|
686 |
|
|
# This version simply enables the A20 gate.
|
687 |
|
|
|
688 |
|
|
#ifndef CYGPKG_HAL_I386_MEMC_DEFINED
|
689 |
|
|
|
690 |
|
|
.macro hal_memc_init
|
691 |
|
|
hal_a20_enable
|
692 |
|
|
.endm
|
693 |
|
|
|
694 |
|
|
#endif
|
695 |
|
|
|
696 |
|
|
#------------------------------------------------------------------------------
|
697 |
|
|
# Cache macros.
|
698 |
|
|
|
699 |
|
|
#ifndef CYGPKG_HAL_I386_CACHE_DEFINED
|
700 |
|
|
|
701 |
|
|
.macro hal_cache_init
|
702 |
|
|
.endm
|
703 |
|
|
|
704 |
|
|
#endif
|
705 |
|
|
|
706 |
|
|
#------------------------------------------------------------------------------
|
707 |
|
|
# Diagnostics macros.
|
708 |
|
|
|
709 |
|
|
#ifndef CYGPKG_HAL_I386_DIAG_DEFINED
|
710 |
|
|
|
711 |
|
|
.macro hal_diag_init
|
712 |
|
|
.endm
|
713 |
|
|
|
714 |
|
|
.macro hal_diag_excpt_start
|
715 |
|
|
.endm
|
716 |
|
|
|
717 |
|
|
.macro hal_diag_intr_start
|
718 |
|
|
.endm
|
719 |
|
|
|
720 |
|
|
.macro hal_diag_restore
|
721 |
|
|
.endm
|
722 |
|
|
#endif
|
723 |
|
|
|
724 |
|
|
#------------------------------------------------------------------------------
|
725 |
|
|
# Timer initialization.
|
726 |
|
|
|
727 |
|
|
#ifndef CYGPKG_HAL_I386_TIMER_DEFINED
|
728 |
|
|
|
729 |
|
|
.macro hal_timer_init
|
730 |
|
|
.endm
|
731 |
|
|
|
732 |
|
|
#endif
|
733 |
|
|
|
734 |
|
|
#------------------------------------------------------------------------------
|
735 |
|
|
# Monitor initialization.
|
736 |
|
|
|
737 |
|
|
#ifndef CYGPKG_HAL_I386_MON_DEFINED
|
738 |
|
|
|
739 |
|
|
.macro hal_mon_init
|
740 |
|
|
.endm
|
741 |
|
|
|
742 |
|
|
#endif
|
743 |
|
|
|
744 |
|
|
#------------------------------------------------------------------------------
|
745 |
|
|
#endif // ifndef CYGONCE_HAL_ARCH_INC
|
746 |
|
|
# end of arch.inc
|