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