source: trunk/hal/x86_64/core/hal_special.c @ 129

Last change on this file since 129 was 125, checked in by max@…, 7 years ago

implement hal_time_stamp and hal_fence

File size: 3.1 KB
Line 
1/*
2 * hal_special.c - implementation of TLS API for x86_64
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
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 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
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>
23#include <hal_apic.h>
24#include <hal_special.h>
25#include <hal_register.h>
26#include <hal_internal.h>
27
28#include <core.h>
29#include <thread.h>
30
31struct thread_s;
32
33typedef struct cpu_info {
34        void *ci_self;
35        uint32_t ci_gid;
36        uint32_t ci_lid;
37        struct thread_s *ci_thr;
38} cpu_info_t;
39
40cpu_info_t cpu0 __in_kdata;
41
42cpu_info_t *curcpu()
43{
44        cpu_info_t *ci;
45
46        __asm volatile("movq %%gs:%1, %0" :
47            "=r" (ci) :
48            "m"
49            (*(cpu_info_t * const *)offsetof(cpu_info_t, ci_self)));
50        return ci;
51}
52
53static void hal_tls_load_cpu(cpu_info_t *ci)
54{
55        wrmsr(MSR_FSBASE, 0);
56        wrmsr(MSR_GSBASE, (uint64_t)ci);
57        wrmsr(MSR_KERNELGSBASE, 0);
58}
59
60void hal_tls_init_cpu0()
61{
62        cpu_info_t *ci = &cpu0;
63
64        memset(ci, 0, sizeof(cpu_info_t));
65
66        ci->ci_self = ci;
67        ci->ci_gid = hal_lapic_gid();
68        ci->ci_lid = 0; /* XXX */
69
70        hal_tls_load_cpu(ci);
71}
72
73gid_t hal_get_gid()
74{
75        return curcpu()->ci_gid;
76}
77
78cycle_t hal_time_stamp()
79{
80        return rdtsc();
81}
82
83uint64_t hal_get_cycles()
84{
85        uint64_t cycles;
86        core_t *core = CURRENT_THREAD->core;
87
88        /*
89         * Put the value of the TSC everywhere
90         */
91        cycles = rdtsc();
92        core->time_stamp = cycles;
93        core->cycles = cycles;
94
95        return cycles;
96}
97
98struct thread_s *hal_get_current_thread()
99{
100        return curcpu()->ci_thr;
101}
102
103void hal_set_current_thread( struct thread_s * thread )
104{
105        curcpu()->ci_thr = thread;
106}
107
108/* -------------------------------------------------------------------------- */
109
110void hal_fpu_enable()
111{
112        x86_panic((char *)__func__);
113}
114
115void hal_fpu_disable()
116{
117        x86_panic((char *)__func__);
118}
119
120uint32_t hal_get_stack()
121{
122        x86_panic((char *)__func__);
123        return 0;
124}
125
126uint32_t hal_set_stack( void * new_val )
127{
128        x86_panic((char *)__func__);
129        return 0;
130}
131
132uint32_t hal_get_bad_vaddr()
133{
134        x86_panic((char *)__func__);
135        return 0;
136}
137
138uint32_t hal_uncached_read( uint32_t * ptr )
139{
140        x86_panic((char *)__func__);
141        return 0;
142}
143
144void hal_invalid_dcache_line( void * ptr )
145{
146        x86_panic((char *)__func__);
147}
148
149void hal_fence()
150{
151        mfence();
152}
153
154void hal_rdbar()
155{
156        x86_panic((char *)__func__);
157}
158
159void hal_core_sleep()
160{
161        x86_panic((char *)__func__);
162}
163
164void hal_fixed_delay( uint32_t delay )
165{
166        x86_panic((char *)__func__);
167}
168
169void hal_get_mmu_excp( intptr_t * mmu_ins_excp_code,
170                       intptr_t * mmu_ins_bad_vaddr,
171                       intptr_t * mmu_dat_excp_code,
172                       intptr_t * mmu_dat_bad_vaddr )
173{
174        x86_panic((char *)__func__);
175}
Note: See TracBrowser for help on using the repository browser.