Ignore:
Timestamp:
Jul 19, 2017, 2:30:15 PM (5 years ago)
Author:
max@…
Message:

Launch the secondary CPUs. For now, they all say hello and enter
an infinite loop.

File:
1 edited

Legend:

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

    r235 r236  
    5858uint8_t mb_mmap[PAGE_SIZE] __in_kdata;
    5959
     60/* x86-specific per-cluster structures */
     61uint8_t gdtstore[PAGE_SIZE] __in_kdata;
     62uint8_t idtstore[PAGE_SIZE] __in_kdata;
     63
     64/* x86-specific per-cpu structures */
     65typedef struct {
     66        bool_t valid;
     67        struct tss tss;
     68        struct tls tls;
     69        uint8_t boot_stack[STKSIZE];
     70        uint8_t intr_stack[STKSIZE];
     71        uint8_t dbfl_stack[STKSIZE];
     72        uint8_t nmfl_stack[STKSIZE];
     73} percpu_archdata_t;
     74percpu_archdata_t cpudata[CONFIG_MAX_LOCAL_CORES] __in_kdata;
     75
    6076/* -------------------------------------------------------------------------- */
    6177
     
    245261/* -------------------------------------------------------------------------- */
    246262
     263static uint32_t cpuN_booted __in_kdata;
     264
     265void start_secondary_cpus()
     266{
     267        pt_entry_t flags = PG_V | PG_KW;
     268        extern vaddr_t cpuN_boot_trampoline;
     269        extern vaddr_t cpuN_boot_trampoline_end;
     270        extern paddr_t smp_L4pa;
     271        extern vaddr_t smp_stkva;
     272        extern paddr_t L4paddr;
     273        size_t i, sz;
     274
     275        smp_L4pa = L4paddr;
     276
     277        /* map the SMP trampoline (identity) */
     278        vaddr_t trampva = (vaddr_t)SMP_TRAMPOLINE_PA;
     279        hal_gpt_maptree_area(trampva, trampva + PAGE_SIZE);
     280        hal_gpt_enter(trampva, SMP_TRAMPOLINE_PA, flags);
     281
     282        /* copy it */
     283        sz = (size_t)&cpuN_boot_trampoline_end - (size_t)&cpuN_boot_trampoline;
     284        memcpy((void *)trampva, (void *)&cpuN_boot_trampoline, sz);
     285
     286        for (i = 0; i < CONFIG_MAX_LOCAL_CORES; i++) {
     287                if (i == 0 || !cpudata[i].valid) {
     288                        continue;
     289                }
     290
     291                smp_stkva = (vaddr_t)cpudata[i].boot_stack + STKSIZE;
     292
     293                cpuN_booted = 0;
     294                boot_cpuN(i, SMP_TRAMPOLINE_PA);
     295                while (!hal_atomic_cas(&cpuN_booted, 1, 0)) {
     296                        /* wait */
     297                }
     298        }
     299
     300        // XXX: unmap the trampoline
     301}
     302
     303void init_x86_64_cpuN()
     304{
     305        cpuN_booted = 1;
     306        x86_printf("-> cpu%z is alive!\n", hal_lapic_gid());
     307        while (1);
     308}
     309
     310/* -------------------------------------------------------------------------- */
     311
    247312static void apic_map()
    248313{
     
    310375        init_bootinfo(&btinfo);
    311376
     377        start_secondary_cpus();
     378
    312379        reg_t dummy;
    313380        hal_enable_irq(&dummy);
     
    342409
    343410/* -------------------------------------------------------------------------- */
    344 
    345 /* x86-specific per-cluster structures */
    346 uint8_t gdtstore[PAGE_SIZE] __in_kdata;
    347 uint8_t idtstore[PAGE_SIZE] __in_kdata;
    348 
    349 /* x86-specific per-cpu structures */
    350 typedef struct {
    351         bool_t valid;
    352         struct tss tss;
    353         struct tls tls;
    354         uint8_t intr_stack[STKSIZE];
    355         uint8_t dbfl_stack[STKSIZE];
    356         uint8_t nmfl_stack[STKSIZE];
    357 } percpu_archdata_t;
    358 percpu_archdata_t cpudata[CONFIG_MAX_LOCAL_CORES] __in_kdata;
    359411
    360412void cpu_activate(uint32_t gid)
Note: See TracChangeset for help on using the changeset viewer.