Mercurial > flash_v2
annotate packages/hal/arm/arch/current/src/hal_misc.c @ 50:a0774359f013 ecos-sw-1999-11-02
Merge from eCos master repository on 1999-11-02-17:02:15-GMT
| author | jlarmour |
|---|---|
| date | Tue, 02 Nov 1999 20:57:07 +0000 |
| parents | e7ba79f6d3a8 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 2 | 1 /*========================================================================== |
| 2 // | |
| 3 // hal_misc.c | |
| 4 // | |
| 5 // HAL miscellaneous functions | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 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 | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): nickg, gthomas | |
| 33 // Contributors: nickg, gthomas | |
| 34 // Date: 1999-02-20 | |
| 35 // Purpose: HAL miscellaneous functions | |
| 36 // Description: This file contains miscellaneous functions provided by the | |
| 37 // HAL. | |
| 38 // | |
| 39 //####DESCRIPTIONEND#### | |
| 40 // | |
| 41 //=========================================================================*/ | |
| 42 | |
| 43 #include <pkgconf/hal.h> | |
| 44 #include <pkgconf/hal_arm.h> | |
| 45 #ifdef CYGPKG_KERNEL | |
| 46 #include <pkgconf/kernel.h> | |
| 47 #endif | |
|
50
a0774359f013
Merge from eCos master repository on 1999-11-02-17:02:15-GMT
jlarmour
parents:
38
diff
changeset
|
48 #ifdef CYGPKG_CYGMON |
|
a0774359f013
Merge from eCos master repository on 1999-11-02-17:02:15-GMT
jlarmour
parents:
38
diff
changeset
|
49 #include <pkgconf/cygmon.h> |
|
a0774359f013
Merge from eCos master repository on 1999-11-02-17:02:15-GMT
jlarmour
parents:
38
diff
changeset
|
50 #endif |
| 2 | 51 |
| 52 #include <cyg/infra/cyg_type.h> | |
| 53 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 54 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 55 | |
| 56 #include <cyg/hal/hal_arch.h> // HAL header | |
| 57 #include <cyg/hal/hal_intr.h> // HAL header | |
| 58 | |
| 59 externC void diag_printf(const char *fmt, ...); | |
| 60 | |
| 61 /*------------------------------------------------------------------------*/ | |
| 62 /* First level C exception handler. */ | |
| 63 | |
| 64 externC void __handle_exception (void); | |
| 65 | |
| 66 externC HAL_SavedRegisters *_hal_registers; | |
| 67 extern void *__mem_fault_handler; | |
| 68 | |
| 69 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 70 /* Force exception handling into the GDB stubs. This is done by taking over | |
| 71 the exception vectors while executing in the stubs. This allows for the | |
| 72 debugged program to handle exceptions itself, except while the GDB | |
| 73 processing is underway. The only vector that can't be handled this way | |
| 74 is the illegal instruction vector which is used for breakpoint/single-step | |
| 75 and must be maintained by the stubs at all times. | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
76 Note: the interrupt vectors are _not_ preempted as the stubs probably can't |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
77 handle them properly. |
| 2 | 78 */ |
| 79 | |
| 80 #define ARM_VECTORS 8 | |
| 81 extern unsigned long vectors[]; // exception vectors as defined by the stubs | |
| 82 static unsigned long *hardware_vectors = (unsigned long *)0x20; | |
| 83 static unsigned long hold_vectors[ARM_VECTORS]; | |
| 84 | |
| 85 static int exception_level; | |
| 86 | |
| 87 static void | |
| 88 __take_over_debug_traps(void) | |
| 89 { | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
90 hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH]; |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
91 hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH]; |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
92 hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA]; |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
93 hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = vectors[CYGNUM_HAL_VECTOR_ABORT_DATA]; |
| 2 | 94 } |
| 95 | |
| 96 static void | |
| 97 __restore_debug_traps(void) | |
| 98 { | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
99 hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH]; |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
100 hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA]; |
| 2 | 101 } |
| 102 #endif | |
| 103 | |
| 104 void | |
| 105 exception_handler(HAL_SavedRegisters *regs) | |
| 106 { | |
|
50
a0774359f013
Merge from eCos master repository on 1999-11-02-17:02:15-GMT
jlarmour
parents:
38
diff
changeset
|
107 #if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) && !defined(CYGDAT_CYGMON_ENABLE) |
| 2 | 108 if (__mem_fault_handler && |
| 109 regs->vector == CYGNUM_HAL_EXCEPTION_DATA_ACCESS) { | |
| 110 regs->pc = (unsigned long)__mem_fault_handler; | |
| 111 return; // Caught an exception inside stubs | |
| 112 } | |
| 113 | |
| 114 if (++exception_level == 1) __take_over_debug_traps(); | |
| 115 | |
| 116 _hal_registers = regs; | |
| 117 __handle_exception(); | |
| 118 | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
119 if (--exception_level == 0) __restore_debug_traps(); |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
120 |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
121 #elif defined(CYGPKG_KERNEL_EXCEPTIONS) |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
28
diff
changeset
|
122 |
| 2 | 123 // We should decode the vector and pass a more appropriate |
| 124 // value as the second argument. For now we simply pass a | |
| 125 // pointer to the saved registers. We should also divert | |
| 126 // breakpoint and other debug vectors into the debug stubs. | |
| 127 | |
| 128 cyg_hal_deliver_exception( regs->vector, (CYG_ADDRWORD)regs ); | |
| 129 | |
| 130 #else | |
| 131 | |
| 132 CYG_FAIL("Exception!!!"); | |
| 133 | |
| 134 #endif | |
| 135 | |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 /*------------------------------------------------------------------------*/ | |
| 140 /* C++ support - run initial constructors */ | |
| 141 | |
| 142 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 143 cyg_bool cyg_hal_stop_constructors; | |
| 144 #endif | |
| 145 | |
| 146 typedef void (*pfunc) (void); | |
| 147 extern pfunc __CTOR_LIST__[]; | |
| 148 extern pfunc __CTOR_END__[]; | |
| 149 | |
| 150 void | |
| 151 cyg_hal_invoke_constructors (void) | |
| 152 { | |
| 153 | |
| 154 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG | |
| 155 static pfunc *p = &__CTOR_END__[-1]; | |
| 156 | |
| 157 cyg_hal_stop_constructors = 0; | |
| 158 for (; p >= __CTOR_LIST__; p--) { | |
| 159 (*p) (); | |
| 160 if (cyg_hal_stop_constructors) { | |
| 161 p--; | |
| 162 break; | |
| 163 } | |
| 164 } | |
| 165 #else | |
| 166 pfunc *p; | |
| 167 | |
| 168 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) | |
| 169 (*p) (); | |
| 170 #endif | |
| 171 } | |
| 172 | |
| 173 /*------------------------------------------------------------------------*/ | |
| 174 /* default ISR */ | |
| 175 | |
| 176 externC cyg_uint32 | |
| 177 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data) | |
| 178 { | |
| 179 CYG_TRACE1(true, "Interrupt: %d", vector); | |
|
28
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
180 |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
181 #ifndef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
182 #ifdef CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
183 #ifdef CYGDBG_HAL_CTRLC_ISR |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
184 // then see if it is an incoming character interrupt and break |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
185 // into the stub ROM if the char is a ^C. |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
186 if ( CYGDBG_HAL_CTRLC_ISR( vector, data ) ) |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
187 return 1; // interrupt handled |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
188 #endif |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
189 #endif |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
190 #endif |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
20
diff
changeset
|
191 |
| 2 | 192 diag_printf("Spurious Interrupt!!! - vector: %d, data: %x\n", vector, |
| 193 data); | |
| 194 CYG_FAIL("Spurious Interrupt!!!"); | |
| 195 return 0; | |
| 196 } | |
| 197 | |
| 198 /*------------------------------------------------------------------------*/ | |
| 199 /* Idle thread action */ | |
| 200 | |
| 201 void | |
| 202 hal_idle_thread_action( cyg_uint32 count ) | |
| 203 { | |
| 204 } | |
| 205 | |
| 206 /*-------------------------------------------------------------------------*/ | |
| 207 /* Misc functions */ | |
| 208 | |
| 209 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 210 /* This function will generate a breakpoint exception. It is used at the | |
| 211 beginning of a program to sync up with a debugger and can be used | |
| 212 otherwise as a quick means to stop program execution and "break" into | |
| 213 the debugger. */ | |
| 214 | |
| 215 void | |
| 216 breakpoint(void) | |
| 217 { | |
| 218 HAL_BREAKPOINT(breakinst); | |
| 219 } | |
| 220 | |
| 221 | |
| 222 /* This function returns the opcode for a 'trap' instruction. */ | |
| 223 | |
| 224 unsigned long | |
| 225 __break_opcode (void) | |
| 226 { | |
| 227 return HAL_BREAKINST; | |
| 228 } | |
| 229 #endif | |
| 230 | |
| 231 int | |
| 232 hal_lsbindex(int mask) | |
| 233 { | |
| 234 int i; | |
| 235 for (i = 0; i < 32; i++) { | |
| 236 if (mask & (1<<i)) return (i); | |
| 237 } | |
| 238 return (-1); | |
| 239 } | |
| 240 | |
| 241 int | |
| 242 hal_msbindex(int mask) | |
| 243 { | |
| 244 int i; | |
| 245 for (i = 32; i >= 0; i++) { | |
| 246 if (mask & (1<<i)) return (i); | |
| 247 } | |
| 248 return (-1); | |
| 249 } | |
| 250 | |
| 251 void | |
| 252 dump_buf_with_offset(unsigned char *p, | |
| 253 int s, | |
| 254 unsigned char *base) | |
| 255 { | |
| 256 int i, c; | |
| 257 if ((unsigned int)s > (unsigned int)p) { | |
| 258 s = (unsigned int)s - (unsigned int)p; | |
| 259 } | |
| 260 while (s > 0) { | |
| 261 if (base) { | |
| 262 diag_printf("%08X: ", (int)p - (int)base); | |
| 263 } else { | |
| 264 diag_printf("%08X: ", p); | |
| 265 } | |
| 266 for (i = 0; i < 16; i++) { | |
| 267 if (i < s) { | |
| 268 diag_printf("%02X", p[i] & 0xFF); | |
| 269 } else { | |
| 270 diag_printf(" "); | |
| 271 } | |
| 272 if ((i % 2) == 1) diag_printf(" "); | |
| 273 if ((i % 8) == 7) diag_printf(" "); | |
| 274 } | |
| 275 diag_printf(" |"); | |
| 276 for (i = 0; i < 16; i++) { | |
| 277 if (i < s) { | |
| 278 c = p[i] & 0xFF; | |
| 279 if ((c < 0x20) || (c >= 0x7F)) c = '.'; | |
| 280 } else { | |
| 281 c = ' '; | |
| 282 } | |
| 283 diag_printf("%c", c); | |
| 284 } | |
| 285 diag_printf("|\n"); | |
| 286 s -= 16; | |
| 287 p += 16; | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 void | |
| 292 dump_buf(unsigned char *p, int s) | |
| 293 { | |
| 294 dump_buf_with_offset(p, s, 0); | |
| 295 } | |
| 296 | |
| 297 #ifdef CYGHWR_HAL_ARM_DUMP_EXCEPTIONS | |
| 298 void | |
| 299 dump_frame(unsigned char *frame) | |
| 300 { | |
| 301 HAL_SavedRegisters *rp = (HAL_SavedRegisters *)frame; | |
| 302 int i; | |
| 303 dump_buf(frame, 128); | |
| 304 diag_printf("Registers:\n"); | |
| 305 for (i = 0; i <= 10; i++) { | |
| 306 if ((i == 0) || (i == 6)) diag_printf("R%d: ", i); | |
| 307 diag_printf("%08X ", rp->d[i]); | |
| 308 if ((i == 5) || (i == 10)) diag_printf("\n"); | |
| 309 } | |
| 310 diag_printf("FP: %08X, SP: %08X, LR: %08X, PC: %08X, PSR: %08X\n", | |
| 311 rp->fp, rp->sp, rp->lr, rp->pc, rp->cpsr); | |
| 312 } | |
| 313 #endif | |
| 314 | |
| 315 #if 0 | |
| 316 void | |
| 317 show_frame_in(HAL_SavedRegisters *frame) | |
| 318 { | |
| 319 int old; | |
| 320 HAL_DISABLE_INTERRUPTS(old); | |
| 321 diag_printf("[IN] IRQ Frame:\n"); | |
| 322 dump_frame((unsigned char *)frame); | |
| 323 HAL_RESTORE_INTERRUPTS(old); | |
| 324 } | |
| 325 | |
| 326 void | |
| 327 show_frame_out(HAL_SavedRegisters *frame) | |
| 328 { | |
| 329 int old; | |
| 330 HAL_DISABLE_INTERRUPTS(old); | |
| 331 diag_printf("[OUT] IRQ Frame:\n"); | |
| 332 dump_frame((unsigned char *)frame); | |
| 333 HAL_RESTORE_INTERRUPTS(old); | |
| 334 } | |
| 335 #endif | |
| 336 | |
| 337 #ifdef CYGHWR_HAL_ARM_DUMP_EXCEPTIONS | |
| 338 // Debug routines | |
|
20
5f5102441818
Merge from eCos master repository on 1999-07-02-23:17:07-BST
jlarmour
parents:
2
diff
changeset
|
339 void cyg_hal_report_undefined_instruction(HAL_SavedRegisters *frame) |
| 2 | 340 { |
| 341 int old; | |
| 342 HAL_DISABLE_INTERRUPTS(old); | |
| 343 diag_printf("[UNDEFINED INSTRUCTION] Frame:\n"); | |
| 344 dump_frame((unsigned char *)frame); | |
| 345 HAL_RESTORE_INTERRUPTS(old); | |
| 346 } | |
| 347 | |
|
20
5f5102441818
Merge from eCos master repository on 1999-07-02-23:17:07-BST
jlarmour
parents:
2
diff
changeset
|
348 void cyg_hal_report_software_interrupt(HAL_SavedRegisters *frame) |
| 2 | 349 { |
| 350 int old; | |
| 351 HAL_DISABLE_INTERRUPTS(old); | |
| 352 diag_printf("[SOFTWARE INTERRUPT] Frame:\n"); | |
| 353 dump_frame((unsigned char *)frame); | |
| 354 HAL_RESTORE_INTERRUPTS(old); | |
| 355 } | |
| 356 | |
|
20
5f5102441818
Merge from eCos master repository on 1999-07-02-23:17:07-BST
jlarmour
parents:
2
diff
changeset
|
357 void cyg_hal_report_abort_prefetch(HAL_SavedRegisters *frame) |
| 2 | 358 { |
| 359 int old; | |
| 360 HAL_DISABLE_INTERRUPTS(old); | |
| 361 diag_printf("[ABORT PREFETCH] Frame:\n"); | |
| 362 dump_frame((unsigned char *)frame); | |
| 363 HAL_RESTORE_INTERRUPTS(old); | |
| 364 } | |
| 365 | |
|
20
5f5102441818
Merge from eCos master repository on 1999-07-02-23:17:07-BST
jlarmour
parents:
2
diff
changeset
|
366 void cyg_hal_report_abort_data(HAL_SavedRegisters *frame) |
| 2 | 367 { |
| 368 int old; | |
| 369 HAL_DISABLE_INTERRUPTS(old); | |
| 370 diag_printf("[ABORT DATA] Frame:\n"); | |
| 371 dump_frame((unsigned char *)frame); | |
| 372 HAL_RESTORE_INTERRUPTS(old); | |
| 373 } | |
| 374 | |
|
20
5f5102441818
Merge from eCos master repository on 1999-07-02-23:17:07-BST
jlarmour
parents:
2
diff
changeset
|
375 void cyg_hal_report_exception_handler_returned(HAL_SavedRegisters *frame) |
| 2 | 376 { |
| 377 int old; | |
| 378 HAL_DISABLE_INTERRUPTS(old); | |
| 379 diag_printf("Exception handler returned!\n"); | |
| 380 dump_frame((unsigned char *)frame); | |
| 381 HAL_RESTORE_INTERRUPTS(old); | |
| 382 } | |
| 383 #endif | |
| 384 | |
| 385 /*------------------------------------------------------------------------*/ | |
| 386 // EOF hal_misc.c |
