source: rtems/cpukit/score/cpu/m68k/cpu.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: 6.0 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Motorola MC68xxx Dependent Source
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-1999.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/score/isr.h>
21#include <rtems/score/percpu.h>
22#include <rtems/score/tls.h>
23#include <rtems/config.h>
24
25#if ( M68K_HAS_VBR == 0 )
26
27/*
28 * Table of ISR handler entries that resides in RAM. The FORMAT/ID is
29 * pushed onto the stack. This is not is the same order as VBR processors.
30 * The ISR handler takes the format and uses it for dispatching the user
31 * handler.
32 */
33
34typedef struct {
35  uint16_t   move_a7;            /* move #FORMAT_ID,%a7@- */
36  uint16_t   format_id;
37  uint16_t   jmp;                /* jmp  _ISR_Handlers */
38  uint32_t   isr_handler;
39} _CPU_ISR_handler_entry;
40
41#define M68K_MOVE_A7 0x3F3C
42#define M68K_JMP     0x4EF9
43
44/* points to jsr-exception-table in targets wo/ VBR register */
45static _CPU_ISR_handler_entry
46_CPU_ISR_jump_table[ CPU_INTERRUPT_NUMBER_OF_VECTORS ];
47
48#endif /* M68K_HAS_VBR */
49
50#if (M68K_HAS_FPSP_PACKAGE == 1)
51int (*_FPSP_install_raw_handler)(
52  uint32_t   vector,
53  proc_ptr new_handler,
54  proc_ptr *old_handler
55);
56#endif
57
58#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
59  uint32_t _CPU_cacr_shadow;
60#endif
61
62static void m68k_install_interrupt_stack( void )
63{
64#if ( M68K_HAS_SEPARATE_STACKS == 1 )
65  uintptr_t isp = (uintptr_t) _Configuration_Interrupt_stack_area_end;
66
67  __asm__ volatile ( "movec %0,%%isp" : "=r" (isp) : "0" (isp) );
68#endif
69}
70
71void _CPU_Initialize(void)
72{
73#if ( M68K_HAS_VBR == 0 )
74  /* fill the isr redirect table with the code to place the format/id
75     onto the stack */
76
77  uint32_t   slot;
78
79  for (slot = 0; slot < CPU_INTERRUPT_NUMBER_OF_VECTORS; slot++)
80  {
81    _CPU_ISR_jump_table[slot].move_a7 = M68K_MOVE_A7;
82    _CPU_ISR_jump_table[slot].format_id = slot << 2;
83    _CPU_ISR_jump_table[slot].jmp = M68K_JMP;
84    _CPU_ISR_jump_table[slot].isr_handler = (uint32_t) 0xDEADDEAD;
85  }
86#endif /* M68K_HAS_VBR */
87
88  m68k_install_interrupt_stack();
89}
90
91uint32_t   _CPU_ISR_Get_level( void )
92{
93  uint32_t   level;
94
95  m68k_get_interrupt_level( level );
96
97  return level;
98}
99
100/*
101 *  _CPU_ISR_install_raw_handler
102 */
103
104void _CPU_ISR_install_raw_handler(
105  uint32_t    vector,
106  proc_ptr    new_handler,
107  proc_ptr   *old_handler
108)
109{
110  proc_ptr *interrupt_table = NULL;
111
112#if (M68K_HAS_FPSP_PACKAGE == 1)
113  /*
114   *  If this vector being installed is one related to FP, then the
115   *  FPSP will install the handler itself and handle it completely
116   *  with no intervention from RTEMS.
117   */
118
119  if (*_FPSP_install_raw_handler &&
120      (*_FPSP_install_raw_handler)(vector, new_handler, *old_handler))
121        return;
122#endif
123
124
125  /*
126   *  On CPU models without a VBR, it is necessary for there to be some
127   *  header code for each ISR which saves a register, loads the vector
128   *  number, and jumps to _ISR_Handler.
129   */
130
131  m68k_get_vbr( interrupt_table );
132#if ( M68K_HAS_VBR == 1 )
133  *old_handler = interrupt_table[ vector ];
134  interrupt_table[ vector ] = new_handler;
135#else
136
137  /*
138   *  Install handler into RTEMS jump table and if VBR table is in
139   *  RAM, install the pointer to the appropriate jump table slot.
140   *  If the VBR table is in ROM, it is the BSP's responsibility to
141   *  load it appropriately to vector to the RTEMS jump table.
142   */
143
144  *old_handler = (proc_ptr) _CPU_ISR_jump_table[vector].isr_handler;
145  _CPU_ISR_jump_table[vector].isr_handler = (uint32_t) new_handler;
146  if ( (uint32_t) interrupt_table != 0xFFFFFFFF )
147    interrupt_table[ vector ] = (proc_ptr) &_CPU_ISR_jump_table[vector];
148#endif /* M68K_HAS_VBR */
149}
150
151void _CPU_ISR_install_vector(
152  uint32_t    vector,
153  proc_ptr    new_handler,
154  proc_ptr   *old_handler
155)
156{
157  proc_ptr ignored = 0;  /* to avoid warning */
158
159  *old_handler = _ISR_Vector_table[ vector ];
160
161  _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
162
163  _ISR_Vector_table[ vector ] = new_handler;
164}
165
166#if ( M68K_HAS_BFFFO != 1 )
167/*
168 * Returns table for duplication of the BFFFO instruction (16 bits only)
169 */
170const unsigned char _CPU_m68k_BFFFO_table[256] = {
171    8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
172    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
173    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
174    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
175    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
176    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
177    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
178    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
179    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
183    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
184    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
185    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
186    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
187};
188#endif
189
190/*
191 *  The following code context switches the software FPU emulation
192 *  code provided with GCC.
193 */
194
195#if (CPU_SOFTWARE_FP == TRUE)
196extern Context_Control_fp _fpCCR;
197
198void _CPU_Context_save_fp (Context_Control_fp **fp_context_ptr)
199{
200  Context_Control_fp *fp;
201
202  fp = *fp_context_ptr;
203
204  *fp = _fpCCR;
205}
206
207void _CPU_Context_restore_fp (Context_Control_fp **fp_context_ptr)
208{
209  Context_Control_fp *fp;
210
211  fp = *fp_context_ptr;
212
213  _fpCCR = *fp;
214}
215#endif
216
217void _CPU_Context_Initialize(
218  Context_Control *the_context,
219  void *stack_area_begin,
220  size_t stack_area_size,
221  uint32_t new_level,
222  void (*entry_point)( void ),
223  bool is_fp,
224  void *tls_area
225)
226{
227  uint32_t stack;
228
229  the_context->sr      = 0x3000 | (new_level << 8);
230  stack                = (uint32_t)stack_area_begin + stack_area_size - 4;
231  the_context->a7_msp  = (void *)stack;
232  *(void **)stack      = (void *)entry_point;
233
234#if (defined(__mcoldfire__) && ( M68K_HAS_FPU == 1 ))
235  the_context->fpu_dis = is_fp ? 0x00 : 0x10;
236#endif
237
238  if ( tls_area != NULL ) {
239    _TLS_TCB_before_TLS_block_initialize( tls_area );
240  }
241}
Note: See TracBrowser for help on using the repository browser.