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

4.104.115
Last change on this file since f086af89 was f086af89, checked in by Joel Sherrill <joel.sherrill@…>, on 03/27/10 at 15:02:35

2010-03-27 Joel Sherrill <joel.sherrill@…>

  • context.c, cpu.c: Add include of config.h
  • Property mode set to 100644
File size: 5.0 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#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <rtems/system.h>
30#include <rtems/score/isr.h>
31#include <rtems/score/sh_io.h>
32#include <rtems/score/cpu.h>
33#include <rtems/score/sh.h>
34
35/* referenced in start.S */
36extern proc_ptr vectab[] ;
37
38proc_ptr vectab[256] ;
39
40extern proc_ptr _Hardware_isr_Table[];
41
42/*  _CPU_Initialize
43 *
44 *  This routine performs processor dependent initialization.
45 *
46 *  INPUT PARAMETERS: NONE
47 */
48
49void _CPU_Initialize(void)
50{
51  register uint32_t   level = 0;
52
53  /*
54   *  If there is not an easy way to initialize the FP context
55   *  during Context_Initialize, then it is usually easier to
56   *  save an "uninitialized" FP context here and copy it to
57   *  the task's during Context_Initialize.
58   */
59
60  /* FP context initialization support goes here */
61  /* FIXME: When not to use SH4_FPSCR_PR ? */
62#ifdef __SH4__
63  _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM | SH4_FPSCR_PR;
64#endif
65#ifdef __SH3E__
66  /* FIXME: Wild guess :) */
67  _CPU_Null_fp_context.fpscr = SH4_FPSCR_DN | SH4_FPSCR_RM;
68#endif
69
70  /* enable interrupts */
71  _CPU_ISR_Set_level( level ) ;
72}
73
74/*PAGE
75 *
76 *  _CPU_ISR_Get_level
77 */
78
79uint32_t   _CPU_ISR_Get_level( void )
80{
81  /*
82   *  This routine returns the current interrupt level.
83   */
84
85  register uint32_t   _mask ;
86
87  sh_get_interrupt_level( _mask );
88
89  return ( _mask);
90}
91
92/*PAGE
93 *
94 *  _CPU_ISR_install_raw_handler
95 */
96
97void _CPU_ISR_install_raw_handler(
98  uint32_t    vector,
99  proc_ptr    new_handler,
100  proc_ptr   *old_handler
101)
102{
103  /*
104   *  This is where we install the interrupt handler into the "raw" interrupt
105   *  table used by the CPU to dispatch interrupt handlers.
106   */
107  volatile proc_ptr     *vbr ;
108
109#if SH_PARANOID_ISR
110  uint32_t              level ;
111
112  sh_disable_interrupts( level );
113#endif
114
115  /* get vbr */
116  asm ( "stc vbr,%0" : "=r" (vbr) );
117
118  *old_handler = vbr[vector] ;
119  vbr[vector]  = new_handler ;
120
121#if SH_PARANOID_ISR
122  sh_enable_interrupts( level );
123#endif
124}
125
126
127/*PAGE
128 *
129 *  _CPU_ISR_install_vector
130 *
131 *  This kernel routine installs the RTEMS handler for the
132 *  specified vector.
133 *
134 *  Input parameters:
135 *    vector      - interrupt vector number
136 *    old_handler - former ISR for this vector number
137 *    new_handler - replacement ISR for this vector number
138 *
139 *  Output parameters:  NONE
140 *
141 */
142
143void _CPU_ISR_install_vector(
144  uint32_t    vector,
145  proc_ptr    new_handler,
146  proc_ptr   *old_handler
147)
148{
149   proc_ptr ignored ;
150   *old_handler = _ISR_Vector_table[ vector ];
151
152 /*
153  *  If the interrupt vector table is a table of pointer to isr entry
154  *  points, then we need to install the appropriate RTEMS interrupt
155  *  handler for this vector number.
156  */
157#if defined(__sh1__) || defined(__sh2__)
158  _CPU_ISR_install_raw_handler(vector, _Hardware_isr_Table[vector], &ignored );
159#endif
160
161 /*
162  *  We put the actual user ISR address in '_ISR_Vector_table'.
163  *  This will be used by __ISR_Handler so the user gets control.
164  */
165
166 _ISR_Vector_table[ vector ] = new_handler;
167}
168
169/*PAGE
170 *
171 *  _CPU_Thread_Idle_body
172 *
173 *  NOTES:
174 *
175 *  1. This is the same as the regular CPU independent algorithm.
176 *
177 *  2. If you implement this using a "halt", "idle", or "shutdown"
178 *     instruction, then don't forget to put it in an infinite loop.
179 *
180 *  3. Be warned. Some processors with onboard DMA have been known
181 *     to stop the DMA if the CPU were put in IDLE mode.  This might
182 *     also be a problem with other on-chip peripherals.  So use this
183 *     hook with caution.
184 */
185
186#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
187void *_CPU_Thread_Idle_body( uintptr_t ignored )
188{
189
190  for( ; ; )
191    {
192      asm volatile("nop");
193    }
194    /* insert your "halt" instruction here */ ;
195}
196#endif
197
198#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
199
200uint8_t   _bit_set_table[16] =
201  { 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1,0};
202
203
204#endif
205
206void _CPU_Context_Initialize(
207  Context_Control       *_the_context,
208  void                  *_stack_base,
209  uint32_t              _size,
210  uint32_t              _isr,
211  void  (*_entry_point)(void),
212  int                   _is_fp )
213{
214  _the_context->r15 = (uint32_t *) ((uint32_t) (_stack_base) + (_size) );
215#if defined(__sh1__) || defined(__sh2__) || defined(__SH2E__)
216  _the_context->sr  = (_isr << 4) & 0x00f0 ;
217#else
218  _the_context->sr  = SH4_SR_MD | ((_isr << 4) & 0x00f0);
219#endif
220  _the_context->pr  = (uint32_t *) _entry_point ;
221
222
223#if 0 && SH_HAS_FPU
224   /* Disable FPU if it is non-fp task */
225  if(!_is_fp)
226    _the_context->sr |= SH4_SR_FD;
227#endif
228}
Note: See TracBrowser for help on using the repository browser.