source: rtems/cpukit/score/src/threadhandler.c @ 742c140

4.115
Last change on this file since 742c140 was 742c140, checked in by Ralf Corsepius <ralf.corsepius@…>, on 10/07/11 at 11:06:21

2011-10-07 Ralf Corsépius <ralf.corsepius@…>

  • score/src/threadhandler.c: Don't undefine USE_INIT_FINI for the avr.
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2011.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/wkspace.h>
32#if defined(RTEMS_SMP)
33  #include <rtems/score/smp.h>
34#endif
35
36/*
37 *  Conditional magic to determine what style of C++ constructor
38 *  initialization this target and compiler version uses.
39 */
40#if defined(__USE_INIT_FINI__)
41  #if defined(__M32R__)
42    #define INIT_NAME __init
43  #elif defined(__ARM_EABI__)
44    #define INIT_NAME __libc_init_array
45  #else
46    #define INIT_NAME _init
47  #endif
48
49  extern void INIT_NAME(void);
50  #define EXECUTE_GLOBAL_CONSTRUCTORS
51#endif
52
53#if defined(__USE__MAIN__)
54  extern void _main(void);
55  #define INIT_NAME __main
56  #define EXECUTE_GLOBAL_CONSTRUCTORS
57#endif
58
59/*
60 *  _Thread_Handler
61 *
62 *  This routine is the "primal" entry point for all threads.
63 *  _Context_Initialize() dummies up the thread's initial context
64 *  to cause the first Context_Switch() to jump to _Thread_Handler().
65 *
66 *  This routine is the default thread exitted error handler.  It is
67 *  returned to when a thread exits.  The configured fatal error handler
68 *  is invoked to process the exit.
69 *
70 *  NOTE:
71 *
72 *  On entry, it is assumed all interrupts are blocked and that this
73 *  routine needs to set the initial isr level.  This may or may not
74 *  actually be needed by the context switch routine and as a result
75 *  interrupts may already be at there proper level.  Either way,
76 *  setting the initial isr level properly here is safe.
77 *
78 *  Input parameters:   NONE
79 *
80 *  Output parameters:  NONE
81 */
82void _Thread_Handler( void )
83{
84  ISR_Level  level;
85  Thread_Control *executing;
86  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
87    static bool doneConstructors;
88    bool doCons;
89  #endif
90
91  executing = _Thread_Executing;
92
93  /*
94   * Some CPUs need to tinker with the call frame or registers when the
95   * thread actually begins to execute for the first time.  This is a
96   * hook point where the port gets a shot at doing whatever it requires.
97   */
98  _Context_Initialization_at_thread_begin();
99
100  /*
101   * have to put level into a register for those cpu's that use
102   * inline asm here
103   */
104  level = executing->Start.isr_level;
105  _ISR_Set_level(level);
106
107  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
108    #if defined(RTEMS_MULTIPROCESSING)
109      doCons = !doneConstructors
110        && _Objects_Get_API( executing->Object.id ) != OBJECTS_INTERNAL_API;
111      if (doCons)
112        doneConstructors = true;
113    #else
114      doCons = !doneConstructors;
115      doneConstructors = true;
116    #endif
117  #endif
118
119  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
120    #if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
121      if ( (executing->fp_context != NULL) &&
122            !_Thread_Is_allocated_fp( executing ) ) {
123        if ( _Thread_Allocated_fp != NULL )
124          _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
125        _Thread_Allocated_fp = executing;
126      }
127    #endif
128  #endif
129
130  /*
131   * Take care that 'begin' extensions get to complete before
132   * 'switch' extensions can run.  This means must keep dispatch
133   * disabled until all 'begin' extensions complete.
134   */
135  _User_extensions_Thread_begin( executing );
136
137  /*
138   *  At this point, the dispatch disable level BETTER be 1.
139   */
140  _Thread_Enable_dispatch();
141
142  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
143    /*
144     *  _init could be a weak symbol and we SHOULD test it but it isn't
145     *  in any configuration I know of and it generates a warning on every
146     *  RTEMS target configuration.  --joel (12 May 2007)
147     */
148    if (doCons) /* && (volatile void *)_init) */ {
149      INIT_NAME ();
150   
151      #if defined(RTEMS_SMP)
152        _Thread_Disable_dispatch();
153          _SMP_Request_other_cores_to_perform_first_context_switch();
154        _Thread_Enable_dispatch();
155      #endif
156    }
157 #endif
158
159  if ( executing->Start.prototype == THREAD_START_NUMERIC ) {
160    executing->Wait.return_argument =
161      (*(Thread_Entry_numeric) executing->Start.entry_point)(
162        executing->Start.numeric_argument
163      );
164  }
165  #if defined(RTEMS_POSIX_API)
166    else if ( executing->Start.prototype == THREAD_START_POINTER ) {
167      executing->Wait.return_argument =
168        (*(Thread_Entry_pointer) executing->Start.entry_point)(
169          executing->Start.pointer_argument
170        );
171    }
172  #endif
173  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
174    else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
175      executing->Wait.return_argument =
176         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
177           executing->Start.pointer_argument,
178           executing->Start.numeric_argument
179         );
180    }
181    else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
182      executing->Wait.return_argument =
183       (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
184         executing->Start.numeric_argument,
185         executing->Start.pointer_argument
186       );
187    }
188  #endif
189
190  /*
191   *  In the switch above, the return code from the user thread body
192   *  was placed in return_argument.  This assumed that if it returned
193   *  anything (which is not supporting in all APIs), then it would be
194   *  able to fit in a (void *).
195   */
196
197  _User_extensions_Thread_exitted( executing );
198
199  _Internal_error_Occurred(
200    INTERNAL_ERROR_CORE,
201    true,
202    INTERNAL_ERROR_THREAD_EXITTED
203  );
204}
Note: See TracBrowser for help on using the repository browser.