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