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 saves in the thread context the CPU registers values that must be |
---|
72 | * saved at context switch. |
---|
73 | **************************************************************************************** |
---|
74 | * @ ctx : pointer on cpu context. |
---|
75 | ***************************************************************************************/ |
---|
76 | void hal_cpu_context_save( void * ctx ); |
---|
77 | |
---|
78 | /**************************************************************************************** |
---|
79 | * This function restores from the thread context the CPU registers values that must |
---|
80 | * be restored at context switch. |
---|
81 | **************************************************************************************** |
---|
82 | * @ ctx : pointer on cpu context. |
---|
83 | ***************************************************************************************/ |
---|
84 | void hal_cpu_context_restore( void * ctx ); |
---|
85 | |
---|
86 | /**************************************************************************************** |
---|
87 | * This function loads the relevant CPU registers from values contained in |
---|
88 | * the thread context. It should be called for a thread that has not been executed yet. |
---|
89 | * It reset the loadable flag in thread descriptor. |
---|
90 | **************************************************************************************** |
---|
91 | * @ thread : pointer on the thread descriptor. |
---|
92 | ***************************************************************************************/ |
---|
93 | void hal_cpu_context_load( struct thread_s * thread ); |
---|
94 | |
---|
95 | |
---|
96 | /**************************************************************************************** |
---|
97 | * This function allocates, from the local cluster, the physical memory required for |
---|
98 | * the thread FPU context, and initialises the thread pointer. |
---|
99 | **************************************************************************************** |
---|
100 | * @ thread : pointer on the thread descriptor. |
---|
101 | * @ return 0 if success / return ENOMEM if error |
---|
102 | ***************************************************************************************/ |
---|
103 | error_t hal_fpu_context_create( struct thread_s * thread ); |
---|
104 | |
---|
105 | /**************************************************************************************** |
---|
106 | * This function allocates, from the local cluster, the physical memory required for |
---|
107 | * a thread FPU context, initialises it from values contained in "src" thread context, |
---|
108 | * and link the context to the "dst" thread. |
---|
109 | **************************************************************************************** |
---|
110 | * @ dst : pointer on the destination thread descriptor. |
---|
111 | * @ src : pointer on the source thread descriptor. |
---|
112 | * @ return 0 if success / return ENOMEM if error |
---|
113 | ***************************************************************************************/ |
---|
114 | error_t hal_fpu_context_copy( struct thread_s * dst, |
---|
115 | struct thread_s * src ); |
---|
116 | |
---|
117 | /**************************************************************************************** |
---|
118 | * This function releases the physical memory allocated for a FPU context. |
---|
119 | **************************************************************************************** |
---|
120 | * @ thread : pointer on the thread descriptor. |
---|
121 | ***************************************************************************************/ |
---|
122 | void hal_fpu_context_destroy( struct thread_s * thread ); |
---|
123 | |
---|
124 | /**************************************************************************************** |
---|
125 | * This function saves in the thread uzone the FPU registers values. |
---|
126 | **************************************************************************************** |
---|
127 | * @ thread : pointer on the thread descriptor. |
---|
128 | ***************************************************************************************/ |
---|
129 | void hal_fpu_context_save( struct thread_s * thread ); |
---|
130 | |
---|
131 | /**************************************************************************************** |
---|
132 | * This function restores from the thread uzone the FPU registers values. |
---|
133 | **************************************************************************************** |
---|
134 | * @ thread : pointer on the thread descriptor. |
---|
135 | ***************************************************************************************/ |
---|
136 | void hal_fpu_context_restore( struct thread_s * thread ); |
---|
137 | |
---|
138 | #endif /* _HAL_CONTEXT_H_ */ |
---|