+extern pmap_paddr_t avail_start, avail_end;
+extern vm_offset_t etext;
+extern void *sectHIBB;
+extern int sectSizeHIB;
+
+
+vm_offset_t
+pmap_high_shared_remap(enum high_fixed_addresses e, vm_offset_t va, int sz)
+{
+ vm_offset_t ve = pmap_index_to_virt(e);
+ pt_entry_t *ptep;
+ pmap_paddr_t pa;
+ int i;
+
+ assert(0 == (va & PAGE_MASK)); /* expecting page aligned */
+ ptep = pmap_pte(kernel_pmap, (vm_map_offset_t)ve);
+
+ for (i=0; i< sz; i++) {
+ pa = (pmap_paddr_t) kvtophys(va);
+ pmap_store_pte(ptep, (pa & PG_FRAME)
+ | INTEL_PTE_VALID
+ | INTEL_PTE_GLOBAL
+ | INTEL_PTE_RW
+ | INTEL_PTE_REF
+ | INTEL_PTE_MOD);
+ va+= PAGE_SIZE;
+ ptep++;
+ }
+ return ve;
+}
+
+vm_offset_t
+pmap_cpu_high_shared_remap(int cpu, enum high_cpu_types e, vm_offset_t va, int sz)
+{
+ enum high_fixed_addresses a = e + HIGH_CPU_END * cpu;
+ return pmap_high_shared_remap(HIGH_FIXED_CPUS_BEGIN + a, va, sz);
+}
+
+void pmap_init_high_shared(void);
+
+extern vm_offset_t gdtptr, idtptr;
+
+extern uint32_t low_intstack;
+
+extern struct fake_descriptor ldt_desc_pattern;
+extern struct fake_descriptor tss_desc_pattern;
+
+extern char hi_remap_text, hi_remap_etext;
+extern char t_zero_div;
+
+pt_entry_t *pte_unique_base;
+
+void
+pmap_init_high_shared(void)
+{
+
+ vm_offset_t haddr;
+ struct __gdt_desc_struct gdt_desc = {0,0,0};
+ struct __idt_desc_struct idt_desc = {0,0,0};
+#if MACH_KDB
+ struct i386_tss *ttss;
+#endif
+
+ kprintf("HIGH_MEM_BASE 0x%x fixed per-cpu begin 0x%x\n",
+ HIGH_MEM_BASE,pmap_index_to_virt(HIGH_FIXED_CPUS_BEGIN));
+ pte_unique_base = pmap_pte(kernel_pmap, (vm_map_offset_t)pmap_index_to_virt(HIGH_FIXED_CPUS_BEGIN));
+
+ if (i386_btop(&hi_remap_etext - &hi_remap_text + 1) >
+ HIGH_FIXED_TRAMPS_END - HIGH_FIXED_TRAMPS + 1)
+ panic("tramps too large");
+ haddr = pmap_high_shared_remap(HIGH_FIXED_TRAMPS,
+ (vm_offset_t) &hi_remap_text, 3);
+ kprintf("tramp: 0x%x, ",haddr);
+ printf("hi mem tramps at 0x%x\n",haddr);
+ /* map gdt up high and update ptr for reload */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_GDT,
+ (vm_offset_t) master_gdt, 1);
+ __asm__ __volatile__("sgdt %0": "=m" (gdt_desc): :"memory");
+ gdt_desc.address = haddr;
+ kprintf("GDT: 0x%x, ",haddr);
+ /* map ldt up high */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_LDT_BEGIN,
+ (vm_offset_t) master_ldt,
+ HIGH_FIXED_LDT_END - HIGH_FIXED_LDT_BEGIN + 1);
+ kprintf("LDT: 0x%x, ",haddr);
+ /* put new ldt addr into gdt */
+ master_gdt[sel_idx(KERNEL_LDT)] = ldt_desc_pattern;
+ master_gdt[sel_idx(KERNEL_LDT)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(KERNEL_LDT)], 1);
+ master_gdt[sel_idx(USER_LDT)] = ldt_desc_pattern;
+ master_gdt[sel_idx(USER_LDT)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(USER_LDT)], 1);
+
+ /* map idt up high */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_IDT,
+ (vm_offset_t) master_idt, 1);
+ __asm__ __volatile__("sidt %0" : "=m" (idt_desc));
+ idt_desc.address = haddr;
+ kprintf("IDT: 0x%x, ", haddr);
+ /* remap ktss up high and put new high addr into gdt */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_KTSS,
+ (vm_offset_t) &master_ktss, 1);
+ master_gdt[sel_idx(KERNEL_TSS)] = tss_desc_pattern;
+ master_gdt[sel_idx(KERNEL_TSS)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(KERNEL_TSS)], 1);
+ kprintf("KTSS: 0x%x, ",haddr);
+#if MACH_KDB
+ /* remap dbtss up high and put new high addr into gdt */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_DBTSS,
+ (vm_offset_t) &master_dbtss, 1);
+ master_gdt[sel_idx(DEBUG_TSS)] = tss_desc_pattern;
+ master_gdt[sel_idx(DEBUG_TSS)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(DEBUG_TSS)], 1);
+ ttss = (struct i386_tss *)haddr;
+ kprintf("DBTSS: 0x%x, ",haddr);
+#endif /* MACH_KDB */
+
+ /* remap dftss up high and put new high addr into gdt */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_DFTSS,
+ (vm_offset_t) &master_dftss, 1);
+ master_gdt[sel_idx(DF_TSS)] = tss_desc_pattern;
+ master_gdt[sel_idx(DF_TSS)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(DF_TSS)], 1);
+ kprintf("DFTSS: 0x%x\n",haddr);
+
+ /* remap mctss up high and put new high addr into gdt */
+ haddr = pmap_high_shared_remap(HIGH_FIXED_DFTSS,
+ (vm_offset_t) &master_mctss, 1);
+ master_gdt[sel_idx(MC_TSS)] = tss_desc_pattern;
+ master_gdt[sel_idx(MC_TSS)].offset = (vm_offset_t) haddr;
+ fix_desc(&master_gdt[sel_idx(MC_TSS)], 1);
+ kprintf("MCTSS: 0x%x\n",haddr);
+
+ __asm__ __volatile__("lgdt %0": "=m" (gdt_desc));
+ __asm__ __volatile__("lidt %0": "=m" (idt_desc));
+ kprintf("gdt/idt reloaded, ");
+ set_tr(KERNEL_TSS);
+ kprintf("tr reset to KERNEL_TSS\n");
+}
+