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

Last change on this file since 407 was 407, checked in by alain, 6 years ago

First implementation of fork/exec.

File size: 6.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 memory for a CPU context and links it to the thread
43 * identified by the <thread> argument. The context is not initialised.
44 ****************************************************************************************
45 * @ return 0 if success / return -1 if failure.
46 ***************************************************************************************/
47error_t hal_cpu_context_alloc( struct thread_s * thread );
48
49/****************************************************************************************
50 * This function allocates memory for a CPU context, initialize it from scratch,
51 * and links it to the thread identified by the <thread> argument.
52 ****************************************************************************************
53 * @ thread  : pointer on the thread descriptor.
54 * @ return 0 if success / return -1 if failure.
55 ***************************************************************************************/
56error_t hal_cpu_context_create( struct thread_s * thread );
57
58/****************************************************************************************
59 * This function display the following slots of a thread CPU context:
60 * - GPR : gp_28 , sp_29 , ra_31
61 * - CP0 : c0_sr , c0_th , c0_epc
62 * - CP2 : c2_ptpr , c2-mode
63 ****************************************************************************************
64 * @ thread  : local pointer on the thread descriptor.
65 ***************************************************************************************/
66void hal_cpu_context_display( struct thread_s * thread );
67
68/****************************************************************************************
69 * This function releases the physical memory allocated for a thread CPU context.
70 ****************************************************************************************
71 * @ thread  : pointer on the thread descriptor.
72 ***************************************************************************************/
73void hal_cpu_context_destroy( struct thread_s * thread );
74
75
76
77
78
79
80
81/****************************************************************************************
82 * This function allocates memory for a FPU context, reset all entries,
83 * and links it to the thread identified by the <thread> argument.
84 ****************************************************************************************
85 * @ thread  : pointer on the thread descriptor.
86 * @ return 0 if success / return -1 if failure.
87 ***************************************************************************************/
88error_t hal_fpu_context_alloc( struct thread_s * thread );
89
90/****************************************************************************************
91 * This function copies a FPU context defined by the <src> argument to the FPU context
92 * defined by the <dst> argument. It is used by the fork system call.
93 ****************************************************************************************
94 * @ dst  : pointer on the destination thread descriptor.
95 * @ src  : pointer on the source thread descriptor.
96 ***************************************************************************************/
97void hal_fpu_context_copy( struct thread_s * dst,
98                           struct thread_s * src );
99
100/****************************************************************************************
101 * This function releases the physical memory allocated for a FPU context.
102 ****************************************************************************************
103 * @ thread  : pointer on the thread descriptor.
104 ***************************************************************************************/
105void hal_fpu_context_destroy( struct thread_s * thread );
106
107/****************************************************************************************
108 * This function saves in the thread uzone the FPU registers values.
109 ****************************************************************************************
110 * @ thread  : pointer on the thread descriptor.
111 ***************************************************************************************/
112void hal_fpu_context_save( struct thread_s * thread );
113
114/****************************************************************************************
115 * This function restores from the thread uzone the FPU registers values.
116 ****************************************************************************************
117 * @ thread  : pointer on the thread descriptor.
118 ***************************************************************************************/
119void hal_fpu_context_restore( struct thread_s * thread );
120
121#endif  /* _HAL_CONTEXT_H_ */
Note: See TracBrowser for help on using the repository browser.