Mercurial > flash_v2
comparison packages/hal/mn10300/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 | 01ce82f3e11a |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 1 /*============================================================================= | 1 /*========================================================================== |
| 2 // | 2 // |
| 3 // hal_misc.c | 3 // hal_misc.c |
| 4 // | 4 // |
| 5 // HAL miscellaneous functions | 5 // HAL miscellaneous functions |
| 6 // | 6 // |
| 7 //============================================================================= | 7 //========================================================================== |
| 8 //####COPYRIGHTBEGIN#### | 8 //####COPYRIGHTBEGIN#### |
| 9 // | 9 // |
| 10 // ------------------------------------------- | 10 // ------------------------------------------- |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | 11 // The contents of this file are subject to the Cygnus eCos Public License |
| 12 // Version 1.0 (the "License"); you may not use this file except in | 12 // Version 1.0 (the "License"); you may not use this file except in |
| 20 // | 20 // |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | 21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 22 // September 30, 1998. | 22 // September 30, 1998. |
| 23 // | 23 // |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | 24 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 26 // ------------------------------------------- | 26 // ------------------------------------------- |
| 27 // | 27 // |
| 28 //####COPYRIGHTEND#### | 28 //####COPYRIGHTEND#### |
| 29 //============================================================================= | 29 //========================================================================== |
| 30 //#####DESCRIPTIONBEGIN#### | 30 //#####DESCRIPTIONBEGIN#### |
| 31 // | 31 // |
| 32 // Author(s): nickg | 32 // Author(s): nickg |
| 33 // Contributors: nickg | 33 // Contributors: nickg, jlarmour |
| 34 // Date: 1997-11-12 | 34 // Date: 1999-02-18 |
| 35 // Purpose: HAL miscellaneous functions | 35 // Purpose: HAL miscellaneous functions |
| 36 // Description: This file contains miscellaneous functions provided by the | 36 // Description: This file contains miscellaneous functions provided by the |
| 37 // HAL. | 37 // HAL. |
| 38 // | 38 // |
| 39 //####DESCRIPTIONEND#### | 39 //####DESCRIPTIONEND#### |
| 40 // | 40 // |
| 41 //===========================================================================*/ | 41 //========================================================================*/ |
| 42 | 42 |
| 43 #include <pkgconf/hal.h> | 43 #include <pkgconf/hal.h> |
| 44 | 44 |
| 45 #include <cyg/infra/cyg_type.h> | 45 #include <cyg/infra/cyg_type.h> |
| 46 | 46 |
| 48 | 48 |
| 49 #include <cyg/hal/hal_intr.h> | 49 #include <cyg/hal/hal_intr.h> |
| 50 | 50 |
| 51 #include <cyg/hal/hal_cache.h> | 51 #include <cyg/hal/hal_cache.h> |
| 52 | 52 |
| 53 /*---------------------------------------------------------------------------*/ | 53 #if 0 |
| 54 | 54 void trace( CYG_ADDRWORD tag, CYG_ADDRWORD a1, CYG_ADDRWORD a2) |
| 55 void | 55 { |
| 56 cyg_hal_invoke_constructors (void) | 56 CYG_ADDRWORD **pp = (CYG_ADDRWORD **)0x48100000; |
| 57 CYG_ADDRWORD *ix = (CYG_ADDRWORD *)0x4810000C; | |
| 58 CYG_ADDRWORD *p = *pp; | |
| 59 *p++ = tag; | |
| 60 *ix = *ix + 1; | |
| 61 *p++ = *ix; | |
| 62 *p++ = a1; | |
| 63 *p++ = a2; | |
| 64 *pp = p; | |
| 65 } | |
| 66 #endif | |
| 67 | |
| 68 /*------------------------------------------------------------------------*/ | |
| 69 | |
| 70 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 71 cyg_bool cyg_hal_stop_constructors; | |
| 72 #endif | |
| 73 | |
| 74 void | |
| 75 cyg_hal_invoke_constructors(void) | |
| 57 { | 76 { |
| 58 typedef void (*pfunc) (void); | 77 typedef void (*pfunc) (void); |
| 59 extern pfunc _CTOR_LIST__[]; | 78 extern pfunc _CTOR_LIST__[]; |
| 60 extern pfunc _CTOR_END__[]; | 79 extern pfunc _CTOR_END__[]; |
| 80 | |
| 81 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 82 static pfunc *p = &_CTOR_END__[-1]; | |
| 83 | |
| 84 cyg_hal_stop_constructors = 0; | |
| 85 for (; p >= _CTOR_LIST__; p--) { | |
| 86 (*p) (); | |
| 87 if (cyg_hal_stop_constructors) { | |
| 88 p--; | |
| 89 break; | |
| 90 } | |
| 91 } | |
| 92 #else | |
| 61 pfunc *p; | 93 pfunc *p; |
| 62 | 94 |
| 63 #ifdef CYG_KERNEL_USE_INIT_PRIORITY | |
| 64 for (p = &_CTOR_END__[-1]; p >= _CTOR_LIST__; p--) | 95 for (p = &_CTOR_END__[-1]; p >= _CTOR_LIST__; p--) |
| 65 (*p) (); | 96 (*p) (); |
| 66 #else | 97 #endif |
| 67 for (p = _CTOR_LIST__; p != _CTOR_END__; p++) | 98 |
| 68 (*p) (); | 99 } // cyg_hal_invoke_constructors() |
| 69 #endif | 100 |
| 70 | 101 void |
| 102 cyg_hal_enable_caches(void) | |
| 103 { | |
| 71 #ifdef CYG_HAL_MN10300_STDEVAL1 | 104 #ifdef CYG_HAL_MN10300_STDEVAL1 |
| 72 | 105 |
| 73 // On the real hardware we also enable the cache. | 106 // On the real hardware we also enable the cache. |
| 74 // doing this here is a temporary measure until we | 107 // doing this here is a temporary measure until we |
| 75 // have a proper platform specific place to do it. | 108 // have a proper platform specific place to do it. |
| 83 HAL_DCACHE_INVALIDATE_ALL(); | 116 HAL_DCACHE_INVALIDATE_ALL(); |
| 84 HAL_DCACHE_ENABLE(); | 117 HAL_DCACHE_ENABLE(); |
| 85 | 118 |
| 86 #endif | 119 #endif |
| 87 | 120 |
| 88 #if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \ | 121 } // cyg_hal_enable_caches() |
| 122 | |
| 123 void | |
| 124 cyg_hal_debug_init(void) | |
| 125 { | |
| 126 #if defined(CYGPKG_KERNEL) && \ | |
| 127 defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \ | |
| 89 defined(CYG_HAL_USE_ROM_MONITOR) && \ | 128 defined(CYG_HAL_USE_ROM_MONITOR) && \ |
| 90 defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) | 129 defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) |
| 91 { | 130 { |
| 92 extern CYG_ADDRESS hal_virtual_vector_table[32]; | 131 extern CYG_ADDRESS hal_virtual_vector_table[32]; |
| 93 extern void patch_dbg_syscalls(void * vector); | 132 extern void patch_dbg_syscalls(void * vector); |
| 94 #define DBG_SYSCALL_VEC_NUM 15 | 133 patch_dbg_syscalls( (void *)(&hal_virtual_vector_table[0]) ); |
| 95 patch_dbg_syscalls( (void *)(&hal_virtual_vector_table[DBG_SYSCALL_VEC_NUM]) ); | |
| 96 } | 134 } |
| 97 #endif | 135 #endif |
| 98 | 136 |
| 99 } | 137 } |
| 100 | 138 |
| 101 /*---------------------------------------------------------------------------*/ | 139 /*------------------------------------------------------------------------*/ |
| 102 /* Determine the index of the ls bit of the supplied mask. */ | 140 /* Determine the index of the ls bit of the supplied mask. */ |
| 103 | 141 |
| 104 cyg_uint32 hal_lsbit_index(cyg_uint32 mask) | 142 cyg_uint32 |
| 143 hal_lsbit_index(cyg_uint32 mask) | |
| 105 { | 144 { |
| 106 cyg_uint32 n = mask; | 145 cyg_uint32 n = mask; |
| 107 | 146 |
| 108 static const signed char tab[64] = | 147 static const signed char tab[64] = |
| 109 { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10, | 148 { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10, |
| 118 n = (n<<4)+n; | 157 n = (n<<4)+n; |
| 119 | 158 |
| 120 return tab[n>>26]; | 159 return tab[n>>26]; |
| 121 } | 160 } |
| 122 | 161 |
| 123 /*---------------------------------------------------------------------------*/ | 162 /*------------------------------------------------------------------------*/ |
| 124 /* Determine the index of the ms bit of the supplied mask. */ | 163 /* Determine the index of the ms bit of the supplied mask. */ |
| 125 | 164 |
| 126 cyg_uint32 hal_msbit_index(cyg_uint32 mask) | 165 cyg_uint32 |
| 166 hal_msbit_index(cyg_uint32 mask) | |
| 127 { | 167 { |
| 128 cyg_uint32 x = mask; | 168 cyg_uint32 x = mask; |
| 129 cyg_uint32 w; | 169 cyg_uint32 w; |
| 130 | 170 |
| 131 /* Phase 1: make word with all ones from that one to the right */ | 171 /* Phase 1: make word with all ones from that one to the right */ |
| 142 w = (w & 0x000F000F) + ((w >> 8) & 0x000F000F); | 182 w = (w & 0x000F000F) + ((w >> 8) & 0x000F000F); |
| 143 return (cyg_uint32)((w + (w >> 16)) & 0xFF); | 183 return (cyg_uint32)((w + (w >> 16)) & 0xFF); |
| 144 | 184 |
| 145 } | 185 } |
| 146 | 186 |
| 147 /*---------------------------------------------------------------------------*/ | 187 /*------------------------------------------------------------------------*/ |
| 148 /* First level C exception handler. */ | 188 /* First level C exception handler. */ |
| 149 | 189 |
| 150 void exception_handler(HAL_SavedRegisters *regs) | 190 externC void __handle_exception (void); |
| 151 { | 191 |
| 192 externC HAL_SavedRegisters *_hal_registers; | |
| 193 | |
| 194 void | |
| 195 cyg_hal_exception_handler(HAL_SavedRegisters *regs) | |
| 196 { | |
| 197 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 198 | |
| 199 // Set the pointer to the registers of the current exception | |
| 200 // context. At entry the GDB stub will expand the | |
| 201 // HAL_SavedRegisters structure into a (bigger) register array. | |
| 202 _hal_registers = regs; | |
| 203 | |
| 204 __handle_exception(); | |
| 205 | |
| 206 #elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) | |
| 207 | |
| 208 CYG_WORD vector = regs->vector; | |
| 209 | |
| 210 if( vector == CYGNUM_HAL_INTERRUPT_WATCHDOG ) | |
| 211 { | |
| 212 // Special case the watchdog timer exception, look for an | |
| 213 // ISR for it and call it if present. Otherwise pass on to | |
| 214 // the exception system. | |
| 215 | |
| 216 cyg_uint32 (*isr)(CYG_ADDRWORD,CYG_ADDRWORD); | |
| 217 cyg_uint32 index; | |
| 218 | |
| 219 HAL_TRANSLATE_VECTOR( CYGNUM_HAL_INTERRUPT_WATCHDOG, index ); | |
| 220 | |
| 221 isr = (cyg_uint32 (*)(CYG_ADDRWORD,CYG_ADDRWORD)) | |
| 222 (hal_interrupt_handlers[index]); | |
| 223 | |
| 224 if( isr != 0 ) | |
| 225 { | |
| 226 isr(CYGNUM_HAL_INTERRUPT_WATCHDOG, | |
| 227 hal_interrupt_data[CYGNUM_HAL_INTERRUPT_WATCHDOG] | |
| 228 ); | |
| 229 return; | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 #if defined(CYGPKG_HAL_EXCEPTIONS) | |
| 234 | |
| 152 // We should decode the vector and pass a more appropriate | 235 // We should decode the vector and pass a more appropriate |
| 153 // value as the second argument. For now we simply pass a | 236 // value as the second argument. For now we simply pass a |
| 154 // pointer to the saved registers. We should also divert | 237 // pointer to the saved registers. We should also divert |
| 155 // breakpoint and other debug vectors into the debug stubs. | 238 // breakpoint and other debug vectors into the debug stubs. |
| 156 | 239 |
| 157 #if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) | 240 cyg_hal_deliver_exception( vector, (CYG_ADDRWORD)regs ); |
| 158 | |
| 159 CYG_WORD vector = regs->vector; | |
| 160 | |
| 161 if( vector == 0 ) | |
| 162 { | |
| 163 // An NMI vector, decode it from the NMIGR | |
| 164 | |
| 165 cyg_uint32 nmigr = mn10300_interrupt_control[0]; | |
| 166 | |
| 167 // Write back to clear interrupt bits | |
| 168 mn10300_interrupt_control[0] = nmigr; | |
| 169 | |
| 170 if( nmigr & 0x0002 ) | |
| 171 { | |
| 172 // Special case the watchdog timer exception, look for an | |
| 173 // ISR for it and call it if present. Otherwise pass on to | |
| 174 // the exception system. | |
| 175 | |
| 176 cyg_uint32 (*isr)(CYG_ADDRWORD,CYG_ADDRWORD); | |
| 177 cyg_uint32 index; | |
| 178 | |
| 179 HAL_TRANSLATE_VECTOR( CYG_VECTOR_WATCHDOG, index ); | |
| 180 | |
| 181 isr = (cyg_uint32 (*)(CYG_ADDRWORD,CYG_ADDRWORD)) | |
| 182 (hal_interrupt_handlers[index]); | |
| 183 | |
| 184 if( isr != 0 ) | |
| 185 { | |
| 186 isr(CYG_VECTOR_WATCHDOG, | |
| 187 hal_interrupt_data[CYG_VECTOR_WATCHDOG] | |
| 188 ); | |
| 189 return; | |
| 190 } | |
| 191 vector = CYG_VECTOR_WATCHDOG; | |
| 192 } | |
| 193 // Check for system error | |
| 194 else if( nmigr & 0x0004 ) vector = CYG_VECTOR_SYSTEM_ERROR; | |
| 195 | |
| 196 // otherwise it is an NMI and vector is correct. | |
| 197 } | |
| 198 | |
| 199 #if defined(CYGPKG_HAL_EXCEPTIONS) | |
| 200 | |
| 201 deliver_exception( vector, (CYG_ADDRWORD)regs ); | |
| 202 | 241 |
| 203 #endif | 242 #endif |
| 204 | 243 |
| 205 #endif | 244 #endif |
| 206 | 245 |
| 207 return; | 246 return; |
| 208 } | 247 } |
| 209 | 248 |
| 210 /*---------------------------------------------------------------------------*/ | 249 /*------------------------------------------------------------------------*/ |
| 211 /* End of hal_misc.c */ | 250 /* End of hal_misc.c */ |
