source: rtems/c/src/lib/libbsp/arm/shared/abort/abort.c @ 89b7e69

4.104.114.84.95
Last change on this file since 89b7e69 was 4008232, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/07 at 18:03:05

2007-05-15 Ray Xu <rayx@…>

  • shared/abort/abort.c, shared/abort/simple_abort.c: New files.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  ARM CPU Dependent Source
3 *
4 *  COPYRIGHT (c) 2007 Ray Xu.
5 *  mailto: Rayx 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 *  If you want a small footprint RTEMS, pls use simple_abort.c
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/system.h>
22#include <rtems.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
46extern void printk(char *fmt, ...);
47
48uint32_t        g_data_abort_cnt = 0;
49/*this is a big overhead for MCU only got 16K RAM*/
50uint32_t        g_data_abort_insn_list[1024];
51
52
53char *_print_full_context_mode2txt[0x20]={
54   [0x0]="user",  /* User */
55        [0x1]="fiq",   /* FIQ - Fast Interrupt Request */
56        [0x2]="irq",   /* IRQ - Interrupt Request */
57        [0x3]="super", /* Supervisor */
58        [0x7]="abort", /* Abort */
59        [0xb]="undef", /* Undefined */
60        [0xf]="system" /* System */
61    };
62   
63
64void _print_full_context(uint32_t spsr)
65{
66    char *mode;
67    uint32_t prev_sp,prev_lr,cpsr,tmp;
68    int i;
69
70    printk("active thread thread 0x%08x\n", _Thread_Executing->Object.id);
71
72    mode=_print_full_context_mode2txt[spsr&0x1f];
73    if(!mode) mode="unknown";
74
75    asm volatile ("     MRS  %[cpsr], cpsr \n"
76              " ORR  %[tmp], %[spsr], #0xc0 \n"
77              " MSR  cpsr_c, %[tmp] \n"
78              " MOV  %[prev_sp], sp \n"
79              " MOV  %[prev_lr], lr \n"
80              " MSR  cpsr_c, %[cpsr] \n"
81              : [prev_sp] "=&r" (prev_sp), [prev_lr] "=&r" (prev_lr),
82                [cpsr] "=&r" (cpsr), [tmp] "=&r" (tmp)
83              : [spsr] "r" (spsr)
84              : "cc");
85
86    printk("Previous sp=0x%08x lr=0x%08x and actual cpsr=%08x\n", prev_sp, prev_lr, cpsr);
87
88    for(i=0;i<48;){
89        printk(" 0x%08x",((uint32_t*)prev_sp)[i++]);
90        if((i%6) == 0)
91            printk("\n");
92    }
93
94}
95
96
97/* This function is supposed to figure out what caused the
98 * data abort, do that, then return.
99 *
100 * All unhandled instructions cause the system to hang.
101 */
102
103void do_data_abort(uint32_t   insn, uint32_t   spsr,
104                    Context_Control *ctx)
105{
106    /* Clarify, which type is correct, CPU_Exception_frame or Context_Control */
107
108    uint8_t    decode;
109    uint8_t    insn_type;
110
111    uint32_t    tmp;
112
113    g_data_abort_insn_list[g_data_abort_cnt & 0x3ff] = ctx->register_lr - 8;
114    g_data_abort_cnt++;
115   
116    decode = ((insn >> 20) & 0xff);
117
118    insn_type = decode & INSN_MASK;
119    switch(insn_type) {
120    case INSN_STM1:
121        printk("\n\nINSN_STM1\n");
122        break;
123    case INSN_STM2:
124        printk("\n\nINSN_STM2\n");
125        break;
126    case INSN_STR:
127        printk("\n\nINSN_STR\n");
128        break;
129    case INSN_STRB:
130        printk("\n\nINSN_STRB\n");
131        break;
132    case INSN_LDM1:
133        printk("\n\nINSN_LDM1\n");
134        break;
135    case INSN_LDM23:
136        printk("\n\nINSN_LDM23\n");
137        break;
138    case INSN_LDR:
139        printk("\n\nINSN_LDR\n");
140        break;
141    case INSN_LDRB:
142        printk("\n\nINSN_LDRB\n");
143        break;
144    default:
145        printk("\n\nUnrecognized instruction\n");
146        break;
147    }
148   
149    printk("data_abort at address 0x%x, instruction: 0x%x,   spsr = 0x%x\n",
150           ctx->register_lr - 8, insn, spsr);
151
152    _print_full_context(spsr);
153
154    /* disable interrupts, wait forever */
155    _CPU_ISR_Disable(tmp);
156    while(1) {
157        continue;
158    }
159    return;
160}
161
Note: See TracBrowser for help on using the repository browser.