2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
55 #include <kern/cpu_number.h>
56 #include <kern/kalloc.h>
57 #include <kern/cpu_data.h>
58 #include <mach/mach_types.h>
59 #include <mach/machine.h>
60 #include <mach/vm_map.h>
61 #include <vm/vm_kern.h>
62 #include <vm/vm_map.h>
64 #include <i386/mp_desc.h>
65 #include <i386/lock.h>
66 #include <i386/misc_protos.h>
68 #include <i386/pmap.h>
69 #include <i386/cpu_threads.h>
71 #include <kern/misc_protos.h>
76 * The i386 needs an interrupt stack to keep the PCB stack from being
77 * overrun by interrupts. All interrupt stacks MUST lie at lower addresses
78 * than any thread`s kernel stack.
82 * First cpu`s interrupt stack.
84 extern uint32_t low_intstack
[]; /* bottom */
85 extern uint32_t low_eintstack
[]; /* top */
88 * Per-cpu data area pointers.
89 * The master cpu (cpu 0) has its data area statically allocated;
90 * others are allocated dynamically and this array is updated at runtime.
92 cpu_data_t cpu_data_master
;
93 cpu_data_t
*cpu_data_ptr
[MAX_CPUS
] = { [0] &cpu_data_master
};
95 decl_simple_lock_data(,cpu_lock
); /* protects real_ncpus */
96 unsigned int real_ncpus
= 1;
97 unsigned int max_ncpus
= MAX_CPUS
;
99 extern void *hi_remap_text
;
100 #define HI_TEXT(lo_text) \
101 (((uint32_t)&lo_text - (uint32_t)&hi_remap_text) + HIGH_MEM_BASE)
103 extern void hi_sysenter(void);
104 extern void hi64_sysenter(void);
105 extern void hi64_syscall(void);
109 * Multiprocessor i386/i486 systems use a separate copy of the
110 * GDT, IDT, LDT, and kernel TSS per processor. The first three
111 * are separate to avoid lock contention: the i386 uses locked
112 * memory cycles to access the descriptor tables. The TSS is
113 * separate since each processor needs its own kernel stack,
114 * and since using a TSS marks it busy.
118 * Allocate and initialize the per-processor descriptor tables.
121 struct fake_descriptor ldt_desc_pattern
= {
123 LDTSZ_MIN
* sizeof(struct fake_descriptor
) - 1,
125 ACC_P
|ACC_PL_K
|ACC_LDT
128 struct fake_descriptor tss_desc_pattern
= {
130 sizeof(struct i386_tss
) - 1,
132 ACC_P
|ACC_PL_K
|ACC_TSS
135 struct fake_descriptor cpudata_desc_pattern
= {
137 sizeof(cpu_data_t
)-1,
139 ACC_P
|ACC_PL_K
|ACC_DATA_W
142 struct fake_descriptor userwindow_desc_pattern
= {
144 ((NBPDE
* NCOPY_WINDOWS
) / PAGE_SIZE
) - 1,
146 ACC_P
|ACC_PL_U
|ACC_DATA_W
149 struct fake_descriptor physwindow_desc_pattern
= {
153 ACC_P
|ACC_PL_K
|ACC_DATA_W
157 * This is the expanded, 64-bit variant of the kernel LDT descriptor.
158 * When switching to 64-bit mode this replaces KERNEL_LDT entry
159 * and the following empty slot. This enables the LDT to be referenced
160 * in the uber-space remapping window on the kernel.
162 struct fake_descriptor64 kernel_ldt_desc64
= {
163 FAKE_UBER64(&master_ldt
),
164 LDTSZ_MIN
*sizeof(struct fake_descriptor
)-1,
166 ACC_P
|ACC_PL_K
|ACC_LDT
,
171 * This is the expanded, 64-bit variant of the kernel TSS descriptor.
172 * It is follows pattern of the KERNEL_LDT.
174 struct fake_descriptor64 kernel_tss_desc64
= {
175 FAKE_UBER64(&master_ktss64
),
176 sizeof(struct x86_64_tss
)-1,
178 ACC_P
|ACC_PL_K
|ACC_TSS
,
185 boolean_t is_boot_cpu
)
187 cpu_desc_table_t
*cdt
= cdp
->cpu_desc_tablep
;
188 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
192 * Master CPU uses the tables built at boot time.
193 * Just set the index pointers to the high shared-mapping space.
194 * Note that the sysenter stack uses empty space above the ktss
195 * in the HIGH_FIXED_KTSS page. In this case we don't map the
196 * the real master_sstk in low memory.
198 cdi
->cdi_ktss
= (struct i386_tss
*)
199 pmap_index_to_virt(HIGH_FIXED_KTSS
) ;
200 cdi
->cdi_sstk
= (vm_offset_t
) (cdi
->cdi_ktss
+ 1) +
201 (vm_offset_t
) &master_sstk
.top
-
202 (vm_offset_t
) &master_sstk
;
204 cdi
->cdi_dbtss
= (struct i386_tss
*)
205 pmap_index_to_virt(HIGH_FIXED_DBTSS
);
206 #endif /* MACH_KDB */
207 cdi
->cdi_gdt
= (struct fake_descriptor
*)
208 pmap_index_to_virt(HIGH_FIXED_GDT
);
209 cdi
->cdi_idt
= (struct fake_descriptor
*)
210 pmap_index_to_virt(HIGH_FIXED_IDT
);
211 cdi
->cdi_ldt
= (struct fake_descriptor
*)
212 pmap_index_to_virt(HIGH_FIXED_LDT_BEGIN
);
216 vm_offset_t cpu_hi_desc
;
218 cpu_hi_desc
= pmap_cpu_high_shared_remap(cdp
->cpu_number
,
220 (vm_offset_t
) cdt
, 1);
223 * Per-cpu GDT, IDT, LDT, KTSS descriptors are allocated in one
224 * block (cpu_desc_table) and double-mapped into high shared space
225 * in one page window.
226 * Also, a transient stack for the fast sysenter path. The top of
227 * which is set at context switch time to point to the PCB using
230 cdi
->cdi_gdt
= (struct fake_descriptor
*) (cpu_hi_desc
+
231 offsetof(cpu_desc_table_t
, gdt
[0]));
232 cdi
->cdi_idt
= (struct fake_descriptor
*) (cpu_hi_desc
+
233 offsetof(cpu_desc_table_t
, idt
[0]));
234 cdi
->cdi_ktss
= (struct i386_tss
*) (cpu_hi_desc
+
235 offsetof(cpu_desc_table_t
, ktss
));
236 cdi
->cdi_sstk
= cpu_hi_desc
+
237 offsetof(cpu_desc_table_t
, sstk
.top
);
240 * LDT descriptors are mapped into a seperate area.
242 cdi
->cdi_ldt
= (struct fake_descriptor
*)
243 pmap_cpu_high_shared_remap(
246 (vm_offset_t
) cdp
->cpu_ldtp
,
247 HIGH_CPU_LDT_END
- HIGH_CPU_LDT_BEGIN
+ 1);
252 bcopy((char *)master_idt
,
255 bcopy((char *)master_gdt
,
258 bcopy((char *)master_ldt
,
259 (char *)cdp
->cpu_ldtp
,
261 bzero((char *)&cdt
->ktss
,
262 sizeof(struct i386_tss
));
265 cdi
->cdi_dbtss
= (struct i386_tss
*) (cpu_hi_desc
+
266 offsetof(cpu_desc_table_t
, dbtss
));
267 bcopy((char *)&master_dbtss
,
269 sizeof(struct i386_tss
));
270 #endif /* MACH_KDB */
273 * Fix up the entries in the GDT to point to
274 * this LDT and this TSS.
276 cdt
->gdt
[sel_idx(KERNEL_LDT
)] = ldt_desc_pattern
;
277 cdt
->gdt
[sel_idx(KERNEL_LDT
)].offset
= (vm_offset_t
) cdi
->cdi_ldt
;
278 fix_desc(&cdt
->gdt
[sel_idx(KERNEL_LDT
)], 1);
280 cdt
->gdt
[sel_idx(USER_LDT
)] = ldt_desc_pattern
;
281 cdt
->gdt
[sel_idx(USER_LDT
)].offset
= (vm_offset_t
) cdi
->cdi_ldt
;
282 fix_desc(&cdt
->gdt
[sel_idx(USER_LDT
)], 1);
284 cdt
->gdt
[sel_idx(KERNEL_TSS
)] = tss_desc_pattern
;
285 cdt
->gdt
[sel_idx(KERNEL_TSS
)].offset
= (vm_offset_t
) cdi
->cdi_ktss
;
286 fix_desc(&cdt
->gdt
[sel_idx(KERNEL_TSS
)], 1);
288 cdt
->gdt
[sel_idx(CPU_DATA_GS
)] = cpudata_desc_pattern
;
289 cdt
->gdt
[sel_idx(CPU_DATA_GS
)].offset
= (vm_offset_t
) cdp
;
290 fix_desc(&cdt
->gdt
[sel_idx(CPU_DATA_GS
)], 1);
293 cdt
->gdt
[sel_idx(DEBUG_TSS
)] = tss_desc_pattern
;
294 cdt
->gdt
[sel_idx(DEBUG_TSS
)].offset
= (vm_offset_t
) cdi
->cdi_dbtss
;
295 fix_desc(&cdt
->gdt
[sel_idx(DEBUG_TSS
)], 1);
297 cdt
->dbtss
.esp0
= (int)(db_task_stack_store
+
298 (INTSTACK_SIZE
* (cdp
->cpu_number
)) - sizeof (natural_t
));
299 cdt
->dbtss
.esp
= cdt
->dbtss
.esp0
;
300 cdt
->dbtss
.eip
= (int)&db_task_start
;
301 #endif /* MACH_KDB */
303 cdt
->ktss
.ss0
= KERNEL_DS
;
304 cdt
->ktss
.io_bit_map_offset
= 0x0FFF; /* no IO bitmap */
306 cpu_window_init(cdp
->cpu_number
);
315 boolean_t is_boot_cpu
)
317 cpu_desc_table64_t
*cdt
= (cpu_desc_table64_t
*)
318 cdp
->cpu_desc_tablep
;
319 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
323 * Master CPU uses the tables built at boot time.
324 * Just set the index pointers to the low memory space.
325 * Note that in 64-bit mode these are addressed in the
326 * double-mapped window (uber-space).
328 cdi
->cdi_ktss
= (struct i386_tss
*) &master_ktss64
;
329 cdi
->cdi_sstk
= (vm_offset_t
) &master_sstk
.top
;
330 cdi
->cdi_gdt
= master_gdt
;
331 cdi
->cdi_idt
= (struct fake_descriptor
*) &master_idt64
;
332 cdi
->cdi_ldt
= (struct fake_descriptor
*) &master_ldt
;
334 /* Replace the expanded LDT and TSS slots in the GDT: */
335 *(struct fake_descriptor64
*) &master_gdt
[sel_idx(KERNEL_LDT
)] =
337 *(struct fake_descriptor64
*) &master_gdt
[sel_idx(KERNEL_TSS
)] =
341 * Fix up the expanded descriptors for 64-bit.
343 fix_desc64((void *) &master_idt64
, IDTSZ
);
344 fix_desc64((void *) &master_gdt
[sel_idx(KERNEL_LDT
)], 1);
345 fix_desc64((void *) &master_gdt
[sel_idx(KERNEL_TSS
)], 1);
348 * Set the double-fault stack as IST1 in the 64-bit TSS
350 master_ktss64
.ist1
= UBER64(df_task_stack_end
);
354 * Per-cpu GDT, IDT, KTSS descriptors are allocated in kernel
355 * heap (cpu_desc_table) and double-mapped in uber-space (over 4GB).
356 * LDT descriptors are mapped into a separate area.
358 cdi
->cdi_gdt
= cdt
->gdt
;
359 cdi
->cdi_idt
= (struct fake_descriptor
*) cdt
->idt
;
360 cdi
->cdi_ktss
= (struct i386_tss
*) &cdt
->ktss
;
361 cdi
->cdi_sstk
= (vm_offset_t
) &cdt
->sstk
.top
;
362 cdi
->cdi_ldt
= cdp
->cpu_ldtp
;
367 bcopy((char *)master_idt64
,
369 sizeof(master_idt64
));
370 bcopy((char *)master_gdt
,
373 bcopy((char *)master_ldt
,
374 (char *)cdp
->cpu_ldtp
,
376 bcopy((char *)&master_ktss64
,
378 sizeof(struct x86_64_tss
));
381 * Fix up the entries in the GDT to point to
382 * this LDT and this TSS.
384 kernel_ldt_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ldt
;
385 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(KERNEL_LDT
)] =
387 fix_desc64(&cdt
->gdt
[sel_idx(KERNEL_LDT
)], 1);
389 kernel_ldt_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ldt
;
390 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(USER_LDT
)] =
392 fix_desc64(&cdt
->gdt
[sel_idx(USER_LDT
)], 1);
394 kernel_tss_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ktss
;
395 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(KERNEL_TSS
)] =
397 fix_desc64(&cdt
->gdt
[sel_idx(KERNEL_TSS
)], 1);
399 cdt
->gdt
[sel_idx(CPU_DATA_GS
)] = cpudata_desc_pattern
;
400 cdt
->gdt
[sel_idx(CPU_DATA_GS
)].offset
= (vm_offset_t
) cdp
;
401 fix_desc(&cdt
->gdt
[sel_idx(CPU_DATA_GS
)], 1);
403 /* Set double-fault stack as IST1 */
404 cdt
->ktss
.ist1
= UBER64(cdt
->dfstk
+ sizeof(cdt
->dfstk
));
407 * Allocate copyio windows.
409 cpu_window_init(cdp
->cpu_number
);
413 /* Require that the top of the sysenter stack is 16-byte aligned */
414 if ((cdi
->cdi_sstk
% 16) != 0)
415 panic("cpu_desc_init64() sysenter stack not 16-byte aligned");
419 * Set MSRs for sysenter/sysexit for 64-bit.
422 fast_syscall_init64(void)
424 wrmsr64(MSR_IA32_SYSENTER_CS
, SYSENTER_CS
);
425 wrmsr64(MSR_IA32_SYSENTER_EIP
, UBER64(hi64_sysenter
));
426 wrmsr64(MSR_IA32_SYSENTER_ESP
, UBER64(current_sstk()));
428 /* Enable syscall/sysret */
429 wrmsr64(MSR_IA32_EFER
, rdmsr64(MSR_IA32_EFER
) | MSR_IA32_EFER_SCE
);
432 * MSRs for 64-bit syscall/sysret
433 * Note USER_CS because sysret uses this + 16 when returning to
436 wrmsr64(MSR_IA32_LSTAR
, UBER64(hi64_syscall
));
437 wrmsr64(MSR_IA32_STAR
, (((uint64_t)USER_CS
) << 48) |
438 (((uint64_t)KERNEL64_CS
) << 32));
440 * Emulate eflags cleared by sysenter but note that
441 * we also clear the trace trap to avoid the complications
442 * of single-stepping into a syscall. We also clear
443 * the nested task bit to avoid a spurious "task switch"
446 wrmsr64(MSR_IA32_FMASK
, EFL_DF
|EFL_IF
|EFL_TF
|EFL_NT
);
449 * Set the Kermel GS base MSR to point to per-cpu data in uber-space.
450 * The uber-space handler (hi64_syscall) uses the swapgs instruction.
452 wrmsr64(MSR_IA32_KERNEL_GS_BASE
, UBER64(current_cpu_datap()));
453 kprintf("fast_syscall_init64() KERNEL_GS_BASE=0x%016llx\n",
454 rdmsr64(MSR_IA32_KERNEL_GS_BASE
));
458 * Set MSRs for sysenter/sysexit
461 fast_syscall_init(void)
463 wrmsr(MSR_IA32_SYSENTER_CS
, SYSENTER_CS
, 0);
464 wrmsr(MSR_IA32_SYSENTER_EIP
, HI_TEXT(hi_sysenter
), 0);
465 wrmsr(MSR_IA32_SYSENTER_ESP
, current_sstk(), 0);
469 cpu_data_alloc(boolean_t is_boot_cpu
)
475 assert(real_ncpus
== 1);
476 simple_lock_init(&cpu_lock
, 0);
477 cdp
= &cpu_data_master
;
478 if (cdp
->cpu_processor
== NULL
) {
479 cdp
->cpu_processor
= cpu_processor_alloc(TRUE
);
480 cdp
->cpu_pmap
= pmap_cpu_alloc(TRUE
);
482 cdp
->cpu_is64bit
= FALSE
;
483 cdp
->cpu_int_stack_top
= (vm_offset_t
) low_eintstack
;
484 cpu_desc_init(cdp
, TRUE
);
490 /* Check count before making allocations */
491 if (real_ncpus
>= max_ncpus
)
495 * Allocate per-cpu data:
497 ret
= kmem_alloc(kernel_map
,
498 (vm_offset_t
*) &cdp
, sizeof(cpu_data_t
));
499 if (ret
!= KERN_SUCCESS
) {
500 printf("cpu_data_alloc() failed, ret=%d\n", ret
);
503 bzero((void*) cdp
, sizeof(cpu_data_t
));
507 cdp
->cpu_is64bit
= cpu_mode_is64bit();
510 * Allocate interrupt stack:
512 ret
= kmem_alloc(kernel_map
,
513 (vm_offset_t
*) &cdp
->cpu_int_stack_top
,
515 if (ret
!= KERN_SUCCESS
) {
516 printf("cpu_data_alloc() int stack failed, ret=%d\n", ret
);
519 bzero((void*) cdp
->cpu_int_stack_top
, INTSTACK_SIZE
);
520 cdp
->cpu_int_stack_top
+= INTSTACK_SIZE
;
523 * Allocate descriptor table:
524 * Size depends on cpu mode.
526 ret
= kmem_alloc(kernel_map
,
527 (vm_offset_t
*) &cdp
->cpu_desc_tablep
,
528 cdp
->cpu_is64bit
? sizeof(cpu_desc_table64_t
)
529 : sizeof(cpu_desc_table_t
));
530 if (ret
!= KERN_SUCCESS
) {
531 printf("cpu_data_alloc() desc_table failed, ret=%d\n", ret
);
538 ret
= kmem_alloc(kernel_map
,
539 (vm_offset_t
*) &cdp
->cpu_ldtp
,
540 sizeof(struct real_descriptor
) * LDTSZ
);
541 if (ret
!= KERN_SUCCESS
) {
542 printf("cpu_data_alloc() ldt failed, ret=%d\n", ret
);
546 simple_lock(&cpu_lock
);
547 if (real_ncpus
>= max_ncpus
) {
548 simple_unlock(&cpu_lock
);
551 cpu_data_ptr
[real_ncpus
] = cdp
;
552 cdp
->cpu_number
= real_ncpus
;
554 simple_unlock(&cpu_lock
);
556 kprintf("cpu_data_alloc(%d) 0x%x desc_table: 0x%x "
558 "int_stack: 0x%x-0x%x\n",
559 cdp
->cpu_number
, cdp
, cdp
->cpu_desc_tablep
, cdp
->cpu_ldtp
,
560 cdp
->cpu_int_stack_top
- INTSTACK_SIZE
, cdp
->cpu_int_stack_top
);
566 if (cdp
->cpu_desc_tablep
)
567 kfree((void *) cdp
->cpu_desc_tablep
,
568 sizeof(*cdp
->cpu_desc_tablep
));
569 if (cdp
->cpu_int_stack_top
)
570 kfree((void *) (cdp
->cpu_int_stack_top
- INTSTACK_SIZE
),
572 kfree((void *) cdp
, sizeof(*cdp
));
578 valid_user_segment_selectors(uint16_t cs
,
585 return valid_user_code_selector(cs
) &&
586 valid_user_stack_selector(ss
) &&
587 valid_user_data_selector(ds
) &&
588 valid_user_data_selector(es
) &&
589 valid_user_data_selector(fs
) &&
590 valid_user_data_selector(gs
);
594 static vm_offset_t user_window_base
= 0;
595 static vm_offset_t phys_window_base
= 0;
598 cpu_window_init(int cpu
)
600 cpu_data_t
*cdp
= cpu_data_ptr
[cpu
];
601 cpu_desc_index_t
*cdi
;
602 vm_offset_t user_window
;
603 vm_offset_t phys_window
;
607 num_cpus
= ml_get_max_cpus();
610 panic("copy_window_init: cpu > num_cpus");
612 if (user_window_base
== 0) {
614 if (vm_allocate(kernel_map
, &vaddr
,
615 (NBPDE
* NCOPY_WINDOWS
* num_cpus
) + NBPDE
,
616 VM_FLAGS_ANYWHERE
) != KERN_SUCCESS
)
617 panic("copy_window_init: "
618 "couldn't allocate user map window");
621 * window must start on a page table boundary
622 * in the virtual address space
624 user_window_base
= (vaddr
+ (NBPDE
- 1)) & ~(NBPDE
- 1);
627 * get rid of any allocation leading up to our
630 vm_deallocate(kernel_map
, vaddr
, user_window_base
- vaddr
);
633 * get rid of tail that we don't need
635 user_window
= user_window_base
+
636 (NBPDE
* NCOPY_WINDOWS
* num_cpus
);
638 vm_deallocate(kernel_map
, user_window
,
640 ((NBPDE
* NCOPY_WINDOWS
* num_cpus
) + NBPDE
)) -
643 if (vm_allocate(kernel_map
, &phys_window_base
,
644 PAGE_SIZE
* num_cpus
, VM_FLAGS_ANYWHERE
)
646 panic("copy_window_init: "
647 "couldn't allocate phys map window");
650 user_window
= user_window_base
+ (cpu
* NCOPY_WINDOWS
* NBPDE
);
651 phys_window
= phys_window_base
+ (cpu
* PAGE_SIZE
);
653 cdi
= &cdp
->cpu_desc_index
;
655 cdp
->cpu_copywindow_base
= user_window
;
656 cdp
->cpu_copywindow_pdp
= pmap_pde(kernel_pmap
, user_window
);
658 cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)] = userwindow_desc_pattern
;
659 cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)].offset
= user_window
;
661 fix_desc(&cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)], 1);
663 cdp
->cpu_physwindow_base
= phys_window
;
664 cdp
->cpu_physwindow_ptep
= vtopte(phys_window
);
666 cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)] = physwindow_desc_pattern
;
667 cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)].offset
= phys_window
;
669 fix_desc(&cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)], 1);
677 } __attribute__((__packed__
)) table_descriptor64_t
;
679 extern table_descriptor64_t gdtptr64
;
680 extern table_descriptor64_t idtptr64
;
682 * Load the segment descriptor tables for the current processor.
685 cpu_desc_load64(cpu_data_t
*cdp
)
687 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
690 * Load up the new descriptors etc
691 * ml_load_desc64() expects these global pseudo-descriptors:
692 * gdtptr64 -> master_gdt
693 * idtptr64 -> master_idt64
694 * These are 10-byte descriptors with 64-bit addresses into
697 gdtptr64
.length
= sizeof(master_gdt
) - 1;
698 gdtptr64
.offset
[0] = (uint32_t) cdi
->cdi_gdt
;
699 gdtptr64
.offset
[1] = KERNEL_UBER_BASE_HI32
;
700 idtptr64
.length
= sizeof(master_idt64
) - 1;
701 idtptr64
.offset
[0] = (uint32_t) cdi
->cdi_idt
;
702 idtptr64
.offset
[1] = KERNEL_UBER_BASE_HI32
;
704 /* Make sure busy bit is cleared in the TSS */
705 gdt_desc_p(KERNEL_TSS
)->access
&= ~ACC_TSS_BUSY
;
709 kprintf("64-bit descriptor tables loaded\n");