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

4.8
Last change on this file since bd029d87 was 334573e3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/07 at 13:35:12

2007-11-02 Joel Sherrill <joel.sherrill@…>

  • score/cpu/sparc/cpu.c, score/cpu/sparc/rtems/score/cpu.h, score/include/rtems/score/context.h, score/src/threadhandler.c: Fix stack so gdb backtrace does not print corrupted frame message after _Thread_Handler. Daniel Hellstrom <daniel@…> provided the SPARC implementation and I made it more general.
  • Property mode set to 100644
File size: 5.0 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   * Some CPUs need to tinker with the call frame or registers when the
80   * thread actually begins to execute for the first time.  This is a
81   * hook point where the port gets a shot at doing whatever it requires.
82   */
83  _Context_Initialization_at_thread_begin();
84
85  /*
86   * have to put level into a register for those cpu's that use
87   * inline asm here
88   */
89
90  level = executing->Start.isr_level;
91  _ISR_Set_level(level);
92
93#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
94  doneCons = doneConstructors;
95  doneConstructors = 1;
96#endif
97
98#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
99#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
100  if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
101    if ( _Thread_Allocated_fp != NULL )
102      _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
103    _Thread_Allocated_fp = executing;
104  }
105#endif
106#endif
107
108  /*
109   * Take care that 'begin' extensions get to complete before
110   * 'switch' extensions can run.  This means must keep dispatch
111   * disabled until all 'begin' extensions complete.
112   */
113
114  _User_extensions_Thread_begin( executing );
115
116  /*
117   *  At this point, the dispatch disable level BETTER be 1.
118   */
119
120  _Thread_Enable_dispatch();
121#if defined(__USE_INIT_FINI__)
122  /*
123   *  _init could be a weak symbol and we SHOULD test it but it isn't
124   *  in any configuration I know of and it generates a warning on every
125   *  RTEMS target configuration.  --joel (12 May 2007)
126   */
127  if (!doneCons) /* && (volatile void *)_init) */
128    _init ();
129#endif
130#if defined(__USE__MAIN__)
131  if (!doneCons && _main)
132    __main ();
133#endif
134
135  switch ( executing->Start.prototype ) {
136    case THREAD_START_NUMERIC:
137      executing->Wait.return_argument =
138        (*(Thread_Entry_numeric) executing->Start.entry_point)(
139          executing->Start.numeric_argument
140      );
141      break;
142    case THREAD_START_POINTER:
143      executing->Wait.return_argument =
144        (*(Thread_Entry_pointer) executing->Start.entry_point)(
145          executing->Start.pointer_argument
146        );
147      break;
148    case THREAD_START_BOTH_POINTER_FIRST:
149      executing->Wait.return_argument =
150         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
151           executing->Start.pointer_argument,
152           executing->Start.numeric_argument
153         );
154      break;
155    case THREAD_START_BOTH_NUMERIC_FIRST:
156      executing->Wait.return_argument =
157         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
158           executing->Start.numeric_argument,
159           executing->Start.pointer_argument
160         );
161      break;
162  }
163
164  /*
165   *  In the switch above, the return code from the user thread body
166   *  was placed in return_argument.  This assumed that if it returned
167   *  anything (which is not supporting in all APIs), then it would be
168   *  able to fit in a (void *).
169   */
170
171  _User_extensions_Thread_exitted( executing );
172
173  _Internal_error_Occurred(
174    INTERNAL_ERROR_CORE,
175    TRUE,
176    INTERNAL_ERROR_THREAD_EXITTED
177  );
178}
Note: See TracBrowser for help on using the repository browser.