2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
63 #include <kern/cpu_number.h>
64 #include <kern/kalloc.h>
65 #include <kern/cpu_data.h>
66 #include <mach/mach_types.h>
67 #include <mach/machine.h>
68 #include <mach/vm_map.h>
69 #include <vm/vm_kern.h>
70 #include <vm/vm_map.h>
72 #include <i386/mp_desc.h>
73 #include <i386/lock.h>
74 #include <i386/misc_protos.h>
76 #include <i386/pmap.h>
77 #include <i386/cpu_threads.h>
79 #include <kern/misc_protos.h>
84 * The i386 needs an interrupt stack to keep the PCB stack from being
85 * overrun by interrupts. All interrupt stacks MUST lie at lower addresses
86 * than any thread`s kernel stack.
90 * First cpu`s interrupt stack.
92 extern uint32_t low_intstack
[]; /* bottom */
93 extern uint32_t low_eintstack
[]; /* top */
96 * Per-cpu data area pointers.
97 * The master cpu (cpu 0) has its data area statically allocated;
98 * others are allocated dynamically and this array is updated at runtime.
100 cpu_data_t cpu_data_master
;
101 cpu_data_t
*cpu_data_ptr
[MAX_CPUS
] = { [0] &cpu_data_master
};
103 decl_simple_lock_data(,cpu_lock
); /* protects real_ncpus */
104 unsigned int real_ncpus
= 1;
105 unsigned int max_ncpus
= MAX_CPUS
;
107 extern void *hi_remap_text
;
108 #define HI_TEXT(lo_text) \
109 (((uint32_t)&lo_text - (uint32_t)&hi_remap_text) + HIGH_MEM_BASE)
111 extern void hi_sysenter(void);
112 extern void hi64_sysenter(void);
113 extern void hi64_syscall(void);
117 * Multiprocessor i386/i486 systems use a separate copy of the
118 * GDT, IDT, LDT, and kernel TSS per processor. The first three
119 * are separate to avoid lock contention: the i386 uses locked
120 * memory cycles to access the descriptor tables. The TSS is
121 * separate since each processor needs its own kernel stack,
122 * and since using a TSS marks it busy.
126 * Allocate and initialize the per-processor descriptor tables.
129 struct fake_descriptor ldt_desc_pattern
= {
131 LDTSZ_MIN
* sizeof(struct fake_descriptor
) - 1,
133 ACC_P
|ACC_PL_K
|ACC_LDT
136 struct fake_descriptor tss_desc_pattern
= {
138 sizeof(struct i386_tss
) - 1,
140 ACC_P
|ACC_PL_K
|ACC_TSS
143 struct fake_descriptor cpudata_desc_pattern
= {
145 sizeof(cpu_data_t
)-1,
147 ACC_P
|ACC_PL_K
|ACC_DATA_W
150 struct fake_descriptor userwindow_desc_pattern
= {
152 ((NBPDE
* NCOPY_WINDOWS
) / PAGE_SIZE
) - 1,
154 ACC_P
|ACC_PL_U
|ACC_DATA_W
157 struct fake_descriptor physwindow_desc_pattern
= {
161 ACC_P
|ACC_PL_K
|ACC_DATA_W
165 * This is the expanded, 64-bit variant of the kernel LDT descriptor.
166 * When switching to 64-bit mode this replaces KERNEL_LDT entry
167 * and the following empty slot. This enables the LDT to be referenced
168 * in the uber-space remapping window on the kernel.
170 struct fake_descriptor64 kernel_ldt_desc64
= {
171 FAKE_UBER64(&master_ldt
),
172 LDTSZ_MIN
*sizeof(struct fake_descriptor
)-1,
174 ACC_P
|ACC_PL_K
|ACC_LDT
,
179 * This is the expanded, 64-bit variant of the kernel TSS descriptor.
180 * It is follows pattern of the KERNEL_LDT.
182 struct fake_descriptor64 kernel_tss_desc64
= {
183 FAKE_UBER64(&master_ktss64
),
184 sizeof(struct x86_64_tss
)-1,
186 ACC_P
|ACC_PL_K
|ACC_TSS
,
193 boolean_t is_boot_cpu
)
195 cpu_desc_table_t
*cdt
= cdp
->cpu_desc_tablep
;
196 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
200 * Master CPU uses the tables built at boot time.
201 * Just set the index pointers to the high shared-mapping space.
202 * Note that the sysenter stack uses empty space above the ktss
203 * in the HIGH_FIXED_KTSS page. In this case we don't map the
204 * the real master_sstk in low memory.
206 cdi
->cdi_ktss
= (struct i386_tss
*)
207 pmap_index_to_virt(HIGH_FIXED_KTSS
) ;
208 cdi
->cdi_sstk
= (vm_offset_t
) (cdi
->cdi_ktss
+ 1) +
209 (vm_offset_t
) &master_sstk
.top
-
210 (vm_offset_t
) &master_sstk
;
212 cdi
->cdi_dbtss
= (struct i386_tss
*)
213 pmap_index_to_virt(HIGH_FIXED_DBTSS
);
214 #endif /* MACH_KDB */
215 cdi
->cdi_gdt
= (struct fake_descriptor
*)
216 pmap_index_to_virt(HIGH_FIXED_GDT
);
217 cdi
->cdi_idt
= (struct fake_descriptor
*)
218 pmap_index_to_virt(HIGH_FIXED_IDT
);
219 cdi
->cdi_ldt
= (struct fake_descriptor
*)
220 pmap_index_to_virt(HIGH_FIXED_LDT_BEGIN
);
224 vm_offset_t cpu_hi_desc
;
226 cpu_hi_desc
= pmap_cpu_high_shared_remap(cdp
->cpu_number
,
228 (vm_offset_t
) cdt
, 1);
231 * Per-cpu GDT, IDT, LDT, KTSS descriptors are allocated in one
232 * block (cpu_desc_table) and double-mapped into high shared space
233 * in one page window.
234 * Also, a transient stack for the fast sysenter path. The top of
235 * which is set at context switch time to point to the PCB using
238 cdi
->cdi_gdt
= (struct fake_descriptor
*) (cpu_hi_desc
+
239 offsetof(cpu_desc_table_t
, gdt
[0]));
240 cdi
->cdi_idt
= (struct fake_descriptor
*) (cpu_hi_desc
+
241 offsetof(cpu_desc_table_t
, idt
[0]));
242 cdi
->cdi_ktss
= (struct i386_tss
*) (cpu_hi_desc
+
243 offsetof(cpu_desc_table_t
, ktss
));
244 cdi
->cdi_sstk
= cpu_hi_desc
+
245 offsetof(cpu_desc_table_t
, sstk
.top
);
248 * LDT descriptors are mapped into a seperate area.
250 cdi
->cdi_ldt
= (struct fake_descriptor
*)
251 pmap_cpu_high_shared_remap(
254 (vm_offset_t
) cdp
->cpu_ldtp
,
255 HIGH_CPU_LDT_END
- HIGH_CPU_LDT_BEGIN
+ 1);
260 bcopy((char *)master_idt
,
263 bcopy((char *)master_gdt
,
266 bcopy((char *)master_ldt
,
267 (char *)cdp
->cpu_ldtp
,
269 bzero((char *)&cdt
->ktss
,
270 sizeof(struct i386_tss
));
273 cdi
->cdi_dbtss
= (struct i386_tss
*) (cpu_hi_desc
+
274 offsetof(cpu_desc_table_t
, dbtss
));
275 bcopy((char *)&master_dbtss
,
277 sizeof(struct i386_tss
));
278 #endif /* MACH_KDB */
281 * Fix up the entries in the GDT to point to
282 * this LDT and this TSS.
284 cdt
->gdt
[sel_idx(KERNEL_LDT
)] = ldt_desc_pattern
;
285 cdt
->gdt
[sel_idx(KERNEL_LDT
)].offset
= (vm_offset_t
) cdi
->cdi_ldt
;
286 fix_desc(&cdt
->gdt
[sel_idx(KERNEL_LDT
)], 1);
288 cdt
->gdt
[sel_idx(USER_LDT
)] = ldt_desc_pattern
;
289 cdt
->gdt
[sel_idx(USER_LDT
)].offset
= (vm_offset_t
) cdi
->cdi_ldt
;
290 fix_desc(&cdt
->gdt
[sel_idx(USER_LDT
)], 1);
292 cdt
->gdt
[sel_idx(KERNEL_TSS
)] = tss_desc_pattern
;
293 cdt
->gdt
[sel_idx(KERNEL_TSS
)].offset
= (vm_offset_t
) cdi
->cdi_ktss
;
294 fix_desc(&cdt
->gdt
[sel_idx(KERNEL_TSS
)], 1);
296 cdt
->gdt
[sel_idx(CPU_DATA_GS
)] = cpudata_desc_pattern
;
297 cdt
->gdt
[sel_idx(CPU_DATA_GS
)].offset
= (vm_offset_t
) cdp
;
298 fix_desc(&cdt
->gdt
[sel_idx(CPU_DATA_GS
)], 1);
301 cdt
->gdt
[sel_idx(DEBUG_TSS
)] = tss_desc_pattern
;
302 cdt
->gdt
[sel_idx(DEBUG_TSS
)].offset
= (vm_offset_t
) cdi
->cdi_dbtss
;
303 fix_desc(&cdt
->gdt
[sel_idx(DEBUG_TSS
)], 1);
305 cdt
->dbtss
.esp0
= (int)(db_task_stack_store
+
306 (INTSTACK_SIZE
* (cdp
->cpu_number
)) - sizeof (natural_t
));
307 cdt
->dbtss
.esp
= cdt
->dbtss
.esp0
;
308 cdt
->dbtss
.eip
= (int)&db_task_start
;
309 #endif /* MACH_KDB */
311 cdt
->ktss
.ss0
= KERNEL_DS
;
312 cdt
->ktss
.io_bit_map_offset
= 0x0FFF; /* no IO bitmap */
314 cpu_window_init(cdp
->cpu_number
);
323 boolean_t is_boot_cpu
)
325 cpu_desc_table64_t
*cdt
= (cpu_desc_table64_t
*)
326 cdp
->cpu_desc_tablep
;
327 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
331 * Master CPU uses the tables built at boot time.
332 * Just set the index pointers to the low memory space.
333 * Note that in 64-bit mode these are addressed in the
334 * double-mapped window (uber-space).
336 cdi
->cdi_ktss
= (struct i386_tss
*) &master_ktss64
;
337 cdi
->cdi_sstk
= (vm_offset_t
) &master_sstk
.top
;
338 cdi
->cdi_gdt
= master_gdt
;
339 cdi
->cdi_idt
= (struct fake_descriptor
*) &master_idt64
;
340 cdi
->cdi_ldt
= (struct fake_descriptor
*) &master_ldt
;
342 /* Replace the expanded LDT and TSS slots in the GDT: */
343 *(struct fake_descriptor64
*) &master_gdt
[sel_idx(KERNEL_LDT
)] =
345 *(struct fake_descriptor64
*) &master_gdt
[sel_idx(KERNEL_TSS
)] =
349 * Fix up the expanded descriptors for 64-bit.
351 fix_desc64((void *) &master_idt64
, IDTSZ
);
352 fix_desc64((void *) &master_gdt
[sel_idx(KERNEL_LDT
)], 1);
353 fix_desc64((void *) &master_gdt
[sel_idx(KERNEL_TSS
)], 1);
356 * Set the double-fault stack as IST1 in the 64-bit TSS
358 master_ktss64
.ist1
= UBER64(df_task_stack_end
);
362 * Per-cpu GDT, IDT, KTSS descriptors are allocated in kernel
363 * heap (cpu_desc_table) and double-mapped in uber-space (over 4GB).
364 * LDT descriptors are mapped into a separate area.
366 cdi
->cdi_gdt
= cdt
->gdt
;
367 cdi
->cdi_idt
= (struct fake_descriptor
*) cdt
->idt
;
368 cdi
->cdi_ktss
= (struct i386_tss
*) &cdt
->ktss
;
369 cdi
->cdi_sstk
= (vm_offset_t
) &cdt
->sstk
.top
;
370 cdi
->cdi_ldt
= cdp
->cpu_ldtp
;
375 bcopy((char *)master_idt64
,
377 sizeof(master_idt64
));
378 bcopy((char *)master_gdt
,
381 bcopy((char *)master_ldt
,
382 (char *)cdp
->cpu_ldtp
,
384 bcopy((char *)&master_ktss64
,
386 sizeof(struct x86_64_tss
));
389 * Fix up the entries in the GDT to point to
390 * this LDT and this TSS.
392 kernel_ldt_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ldt
;
393 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(KERNEL_LDT
)] =
395 fix_desc64(&cdt
->gdt
[sel_idx(KERNEL_LDT
)], 1);
397 kernel_ldt_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ldt
;
398 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(USER_LDT
)] =
400 fix_desc64(&cdt
->gdt
[sel_idx(USER_LDT
)], 1);
402 kernel_tss_desc64
.offset
[0] = (vm_offset_t
) cdi
->cdi_ktss
;
403 *(struct fake_descriptor64
*) &cdt
->gdt
[sel_idx(KERNEL_TSS
)] =
405 fix_desc64(&cdt
->gdt
[sel_idx(KERNEL_TSS
)], 1);
407 cdt
->gdt
[sel_idx(CPU_DATA_GS
)] = cpudata_desc_pattern
;
408 cdt
->gdt
[sel_idx(CPU_DATA_GS
)].offset
= (vm_offset_t
) cdp
;
409 fix_desc(&cdt
->gdt
[sel_idx(CPU_DATA_GS
)], 1);
411 /* Set double-fault stack as IST1 */
412 cdt
->ktss
.ist1
= UBER64(cdt
->dfstk
+ sizeof(cdt
->dfstk
));
415 * Allocate copyio windows.
417 cpu_window_init(cdp
->cpu_number
);
421 /* Require that the top of the sysenter stack is 16-byte aligned */
422 if ((cdi
->cdi_sstk
% 16) != 0)
423 panic("cpu_desc_init64() sysenter stack not 16-byte aligned");
427 * Set MSRs for sysenter/sysexit for 64-bit.
430 fast_syscall_init64(void)
432 wrmsr64(MSR_IA32_SYSENTER_CS
, SYSENTER_CS
);
433 wrmsr64(MSR_IA32_SYSENTER_EIP
, UBER64(hi64_sysenter
));
434 wrmsr64(MSR_IA32_SYSENTER_ESP
, UBER64(current_sstk()));
436 /* Enable syscall/sysret */
437 wrmsr64(MSR_IA32_EFER
, rdmsr64(MSR_IA32_EFER
) | MSR_IA32_EFER_SCE
);
440 * MSRs for 64-bit syscall/sysret
441 * Note USER_CS because sysret uses this + 16 when returning to
444 wrmsr64(MSR_IA32_LSTAR
, UBER64(hi64_syscall
));
445 wrmsr64(MSR_IA32_STAR
, (((uint64_t)USER_CS
) << 48) |
446 (((uint64_t)KERNEL64_CS
) << 32));
448 * Emulate eflags cleared by sysenter but note that
449 * we also clear the trace trap to avoid the complications
450 * of single-stepping into a syscall. We also clear
451 * the nested task bit to avoid a spurious "task switch"
454 wrmsr64(MSR_IA32_FMASK
, EFL_DF
|EFL_IF
|EFL_TF
|EFL_NT
);
457 * Set the Kermel GS base MSR to point to per-cpu data in uber-space.
458 * The uber-space handler (hi64_syscall) uses the swapgs instruction.
460 wrmsr64(MSR_IA32_KERNEL_GS_BASE
, UBER64(current_cpu_datap()));
461 kprintf("fast_syscall_init64() KERNEL_GS_BASE=0x%016llx\n",
462 rdmsr64(MSR_IA32_KERNEL_GS_BASE
));
466 * Set MSRs for sysenter/sysexit
469 fast_syscall_init(void)
471 wrmsr(MSR_IA32_SYSENTER_CS
, SYSENTER_CS
, 0);
472 wrmsr(MSR_IA32_SYSENTER_EIP
, HI_TEXT(hi_sysenter
), 0);
473 wrmsr(MSR_IA32_SYSENTER_ESP
, current_sstk(), 0);
477 cpu_data_alloc(boolean_t is_boot_cpu
)
483 assert(real_ncpus
== 1);
484 simple_lock_init(&cpu_lock
, 0);
485 cdp
= &cpu_data_master
;
486 if (cdp
->cpu_processor
== NULL
) {
487 cdp
->cpu_processor
= cpu_processor_alloc(TRUE
);
488 cdp
->cpu_pmap
= pmap_cpu_alloc(TRUE
);
490 cdp
->cpu_is64bit
= FALSE
;
491 cdp
->cpu_int_stack_top
= (vm_offset_t
) low_eintstack
;
492 cpu_desc_init(cdp
, TRUE
);
498 /* Check count before making allocations */
499 if (real_ncpus
>= max_ncpus
)
503 * Allocate per-cpu data:
505 ret
= kmem_alloc(kernel_map
,
506 (vm_offset_t
*) &cdp
, sizeof(cpu_data_t
));
507 if (ret
!= KERN_SUCCESS
) {
508 printf("cpu_data_alloc() failed, ret=%d\n", ret
);
511 bzero((void*) cdp
, sizeof(cpu_data_t
));
515 cdp
->cpu_is64bit
= cpu_mode_is64bit();
518 * Allocate interrupt stack:
520 ret
= kmem_alloc(kernel_map
,
521 (vm_offset_t
*) &cdp
->cpu_int_stack_top
,
523 if (ret
!= KERN_SUCCESS
) {
524 printf("cpu_data_alloc() int stack failed, ret=%d\n", ret
);
527 bzero((void*) cdp
->cpu_int_stack_top
, INTSTACK_SIZE
);
528 cdp
->cpu_int_stack_top
+= INTSTACK_SIZE
;
531 * Allocate descriptor table:
532 * Size depends on cpu mode.
534 ret
= kmem_alloc(kernel_map
,
535 (vm_offset_t
*) &cdp
->cpu_desc_tablep
,
536 cdp
->cpu_is64bit
? sizeof(cpu_desc_table64_t
)
537 : sizeof(cpu_desc_table_t
));
538 if (ret
!= KERN_SUCCESS
) {
539 printf("cpu_data_alloc() desc_table failed, ret=%d\n", ret
);
546 ret
= kmem_alloc(kernel_map
,
547 (vm_offset_t
*) &cdp
->cpu_ldtp
,
548 sizeof(struct real_descriptor
) * LDTSZ
);
549 if (ret
!= KERN_SUCCESS
) {
550 printf("cpu_data_alloc() ldt failed, ret=%d\n", ret
);
554 simple_lock(&cpu_lock
);
555 if (real_ncpus
>= max_ncpus
) {
556 simple_unlock(&cpu_lock
);
559 cpu_data_ptr
[real_ncpus
] = cdp
;
560 cdp
->cpu_number
= real_ncpus
;
562 simple_unlock(&cpu_lock
);
564 kprintf("cpu_data_alloc(%d) 0x%x desc_table: 0x%x "
566 "int_stack: 0x%x-0x%x\n",
567 cdp
->cpu_number
, cdp
, cdp
->cpu_desc_tablep
, cdp
->cpu_ldtp
,
568 cdp
->cpu_int_stack_top
- INTSTACK_SIZE
, cdp
->cpu_int_stack_top
);
574 if (cdp
->cpu_desc_tablep
)
575 kfree((void *) cdp
->cpu_desc_tablep
,
576 sizeof(*cdp
->cpu_desc_tablep
));
577 if (cdp
->cpu_int_stack_top
)
578 kfree((void *) (cdp
->cpu_int_stack_top
- INTSTACK_SIZE
),
580 kfree((void *) cdp
, sizeof(*cdp
));
586 valid_user_segment_selectors(uint16_t cs
,
593 return valid_user_code_selector(cs
) &&
594 valid_user_stack_selector(ss
) &&
595 valid_user_data_selector(ds
) &&
596 valid_user_data_selector(es
) &&
597 valid_user_data_selector(fs
) &&
598 valid_user_data_selector(gs
);
602 static vm_offset_t user_window_base
= 0;
603 static vm_offset_t phys_window_base
= 0;
606 cpu_window_init(int cpu
)
608 cpu_data_t
*cdp
= cpu_data_ptr
[cpu
];
609 cpu_desc_index_t
*cdi
;
610 vm_offset_t user_window
;
611 vm_offset_t phys_window
;
615 num_cpus
= ml_get_max_cpus();
618 panic("copy_window_init: cpu > num_cpus");
620 if (user_window_base
== 0) {
622 if (vm_allocate(kernel_map
, &vaddr
,
623 (NBPDE
* NCOPY_WINDOWS
* num_cpus
) + NBPDE
,
624 VM_FLAGS_ANYWHERE
) != KERN_SUCCESS
)
625 panic("copy_window_init: "
626 "couldn't allocate user map window");
629 * window must start on a page table boundary
630 * in the virtual address space
632 user_window_base
= (vaddr
+ (NBPDE
- 1)) & ~(NBPDE
- 1);
635 * get rid of any allocation leading up to our
638 vm_deallocate(kernel_map
, vaddr
, user_window_base
- vaddr
);
641 * get rid of tail that we don't need
643 user_window
= user_window_base
+
644 (NBPDE
* NCOPY_WINDOWS
* num_cpus
);
646 vm_deallocate(kernel_map
, user_window
,
648 ((NBPDE
* NCOPY_WINDOWS
* num_cpus
) + NBPDE
)) -
651 if (vm_allocate(kernel_map
, &phys_window_base
,
652 PAGE_SIZE
* num_cpus
, VM_FLAGS_ANYWHERE
)
654 panic("copy_window_init: "
655 "couldn't allocate phys map window");
658 user_window
= user_window_base
+ (cpu
* NCOPY_WINDOWS
* NBPDE
);
659 phys_window
= phys_window_base
+ (cpu
* PAGE_SIZE
);
661 cdi
= &cdp
->cpu_desc_index
;
663 cdp
->cpu_copywindow_base
= user_window
;
664 cdp
->cpu_copywindow_pdp
= pmap_pde(kernel_pmap
, user_window
);
666 cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)] = userwindow_desc_pattern
;
667 cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)].offset
= user_window
;
669 fix_desc(&cdi
->cdi_gdt
[sel_idx(USER_WINDOW_SEL
)], 1);
671 cdp
->cpu_physwindow_base
= phys_window
;
674 * make sure the page that encompasses the
675 * pte pointer we're interested in actually
676 * exists in the page table
678 pmap_expand(kernel_pmap
, phys_window
);
680 cdp
->cpu_physwindow_ptep
= vtopte(phys_window
);
682 cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)] = physwindow_desc_pattern
;
683 cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)].offset
= phys_window
;
685 fix_desc(&cdi
->cdi_gdt
[sel_idx(PHYS_WINDOW_SEL
)], 1);
692 } __attribute__((__packed__
)) table_descriptor64_t
;
694 extern table_descriptor64_t gdtptr64
;
695 extern table_descriptor64_t idtptr64
;
697 * Load the segment descriptor tables for the current processor.
700 cpu_desc_load64(cpu_data_t
*cdp
)
702 cpu_desc_index_t
*cdi
= &cdp
->cpu_desc_index
;
705 * Load up the new descriptors etc
706 * ml_load_desc64() expects these global pseudo-descriptors:
707 * gdtptr64 -> master_gdt
708 * idtptr64 -> master_idt64
709 * These are 10-byte descriptors with 64-bit addresses into
712 gdtptr64
.length
= sizeof(master_gdt
) - 1;
713 gdtptr64
.offset
[0] = (uint32_t) cdi
->cdi_gdt
;
714 gdtptr64
.offset
[1] = KERNEL_UBER_BASE_HI32
;
715 idtptr64
.length
= sizeof(master_idt64
) - 1;
716 idtptr64
.offset
[0] = (uint32_t) cdi
->cdi_idt
;
717 idtptr64
.offset
[1] = KERNEL_UBER_BASE_HI32
;
719 /* Make sure busy bit is cleared in the TSS */
720 gdt_desc_p(KERNEL_TSS
)->access
&= ~ACC_TSS_BUSY
;
724 kprintf("64-bit descriptor tables loaded\n");