Skip to content

Commit 21b017b

Browse files
committed
Fix nasa#158, Exception handling in PSP
Implment exceptions for VxWorks and PC-Linux PSP Exceptions are buffered in an extra block inside the PSP reserved area. On pc-linux, the interrupt (CTRL+C) handling is also treated as an exception, which shuts down the CFE normally. This also means processor resets on the pc-linux can be tested.
1 parent 09b62df commit 21b017b

25 files changed

+1591
-723
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ add_definitions(-D_CFE_PSP_)
99
include_directories(fsw/shared)
1010

1111
# Build the PSP implementation which lies in a system-specific subdirectory
12+
include_directories(fsw/shared)
1213
include_directories(fsw/${CFE_SYSTEM_PSPNAME}/inc)
1314
add_subdirectory(fsw/${CFE_SYSTEM_PSPNAME} ${CFE_SYSTEM_PSPNAME})
1415

1516
# Build the "common" parts as a library
1617
add_library(psp-${CFE_SYSTEM_PSPNAME} STATIC
1718
fsw/shared/cfe_psp_configdata.c
1819
fsw/shared/cfe_psp_eeprom.c
20+
fsw/shared/cfe_psp_exceptionstorage.c
1921
fsw/shared/cfe_psp_memrange.c
2022
fsw/shared/cfe_psp_memutils.c
2123
fsw/shared/cfe_psp_module.c

fsw/inc/cfe_psp.h

+6-11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (-27)
6666
#define CFE_PSP_INVALID_MODULE_NAME (-28)
6767
#define CFE_PSP_INVALID_MODULE_ID (-29)
68+
#define CFE_PSP_NO_EXCEPTION_DATA (-30)
6869

6970

7071

@@ -196,7 +197,7 @@ extern uint32 CFE_PSP_GetRestartType(uint32 *restartSubType );
196197
*/
197198

198199

199-
extern void CFE_PSP_FlushCaches(uint32 type, cpuaddr address, uint32 size);
200+
extern void CFE_PSP_FlushCaches(uint32 type, void* address, uint32 size);
200201
/*
201202
** This is a BSP specific cache flush routine
202203
*/
@@ -247,16 +248,6 @@ extern uint32 CFE_PSP_Get_Dec(void);
247248
** CFE_PSP_Get_Dec
248249
*/
249250

250-
251-
extern int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType );
252-
/*
253-
** CFE_PSP_InitProcessorReservedMemory initializes all of the memory in the
254-
** BSP that is preserved on a processor reset. The memory includes the
255-
** Critical Data Store, the ES Reset Area, the Volatile Disk Memory, and
256-
** the User Reserved Memory. In general, the memory areas will be initialized
257-
** ( cleared ) on a Power On reset, and preserved during a processor reset.
258-
*/
259-
260251
extern int32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS);
261252
/*
262253
** CFE_PSP_GetCDSSize fetches the size of the OS Critical Data Store area.
@@ -368,6 +359,10 @@ extern void CFE_PSP_SetDefaultExceptionEnvironment(void);
368359
*/
369360

370361

362+
extern uint32 CFE_PSP_Exception_GetCount(void);
363+
extern int32 CFE_PSP_Exception_GetSummary(uint32 *ContextLogId, uint32 *TaskId, char *ReasonBuf, uint32 ReasonSize);
364+
extern int32 CFE_PSP_Exception_CopyContext(uint32 ContextLogId, void *ContextBuf, uint32 ContextSize);
365+
371366
/*
372367
** I/O Port API
373368
*/

fsw/inc/cfe_psp_configdata.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,12 @@ typedef const struct
5858
uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */
5959
uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */
6060
uint32 PSP_MemTableSize; /**< Size of PSP memory table */
61+
uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */
6162
CFE_PSP_MemTable_t *PSP_MemoryTable; /**< Pointer to PSP memory table (forward reference) */
6263

6364
uint32 OS_VolumeTableSize; /**< Size of OS volume table */
6465
OS_VolumeInfo_t *OS_VolumeTable; /**< Pointer to OS volume table (forward reference) */
6566

66-
/**
67-
* Processor Context type.
68-
* This is needed to determine the size of the context entry in the ER log.
69-
* It is a placeholder as the implementation to use it is not merged in yet.
70-
*/
71-
uint32 OS_CpuContextSize;
72-
7367
/**
7468
* Number of EEPROM banks on this platform
7569
*/

fsw/mcp750-vxworks/inc/cfe_psp_config.h

+47-11
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,47 @@
4444
*/
4545
#define CFE_PSP_MEM_TABLE_SIZE 10
4646

47+
/**
48+
* This define sets the maximum number of exceptions
49+
* that can be stored.
50+
*
51+
* It must always be a power of two.
52+
*/
53+
#define CFE_PSP_MAX_EXCEPTION_ENTRIES 4
54+
4755
/*
48-
** Processor Context type.
49-
** This is needed to determine the size of the context entry in the ER log.
50-
** Although this file is in a CPU directory, it really is OS dependant, so supporting
51-
** multiple OSs on the same CPU architecture ( i.e. x86/linux, x86/windows, x86/osx )
52-
** will require IFDEFS.
56+
** Typedef for the layout of the vxWorks boot record structure
57+
**
58+
** This is statically placed at the beginning of system memory (sysMemTop)
59+
** which should be reserved in the kernel.
5360
*/
54-
typedef struct
61+
typedef struct
5562
{
56-
ESFPPC esf; /* Exception stack frame */
57-
FP_CONTEXT fp; /* floating point registers */
58-
59-
} CFE_PSP_ExceptionContext_t;
63+
uint32 bsp_reset_type;
64+
uint32 spare1;
65+
uint32 spare2;
66+
uint32 spare3;
67+
68+
} CFE_PSP_ReservedMemoryBootRecord_t;
6069

61-
#define CFE_PSP_CPU_CONTEXT_SIZE (sizeof(CFE_PSP_ExceptionContext_t))
70+
71+
/**
72+
* \brief The data type used by the underlying OS to represent a thread ID.
73+
*/
74+
typedef TASK_ID CFE_PSP_Exception_SysTaskId_t;
75+
76+
/*
77+
** Global variables
78+
*/
79+
typedef struct
80+
{
81+
UINT32 timebase_upper; /* Upper 32 bits of timebase as sampled by hook */
82+
UINT32 timebase_lower; /* Lower 32 bits of timebase as sampled by hook */
83+
int vector; /* vector number */
84+
ESFPPC esf; /* Exception stack frame */
85+
FP_CONTEXT fp; /* floating point registers */
86+
87+
} CFE_PSP_Exception_ContextDataEntry_t;
6288

6389
/*
6490
** Watchdog minimum and maximum values ( in milliseconds )
@@ -71,6 +97,16 @@ typedef struct
7197
*/
7298
#define CFE_PSP_NUM_EEPROM_BANKS 1
7399

100+
/*
101+
* The alignment to use for each reserved memory block.
102+
*
103+
* This is a mask to be applied to each block base address
104+
*
105+
* Chosen as the cache line size of the MPC750 processor (32 bytes)
106+
* such that the blocks will be cached more efficiently.
107+
*/
108+
#define CFE_PSP_MEMALIGN_MASK ((cpuaddr)0x1F)
109+
74110

75111
#endif
76112

fsw/mcp750-vxworks/src/cfe_psp_exception.c

+59-58
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,11 @@
5454

5555
#include "cfe_psp.h"
5656
#include "cfe_psp_config.h"
57+
#include "cfe_psp_exceptionstorage.h"
5758
#include "cfe_psp_memory.h"
5859

5960
#include <target_config.h>
6061

61-
/*
62-
** Types and prototypes for this module
63-
*/
64-
65-
/* use the exception ISR binding from the global config data */
66-
#define CFE_PSP_ES_EXCEPTION_FUNCTION (*GLOBAL_CONFIGDATA.CfeConfig->SystemExceptionISR)
67-
68-
/*
69-
** BSP Specific defines
70-
*/
71-
72-
73-
/*
74-
** External Declarations
75-
*/
76-
77-
/*
78-
** Global variables
79-
*/
80-
81-
CFE_PSP_ExceptionContext_t CFE_PSP_ExceptionContext;
82-
char CFE_PSP_ExceptionReasonString[256];
83-
8462
/*
8563
**
8664
** LOCAL FUNCTION PROTOTYPES
@@ -110,7 +88,8 @@ void CFE_PSP_ExceptionHook ( TASK_ID task_id, int vector, void* vpEsf );
11088
void CFE_PSP_AttachExceptions(void)
11189
{
11290
excHookAdd( CFE_PSP_ExceptionHook );
113-
OS_printf("CFE_PSP: Attached cFE Exception Handler. Context Size = %d bytes.\n",CFE_PSP_CPU_CONTEXT_SIZE);
91+
OS_printf("CFE_PSP: Attached cFE Exception Handler. Context Size = %u bytes.\n",sizeof(CFE_PSP_Exception_ContextDataEntry_t));
92+
CFE_PSP_Exception_Reset();
11493
}
11594

11695

@@ -135,46 +114,42 @@ void CFE_PSP_AttachExceptions(void)
135114
*/
136115
void CFE_PSP_ExceptionHook (TASK_ID task_id, int vector, void* vpEsf )
137116
{
138-
ESFPPC *pEsf = vpEsf;
139-
char *TaskName;
117+
CFE_PSP_Exception_LogData_t* Buffer;
140118

141-
/*
142-
** Get the vxWorks task name
143-
*/
144-
TaskName = taskName(task_id);
145-
146-
if ( TaskName == NULL )
119+
Buffer = CFE_PSP_Exception_GetNextContextBuffer();
120+
if (Buffer != NULL)
147121
{
148-
sprintf(CFE_PSP_ExceptionReasonString, "Exception: Vector=0x%06X, vxWorks Task Name=NULL, Task ID=0x%08X",
149-
vector,task_id);
122+
/*
123+
* Immediately get a snapshot of the timebase when exception occurred
124+
*
125+
* This is because the remainder of exception processing might be done
126+
* in a cleanup job as a low priority background task, and might be
127+
* considerably delayed from the time the actual exception occurred.
128+
*/
129+
vxTimeBaseGet(&Buffer->context_info.timebase_upper, &Buffer->context_info.timebase_lower);
130+
131+
Buffer->sys_task_id = task_id;
132+
Buffer->context_info.vector = vector;
133+
134+
/*
135+
* Save Exception Stack frame
136+
*/
137+
memcpy(&Buffer->context_info.esf, vpEsf, sizeof(Buffer->context_info.esf));
138+
139+
/*
140+
* Save floating point registers
141+
*/
142+
fppSave(&Buffer->context_info.fp);
143+
144+
CFE_PSP_Exception_WriteComplete();
150145
}
151-
else
146+
147+
if (GLOBAL_CFE_CONFIGDATA.SystemNotify != NULL)
152148
{
153-
sprintf(CFE_PSP_ExceptionReasonString, "Exception: Vector=0x%06X, vxWorks Task Name=%s, Task ID=0x%08X",
154-
vector, TaskName, task_id);
149+
/* notify the CFE of the event */
150+
GLOBAL_CFE_CONFIGDATA.SystemNotify();
155151
}
156152

157-
/*
158-
** Save Exception Stack frame
159-
*/
160-
memcpy(&(CFE_PSP_ExceptionContext.esf), pEsf, sizeof(ESFPPC));
161-
162-
/*
163-
** Save floating point registers
164-
*/
165-
fppSave(&CFE_PSP_ExceptionContext.fp);
166-
167-
/*
168-
** Call the Generic cFE routine to finish processing the exception and
169-
** restart the cFE
170-
*/
171-
CFE_PSP_ES_EXCEPTION_FUNCTION((uint32) task_id,
172-
(char *) CFE_PSP_ExceptionReasonString,
173-
(uint32 *) &CFE_PSP_ExceptionContext,
174-
sizeof(CFE_PSP_ExceptionContext_t));
175-
/*
176-
** No return to here
177-
*/
178153

179154
} /* end function */
180155

@@ -210,3 +185,29 @@ void CFE_PSP_SetDefaultExceptionEnvironment(void)
210185
_PPC_FPSCR_UE ); /* fp underflow enable */
211186
}
212187

188+
/*
189+
* Name: CFE_PSP_ExceptionGetSummary_Impl
190+
*
191+
* Purpose: Translate a stored exception log entry into a summary string
192+
*/
193+
int32 CFE_PSP_ExceptionGetSummary_Impl(const CFE_PSP_Exception_LogData_t* Buffer, char *ReasonBuf, uint32 ReasonSize)
194+
{
195+
const char *TaskName;
196+
197+
/*
198+
** Get the vxWorks task name
199+
*/
200+
TaskName = taskName(Buffer->sys_task_id);
201+
202+
if ( TaskName == NULL )
203+
{
204+
TaskName = "NULL";
205+
}
206+
207+
snprintf(ReasonBuf, ReasonSize, "Vector=0x%06X, vxWorks Task Name=%s, Task ID=0x%08X",
208+
Buffer->context_info.vector,TaskName,Buffer->sys_task_id);
209+
210+
return CFE_PSP_SUCCESS;
211+
}
212+
213+

0 commit comments

Comments
 (0)