1 | /* |
---|
2 | * hal_context.h - Generic Thread Context Access API definition. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _HAL_CONTEXT_H_ |
---|
25 | #define _HAL_CONTEXT_H_ |
---|
26 | |
---|
27 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
28 | // Generic Thread Context API definition (implementation in hal_context.c) |
---|
29 | // |
---|
30 | // A thread context is defined by the two (core specific) structures hal_cpu_context_t |
---|
31 | // and hal_fpu_context_t, defined in hal_context.c file, that are accessed with generic |
---|
32 | // void* pointers stored in the thread descriptor. |
---|
33 | // - the "hal_context_t" structure is used to store the CPU registers values that |
---|
34 | // have not been saved in the kernel stack by the interrupt handler. |
---|
35 | // - the "hal_fpu_context_t" structure is used to save the FPU registers when required. |
---|
36 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
37 | |
---|
38 | /**** Forward declarations ****/ |
---|
39 | |
---|
40 | struct thread_s; |
---|
41 | |
---|
42 | /**************************************************************************************** |
---|
43 | * This function allocates, from the local cluster, the physical memory required for |
---|
44 | * the thread CPU context, initialises it, and links the context to the thread. |
---|
45 | **************************************************************************************** |
---|
46 | * @ thread : pointer on the thread descriptor. |
---|
47 | * @ return 0 if success / return ENOMEM if error |
---|
48 | ***************************************************************************************/ |
---|
49 | error_t hal_cpu_context_create( struct thread_s * thread ); |
---|
50 | |
---|
51 | /**************************************************************************************** |
---|
52 | * This function allocates, from the local cluster, the physical memory required for |
---|
53 | * a thread CPU context, initialises it from values contained in "src" thread context, |
---|
54 | * and links the context to the "dst" thread. |
---|
55 | **************************************************************************************** |
---|
56 | * @ dst : pointer on the destination thread descriptor. |
---|
57 | * @ src : pointer on the source thread descriptor. |
---|
58 | * @ return 0 if success / return ENOMEM if error |
---|
59 | ***************************************************************************************/ |
---|
60 | error_t hal_cpu_context_copy( struct thread_s * dst, |
---|
61 | struct thread_s * src ); |
---|
62 | |
---|
63 | /**************************************************************************************** |
---|
64 | * This function releases the physical memory allocated for a thread CPU context. |
---|
65 | **************************************************************************************** |
---|
66 | * @ thread : pointer on the thread descriptor. |
---|
67 | ***************************************************************************************/ |
---|
68 | void hal_cpu_context_destroy( struct thread_s * thread ); |
---|
69 | |
---|
70 | /**************************************************************************************** |
---|
71 | * This function performs a context switch, saving the CPU register values into the |
---|
72 | * old thread, and initializing these registers with the values of the new thread. |
---|
73 | **************************************************************************************** |
---|
74 | * @ old : pointer on current thread. |
---|
75 | * @ new : pointer on the thread we want to switch to. |
---|
76 | ***************************************************************************************/ |
---|
77 | void hal_cpu_context_switch( struct thread_s * old , struct thread_s * new ); |
---|
78 | |
---|
79 | /**************************************************************************************** |
---|
80 | * This function loads the relevant CPU registers from values contained in |
---|
81 | * the thread context. It should be called for a thread that has not been executed yet. |
---|
82 | * It reset the loadable flag in thread descriptor. |
---|
83 | **************************************************************************************** |
---|
84 | * @ thread : pointer on the thread descriptor. |
---|
85 | ***************************************************************************************/ |
---|
86 | void hal_cpu_context_load( struct thread_s * thread ); |
---|
87 | |
---|
88 | /**************************************************************************************** |
---|
89 | * This function allocates, from the local cluster, the physical memory required for |
---|
90 | * the thread FPU context, and initialises the thread pointer. |
---|
91 | **************************************************************************************** |
---|
92 | * @ thread : pointer on the thread descriptor. |
---|
93 | * @ return 0 if success / return ENOMEM if error |
---|
94 | ***************************************************************************************/ |
---|
95 | error_t hal_fpu_context_create( struct thread_s * thread ); |
---|
96 | |
---|
97 | /**************************************************************************************** |
---|
98 | * This function allocates, from the local cluster, the physical memory required for |
---|
99 | * a thread FPU context, initialises it from values contained in "src" thread context, |
---|
100 | * and link the context to the "dst" thread. |
---|
101 | **************************************************************************************** |
---|
102 | * @ dst : pointer on the destination thread descriptor. |
---|
103 | * @ src : pointer on the source thread descriptor. |
---|
104 | * @ return 0 if success / return ENOMEM if error |
---|
105 | ***************************************************************************************/ |
---|
106 | error_t hal_fpu_context_copy( struct thread_s * dst, |
---|
107 | struct thread_s * src ); |
---|
108 | |
---|
109 | /**************************************************************************************** |
---|
110 | * This function releases the physical memory allocated for a FPU context. |
---|
111 | **************************************************************************************** |
---|
112 | * @ thread : pointer on the thread descriptor. |
---|
113 | ***************************************************************************************/ |
---|
114 | void hal_fpu_context_destroy( struct thread_s * thread ); |
---|
115 | |
---|
116 | /**************************************************************************************** |
---|
117 | * This function saves in the thread uzone the FPU registers values. |
---|
118 | **************************************************************************************** |
---|
119 | * @ thread : pointer on the thread descriptor. |
---|
120 | ***************************************************************************************/ |
---|
121 | void hal_fpu_context_save( struct thread_s * thread ); |
---|
122 | |
---|
123 | /**************************************************************************************** |
---|
124 | * This function restores from the thread uzone the FPU registers values. |
---|
125 | **************************************************************************************** |
---|
126 | * @ thread : pointer on the thread descriptor. |
---|
127 | ***************************************************************************************/ |
---|
128 | void hal_fpu_context_restore( struct thread_s * thread ); |
---|
129 | |
---|
130 | #endif /* _HAL_CONTEXT_H_ */ |
---|