File indexing completed on 2025-05-11 08:24:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include <bsp.h>
0039 #include <bsp/bootcard.h>
0040 #include <rtems/bspIo.h>
0041 #include <rtems/version.h>
0042 #include <rtems/score/heap.h>
0043 #include <rtems/score/smpimpl.h>
0044 #include <rtems/score/threadimpl.h>
0045 #include <inttypes.h>
0046
0047 void bsp_fatal_extension(
0048 rtems_fatal_source source,
0049 bool always_set_to_false,
0050 rtems_fatal_code code
0051 )
0052 {
0053 #if defined(RTEMS_SMP)
0054 if (
0055 source == RTEMS_FATAL_SOURCE_SMP &&
0056 code == SMP_FATAL_SHUTDOWN_RESPONSE
0057 ) {
0058
0059
0060
0061
0062
0063 _CPU_Thread_Idle_body( 0 );
0064 }
0065
0066
0067
0068
0069
0070 _SMP_Request_shutdown();
0071 #endif
0072
0073 #if BSP_VERBOSE_FATAL_EXTENSION
0074 Thread_Control *executing;
0075 const char* TYPE = "*** FATAL ***";
0076 const char* type = "fatal";
0077
0078 if ( source == RTEMS_FATAL_SOURCE_EXIT ) {
0079 if ( code == 0 ) {
0080 TYPE = "[ RTEMS shutdown ]";
0081 } else {
0082 TYPE = "*** EXIT STATUS NOT ZERO ***";
0083 }
0084 type = "exit";
0085 }
0086
0087 printk(
0088 "\n"
0089 "%s\n"
0090 ,
0091 TYPE
0092 );
0093
0094 if ( source != RTEMS_FATAL_SOURCE_EXIT || code != 0 ) {
0095 printk(
0096 "%s source: %i (%s)\n"
0097 ,
0098 type,
0099 source,
0100 rtems_fatal_source_text( source )
0101 );
0102 }
0103
0104 #ifdef RTEMS_SMP
0105 printk(
0106 "CPU: %" PRIu32 "\n"
0107 ,
0108 rtems_scheduler_get_processor()
0109 );
0110 #endif
0111 #endif
0112
0113 #if (BSP_PRINT_EXCEPTION_CONTEXT) || BSP_VERBOSE_FATAL_EXTENSION
0114 if ( source == RTEMS_FATAL_SOURCE_EXCEPTION ) {
0115 rtems_exception_frame_print( (const rtems_exception_frame *) code );
0116 }
0117 #endif
0118
0119 #if BSP_VERBOSE_FATAL_EXTENSION
0120 else if ( source == INTERNAL_ERROR_CORE ) {
0121 printk(
0122 "%s code: %ju (%s)\n",
0123 type,
0124 (uintmax_t) code,
0125 rtems_internal_error_text( code )
0126 );
0127 #if defined(HEAP_PROTECTION)
0128 } else if ( source == RTEMS_FATAL_SOURCE_HEAP ) {
0129 Heap_Error_context *error_context = (Heap_Error_context*) code;
0130 const char* reasons[] = {
0131 "HEAP_ERROR_BROKEN_PROTECTOR",
0132 "HEAP_ERROR_FREE_PATTERN",
0133 "HEAP_ERROR_DOUBLE_FREE",
0134 "HEAP_ERROR_BAD_USED_BLOCK",
0135 "HEAP_ERROR_BAD_FREE_BLOCK"
0136 };
0137 const char* reason = "invalid reason";
0138 if ( error_context->reason <= (int) HEAP_ERROR_BAD_FREE_BLOCK ) {
0139 reason = reasons[(int) error_context->reason];
0140 }
0141 printk(
0142 "heap error: heap=%p block=%p reason=%s(%d)",
0143 error_context->heap,
0144 error_context->block,
0145 reason,
0146 error_context->reason
0147 );
0148 if ( error_context->reason == HEAP_ERROR_BROKEN_PROTECTOR ) {
0149 uintptr_t *pb0 = &error_context->block->Protection_begin.protector [0];
0150 uintptr_t *pb1 = &error_context->block->Protection_begin.protector [1];
0151 uintptr_t *pe0 = &error_context->block->Protection_end.protector [0];
0152 uintptr_t *pe1 = &error_context->block->Protection_end.protector [1];
0153 printk(
0154 "=[%p,%p,%p,%p]",
0155 *pb0 != HEAP_BEGIN_PROTECTOR_0 ? pb0 : NULL,
0156 *pb1 != HEAP_BEGIN_PROTECTOR_1 ? pb1 : NULL,
0157 *pe0 != HEAP_END_PROTECTOR_0 ? pe0 : NULL,
0158 *pe1 != HEAP_END_PROTECTOR_1 ? pe1 : NULL
0159 );
0160 printk( "\n" );
0161 }
0162 #endif
0163 } else if ( source != RTEMS_FATAL_SOURCE_EXIT || code != 0 ) {
0164 printk(
0165 "%s code: %ju (0x%08jx)\n",
0166 type,
0167 (uintmax_t) code,
0168 (uintmax_t) code
0169 );
0170 }
0171
0172 printk(
0173 "RTEMS version: %s\n"
0174 "RTEMS tools: %s\n",
0175 rtems_version(),
0176 __VERSION__
0177 );
0178
0179 executing = _Thread_Get_executing();
0180
0181 if ( executing != NULL ) {
0182 char name[ 2 * THREAD_DEFAULT_MAXIMUM_NAME_SIZE ];
0183
0184 _Thread_Get_name( executing, name, sizeof( name ) );
0185 printk(
0186 "executing thread ID: 0x%08" PRIx32 "\n"
0187 "executing thread name: %s\n",
0188 executing->Object.id,
0189 name
0190 );
0191 } else {
0192 printk( "executing thread is NULL\n" );
0193 }
0194 #endif
0195
0196 #if (BSP_PRESS_KEY_FOR_RESET)
0197 printk( "\nFATAL ERROR - Executive shutdown! Any key to reboot..." );
0198
0199
0200
0201
0202 while ( getchark() == -1 )
0203 ;
0204
0205 printk("\n");
0206 #endif
0207
0208
0209
0210
0211
0212 #if (BSP_PRESS_KEY_FOR_RESET) || (BSP_RESET_BOARD_AT_EXIT)
0213 bsp_reset( source, code );
0214 #endif
0215 }