source: rtems/cpukit/score/src/threadhandler.c @ 1f3585d1

4.115
Last change on this file since 1f3585d1 was 1f3585d1, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 15, 2011 at 8:23:49 AM

2011-08-15 Sebastian Huber <sebastian.huber@…>

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