Break GDT, TSS out of init.c, mmu.h.
[pintos-anon] / src / threads / gdt.h
1 #ifndef HEADER_GDT_H
2 #define HEADER_GDT_H 1
3
4 /* Segment selectors. */
5 #define SEL_NULL        0x00    /* Null selector. */
6 #define SEL_KCSEG       0x08    /* Kernel code selector. */
7 #define SEL_KDSEG       0x10    /* Kernel data selector. */
8 #define SEL_UCSEG       0x1B    /* User code selector. */
9 #define SEL_UDSEG       0x23    /* User data selector. */
10 #define SEL_TSS         0x28    /* Task-state segment. */
11 #define SEL_CNT         6       /* Number of segments. */
12
13 #ifndef __ASSEMBLER__
14 #include <stdint.h>
15
16 struct tss
17   {
18     uint16_t back_link, :16;
19     uint32_t esp0;
20     uint16_t ss0, :16;
21     uint32_t esp1;
22     uint16_t ss1, :16;
23     uint32_t esp2;
24     uint16_t ss2, :16;
25     uint32_t cr3;
26     uint32_t eip;
27     uint32_t eflags;
28     uint32_t eax, ecx, edx, ebx;
29     uint32_t esp, ebp, esi, edi;
30     uint16_t es, :16;
31     uint16_t cs, :16;
32     uint16_t ss, :16;
33     uint16_t ds, :16;
34     uint16_t fs, :16;
35     uint16_t gs, :16;
36     uint16_t ldt, :16;
37     uint16_t trace, bitmap;
38   };
39
40
41 static inline uint64_t
42 make_dtr_operand (uint16_t limit, void *base)
43 {
44   return limit | ((uint64_t) (uint32_t) base << 16);
45 }
46
47 extern struct tss *tss;
48
49 void gdt_init (void);
50 #endif
51
52 #endif /* gdt.h */