source: rtems/cpukit/score/src/threadhandler.c @ 2d7ae960

4.115
Last change on this file since 2d7ae960 was 97bda25, checked in by Joel Sherrill <joel.sherrill@…>, on 06/11/12 at 17:26:21

threadhandler.c: Fix spelling of main() in prototype

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