summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/cpu.c
blob: d088fcd4ab1c9eef0edfaefa8145c9f44624ced9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "arch/cpu.h"
#include "arch/x86_64/msr.h"

extern void _syscall_entry(void);

extern void idt_init();

void
cpu_setup(void)
{
    idt_init();

    cpu_arch_enable_sce();
    cpu_set_syscall_entry((void*)_syscall_entry);
}

void cpu_arch_enable_sce(void)
{
    msr_efer_t feat = msr_efer_read();
    feat.sce = 1;
    msr_efer_write(feat);

    msr_star_t star = msr_star_read();
    star.kcs = 0x08;
    star.ucs = 0x18;
    msr_star_write(star);
}

void
cpu_set_syscall_entry(void *ptr)
{
    msr_lstar_t lstar = (msr_lstar_t)ptr;
    msr_lstar_write(lstar);
}