hal_misc.c
来自「eCos操作系统源码」· C语言 代码 · 共 587 行 · 第 1/2 页
C
587 行
//==========================================================================//// hal_misc.c//// HAL miscellaneous functions////==========================================================================//####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, jlarmour// Date: 1999-01-21// Purpose: HAL miscellaneous functions// Description: This file contains miscellaneous functions provided by the// HAL.////####DESCRIPTIONEND####////========================================================================*/#include <pkgconf/hal.h>#include <cyg/infra/cyg_type.h> // Base types#include <cyg/infra/cyg_trac.h> // tracing macros#include <cyg/infra/cyg_ass.h> // assertion macros#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS#include <cyg/hal/hal_arch.h> // architectural definitions#include <cyg/hal/hal_intr.h> // Interrupt handling#include <cyg/hal/hal_cache.h> // Cache handling#include <cyg/hal/hal_if.h> // hal_ctrlc_isr()#include <cyg/hal/mips-regs.h> // FPU cause register definitions#include CYGHWR_MEMORY_LAYOUT_H/*------------------------------------------------------------------------*//* If required, define a variable to store the clock period. */#ifdef CYGHWR_HAL_CLOCK_PERIOD_DEFINEDCYG_WORD32 cyg_hal_clock_period;#endif/*------------------------------------------------------------------------*//* First level C exception handler. */externC void __handle_exception (void);externC HAL_SavedRegisters *_hal_registers;externC void* volatile __mem_fault_handler;externC cyg_uint8 cyg_hal_mips_process_fpe( HAL_SavedRegisters *regs );externC cyg_uint32 cyg_hal_exception_handler(HAL_SavedRegisters *regs){#if defined(CYGHWR_HAL_MIPS_FPU) || \ (defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && defined(CYGPKG_HAL_EXCEPTIONS)) int vec = regs->vector>>2;#endif#if defined(CYGHWR_HAL_MIPS_FPU) // Special handling of FPU exceptions if (CYGNUM_HAL_VECTOR_FPE == vec) {#if defined(CYGSEM_HAL_MIPS_EMULATE_UNIMPLEMENTED_FPU_OPS) // We may be required to emulate certain unimplemented Floating Point // operations // cyg_hal_mips_process_fpe() returns non-zero if it could handle // the exception successfully. If so, we just return if ( cyg_hal_mips_process_fpe(regs) ) return 0;#endif // Find the cause of the FPU exception, clear the flag and use // the decoded vector number. { cyg_uint32 cause = regs->fcr31; if (cause & FCR31_CAUSE_I) { vec = CYGNUM_HAL_EXCEPTION_FPU_INEXACT; cause &= ~(FCR31_FLAGS_I | FCR31_CAUSE_I); } else if (cause & FCR31_CAUSE_U) { vec = CYGNUM_HAL_EXCEPTION_FPU_UNDERFLOW; cause &= ~(FCR31_FLAGS_U | FCR31_CAUSE_U); } else if (cause & FCR31_CAUSE_O) { vec = CYGNUM_HAL_EXCEPTION_FPU_OVERFLOW; cause &= ~(FCR31_FLAGS_O | FCR31_CAUSE_O); } else if (cause & FCR31_CAUSE_Z) { vec = CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO; cause &= ~(FCR31_FLAGS_Z | FCR31_CAUSE_Z); } else if (cause & FCR31_CAUSE_V) { vec = CYGNUM_HAL_EXCEPTION_FPU_INVALID; cause &= ~(FCR31_FLAGS_V | FCR31_CAUSE_V); } regs->fcr31 = cause;#if 1 // Update the FPU status register with the new // setting. This is a workaround for the signal2 test // which does a longjump in the exception handler and thus // never gets around to executing the register restore // code. asm ("ctc1 %0,$31" : : "r" (cause));#endif } }#endif // CYGHWR_HAL_MIPS_FPU#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) // If we caught an exception inside the stubs, see if we were expecting it // and if so jump to the saved address if (__mem_fault_handler) { regs->pc = (CYG_HAL_MIPS_REG)(signed long)__mem_fault_handler; return 0; // Caught an exception inside stubs } // Set the pointer to the registers of the current exception // context. At entry the GDB stub will expand the // HAL_SavedRegisters structure into a (bigger) register array. _hal_registers = regs; __handle_exception();#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && defined(CYGPKG_HAL_EXCEPTIONS) // We should decode the vector and pass a more appropriate // value as the second argument. For now we simply pass a // pointer to the saved registers. We should also divert // breakpoint and other debug vectors into the debug stubs. cyg_hal_deliver_exception( vec, (CYG_ADDRWORD)regs );#else CYG_FAIL("Exception!!!"); #endif return 0;}/*------------------------------------------------------------------------*//* default ISR */#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORTexternC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data){#if defined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT) && \ defined(CYGHWR_HAL_GDB_PORT_VECTOR) && \ defined(HAL_CTRLC_ISR)#ifndef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN if( vector == CYGHWR_HAL_GDB_PORT_VECTOR )#endif { cyg_uint32 result = HAL_CTRLC_ISR( vector, data ); if( result != 0 ) return result; } #if defined(CYGSEM_HAL_USE_ROM_MONITOR_CygMon)#if defined(HAL_DIAG_IRQ_CHECK) { cyg_uint32 ret; /* let ROM monitor handle unexpected interrupts */ HAL_DIAG_IRQ_CHECK(vector, ret); if (ret<=0) return ret; }#endif // def HAL_DIAG_IRQ_CHECK#endif // def CYGSEM_HAL_USE_ROM_MONITOR_CygMon#endif CYG_TRACE1(true, "Interrupt: %d", vector); CYG_FAIL("Spurious Interrupt!!!"); return 0;}#else // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORTexternC cyg_uint32 hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data){#if defined(CYGDBG_HAL_MIPS_DEBUG_GDB_CTRLC_SUPPORT) && \ defined(CYGHWR_HAL_GDB_PORT_VECTOR) && \ defined(HAL_CTRLC_ISR)#if defined(CYGSEM_HAL_USE_ROM_MONITOR_CygMon)#if defined(HAL_DIAG_IRQ_CHECK) { cyg_uint32 ret; /* let ROM monitor handle unexpected interrupts */ HAL_DIAG_IRQ_CHECK(vector, ret); if (ret<=0) return ret; }#endif // def HAL_DIAG_IRQ_CHECK#endif // def CYGSEM_HAL_USE_ROM_MONITOR_CygMon#endif#ifdef CYGPKG_REDBOOT hal_ctrlc_isr( vector, data );#endif return 0;}#endif // CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT/*------------------------------------------------------------------------*//* data copy and bss zero functions */typedef void (CYG_SYM_ADDRESS)(void);// All these must use this type of address to stop them being given relocations// relative to $gp (i.e. assuming they would be in .sdata)extern CYG_SYM_ADDRESS __ram_data_start;extern CYG_SYM_ADDRESS __ram_data_end;extern CYG_SYM_ADDRESS __rom_data_start; #ifdef CYG_HAL_STARTUP_ROM void hal_copy_data(void){ char *p = (char *)&__ram_data_start; char *q = (char *)&__rom_data_start; while( p != (char *)&__ram_data_end ) *p++ = *q++;}#endif/*------------------------------------------------------------------------*/#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAGcyg_bool cyg_hal_stop_constructors;#endiftypedef void (*pfunc) (void);extern pfunc __CTOR_LIST__[];extern pfunc __CTOR_END__[];voidcyg_hal_invoke_constructors(void){#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG static pfunc *p = &__CTOR_END__[-1]; cyg_hal_stop_constructors = 0; for (; p >= __CTOR_LIST__; p--) { (*p) (); if (cyg_hal_stop_constructors) { p--; break; } }#else pfunc *p;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?