| [1] | 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 | // |
|---|
| [151] | 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 |
|---|
| [1] | 32 | // void* pointers stored in the thread descriptor. |
|---|
| [337] | 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. |
|---|
| [1] | 35 | ////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 36 | |
|---|
| 37 | /**** Forward declarations ****/ |
|---|
| 38 | |
|---|
| 39 | struct thread_s; |
|---|
| 40 | |
|---|
| 41 | /**************************************************************************************** |
|---|
| 42 | * This function allocates, from the local cluster, the physical memory required for |
|---|
| [17] | 43 | * the thread CPU context, initialises it, and links the context to the thread. |
|---|
| [1] | 44 | **************************************************************************************** |
|---|
| 45 | * @ thread : pointer on the thread descriptor. |
|---|
| 46 | * @ return 0 if success / return ENOMEM if error |
|---|
| 47 | ***************************************************************************************/ |
|---|
| 48 | error_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, |
|---|
| [17] | 53 | * and links the context to the "dst" thread. |
|---|
| [1] | 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 | ***************************************************************************************/ |
|---|
| 59 | error_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 | ***************************************************************************************/ |
|---|
| 67 | void hal_cpu_context_destroy( struct thread_s * thread ); |
|---|
| 68 | |
|---|
| 69 | /**************************************************************************************** |
|---|
| [311] | 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. |
|---|
| [1] | 72 | **************************************************************************************** |
|---|
| [311] | 73 | * @ old : pointer on current thread. |
|---|
| 74 | * @ new : pointer on the thread we want to switch to. |
|---|
| [1] | 75 | ***************************************************************************************/ |
|---|
| [311] | 76 | void hal_cpu_context_switch( struct thread_s * old , struct thread_s * new ); |
|---|
| [1] | 77 | |
|---|
| 78 | /**************************************************************************************** |
|---|
| [17] | 79 | * This function loads the relevant CPU registers from values contained in |
|---|
| [1] | 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 | ***************************************************************************************/ |
|---|
| 85 | void 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 | ***************************************************************************************/ |
|---|
| 94 | error_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 | ***************************************************************************************/ |
|---|
| 105 | error_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 | ***************************************************************************************/ |
|---|
| 113 | void hal_fpu_context_destroy( struct thread_s * thread ); |
|---|
| 114 | |
|---|
| 115 | /**************************************************************************************** |
|---|
| [17] | 116 | * This function saves in the thread uzone the FPU registers values. |
|---|
| [1] | 117 | **************************************************************************************** |
|---|
| 118 | * @ thread : pointer on the thread descriptor. |
|---|
| 119 | ***************************************************************************************/ |
|---|
| 120 | void hal_fpu_context_save( struct thread_s * thread ); |
|---|
| 121 | |
|---|
| 122 | /**************************************************************************************** |
|---|
| [17] | 123 | * This function restores from the thread uzone the FPU registers values. |
|---|
| [1] | 124 | **************************************************************************************** |
|---|
| 125 | * @ thread : pointer on the thread descriptor. |
|---|
| 126 | ***************************************************************************************/ |
|---|
| 127 | void hal_fpu_context_restore( struct thread_s * thread ); |
|---|
| 128 | |
|---|
| 129 | #endif /* _HAL_CONTEXT_H_ */ |
|---|