source: rtems/c/src/lib/libcpu/powerpc/new-exceptions/bspsupport/ppc_exc_hdl.c @ 4bd4c9e

4.115
Last change on this file since 4bd4c9e was 4bd4c9e, checked in by Sebastian Huber <sebastian.huber@…>, on 11/23/12 at 08:32:52

bsps/powerpc: Add PPC_EXC_CONFIG_USE_FIXED_HANDLER

In case a BSP enables this option, then fixed high level exception
handler will be used. For normal asynchronous exceptions this is
bsp_interrupt_dispatch() and for other exceptions this is the handler
from the read-only ppc_exc_handler_table. The global handler is
C_exception_handler(). This avoids some dependencies on valid
read-write data.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/* PowerPC exception handling middleware; consult README for more
2 * information.
3 *
4 * Author: Till Straumann <strauman@slac.stanford.edu>, 2007
5 *
6 *  The license and distribution terms for this file may be
7 *  found in the file LICENSE in this distribution or at
8 *  http://www.rtems.com/license/LICENSE.
9 */
10
11#include <rtems.h>
12#include <rtems/score/apiext.h>
13
14#include <bsp/vectors.h>
15
16/* Provide temp. storage space for a few registers.
17 * This is used by the assembly code prior to setting up
18 * the stack.
19 * One set is needed for each exception type with its
20 * own SRR0/SRR1 pair since such exceptions may nest.
21 *
22 * NOTE: The assembly code needs these variables to
23 *       be in the .sdata section and accesses them
24 *       via R13.
25 */
26uint32_t ppc_exc_lock_std  = 0;
27uint32_t ppc_exc_lock_crit = 0;
28uint32_t ppc_exc_lock_mchk = 0;
29
30uint32_t ppc_exc_vector_register_std  = 0;
31uint32_t ppc_exc_vector_register_crit = 0;
32uint32_t ppc_exc_vector_register_mchk = 0;
33
34/* MSR bits to enable once critical status info is saved and the stack
35 * is switched; must be set depending on CPU type
36 *
37 * Default is set here for classic PPC CPUs with a MMU
38 * but is overridden from vectors_init.c
39 */
40uint32_t ppc_exc_msr_bits = MSR_IR | MSR_DR | MSR_RI;
41
42int ppc_exc_handler_default(BSP_Exception_frame *f, unsigned int vector)
43{
44  return -1;
45}
46
47#ifndef PPC_EXC_CONFIG_USE_FIXED_HANDLER
48
49exception_handler_t globalExceptHdl = C_exception_handler;
50
51/* Table of C-handlers */
52ppc_exc_handler_t ppc_exc_handler_table [LAST_VALID_EXC + 1] = {
53  [0 ... LAST_VALID_EXC] = ppc_exc_handler_default
54};
55
56#endif /* PPC_EXC_CONFIG_USE_FIXED_HANDLER */
57
58ppc_exc_handler_t ppc_exc_get_handler(unsigned vector)
59{
60  if (
61    vector <= LAST_VALID_EXC
62      && ppc_exc_handler_table [vector] != ppc_exc_handler_default
63  ) {
64    return ppc_exc_handler_table [vector];
65  } else {
66    return NULL;
67  }
68}
69
70rtems_status_code ppc_exc_set_handler(unsigned vector, ppc_exc_handler_t handler)
71{
72  if (vector <= LAST_VALID_EXC) {
73    if (handler == NULL) {
74      handler = ppc_exc_handler_default;
75    }
76
77    if (ppc_exc_handler_table [vector] != handler) {
78#ifndef PPC_EXC_CONFIG_USE_FIXED_HANDLER
79      ppc_exc_handler_table [vector] = handler;
80#else /* PPC_EXC_CONFIG_USE_FIXED_HANDLER */
81      return RTEMS_RESOURCE_IN_USE;
82#endif /* PPC_EXC_CONFIG_USE_FIXED_HANDLER */
83    }
84
85    return RTEMS_SUCCESSFUL;
86  } else {
87    return RTEMS_INVALID_ID;
88  }
89}
90
91void ppc_exc_wrapup(BSP_Exception_frame *frame)
92{
93  /* dispatch_disable level is decremented from assembly code.  */
94  if ( _Thread_Dispatch_necessary ) {
95    /* FIXME: I believe it should be OK to re-enable
96     *        interrupts around the execution of _Thread_Dispatch();
97     */
98    _Thread_Dispatch();
99  }
100}
Note: See TracBrowser for help on using the repository browser.