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

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

update

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