Ignore:
Timestamp:
Jun 23, 2017, 1:31:23 PM (5 years ago)
Author:
max@…
Message:

Start implementing TLS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/hal_special.c

    r25 r46  
    11/*
    2  * hal_special.c - implementation of Generic Special Register Access API for TSAR-MIPS32
     2 * hal_special.c - implementation of TLS API for x86_64
    33 *
    4  * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *         Alain Greiner    (2016)
     4 * Copyright (c) 2017 Maxime Villard
     5 *
     6 * This file is part of ALMOS-MKH.
    67 *
    7  * Copyright (c) UPMC Sorbonne Universites
    8  *
    9  * This file is part of ALMOS-MKH..
    10  *
    11  * ALMOS-MKH. is free software; you can redistribute it and/or modify it
     8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    129 * under the terms of the GNU General Public License as published by
    1310 * the Free Software Foundation; version 2.0 of the License.
    1411 *
    15  * ALMOS-MKH. is distributed in the hope that it will be useful, but
     12 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1613 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1714 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    2320 */
    2421
    25 
    2622#include <hal_types.h>
     23#include <hal_lapic.h>
    2724#include <hal_special.h>
    28 
    29 /****  Forward declarations ****/
     25#include <hal_register.h>
     26#include <hal_internal.h>
    3027
    3128struct thread_s;
    3229
     30typedef struct cpu_info {
     31        void *ci_self;
     32        uint32_t ci_gid;
     33        uint32_t ci_lid;
     34        struct thread_s *ci_thr;
     35} cpu_info_t;
     36
     37cpu_info_t cpu0 __in_kdata;
     38
     39cpu_info_t *curcpu()
     40{
     41        cpu_info_t *ci;
     42
     43        __asm volatile("movq %%gs:%1, %0" :
     44            "=r" (ci) :
     45            "m"
     46            (*(cpu_info_t * const *)offsetof(cpu_info_t, ci_self)));
     47        return ci;
     48}
     49
     50static void hal_tls_load_cpu(cpu_info_t *ci)
     51{
     52        wrmsr(MSR_FSBASE, 0);
     53        wrmsr(MSR_GSBASE, (uint64_t)ci);
     54        wrmsr(MSR_KERNELGSBASE, 0);
     55}
     56
     57void hal_tls_init_cpu0()
     58{
     59        cpu_info_t *ci = &cpu0;
     60
     61        memset(ci, 0, sizeof(cpu_info_t));
     62
     63        ci->ci_self = ci;
     64        ci->ci_gid = hal_lapic_gid();
     65        ci->ci_lid = 0; /* XXX */
     66
     67        hal_tls_load_cpu(ci);
     68}
     69
    3370gid_t hal_get_gid()
    3471{
    35         return 0;
     72        x86_panic((char *)__func__);
     73        return curcpu()->ci_gid;
    3674}
    3775
    3876uint32_t hal_time_stamp()
    3977{
     78        x86_panic((char *)__func__);
    4079        return 0;
    4180}
     
    4382struct thread_s * hal_get_current_thread()
    4483{
    45         return NULL;
     84        x86_panic((char *)__func__);
     85        return curcpu()->ci_thr;
    4686}
    4787
    4888void hal_set_current_thread( struct thread_s * thread )
    4989{
     90        x86_panic((char *)__func__);
     91        curcpu()->ci_thr = thread;
     92}
    5093
    51 }
     94/* -------------------------------------------------------------------------- */
    5295
    5396void hal_fpu_enable()
    5497{
    55 
     98        x86_panic((char *)__func__);
    5699}
    57100
    58101void hal_fpu_disable()
    59102{
    60 
     103        x86_panic((char *)__func__);
    61104}
    62105
    63106uint32_t hal_get_stack()
    64107{
     108        x86_panic((char *)__func__);
    65109        return 0;
    66110}
     
    68112uint32_t hal_set_stack( void * new_val )
    69113{
     114        x86_panic((char *)__func__);
    70115        return 0;
    71116}
     
    73118uint32_t hal_get_bad_vaddr()
    74119{
     120        x86_panic((char *)__func__);
    75121        return 0;
    76122}
     
    78124uint32_t hal_uncached_read( uint32_t * ptr )
    79125{
     126        x86_panic((char *)__func__);
    80127        return 0;
    81128}
     
    83130void hal_invalid_dcache_line( void * ptr )
    84131{
    85 
     132        x86_panic((char *)__func__);
    86133}
    87134
    88135void hal_wbflush()
    89136{
    90 
     137        x86_panic((char *)__func__);
    91138}
    92139
    93140void hal_rdbar()
    94141{
    95 
     142        x86_panic((char *)__func__);
    96143}
    97144
    98145void hal_core_sleep()
    99146{
    100 
     147        x86_panic((char *)__func__);
    101148}
    102149
    103150void hal_fixed_delay( uint32_t delay )
    104151{
    105 
     152        x86_panic((char *)__func__);
    106153}
    107154
     
    111158                       intptr_t * mmu_dat_bad_vaddr )
    112159{
    113 
     160        x86_panic((char *)__func__);
    114161}
Note: See TracChangeset for help on using the changeset viewer.