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

Last change on this file since 177 was 151, checked in by alain, 7 years ago

Move the core specific hal_cpu_context_t & hafpu_context_t structures
from the igeneric hal_context.h file to the specific hal_context.c file.

File size: 8.0 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" structure is used to store the CPU registers values that
34//   have not been saved in the 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
40struct 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 * Seven registers are initialised:
46 * - sp_29 / fp_30 / ra_31
47 * - c0_sr / c0_th
48 * - c2_ptpr / c2_mode
49 ****************************************************************************************
50 * @ thread  : pointer on the thread descriptor.
51 * @ return 0 if success / return ENOMEM if error
52 ***************************************************************************************/
53error_t hal_cpu_context_create( struct thread_s * thread );
54
55/****************************************************************************************
56 * This function allocates, from the local cluster, the physical memory required for
57 * a thread CPU context, initialises it from values contained in "src" thread context,
58 * and links the context to the "dst" thread.
59 ****************************************************************************************
60 * @ dst  : pointer on the destination thread descriptor.
61 * @ src  : pointer on the source thread descriptor.
62 * @ return 0 if success / return ENOMEM if error
63 ***************************************************************************************/
64error_t hal_cpu_context_copy( struct thread_s * dst,
65                              struct thread_s * src );
66
67/****************************************************************************************
68 * This function releases the physical memory allocated for a thread CPU context.
69 ****************************************************************************************
70 * @ thread  : pointer on the thread descriptor.
71 ***************************************************************************************/
72void hal_cpu_context_destroy( struct thread_s * thread );
73
74/****************************************************************************************
75 * This function saves in the thread context the CPU registers values that have not
76 * been saved in the thread stack by the exception handler:
77 * - GRs : s0 to S7 , sp , fp, ra
78 * - CP0 : th
79 * - CP2 : ptpr , mode
80 ****************************************************************************************
81 * @ thread  : pointer on the thread descriptor.
82 ***************************************************************************************/
83void hal_cpu_context_save( struct thread_s * thread );
84
85/****************************************************************************************
86 * This function restores from the thread context the CPU registers values that have not
87 * been saved in the thread stack by the exception handler.
88 * - GRs : s0 to S7 , sp , fp, ra
89 * - CP0 : th
90 * - CP2 : ptpr , mode
91 ****************************************************************************************
92 * @ thread  : pointer on the thread descriptor.
93 ***************************************************************************************/
94void hal_cpu_context_restore( struct thread_s * thread );
95
96/****************************************************************************************
97 * This function loads the relevant CPU registers from values contained in
98 * the thread context. It should be called for a thread that has not been executed yet.
99 * - GRs : sp , fp , a0
100 * - CP0 : sr , epc , th
101 * - CP2 : ptpr , mode
102 * It reset the loadable flag in thread descriptor.
103 ****************************************************************************************
104 * @ thread  : pointer on the thread descriptor.
105 ***************************************************************************************/
106void hal_cpu_context_load( struct thread_s * thread );
107
108
109
110/****************************************************************************************
111 * This function allocates, from the local cluster, the physical memory required for
112 * the thread FPU context, and initialises the thread pointer.
113 ****************************************************************************************
114 * @ thread  : pointer on the thread descriptor.
115 * @ return 0 if success / return ENOMEM if error
116 ***************************************************************************************/
117error_t hal_fpu_context_create( struct thread_s * thread );
118
119/****************************************************************************************
120 * This function allocates, from the local cluster, the physical memory required for
121 * a thread FPU context, initialises it from values contained in "src" thread context,
122 * and link the context to the "dst" thread.
123 ****************************************************************************************
124 * @ dst  : pointer on the destination thread descriptor.
125 * @ src  : pointer on the source thread descriptor.
126 * @ return 0 if success / return ENOMEM if error
127 ***************************************************************************************/
128error_t hal_fpu_context_copy( struct thread_s * dst,
129                           struct thread_s * src );
130
131/****************************************************************************************
132 * This function releases the physical memory allocated for a FPU context.
133 ****************************************************************************************
134 * @ thread  : pointer on the thread descriptor.
135 ***************************************************************************************/
136void hal_fpu_context_destroy( struct thread_s * thread );
137
138/****************************************************************************************
139 * This function saves in the thread uzone the FPU registers values.
140 ****************************************************************************************
141 * @ thread  : pointer on the thread descriptor.
142 ***************************************************************************************/
143void hal_fpu_context_save( struct thread_s * thread );
144
145/****************************************************************************************
146 * This function restores from the thread uzone the FPU registers values.
147 ****************************************************************************************
148 * @ thread  : pointer on the thread descriptor.
149 ***************************************************************************************/
150void hal_fpu_context_restore( struct thread_s * thread );
151
152#endif  /* _HAL_CONTEXT_H_ */
Note: See TracBrowser for help on using the repository browser.