Mercurial > flash_v2
diff packages/hal/mips/arch/current/src/hal_misc.c @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | d376b777e2ce |
line wrap: on
line diff
--- a/packages/hal/mips/arch/current/src/hal_misc.c +++ b/packages/hal/mips/arch/current/src/hal_misc.c @@ -1,10 +1,10 @@ -//============================================================================= +//========================================================================== // -// hal_misc.c +// hal_misc.c // -// HAL miscellaneous functions +// HAL miscellaneous functions // -//============================================================================= +//========================================================================== //####COPYRIGHTBEGIN#### // // ------------------------------------------- @@ -22,23 +22,23 @@ // September 30, 1998. // // The Initial Developer of the Original Code is Cygnus. Portions created -// by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. +// by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. // ------------------------------------------- // //####COPYRIGHTEND#### -//============================================================================= +//========================================================================== //#####DESCRIPTIONBEGIN#### // -// Author(s): nickg -// Contributors: nickg -// Date: 1998-02-05 -// Purpose: HAL miscellaneous functions -// Description: This file contains miscellaneous functions provided by the -// HAL. +// 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> @@ -52,8 +52,8 @@ #include <cyg/hal/hal_cache.h> // Cache handling -/*---------------------------------------------------------------------------*/ -/* First level C exception handler. */ +/*------------------------------------------------------------------------*/ +/* First level C exception handler. */ externC void __handle_exception (void); @@ -76,7 +76,7 @@ externC void exception_handler(HAL_Saved // pointer to the saved registers. We should also divert // breakpoint and other debug vectors into the debug stubs. - deliver_exception( regs->vector>>2, (CYG_ADDRWORD)regs ); + cyg_hal_deliver_exception( regs->vector>>2, (CYG_ADDRWORD)regs ); #else @@ -86,8 +86,8 @@ externC void exception_handler(HAL_Saved return; } -/*---------------------------------------------------------------------------*/ -/* default ISR */ +/*------------------------------------------------------------------------*/ +/* default ISR */ externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data) { @@ -96,17 +96,18 @@ externC cyg_uint32 hal_default_isr(CYG_A return 0; } -/*---------------------------------------------------------------------------*/ -/* data copy and bss zero functions */ +/*------------------------------------------------------------------------*/ +/* data copy and bss zero functions */ typedef void (CYG_ROM_ADDRESS)(void); -#ifdef CYG_HAL_STARTUP_ROM +extern char __ram_data_start; +extern char __ram_data_end; +extern CYG_ROM_ADDRESS __rom_data_start; + +#ifdef CYG_HAL_STARTUP_ROM void hal_copy_data(void) { - extern char __ram_data_start; - extern char __ram_data_end; - extern CYG_ROM_ADDRESS __rom_data_start; char *p = &__ram_data_start; char *q = (char *)&__rom_data_start; @@ -115,109 +116,98 @@ void hal_copy_data(void) } #endif +extern CYG_ROM_ADDRESS __bss_start; +extern CYG_ROM_ADDRESS __bss_end; + void hal_zero_bss(void) { - extern CYG_ROM_ADDRESS __bss_start; - extern CYG_ROM_ADDRESS _end; char *p = (char *)&__bss_start; - while( p != (char *)&_end ) + while( p != (char *)&__bss_end ) *p++ = 0; } -/*---------------------------------------------------------------------------*/ +/*------------------------------------------------------------------------*/ -void fake_ctor(void) {}; +#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG +cyg_bool cyg_hal_stop_constructors; +#endif + +typedef void (*pfunc) (void); +extern pfunc __CTOR_LIST__[]; +extern void patch_dbg_syscalls(void * vector); void -cyg_hal_invoke_constructors (void) +cyg_hal_invoke_constructors(void) { -#ifdef CYG_KERNEL_USE_INIT_PRIORITY + pfunc p; - typedef void (*pfunc) (void); - extern pfunc __CTOR_LIST__[]; +#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG + static long i = 0; + long j = (long)(__CTOR_LIST__[0]); + + cyg_hal_stop_constructors=0; + for ( ; i < j; i++ ) + { + p = __CTOR_LIST__[j - i]; + p (); + if (cyg_hal_stop_constructors) { + i++; + break; + } + } +#else long i = (long)(__CTOR_LIST__[0]); - pfunc p; for ( ; i > 0; i-- ) { p = __CTOR_LIST__[i]; p (); } - -#else +#endif +} // cyg_hal_invoke_constructors() - typedef void (CYG_CODE_ADDRESS)(); - extern CYG_CODE_ADDRESS __sched_text_start; - extern CYG_CODE_ADDRESS __sched_text_end; - extern CYG_CODE_ADDRESS __clock_text_start; - extern CYG_CODE_ADDRESS __clock_text_end; - extern CYG_CODE_ADDRESS __thread_text_start; - extern CYG_CODE_ADDRESS __thread_text_end; - - typedef void (*pfunc) (); - extern pfunc __CTOR_LIST__[]; - pfunc *p; - - for (p = __CTOR_LIST__+1; *p != 0; p++) - { - CYG_ADDRESS *pp = (CYG_ADDRESS *)*p; - - if( pp > (CYG_ADDRESS *)&__sched_text_start && - pp < (CYG_ADDRESS *)&__sched_text_end ) - { - (*p) (); - *p = fake_ctor; - } - } - - for (p = __CTOR_LIST__+1; *p != 0; p++) - { - CYG_ADDRESS *pp = (CYG_ADDRESS *)*p; - - if( pp > (CYG_ADDRESS *)&__clock_text_start && - pp < (CYG_ADDRESS *)&__clock_text_end ) - { - (*p) (); - *p = fake_ctor; - } - } - - for (p = __CTOR_LIST__+1; *p != 0; p++) - { - CYG_ADDRESS *pp = (CYG_ADDRESS *)*p; - - if( pp > (CYG_ADDRESS *)&__thread_text_start && - pp < (CYG_ADDRESS *)&__thread_text_end ) - { - (*p) (); - *p = fake_ctor; - } - } - - for (p = __CTOR_LIST__+1; *p != 0; p++) - { - (*p) (); - *p = fake_ctor; - } - -#endif - +void +cyg_hal_enable_caches(void) +{ #ifdef CYG_HAL_MIPS_TX3904 // On the real hardware we also enable the cache. // doing this here is a temporary measure until we // have a proper platform specific place to do it. +#if !defined(CYGHWR_HAL_TX39_JMR3904_ENABLE_TOE) + HAL_ICACHE_INVALIDATE_ALL(); HAL_ICACHE_ENABLE(); HAL_DCACHE_INVALIDATE_ALL(); HAL_DCACHE_ENABLE(); + HAL_TX39_DEBUG_TOE_DISABLE(); + +#else + + // If TOE is enabled, caches are disabled by default + // until spurious Bus Timeout problem is fixed. + + HAL_ICACHE_INVALIDATE_ALL(); + HAL_ICACHE_DISABLE(); + HAL_DCACHE_INVALIDATE_ALL(); + HAL_DCACHE_DISABLE(); + + HAL_TX39_DEBUG_TOE_ENABLE(); + #endif - -#if defined(CYG_HAL_USE_ROM_MONITOR) && \ - !defined(CYGDBG_INFRA_DIAG_USE_DEVICE) && \ + +#endif +} // cyg_hal_enable_caches() + +void +cyg_hal_debug_init(void) +{ +#ifdef CYGDBG_HAL_MIPS_INSTALL_CTRL_C_ISR +#if defined(CYG_HAL_USE_ROM_MONITOR) && \ + !defined(CYGDBG_INFRA_DIAG_USE_DEVICE) && \ defined(CYG_HAL_TX39_JMR3904) { @@ -226,19 +216,19 @@ cyg_hal_invoke_constructors (void) } #endif +#endif // CYGDBG_HAL_MIPS_INSTALL_CTRL_C_ISR + #if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \ defined(CYG_HAL_USE_ROM_MONITOR) && \ defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) { - extern void patch_dbg_syscalls(void * vector); -#define DBG_SYSCALL_VEC_NUM 15 - patch_dbg_syscalls( (void *)(&hal_vsr_table[DBG_SYSCALL_VEC_NUM]) ); + patch_dbg_syscalls( (void *)(&hal_vsr_table[0]) ); } #endif -} +} // cyg_hal_debug_init() -/*---------------------------------------------------------------------------*/ -/* Determine the index of the ls bit of the supplied mask. */ +/*------------------------------------------------------------------------*/ +/* Determine the index of the ls bit of the supplied mask. */ cyg_uint32 hal_lsbit_index(cyg_uint32 mask) { @@ -259,8 +249,8 @@ cyg_uint32 hal_lsbit_index(cyg_uint32 ma return tab[n>>26]; } -/*---------------------------------------------------------------------------*/ -/* Determine the index of the ms bit of the supplied mask. */ +/*------------------------------------------------------------------------*/ +/* Determine the index of the ms bit of the supplied mask. */ cyg_uint32 hal_msbit_index(cyg_uint32 mask) { @@ -283,8 +273,8 @@ cyg_uint32 hal_msbit_index(cyg_uint32 ma } -/*---------------------------------------------------------------------------*/ -/* Idle thread action */ +/*------------------------------------------------------------------------*/ +/* Idle thread action */ void hal_idle_thread_action( cyg_uint32 count ) { @@ -337,10 +327,50 @@ void hal_idle_thread_action( cyg_uint32 #endif } -/*---------------------------------------------------------------------------*/ -/* This code installs an interrupt handler to capture Ctrl-C. */ -/* It's here for lack of anywhere more suitable to put it. */ - +/*------------------------------------------------------------------------*/ +/* Functions to support the detection and execution of a user provoked */ +/* program break. These are usually called from interrupt routines. */ + +cyg_bool cyg_hal_is_break(char *buf, int size) +{ + while( size ) + if( buf[--size] == 0x03 ) return true; + + return false; +} + +void cyg_hal_user_break( CYG_ADDRWORD *regs ) +{ +#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) + + // Ctrl-C: breakpoint. + extern void breakpoint(void); + breakpoint(); + +#elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_GDB_STUBS) + + // Ctrl-C: breakpoint. + typedef void bpt_fn(void); + bpt_fn *bfn = ((bpt_fn **)0x80000100)[61]; + bfn(); + +#elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) + + // Ctrl-C: breakpoint. + typedef void install_bpt_fn(void *epc); + HAL_SavedRegisters *sreg = (HAL_SavedRegisters *)regs; + install_bpt_fn *ibp = (install_bpt_fn *)hal_vsr_table[35]; + if( ibp != NULL ) ibp((void *)sreg->pc); + +#endif + +} + +/*------------------------------------------------------------------------*/ +/* This code installs an interrupt handler to capture Ctrl-C. */ +/* It's here for lack of anywhere more suitable to put it. */ + +#ifdef CYGDBG_HAL_MIPS_INSTALL_CTRL_C_ISR #if defined(CYG_HAL_USE_ROM_MONITOR) && \ !defined(CYGDBG_INFRA_DIAG_USE_DEVICE) && \ defined(CYG_HAL_TX39_JMR3904) @@ -359,8 +389,12 @@ void hal_idle_thread_action( cyg_uint32 #define BRG_T2 0x0100 #define BRG_T4 0x0200 #define BRG_T5 0x0300 - -static cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data) + +typedef cyg_uint32 (*original_isr_ptr_t)(CYG_ADDRWORD vector, CYG_ADDRWORD data); +static original_isr_ptr_t original_isr_ptr; +static CYG_ADDRWORD original_data, original_object; + +static cyg_uint32 hal_ctrlc_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data, CYG_ADDRWORD* regs) { char c; CYG_WORD16 disr; @@ -375,34 +409,13 @@ static cyg_uint32 hal_ctrlc_isr(CYG_ADDR HAL_READ_UINT8( DIAG_RFIFO, c ); HAL_WRITE_UINT16( DIAG_SLDISR , disr ); - -#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) - if( c == 3 ) - { - // Ctrl-C: breakpoint. - extern void breakpoint(void); - breakpoint(); - } -#elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_GDB_STUBS) - if( c == 3 ) - { - // Ctrl-C: breakpoint. -// HAL_BREAKPOINT(_breakinst); - typedef void bpt_fn(void); - bpt_fn *bfn = ((bpt_fn **)0x80000100)[61]; - - bfn(); - } -#elif defined(CYG_HAL_USE_ROM_MONITOR) && defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) - if( c == 3 ) - { - // Ctrl-C: breakpoint. - HAL_BREAKPOINT(_breakinst1); - } -#endif + + if( cyg_hal_is_break( &c , 1 ) ) + cyg_hal_user_break( regs ); + return 0; } - - return 0; + /* else */ + return (*original_isr_ptr)(vector, data); } @@ -410,9 +423,20 @@ static void hal_init_ctrlc_intr(void) { CYG_WORD16 dicr; - HAL_INTERRUPT_ATTACH( CYG_VECTOR_SIO_0, hal_ctrlc_isr, NULL, NULL ); + cyg_uint32 index; + HAL_TRANSLATE_VECTOR(CYGNUM_HAL_INTERRUPT_SIO_0, index); + + original_data = hal_interrupt_data[index]; + original_object = hal_interrupt_objects[index]; + original_isr_ptr = (original_isr_ptr_t) hal_interrupt_handlers[index]; - HAL_INTERRUPT_UNMASK( CYG_VECTOR_SIO_0 ); + hal_interrupt_handlers[index] = + (CYG_ADDRESS)hal_default_isr; + + HAL_INTERRUPT_ATTACH( CYGNUM_HAL_INTERRUPT_SIO_0, hal_ctrlc_isr, original_data, + original_object ); + + HAL_INTERRUPT_UNMASK( CYGNUM_HAL_INTERRUPT_SIO_0 ); HAL_READ_UINT16( DIAG_SLDICR , dicr ); dicr = 0x0001; @@ -420,6 +444,7 @@ static void hal_init_ctrlc_intr(void) } #endif +#endif // CYGDBG_HAL_MIPS_INSTALL_CTRL_C_ISR -/*---------------------------------------------------------------------------*/ -/* End of hal_misc.c */ +/*------------------------------------------------------------------------*/ +/* End of hal_misc.c */
