source: rtems/cpukit/score/cpu/arm/cpu.c @ 804e3bd0

4.104.114.84.95
Last change on this file since 804e3bd0 was 91e07d0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/07 at 17:59:47

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

  • cpu.c: move do_data_abort() to libbsp/arm/shared/abort/ implement a compact do_data_abort() in simple_abort.c
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 *  ARM CPU Dependent Source
3 *
4 *
5 *  COPYRIGHT (c) 2000 Canon Research Centre France SA.
6 *  Emmanuel Raguet, mailto:raguet@crf.canon.fr
7 *
8 *  Copyright (c) 2002 Advent Networks, Inc
9 *      Jay Monkman <jmonkman@adventnetworks.com>
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 */
16
17#include <rtems/system.h>
18#include <rtems.h>
19#include <rtems/bspIo.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/wkspace.h>
22#include <rtems/score/thread.h>
23#include <rtems/score/cpu.h>
24
25/*  _CPU_Initialize
26 *
27 *  This routine performs processor dependent initialization.
28 *
29 *  INPUT PARAMETERS:
30 *    cpu_table       - CPU table to initialize
31 *    thread_dispatch - address of ISR disptaching routine (unused)
32 *   
33 */
34
35void _CPU_Initialize(
36  rtems_cpu_table  *cpu_table,
37  void      (*thread_dispatch)      /* ignored on this CPU */
38)
39{
40    _CPU_Table = *cpu_table;
41}
42
43/*
44 *
45 *  _CPU_ISR_Get_level - returns the current interrupt level
46 */
47 
48uint32_t   _CPU_ISR_Get_level( void )
49{
50    uint32_t   reg = 0; /* to avoid warning */
51   
52    asm volatile ("mrs  %0, cpsr \n"           \
53                  "and  %0,  %0, #0xc0 \n"     \
54                  : "=r" (reg)                 \
55                  : "0" (reg) );
56   
57    return reg;
58}
59
60/*
61 *  _CPU_ISR_install_vector
62 *
63 *  This kernel routine installs the RTEMS handler for the
64 *  specified vector.
65 *
66 *  Input parameters:
67 *    vector      - interrupt vector number
68 *    new_handler - replacement ISR for this vector number
69 *    old_handler - pointer to store former ISR for this vector number
70 *
71 *  FIXME: This vector scheme should be changed to allow FIQ to be
72 *         handled better. I'd like to be able to put VectorTable
73 *         elsewhere - JTM
74 *
75 *
76 *  Output parameters:  NONE
77 *
78 */
79void _CPU_ISR_install_vector(
80  uint32_t    vector,
81  proc_ptr    new_handler,
82  proc_ptr   *old_handler
83)
84{
85    /* pointer on the redirection table in RAM */
86    long *VectorTable = (long *)(MAX_EXCEPTIONS * 4);
87   
88    if (old_handler != NULL) {
89        old_handler = *(proc_ptr *)(VectorTable + vector);
90    }
91
92    *(VectorTable + vector) = (long)new_handler ;
93 
94}
95
96void _CPU_Context_Initialize(
97  Context_Control  *the_context,
98  uint32_t         *stack_base,
99  uint32_t          size,
100  uint32_t          new_level,
101  void             *entry_point,
102  boolean           is_fp
103)
104{
105    the_context->register_sp = (uint32_t  )stack_base + size ;
106    the_context->register_lr = (uint32_t  )entry_point;
107    the_context->register_cpsr = new_level | 0x13;
108}
109
110
111/*
112 *  _CPU_Install_interrupt_stack - this function is empty since the
113 *  BSP must set up the interrupt stacks.
114 */
115
116void _CPU_Install_interrupt_stack( void )
117{
118}
119
120void _defaultExcHandler (CPU_Exception_frame *ctx)
121{
122    printk("\n\r");
123    printk("----------------------------------------------------------\n\r");
124#if 1
125    printk("Exception 0x%x caught at PC 0x%x by thread %d\n",
126           ctx->register_ip, ctx->register_lr - 4,
127           _Thread_Executing->Object.id);
128#endif
129    printk("----------------------------------------------------------\n\r");
130    printk("Processor execution context at time of the fault was  :\n\r");
131    printk("----------------------------------------------------------\n\r");
132#if 0
133    printk(" r0  = %8x  r1  = %8x  r2  = %8x  r3  = %8x\n\r",
134           ctx->register_r0, ctx->register_r1,
135           ctx->register_r2, ctx->register_r3);
136    printk(" r4  = %8x  r5  = %8x  r6  = %8x  r7  = %8x\n\r",
137           ctx->register_r4, ctx->register_r5,
138           ctx->register_r6, ctx->register_r7);
139    printk(" r8  = %8x  r9  = %8x  r10 = %8x\n\r",
140           ctx->register_r8, ctx->register_r9, ctx->register_r10);
141    printk(" fp  = %8x  ip  = %8x  sp  = %8x  pc  = %8x\n\r",
142           ctx->register_fp, ctx->register_ip,
143           ctx->register_sp, ctx->register_lr - 4);
144    printk("----------------------------------------------------------\n\r");
145#endif   
146    if (_ISR_Nest_level > 0) {
147        /*
148         * In this case we shall not delete the task interrupted as
149         * it has nothing to do with the fault. We cannot return either
150         * because the eip points to the faulty instruction so...
151         */
152        printk("Exception while executing ISR!!!. System locked\n\r");
153        while(1);
154    }
155    else {
156        printk("*********** FAULTY THREAD WILL BE DELETED **************\n\r");
157        rtems_task_delete(_Thread_Executing->Object.id);
158    }
159}
160
161cpuExcHandlerType _currentExcHandler = _defaultExcHandler;
162
163extern void _Exception_Handler_Undef_Swi();
164extern void _Exception_Handler_Abort();
165extern void _exc_data_abort();
166/* FIXME: put comments here */
167void rtems_exception_init_mngt()
168{
169        ISR_Level level;
170     
171      _CPU_ISR_Disable(level);
172      _CPU_ISR_install_vector(ARM_EXCEPTION_UNDEF,
173                              _Exception_Handler_Undef_Swi,
174                              NULL);
175 
176      _CPU_ISR_install_vector(ARM_EXCEPTION_SWI,
177                              _Exception_Handler_Undef_Swi,
178                              NULL);
179     
180      _CPU_ISR_install_vector(ARM_EXCEPTION_PREF_ABORT,
181                              _Exception_Handler_Abort,
182                              NULL);
183     
184      _CPU_ISR_install_vector(ARM_EXCEPTION_DATA_ABORT,
185                              _exc_data_abort,
186                              NULL);
187     
188      _CPU_ISR_install_vector(ARM_EXCEPTION_FIQ,       
189                              _Exception_Handler_Abort,
190                              NULL);
191     
192      _CPU_ISR_install_vector(ARM_EXCEPTION_IRQ,
193                              _Exception_Handler_Abort,
194                              NULL);
195     
196      _CPU_ISR_Enable(level);
197}
198 
199#define INSN_MASK         0xc5
200
201#define INSN_STM1         0x80
202#define INSN_STM2         0x84
203#define INSN_STR          0x40
204#define INSN_STRB         0x44
205
206#define INSN_LDM1         0x81
207#define INSN_LDM23        0x85
208#define INSN_LDR          0x41
209#define INSN_LDRB         0x45
210
211#define GET_RD(x)         ((x & 0x0000f000) >> 12)
212#define GET_RN(x)         ((x & 0x000f0000) >> 16)
213
214#define GET_U(x)              ((x & 0x00800000) >> 23)
215#define GET_I(x)              ((x & 0x02000000) >> 25)
216
217#define GET_REG(r, ctx)      (((uint32_t   *)ctx)[r])
218#define SET_REG(r, ctx, v)   (((uint32_t   *)ctx)[r] = v)
219#define GET_OFFSET(insn)     (insn & 0xfff)
220
Note: See TracBrowser for help on using the repository browser.