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

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

remove my fake_apic shit from yesterday

File size: 3.1 KB
RevLine 
[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>
[25]27
[102]28#include <core.h>
29#include <thread.h>
30
[25]31struct thread_s;
32
[138]33struct cpu_info {
[46]34        void *ci_self;
35        uint32_t ci_gid;
36        uint32_t ci_lid;
37        struct thread_s *ci_thr;
[138]38} __packed;
39typedef struct cpu_info cpu_info_t;
[46]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
[25]74gid_t hal_get_gid()
75{
[46]76        return curcpu()->ci_gid;
[25]77}
78
[125]79cycle_t hal_time_stamp()
80{
81        return rdtsc();
82}
83
[102]84uint64_t hal_get_cycles()
[25]85{
[102]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;
[25]97}
98
[102]99struct thread_s *hal_get_current_thread()
[25]100{
[46]101        return curcpu()->ci_thr;
[25]102}
103
104void hal_set_current_thread( struct thread_s * thread )
[71]105{
[46]106        curcpu()->ci_thr = thread;
[25]107}
108
[46]109/* -------------------------------------------------------------------------- */
110
[25]111void hal_fpu_enable()
112{
[46]113        x86_panic((char *)__func__);
[25]114}
115
116void hal_fpu_disable()
117{
[46]118        x86_panic((char *)__func__);
[25]119}
120
121uint32_t hal_get_stack()
122{
[46]123        x86_panic((char *)__func__);
[25]124        return 0;
125}
126
127uint32_t hal_set_stack( void * new_val )
128{
[46]129        x86_panic((char *)__func__);
[25]130        return 0;
131}
132
133uint32_t hal_get_bad_vaddr()
134{
[46]135        x86_panic((char *)__func__);
[25]136        return 0;
137}
138
139uint32_t hal_uncached_read( uint32_t * ptr )
140{
[46]141        x86_panic((char *)__func__);
[25]142        return 0;
143}
144
145void hal_invalid_dcache_line( void * ptr )
146{
[46]147        x86_panic((char *)__func__);
[25]148}
149
[124]150void hal_fence()
[25]151{
[125]152        mfence();
[25]153}
154
155void hal_rdbar()
156{
[46]157        x86_panic((char *)__func__);
[25]158}
159
160void hal_core_sleep()
161{
[46]162        x86_panic((char *)__func__);
[25]163}
164
165void hal_fixed_delay( uint32_t delay )
[71]166{
[46]167        x86_panic((char *)__func__);
[25]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{
[46]175        x86_panic((char *)__func__);
[25]176}
Note: See TracBrowser for help on using the repository browser.