svn commit: r185325 - projects/release_6_3_xen/sys/i386/xen

Kip Macy kmacy at FreeBSD.org
Tue Nov 25 19:14:24 PST 2008


Author: kmacy
Date: Wed Nov 26 03:14:24 2008
New Revision: 185325
URL: http://svn.freebsd.org/changeset/base/185325

Log:
  make initvalues able to handle an arbitrary number of page directories or page tables at startup

Modified:
  projects/release_6_3_xen/sys/i386/xen/xen_machdep.c

Modified: projects/release_6_3_xen/sys/i386/xen/xen_machdep.c
==============================================================================
--- projects/release_6_3_xen/sys/i386/xen/xen_machdep.c	Wed Nov 26 01:09:48 2008	(r185324)
+++ projects/release_6_3_xen/sys/i386/xen/xen_machdep.c	Wed Nov 26 03:14:24 2008	(r185325)
@@ -821,16 +821,17 @@ initvalues(start_info_t *startinfo)
 	vm_offset_t cur_space, cur_space_pt;
 	struct physdev_set_iopl set_iopl;
 	
-	vm_paddr_t KPTphys, IdlePTDma;
 	vm_paddr_t console_page_ma, xen_store_ma;
-	vm_offset_t KPTphysoff, tmpva;
+	vm_offset_t tmpva;
 	vm_paddr_t shinfo;
 #ifdef PAE
 	vm_paddr_t IdlePDPTma, IdlePDPTnewma;
 	vm_paddr_t IdlePTDnewma[4];
 	pd_entry_t *IdlePDPTnew, *IdlePTDnew;
+	vm_paddr_t IdlePTDma[4];
 #else
-	vm_paddr_t pdir_shadow_ma;
+	vm_paddr_t IdlePTDma[1];
+	
 #endif
 	unsigned long i;
 	int ncpus = MAXCPU;
@@ -850,10 +851,37 @@ initvalues(start_info_t *startinfo)
 #endif	
 	xen_start_info = startinfo;
 	xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list;
+	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
+	l1_pages = 0;
+	
+#ifdef PAE
+	l3_pages = 1;
+	l2_pages = 0;
+	IdlePDPT = (pd_entry_t *)startinfo->pt_base;
+	IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base));
+	for (i = (((KERNBASE >> 18) & PAGE_MASK) >> 30);
+	     (i < 4) && (IdlePDPT[i] != 0); i++)
+			l2_pages++;
+	/*
+	 * Note that only one page directory has been allocated at this point.
+	 * Thus, if KERNBASE
+	 */
+	for (i = 0; i < l2_pages; i++)
+		IdlePTDma[i] = xpmap_ptom(VTOP(IdlePTD + i*PAGE_SIZE));
+#else	
+	l3_pages = 0;
+	l2_pages = 1;
+#endif
+	for (i = (((KERNBASE>>18) & PAGE_MASK)>>PAGE_SHIFT);
+	     (i<l2_pages*NPDEPG) && (i<(VM_MAX_KERNEL_ADDRESS>>PDRSHIFT)); i++)
+		if (IdlePTD[i] != 0)
+			l1_pages++;
 
+	
 	/* number of pages allocated after the pts + 1*/;
 	cur_space = xen_start_info->pt_base +
-	    ((xen_start_info->nr_pt_frames) + 3 )*PAGE_SIZE;
+	    (l3_pages + l2_pages + l1_pages + 1)*PAGE_SIZE;
+	
 	printk("initvalues(): wooh - availmem=%x,%x\n", avail_space, cur_space);
 
 	printk("KERNBASE=%x,pt_base=%x, VTOPFN(base)=%x, nr_pt_frames=%x\n",
@@ -861,55 +889,14 @@ initvalues(start_info_t *startinfo)
 	    xen_start_info->nr_pt_frames);
 	xendebug_flags = 0; /* 0xffffffff; */
 
-	/* allocate 4 pages for bootmem allocator */
-	bootmem_start = bootmem_current = (char *)cur_space;
-	cur_space += (4 * PAGE_SIZE);
-	bootmem_end = (char *)cur_space;
-	
-	/* allocate pages for gdt */
-	gdt = (union descriptor *)cur_space;
-	cur_space += PAGE_SIZE*ncpus;
-
-        /* allocate page for ldt */
-	ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE;
-	cur_space += PAGE_SIZE;
 	
-	HYPERVISOR_shared_info = (shared_info_t *)cur_space;
-	cur_space += PAGE_SIZE;
-
-	xen_store = (struct ringbuf_head *)cur_space;
-	cur_space += PAGE_SIZE;
-
-	console_page = (char *)cur_space;
-	cur_space += PAGE_SIZE;
-
 #ifdef ADD_ISA_HOLE
 	shift_phys_machine(xen_phys_machine, xen_start_info->nr_pages);
 #endif
 	/* 
 	 * pre-zero unused mapped pages - mapped on 4MB boundary
 	 */
-#ifdef PAE
-	IdlePDPT = (pd_entry_t *)startinfo->pt_base;
-	IdlePDPTma = xpmap_ptom(VTOP(startinfo->pt_base));
-	/*
-	 * Note that only one page directory has been allocated at this point.
-	 * Thus, if KERNBASE
-	 */
-	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
-	IdlePTDma = xpmap_ptom(VTOP(IdlePTD));
-	l3_pages = 1;
-#else	
-	IdlePTD = (pd_entry_t *)startinfo->pt_base;
-	IdlePTDma = xpmap_ptom(VTOP(startinfo->pt_base));
-	l3_pages = 0;
-#endif
-	l2_pages = 1;
-	l1_pages = xen_start_info->nr_pt_frames - l2_pages - l3_pages;
-
-	KPTphysoff = (l2_pages + l3_pages)*PAGE_SIZE;
 
-	KPTphys = xpmap_ptom(VTOP(startinfo->pt_base + KPTphysoff));
 	XENPRINTF("IdlePTD %p\n", IdlePTD);
 	XENPRINTF("nr_pages: %ld shared_info: 0x%lx flags: 0x%lx pt_base: 0x%lx "
 		  "mod_start: 0x%lx mod_len: 0x%lx\n",
@@ -918,16 +905,6 @@ initvalues(start_info_t *startinfo)
 		  xen_start_info->mod_start, xen_start_info->mod_len);
 	/* Map proc0's KSTACK */
 
-	proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE);
-	printk("proc0kstack=%u\n", proc0kstack);
-
-	/* vm86/bios stack */
-	cur_space += PAGE_SIZE;
-
-	/* Map space for the vm86 region */
-	vm86paddr = (vm_offset_t)cur_space;
-	cur_space += (PAGE_SIZE * 3);
-
 #ifdef PAE
 	IdlePDPTnew = (pd_entry_t *)cur_space; cur_space += PAGE_SIZE;
 	bzero(IdlePDPTnew, PAGE_SIZE);
@@ -948,7 +925,6 @@ initvalues(start_info_t *startinfo)
 	for (i = 0; i < 4; i++)
 		IdlePDPTnew[i] = IdlePTDnewma[i] | PG_V;
 
-	__asm__("nop;");
 	/*
 	 *
 	 * re-map the new PDPT read-only
@@ -959,17 +935,30 @@ initvalues(start_info_t *startinfo)
 	 * Unpin the current PDPT
 	 */
 	xen_pt_unpin(IdlePDPTma);
-	
-	for (i = 0; i < 20; i++) {
-		int startidx = ((KERNBASE >> 18) & PAGE_MASK) >> 3;
-
-		if (IdlePTD[startidx + i] == 0) {
-			l1_pages = i;
-			break;
-		}	
-	}
 		    
 #endif  /* PAE */
+	proc0kstack = cur_space; cur_space += (KSTACK_PAGES * PAGE_SIZE);
+	printk("proc0kstack=%u\n", proc0kstack);
+
+	/* vm86/bios stack */
+	cur_space += PAGE_SIZE;
+
+	/* Map space for the vm86 region */
+	vm86paddr = (vm_offset_t)cur_space;
+	cur_space += (PAGE_SIZE * 3);
+
+	/* allocate 4 pages for bootmem allocator */
+	bootmem_start = bootmem_current = (char *)cur_space;
+	cur_space += (4 * PAGE_SIZE);
+	bootmem_end = (char *)cur_space;
+	
+	/* allocate pages for gdt */
+	gdt = (union descriptor *)cur_space;
+	cur_space += PAGE_SIZE*ncpus;
+
+        /* allocate page for ldt */
+	ldt = (union descriptor *)cur_space; cur_space += PAGE_SIZE;
+	cur_space += PAGE_SIZE;
 	
 	/* unmap remaining pages from initial 4MB chunk
 	 *
@@ -1035,6 +1024,15 @@ initvalues(start_info_t *startinfo)
 	IdlePTD = IdlePTDnew;
 	IdlePDPT = IdlePDPTnew;
 	IdlePDPTma = IdlePDPTnewma;
+
+	HYPERVISOR_shared_info = (shared_info_t *)cur_space;
+	cur_space += PAGE_SIZE;
+
+	xen_store = (struct ringbuf_head *)cur_space;
+	cur_space += PAGE_SIZE;
+
+	console_page = (char *)cur_space;
+	cur_space += PAGE_SIZE;
 	
 	/*
 	 * shared_info is an unsigned long so this will randomly break if
@@ -1043,10 +1041,7 @@ initvalues(start_info_t *startinfo)
 	 */
 	shinfo = xen_start_info->shared_info;
 	PT_SET_MA(HYPERVISOR_shared_info, shinfo | PG_KERNEL);
-	
 	printk("#4\n");
-
-	
 	xen_store_ma = (((vm_paddr_t)xen_start_info->store_mfn) << PAGE_SHIFT);
 	PT_SET_MA(xen_store, xen_store_ma | PG_KERNEL);
 	console_page_ma = (((vm_paddr_t)xen_start_info->console.domU.mfn) << PAGE_SHIFT);


More information about the svn-src-projects mailing list