source: rtems/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c @ 61b1c413

4.115
Last change on this file since 61b1c413 was 61b1c413, checked in by Joel Sherrill <joel.sherrill@…>, on 06/29/10 at 00:39:41

2010-06-28 Joel Sherrill <joel.sherrill@…>

PR 1573/cpukit

  • sh7032/score/cpu_asm.c, sh7045/score/cpu_asm.c, sh7750/score/cpu_asm.c, shgdb/score/cpu_asm.c: Add a per cpu data structure which contains the information required by RTEMS for each CPU core. This encapsulates information such as thread executing, heir, idle and dispatch needed.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  This file contains the basic algorithms for all assembly code used
3 *  in an specific CPU port of RTEMS.  These algorithms must be implemented
4 *  in assembly language
5 *
6 *  NOTE:  This port uses a C file with inline assembler instructions
7 *
8 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
9 *           Bernd Becker (becker@faw.uni-ulm.de)
10 *
11 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 *
18 *  COPYRIGHT (c) 1998.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 *
27 */
28
29/*
30 *  This is supposed to be an assembly file.  This means that system.h
31 *  and cpu.h should not be included in a "real" cpu_asm file.  An
32 *  implementation in assembly should include "cpu_asm.h"
33 */
34
35#include <rtems/system.h>
36#include <rtems/score/cpu.h>
37#include <rtems/score/isr.h>
38#include <rtems/score/thread.h>
39#include <rtems/score/sh.h>
40
41#include <rtems/score/ispsh7032.h>
42#include <rtems/score/iosh7032.h>
43#include <rtems/score/sh_io.h>
44
45/* from cpu_isps.c */
46extern proc_ptr         _Hardware_isr_Table[];
47
48#if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
49  unsigned long    *_old_stack_ptr;
50#endif
51
52register unsigned long  *stack_ptr asm("r15");
53
54/*
55 * sh_set_irq_priority
56 *
57 * this function sets the interrupt level of the specified interrupt
58 *
59 * parameters:
60 *             - irq : interrupt number
61 *             - prio: priority to set for this interrupt number
62 *
63 * returns:    0 if ok
64 *             -1 on error
65 */
66
67unsigned int sh_set_irq_priority(
68  unsigned int irq,
69  unsigned int prio )
70{
71  uint32_t         shiftcount;
72  uint32_t         prioreg;
73  uint16_t         temp16;
74  ISR_Level        level;
75
76  /*
77   * first check for valid interrupt
78   */
79  if (( irq > 113) || (_Hardware_isr_Table[irq] == _dummy_isp))
80    return -1;
81  /*
82   * check for valid irq priority
83   */
84  if ( prio > 15 )
85    return -1;
86
87  /*
88   * look up appropriate interrupt priority register
89   */
90  if ( irq > 71)
91    {
92      irq = irq - 72;
93      shiftcount = 12 - ((irq & ~0x03) % 16);
94
95      switch( irq / 16)
96        {
97        case 0: { prioreg = INTC_IPRC; break;}
98        case 1: { prioreg = INTC_IPRD; break;}
99        case 2: { prioreg = INTC_IPRE; break;}
100        default: return -1;
101        }
102    }
103  else
104    {
105      shiftcount = 12 - 4 * ( irq % 4);
106      if ( irq > 67)
107        prioreg = INTC_IPRB;
108      else
109        prioreg = INTC_IPRA;
110    }
111
112  /*
113   * Set the interrupt priority register
114   */
115  _ISR_Disable( level );
116
117    temp16 = read16( prioreg);
118    temp16 &= ~( 15 << shiftcount);
119    temp16 |= prio << shiftcount;
120    write16( temp16, prioreg);
121
122  _ISR_Enable( level );
123
124  return 0;
125}
126
127/*
128 *  This routine provides the RTEMS interrupt management.
129 */
130
131void __ISR_Handler( uint32_t   vector)
132{
133  ISR_Level level;
134
135  _ISR_Disable( level );
136
137  _Thread_Dispatch_disable_level++;
138
139#if (CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
140  if ( _ISR_Nest_level == 0 )
141    {
142      /* Install irq stack */
143      _old_stack_ptr = stack_ptr;
144      stack_ptr = _CPU_Interrupt_stack_high;
145    }
146
147#endif
148
149  _ISR_Nest_level++;
150
151  _ISR_Enable( level );
152
153  /* call isp */
154  if ( _ISR_Vector_table[ vector])
155    (*_ISR_Vector_table[ vector ])( vector );
156
157  _ISR_Disable( level );
158
159  _Thread_Dispatch_disable_level--;
160
161  _ISR_Nest_level--;
162
163#if(CPU_HAS_SOFTWARE_INTERRUPT_STACK == TRUE)
164
165  if ( _ISR_Nest_level == 0 )
166    /* restore old stack pointer */
167    stack_ptr = _old_stack_ptr;
168#endif
169
170  _ISR_Enable( level );
171
172  if ( _ISR_Nest_level )
173    return;
174
175  if ( _Thread_Dispatch_disable_level ) {
176    return;
177  }
178
179  if ( _Context_Switch_necessary ) {
180    _Thread_Dispatch();
181  }
182}
Note: See TracBrowser for help on using the repository browser.