-
Notifications
You must be signed in to change notification settings - Fork 57
/
cfe_psp_exception.c
211 lines (184 loc) · 6.91 KB
/
cfe_psp_exception.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/******************************************************************************
**
** File: cfe_psp_exception.c
**
** MCP750 vxWorks 6.2 Version
**
** Purpose:
** cFE PSP Exception related functions.
**
** History:
** 2007/05/29 A. Cudmore | vxWorks 6.2 MCP750 version
** 2016/04/07 M.Grubb | Updated for PSP version 1.3
**
******************************************************************************/
/*
** Include Files
*/
#include <stdio.h>
#include <string.h>
#include <vxWorks.h>
#include <sysLib.h>
#include "fppLib.h"
#include "excLib.h"
#include "taskLib.h"
#include "arch/ppc/vxPpcLib.h"
#include "arch/ppc/esfPpc.h"
/*
** cFE includes
*/
#include "common_types.h"
#include "osapi.h"
#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "cfe_psp_exceptionstorage_types.h"
#include "cfe_psp_exceptionstorage_api.h"
#include "cfe_psp_memory.h"
#include <target_config.h>
/*
**
** LOCAL FUNCTION PROTOTYPES
**
*/
void CFE_PSP_ExceptionHook(TASK_ID task_id, int vector, void *vpEsf);
/***************************************************************************
** FUNCTIONS DEFINITIONS
***************************************************************************/
/*
**
** Name: CFE_PSP_AttachExceptions
**
** Purpose: This function Initializes the task execptions and adds a hook
** into the VxWorks exception handling. The below hook is called
** for every exception that VxWorks catches.
**
** Notes: if desired - to attach a custom handler put following code in
** this function: excConnect ((VOIDFUNCPTR*)VECTOR, ExceptionHandler);
**
*/
void CFE_PSP_AttachExceptions(void)
{
excHookAdd(CFE_PSP_ExceptionHook);
OS_printf("CFE_PSP: Attached cFE Exception Handler. Context Size = %lu bytes.\n",
(unsigned long)sizeof(CFE_PSP_Exception_ContextDataEntry_t));
CFE_PSP_Exception_Reset();
}
/*
** Name: CFE_PSP_ExceptionHook
**
** Purpose: Make the proper call to CFE_ES_EXCEPTION_FUNCTION (defined in
** cfe_es_platform.cfg)
**
** Notes: pEsf - pointer to exception stack frame.
** fppSave - When it makes this call, it captures the last floating
** point context - which may not be valid. If a floating
** point exception occurs you can be almost 100% sure
** that this will reflect the proper context. But if another
** type of exception occurred then this has the possibility
** of not being valid. Specifically if a task that is not
** enabled for floating point causes a non-floating point
** exception, then the meaning of the floating point context
** will not be valid. If the task is enabled for floating point,
** then it will be valid.
**
*/
void CFE_PSP_ExceptionHook(TASK_ID task_id, int vector, void *vpEsf)
{
CFE_PSP_Exception_LogData_t *Buffer;
Buffer = CFE_PSP_Exception_GetNextContextBuffer();
if (Buffer != NULL)
{
/*
* Immediately get a snapshot of the timebase when exception occurred
*
* This is because the remainder of exception processing might be done
* in a cleanup job as a low priority background task, and might be
* considerably delayed from the time the actual exception occurred.
*/
vxTimeBaseGet(&Buffer->context_info.timebase_upper, &Buffer->context_info.timebase_lower);
Buffer->sys_task_id = task_id;
Buffer->context_info.vector = vector;
/*
* Save Exception Stack frame
*/
memcpy(&Buffer->context_info.esf, vpEsf, sizeof(Buffer->context_info.esf));
/*
* Save floating point registers
*/
fppSave(&Buffer->context_info.fp);
/*
* Save total size of context info.
* (This PSP always fills the entire structure)
*/
Buffer->context_size = sizeof(Buffer->context_info);
CFE_PSP_Exception_WriteComplete();
}
if (GLOBAL_CFE_CONFIGDATA.SystemNotify != NULL)
{
/* notify the CFE of the event */
GLOBAL_CFE_CONFIGDATA.SystemNotify();
}
} /* end function */
/*
**
** Name: CFE_PSP_SetDefaultExceptionEnvironment
**
** Purpose: This function sets a default exception environment that can be used
**
** Notes: The exception environment is local to each task Therefore this must be
** called for each task that that wants to do floating point and catch exceptions
*/
void CFE_PSP_SetDefaultExceptionEnvironment(void)
{
vxMsrSet(vxMsrGet() | _PPC_MSR_EE | /* enable the external interrupt */
_PPC_MSR_FP | /* enable floating point */
_PPC_MSR_ME | /* major hardware failures */
_PPC_MSR_FE0 | /* floating point exception 0 */
_PPC_MSR_FE1 | /* generate unrecoverable floating point exceptions */
_PPC_MSR_DR); /* enable data address translation (dbats?) */
vxFpscrSet(vxFpscrGet() | _PPC_FPSCR_VE | /* enable exceptions for invalid operations */
_PPC_FPSCR_OE | /* enable overflow exceptions */
_PPC_FPSCR_NI | /* Non-IEEE mode for denormailized numbers */
_PPC_FPSCR_ZE); /* enable divide by zero exceptions */
vxFpscrSet(vxFpscrGet() | _PPC_FPSCR_XE | /* fp inexact exc enable */
_PPC_FPSCR_UE); /* fp underflow enable */
}
/*
* Name: CFE_PSP_ExceptionGetSummary_Impl
*
* Purpose: Translate a stored exception log entry into a summary string
*/
int32 CFE_PSP_ExceptionGetSummary_Impl(const CFE_PSP_Exception_LogData_t *Buffer, char *ReasonBuf, uint32 ReasonSize)
{
const char *TaskName;
/*
** Get the vxWorks task name
*/
TaskName = taskName(Buffer->sys_task_id);
if (TaskName == NULL)
{
TaskName = "NULL";
}
snprintf(ReasonBuf, ReasonSize, "Vector=0x%06X, vxWorks Task Name=%s, Task ID=0x%08X", Buffer->context_info.vector,
TaskName, Buffer->sys_task_id);
return CFE_PSP_SUCCESS;
}