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

Last change on this file since 146 was 146, checked in by max@…, 5 years ago

remove my fake_apic shit from yesterday

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