1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSBSPsShared |
---|
7 | * |
---|
8 | * @brief This source file contains the implementation of |
---|
9 | * bsp_fatal_extension(). |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-1999. |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #include <bsp.h> |
---|
39 | #include <bsp/bootcard.h> |
---|
40 | #include <rtems/bspIo.h> |
---|
41 | #include <rtems/version.h> |
---|
42 | #include <rtems/score/heap.h> |
---|
43 | #include <rtems/score/threadimpl.h> |
---|
44 | #include <inttypes.h> |
---|
45 | |
---|
46 | void bsp_fatal_extension( |
---|
47 | rtems_fatal_source source, |
---|
48 | bool always_set_to_false, |
---|
49 | rtems_fatal_code code |
---|
50 | ) |
---|
51 | { |
---|
52 | #if BSP_VERBOSE_FATAL_EXTENSION |
---|
53 | Thread_Control *executing; |
---|
54 | const char* TYPE = "*** FATAL ***"; |
---|
55 | const char* type = "fatal"; |
---|
56 | |
---|
57 | if ( source == RTEMS_FATAL_SOURCE_EXIT ) { |
---|
58 | if ( code == 0 ) { |
---|
59 | TYPE = "[ RTEMS shutdown ]"; |
---|
60 | } else { |
---|
61 | TYPE = "*** EXIT STATUS NOT ZERO ***"; |
---|
62 | } |
---|
63 | type = "exit"; |
---|
64 | } |
---|
65 | |
---|
66 | printk( |
---|
67 | "\n" |
---|
68 | "%s\n" |
---|
69 | , |
---|
70 | TYPE |
---|
71 | ); |
---|
72 | |
---|
73 | if ( source != RTEMS_FATAL_SOURCE_EXIT || code != 0 ) { |
---|
74 | printk( |
---|
75 | "%s source: %i (%s)\n" |
---|
76 | , |
---|
77 | type, |
---|
78 | source, |
---|
79 | rtems_fatal_source_text( source ) |
---|
80 | ); |
---|
81 | } |
---|
82 | |
---|
83 | #ifdef RTEMS_SMP |
---|
84 | printk( |
---|
85 | "CPU: %" PRIu32 "\n" |
---|
86 | , |
---|
87 | rtems_scheduler_get_processor() |
---|
88 | ); |
---|
89 | #endif |
---|
90 | #endif |
---|
91 | |
---|
92 | #if (BSP_PRINT_EXCEPTION_CONTEXT) || BSP_VERBOSE_FATAL_EXTENSION |
---|
93 | if ( source == RTEMS_FATAL_SOURCE_EXCEPTION ) { |
---|
94 | rtems_exception_frame_print( (const rtems_exception_frame *) code ); |
---|
95 | } |
---|
96 | #endif |
---|
97 | |
---|
98 | #if BSP_VERBOSE_FATAL_EXTENSION |
---|
99 | else if ( source == INTERNAL_ERROR_CORE ) { |
---|
100 | printk( |
---|
101 | "%s code: %ju (%s)\n", |
---|
102 | type, |
---|
103 | (uintmax_t) code, |
---|
104 | rtems_internal_error_text( code ) |
---|
105 | ); |
---|
106 | #if defined(HEAP_PROTECTION) |
---|
107 | } else if ( source == RTEMS_FATAL_SOURCE_HEAP ) { |
---|
108 | Heap_Error_context *error_context = (Heap_Error_context*) code; |
---|
109 | const char* reasons[] = { |
---|
110 | "HEAP_ERROR_BROKEN_PROTECTOR", |
---|
111 | "HEAP_ERROR_FREE_PATTERN", |
---|
112 | "HEAP_ERROR_DOUBLE_FREE", |
---|
113 | "HEAP_ERROR_BAD_USED_BLOCK", |
---|
114 | "HEAP_ERROR_BAD_FREE_BLOCK" |
---|
115 | }; |
---|
116 | const char* reason = "invalid reason"; |
---|
117 | if ( error_context->reason <= (int) HEAP_ERROR_BAD_FREE_BLOCK ) { |
---|
118 | reason = reasons[(int) error_context->reason]; |
---|
119 | } |
---|
120 | printk( |
---|
121 | "heap error: heap=%p block=%p reason=%s(%d)", |
---|
122 | error_context->heap, |
---|
123 | error_context->block, |
---|
124 | reason, |
---|
125 | error_context->reason |
---|
126 | ); |
---|
127 | if ( error_context->reason == HEAP_ERROR_BROKEN_PROTECTOR ) { |
---|
128 | uintptr_t *pb0 = &error_context->block->Protection_begin.protector [0]; |
---|
129 | uintptr_t *pb1 = &error_context->block->Protection_begin.protector [1]; |
---|
130 | uintptr_t *pe0 = &error_context->block->Protection_end.protector [0]; |
---|
131 | uintptr_t *pe1 = &error_context->block->Protection_end.protector [1]; |
---|
132 | printk( |
---|
133 | "=[%p,%p,%p,%p]", |
---|
134 | *pb0 != HEAP_BEGIN_PROTECTOR_0 ? pb0 : NULL, |
---|
135 | *pb1 != HEAP_BEGIN_PROTECTOR_1 ? pb1 : NULL, |
---|
136 | *pe0 != HEAP_END_PROTECTOR_0 ? pe0 : NULL, |
---|
137 | *pe1 != HEAP_END_PROTECTOR_1 ? pe1 : NULL |
---|
138 | ); |
---|
139 | printk( "\n" ); |
---|
140 | } |
---|
141 | #endif |
---|
142 | } else if ( source != RTEMS_FATAL_SOURCE_EXIT || code != 0 ) { |
---|
143 | printk( |
---|
144 | "%s code: %ju (0x%08jx)\n", |
---|
145 | type, |
---|
146 | (uintmax_t) code, |
---|
147 | (uintmax_t) code |
---|
148 | ); |
---|
149 | } |
---|
150 | |
---|
151 | printk( |
---|
152 | "RTEMS version: %s\n" |
---|
153 | "RTEMS tools: %s\n", |
---|
154 | rtems_version(), |
---|
155 | __VERSION__ |
---|
156 | ); |
---|
157 | |
---|
158 | executing = _Thread_Get_executing(); |
---|
159 | |
---|
160 | if ( executing != NULL ) { |
---|
161 | char name[ 2 * THREAD_DEFAULT_MAXIMUM_NAME_SIZE ]; |
---|
162 | |
---|
163 | _Thread_Get_name( executing, name, sizeof( name ) ); |
---|
164 | printk( |
---|
165 | "executing thread ID: 0x%08" PRIx32 "\n" |
---|
166 | "executing thread name: %s\n", |
---|
167 | executing->Object.id, |
---|
168 | name |
---|
169 | ); |
---|
170 | } else { |
---|
171 | printk( "executing thread is NULL\n" ); |
---|
172 | } |
---|
173 | #endif |
---|
174 | |
---|
175 | #if (BSP_PRESS_KEY_FOR_RESET) |
---|
176 | printk( "\nFATAL ERROR - Executive shutdown! Any key to reboot..." ); |
---|
177 | |
---|
178 | /* |
---|
179 | * Wait for a key to be pressed |
---|
180 | */ |
---|
181 | while ( getchark() == -1 ) |
---|
182 | ; |
---|
183 | |
---|
184 | printk("\n"); |
---|
185 | #endif |
---|
186 | |
---|
187 | /* |
---|
188 | * Check both conditions -- if you want to ask for reboot, then |
---|
189 | * you must have meant to reset the board. |
---|
190 | */ |
---|
191 | #if (BSP_PRESS_KEY_FOR_RESET) || (BSP_RESET_BOARD_AT_EXIT) |
---|
192 | bsp_reset(); |
---|
193 | #endif |
---|
194 | } |
---|