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

4.104.114.84.95
Last change on this file since bc5fc7a6 was bc5fc7a6, checked in by Joel Sherrill <joel.sherrill@…>, on 10/12/01 at 17:40:22

2001-10-12 Alexandra Kossovsky <sasha@…>

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