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

4.104.114.84.95
Last change on this file since 3127180 was dd687d97, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:56:05

2003-09-04 Joel Sherrill <joel@…>

  • include/rtems/debug.h, include/rtems/seterr.h, include/rtems/system.h, include/rtems/score/address.h, include/rtems/score/apiext.h, include/rtems/score/apimutex.h, include/rtems/score/bitfield.h, include/rtems/score/chain.h, include/rtems/score/context.h, include/rtems/score/copyrt.h, include/rtems/score/coremsg.h, include/rtems/score/coremutex.h, include/rtems/score/coresem.h, include/rtems/score/heap.h, include/rtems/score/interr.h, include/rtems/score/isr.h, include/rtems/score/mpci.h, include/rtems/score/mppkt.h, include/rtems/score/object.h, include/rtems/score/objectmp.h, include/rtems/score/priority.h, include/rtems/score/stack.h, include/rtems/score/states.h, include/rtems/score/sysstate.h, include/rtems/score/thread.h, include/rtems/score/threadmp.h, include/rtems/score/threadq.h, include/rtems/score/tod.h, include/rtems/score/tqdata.h, include/rtems/score/userext.h, include/rtems/score/watchdog.h, include/rtems/score/wkspace.h, inline/rtems/score/address.inl, inline/rtems/score/chain.inl, inline/rtems/score/coremsg.inl, inline/rtems/score/coremutex.inl, inline/rtems/score/coresem.inl, inline/rtems/score/heap.inl, inline/rtems/score/isr.inl, inline/rtems/score/mppkt.inl, inline/rtems/score/object.inl, inline/rtems/score/objectmp.inl, inline/rtems/score/priority.inl, inline/rtems/score/stack.inl, inline/rtems/score/states.inl, inline/rtems/score/sysstate.inl, inline/rtems/score/thread.inl, inline/rtems/score/threadmp.inl, inline/rtems/score/tod.inl, inline/rtems/score/tqdata.inl, inline/rtems/score/userext.inl, inline/rtems/score/watchdog.inl, inline/rtems/score/wkspace.inl, macros/rtems/score/address.inl, macros/rtems/score/chain.inl, macros/rtems/score/coremsg.inl, macros/rtems/score/coremutex.inl, macros/rtems/score/coresem.inl, macros/rtems/score/heap.inl, macros/rtems/score/isr.inl, macros/rtems/score/mppkt.inl, macros/rtems/score/object.inl, macros/rtems/score/objectmp.inl, macros/rtems/score/priority.inl, macros/rtems/score/stack.inl, macros/rtems/score/states.inl, macros/rtems/score/sysstate.inl, macros/rtems/score/thread.inl, macros/rtems/score/threadmp.inl, macros/rtems/score/tod.inl, macros/rtems/score/tqdata.inl, macros/rtems/score/userext.inl, macros/rtems/score/watchdog.inl, macros/rtems/score/wkspace.inl, src/apiext.c, src/chain.c, src/coremsg.c, src/coremsgbroadcast.c, src/coremsgclose.c, src/coremsgflush.c, src/coremsgflushsupp.c, src/coremsgflushwait.c, src/coremsginsert.c, src/coremsgseize.c, src/coremsgsubmit.c, src/coremutex.c, src/coremutexflush.c, src/coremutexseize.c, src/coremutexsurrender.c, src/coresem.c, src/coresemflush.c, src/coresemseize.c, src/coresemsurrender.c, src/coretod.c, src/coretodset.c, src/coretodtickle.c, src/coretodtoseconds.c, src/coretodvalidate.c, src/heap.c, src/heapallocate.c, src/heapextend.c, src/heapfree.c, src/heapgetinfo.c, src/heapsizeofuserarea.c, src/heapwalk.c, src/interr.c, src/isr.c, src/iterateoverthreads.c, src/mpci.c, src/object.c, src/objectallocate.c, src/objectallocatebyindex.c, src/objectclearname.c, src/objectcomparenameraw.c, src/objectcomparenamestring.c, src/objectcopynameraw.c, src/objectcopynamestring.c, src/objectextendinformation.c, src/objectfree.c, src/objectget.c, src/objectgetbyindex.c, src/objectgetisr.c, src/objectgetnext.c, src/objectgetnoprotection.c, src/objectidtoname.c, src/objectinitializeinformation.c, src/objectmp.c, src/objectnametoid.c, src/objectshrinkinformation.c, src/thread.c, src/threadchangepriority.c, src/threadclearstate.c, src/threadclose.c, src/threadcreateidle.c, src/threaddelayended.c, src/threaddispatch.c, src/threadevaluatemode.c, src/threadget.c, src/threadhandler.c, src/threadidlebody.c, src/threadinitialize.c, src/threadloadenv.c, src/threadmp.c, src/threadq.c, src/threadqdequeue.c, src/threadqdequeuefifo.c, src/threadqdequeuepriority.c, src/threadqenqueue.c, src/threadqenqueuefifo.c, src/threadqenqueuepriority.c, src/threadqextract.c, src/threadqextractfifo.c, src/threadqextractpriority.c, src/threadqextractwithproxy.c, src/threadqfirst.c, src/threadqfirstfifo.c, src/threadqfirstpriority.c, src/threadqflush.c, src/threadqtimeout.c, src/threadready.c, src/threadreset.c, src/threadresettimeslice.c, src/threadrestart.c, src/threadresume.c, src/threadrotatequeue.c, src/threadsetpriority.c, src/threadsetstate.c, src/threadsettransient.c, src/threadstackallocate.c, src/threadstackfree.c, src/threadstart.c, src/threadstartmultitasking.c, src/threadsuspend.c, src/threadtickletimeslice.c, src/threadyieldprocessor.c, src/userext.c, src/watchdog.c, src/watchdogadjust.c, src/watchdoginsert.c, src/watchdogremove.c, src/watchdogtickle.c, src/wkspace.c: URL for license changed.
  • Property mode set to 100644
File size: 4.4 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#include <rtems/system.h>
16#include <rtems/score/apiext.h>
17#include <rtems/score/context.h>
18#include <rtems/score/interr.h>
19#include <rtems/score/isr.h>
20#include <rtems/score/object.h>
21#include <rtems/score/priority.h>
22#include <rtems/score/states.h>
23#include <rtems/score/sysstate.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28
29/*PAGE
30 *
31 *  _Thread_Handler
32 *
33 *  This routine is the "primal" entry point for all threads.
34 *  _Context_Initialize() dummies up the thread's initial context
35 *  to cause the first Context_Switch() to jump to _Thread_Handler().
36 *
37 *  This routine is the default thread exitted error handler.  It is
38 *  returned to when a thread exits.  The configured fatal error handler
39 *  is invoked to process the exit.
40 *
41 *  NOTE:
42 *
43 *  On entry, it is assumed all interrupts are blocked and that this
44 *  routine needs to set the initial isr level.  This may or may not
45 *  actually be needed by the context switch routine and as a result
46 *  interrupts may already be at there proper level.  Either way,
47 *  setting the initial isr level properly here is safe.
48 * 
49 *  Currently this is only really needed for the posix port,
50 *  ref: _Context_Switch in unix/cpu.c
51 *
52 *  Input parameters:   NONE
53 *
54 *  Output parameters:  NONE
55 */
56
57void _Thread_Handler( void )
58{
59  ISR_Level  level;
60  Thread_Control *executing;
61#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
62  static char doneConstructors;
63  char doneCons;
64#endif
65#if defined(__USE_INIT_FINI__)
66  extern void _init(void);
67#endif
68#if defined(__USE__MAIN__)
69  extern void _main(void);
70#endif
71 
72  executing = _Thread_Executing;
73 
74  /*
75   * have to put level into a register for those cpu's that use
76   * inline asm here
77   */
78 
79  level = executing->Start.isr_level;
80  _ISR_Set_level(level);
81
82#if defined(__USE_INIT_FINI__) || defined(__USE__MAIN__)
83  doneCons = doneConstructors;
84  doneConstructors = 1;
85#endif
86
87#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
88#if ( CPU_USE_DEFERRED_FP_SWITCH == TRUE )
89  if ( (executing->fp_context != NULL) && !_Thread_Is_allocated_fp( executing ) ) {
90    if ( _Thread_Allocated_fp != NULL )
91      _Context_Save_fp( &_Thread_Allocated_fp->fp_context );
92    _Thread_Allocated_fp = executing;
93  }
94#endif
95#endif
96
97
98  /*
99   * Take care that 'begin' extensions get to complete before
100   * 'switch' extensions can run.  This means must keep dispatch
101   * disabled until all 'begin' extensions complete.
102   */
103 
104  _User_extensions_Thread_begin( executing );
105 
106  /*
107   *  At this point, the dispatch disable level BETTER be 1.
108   */
109
110  _Thread_Enable_dispatch();
111#if defined(__USE_INIT_FINI__)
112  if (!doneCons && _init)
113    _init ();
114#endif
115#if defined(__USE__MAIN__)
116  if (!doneCons && _main)
117    __main ();
118#endif
119
120 
121  switch ( executing->Start.prototype ) {
122    case THREAD_START_NUMERIC:
123      executing->Wait.return_argument =
124        (*(Thread_Entry_numeric) executing->Start.entry_point)(
125          executing->Start.numeric_argument
126      );
127      break;
128    case THREAD_START_POINTER:
129      executing->Wait.return_argument =
130        (*(Thread_Entry_pointer) executing->Start.entry_point)(
131          executing->Start.pointer_argument
132        );
133      break;
134    case THREAD_START_BOTH_POINTER_FIRST:
135      executing->Wait.return_argument =
136         (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)(
137           executing->Start.pointer_argument,
138           executing->Start.numeric_argument
139         );
140      break;
141    case THREAD_START_BOTH_NUMERIC_FIRST:
142      executing->Wait.return_argument =
143         (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)(
144           executing->Start.numeric_argument,
145           executing->Start.pointer_argument
146         );
147      break;
148  }
149
150  /*
151   *  In the switch above, the return code from the user thread body
152   *  was placed in return_argument.  This assumed that if it returned
153   *  anything (which is not supporting in all APIs), then it would be
154   *  able to fit in a (void *).
155   */
156
157  _User_extensions_Thread_exitted( executing );
158
159  _Internal_error_Occurred(
160    INTERNAL_ERROR_CORE,
161    TRUE,
162    INTERNAL_ERROR_THREAD_EXITTED
163  );
164}
Note: See TracBrowser for help on using the repository browser.