Ignore:
Timestamp:
Aug 1, 2017, 10:30:39 AM (7 years ago)
Author:
max@…
Message:

Add a basic syscall entry.

File:
1 edited

Legend:

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

    r298 r308  
    2626#include <hal_acpi.h>
    2727#include <hal_apic.h>
     28#include <hal_kentry.h>
    2829#include <hal_internal.h>
    2930#include <hal_register.h>
     
    447448static void
    448449gdt_set_memseg(struct gdt_memseg *sd, void *base, size_t limit,
    449         int type, int dpl, int gran, int is64)
     450        int type, int dpl, int gran, bool_t is64)
    450451{
    451452        sd->sd_lolimit = (unsigned)limit;
     
    457458        sd->sd_avl = 0;
    458459        sd->sd_long = is64;
    459         sd->sd_def32 = 0;
     460        sd->sd_def32 = !is64;
    460461        sd->sd_gran = gran;
    461462        sd->sd_hibase = (unsigned long)base >> 24;
     
    483484        /* Flat segments */
    484485        gdt_set_memseg(GDT_ADDR_MEM(gdtstore, GDT_KCODE_SEL), 0,
    485             0xfffff, SDT_MEMERA, SEL_KPL, 1, 1);
     486            0xfffff, SDT_MEMERA, SEL_KPL, 1, true);
    486487        gdt_set_memseg(GDT_ADDR_MEM(gdtstore, GDT_KDATA_SEL), 0,
    487             0xfffff, SDT_MEMRWA, SEL_KPL, 1, 1);
     488            0xfffff, SDT_MEMRWA, SEL_KPL, 1, true);
     489        gdt_set_memseg(GDT_ADDR_MEM(gdtstore, GDT_UCODE32_SEL), 0,
     490            0xfffff, SDT_MEMERA, SEL_UPL, 1, false);
    488491        gdt_set_memseg(GDT_ADDR_MEM(gdtstore, GDT_UCODE_SEL), 0,
    489             0xfffff, SDT_MEMERA, SEL_UPL, 1, 1);
     492            0xfffff, SDT_MEMERA, SEL_UPL, 1, true);
    490493        gdt_set_memseg(GDT_ADDR_MEM(gdtstore, GDT_UDATA_SEL), 0,
    491             0xfffff, SDT_MEMRWA, SEL_UPL, 1, 1);
     494            0xfffff, SDT_MEMRWA, SEL_UPL, 1, true);
    492495}
    493496
     
    625628void cpu_tls_init(size_t lid)
    626629{
     630        extern uint64_t x86_syscall;
     631        extern uint64_t x86_syscall32;
     632
    627633        percpu_archdata_t *data = &cpudata[lid];
    628634        tls_t *cputls = &data->tls;
     
    635641        cputls->tls_intr = INTRS_DISABLED;
    636642
     643        /* syscall */
     644        wrmsr(MSR_STAR,
     645            ((uint64_t)GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL) << 32) |
     646            ((uint64_t)GDT_FIXED_SEL(GDT_UCODE32_SEL, SEL_UPL) << 48));
     647        wrmsr(MSR_LSTAR, (uint64_t)&x86_syscall);
     648        wrmsr(MSR_CSTAR, (uint64_t)&x86_syscall32);
     649        wrmsr(MSR_SFMASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D);
     650
     651        /* TLS */
    637652        wrmsr(MSR_FSBASE, 0);
    638653        wrmsr(MSR_GSBASE, (uint64_t)cputls);
Note: See TracChangeset for help on using the changeset viewer.