source: rtems/c/src/lib/libbsp/arm/shared/abort/simple_abort.c @ 2ee9d3d

4.115
Last change on this file since 2ee9d3d was 2ee9d3d, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/11/11 at 11:49:52

2011-02-11 Ralf Corsépius <ralf.corsepius@…>

  • shared/abort/abort.c, shared/abort/simple_abort.c: Use "asm" instead of "asm" for improved c99-compliance.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  ARM CPU Dependent Source
3 *
4 *  COPYRIGHT (c) 2007 Ray Xu.
5 *  mailto: Rayx.cn at gmail dot com
6 *
7 *  COPYRIGHT (c) 2000 Canon Research Centre France SA.
8 *  Emmanuel Raguet, mailto:raguet@crf.canon.fr
9 *
10 *  Copyright (c) 2002 Advent Networks, Inc
11 *      Jay Monkman <jmonkman@adventnetworks.com>
12 *
13 *  This is a simple implement of abort
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.com/license/LICENSE.
18 *
19 */
20
21#include <rtems.h>
22#include <rtems/bspIo.h>
23
24#define INSN_MASK         0xc5
25
26#define INSN_STM1         0x80
27#define INSN_STM2         0x84
28#define INSN_STR          0x40
29#define INSN_STRB         0x44
30
31#define INSN_LDM1         0x81
32#define INSN_LDM23        0x85
33#define INSN_LDR          0x41
34#define INSN_LDRB         0x45
35
36#define GET_RD(x)         ((x & 0x0000f000) >> 12)
37#define GET_RN(x)         ((x & 0x000f0000) >> 16)
38
39#define GET_U(x)              ((x & 0x00800000) >> 23)
40#define GET_I(x)              ((x & 0x02000000) >> 25)
41
42#define GET_REG(r, ctx)      (((uint32_t   *)ctx)[r])
43#define SET_REG(r, ctx, v)   (((uint32_t   *)ctx)[r] = v)
44#define GET_OFFSET(insn)     (insn & 0xfff)
45
46char *_print_full_context_mode2txt[0x10]={
47  [0x0]="user",  /* User */
48  [0x1]="fiq",   /* FIQ - Fast Interrupt Request */
49  [0x2]="irq",   /* IRQ - Interrupt Request */
50  [0x3]="super", /* Supervisor */
51  [0x7]="abort", /* Abort */
52  [0xb]="undef", /* Undefined */
53  [0xf]="system" /* System */
54};
55
56void _print_full_context(uint32_t spsr)
57{
58  char *mode;
59  uint32_t prev_sp,prev_lr,cpsr,arm_switch_reg;
60  int i, j;
61
62  printk("active thread thread 0x%08x\n", _Thread_Executing->Object.id);
63
64  mode=_print_full_context_mode2txt[(spsr&0x1f)-0x10];
65  if(!mode) mode="unknown";
66
67  __asm__ volatile (
68    ARM_SWITCH_TO_ARM
69    "mrs %[cpsr], cpsr\n"
70    "orr %[arm_switch_reg], %[spsr], #0xc0\n"
71    "msr cpsr_c, %[arm_switch_reg]\n"
72    "mov %[prev_sp], sp\n"
73    "mov %[prev_lr], lr\n"
74    "msr cpsr_c, %[cpsr]\n"
75    ARM_SWITCH_BACK
76    : [prev_sp] "=&r" (prev_sp), [prev_lr] "=&r" (prev_lr),
77      [cpsr] "=&r" (cpsr), [arm_switch_reg] "=&r" (arm_switch_reg)
78    : [spsr] "r" (spsr)
79    : "cc"
80  );
81
82  printk(
83    "Previous sp=0x%08x lr=0x%08x and actual cpsr=%08x\n",
84     prev_sp,
85     prev_lr,
86     cpsr
87  );
88
89  j=0;
90  for(i=0;i<48;) {
91      printk(" 0x%08x",((uint32_t*)prev_sp)[i++]);
92      j++;
93      /*try not to use % because it introduces hundreds of byte overhead*/
94      if((j-6)==0) {
95          printk("\n");
96        j=0;
97      }
98  }
99}
100
101
102/* This function is supposed to figure out what caused the
103 * data abort, do that, then return.
104 *
105 * All unhandled instructions cause the system to hang.
106 */
107
108void do_data_abort(
109  uint32_t         insn,
110  uint32_t         spsr,
111  Context_Control *ctx
112)
113{
114  /* Clarify, which type is correct, CPU_Exception_frame or Context_Control */
115
116  uint8_t               decode;
117  uint8_t               insn_type;
118  rtems_interrupt_level level;
119
120  decode = ((insn >> 20) & 0xff);
121
122  insn_type = decode & INSN_MASK;
123  switch(insn_type) {
124  case INSN_STM1:
125    printk("\n\nINSN_STM1\n");
126    break;
127  case INSN_STM2:
128    printk("\n\nINSN_STM2\n");
129    break;
130  case INSN_STR:
131    printk("\n\nINSN_STR\n");
132    break;
133  case INSN_STRB:
134    printk("\n\nINSN_STRB\n");
135    break;
136  case INSN_LDM1:
137    printk("\n\nINSN_LDM1\n");
138    break;
139  case INSN_LDM23:
140    printk("\n\nINSN_LDM23\n");
141    break;
142  case INSN_LDR:
143    printk("\n\nINSN_LDR\n");
144    break;
145  case INSN_LDRB:
146    printk("\n\nINSN_LDRB\n");
147    break;
148  default:
149    printk("\n\nUnrecognized instruction\n");
150    break;
151  }
152
153  printk("data_abort at address 0x%x, instruction: 0x%x,   spsr = 0x%x\n",
154         ctx->register_lr - 8, insn, spsr);
155
156  _print_full_context(spsr);
157
158  /* disable interrupts, wait forever */
159  rtems_interrupt_disable(level);
160  while(1) {
161    continue;
162  }
163  return;
164}
165
Note: See TracBrowser for help on using the repository browser.