1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread Handler |
---|
5 | * @ingroup ScoreThread |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2012. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | #include <rtems/score/assert.h> |
---|
23 | #include <rtems/score/interr.h> |
---|
24 | #include <rtems/score/isrlevel.h> |
---|
25 | #include <rtems/score/userextimpl.h> |
---|
26 | |
---|
27 | void _Thread_Handler( void ) |
---|
28 | { |
---|
29 | Thread_Control *executing; |
---|
30 | ISR_Level level; |
---|
31 | Per_CPU_Control *cpu_self; |
---|
32 | |
---|
33 | /* |
---|
34 | * Some CPUs need to tinker with the call frame or registers when the |
---|
35 | * thread actually begins to execute for the first time. This is a |
---|
36 | * hook point where the port gets a shot at doing whatever it requires. |
---|
37 | */ |
---|
38 | _Context_Initialization_at_thread_begin(); |
---|
39 | executing = _Thread_Executing; |
---|
40 | |
---|
41 | /* |
---|
42 | * have to put level into a register for those cpu's that use |
---|
43 | * inline asm here |
---|
44 | */ |
---|
45 | level = executing->Start.isr_level; |
---|
46 | _ISR_Set_level( level ); |
---|
47 | |
---|
48 | /* |
---|
49 | * Initialize the floating point context because we do not come |
---|
50 | * through _Thread_Dispatch on our first invocation. So the normal |
---|
51 | * code path for performing the FP context switch is not hit. |
---|
52 | */ |
---|
53 | _Thread_Restore_fp( executing ); |
---|
54 | |
---|
55 | /* |
---|
56 | * Do not use the level of the thread control block, since it has a |
---|
57 | * different format. |
---|
58 | */ |
---|
59 | _ISR_Local_disable( level ); |
---|
60 | |
---|
61 | /* |
---|
62 | * At this point, the dispatch disable level BETTER be 1. |
---|
63 | */ |
---|
64 | cpu_self = _Per_CPU_Get(); |
---|
65 | _Assert( cpu_self->thread_dispatch_disable_level == 1 ); |
---|
66 | |
---|
67 | /* |
---|
68 | * Make sure we lose no thread dispatch necessary update and execute the |
---|
69 | * post-switch actions. As a side-effect change the thread dispatch level |
---|
70 | * from one to zero. Do not use _Thread_Enable_dispatch() since there is no |
---|
71 | * valid thread dispatch necessary indicator in this context. |
---|
72 | */ |
---|
73 | _Thread_Do_dispatch( cpu_self, level ); |
---|
74 | |
---|
75 | /* |
---|
76 | * Invoke the thread begin extensions in the context of the thread entry |
---|
77 | * function with thread dispatching enabled. This enables use of dynamic |
---|
78 | * memory allocation, creation of POSIX keys and use of C++ thread local |
---|
79 | * storage. Blocking synchronization primitives are allowed also. |
---|
80 | */ |
---|
81 | _User_extensions_Thread_begin( executing ); |
---|
82 | |
---|
83 | /* |
---|
84 | * RTEMS supports multiple APIs and each API can define a different |
---|
85 | * thread/task prototype. The following code supports invoking the |
---|
86 | * user thread entry point using the prototype expected. |
---|
87 | */ |
---|
88 | ( *executing->Start.Entry.adaptor )( executing ); |
---|
89 | |
---|
90 | /* |
---|
91 | * In the call above, the return code from the user thread body which return |
---|
92 | * something was placed in return_argument. This assumed that if it |
---|
93 | * returned anything (which is not supporting in all APIs), then it would be |
---|
94 | * able to fit in a (void *). |
---|
95 | */ |
---|
96 | |
---|
97 | _User_extensions_Thread_exitted( executing ); |
---|
98 | |
---|
99 | _Internal_error( INTERNAL_ERROR_THREAD_EXITTED ); |
---|
100 | } |
---|