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 08/15/11 at 08:23:49

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
RevLine 
[05df0a8]1/*
2 *  Thread Handler
3 *
4 *
[d4dc7c8]5 *  COPYRIGHT (c) 1989-2011.
[05df0a8]6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
[dcf3687]9 *  found in the file LICENSE in this distribution or at
[dd687d97]10 *  http://www.rtems.com/license/LICENSE.
[05df0a8]11 *
12 *  $Id$
13 */
14
[a8eed23]15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
[05df0a8]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
[bd59b348]33#if defined(__AVR__)
34  #undef __USE_INIT_FINI__
[42fce5d3]35#endif
36
[f73fc29]37#if defined(__USE_INIT_FINI__)
[d104778]38  #if defined(__M32R__)
39    #define INIT_NAME __init
[1f3585d1]40  #elif defined(__ARM_EABI__)
41    #define INIT_NAME __libc_init_array
[d104778]42  #else
43    #define INIT_NAME _init
44  #endif
45
46  extern void INIT_NAME(void);
[46a67b19]47  #define EXECUTE_GLOBAL_CONSTRUCTORS
[f73fc29]48#endif
[46a67b19]49
[f73fc29]50#if defined(__USE__MAIN__)
51  extern void _main(void);
[46a67b19]52  #define INIT_NAME __main
53  #define EXECUTE_GLOBAL_CONSTRUCTORS
[f73fc29]54#endif
55
[d4dc7c8]56#if defined(RTEMS_SMP)
57  #include <rtems/score/smp.h>
58#endif
59
60
[64adc13]61/*
[05df0a8]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
[a0ed4ed]75 *  routine needs to set the initial isr level.  This may or may not
[05df0a8]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.
[a0ed4ed]79 *
[05df0a8]80 *  Input parameters:   NONE
81 *
82 *  Output parameters:  NONE
83 */
84
85void _Thread_Handler( void )
86{
87  ISR_Level  level;
88  Thread_Control *executing;
[46a67b19]89  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
90    static char doneConstructors;
91    char doneCons;
92  #endif
[05279b84]93
[05df0a8]94  executing = _Thread_Executing;
[05279b84]95
[48816d7]96  /*
[28352fae]97   * Some CPUs need to tinker with the call frame or registers when the
[48816d7]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
[05df0a8]103  /*
104   * have to put level into a register for those cpu's that use
105   * inline asm here
106   */
[05279b84]107
[05df0a8]108  level = executing->Start.isr_level;
109  _ISR_Set_level(level);
110
[46a67b19]111  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
112    doneCons = doneConstructors;
113    doneConstructors = 1;
114  #endif
[5b87515d]115
[46a67b19]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
[48f89683]126
[05df0a8]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 );
[05279b84]133
[05df0a8]134  /*
135   *  At this point, the dispatch disable level BETTER be 1.
136   */
137  _Thread_Enable_dispatch();
[94ab166]138
[46a67b19]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 ();
[d4dc7c8]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
[46a67b19]154    }
[d4dc7c8]155 #endif
[46a67b19]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
[05df0a8]161      );
[46a67b19]162  }
[442eac69]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
[46a67b19]171  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
172    else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
[a0ed4ed]173      executing->Wait.return_argument =
174         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
[260b0c2]175           executing->Start.pointer_argument,
176           executing->Start.numeric_argument
177         );
[46a67b19]178    }
179    else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
[a0ed4ed]180      executing->Wait.return_argument =
[46a67b19]181       (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
182         executing->Start.numeric_argument,
183         executing->Start.pointer_argument
184       );
185    }
186  #endif
[05df0a8]187
[260b0c2]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
[a0ed4ed]191   *  anything (which is not supporting in all APIs), then it would be
[260b0c2]192   *  able to fit in a (void *).
193   */
194
[05df0a8]195  _User_extensions_Thread_exitted( executing );
196
197  _Internal_error_Occurred(
198    INTERNAL_ERROR_CORE,
[aae7f1a1]199    true,
[05df0a8]200    INTERNAL_ERROR_THREAD_EXITTED
201  );
202}
Note: See TracBrowser for help on using the repository browser.