source: rtems/cpukit/score/cpu/sh/cpu.c @ 7111268

4.104.114.84.95
Last change on this file since 7111268 was 3239698, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/15/04 at 13:26:21

Remove stray white spaces.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 *  This file contains information pertaining to the Hitachi SH
3 *  processor.
4 *
5 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
6 *           Bernd Becker (becker@faw.uni-ulm.de)
7 *
8 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 *
15 *  COPYRIGHT (c) 1998-2001.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.com/license/LICENSE.
21 *
22 *  $Id$
23 */
24 
25#include <rtems/system.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/sh_io.h>
28#include <rtems/score/cpu.h>
29#include <rtems/score/sh.h>
30
31/* referenced in start.S */
32extern proc_ptr vectab[] ;
33
34proc_ptr vectab[256] ;
35
36extern proc_ptr _Hardware_isr_Table[];
37
38/*  _CPU_Initialize
39 *
40 *  This routine performs processor dependent initialization.
41 *
42 *  INPUT PARAMETERS:
43 *    cpu_table       - CPU table to initialize
44 *    thread_dispatch - address of disptaching routine
45 */
46
47
48void _CPU_Initialize(
49  rtems_cpu_table  *cpu_table,
50  void      (*thread_dispatch)      /* ignored on this CPU */
51)
52{
53  register uint32_t   level = 0;
54
55  /*
56   *  The thread_dispatch argument is the address of the entry point
57   *  for the routine called at the end of an ISR once it has been
58   *  decided a context switch is necessary.  On some compilation
59   *  systems it is difficult to call a high-level language routine
60   *  from assembly.  This allows us to trick these systems.
61   *
62   *  If you encounter this problem save the entry point in a CPU
63   *  dependent variable.
64   */
65
66  _CPU_Thread_dispatch_pointer = thread_dispatch;
67
68  /*
69   *  If there is not an easy way to initialize the FP context
70   *  during Context_Initialize, then it is usually easier to
71   *  save an "uninitialized" FP context here and copy it to
72   *  the task's during Context_Initialize.
73   */
74
75  /* FP context initialization support goes here */
76  /* FIXME: When not to use SH4_FPSCR_PR ? */
77#ifdef __SH4__
78  _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM | SH4_FPSCR_PR;
79#endif
80#ifdef __SH3E__
81  /* FIXME: Wild guess :) */
82  _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM;
83#endif
84
85  _CPU_Table = *cpu_table;
86
87  /* enable interrupts */
88  _CPU_ISR_Set_level( level);
89}
90
91/*PAGE
92 *
93 *  _CPU_ISR_Get_level
94 */
95 
96uint32_t   _CPU_ISR_Get_level( void )
97{
98  /*
99   *  This routine returns the current interrupt level.
100   */
101
102  register uint32_t   _mask ;
103 
104  sh_get_interrupt_level( _mask );
105 
106  return ( _mask);
107}
108
109/*PAGE
110 *
111 *  _CPU_ISR_install_raw_handler
112 */
113 
114void _CPU_ISR_install_raw_handler(
115  uint32_t    vector,
116  proc_ptr    new_handler,
117  proc_ptr   *old_handler
118)
119{
120  /*
121   *  This is where we install the interrupt handler into the "raw" interrupt
122   *  table used by the CPU to dispatch interrupt handlers.
123   */
124  volatile proc_ptr     *vbr ;
125
126#if SH_PARANOID_ISR 
127  uint32_t              level ;
128
129  sh_disable_interrupts( level );
130#endif   
131
132  /* get vbr */
133  asm ( "stc vbr,%0" : "=r" (vbr) );
134
135  *old_handler = vbr[vector] ;
136  vbr[vector]  = new_handler ;
137
138#if SH_PARANOID_ISR
139  sh_enable_interrupts( level );
140#endif
141}
142
143
144/*PAGE
145 *
146 *  _CPU_ISR_install_vector
147 *
148 *  This kernel routine installs the RTEMS handler for the
149 *  specified vector.
150 *
151 *  Input parameters:
152 *    vector      - interrupt vector number
153 *    old_handler - former ISR for this vector number
154 *    new_handler - replacement ISR for this vector number
155 *
156 *  Output parameters:  NONE
157 *
158 */
159
160#if defined(__sh1__) || defined(__sh2__)
161void _CPU_ISR_install_vector(
162  uint32_t    vector,
163  proc_ptr    new_handler,
164  proc_ptr   *old_handler
165)
166{
167   proc_ptr ignored ;
168#if 0
169   if(( vector <= 113) && ( vector >= 11))
170     {
171#endif
172       *old_handler = _ISR_Vector_table[ vector ];
173
174       /*
175        *  If the interrupt vector table is a table of pointer to isr entry
176        *  points, then we need to install the appropriate RTEMS interrupt
177        *  handler for this vector number.
178        */
179       _CPU_ISR_install_raw_handler(vector,
180                                    _Hardware_isr_Table[vector],
181                                    &ignored );
182
183       /*
184        *  We put the actual user ISR address in '_ISR_Vector_table'. 
185        *  This will be used by __ISR_Handler so the user gets control.
186        */
187
188       _ISR_Vector_table[ vector ] = new_handler;
189#if 0
190     }
191#endif
192}
193#endif /* _CPU_ISR_install_vector */
194
195/*PAGE
196 *
197 *  _CPU_Thread_Idle_body
198 *
199 *  NOTES:
200 *
201 *  1. This is the same as the regular CPU independent algorithm.
202 *
203 *  2. If you implement this using a "halt", "idle", or "shutdown"
204 *     instruction, then don't forget to put it in an infinite loop.
205 *
206 *  3. Be warned. Some processors with onboard DMA have been known
207 *     to stop the DMA if the CPU were put in IDLE mode.  This might
208 *     also be a problem with other on-chip peripherals.  So use this
209 *     hook with caution.
210 */
211
212#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
213void _CPU_Thread_Idle_body( void )
214{
215
216  for( ; ; )
217    {
218      asm volatile("nop");
219    }
220    /* insert your "halt" instruction here */ ;
221}
222#endif
223
224#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
225
226uint8_t   _bit_set_table[16] =
227  { 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1,0};
228
229
230#endif
231
232void _CPU_Context_Initialize(
233  Context_Control       *_the_context,
234  void                  *_stack_base,
235  uint32_t              _size,
236  uint32_t              _isr,
237  void  (*_entry_point)(void),
238  int                   _is_fp )
239{
240  _the_context->r15 = (uint32_t  *) ((uint32_t  ) (_stack_base) + (_size) );
241#if defined(__sh1__) || defined(__sh2__)
242  _the_context->sr  = (_isr << 4) & 0x00f0 ;
243#else
244  _the_context->sr  = SH4_SR_MD | ((_isr << 4) & 0x00f0);
245#endif
246  _the_context->pr  = (uint32_t  *) _entry_point ;
247
248
249#if 0 && SH_HAS_FPU
250   /* Disable FPU if it is non-fp task */
251  if(!_is_fp)
252    _the_context->sr |= SH4_SR_FD;
253#endif
254}
Note: See TracBrowser for help on using the repository browser.