Skip to content

Commit

Permalink
Fix #158, Exception handling in PSP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Apr 29, 2020
1 parent 09b62df commit 21b017b
Show file tree
Hide file tree
Showing 25 changed files with 1,591 additions and 723 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ add_definitions(-D_CFE_PSP_)
include_directories(fsw/shared)

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

# Build the "common" parts as a library
add_library(psp-${CFE_SYSTEM_PSPNAME} STATIC
fsw/shared/cfe_psp_configdata.c
fsw/shared/cfe_psp_eeprom.c
fsw/shared/cfe_psp_exceptionstorage.c
fsw/shared/cfe_psp_memrange.c
fsw/shared/cfe_psp_memutils.c
fsw/shared/cfe_psp_module.c
Expand Down
17 changes: 6 additions & 11 deletions fsw/inc/cfe_psp.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define CFE_PSP_ERROR_NOT_IMPLEMENTED (-27)
#define CFE_PSP_INVALID_MODULE_NAME (-28)
#define CFE_PSP_INVALID_MODULE_ID (-29)
#define CFE_PSP_NO_EXCEPTION_DATA (-30)



Expand Down Expand Up @@ -196,7 +197,7 @@ extern uint32 CFE_PSP_GetRestartType(uint32 *restartSubType );
*/


extern void CFE_PSP_FlushCaches(uint32 type, cpuaddr address, uint32 size);
extern void CFE_PSP_FlushCaches(uint32 type, void* address, uint32 size);
/*
** This is a BSP specific cache flush routine
*/
Expand Down Expand Up @@ -247,16 +248,6 @@ extern uint32 CFE_PSP_Get_Dec(void);
** CFE_PSP_Get_Dec
*/


extern int32 CFE_PSP_InitProcessorReservedMemory(uint32 RestartType );
/*
** CFE_PSP_InitProcessorReservedMemory initializes all of the memory in the
** BSP that is preserved on a processor reset. The memory includes the
** Critical Data Store, the ES Reset Area, the Volatile Disk Memory, and
** the User Reserved Memory. In general, the memory areas will be initialized
** ( cleared ) on a Power On reset, and preserved during a processor reset.
*/

extern int32 CFE_PSP_GetCDSSize(uint32 *SizeOfCDS);
/*
** CFE_PSP_GetCDSSize fetches the size of the OS Critical Data Store area.
Expand Down Expand Up @@ -368,6 +359,10 @@ extern void CFE_PSP_SetDefaultExceptionEnvironment(void);
*/


extern uint32 CFE_PSP_Exception_GetCount(void);
extern int32 CFE_PSP_Exception_GetSummary(uint32 *ContextLogId, uint32 *TaskId, char *ReasonBuf, uint32 ReasonSize);
extern int32 CFE_PSP_Exception_CopyContext(uint32 ContextLogId, void *ContextBuf, uint32 ContextSize);

/*
** I/O Port API
*/
Expand Down
8 changes: 1 addition & 7 deletions fsw/inc/cfe_psp_configdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,12 @@ typedef const struct
uint32 PSP_WatchdogMin; /**< PSP Minimum watchdog in milliseconds */
uint32 PSP_WatchdogMax; /**< PSP Maximum watchdog in milliseconds */
uint32 PSP_MemTableSize; /**< Size of PSP memory table */
uint32 PSP_ExceptionLogSize; /**< Size of PSP exception log */
CFE_PSP_MemTable_t *PSP_MemoryTable; /**< Pointer to PSP memory table (forward reference) */

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

/**
* Processor Context type.
* This is needed to determine the size of the context entry in the ER log.
* It is a placeholder as the implementation to use it is not merged in yet.
*/
uint32 OS_CpuContextSize;

/**
* Number of EEPROM banks on this platform
*/
Expand Down
58 changes: 47 additions & 11 deletions fsw/mcp750-vxworks/inc/cfe_psp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,47 @@
*/
#define CFE_PSP_MEM_TABLE_SIZE 10

/**
* This define sets the maximum number of exceptions
* that can be stored.
*
* It must always be a power of two.
*/
#define CFE_PSP_MAX_EXCEPTION_ENTRIES 4

/*
** Processor Context type.
** This is needed to determine the size of the context entry in the ER log.
** Although this file is in a CPU directory, it really is OS dependant, so supporting
** multiple OSs on the same CPU architecture ( i.e. x86/linux, x86/windows, x86/osx )
** will require IFDEFS.
** Typedef for the layout of the vxWorks boot record structure
**
** This is statically placed at the beginning of system memory (sysMemTop)
** which should be reserved in the kernel.
*/
typedef struct
typedef struct
{
ESFPPC esf; /* Exception stack frame */
FP_CONTEXT fp; /* floating point registers */

} CFE_PSP_ExceptionContext_t;
uint32 bsp_reset_type;
uint32 spare1;
uint32 spare2;
uint32 spare3;

} CFE_PSP_ReservedMemoryBootRecord_t;

#define CFE_PSP_CPU_CONTEXT_SIZE (sizeof(CFE_PSP_ExceptionContext_t))

/**
* \brief The data type used by the underlying OS to represent a thread ID.
*/
typedef TASK_ID CFE_PSP_Exception_SysTaskId_t;

/*
** Global variables
*/
typedef struct
{
UINT32 timebase_upper; /* Upper 32 bits of timebase as sampled by hook */
UINT32 timebase_lower; /* Lower 32 bits of timebase as sampled by hook */
int vector; /* vector number */
ESFPPC esf; /* Exception stack frame */
FP_CONTEXT fp; /* floating point registers */

} CFE_PSP_Exception_ContextDataEntry_t;

/*
** Watchdog minimum and maximum values ( in milliseconds )
Expand All @@ -71,6 +97,16 @@ typedef struct
*/
#define CFE_PSP_NUM_EEPROM_BANKS 1

/*
* The alignment to use for each reserved memory block.
*
* This is a mask to be applied to each block base address
*
* Chosen as the cache line size of the MPC750 processor (32 bytes)
* such that the blocks will be cached more efficiently.
*/
#define CFE_PSP_MEMALIGN_MASK ((cpuaddr)0x1F)


#endif

117 changes: 59 additions & 58 deletions fsw/mcp750-vxworks/src/cfe_psp_exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,11 @@

#include "cfe_psp.h"
#include "cfe_psp_config.h"
#include "cfe_psp_exceptionstorage.h"
#include "cfe_psp_memory.h"

#include <target_config.h>

/*
** Types and prototypes for this module
*/

/* use the exception ISR binding from the global config data */
#define CFE_PSP_ES_EXCEPTION_FUNCTION (*GLOBAL_CONFIGDATA.CfeConfig->SystemExceptionISR)

/*
** BSP Specific defines
*/


/*
** External Declarations
*/

/*
** Global variables
*/

CFE_PSP_ExceptionContext_t CFE_PSP_ExceptionContext;
char CFE_PSP_ExceptionReasonString[256];

/*
**
** LOCAL FUNCTION PROTOTYPES
Expand Down Expand Up @@ -110,7 +88,8 @@ void CFE_PSP_ExceptionHook ( TASK_ID task_id, int vector, void* vpEsf );
void CFE_PSP_AttachExceptions(void)
{
excHookAdd( CFE_PSP_ExceptionHook );
OS_printf("CFE_PSP: Attached cFE Exception Handler. Context Size = %d bytes.\n",CFE_PSP_CPU_CONTEXT_SIZE);
OS_printf("CFE_PSP: Attached cFE Exception Handler. Context Size = %u bytes.\n",sizeof(CFE_PSP_Exception_ContextDataEntry_t));
CFE_PSP_Exception_Reset();
}


Expand All @@ -135,46 +114,42 @@ void CFE_PSP_AttachExceptions(void)
*/
void CFE_PSP_ExceptionHook (TASK_ID task_id, int vector, void* vpEsf )
{
ESFPPC *pEsf = vpEsf;
char *TaskName;
CFE_PSP_Exception_LogData_t* Buffer;

/*
** Get the vxWorks task name
*/
TaskName = taskName(task_id);

if ( TaskName == NULL )
Buffer = CFE_PSP_Exception_GetNextContextBuffer();
if (Buffer != NULL)
{
sprintf(CFE_PSP_ExceptionReasonString, "Exception: Vector=0x%06X, vxWorks Task Name=NULL, Task ID=0x%08X",
vector,task_id);
/*
* 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);

CFE_PSP_Exception_WriteComplete();
}
else

if (GLOBAL_CFE_CONFIGDATA.SystemNotify != NULL)
{
sprintf(CFE_PSP_ExceptionReasonString, "Exception: Vector=0x%06X, vxWorks Task Name=%s, Task ID=0x%08X",
vector, TaskName, task_id);
/* notify the CFE of the event */
GLOBAL_CFE_CONFIGDATA.SystemNotify();
}

/*
** Save Exception Stack frame
*/
memcpy(&(CFE_PSP_ExceptionContext.esf), pEsf, sizeof(ESFPPC));

/*
** Save floating point registers
*/
fppSave(&CFE_PSP_ExceptionContext.fp);

/*
** Call the Generic cFE routine to finish processing the exception and
** restart the cFE
*/
CFE_PSP_ES_EXCEPTION_FUNCTION((uint32) task_id,
(char *) CFE_PSP_ExceptionReasonString,
(uint32 *) &CFE_PSP_ExceptionContext,
sizeof(CFE_PSP_ExceptionContext_t));
/*
** No return to here
*/

} /* end function */

Expand Down Expand Up @@ -210,3 +185,29 @@ void CFE_PSP_SetDefaultExceptionEnvironment(void)
_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;
}


Loading

0 comments on commit 21b017b

Please sign in to comment.