[25] | 1 | /* |
---|
[46] | 2 | * hal_special.c - implementation of TLS API for x86_64 |
---|
[71] | 3 | * |
---|
[46] | 4 | * Copyright (c) 2017 Maxime Villard |
---|
[71] | 5 | * |
---|
[46] | 6 | * This file is part of ALMOS-MKH. |
---|
[25] | 7 | * |
---|
[46] | 8 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[25] | 9 | * under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 11 | * |
---|
[46] | 12 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[25] | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | * General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include <hal_types.h> |
---|
[82] | 23 | #include <hal_apic.h> |
---|
[25] | 24 | #include <hal_special.h> |
---|
[46] | 25 | #include <hal_register.h> |
---|
| 26 | #include <hal_internal.h> |
---|
[167] | 27 | #include <hal_segmentation.h> |
---|
[25] | 28 | |
---|
[102] | 29 | #include <core.h> |
---|
| 30 | #include <thread.h> |
---|
| 31 | |
---|
[25] | 32 | struct thread_s; |
---|
| 33 | |
---|
[167] | 34 | tls_t cpu0 __in_kdata; |
---|
[46] | 35 | |
---|
[167] | 36 | tls_t *curcpu() |
---|
[46] | 37 | { |
---|
[167] | 38 | tls_t *cputls; |
---|
[46] | 39 | |
---|
| 40 | __asm volatile("movq %%gs:%1, %0" : |
---|
[167] | 41 | "=r" (cputls) : |
---|
[46] | 42 | "m" |
---|
[167] | 43 | (*(tls_t * const *)offsetof(tls_t, tls_self))); |
---|
| 44 | return cputls; |
---|
[46] | 45 | } |
---|
| 46 | |
---|
[25] | 47 | gid_t hal_get_gid() |
---|
| 48 | { |
---|
[167] | 49 | return curcpu()->tls_gid; |
---|
[25] | 50 | } |
---|
| 51 | |
---|
[125] | 52 | cycle_t hal_time_stamp() |
---|
| 53 | { |
---|
| 54 | return rdtsc(); |
---|
| 55 | } |
---|
| 56 | |
---|
[102] | 57 | uint64_t hal_get_cycles() |
---|
[25] | 58 | { |
---|
[102] | 59 | uint64_t cycles; |
---|
| 60 | core_t *core = CURRENT_THREAD->core; |
---|
| 61 | |
---|
| 62 | /* |
---|
| 63 | * Put the value of the TSC everywhere |
---|
| 64 | */ |
---|
| 65 | cycles = rdtsc(); |
---|
| 66 | core->time_stamp = cycles; |
---|
| 67 | core->cycles = cycles; |
---|
| 68 | |
---|
| 69 | return cycles; |
---|
[25] | 70 | } |
---|
| 71 | |
---|
[102] | 72 | struct thread_s *hal_get_current_thread() |
---|
[25] | 73 | { |
---|
[167] | 74 | return curcpu()->tls_thr; |
---|
[25] | 75 | } |
---|
| 76 | |
---|
| 77 | void hal_set_current_thread( struct thread_s * thread ) |
---|
[71] | 78 | { |
---|
[167] | 79 | curcpu()->tls_thr = thread; |
---|
[25] | 80 | } |
---|
| 81 | |
---|
[46] | 82 | /* -------------------------------------------------------------------------- */ |
---|
| 83 | |
---|
[25] | 84 | void hal_fpu_enable() |
---|
| 85 | { |
---|
[46] | 86 | x86_panic((char *)__func__); |
---|
[25] | 87 | } |
---|
| 88 | |
---|
| 89 | void hal_fpu_disable() |
---|
| 90 | { |
---|
[46] | 91 | x86_panic((char *)__func__); |
---|
[25] | 92 | } |
---|
| 93 | |
---|
| 94 | uint32_t hal_get_stack() |
---|
| 95 | { |
---|
[46] | 96 | x86_panic((char *)__func__); |
---|
[25] | 97 | return 0; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | uint32_t hal_set_stack( void * new_val ) |
---|
| 101 | { |
---|
[46] | 102 | x86_panic((char *)__func__); |
---|
[25] | 103 | return 0; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | uint32_t hal_get_bad_vaddr() |
---|
| 107 | { |
---|
[46] | 108 | x86_panic((char *)__func__); |
---|
[25] | 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | uint32_t hal_uncached_read( uint32_t * ptr ) |
---|
| 113 | { |
---|
[46] | 114 | x86_panic((char *)__func__); |
---|
[25] | 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void hal_invalid_dcache_line( void * ptr ) |
---|
| 119 | { |
---|
[46] | 120 | x86_panic((char *)__func__); |
---|
[25] | 121 | } |
---|
| 122 | |
---|
[124] | 123 | void hal_fence() |
---|
[25] | 124 | { |
---|
[125] | 125 | mfence(); |
---|
[25] | 126 | } |
---|
| 127 | |
---|
| 128 | void hal_rdbar() |
---|
| 129 | { |
---|
[46] | 130 | x86_panic((char *)__func__); |
---|
[25] | 131 | } |
---|
| 132 | |
---|
| 133 | void hal_core_sleep() |
---|
| 134 | { |
---|
[46] | 135 | x86_panic((char *)__func__); |
---|
[25] | 136 | } |
---|
| 137 | |
---|
| 138 | void hal_fixed_delay( uint32_t delay ) |
---|
[71] | 139 | { |
---|
[46] | 140 | x86_panic((char *)__func__); |
---|
[25] | 141 | } |
---|
| 142 | |
---|
| 143 | void hal_get_mmu_excp( intptr_t * mmu_ins_excp_code, |
---|
| 144 | intptr_t * mmu_ins_bad_vaddr, |
---|
| 145 | intptr_t * mmu_dat_excp_code, |
---|
| 146 | intptr_t * mmu_dat_bad_vaddr ) |
---|
| 147 | { |
---|
[46] | 148 | x86_panic((char *)__func__); |
---|
[25] | 149 | } |
---|