[05df0a8] | 1 | /* |
---|
| 2 | * Thread Handler |
---|
| 3 | * |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[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 |
---|
| 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 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 | |
---|
| 57 | void _Thread_Handler( void ) |
---|
| 58 | { |
---|
| 59 | ISR_Level level; |
---|
| 60 | Thread_Control *executing; |
---|
[5b87515d] | 61 | #ifdef USE_INIT_FINI |
---|
| 62 | static char doneConstructors; |
---|
| 63 | char doneCons; |
---|
| 64 | #endif |
---|
[05df0a8] | 65 | |
---|
| 66 | executing = _Thread_Executing; |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * have to put level into a register for those cpu's that use |
---|
| 70 | * inline asm here |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | level = executing->Start.isr_level; |
---|
| 74 | _ISR_Set_level(level); |
---|
| 75 | |
---|
[5b87515d] | 76 | #ifdef USE_INIT_FINI |
---|
| 77 | doneCons = doneConstructors; |
---|
| 78 | doneConstructors = 1; |
---|
| 79 | #endif |
---|
| 80 | |
---|
[05df0a8] | 81 | /* |
---|
| 82 | * Take care that 'begin' extensions get to complete before |
---|
| 83 | * 'switch' extensions can run. This means must keep dispatch |
---|
| 84 | * disabled until all 'begin' extensions complete. |
---|
| 85 | */ |
---|
| 86 | |
---|
| 87 | _User_extensions_Thread_begin( executing ); |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * At this point, the dispatch disable level BETTER be 1. |
---|
| 91 | */ |
---|
| 92 | |
---|
| 93 | _Thread_Enable_dispatch(); |
---|
[5b87515d] | 94 | #ifdef USE_INIT_FINI |
---|
| 95 | if (!doneCons) |
---|
| 96 | _init (); |
---|
| 97 | #endif |
---|
[05df0a8] | 98 | |
---|
| 99 | switch ( executing->Start.prototype ) { |
---|
| 100 | case THREAD_START_NUMERIC: |
---|
[260b0c2] | 101 | executing->Wait.return_argument = |
---|
| 102 | (*(Thread_Entry_numeric) executing->Start.entry_point)( |
---|
| 103 | executing->Start.numeric_argument |
---|
[05df0a8] | 104 | ); |
---|
| 105 | break; |
---|
| 106 | case THREAD_START_POINTER: |
---|
[260b0c2] | 107 | executing->Wait.return_argument = |
---|
| 108 | (*(Thread_Entry_pointer) executing->Start.entry_point)( |
---|
| 109 | executing->Start.pointer_argument |
---|
| 110 | ); |
---|
[05df0a8] | 111 | break; |
---|
| 112 | case THREAD_START_BOTH_POINTER_FIRST: |
---|
[260b0c2] | 113 | executing->Wait.return_argument = |
---|
| 114 | (*(Thread_Entry_both_pointer_first) executing->Start.entry_point)( |
---|
| 115 | executing->Start.pointer_argument, |
---|
| 116 | executing->Start.numeric_argument |
---|
| 117 | ); |
---|
[05df0a8] | 118 | break; |
---|
| 119 | case THREAD_START_BOTH_NUMERIC_FIRST: |
---|
[260b0c2] | 120 | executing->Wait.return_argument = |
---|
| 121 | (*(Thread_Entry_both_numeric_first) executing->Start.entry_point)( |
---|
| 122 | executing->Start.numeric_argument, |
---|
| 123 | executing->Start.pointer_argument |
---|
| 124 | ); |
---|
[05df0a8] | 125 | break; |
---|
| 126 | } |
---|
| 127 | |
---|
[260b0c2] | 128 | /* |
---|
| 129 | * In the switch above, the return code from the user thread body |
---|
| 130 | * was placed in return_argument. This assumed that if it returned |
---|
| 131 | * anything (which is not supporting in all APIs), then it would be |
---|
| 132 | * able to fit in a (void *). |
---|
| 133 | */ |
---|
| 134 | |
---|
[05df0a8] | 135 | _User_extensions_Thread_exitted( executing ); |
---|
| 136 | |
---|
| 137 | _Internal_error_Occurred( |
---|
| 138 | INTERNAL_ERROR_CORE, |
---|
| 139 | TRUE, |
---|
| 140 | INTERNAL_ERROR_THREAD_EXITTED |
---|
| 141 | ); |
---|
| 142 | } |
---|