source: rtems/c/src/lib/libbsp/powerpc/shared/vectors/vectors_init.c @ d8ada5b

4.104.114.84.9
Last change on this file since d8ada5b was d8ada5b, checked in by Till Straumann <strauman@…>, on Dec 2, 2005 at 2:47:23 AM

2005-12-01 Till Straumann <strauman@…>

  • shared/vectors/vectors.h, shared/vectors/vectors.S, shared/vectors/vectors_init.c: Reduced size of default prologue (some exceptions, e.g., altivec unavail.) are only 0x20 bytes apart. Also introduced a modified prologue that switches r0..r3 shadowing off (r0..r3 undefined on certain 603e variants when incurring a TLB miss).
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * vectors_init.c Exception hanlding initialisation (and generic handler).
3 *
4 *  This include file describe the data structure and the functions implemented
5 *  by rtems to handle exceptions.
6 *
7 *  CopyRight (C) 1999 valette@crf.canon.fr
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15#include <rtems.h>
16#include <bsp.h>
17
18#include <rtems/bspIo.h>
19
20#include <bsp/vectors.h>
21#include <libcpu/raw_exception.h>
22#include <libcpu/spr.h>
23#include <libcpu/cpuIdent.h>
24
25static rtems_raw_except_global_settings exception_config;
26static rtems_raw_except_connect_data    exception_table[LAST_VALID_EXC + 1];
27
28extern exception_handler_t globalExceptHdl;
29exception_handler_t globalExceptHdl;
30
31/* T. Straumann: provide a stack trace
32 * <strauman@slac.stanford.edu>, 6/26/2001
33 */
34typedef struct LRFrameRec_ {
35        struct LRFrameRec_ *frameLink;
36        unsigned long *lr;
37} LRFrameRec, *LRFrame;
38
39#define STACK_CLAMP 50  /* in case we have a corrupted bottom */
40
41SPR_RO(LR)
42
43void
44BSP_printStackTrace(BSP_Exception_frame* excPtr)
45{
46LRFrame f;
47int             i;
48LRFrame sp;
49void    *lr;
50
51        printk("Stack Trace: \n  ");
52        if (excPtr) {
53                printk("IP: 0x%08x, ",excPtr->EXC_SRR0);
54                sp=(LRFrame)excPtr->GPR1;
55                lr=(void*)excPtr->EXC_LR;
56        } else {
57                /* there's no macro for this */
58                __asm__ __volatile__("mr %0, 1":"=r"(sp));
59                lr=(LRFrame)_read_LR();
60        }
61        printk("LR: 0x%08x\n",lr);
62        for (f=(LRFrame)sp, i=0; f->frameLink && i<STACK_CLAMP; f=f->frameLink) {
63                printk("--^ 0x%08x", (long)(f->frameLink->lr));
64                if (!(++i%5))
65                        printk("\n");
66        }
67        if (i>=STACK_CLAMP) {
68                printk("Too many stack frames (stack possibly corrupted), giving up...\n");
69        } else {
70                if (i%5)
71                        printk("\n");
72        }
73}
74
75void C_exception_handler(BSP_Exception_frame* excPtr)
76{
77  int recoverable = 0;
78
79  printk("exception handler called for exception %d\n", excPtr->_EXC_number);
80  printk("\t Next PC or Address of fault = %x\n", excPtr->EXC_SRR0);
81  printk("\t Saved MSR = %x\n", excPtr->EXC_SRR1);
82  printk("\t R0 = %x\n", excPtr->GPR0);
83  printk("\t R1 = %x\n", excPtr->GPR1);
84  printk("\t R2 = %x\n", excPtr->GPR2);
85  printk("\t R3 = %x\n", excPtr->GPR3);
86  printk("\t R4 = %x\n", excPtr->GPR4);
87  printk("\t R5 = %x\n", excPtr->GPR5);
88  printk("\t R6 = %x\n", excPtr->GPR6);
89  printk("\t R7 = %x\n", excPtr->GPR7);
90  printk("\t R8 = %x\n", excPtr->GPR8);
91  printk("\t R9 = %x\n", excPtr->GPR9);
92  printk("\t R10 = %x\n", excPtr->GPR10);
93  printk("\t R11 = %x\n", excPtr->GPR11);
94  printk("\t R12 = %x\n", excPtr->GPR12);
95  printk("\t R13 = %x\n", excPtr->GPR13);
96  printk("\t R14 = %x\n", excPtr->GPR14);
97  printk("\t R15 = %x\n", excPtr->GPR15);
98  printk("\t R16 = %x\n", excPtr->GPR16);
99  printk("\t R17 = %x\n", excPtr->GPR17);
100  printk("\t R18 = %x\n", excPtr->GPR18);
101  printk("\t R19 = %x\n", excPtr->GPR19);
102  printk("\t R20 = %x\n", excPtr->GPR20);
103  printk("\t R21 = %x\n", excPtr->GPR21);
104  printk("\t R22 = %x\n", excPtr->GPR22);
105  printk("\t R23 = %x\n", excPtr->GPR23);
106  printk("\t R24 = %x\n", excPtr->GPR24);
107  printk("\t R25 = %x\n", excPtr->GPR25);
108  printk("\t R26 = %x\n", excPtr->GPR26);
109  printk("\t R27 = %x\n", excPtr->GPR27);
110  printk("\t R28 = %x\n", excPtr->GPR28);
111  printk("\t R29 = %x\n", excPtr->GPR29);
112  printk("\t R30 = %x\n", excPtr->GPR30);
113  printk("\t R31 = %x\n", excPtr->GPR31);
114  printk("\t CR = %x\n", excPtr->EXC_CR);
115  printk("\t CTR = %x\n", excPtr->EXC_CTR);
116  printk("\t XER = %x\n", excPtr->EXC_XER);
117  printk("\t LR = %x\n", excPtr->EXC_LR);
118  printk("\t DAR = %x\n", excPtr->EXC_DAR);
119
120  BSP_printStackTrace(excPtr);
121
122  if (excPtr->_EXC_number == ASM_DEC_VECTOR)
123       recoverable = 1;
124  if (excPtr->_EXC_number == ASM_SYS_VECTOR)
125#ifdef TEST_RAW_EXCEPTION_CODE
126    recoverable = 1;
127#else
128    recoverable = 0;
129#endif
130    if (!recoverable) {
131      printk("unrecoverable exception!!! Push reset button\n");
132      while(1);
133    }
134}
135
136void nop_except_enable(const rtems_raw_except_connect_data* ptr)
137{
138}
139int except_always_enabled(const rtems_raw_except_connect_data* ptr)
140{
141  return 1;
142}
143
144int mpc60x_vector_is_valid(rtems_vector vector);
145
146void initialize_exceptions()
147{
148  int i;
149  int has_shadowed_gprs = 0;
150
151  /*
152   * Initialize pointer used by low level execption handling
153   */
154  globalExceptHdl                               = C_exception_handler;
155  /*
156   * Put  default_exception_vector_code_prolog at relevant exception
157   * code entry addresses
158   */
159  exception_config.exceptSize                   = LAST_VALID_EXC + 1;
160  exception_config.rawExceptHdlTbl              = &exception_table[0];
161  exception_config.defaultRawEntry.exceptIndex  = 0;
162  exception_config.defaultRawEntry.hdl.vector   = 0;
163  exception_config.defaultRawEntry.hdl.raw_hdl  = default_exception_vector_code_prolog;
164  /*
165   * Note that next line the '&' before default_exception_vector_code_prolog_size
166   * is not a bug as it is defined a .set directly in asm...
167   */
168  exception_config.defaultRawEntry.hdl.raw_hdl_size = (unsigned) default_exception_vector_code_prolog_size;
169
170  switch ( get_ppc_cpu_type() ) {
171    case PPC_603e:
172    case PPC_8240:
173      has_shadowed_gprs = 1; 
174    default: break;
175  }
176  for (i=0; i <= exception_config.exceptSize; i++) {
177    if (!mpc60x_vector_is_valid (i)) {
178      continue;
179    }
180    exception_table[i].exceptIndex      = i;
181    if ( has_shadowed_gprs
182         && (   ASM_IMISS_VECTOR  == i
183             || ASM_DLMISS_VECTOR == i
184             || ASM_DSMISS_VECTOR == i ) ) {
185      exception_table[i].hdl.raw_hdl      = tgpr_clr_exception_vector_code_prolog;
186      exception_table[i].hdl.raw_hdl_size = (unsigned)tgpr_clr_exception_vector_code_prolog_size;
187    } else {
188      exception_table[i].hdl              = exception_config.defaultRawEntry.hdl;
189    }
190    exception_table[i].hdl.vector       = i;
191    exception_table[i].on               = nop_except_enable;
192    exception_table[i].off              = nop_except_enable;
193    exception_table[i].isOn             = except_always_enabled;
194  }
195  if (!mpc60x_init_exceptions(&exception_config)) {
196    BSP_panic("Exception handling initialization failed\n");
197  }
198#ifdef RTEMS_DEBUG
199  else {
200    printk("Exception handling initialization done\n");
201  }
202#endif
203}
Note: See TracBrowser for help on using the repository browser.