summaryrefslogtreecommitdiffstats
path: root/include/arch/x86_64/processor.h
blob: f8a93ce1d35df96d876cdde65b75d46b041b46ef (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef _JOVE_ARCH_x86_64_PROCESSOR_H
#define _JOVE_ARCH_x86_64_PROCESSOR_H 1

#include "memory.h"
#include "tables.h"
#include "object.h"
#include <stdint.h>

#define MSR_FS_BASE 0xC0000100
#define MSR_GS_BASE 0xC0000101
#define MSR_KGS_BASE 0xC0000102

#define MSR_EFER 0xC0000080
#define MSR_STAR 0xC0000081
#define MSR_LSTAR 0xC0000082
#define MSR_SFMASK 0xC0000084

typedef struct jove_TSS
{
    uint32_t resv0;
    uint64_t rsp[3];
    uint32_t resv1;
    uint64_t ist[8];
    uint32_t resv2[2];
    uint16_t resv3;
    uint16_t iopb;
} tss_t;

enum
{
    GDT_ENTRY_KERNEL_NULL = 0,
    GDT_ENTRY_KERNEL_CODE,
    GDT_ENTRY_KERNEL_DATA,
    GDT_ENTRY_USER_NULL,
    GDT_ENTRY_USER_DATA,
    GDT_ENTRY_USER_CODE,
    GDT_ENTRY_TSS_LOW,
    GDT_ENTRY_TSS_HIGH,
    GDT_ENTRY_COUNT
};

typedef struct jove_Processor
{
    physptr_t pdir;
    struct jove_ObjectDirectory *odir;

    segment_descriptor_t gdt[GDT_ENTRY_COUNT];
    struct {
        uint16_t length;
        uint64_t base;
    } __attribute__((packed)) gdtr;
    struct {
        uint16_t length;
        uint64_t base;
    } __attribute__((packed)) idtr;

    tss_t tss;
    tcb_t *tcb;
} processor_t;

void gdt_setup(processor_t *processor);

void rdmsr(uint32_t msr, uint32_t *lo, uint32_t *hi);
void wrmsr(uint32_t msr, uint32_t lo, uint32_t hi);

#endif