summaryrefslogtreecommitdiffstats
path: root/include/arch/x86_64/processor.h
blob: 1afa6cc427f13061ad7110e4e7e2302dc44402d4 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#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 rsp0;
    uint64_t rsp1;
    uint64_t rsp2;
    uint64_t resv1;
    uint64_t resv2;
    uint64_t ist1;
    uint64_t ist2;
    uint64_t ist3;
    uint64_t ist4;
    uint64_t ist5;
    uint64_t ist6;
    uint64_t ist7;
    uint64_t resv3;
    uint16_t resv4;
    uint16_t iopb;
} __attribute__((packed)) 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
};

#define GDT_OFFSET_KERNEL_CODE (GDT_ENTRY_KERNEL_CODE * sizeof(segment_descriptor_t))
#define GDT_OFFSET_KERNEL_DATA (GDT_ENTRY_KERNEL_DATA * sizeof(segment_descriptor_t))
#define GDT_OFFSET_USER_DATA (GDT_ENTRY_USER_DATA * sizeof(segment_descriptor_t))
#define GDT_OFFSET_USER_CODE (GDT_ENTRY_USER_CODE * sizeof(segment_descriptor_t))
#define GDT_OFFSET_TSS (GDT_ENTRY_TSS_LOW * sizeof(segment_descriptor_t))

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