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

4.104.114.84.95
Last change on this file since fa6b0f5 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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
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/*PAGE
34 *
35 *  _Thread_Handler
36 *
37 *  This routine is the "primal" entry point for all threads.
38 *  _Context_Initialize() dummies up the thread's initial context
39 *  to cause the first Context_Switch() to jump to _Thread_Handler().
40 *
41 *  This routine is the default thread exitted error handler.  It is
42 *  returned to when a thread exits.  The configured fatal error handler
43 *  is invoked to process the exit.
44 *
45 *  NOTE:
46 *
47 *  On entry, it is assumed all interrupts are blocked and that this
48 *  routine needs to set the initial isr level.  This may or may not
49 *  actually be needed by the context switch routine and as a result
50 *  interrupts may already be at there proper level.  Either way,
51 *  setting the initial isr level properly here is safe.
52 *
53 *  Currently this is only really needed for the posix port,
54 *  ref: _Context_Switch in unix/cpu.c
55 *
56 *  Input parameters:   NONE
57 *
58 *  Output parameters:  NONE
59 */
60
61void _Thread_Handler( void )
62{
63  ISR_Level  level;
64  Thread_Control *executing;
65#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
66  static char doneConstructors;
67  char doneCons;
68#endif
69#if defined(__USE_INIT_FINI__)
70  extern void _init(void);
71#endif
72#if defined(__USE__MAIN__)
73  extern void _main(void);
74#endif
75
76  executing = _Thread_Executing;
77
78  /*
79   * have to put level into a register for those cpu's that use
80   * inline asm here
81   */
82
83  level = executing->Start.isr_level;
84  _ISR_Set_level(level);
85
86#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
87  doneCons = doneConstructors;
88  doneConstructors = 1;
89#endif
90
91#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
92#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
93  if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
94    if ( _Thread_Allocated_fp != NULL )
95      _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
96    _Thread_Allocated_fp = executing;
97  }
98#endif
99#endif
100
101
102  /*
103   * Take care that 'begin' extensions get to complete before
104   * 'switch' extensions can run.  This means must keep dispatch
105   * disabled until all 'begin' extensions complete.
106   */
107
108  _User_extensions_Thread_begin( executing );
109
110  /*
111   *  At this point, the dispatch disable level BETTER be 1.
112   */
113
114  _Thread_Enable_dispatch();
115#if defined(__USE_INIT_FINI__)
116  if (!doneCons && _init)
117    _init ();
118#endif
119#if defined(__USE__MAIN__)
120  if (!doneCons && _main)
121    __main ();
122#endif
123
124
125  switch ( executing->Start.prototype ) {
126    case THREAD_START_NUMERIC:
127      executing->Wait.return_argument =
128        (*(Thread_Entry_numeric) executing->Start.entry_point)(
129          executing->Start.numeric_argument
130      );
131      break;
132    case THREAD_START_POINTER:
133      executing->Wait.return_argument =
134        (*(Thread_Entry_pointer) executing->Start.entry_point)(
135          executing->Start.pointer_argument
136        );
137      break;
138    case THREAD_START_BOTH_POINTER_FIRST:
139      executing->Wait.return_argument =
140         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
141           executing->Start.pointer_argument,
142           executing->Start.numeric_argument
143         );
144      break;
145    case THREAD_START_BOTH_NUMERIC_FIRST:
146      executing->Wait.return_argument =
147         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
148           executing->Start.numeric_argument,
149           executing->Start.pointer_argument
150         );
151      break;
152  }
153
154  /*
155   *  In the switch above, the return code from the user thread body
156   *  was placed in return_argument.  This assumed that if it returned
157   *  anything (which is not supporting in all APIs), then it would be
158   *  able to fit in a (void *).
159   */
160
161  _User_extensions_Thread_exitted( executing );
162
163  _Internal_error_Occurred(
164    INTERNAL_ERROR_CORE,
165    TRUE,
166    INTERNAL_ERROR_THREAD_EXITTED
167  );
168}
Note: See TracBrowser for help on using the repository browser.