Changeset 168


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

make the TLS initialization per-cpu

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

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_init.c

    r166 r168  
    4848static void gdt_create();
    4949static void idt_create();
     50void cpu_tls_init(size_t lid);
    5051void cpu_identify();
    5152void cpu_attach();
     
    292293        x86_printf("[+] hal_apic_init called\n");
    293294
    294         hal_tls_init_cpu0();
    295         x86_printf("[+] hal_tls_init_cpu0 called\n");
     295        cpu_tls_init(0);
     296        x86_printf("[+] cput_tls_init called\n");
    296297
    297298        x86_printf("-> mytest = %z\n", mytest);
     
    328329typedef struct {
    329330        struct tss tss;
     331        struct tls tls;
    330332        uint8_t intr_stack[STKSIZE];
    331333        uint8_t dbfl_stack[STKSIZE];
     
    485487/* -------------------------------------------------------------------------- */
    486488
     489void cpu_tls_init(size_t lid)
     490{
     491        percpu_archdata_t *data = &cpudata[lid];
     492        tls_t *cputls = &data->tls;
     493
     494        memset(cputls, 0, sizeof(tls_t));
     495
     496        cputls->tls_self = cputls;
     497        cputls->tls_gid = hal_lapic_gid();
     498        cputls->tls_lid = lid;
     499
     500        wrmsr(MSR_FSBASE, 0);
     501        wrmsr(MSR_GSBASE, (uint64_t)cputls);
     502        wrmsr(MSR_KERNELGSBASE, 0);
     503}
     504
     505/* -------------------------------------------------------------------------- */
     506
    487507uint64_t cpu_features[4] __in_kdata;
    488508
     
    532552void cpu_attach(size_t lid)
    533553{
     554        /* Per-cluster structures */
    534555        cpu_load_gdt();
    535556        cpu_load_idt();
     557
     558        /* Per-cpu structures */
    536559        cpu_create_tss(lid);
    537560
  • trunk/hal/x86_64/core/hal_internal.h

    r166 r168  
    6666
    6767/* hal_special.c */
    68 void hal_tls_init_cpu0();
    6968
    7069/* x86_printf.c */
  • trunk/hal/x86_64/core/hal_interrupt.c

    r155 r168  
    2929#include <hal_apic.h>
    3030#include <hal_internal.h>
     31#include <hal_special.h>
    3132
    3233/* -------------------------------------------------------------------------- */
     
    3738void hal_timer_intr(struct trapframe *tf)
    3839{
    39         x86_printf("-> got timer: rip=%Z\n", tf->tf_rip);
     40        x86_printf("-> got timer: rip=%Z (th=%Z)\n", tf->tf_rip,
     41            hal_get_current_thread());
    4042        return;
    4143}
  • trunk/hal/x86_64/core/hal_special.c

    r167 r168  
    4343            (*(tls_t * const *)offsetof(tls_t, tls_self)));
    4444        return cputls;
    45 }
    46 
    47 static void hal_tls_load_cpu(tls_t *cputls)
    48 {
    49         wrmsr(MSR_FSBASE, 0);
    50         wrmsr(MSR_GSBASE, (uint64_t)cputls);
    51         wrmsr(MSR_KERNELGSBASE, 0);
    52 }
    53 
    54 void hal_tls_init_cpu0()
    55 {
    56         tls_t *cputls = &cpu0;
    57 
    58         memset(cputls, 0, sizeof(tls_t));
    59 
    60         cputls->tls_self = cputls;
    61         cputls->tls_gid = hal_lapic_gid();
    62         cputls->tls_lid = 0; /* XXX */
    63 
    64         hal_tls_load_cpu(cputls);
    6545}
    6646
Note: See TracChangeset for help on using the changeset viewer.