[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 |
---|
[234] | 18 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[25] | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
[457] | 22 | #include <hal_kernel_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 | |
---|
[482] | 34 | tls_t *curtls( void ) |
---|
[46] | 35 | { |
---|
[167] | 36 | tls_t *cputls; |
---|
[46] | 37 | |
---|
| 38 | __asm volatile("movq %%gs:%1, %0" : |
---|
[167] | 39 | "=r" (cputls) : |
---|
[46] | 40 | "m" |
---|
[167] | 41 | (*(tls_t * const *)offsetof(tls_t, tls_self))); |
---|
| 42 | return cputls; |
---|
[46] | 43 | } |
---|
| 44 | |
---|
[482] | 45 | gid_t hal_get_gid( void ) |
---|
[25] | 46 | { |
---|
[336] | 47 | return curtls()->tls_gid; |
---|
[25] | 48 | } |
---|
| 49 | |
---|
[482] | 50 | cycle_t hal_time_stamp( void ) |
---|
[125] | 51 | { |
---|
| 52 | return rdtsc(); |
---|
| 53 | } |
---|
| 54 | |
---|
[482] | 55 | inline reg_t hal_get_sr( void ) |
---|
[280] | 56 | { |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
[482] | 60 | uint64_t hal_get_cycles( void ) |
---|
[25] | 61 | { |
---|
[102] | 62 | uint64_t cycles; |
---|
| 63 | core_t *core = CURRENT_THREAD->core; |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | * Put the value of the TSC everywhere |
---|
| 67 | */ |
---|
| 68 | cycles = rdtsc(); |
---|
| 69 | core->time_stamp = cycles; |
---|
| 70 | core->cycles = cycles; |
---|
| 71 | |
---|
| 72 | return cycles; |
---|
[25] | 73 | } |
---|
| 74 | |
---|
[482] | 75 | struct thread_s *hal_get_current_thread( void ) |
---|
[25] | 76 | { |
---|
[336] | 77 | return curtls()->tls_thr; |
---|
[25] | 78 | } |
---|
| 79 | |
---|
| 80 | void hal_set_current_thread( struct thread_s * thread ) |
---|
[71] | 81 | { |
---|
[336] | 82 | curtls()->tls_thr = thread; |
---|
[25] | 83 | } |
---|
| 84 | |
---|
[46] | 85 | /* -------------------------------------------------------------------------- */ |
---|
| 86 | |
---|
[482] | 87 | void hal_fpu_enable( void ) |
---|
[25] | 88 | { |
---|
[368] | 89 | /* FPU not implemented yet */ |
---|
| 90 | return; |
---|
[309] | 91 | clts(); |
---|
[25] | 92 | } |
---|
| 93 | |
---|
[482] | 94 | void hal_fpu_disable( void ) |
---|
[25] | 95 | { |
---|
[368] | 96 | /* FPU not implemented yet */ |
---|
| 97 | return; |
---|
[309] | 98 | stts(); |
---|
[25] | 99 | } |
---|
| 100 | |
---|
[482] | 101 | uint32_t hal_get_stack( void ) |
---|
[25] | 102 | { |
---|
[46] | 103 | x86_panic((char *)__func__); |
---|
[25] | 104 | return 0; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | uint32_t hal_set_stack( void * new_val ) |
---|
| 108 | { |
---|
[46] | 109 | x86_panic((char *)__func__); |
---|
[25] | 110 | return 0; |
---|
| 111 | } |
---|
| 112 | |
---|
[482] | 113 | uint32_t hal_get_bad_vaddr( void ) |
---|
[25] | 114 | { |
---|
[46] | 115 | x86_panic((char *)__func__); |
---|
[25] | 116 | return 0; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | uint32_t hal_uncached_read( uint32_t * ptr ) |
---|
| 120 | { |
---|
[46] | 121 | x86_panic((char *)__func__); |
---|
[25] | 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void hal_invalid_dcache_line( void * ptr ) |
---|
| 126 | { |
---|
[46] | 127 | x86_panic((char *)__func__); |
---|
[25] | 128 | } |
---|
| 129 | |
---|
[482] | 130 | void hal_fence( void ) |
---|
[25] | 131 | { |
---|
[125] | 132 | mfence(); |
---|
[25] | 133 | } |
---|
| 134 | |
---|
[482] | 135 | void hal_rdbar( void ) |
---|
[25] | 136 | { |
---|
[46] | 137 | x86_panic((char *)__func__); |
---|
[25] | 138 | } |
---|
| 139 | |
---|
[482] | 140 | void hal_core_sleep( void ) |
---|
[25] | 141 | { |
---|
[46] | 142 | x86_panic((char *)__func__); |
---|
[25] | 143 | } |
---|
| 144 | |
---|
| 145 | void hal_fixed_delay( uint32_t delay ) |
---|
[71] | 146 | { |
---|
[46] | 147 | x86_panic((char *)__func__); |
---|
[25] | 148 | } |
---|
| 149 | |
---|
[371] | 150 | void hal_get_mmu_excp(intptr_t *mmu_ins_excp_code, intptr_t *mmu_ins_bad_vaddr, |
---|
| 151 | intptr_t *mmu_dat_excp_code, intptr_t *mmu_dat_bad_vaddr) |
---|
[25] | 152 | { |
---|
[46] | 153 | x86_panic((char *)__func__); |
---|
[25] | 154 | } |
---|
[371] | 155 | |
---|