[1] | 1 | /* |
---|
| 2 | * hal_context.c - implementation of Thread Context API for TSAR-MIPS32 |
---|
| 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 | #include <hal_types.h> |
---|
[317] | 25 | #include <hal_switch.h> |
---|
[1] | 26 | #include <memcpy.h> |
---|
| 27 | #include <thread.h> |
---|
| 28 | #include <string.h> |
---|
| 29 | #include <process.h> |
---|
[8] | 30 | #include <printk.h> |
---|
[1] | 31 | #include <vmm.h> |
---|
| 32 | #include <core.h> |
---|
| 33 | #include <cluster.h> |
---|
| 34 | #include <hal_context.h> |
---|
[406] | 35 | #include <hal_kentry.h> |
---|
[1] | 36 | |
---|
[151] | 37 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[408] | 38 | // Define various SR initialisation values for TSAR-MIPS32 |
---|
[151] | 39 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | |
---|
[408] | 41 | #define SR_USR_MODE 0x0000FF13 |
---|
| 42 | #define SR_USR_MODE_FPU 0x2000FF13 |
---|
| 43 | #define SR_SYS_MODE 0x0000FF00 |
---|
[151] | 44 | |
---|
| 45 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 46 | // This structure defines the CPU context for TSAR MIPS32. |
---|
| 47 | // The following registers are saved/restored at each context switch: |
---|
| 48 | // - GPR : all, but (zero, k0, k1), plus (hi, lo) |
---|
| 49 | // - CP0 : c0_th , c0_sr , C0_epc |
---|
| 50 | // - CP2 : c2_ptpr , C2_mode |
---|
| 51 | // |
---|
[406] | 52 | // WARNING : check the two CONFIG_CPU_CTX_SIZE & CONFIG_FPU_CTX_SIZE configuration |
---|
| 53 | // parameterss when modifying this structure. |
---|
[151] | 54 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 55 | |
---|
| 56 | typedef struct hal_cpu_context_s |
---|
| 57 | { |
---|
[296] | 58 | uint32_t c0_epc; // slot 0 |
---|
| 59 | uint32_t at_01; // slot 1 |
---|
| 60 | uint32_t v0_02; // slot 2 |
---|
| 61 | uint32_t v1_03; // slot 3 |
---|
| 62 | uint32_t a0_04; // slot 4 |
---|
| 63 | uint32_t a1_05; // slot 5 |
---|
| 64 | uint32_t a2_06; // slot 6 |
---|
| 65 | uint32_t a3_07; // slot 7 |
---|
| 66 | |
---|
| 67 | uint32_t t0_08; // slot 8 |
---|
| 68 | uint32_t t1_09; // slot 9 |
---|
| 69 | uint32_t t2_10; // slot 10 |
---|
| 70 | uint32_t t3_11; // slot 11 |
---|
| 71 | uint32_t t4_12; // slot 12 |
---|
| 72 | uint32_t t5_13; // slot 13 |
---|
| 73 | uint32_t t6_14; // slot 14 |
---|
| 74 | uint32_t t7_15; // slot 15 |
---|
| 75 | |
---|
| 76 | uint32_t s0_16; // slot 16 |
---|
| 77 | uint32_t s1_17; // slot 17 |
---|
| 78 | uint32_t s2_18; // slot 18 |
---|
| 79 | uint32_t s3_19; // slot 19 |
---|
| 80 | uint32_t s4_20; // slot 20 |
---|
| 81 | uint32_t s5_21; // slot 21 |
---|
| 82 | uint32_t s6_22; // slot 22 |
---|
| 83 | uint32_t s7_23; // slot 23 |
---|
| 84 | |
---|
| 85 | uint32_t t8_24; // slot 24 |
---|
[406] | 86 | uint32_t t9_25; // slot 25 |
---|
[296] | 87 | uint32_t hi_26; // slot 26 |
---|
| 88 | uint32_t lo_27; // slot 27 |
---|
| 89 | uint32_t gp_28; // slot 28 |
---|
| 90 | uint32_t sp_29; // slot 29 |
---|
[407] | 91 | uint32_t s8_30; // slot 30 |
---|
[296] | 92 | uint32_t ra_31; // slot 31 |
---|
| 93 | |
---|
| 94 | uint32_t c2_ptpr; // slot 32 |
---|
| 95 | uint32_t c2_mode; // slot 33 |
---|
| 96 | |
---|
| 97 | uint32_t c0_sr; // slot 34 |
---|
| 98 | uint32_t c0_th; // slot 35 |
---|
[151] | 99 | } |
---|
| 100 | hal_cpu_context_t; |
---|
| 101 | |
---|
| 102 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 103 | // This structure defines the fpu_context for TSAR MIPS32. |
---|
| 104 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 105 | |
---|
| 106 | typedef struct hal_fpu_context_s |
---|
| 107 | { |
---|
| 108 | uint32_t fpu_regs[32]; |
---|
| 109 | } |
---|
| 110 | hal_fpu_context_t; |
---|
| 111 | |
---|
[296] | 112 | |
---|
| 113 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[407] | 114 | // CPU context related functions |
---|
[296] | 115 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 116 | |
---|
[407] | 117 | |
---|
| 118 | ////////////////////////////////////////////////// |
---|
| 119 | error_t hal_cpu_context_alloc( thread_t * thread ) |
---|
[1] | 120 | { |
---|
[406] | 121 | assert( (sizeof(hal_cpu_context_t) <= CONFIG_CPU_CTX_SIZE) , __FUNCTION__ , |
---|
[407] | 122 | "illegal CPU context size" ); |
---|
[406] | 123 | |
---|
[1] | 124 | // allocate memory for cpu_context |
---|
[407] | 125 | kmem_req_t req; |
---|
[8] | 126 | req.type = KMEM_CPU_CTX; |
---|
[1] | 127 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 128 | |
---|
| 129 | hal_cpu_context_t * context = (hal_cpu_context_t *)kmem_alloc( &req ); |
---|
[407] | 130 | if( context == NULL ) return -1; |
---|
[1] | 131 | |
---|
[407] | 132 | // link to thread |
---|
| 133 | thread->cpu_context = (void *)context; |
---|
| 134 | return 0; |
---|
[1] | 135 | |
---|
[407] | 136 | } // end hal_cpu_context_alloc() |
---|
| 137 | |
---|
| 138 | /////////////////////////////////////////////////// |
---|
| 139 | // The following context slots are initialised : |
---|
| 140 | // GPR : a0_04 / sp_29 / ra_31 |
---|
| 141 | // CP0 : c0_sr / c0_th / c0_epc |
---|
| 142 | // CP2 : c2_ptpr / c2_mode |
---|
| 143 | /////////////////////////////////////////////////// |
---|
| 144 | error_t hal_cpu_context_create( thread_t * thread ) |
---|
| 145 | { |
---|
| 146 | // allocate memory for a CPU context |
---|
| 147 | error_t error = hal_cpu_context_alloc( thread ); |
---|
| 148 | |
---|
| 149 | if( error ) return error; |
---|
| 150 | |
---|
| 151 | hal_cpu_context_t * context = (hal_cpu_context_t *)thread->cpu_context; |
---|
| 152 | |
---|
| 153 | // initialisation depends on thread type |
---|
[1] | 154 | if( thread->type == THREAD_USER ) |
---|
| 155 | { |
---|
[407] | 156 | context->a0_04 = (uint32_t)thread->entry_args; |
---|
| 157 | context->sp_29 = (uint32_t)thread->u_stack_base + (uint32_t)thread->u_stack_size - 8; |
---|
| 158 | context->ra_31 = (uint32_t)&hal_kentry_eret; |
---|
| 159 | context->c0_epc = (uint32_t)thread->entry_func; |
---|
| 160 | context->c0_sr = SR_USR_MODE; |
---|
| 161 | context->c0_th = (uint32_t)thread; |
---|
| 162 | context->c2_ptpr = (uint32_t)((thread->process->vmm.gpt.ppn) >> 1); |
---|
| 163 | context->c2_mode = 0xF; |
---|
[1] | 164 | } |
---|
[407] | 165 | else // kernel thread |
---|
[1] | 166 | { |
---|
[407] | 167 | context->a0_04 = (uint32_t)thread->entry_args; |
---|
| 168 | context->sp_29 = (uint32_t)thread->k_stack_base + (uint32_t)thread->k_stack_size - 8; |
---|
| 169 | context->ra_31 = (uint32_t)thread->entry_func; |
---|
| 170 | context->c0_sr = SR_SYS_MODE; |
---|
| 171 | context->c0_th = (uint32_t)thread; |
---|
| 172 | context->c2_ptpr = (uint32_t)((thread->process->vmm.gpt.ppn) >> 1); |
---|
| 173 | context->c2_mode = 0x3; |
---|
[1] | 174 | } |
---|
| 175 | |
---|
[407] | 176 | context_dmsg("\n[DBG] %s : thread %x in process %x\n" |
---|
[406] | 177 | " - a0 = %x\n" |
---|
| 178 | " - sp = %x\n" |
---|
| 179 | " - ra = %x\n" |
---|
| 180 | " - sr = %x\n" |
---|
| 181 | " - th = %x\n" |
---|
| 182 | " - epc = %x\n" |
---|
| 183 | " - ptpr = %x\n" |
---|
| 184 | " - mode = %x\n", |
---|
| 185 | __FUNCTION__ , thread->trdid , thread->process->pid, |
---|
[407] | 186 | context->a0_04, context->sp_29, context->ra_31, |
---|
[406] | 187 | context->c0_sr, context->c0_th, context->c0_epc, |
---|
| 188 | context->c2_ptpr, context->c2_mode ); |
---|
| 189 | return 0; |
---|
[8] | 190 | |
---|
[1] | 191 | } // end hal_cpu_context_create() |
---|
| 192 | |
---|
[408] | 193 | //////////////////////////////////////////// |
---|
| 194 | void hal_cpu_context_fork( xptr_t child_xp ) |
---|
| 195 | { |
---|
| 196 | // allocate a local CPU context in kernel stack |
---|
| 197 | // It is initialized from local parent context |
---|
| 198 | // and from child specific values, and is copied in |
---|
| 199 | // in the remote child context using a remote_memcpy() |
---|
| 200 | hal_cpu_context_t context; |
---|
| 201 | |
---|
| 202 | // get local parent thread local pointer |
---|
| 203 | thread_t * parent_ptr = CURRENT_THREAD; |
---|
| 204 | |
---|
| 205 | // get remote child thread cluster and local pointer |
---|
| 206 | cxy_t child_cxy = GET_CXY( child_xp ); |
---|
| 207 | thread_t * child_ptr = (thread_t *)GET_PTR( child_xp ); |
---|
| 208 | |
---|
| 209 | // get remote child cpu_context local pointer |
---|
| 210 | char * child_context_ptr = hal_remote_lpt( XPTR(child_cxy , &child_ptr->cpu_context) ); |
---|
| 211 | |
---|
| 212 | // get local pointer on remote child process |
---|
| 213 | process_t * process = (process_t *)hal_remote_lpt( XPTR(child_cxy , &child_ptr->process) ); |
---|
| 214 | |
---|
| 215 | // get ppn of remote child process page table |
---|
| 216 | uint32_t pt_ppn = hal_remote_lw( XPTR(child_cxy , &process->vmm.gpt.ppn) ); |
---|
| 217 | |
---|
| 218 | // save CPU registers in local CPU context |
---|
| 219 | hal_do_cpu_save( &context ); |
---|
| 220 | |
---|
| 221 | // From this point, both parent and child threads execute the following code. |
---|
| 222 | // They can be distinguished by the CURRENT_THREAD value, and child will only |
---|
| 223 | // execute it when it is unblocked by parent, after return to sys_fork(). |
---|
| 224 | // - parent thread copies user stack, and patch sp_29 / c0_th / C0_sr / c2_ptpr |
---|
| 225 | // - child thread does nothing |
---|
| 226 | |
---|
| 227 | thread_t * current = CURRENT_THREAD; |
---|
| 228 | |
---|
| 229 | if( current == parent_ptr ) // current == parent thread |
---|
| 230 | { |
---|
| 231 | // get parent and child stack pointers |
---|
| 232 | char * parent_sp = (char *)context.sp_29; |
---|
| 233 | char * child_sp = (char *)((intptr_t)parent_sp + |
---|
| 234 | (intptr_t)child_ptr - |
---|
| 235 | (intptr_t)parent_ptr ); |
---|
| 236 | |
---|
| 237 | // patch kernel_stack pointer, current thread, and status slots |
---|
| 238 | context.sp_29 = (uint32_t)child_sp; |
---|
| 239 | context.c0_th = (uint32_t)child_ptr; |
---|
| 240 | context.c0_sr = SR_SYS_MODE; |
---|
| 241 | context.c2_ptpr = pt_ppn >> 1; |
---|
| 242 | |
---|
| 243 | // copy local context to remote child context) |
---|
| 244 | hal_remote_memcpy( XPTR( child_cxy , child_context_ptr ), |
---|
| 245 | XPTR( local_cxy , &context ) , |
---|
| 246 | sizeof( hal_cpu_context_t ) ); |
---|
| 247 | |
---|
| 248 | // copy kernel stack content from local parent thread to remote child thread |
---|
| 249 | uint32_t size = (uint32_t)parent_ptr + CONFIG_THREAD_DESC_SIZE - (uint32_t)parent_sp; |
---|
| 250 | hal_remote_memcpy( XPTR( child_cxy , child_sp ), |
---|
| 251 | XPTR( local_cxy , parent_sp ), |
---|
| 252 | size ); |
---|
| 253 | } |
---|
| 254 | else // current == child thread |
---|
| 255 | { |
---|
| 256 | assert( (current == child_ptr) , __FUNCTION__ , "current = %x / child = %x\n"); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | } // end hal_cpu_context_fork() |
---|
| 260 | |
---|
[296] | 261 | ///////////////////////////////////////////////// |
---|
[408] | 262 | void hal_cpu_context_display( xptr_t thread_xp ) |
---|
[296] | 263 | { |
---|
[408] | 264 | hal_cpu_context_t * ctx; |
---|
[296] | 265 | |
---|
[408] | 266 | // get thread cluster and local pointer |
---|
| 267 | cxy_t cxy = GET_CXY( thread_xp ); |
---|
| 268 | thread_t * ptr = (thread_t *)GET_PTR( thread_xp ); |
---|
| 269 | |
---|
| 270 | // get context pointer |
---|
| 271 | ctx = (hal_cpu_context_t *)hal_remote_lpt( XPTR( cxy , &ptr->cpu_context ) ); |
---|
| 272 | |
---|
| 273 | // get relevant context slots values |
---|
| 274 | uint32_t sp_29 = hal_remote_lw( XPTR( cxy , &ctx->sp_29 ) ); |
---|
| 275 | uint32_t ra_31 = hal_remote_lw( XPTR( cxy , &ctx->ra_31 ) ); |
---|
| 276 | uint32_t c0_sr = hal_remote_lw( XPTR( cxy , &ctx->c0_sr ) ); |
---|
| 277 | uint32_t c0_epc = hal_remote_lw( XPTR( cxy , &ctx->c0_epc ) ); |
---|
| 278 | uint32_t c0_th = hal_remote_lw( XPTR( cxy , &ctx->c0_th ) ); |
---|
| 279 | uint32_t c2_ptpr = hal_remote_lw( XPTR( cxy , &ctx->c2_ptpr ) ); |
---|
| 280 | uint32_t c2_mode = hal_remote_lw( XPTR( cxy , &ctx->c2_mode ) ); |
---|
| 281 | |
---|
[406] | 282 | printk("\n***** CPU context for thread %x in process %x / cycle %d\n" |
---|
[408] | 283 | " sp_29 = %X ra_31 = %X\n" |
---|
[296] | 284 | " c0_sr = %X c0_epc = %X c0_th = %X\n" |
---|
| 285 | " c2_ptpr = %X c2_mode = %X\n", |
---|
[408] | 286 | ptr->trdid, ptr->process->pid, hal_time_stamp(), |
---|
| 287 | sp_29 , ra_31, |
---|
| 288 | c0_sr , c0_epc , c0_th, |
---|
| 289 | c2_ptpr , c2_mode ); |
---|
[296] | 290 | |
---|
[407] | 291 | } // end hal_cpu_context_display() |
---|
[317] | 292 | |
---|
[1] | 293 | ///////////////////////////////////////////////// |
---|
| 294 | void hal_cpu_context_destroy( thread_t * thread ) |
---|
| 295 | { |
---|
| 296 | kmem_req_t req; |
---|
| 297 | |
---|
[8] | 298 | req.type = KMEM_CPU_CTX; |
---|
[1] | 299 | req.ptr = thread->cpu_context; |
---|
| 300 | kmem_free( &req ); |
---|
| 301 | |
---|
| 302 | } // end hal_cpu_context_destroy() |
---|
| 303 | |
---|
[317] | 304 | |
---|
[407] | 305 | |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | ////////////////////////////////////////////////// |
---|
| 309 | error_t hal_fpu_context_alloc( thread_t * thread ) |
---|
[1] | 310 | { |
---|
[406] | 311 | assert( (sizeof(hal_fpu_context_t) <= CONFIG_FPU_CTX_SIZE) , __FUNCTION__ , |
---|
[407] | 312 | "illegal CPU context size" ); |
---|
[406] | 313 | |
---|
[407] | 314 | // allocate memory for fpu_context |
---|
| 315 | kmem_req_t req; |
---|
[8] | 316 | req.type = KMEM_FPU_CTX; |
---|
[1] | 317 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 318 | |
---|
| 319 | hal_fpu_context_t * context = (hal_fpu_context_t *)kmem_alloc( &req ); |
---|
[407] | 320 | if( context == NULL ) return -1; |
---|
[1] | 321 | |
---|
[407] | 322 | // link to thread |
---|
| 323 | thread->fpu_context = (void *)context; |
---|
[1] | 324 | return 0; |
---|
| 325 | |
---|
[407] | 326 | } // end hal_fpu_context_alloc() |
---|
| 327 | |
---|
| 328 | ////////////////////////////////////////// |
---|
| 329 | void hal_fpu_context_copy( thread_t * dst, |
---|
| 330 | thread_t * src ) |
---|
[1] | 331 | { |
---|
[407] | 332 | assert( (src != NULL) , __FUNCTION__ , "src thread pointer is NULL\n"); |
---|
| 333 | assert( (dst != NULL) , __FUNCTION__ , "dst thread pointer is NULL\n"); |
---|
[1] | 334 | |
---|
[407] | 335 | // get fpu context pointers |
---|
[1] | 336 | hal_fpu_context_t * src_context = src->fpu_context; |
---|
[407] | 337 | hal_fpu_context_t * dst_context = dst->fpu_context; |
---|
[1] | 338 | |
---|
| 339 | // copy CPU context from src to dst |
---|
| 340 | memcpy( dst_context , src_context , sizeof(hal_fpu_context_t) ); |
---|
| 341 | |
---|
| 342 | } // end hal_fpu_context_copy() |
---|
| 343 | |
---|
| 344 | ///////////////////////////////////////////////// |
---|
| 345 | void hal_fpu_context_destroy( thread_t * thread ) |
---|
| 346 | { |
---|
| 347 | kmem_req_t req; |
---|
| 348 | |
---|
[8] | 349 | req.type = KMEM_FPU_CTX; |
---|
[1] | 350 | req.ptr = thread->fpu_context; |
---|
| 351 | kmem_free( &req ); |
---|
| 352 | |
---|
| 353 | } // end hal_fpu_context_destroy() |
---|
| 354 | |
---|
| 355 | ////////////////////////////////////////////// |
---|
[408] | 356 | void hal_fpu_context_save( xptr_t thread_xp ) |
---|
[1] | 357 | { |
---|
[408] | 358 | // allocate a local FPU context in kernel stack |
---|
| 359 | hal_fpu_context_t context; |
---|
[1] | 360 | |
---|
[408] | 361 | // get remote child cluster and local pointer |
---|
| 362 | cxy_t thread_cxy = GET_CXY( thread_xp ); |
---|
| 363 | thread_t * thread_ptr = (thread_t *)GET_PTR( thread_xp ); |
---|
| 364 | |
---|
[1] | 365 | asm volatile( |
---|
| 366 | ".set noreorder \n" |
---|
| 367 | "swc1 $f0, 0*4(%0) \n" |
---|
| 368 | "swc1 $f1, 1*4(%0) \n" |
---|
| 369 | "swc1 $f2, 2*4(%0) \n" |
---|
| 370 | "swc1 $f3, 3*4(%0) \n" |
---|
| 371 | "swc1 $f4, 4*4(%0) \n" |
---|
| 372 | "swc1 $f5, 5*4(%0) \n" |
---|
| 373 | "swc1 $f6, 6*4(%0) \n" |
---|
| 374 | "swc1 $f7, 7*4(%0) \n" |
---|
| 375 | "swc1 $f8, 8*4(%0) \n" |
---|
| 376 | "swc1 $f9, 9*4(%0) \n" |
---|
| 377 | "swc1 $f10, 10*4(%0) \n" |
---|
| 378 | "swc1 $f11, 11*4(%0) \n" |
---|
| 379 | "swc1 $f12, 12*4(%0) \n" |
---|
| 380 | "swc1 $f13, 13*4(%0) \n" |
---|
| 381 | "swc1 $f14, 14*4(%0) \n" |
---|
| 382 | "swc1 $f15, 15*4(%0) \n" |
---|
| 383 | "swc1 $f16, 16*4(%0) \n" |
---|
| 384 | "swc1 $f17, 17*4(%0) \n" |
---|
| 385 | "swc1 $f18, 18*4(%0) \n" |
---|
| 386 | "swc1 $f19, 19*4(%0) \n" |
---|
| 387 | "swc1 $f20, 20*4(%0) \n" |
---|
| 388 | "swc1 $f21, 21*4(%0) \n" |
---|
| 389 | "swc1 $f22, 22*4(%0) \n" |
---|
| 390 | "swc1 $f23, 23*4(%0) \n" |
---|
| 391 | "swc1 $f24, 24*4(%0) \n" |
---|
| 392 | "swc1 $f25, 25*4(%0) \n" |
---|
| 393 | "swc1 $f26, 26*4(%0) \n" |
---|
| 394 | "swc1 $f27, 27*4(%0) \n" |
---|
| 395 | "swc1 $f28, 28*4(%0) \n" |
---|
| 396 | "swc1 $f29, 29*4(%0) \n" |
---|
| 397 | "swc1 $f30, 30*4(%0) \n" |
---|
| 398 | "swc1 $f31, 31*4(%0) \n" |
---|
| 399 | ".set reorder \n" |
---|
[408] | 400 | : : "r"(&context) ); |
---|
[1] | 401 | |
---|
[408] | 402 | // copy local context to remote child context) |
---|
| 403 | hal_remote_memcpy( XPTR( thread_cxy , &thread_ptr->fpu_context ), |
---|
| 404 | XPTR( local_cxy , &context ) , |
---|
| 405 | sizeof( hal_fpu_context_t ) ); |
---|
[1] | 406 | |
---|
[408] | 407 | } // end hal_fpu_context_save() |
---|
| 408 | |
---|
[1] | 409 | ///////////////////////////////////////////////// |
---|
| 410 | void hal_fpu_context_restore( thread_t * thread ) |
---|
| 411 | { |
---|
| 412 | uint32_t ctx = (uint32_t)thread->fpu_context; |
---|
| 413 | |
---|
| 414 | asm volatile( |
---|
| 415 | ".set noreorder \n" |
---|
| 416 | "lwc1 $f0, 0*4(%0) \n" |
---|
| 417 | "lwc1 $f1, 1*4(%0) \n" |
---|
| 418 | "lwc1 $f2, 2*4(%0) \n" |
---|
| 419 | "lwc1 $f3, 3*4(%0) \n" |
---|
| 420 | "lwc1 $f4, 4*4(%0) \n" |
---|
| 421 | "lwc1 $f5, 5*4(%0) \n" |
---|
| 422 | "lwc1 $f6, 6*4(%0) \n" |
---|
| 423 | "lwc1 $f7, 7*4(%0) \n" |
---|
| 424 | "lwc1 $f8, 8*4(%0) \n" |
---|
| 425 | "lwc1 $f9, 9*4(%0) \n" |
---|
| 426 | "lwc1 $f10, 10*4(%0) \n" |
---|
| 427 | "lwc1 $f11, 11*4(%0) \n" |
---|
| 428 | "lwc1 $f12, 12*4(%0) \n" |
---|
| 429 | "lwc1 $f13, 13*4(%0) \n" |
---|
| 430 | "lwc1 $f14, 14*4(%0) \n" |
---|
| 431 | "lwc1 $f15, 15*4(%0) \n" |
---|
| 432 | "lwc1 $f16, 16*4(%0) \n" |
---|
| 433 | "lwc1 $f17, 17*4(%0) \n" |
---|
| 434 | "lwc1 $f18, 18*4(%0) \n" |
---|
| 435 | "lwc1 $f19, 19*4(%0) \n" |
---|
| 436 | "lwc1 $f20, 20*4(%0) \n" |
---|
| 437 | "lwc1 $f21, 21*4(%0) \n" |
---|
| 438 | "lwc1 $f22, 22*4(%0) \n" |
---|
| 439 | "lwc1 $f23, 23*4(%0) \n" |
---|
| 440 | "lwc1 $f24, 24*4(%0) \n" |
---|
| 441 | "lwc1 $f25, 25*4(%0) \n" |
---|
| 442 | "lwc1 $f26, 26*4(%0) \n" |
---|
| 443 | "lwc1 $f27, 27*4(%0) \n" |
---|
| 444 | "lwc1 $f28, 28*4(%0) \n" |
---|
| 445 | "lwc1 $f29, 29*4(%0) \n" |
---|
| 446 | "lwc1 $f30, 30*4(%0) \n" |
---|
| 447 | "lwc1 $f31, 31*4(%0) \n" |
---|
| 448 | ".set reorder \n" |
---|
| 449 | : : "r"(ctx) ); |
---|
| 450 | |
---|
| 451 | } // end hal_cpu_context_restore() |
---|
| 452 | |
---|
| 453 | |
---|