Exception handling

Exception handlers can be installed to deal with various system-level exceptions, such as alignment errors, resets, timers and so forth. Exception handling is a configurable feature of eCos and is enabled by default.

The range of values for the exception_number parameter in the functions below is hardware-dependent, as are the individual exceptions.

The exception handler is a function of the following type:


typedef void cyg_exception_handler_t(
    cyg_addrword_t    data,
    cyg_code_t        exception_number,
    cyg_addrword_t    info
);

cyg_exception_handler_t is the type used for functions which are called as a result of an exception. It is used in the function cyg_exception_set_handler().

void cyg_exception_set_handler(cyg_code_t exception_number, cyg_exception_handler_t *new_handler, cyg_addrword_t new_data, cyg_exception_handler_t **old_handler, void **old_data);

Replace current exception handler. This may apply to either the thread, or to a global exception handler, according to how exception handling was configured (global or per-thread). The exception may be ignored, or used to specify a particular handler.

void cyg_exception_call_handler(cyg_handle_t thread, cyg_code_t exception_number, cyg_addrword_t exception_info);

Invoke exception handler.

MN10300 exception vectors

Here are the exception vectors for the MN10300 architecture. Notice that the MN10300 architecture does not really have exceptions, so CYG_EXCEPTION_MIN is 0 and CYG_EXCEPTION_MAX is 1. The lone exception vector has been placed there for possible future high-level exceptions.

Example 5-1. MN10300 exception vectors


// The level-specific hardware vectors
#define CYG_VECTOR_0                    0
#define CYG_VECTOR_1                    1
#define CYG_VECTOR_2                    2
#define CYG_VECTOR_3                    3
#define CYG_VECTOR_4                    4
#define CYG_VECTOR_5                    5
#define CYG_VECTOR_6                    6
#define CYG_VECTOR_NMI                  7

#define CYG_VSR_MIN                     0
#define CYG_VSR_MAX                     7

#define CYG_EXCEPTION_MIN               0
#define CYG_EXCEPTION_MAX               1  

TX39 exception vectors

Here are the exception vectors for the TX39 architecture.

Example 5-2. TX39 exception vectors


// These are the exception codes presented in the
// Cause register and correspond to VSRs.

#define CYG_VECTOR_INTERRUPT            0
#define CYG_VECTOR_TLB_MOD              1
#define CYG_VECTOR_TLB_LOAD_REFILL      2
#define CYG_VECTOR_TLB_STORE_REFILL     3
#define CYG_VECTOR_LOAD_ADDRESS         4
#define CYG_VECTOR_STORE_ADDRESS        5
#define CYG_VECTOR_IBE                  6
#define CYG_VECTOR_DBE                  7
#define CYG_VECTOR_SYSTEM_CALL          8
#define CYG_VECTOR_BREAKPOINT           9
#define CYG_VECTOR_RESERVED_INSTRUCTION 10
#define CYG_VECTOR_COPROCESSOR          11
#define CYG_VECTOR_OVERFLOW             12
#define CYG_VECTOR_RESERVED_13          13

#define CYG_VSR_MIN                     0
#define CYG_VSR_MAX                     13

#define CYG_EXCEPTION_MIN                1
#define CYG_EXCEPTION_MAX               13 

PowerPC exception vectors

Here are the exception vectors for the PowerPC architecture.


// PowerPC generic vectors
#define CYG_VECTOR_RESERVED_0           0
#define CYG_VECTOR_RESET                1
#define CYG_VECTOR_MACHINE_CHECK        2
#define CYG_VECTOR_DSI                  3
#define CYG_VECTOR_ISI                  4
#define CYG_VECTOR_INTERRUPT            5
#define CYG_VECTOR_ALIGNMENT            6
#define CYG_VECTOR_PROGRAM              7
#define CYG_VECTOR_FP_UNAVAILABLE       8
#define CYG_VECTOR_DECREMENTER          9
#define CYG_VECTOR_RESERVED_A           10
#define CYG_VECTOR_RESERVED_B           11
#define CYG_VECTOR_SYSTEM_CALL          12
#define CYG_VECTOR_TRACE                13
#define CYG_VECTOR_FP_ASSIST            14

// MPC860 specific vectors
#define CYG_VECTOR_RESERVED_F           15
#define CYG_VECTOR_SW_EMUL              16
#define CYG_VECTOR_ITLB_MISS            17
#define CYG_VECTOR_DTLB_MISS            18
#define CYG_VECTOR_ITLB_ERROR           19
#define CYG_VECTOR_DTLB_ERROR           20
#define CYG_VECTOR_RESERVED_15          21
#define CYG_VECTOR_RESERVED_16          22
#define CYG_VECTOR_RESERVED_17          23
#define CYG_VECTOR_RESERVED_18          24
#define CYG_VECTOR_RESERVED_19          25
#define CYG_VECTOR_RESERVED_1A          26
#define CYG_VECTOR_RESERVED_1B          27
#define CYG_VECTOR_DATA_BP              28
#define CYG_VECTOR_INSTRUCTION_BP       29
#define CYG_VECTOR_PERIPHERAL_BP        30
#define CYG_VECTOR_NMI                  31

#define CYG_EXCEPTION_MIN                0
#define CYG_EXCEPTION_MAX               31
#define CYG_EXCEPTION_COUNT             32