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

4.104.115
Last change on this file since bd59b348 was bd59b348, checked in by Joel Sherrill <joel.sherrill@…>, on 11/20/08 at 19:42:41

2008-11-20 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/newlibc_exit.c, score/src/threadhandler.c: Do not think about running init/fini on AVR. We do not know what mechanism it uses but this is not it.
  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[05df0a8]1/*
2 *  Thread Handler
3 *
4 *
[76deaf0c]5 *  COPYRIGHT (c) 1989-2008.
[05df0a8]6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in 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);
[f73fc29]45#endif
46#if defined(__USE__MAIN__)
47  extern void _main(void);
48#endif
49
[05df0a8]50/*PAGE
51 *
52 *  _Thread_Handler
53 *
54 *  This routine is the "primal" entry point for all threads.
55 *  _Context_Initialize() dummies up the thread's initial context
56 *  to cause the first Context_Switch() to jump to _Thread_Handler().
57 *
58 *  This routine is the default thread exitted error handler.  It is
59 *  returned to when a thread exits.  The configured fatal error handler
60 *  is invoked to process the exit.
61 *
62 *  NOTE:
63 *
64 *  On entry, it is assumed all interrupts are blocked and that this
[a0ed4ed]65 *  routine needs to set the initial isr level.  This may or may not
[05df0a8]66 *  actually be needed by the context switch routine and as a result
67 *  interrupts may already be at there proper level.  Either way,
68 *  setting the initial isr level properly here is safe.
[a0ed4ed]69 *
[05df0a8]70 *  Currently this is only really needed for the posix port,
71 *  ref: _Context_Switch in unix/cpu.c
72 *
73 *  Input parameters:   NONE
74 *
75 *  Output parameters:  NONE
76 */
77
78void _Thread_Handler( void )
79{
80  ISR_Level  level;
81  Thread_Control *executing;
[94ab166]82#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
[5b87515d]83  static char doneConstructors;
84  char doneCons;
85#endif
[05279b84]86
[05df0a8]87  executing = _Thread_Executing;
[05279b84]88
[48816d7]89  /*
90   * Some CPUs need to tinker with the call frame or registers when the
91   * thread actually begins to execute for the first time.  This is a
92   * hook point where the port gets a shot at doing whatever it requires.
93   */
94  _Context_Initialization_at_thread_begin();
95
[05df0a8]96  /*
97   * have to put level into a register for those cpu's that use
98   * inline asm here
99   */
[05279b84]100
[05df0a8]101  level = executing->Start.isr_level;
102  _ISR_Set_level(level);
103
[94ab166]104#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
[5b87515d]105  doneCons = doneConstructors;
106  doneConstructors = 1;
107#endif
108
[48f89683]109#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
110#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
111  if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
112    if ( _Thread_Allocated_fp != NULL )
113      _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
114    _Thread_Allocated_fp = executing;
115  }
116#endif
117#endif
118
[05df0a8]119  /*
120   * Take care that 'begin' extensions get to complete before
121   * 'switch' extensions can run.  This means must keep dispatch
122   * disabled until all 'begin' extensions complete.
123   */
[05279b84]124
[05df0a8]125  _User_extensions_Thread_begin( executing );
[05279b84]126
[05df0a8]127  /*
128   *  At this point, the dispatch disable level BETTER be 1.
129   */
130
131  _Thread_Enable_dispatch();
[6244ab4]132#if defined(__USE_INIT_FINI__)
[e1bce86]133  /*
134   *  _init could be a weak symbol and we SHOULD test it but it isn't
135   *  in any configuration I know of and it generates a warning on every
136   *  RTEMS target configuration.  --joel (12 May 2007)
137   */
138  if (!doneCons) /* && (volatile void *)_init) */
[42fce5d3]139  {
[d104778]140    INIT_NAME ();
[42fce5d3]141  }
[5b87515d]142#endif
[94ab166]143#if defined(__USE__MAIN__)
[66565bb]144  if (!doneCons && _main)
[94ab166]145    __main ();
146#endif
147
[05df0a8]148  switch ( executing->Start.prototype ) {
149    case THREAD_START_NUMERIC:
[a0ed4ed]150      executing->Wait.return_argument =
[260b0c2]151        (*(Thread_Entry_numeric) executing->Start.entry_point)(
152          executing->Start.numeric_argument
[05df0a8]153      );
154      break;
155    case THREAD_START_POINTER:
[260b0c2]156      executing->Wait.return_argument =
157        (*(Thread_Entry_pointer) executing->Start.entry_point)(
158          executing->Start.pointer_argument
159        );
[05df0a8]160      break;
161    case THREAD_START_BOTH_POINTER_FIRST:
[a0ed4ed]162      executing->Wait.return_argument =
163         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
[260b0c2]164           executing->Start.pointer_argument,
165           executing->Start.numeric_argument
166         );
[05df0a8]167      break;
168    case THREAD_START_BOTH_NUMERIC_FIRST:
[a0ed4ed]169      executing->Wait.return_argument =
170         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
[260b0c2]171           executing->Start.numeric_argument,
172           executing->Start.pointer_argument
173         );
[05df0a8]174      break;
175  }
176
[260b0c2]177  /*
178   *  In the switch above, the return code from the user thread body
179   *  was placed in return_argument.  This assumed that if it returned
[a0ed4ed]180   *  anything (which is not supporting in all APIs), then it would be
[260b0c2]181   *  able to fit in a (void *).
182   */
183
[05df0a8]184  _User_extensions_Thread_exitted( executing );
185
186  _Internal_error_Occurred(
187    INTERNAL_ERROR_CORE,
188    TRUE,
189    INTERNAL_ERROR_THREAD_EXITTED
190  );
191}
Note: See TracBrowser for help on using the repository browser.