Rev 224 | Rev 231 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 224 | Rev 229 | ||
---|---|---|---|
Line 106... | Line 106... | ||
106 | * on AMD64 it is 64-bit - 2 items in table */ |
106 | * on AMD64 it is 64-bit - 2 items in table */ |
107 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
107 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
108 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
108 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
109 | }; |
109 | }; |
110 | 110 | ||
111 | struct ptr_16_64 gdtr = {.limit = sizeof(gdtr), .base= (__u64)KA2PA(&gdt) }; |
- | |
112 | - | ||
113 | struct idescriptor idt[IDT_ITEMS]; |
111 | struct idescriptor idt[IDT_ITEMS]; |
114 | 112 | ||
- | 113 | struct ptr_16_64 gdtr = {.limit = sizeof(gdt), .base= (__u64) &gdt }; |
|
- | 114 | struct ptr_16_64 idtr = {.limit = sizeof(idt), .base= (__u64) &idt }; |
|
- | 115 | ||
115 | static struct tss tss; |
116 | static struct tss tss; |
116 | struct tss *tss_p = NULL; |
117 | struct tss *tss_p = NULL; |
117 | 118 | ||
118 | /* TODO: Does not compile correctly if it does not exist ???? */ |
119 | /* TODO: Does not compile correctly if it does not exist ???? */ |
119 | int __attribute__ ((section ("K_DATA_START"))) __fake; |
120 | int __attribute__ ((section ("K_DATA_START"))) __fake; |
Line 214... | Line 215... | ||
214 | ); |
215 | ); |
215 | } |
216 | } |
216 | 217 | ||
217 | void pm_init(void) |
218 | void pm_init(void) |
218 | { |
219 | { |
219 | struct descriptor *gdt_p = (struct descriptor *) PA2KA(gdtr.base); |
220 | struct descriptor *gdt_p = (struct descriptor *) gdtr.base; |
220 | struct tss_descriptor *tss_desc; |
221 | struct tss_descriptor *tss_desc; |
221 | 222 | ||
222 | /* |
223 | /* |
223 | * Each CPU has its private GDT and TSS. |
224 | * Each CPU has its private GDT and TSS. |
224 | * All CPUs share one IDT. |
225 | * All CPUs share one IDT. |
Line 246... | Line 247... | ||
246 | tss_desc->dpl = PL_KERNEL; |
247 | tss_desc->dpl = PL_KERNEL; |
247 | 248 | ||
248 | gdt_tss_setbase(&gdt_p[TSS_DES], (__address) tss_p); |
249 | gdt_tss_setbase(&gdt_p[TSS_DES], (__address) tss_p); |
249 | gdt_tss_setlimit(&gdt_p[TSS_DES], sizeof(struct tss) - 1); |
250 | gdt_tss_setlimit(&gdt_p[TSS_DES], sizeof(struct tss) - 1); |
250 | 251 | ||
- | 252 | __asm__("lgdt %0" : : "m"(gdtr)); |
|
- | 253 | __asm__("lidt %0" : : "m"(idtr)); |
|
251 | /* |
254 | /* |
252 | * As of this moment, the current CPU has its own GDT pointing |
255 | * As of this moment, the current CPU has its own GDT pointing |
253 | * to its own TSS. We just need to load the TR register. |
256 | * to its own TSS. We just need to load the TR register. |
254 | */ |
257 | */ |
255 | __asm__("ltr %0" : : "r" ((__u16) gdtselector(TSS_DES))); |
258 | __asm__("ltr %0" : : "r" ((__u16) gdtselector(TSS_DES))); |