source: rtems/cpukit/score/cpu/m68k/cpu.c @ 022851a

4.115
Last change on this file since 022851a was 022851a, checked in by Sebastian Huber <sebastian.huber@…>, on 01/28/14 at 11:10:08

Add thread-local storage (TLS) support

Tested and implemented on ARM, m68k, PowerPC and SPARC. Other
architectures need more work.

  • Property mode set to 100644
File size: 5.1 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.com/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/system.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/tls.h>
23
24#if defined( __mcoldfire__ ) && ( M68K_HAS_FPU == 1 )
25  uint32_t _CPU_cacr_shadow;
26#endif
27
28void _CPU_Initialize(void)
29{
30#if ( M68K_HAS_VBR == 0 )
31  /* fill the isr redirect table with the code to place the format/id
32     onto the stack */
33
34  uint32_t   slot;
35
36  for (slot = 0; slot < CPU_INTERRUPT_NUMBER_OF_VECTORS; slot++)
37  {
38    _CPU_ISR_jump_table[slot].move_a7 = M68K_MOVE_A7;
39    _CPU_ISR_jump_table[slot].format_id = slot << 2;
40    _CPU_ISR_jump_table[slot].jmp = M68K_JMP;
41    _CPU_ISR_jump_table[slot].isr_handler = (uint32_t) 0xDEADDEAD;
42  }
43#endif /* M68K_HAS_VBR */
44}
45
46uint32_t   _CPU_ISR_Get_level( void )
47{
48  uint32_t   level;
49
50  m68k_get_interrupt_level( level );
51
52  return level;
53}
54
55/*
56 *  _CPU_ISR_install_raw_handler
57 */
58
59void _CPU_ISR_install_raw_handler(
60  uint32_t    vector,
61  proc_ptr    new_handler,
62  proc_ptr   *old_handler
63)
64{
65  proc_ptr *interrupt_table = NULL;
66
67#if (M68K_HAS_FPSP_PACKAGE == 1)
68  /*
69   *  If this vector being installed is one related to FP, then the
70   *  FPSP will install the handler itself and handle it completely
71   *  with no intervention from RTEMS.
72   */
73
74  if (*_FPSP_install_raw_handler &&
75      (*_FPSP_install_raw_handler)(vector, new_handler, *old_handler))
76        return;
77#endif
78
79
80  /*
81   *  On CPU models without a VBR, it is necessary for there to be some
82   *  header code for each ISR which saves a register, loads the vector
83   *  number, and jumps to _ISR_Handler.
84   */
85
86  m68k_get_vbr( interrupt_table );
87#if ( M68K_HAS_VBR == 1 )
88  *old_handler = interrupt_table[ vector ];
89  interrupt_table[ vector ] = new_handler;
90#else
91
92  /*
93   *  Install handler into RTEMS jump table and if VBR table is in
94   *  RAM, install the pointer to the appropriate jump table slot.
95   *  If the VBR table is in ROM, it is the BSP's responsibility to
96   *  load it appropriately to vector to the RTEMS jump table.
97   */
98
99  *old_handler = (proc_ptr) _CPU_ISR_jump_table[vector].isr_handler;
100  _CPU_ISR_jump_table[vector].isr_handler = (uint32_t) new_handler;
101  if ( (uint32_t) interrupt_table != 0xFFFFFFFF )
102    interrupt_table[ vector ] = (proc_ptr) &_CPU_ISR_jump_table[vector];
103#endif /* M68K_HAS_VBR */
104}
105
106void _CPU_ISR_install_vector(
107  uint32_t    vector,
108  proc_ptr    new_handler,
109  proc_ptr   *old_handler
110)
111{
112  proc_ptr ignored = 0;  /* to avoid warning */
113
114  *old_handler = _ISR_Vector_table[ vector ];
115
116  _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
117
118  _ISR_Vector_table[ vector ] = new_handler;
119}
120
121
122/*
123 *  _CPU_Install_interrupt_stack
124 */
125
126void _CPU_Install_interrupt_stack( void )
127{
128#if ( M68K_HAS_SEPARATE_STACKS == 1 )
129  void *isp = _CPU_Interrupt_stack_high;
130
131  __asm__ volatile ( "movec %0,%%isp" : "=r" (isp) : "0" (isp) );
132#endif
133}
134
135#if ( M68K_HAS_BFFFO != 1 )
136/*
137 * Returns table for duplication of the BFFFO instruction (16 bits only)
138 */
139const unsigned char _CPU_m68k_BFFFO_table[256] = {
140    8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
141    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
142    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
143    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
144    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
145    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
146    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
147    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
148    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
151    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
154    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
155    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
156};
157#endif
158
159/*
160 *  The following code context switches the software FPU emulation
161 *  code provided with GCC.
162 */
163
164#if (CPU_SOFTWARE_FP == TRUE)
165extern Context_Control_fp _fpCCR;
166
167void _CPU_Context_save_fp (Context_Control_fp **fp_context_ptr)
168{
169  Context_Control_fp *fp;
170
171  fp = *fp_context_ptr;
172
173  *fp = _fpCCR;
174}
175
176void _CPU_Context_restore_fp (Context_Control_fp **fp_context_ptr)
177{
178  Context_Control_fp *fp;
179
180  fp = *fp_context_ptr;
181
182  _fpCCR = *fp;
183}
184#endif
185
186void _CPU_Context_Initialize(
187  Context_Control *the_context,
188  void *stack_area_begin,
189  size_t stack_area_size,
190  uint32_t new_level,
191  void (*entry_point)( void ),
192  bool is_fp,
193  void *tls_area
194)
195{
196  uint32_t stack;
197
198  the_context->sr      = 0x3000 | (new_level << 8);
199  stack                = (uint32_t)stack_area_begin + stack_area_size - 4;
200  the_context->a7_msp  = (void *)stack;
201  *(void **)stack      = (void *)entry_point;
202
203#if (defined(__mcoldfire__) && ( M68K_HAS_FPU == 1 ))
204  the_context->fpu_dis = is_fp ? 0x00 : 0x10;
205#endif
206
207  if ( tls_area != NULL ) {
208    _TLS_TCB_before_tls_block_initialize( tls_area );
209  }
210}
Note: See TracBrowser for help on using the repository browser.