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

4.115
Last change on this file since dcf3687 was dcf3687, checked in by Joel Sherrill <joel.sherrill@…>, on 01/28/11 at 20:24:54

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
RevLine 
[05df0a8]1/*
2 *  Thread Handler
3 *
4 *
[46a67b19]5 *  COPYRIGHT (c) 1989-2009.
[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
40  #else
41    #define INIT_NAME _init
42  #endif
43
44  extern void INIT_NAME(void);
[46a67b19]45  #define EXECUTE_GLOBAL_CONSTRUCTORS
[f73fc29]46#endif
[46a67b19]47
[f73fc29]48#if defined(__USE__MAIN__)
49  extern void _main(void);
[46a67b19]50  #define INIT_NAME __main
51  #define EXECUTE_GLOBAL_CONSTRUCTORS
[f73fc29]52#endif
53
[05df0a8]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
[a0ed4ed]69 *  routine needs to set the initial isr level.  This may or may not
[05df0a8]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.
[a0ed4ed]73 *
[05df0a8]74 *  Input parameters:   NONE
75 *
76 *  Output parameters:  NONE
77 */
78
79void _Thread_Handler( void )
80{
81  ISR_Level  level;
82  Thread_Control *executing;
[46a67b19]83  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
84    static char doneConstructors;
85    char doneCons;
86  #endif
[05279b84]87
[05df0a8]88  executing = _Thread_Executing;
[05279b84]89
[48816d7]90  /*
[28352fae]91   * Some CPUs need to tinker with the call frame or registers when the
[48816d7]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
[05df0a8]97  /*
98   * have to put level into a register for those cpu's that use
99   * inline asm here
100   */
[05279b84]101
[05df0a8]102  level = executing->Start.isr_level;
103  _ISR_Set_level(level);
104
[46a67b19]105  #if defined(EXECUTE_GLOBAL_CONSTRUCTORS)
106    doneCons = doneConstructors;
107    doneConstructors = 1;
108  #endif
[5b87515d]109
[46a67b19]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
[48f89683]120
[05df0a8]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 );
[05279b84]127
[05df0a8]128  /*
129   *  At this point, the dispatch disable level BETTER be 1.
130   */
131  _Thread_Enable_dispatch();
[94ab166]132
[46a67b19]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
[05df0a8]148      );
[46a67b19]149  }
[442eac69]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
[46a67b19]158  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
159    else if ( executing->Start.prototype == THREAD_START_BOTH_POINTER_FIRST ) {
[a0ed4ed]160      executing->Wait.return_argument =
161         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
[260b0c2]162           executing->Start.pointer_argument,
163           executing->Start.numeric_argument
164         );
[46a67b19]165    }
166    else if ( executing->Start.prototype == THREAD_START_BOTH_NUMERIC_FIRST ) {
[a0ed4ed]167      executing->Wait.return_argument =
[46a67b19]168       (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
169         executing->Start.numeric_argument,
170         executing->Start.pointer_argument
171       );
172    }
173  #endif
[05df0a8]174
[260b0c2]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
[a0ed4ed]178   *  anything (which is not supporting in all APIs), then it would be
[260b0c2]179   *  able to fit in a (void *).
180   */
181
[05df0a8]182  _User_extensions_Thread_exitted( executing );
183
184  _Internal_error_Occurred(
185    INTERNAL_ERROR_CORE,
[aae7f1a1]186    true,
[05df0a8]187    INTERNAL_ERROR_THREAD_EXITTED
188  );
189}
Note: See TracBrowser for help on using the repository browser.