source: trunk/hal/generic/hal_context.h @ 396

Last change on this file since 396 was 337, checked in by alain, 7 years ago

Introduce the delayed context switch if current thread has a lock.

File size: 7.2 KB
Line 
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" struct is used for the CPU registers values at context switch.
34// - the "hal_fpu_context_t" struct is used for the FPU registers when required.
35//////////////////////////////////////////////////////////////////////////////////////////
36
37/**** Forward declarations ****/
38
39struct thread_s;
40
41/****************************************************************************************
42 * This function allocates, from the local cluster, the physical memory required for
43 * the thread CPU context, initialises it, and links the context to the thread.
44 ****************************************************************************************
45 * @ thread  : pointer on the thread descriptor.
46 * @ return 0 if success / return ENOMEM if error
47 ***************************************************************************************/
48error_t hal_cpu_context_create( struct thread_s * thread );
49
50/****************************************************************************************
51 * This function allocates, from the local cluster, the physical memory required for
52 * a thread CPU context, initialises it from values contained in "src" thread context,
53 * and links the context to the "dst" thread.
54 ****************************************************************************************
55 * @ dst  : pointer on the destination thread descriptor.
56 * @ src  : pointer on the source thread descriptor.
57 * @ return 0 if success / return ENOMEM if error
58 ***************************************************************************************/
59error_t hal_cpu_context_copy( struct thread_s * dst,
60                              struct thread_s * src );
61
62/****************************************************************************************
63 * This function releases the physical memory allocated for a thread CPU context.
64 ****************************************************************************************
65 * @ thread  : pointer on the thread descriptor.
66 ***************************************************************************************/
67void hal_cpu_context_destroy( struct thread_s * thread );
68
69/****************************************************************************************
70 * This function performs a context switch, saving the CPU register values into the
71 * old thread, and initializing these registers with the values of the new thread.
72 ****************************************************************************************
73 * @ old     : pointer on current thread.
74 * @ new     : pointer on the thread we want to switch to.
75 ***************************************************************************************/
76void hal_cpu_context_switch( struct thread_s * old , struct thread_s * new );
77
78/****************************************************************************************
79 * This function loads the relevant CPU registers from values contained in
80 * the thread context. It should be called for a thread that has not been executed yet.
81 * It reset the loadable flag in thread descriptor.
82 ****************************************************************************************
83 * @ thread  : pointer on the thread descriptor.
84 ***************************************************************************************/
85void hal_cpu_context_load( struct thread_s * thread );
86
87/****************************************************************************************
88 * This function allocates, from the local cluster, the physical memory required for
89 * the thread FPU context, and initialises the thread pointer.
90 ****************************************************************************************
91 * @ thread  : pointer on the thread descriptor.
92 * @ return 0 if success / return ENOMEM if error
93 ***************************************************************************************/
94error_t hal_fpu_context_create( struct thread_s * thread );
95
96/****************************************************************************************
97 * This function allocates, from the local cluster, the physical memory required for
98 * a thread FPU context, initialises it from values contained in "src" thread context,
99 * and link the context to the "dst" thread.
100 ****************************************************************************************
101 * @ dst  : pointer on the destination thread descriptor.
102 * @ src  : pointer on the source thread descriptor.
103 * @ return 0 if success / return ENOMEM if error
104 ***************************************************************************************/
105error_t hal_fpu_context_copy( struct thread_s * dst,
106                           struct thread_s * src );
107
108/****************************************************************************************
109 * This function releases the physical memory allocated for a FPU context.
110 ****************************************************************************************
111 * @ thread  : pointer on the thread descriptor.
112 ***************************************************************************************/
113void hal_fpu_context_destroy( struct thread_s * thread );
114
115/****************************************************************************************
116 * This function saves in the thread uzone the FPU registers values.
117 ****************************************************************************************
118 * @ thread  : pointer on the thread descriptor.
119 ***************************************************************************************/
120void hal_fpu_context_save( struct thread_s * thread );
121
122/****************************************************************************************
123 * This function restores from the thread uzone the FPU registers values.
124 ****************************************************************************************
125 * @ thread  : pointer on the thread descriptor.
126 ***************************************************************************************/
127void hal_fpu_context_restore( struct thread_s * thread );
128
129#endif  /* _HAL_CONTEXT_H_ */
Note: See TracBrowser for help on using the repository browser.