📄 arch.inc
字号:
#ifndef CYGONCE_HAL_ARCH_INC#define CYGONCE_HAL_ARCH_INC##=============================================================================#### arch.inc#### i386 assembler header file####=============================================================================#####ECOSGPLCOPYRIGHTBEGIN###### -------------------------------------------## This file is part of eCos, the Embedded Configurable Operating System.## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.#### eCos is free software; you can redistribute it and/or modify it under## the terms of the GNU General Public License as published by the Free## Software Foundation; either version 2 or (at your option) any later version.#### eCos is distributed in the hope that it will be useful, but WITHOUT ANY## WARRANTY; without even the implied warranty of MERCHANTABILITY or## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License## for more details.#### You should have received a copy of the GNU General Public License along## with eCos; if not, write to the Free Software Foundation, Inc.,## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.#### As a special exception, if other files instantiate templates or use macros## or inline functions from this file, or you compile this file and link it## with other works to produce a work based on this file, this file does not## by itself cause the resulting work to be covered by the GNU General Public## License. However the source code for this file must still be made available## in accordance with section (3) of the GNU General Public License.#### This exception does not invalidate any other reasons why a work based on## this file might be covered by the GNU General Public License.#### Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.## at http://sources.redhat.com/ecos/ecos-license/## -------------------------------------------#####ECOSGPLCOPYRIGHTEND######=============================================================================#######DESCRIPTIONBEGIN######## Author(s): nickg## Contributors: nickg, pjo## Date: 1999-10-15## Purpose: Architecture definitions.## Description: This file contains various definitions and macros that are## useful for writing assembly code for the i386 CPU family.## Usage:## #include <cyg/hal/arch.inc>## ...## ########DESCRIPTIONEND########=============================================================================#include <cyg/hal/i386.inc>#include <cyg/hal/variant.inc>##-----------------------------------------------------------------------------## CPU specific macros. These provide a common assembler interface to## operations that may have CPU specific implementations on different## variants of the architecture. #ifndef CYGPKG_HAL_I386_CPU_INIT_DEFINED # Initialize CPU .macro hal_cpu_init .endm#endif /* !CYGPKG_HAL_I386_CPU_INIT_DEFINED */##-----------------------------------------------------------------------------#ifndef CYGPKG_HAL_I386_INTC_DEFINED#ifndef CYGPKG_HAL_I386_INTC_INIT_DEFINED # initialize all interrupts to disabled .macro hal_intc_init .endm#endif .macro hal_intc_decode vnum .endm#endif#------------------------------------------------------------------------------# SMP support #ifdef CYGPKG_HAL_SMP_SUPPORT .macro hal_smp_init#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) movl $0,cyg_hal_smp_vsr_sync_flag#endif .endm // Put CPU number in register .macro hal_smp_cpu reg movl cyg_hal_smp_local_apic,\reg movl 0x20(\reg),\reg shrl $24,\reg .endm#else .macro hal_smp_init .endm .macro hal_smp_cpu reg movl $0,\reg .endm#endif #------------------------------------------------------------------------------# Stack switching macros#ifndef CYG_HAL_I386_INTSTACK_MACROS_DEFINED#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK#ifdef CYGPKG_HAL_SMP_SUPPORT .macro hal_init_istack reg hal_smp_cpu %ebx movl $__interrupt_stack_vector,%ecx movl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,%eax imull %ebx,%eax addl $__interrupt_stack_first,%eax movl %eax,0(%ecx,%ebx,4) movl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,\reg addl %eax,\reg .endm .macro hal_load_istack reg hal_load_istack_base \reg addl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,\reg .endm .macro hal_load_istack_base reg hal_smp_cpu \reg movl $__interrupt_stack_vector,%eax movl 0(%eax,\reg,4),\reg .endm#else // CYGPKG_HAL_SMP_SUPPORT .macro hal_init_istack reg,tr movl $__interrupt_stack,\reg // Load interrupt stack .endm .macro hal_load_istack reg movl $__interrupt_stack,\reg // Load interrupt stack .endm .macro hal_load_istack_base reg movl $__interrupt_stack_base,\reg // Load interrupt stack base .endm#endif // CYGPKG_HAL_SMP_SUPPORT .macro hal_to_intstack hal_load_istack_base %ebx // EBX = stack base movl %ebx,%eax addl $CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE,%eax cmpl %ebx,%ebp # compare SP with istack base jb 1f # if sp < istack base, switch cmpl %eax,%ebp # compare SP with istack top jbe 2f # if sp < istack top, dont switch1: movl %eax,%esp # move on to new stack2: pushl %ebp # Save old SP on new stack .endm .macro hal_from_intstack popl %esp # pop old SP from stack .endm#define CYG_HAL_I386_INTSTACK_MACROS_DEFINED#else // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK .macro hal_init_istack reg .endm .macro hal_load_istack_base reg .endm .macro hal_load_istack reg .endm .macro hal_to_intstack .endm .macro hal_from_intstack .endm#define CYG_HAL_I386_INTSTACK_MACROS_DEFINED#endif // CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK#endif // CYG_HAL_I386_INTSTACK_MACROS_DEFINED #------------------------------------------------------------------------------# FPU macros. #ifndef CYGPKG_HAL_I386_FPU_DEFINED#ifdef CYGHWR_HAL_I386_FPU#define CYGPKG_HAL_I386_FPU_DEFINED .macro hal_fpu_init # Tell the CPU to use the math hardware. movl %cr0, %eax orl $0x32, %eax # Set MP, ET, NE bits andl $~0x8, %eax # And clear TS bit movl %eax, %cr0 finit # and initialize... ## Enable floating point exceptions. Bit mask: ## 1 - invalid operation ## 2 - denormalized operand ## 4 - zero divide ## 8 - overflow ## 16 - underflow ## 32 - precision pushl $0 # space for CW fstcw 0(%esp) # store FPCW to stack movl 0(%esp),%eax # get into EAX andb $(~0x04),%al # allow only zero divide exceptions movl %eax,0(%esp) # put back into memory fldcw 0(%esp) # reload addl $4,%esp # pop value#ifdef CYGHWR_HAL_I386_PENTIUM_SSE # set CR4.OSFXSR to safely use stmxcsr/ldmxcsr movl %cr4, %eax orl $0x200, %eax movl %eax, %cr4 ## Enable SIMD exceptions. Bit mask: ## 0x0080 - invalid operation ## 0x0100 - denormalized operand ## 0x0200 - zero divide ## 0x0400 - overflow ## 0x0800 - underflow ## 0x1000 - precision pushl $0 # space for MXCSR stmxcsr 0(%esp) # store MXCSR to stack movl 0(%esp),%eax # get into EAX andw $(~0x0200),%ax # allow only zero divide exceptions movl %eax,0(%esp) # put back into memory ldmxcsr 0(%esp) # reload addl $4,%esp # pop value#endif#ifdef CYGHWR_HAL_I386_FPU_SWITCH_LAZY # Tell the CPU to generate an FPU unavailable exception # when the FPU is first used. movl %cr0, %eax orl $0x8, %eax movl %eax, %cr0 # Plant a pointer to the FPU switch VSR into slot 7 # of the VSR table. movl $__fpu_switch_vsr,%eax movl %eax,(hal_vsr_table+7*4) # Now create an FPU context on the stack so that we can take # FPU-using interrupts and exceptions before the machine starts # up. subl $i386reg_fpucontext_size,%esp movl $0,i386reg_fpucontext_valid(%esp) hal_smp_cpu %ebx # get CPU id movl $cyg_hal_fpustate_current,%ecx # current state table movl %esp,0(%ecx,%ebx,4) # save in table[cpu] entry#endif .endm .macro hal_fpu_cpu_init # Tell the CPU to use the math hardware. movl %cr0, %eax orl $0x32, %eax # Set MP, ET, NE bits andl $~0x8, %eax # And clear TS bit movl %eax, %cr0 finit # and initialize... ## Enable floating point exceptions. Bit mask: ## 1 - invalid operation ## 2 - denormalized operand ## 4 - zero divide ## 8 - overflow ## 16 - underflow ## 32 - precision pushl $0 # space for CW fstcw 0(%esp) # store FPCW to stack movl 0(%esp),%eax # get into EAX andb $(~0x04),%al # allow only zero divide exceptions movl %eax,0(%esp) # put back into memory fldcw 0(%esp) # reload addl $4,%esp # pop value#ifdef CYGHWR_HAL_I386_PENTIUM_SSE # set CR4.OSFXSR to safely use stmxcsr/ldmxcsr movl %cr4, %eax orl $0x200, %eax movl %eax, %cr4 ## Enable SIMD exceptions. Bit mask: ## 0x0080 - invalid operation ## 0x0100 - denormalized operand ## 0x0200 - zero divide ## 0x0400 - overflow ## 0x0800 - underflow ## 0x1000 - precision pushl $0 # space for MXCSR stmxcsr 0(%esp) # store MXCSR to stack movl 0(%esp),%eax # get into EAX andw $(~0x0200),%ax # allow only zero divide exceptions movl %eax,0(%esp) # put back into memory ldmxcsr 0(%esp) # reload addl $4,%esp # pop value#endif#ifdef CYGHWR_HAL_I386_FPU_SWITCH_LAZY # Tell the CPU to generate an FPU unavailable exception # when the FPU is first used. movl %cr0, %eax orl $0x8, %eax movl %eax, %cr0 # Now create an FPU context on the stack so that we can take # FPU-using interrupts and exceptions before the kernel starts # up. subl $i386reg_fpucontext_size,%esp movl $0,i386reg_fpucontext_valid(%esp) hal_smp_cpu %ebx # get CPU id movl $cyg_hal_fpustate_current,%ecx # current state table movl %esp,0(%ecx,%ebx,4) # save in table[cpu] entry#endif .endm#ifndef CYGHWR_HAL_I386_FPU_SWITCH_LAZY # Non-lazy CPU state switching. We simply switch the entire # FPU state on every context switch, interrupt or exception. # ------------------------------------------------------------ # Context switch handling .macro hal_fpu_push_ctx subl $i386reg_fpstate_size,%esp # make space fnsave i386reg_fpstate(%esp) # save FPU state#ifdef CYGHWR_HAL_I386_PENTIUM_SSE # Save SIMD state. # FIXME. This is awfully inefficient. Need to use FXSAVE to # save FPU and SIMD at same time. FXSAVE requires a 16 byte # alignment and does not have an implicit finit as does FSAVE. stmxcsr i386reg_simd_mxcsr(%esp) movups %xmm0,i386reg_simd_xmm0(%esp) movups %xmm1,i386reg_simd_xmm1(%esp) movups %xmm2,i386reg_simd_xmm2(%esp) movups %xmm3,i386reg_simd_xmm3(%esp) movups %xmm4,i386reg_simd_xmm4(%esp) movups %xmm5,i386reg_simd_xmm5(%esp) movups %xmm6,i386reg_simd_xmm6(%esp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -