source: rtems/cpukit/score/src/threadhandler.c @ dcf3687

4.11
Last change on this file since dcf3687 was dcf3687, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 28, 2011 at 8:24:54 PM

2011-01-28 Joel Sherrill <joel.sherrilL@…>

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