source: rtems/bsps/sh/gensh2/start/cpu_asm.c @ 511dc4b

5
Last change on this file since 511dc4b was 511dc4b, checked in by Sebastian Huber <sebastian.huber@…>, on 06/19/18 at 07:09:51

Rework initialization and interrupt stack support

Statically initialize the interrupt stack area
(_Configuration_Interrupt_stack_area_begin,
_Configuration_Interrupt_stack_area_end, and
_Configuration_Interrupt_stack_size) via <rtems/confdefs.h>. Place the
interrupt stack area in a special section ".rtemsstack.interrupt". Let
BSPs define the optimal placement of this section in their linker
command files (e.g. in a fast on-chip memory).

This change makes makes the CPU_HAS_SOFTWARE_INTERRUPT_STACK and
CPU_HAS_HARDWARE_INTERRUPT_STACK CPU port defines superfluous, since the
low level initialization code has all information available via global
symbols.

This change makes the CPU_ALLOCATE_INTERRUPT_STACK CPU port define
superfluous, since the interrupt stacks are allocated by confdefs.h for
all architectures. There is no need for BSP-specific linker command
file magic (except the section placement), see previous ARM linker
command file as a bad example.

Remove _CPU_Install_interrupt_stack(). Initialize the hardware
interrupt stack in _CPU_Initialize() if necessary (e.g.
m68k_install_interrupt_stack()).

The optional _CPU_Interrupt_stack_setup() is still useful to customize
the registration of the interrupt stack area in the per-CPU information.

The initialization stack can reuse the interrupt stack, since

  • interrupts are disabled during the sequential system initialization, and
  • the boot_card() function does not return.

This stack resuse saves memory.

Changes per architecture:

arm:

  • Mostly replace the linker symbol based configuration of stacks with the standard <rtems/confdefs.h> configuration via CONFIGURE_INTERRUPT_STACK_SIZE. The size of the FIQ, ABT and UND mode stack is still defined via linker symbols. These modes are rarely used in applications and the default values provided by the BSP should be sufficient in most cases.
  • Remove the bsp_processor_count linker symbol hack used for the SMP support. This is possible since the interrupt stack area is now allocated by the linker and not allocated from the heap. This makes some configure.ac stuff obsolete. Remove the now superfluous BSP variants altcycv_devkit_smp and realview_pbx_a9_qemu_smp.

bfin:

  • Remove unused magic linker command file allocation of initialization stack. Maybe a previous linker command file copy and paste problem? In the start.S the initialization stack is set to a hard coded value.

lm32, m32c, mips, nios2, riscv, sh, v850:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

m68k:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.

powerpc:

  • Remove magic linker command file allocation of initialization stack. Reuse interrupt stack for initialization stack.
  • Used dedicated memory region (REGION_RTEMSSTACK) for the interrupt stack on BSPs using the shared linkcmds.base (replacement for REGION_RWEXTRA).

sparc:

  • Remove the hard coded initialization stack. Use the interrupt stack for the initialization stack on the boot processor. This saves 16KiB of RAM.

Update #3459.

  • 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.org/license/LICENSE.
24 */
25
26/*
27 *  This is supposed to be an assembly file.  This means that system.h
28 *  and cpu.h should not be included in a "real" cpu_asm file.  An
29 *  implementation in assembly should include "cpu_asm.h"
30 */
31
32#include <rtems/system.h>
33#include <rtems/score/cpu.h>
34#include <rtems/score/isr.h>
35#include <rtems/score/threaddispatch.h>
36#include <rtems/score/sh.h>
37
38#include <rtems/score/ispsh7045.h>
39#include <rtems/score/iosh7045.h>
40#include <rtems/score/sh_io.h>
41
42/* from cpu_isps.c */
43extern proc_ptr         _Hardware_isr_Table[];
44
45unsigned long *_old_stack_ptr;
46
47register unsigned long  *stack_ptr __asm__ ("r15");
48
49/*
50 * sh_set_irq_priority
51 *
52 * this function sets the interrupt level of the specified interrupt
53 *
54 * parameters:
55 *             - irq : interrupt number
56 *             - prio: priority to set for this interrupt number
57 *
58 * returns:    0 if ok
59 *             -1 on error
60 */
61
62unsigned int sh_set_irq_priority(
63  unsigned int irq,
64  unsigned int prio )
65{
66  uint32_t   shiftcount;
67  uint32_t   prioreg;
68  uint16_t   temp16;
69  ISR_Level  level;
70
71  /*
72   * first check for valid interrupt
73   */
74  if (( irq > 156) || (irq < 64) || (_Hardware_isr_Table[irq] == _dummy_isp))
75    return -1;
76  /*
77   * check for valid irq priority
78   */
79  if ( prio > 15 )
80    return -1;
81
82  /*
83   * look up appropriate interrupt priority register
84   */
85  if ( irq > 71)
86    {
87      irq = irq - 72;
88      shiftcount = 12 - ((irq & ~0x03) % 16);
89
90      switch( irq / 16)
91        {
92        case 0: { prioreg = INTC_IPRC; break;}
93        case 1: { prioreg = INTC_IPRD; break;}
94        case 2: { prioreg = INTC_IPRE; break;}
95        case 3: { prioreg = INTC_IPRF; break;}
96        case 4: { prioreg = INTC_IPRG; break;}
97        case 5: { prioreg = INTC_IPRH; break;}
98        default: return -1;
99        }
100    }
101  else
102    {
103      shiftcount = 12 - 4 * ( irq % 4);
104      if ( irq > 67)
105        prioreg = INTC_IPRB;
106      else
107        prioreg = INTC_IPRA;
108    }
109
110  /*
111   * Set the interrupt priority register
112   */
113  _ISR_Local_disable( level );
114
115    temp16 = read16( prioreg);
116    temp16 &= ~( 15 << shiftcount);
117    temp16 |= prio << shiftcount;
118    write16( temp16, prioreg);
119
120  _ISR_Local_enable( level );
121
122  return 0;
123}
124
125/*
126 *  This routine provides the RTEMS interrupt management.
127 */
128
129void __ISR_Handler( uint32_t   vector)
130{
131  ISR_Level level;
132
133  _ISR_Local_disable( level );
134
135  _Thread_Dispatch_disable();
136
137  if ( _ISR_Nest_level == 0 )
138    {
139      /* Install irq stack */
140      _old_stack_ptr = stack_ptr;
141      stack_ptr = _CPU_Interrupt_stack_high;
142    }
143
144  _ISR_Nest_level++;
145
146  _ISR_Local_enable( level );
147
148  /* call isp */
149  if ( _ISR_Vector_table[ vector])
150    (*_ISR_Vector_table[ vector ])( vector );
151
152  _ISR_Local_disable( level );
153
154  _Thread_Dispatch_unnest( _Per_CPU_Get() );
155
156  _ISR_Nest_level--;
157
158  if ( _ISR_Nest_level == 0 )
159    /* restore old stack pointer */
160    stack_ptr = _old_stack_ptr;
161
162  _ISR_Local_enable( level );
163
164  if ( _ISR_Nest_level )
165    return;
166
167  if ( !_Thread_Dispatch_is_enabled() ) {
168    return;
169  }
170
171  if ( _Thread_Dispatch_necessary ) {
172    _Thread_Dispatch();
173  }
174}
Note: See TracBrowser for help on using the repository browser.