Changeset 167 for trunk/hal


Ignore:
Timestamp:
Jul 10, 2017, 10:23:29 AM (7 years ago)
Author:
max@…
Message:

define the TLS in hal_segmentation.h

Location:
trunk/hal/x86_64/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_segmentation.h

    r164 r167  
    145145
    146146#define IOMAP_INVALOFF  0xffff
     147
     148/*
     149 * Our definition of Thread-Local Storage.
     150 */
     151struct tls {
     152        void *tls_self;
     153        uint32_t tls_gid;
     154        uint32_t tls_lid;
     155        void *tls_thr;
     156} __packed;
     157typedef struct tls tls_t;
    147158
    148159void lgdt(struct region_descriptor *);
  • trunk/hal/x86_64/core/hal_special.c

    r146 r167  
    2525#include <hal_register.h>
    2626#include <hal_internal.h>
     27#include <hal_segmentation.h>
    2728
    2829#include <core.h>
     
    3132struct thread_s;
    3233
    33 struct cpu_info {
    34         void *ci_self;
    35         uint32_t ci_gid;
    36         uint32_t ci_lid;
    37         struct thread_s *ci_thr;
    38 } __packed;
    39 typedef struct cpu_info cpu_info_t;
     34tls_t cpu0 __in_kdata;
    4035
    41 cpu_info_t cpu0 __in_kdata;
    42 
    43 cpu_info_t *curcpu()
     36tls_t *curcpu()
    4437{
    45         cpu_info_t *ci;
     38        tls_t *cputls;
    4639
    4740        __asm volatile("movq %%gs:%1, %0" :
    48             "=r" (ci) :
     41            "=r" (cputls) :
    4942            "m"
    50             (*(cpu_info_t * const *)offsetof(cpu_info_t, ci_self)));
    51         return ci;
     43            (*(tls_t * const *)offsetof(tls_t, tls_self)));
     44        return cputls;
    5245}
    5346
    54 static void hal_tls_load_cpu(cpu_info_t *ci)
     47static void hal_tls_load_cpu(tls_t *cputls)
    5548{
    5649        wrmsr(MSR_FSBASE, 0);
    57         wrmsr(MSR_GSBASE, (uint64_t)ci);
     50        wrmsr(MSR_GSBASE, (uint64_t)cputls);
    5851        wrmsr(MSR_KERNELGSBASE, 0);
    5952}
     
    6154void hal_tls_init_cpu0()
    6255{
    63         cpu_info_t *ci = &cpu0;
     56        tls_t *cputls = &cpu0;
    6457
    65         memset(ci, 0, sizeof(cpu_info_t));
     58        memset(cputls, 0, sizeof(tls_t));
    6659
    67         ci->ci_self = ci;
    68         ci->ci_gid = hal_lapic_gid();
    69         ci->ci_lid = 0; /* XXX */
     60        cputls->tls_self = cputls;
     61        cputls->tls_gid = hal_lapic_gid();
     62        cputls->tls_lid = 0; /* XXX */
    7063
    71         hal_tls_load_cpu(ci);
     64        hal_tls_load_cpu(cputls);
    7265}
    7366
    7467gid_t hal_get_gid()
    7568{
    76         return curcpu()->ci_gid;
     69        return curcpu()->tls_gid;
    7770}
    7871
     
    9992struct thread_s *hal_get_current_thread()
    10093{
    101         return curcpu()->ci_thr;
     94        return curcpu()->tls_thr;
    10295}
    10396
    10497void hal_set_current_thread( struct thread_s * thread )
    10598{
    106         curcpu()->ci_thr = thread;
     99        curcpu()->tls_thr = thread;
    107100}
    108101
Note: See TracChangeset for help on using the changeset viewer.