1
2
3
4
5 #define FL_IF 0x00000200
6
7
8 #define CR0_PE 0x00000001
9 #define CR0_WP 0x00010000
10 #define CR0_PG 0x80000000
11
12 #define CR4_PSE 0x00000010
13
14
15 #define SEG_KCODE 1
16 #define SEG_KDATA 2
17 #define SEG_UCODE 3
18 #define SEG_UDATA 4
19 #define SEG_TSS 5
20
21
22 #define NSEGS 6
23
24 #ifndef __ASSEMBLER__
25
26 struct segdesc {
27 uint lim_15_0 : 16;
28 uint base_15_0 : 16;
29 uint base_23_16 : 8;
30 uint type : 4;
31 uint s : 1;
32 uint dpl : 2;
33 uint p : 1;
34 uint lim_19_16 : 4;
35 uint avl : 1;
36 uint rsv1 : 1;
37 uint db : 1;
38 uint g : 1;
39 uint base_31_24 : 8;
40 };
41
42
43 #define SEG(type, base, lim, dpl) (struct segdesc) \
44 { ((lim) >> 12) & 0xffff, (uint)(base) & 0xffff, \
45 ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
46 (uint)(lim) >> 28, 0, 0, 1, 1, (uint)(base) >> 24 }
47 #define SEG16(type, base, lim, dpl) (struct segdesc) \
48 { (lim) & 0xffff, (uint)(base) & 0xffff, \
49 ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
50 (uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 }
51 #endif
52
53 #define DPL_USER 0x3
54
55
56 #define STA_X 0x8
57 #define STA_W 0x2
58 #define STA_R 0x2
59
60
61 #define STS_T32A 0x9
62 #define STS_IG32 0xE
63 #define STS_TG32 0xF
64
65
66
67
68
69
70
71
72
73
74 #define PDX(va) (((uint)(va) >> PDXSHIFT) & 0x3FF)
75
76
77 #define PTX(va) (((uint)(va) >> PTXSHIFT) & 0x3FF)
78
79
80 #define PGADDR(d, t, o) ((uint)((d) << PDXSHIFT | (t) << PTXSHIFT | (o)))
81
82
83 #define NPDENTRIES 1024
84 #define NPTENTRIES 1024
85 #define PGSIZE 4096
86
87 #define PTXSHIFT 12
88 #define PDXSHIFT 22
89
90 #define PGROUNDUP(sz) (((sz)+PGSIZE-1) & ~(PGSIZE-1))
91 #define PGROUNDDOWN(a) (((a)) & ~(PGSIZE-1))
92
93
94 #define PTE_P 0x001
95 #define PTE_W 0x002
96 #define PTE_U 0x004
97 #define PTE_PS 0x080
98
99
100 #define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
101 #define PTE_FLAGS(pte) ((uint)(pte) & 0xFFF)
102
103 #ifndef __ASSEMBLER__
104 typedef uint pte_t;
105
106
107 struct taskstate {
108 uint link;
109 uint esp0;
110 ushort ss0;
111 ushort padding1;
112 uint *esp1;
113 ushort ss1;
114 ushort padding2;
115 uint *esp2;
116 ushort ss2;
117 ushort padding3;
118 void *cr3;
119 uint *eip;
120 uint eflags;
121 uint eax;
122 uint ecx;
123 uint edx;
124 uint ebx;
125 uint *esp;
126 uint *ebp;
127 uint esi;
128 uint edi;
129 ushort es;
130 ushort padding4;
131 ushort cs;
132 ushort padding5;
133 ushort ss;
134 ushort padding6;
135 ushort ds;
136 ushort padding7;
137 ushort fs;
138 ushort padding8;
139 ushort gs;
140 ushort padding9;
141 ushort ldt;
142 ushort padding10;
143 ushort t;
144 ushort iomb;
145 };
146
147
148 struct gatedesc {
149 uint off_15_0 : 16;
150 uint cs : 16;
151 uint args : 5;
152 uint rsv1 : 3;
153 uint type : 4;
154 uint s : 1;
155 uint dpl : 2;
156 uint p : 1;
157 uint off_31_16 : 16;
158 };
159
160
161
162
163
164
165
166
167
168 #define SETGATE(gate, istrap, sel, off, d) \
169 { \
170 (gate).off_15_0 = (uint)(off) & 0xffff; \
171 (gate).cs = (sel); \
172 (gate).args = 0; \
173 (gate).rsv1 = 0; \
174 (gate).type = (istrap) ? STS_TG32 : STS_IG32; \
175 (gate).s = 0; \
176 (gate).dpl = (d); \
177 (gate).p = 1; \
178 (gate).off_31_16 = (uint)(off) >> 16; \
179 }
180
181 #endif