1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Start Thread Multitasking |
---|
5 | * @ingroup ScoreThread |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2006. |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | |
---|
23 | void _Thread_Start_multitasking( Context_Control *context ) |
---|
24 | { |
---|
25 | Per_CPU_Control *self_cpu = _Per_CPU_Get(); |
---|
26 | Thread_Control *heir = self_cpu->heir; |
---|
27 | |
---|
28 | #if defined(RTEMS_SMP) |
---|
29 | _Per_CPU_Change_state( self_cpu, PER_CPU_STATE_UP ); |
---|
30 | |
---|
31 | _Per_CPU_Acquire( self_cpu ); |
---|
32 | |
---|
33 | self_cpu->executing->is_executing = false; |
---|
34 | heir->is_executing = true; |
---|
35 | #endif |
---|
36 | |
---|
37 | self_cpu->dispatch_necessary = false; |
---|
38 | self_cpu->executing = heir; |
---|
39 | |
---|
40 | /* |
---|
41 | * Get the init task(s) running. |
---|
42 | * |
---|
43 | * Note: Thread_Dispatch() is normally used to dispatch threads. As |
---|
44 | * part of its work, Thread_Dispatch() restores floating point |
---|
45 | * state for the heir task. |
---|
46 | * |
---|
47 | * This code avoids Thread_Dispatch(), and so we have to restore |
---|
48 | * (actually initialize) the floating point state "by hand". |
---|
49 | * |
---|
50 | * Ignore the CPU_USE_DEFERRED_FP_SWITCH because we must always |
---|
51 | * switch in the first thread if it is FP. |
---|
52 | */ |
---|
53 | #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) |
---|
54 | /* |
---|
55 | * don't need to worry about saving BSP's floating point state |
---|
56 | */ |
---|
57 | |
---|
58 | if ( heir->fp_context != NULL ) |
---|
59 | _Context_Restore_fp( &heir->fp_context ); |
---|
60 | #endif |
---|
61 | |
---|
62 | #if defined(RTEMS_SMP) |
---|
63 | if ( context != NULL ) { |
---|
64 | #endif |
---|
65 | |
---|
66 | #if defined(_CPU_Start_multitasking) |
---|
67 | _CPU_Start_multitasking( context, &heir->Registers ); |
---|
68 | #else |
---|
69 | _Context_Switch( context, &heir->Registers ); |
---|
70 | #endif |
---|
71 | |
---|
72 | #if defined(RTEMS_SMP) |
---|
73 | } else { |
---|
74 | /* |
---|
75 | * Threads begin execution in the _Thread_Handler() function. This |
---|
76 | * function will set the thread dispatch disable level to zero and calls |
---|
77 | * _Per_CPU_Release(). |
---|
78 | */ |
---|
79 | self_cpu->thread_dispatch_disable_level = 1; |
---|
80 | |
---|
81 | _CPU_Context_switch_to_first_task_smp( &heir->Registers ); |
---|
82 | } |
---|
83 | #endif |
---|
84 | } |
---|