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

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

update

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