source: rtems/bsps/powerpc/ss555/start/raw_exception.c @ 511dc4b

5
Last change on this file since 511dc4b was 09dd82a, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 13, 2018 at 3:43:25 PM

bsp/ss555: Move libcpu content to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * raw_exception.c  - This file contains implementation of C functions to
3 *                    Instantiate mpc5xx primary exception entries.
4 *                    More detailled information can be found on the Motorola
5 *                    site and more precisely in the following book:
6 *
7 *                   MPC555/MPC556 User's Manual
8 *                   Motorola REF : MPC555UM/D Rev. 3, 2000 October 15
9 *
10 *
11 * MPC5xx port sponsored by Defence Research and Development Canada - Suffield
12 * Copyright (C) 2004, Real-Time Systems Inc. (querbach@realtime.bc.ca)
13 *
14 * Derived from libcpu/powerpc/mpc8xx/exceptions/raw_exception.c:
15 *
16 * Copyright (C) 1999  Eric Valette (valette@crf.canon.fr)
17 *                     Canon Centre Recherche France.
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.org/license/LICENSE.
22 *
23 */
24
25#include <rtems.h>
26#include <rtems/score/powerpc.h>
27#include <libcpu/raw_exception.h>
28#include <libcpu/cpuIdent.h>
29#include <rtems/bspIo.h>        /* for printk */
30#include <string.h>
31
32static rtems_raw_except_connect_data*           raw_except_table;
33static rtems_raw_except_connect_data            default_raw_except_entry;
34static rtems_raw_except_global_settings*        local_settings;
35
36int mpc5xx_vector_is_valid(rtems_vector vector)
37{
38  switch (current_ppc_cpu) {
39    case PPC_5XX:
40      switch(vector) {
41        case ASM_RESET_VECTOR:
42        case ASM_MACH_VECTOR:
43
44        case ASM_EXT_VECTOR:
45        case ASM_ALIGN_VECTOR:
46        case ASM_PROG_VECTOR:
47        case ASM_FLOAT_VECTOR:
48        case ASM_DEC_VECTOR:
49
50        case ASM_SYS_VECTOR:
51        case ASM_TRACE_VECTOR:
52        case ASM_FLOATASSIST_VECTOR:
53
54        case ASM_SOFTEMUL_VECTOR:
55
56        case ASM_IPROT_VECTOR:
57        case ASM_DPROT_VECTOR:
58
59        case ASM_DBREAK_VECTOR:
60        case ASM_IBREAK_VECTOR:
61        case ASM_MEBREAK_VECTOR:
62        case ASM_NMEBREAK_VECTOR:
63          return 1;
64        default:
65          return 0;
66      }
67    default:
68      printk("Please complete libcpu/powerpc/mpc5xx/exceptions/raw_exception.c\n");
69      printk("current_ppc_cpu = %x\n", current_ppc_cpu);
70      return 0;
71  }
72}
73
74int mpc5xx_set_exception  (const rtems_raw_except_connect_data* except)
75{
76  rtems_interrupt_level level;
77
78  if (!mpc5xx_vector_is_valid(except->exceptIndex)) {
79    return 0;
80  }
81  /*
82   * Check if default handler is actually connected. If not issue an error.
83   * You must first get the current handler via mpc5xx_get_current_exception
84   * and then disconnect it using mpc5xx_delete_exception.
85   * RATIONALE : to always have the same transition by forcing the user
86   * to get the previous handler before accepting to disconnect.
87   */
88  if (exception_handler_table[except->exceptIndex] !=
89      default_raw_except_entry.hdl.raw_hdl) {
90    return 0;
91  }
92
93  rtems_interrupt_disable(level);
94
95  raw_except_table[except->exceptIndex] = *except;
96
97  exception_handler_table[except->exceptIndex] = except->hdl.raw_hdl;
98  if (except->on)
99        except->on(except);
100
101  rtems_interrupt_enable(level);
102  return 1;
103}
104
105int mpc5xx_get_current_exception (rtems_raw_except_connect_data* except)
106{
107  if (!mpc5xx_vector_is_valid(except->exceptIndex)){
108    return 0;
109  }
110
111  *except = raw_except_table[except->exceptIndex];
112
113  return 1;
114}
115
116int mpc5xx_delete_exception (const rtems_raw_except_connect_data* except)
117{
118  rtems_interrupt_level level;
119
120  if (!mpc5xx_vector_is_valid(except->exceptIndex)){
121    return 0;
122  }
123  /*
124   * Check if handler passed is actually connected. If not issue an error.
125   * You must first get the current handler via mpc5xx_get_current_exception
126   * and then disconnect it using mpc5xx_delete_exception.
127   * RATIONALE : to always have the same transition by forcing the user
128   * to get the previous handler before accepting to disconnect.
129   */
130  if (exception_handler_table[except->exceptIndex] != except->hdl.raw_hdl) {
131    return 0;
132  }
133
134  rtems_interrupt_disable(level);
135
136  if (except->off)
137        except->off(except);
138  exception_handler_table[except->exceptIndex] =
139    default_raw_except_entry.hdl.raw_hdl;
140
141  raw_except_table[except->exceptIndex] = default_raw_except_entry;
142  raw_except_table[except->exceptIndex].exceptIndex = except->exceptIndex;
143
144  rtems_interrupt_enable(level);
145
146  return 1;
147}
148
149/*
150 * Exception global init.
151 *
152 * Install exception handler pointers from the raw exception table into the
153 * exception handler table.
154 */
155int mpc5xx_init_exceptions (rtems_raw_except_global_settings* config)
156{
157  unsigned              i;
158  rtems_interrupt_level level;
159
160  /*
161   * store various accelerators
162   */
163  raw_except_table              = config->rawExceptHdlTbl;
164  local_settings                = config;
165  default_raw_except_entry      = config->defaultRawEntry;
166
167  rtems_interrupt_disable(level);
168
169  for (i = 0; i < NUM_EXCEPTIONS; i++) {
170    exception_handler_table[i] = raw_except_table[i].hdl.raw_hdl;
171
172    if (raw_except_table[i].hdl.raw_hdl != default_raw_except_entry.hdl.raw_hdl) {
173      if (raw_except_table[i].on)
174        raw_except_table[i].on(&raw_except_table[i]);
175    }
176    else {
177      if (raw_except_table[i].off)
178        raw_except_table[i].off(&raw_except_table[i]);
179    }
180  }
181  rtems_interrupt_enable(level);
182
183  return 1;
184}
185
186int mpc5xx_get_exception_config (rtems_raw_except_global_settings** config)
187{
188  *config = local_settings;
189  return 1;
190}
Note: See TracBrowser for help on using the repository browser.