[25] | 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> |
---|
| 25 | #include <memcpy.h> |
---|
| 26 | #include <thread.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include <process.h> |
---|
| 29 | #include <printk.h> |
---|
| 30 | #include <vmm.h> |
---|
| 31 | #include <core.h> |
---|
| 32 | #include <cluster.h> |
---|
| 33 | |
---|
| 34 | #include <hal_context.h> |
---|
[193] | 35 | #include <hal_kentry.h> |
---|
[48] | 36 | #include <hal_internal.h> |
---|
[193] | 37 | #include <hal_segmentation.h> |
---|
[48] | 38 | |
---|
[193] | 39 | error_t hal_cpu_context_create(struct thread_s *thread) |
---|
[25] | 40 | { |
---|
[193] | 41 | hal_cpu_context_t *context; |
---|
| 42 | kmem_req_t req; |
---|
| 43 | |
---|
| 44 | /* allocate memory for cpu_context */ |
---|
| 45 | req.type = KMEM_CPU_CTX; |
---|
| 46 | req.size = sizeof(hal_cpu_context_t); |
---|
| 47 | req.flags = AF_KERNEL | AF_ZERO; |
---|
| 48 | |
---|
| 49 | context = (hal_cpu_context_t *)kmem_alloc(&req); |
---|
| 50 | if (context == NULL) |
---|
| 51 | return ENOMEM; |
---|
| 52 | |
---|
| 53 | /* set cpu context pointer in thread */ |
---|
| 54 | thread->cpu_context = (void*)context; |
---|
| 55 | |
---|
| 56 | /* build the context */ |
---|
| 57 | /* tf_gs */ |
---|
| 58 | /* tf_fs */ |
---|
| 59 | context->tf_es = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); |
---|
| 60 | context->tf_ds = GDT_FIXED_SEL(GDT_UDATA_SEL, SEL_UPL); |
---|
| 61 | context->tf_rip = (uint64_t)thread->entry_func; |
---|
| 62 | context->tf_rflags = PSL_USERSET; |
---|
| 63 | |
---|
| 64 | if (thread->type == THREAD_USER) { |
---|
| 65 | context->tf_cs = GDT_FIXED_SEL(GDT_UCODE_SEL, SEL_UPL); |
---|
| 66 | context->tf_rsp = ((uint64_t)thread->u_stack_base) + |
---|
| 67 | thread->u_stack_size; |
---|
| 68 | } else { |
---|
| 69 | context->tf_cs = GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL); |
---|
| 70 | context->tf_rsp = ((uint64_t)thread->k_stack_base) + |
---|
| 71 | thread->k_stack_size; |
---|
| 72 | } |
---|
| 73 | |
---|
[48] | 74 | return 0; |
---|
[25] | 75 | } |
---|
| 76 | |
---|
| 77 | error_t hal_cpu_context_copy( thread_t * dst, |
---|
| 78 | thread_t * src ) |
---|
| 79 | { |
---|
[48] | 80 | x86_panic((char *)__func__); |
---|
| 81 | return 0; |
---|
[25] | 82 | } |
---|
| 83 | |
---|
| 84 | void hal_cpu_context_destroy( thread_t * thread ) |
---|
| 85 | { |
---|
[48] | 86 | x86_panic((char *)__func__); |
---|
[25] | 87 | } |
---|
| 88 | |
---|
| 89 | error_t hal_fpu_context_create( thread_t * thread ) |
---|
| 90 | { |
---|
[48] | 91 | x86_panic((char *)__func__); |
---|
| 92 | return 0; |
---|
[25] | 93 | } |
---|
| 94 | |
---|
| 95 | error_t hal_fpu_context_copy( thread_t * dst, |
---|
| 96 | thread_t * src ) |
---|
| 97 | { |
---|
[48] | 98 | x86_panic((char *)__func__); |
---|
| 99 | return 0; |
---|
[25] | 100 | } |
---|
| 101 | |
---|
| 102 | void hal_fpu_context_destroy( thread_t * thread ) |
---|
| 103 | { |
---|
[48] | 104 | x86_panic((char *)__func__); |
---|
[25] | 105 | } |
---|
| 106 | |
---|
| 107 | void hal_cpu_context_save( thread_t * thread ) |
---|
| 108 | { |
---|
[48] | 109 | x86_panic((char *)__func__); |
---|
| 110 | } |
---|
[25] | 111 | |
---|
| 112 | void hal_cpu_context_restore( thread_t * thread ) |
---|
| 113 | { |
---|
[48] | 114 | x86_panic((char *)__func__); |
---|
[25] | 115 | } |
---|
| 116 | |
---|
| 117 | void hal_cpu_context_load( thread_t * thread ) |
---|
| 118 | { |
---|
[48] | 119 | x86_panic((char *)__func__); |
---|
[25] | 120 | } |
---|
| 121 | |
---|
| 122 | void hal_fpu_context_save( thread_t * thread ) |
---|
| 123 | { |
---|
[48] | 124 | x86_panic((char *)__func__); |
---|
[25] | 125 | } |
---|
| 126 | |
---|
| 127 | void hal_fpu_context_restore( thread_t * thread ) |
---|
| 128 | { |
---|
[48] | 129 | x86_panic((char *)__func__); |
---|
[25] | 130 | } |
---|
| 131 | |
---|
| 132 | void hal_fpu_context_dup( xptr_t dst, |
---|
| 133 | xptr_t src ) |
---|
| 134 | { |
---|
[48] | 135 | x86_panic((char *)__func__); |
---|
[25] | 136 | } |
---|
| 137 | |
---|