PERFORCE change 89382 for review

Kip Macy kmacy at FreeBSD.org
Sun Jan 8 13:43:56 PST 2006


http://perforce.freebsd.org/chv.cgi?CH=89382

Change 89382 by kmacy at kmacy:freebsd7_xen3 on 2006/01/08 21:43:38

	remove unused / unloved NFS_ROOT code
	remove unusable debug code
	remove dead defines in xen-os.h
	add crude boot memory allocator for use early in initialization to simplify porting
	from linux

Affected files ...

.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_machdep.c#4 edit
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-os.h#2 edit

Differences ...

==== //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_machdep.c#4 (text+ko) ====

@@ -86,233 +86,7 @@
 
 void ni_cli(void);
 void ni_sti(void);
-#ifdef NFS_ROOT
-
-static int
-xdr_opaque_decode(struct mbuf **mptr, u_char *buf, int len)
-{
-	struct mbuf *m;
-	int alignedlen;
-
-	m = *mptr;
-	alignedlen = ( len + 3 ) & ~3;
-
-	if (m->m_len < alignedlen) {
-		m = m_pullup(m, alignedlen);
-		if (m == NULL) {
-			*mptr = NULL;
-			return EBADRPC;
-		}
-	}
-	bcopy(mtod(m, u_char *), buf, len);
-	m_adj(m, alignedlen);
-	*mptr = m;
-	return 0;
-}
-
-
-static int
-getdec(char **ptr)
-{
-	char *p;
-	int ret;
-
-	p = *ptr;
-	ret = 0;
-	if ((*p < '0') || (*p > '9'))
-		return -1;
-	while ((*p >= '0') && (*p <= '9')) {
-		ret = ret * 10 + (*p - '0');
-		p++;
-	}
-	*ptr = p;
-	return ret;
-}
-
-int
-setinaddr(struct sockaddr_in *addr,  char *ipstr)
-{
-	unsigned int ip;
-	int val;
-
-	ip = 0;
-	if (((val = getdec(&ipstr)) < 0) || (val > 255))
-		return 1;
-	ip = val << 24;
-	if (*ipstr != '.')
-		return 1;
-	ipstr++;
-	if (((val = getdec(&ipstr)) < 0) || (val > 255))
-		return 1;
-	ip |= (val << 16);
-	if (*ipstr != '.')
-		return 1;
-	ipstr++;
-	if (((val = getdec(&ipstr)) < 0) || (val > 255))
-		return 1;
-	ip |= (val << 8);
-	if (*ipstr != '.')
-		return 1;
-	ipstr++;
-	if (((val = getdec(&ipstr)) < 0) || (val > 255))
-		return 1;
-	ip |= val;
-
-	addr->sin_addr.s_addr = htonl(ip);
-	addr->sin_len = sizeof(struct sockaddr_in);
-	addr->sin_family = AF_INET;
-
-	return 0;
-}
-
-static int
-hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa)
-{
-	char *cp;
-	u_int32_t a[6];
-	int count;
-
-	bzero(sa, sizeof(*sa));
-	sa->sdl_len = sizeof(*sa);
-	sa->sdl_family = AF_LINK;
-	sa->sdl_type = IFT_ETHER;
-	sa->sdl_alen = ETHER_ADDR_LEN;
-	if ((cp = getenv(ev)) == NULL)
-		return (1);
-	count = sscanf(cp, "%x:%x:%x:%x:%x:%x",
-		       &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
-	freeenv(cp);
-	if (count != 6)
-		return (1);
-	sa->sdl_data[0] = a[0];
-	sa->sdl_data[1] = a[1];
-	sa->sdl_data[2] = a[2];
-	sa->sdl_data[3] = a[3];
-	sa->sdl_data[4] = a[4];
-	sa->sdl_data[5] = a[5];
-	return (0);
-}
-extern int in_control(struct socket *so, u_long cmd,
-		      caddr_t data, struct ifnet *ifp,
-		      struct thread *td);
-
-static int
-xen_setnetwork(void)
-{
-	int error = 0;
-	struct ifaddr *ifa;
-	struct ifnet *ifp;
-	struct sockaddr_dl *sdl, ourdl;
-
-	if (sizeof(struct sockaddr) != sizeof(struct sockaddr_in))
-		panic("sizes not equal\n");
-
-	if (hwaddr_to_sockaddr("boot.netif.hwaddr", &ourdl)) {
-		printf("nfs_diskless: no hardware address\n");
-		return -1;
-	}
-
-
-	ifa = NULL;
-	IFNET_RLOCK();
-	TAILQ_FOREACH(ifp, &ifnet, if_link) {
-		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
-			if ((ifa->ifa_addr->sa_family == AF_LINK) &&
-			    (sdl = ((struct sockaddr_dl *)ifa->ifa_addr))) {
-				if ((sdl->sdl_type == ourdl.sdl_type) &&
-				    (sdl->sdl_alen == ourdl.sdl_alen) &&
-				    !bcmp(sdl->sdl_data + sdl->sdl_nlen,
-					  ourdl.sdl_data + ourdl.sdl_nlen,
-					  sdl->sdl_alen)) {
-					IFNET_RUNLOCK();
-					goto match_done;
-				}
-			}
-		}
-	}
-	IFNET_RUNLOCK();
-	printf("nfs_diskless: no interface\n");
-	return -1; /* no matching interface */
- match_done:
 
-	if (getenv("boot.netif.ip") && getenv("boot.netif.gateway") && 
-	    getenv("boot.netif.netmask")) {
-		struct ifaliasreq ifra;
-		char *ip;
-	
-		bzero(&ifra, sizeof(ifra));
-		strcpy(ifra.ifra_name, "xn0");
-		ip = getenv("boot.netif.ip");
-		setinaddr((struct sockaddr_in *)&(ifra.ifra_addr), ip);
-		printf("setting ip to %s\n", ip);
-		ip = getenv("boot.netif.netmask");
-		setinaddr((struct sockaddr_in *)&ifra.ifra_mask, ip);
-		setinaddr((struct sockaddr_in *)&ifra.ifra_broadaddr, "255.255.255.255");
-
-
-		if ((error = in_control(NULL, SIOCAIFADDR,  (caddr_t) &ifra, ifp, curthread))) 
-			printf("couldn't set interface address %d\n", error);
-#if 0
-		if ((error = xn_ioctl(ifp, SIOCSIFNETMASK, (caddr_t)&ifa)))
-			printf("couldn't set interface netmask %d\n", error);
-#endif
-	}
-	return error;
-}
-
-int
-xen_setnfshandle(void) 
-{
-	char *path, *ip;
-	u_char fhp[NFSX_V2FH];
-	int error = 0;
-	struct sockaddr_in sin_local, *sin ;
-	struct mbuf *m;
-
-	if ((error = xen_setnetwork())) 
-		return error;
-    
-	sin = &sin_local; 
-    
-	path = getenv("boot.nfsroot.path");
-	ip = getenv("boot.nfsroot.server");
-
-	/* we aren't configured for NFS root */ 
-	if (!path || !ip)
-		return 0;
-
-	error = setinaddr(sin, ip);
-	if (error) {
-		printf("invalid ip address %s\n", ip);
-		return error;
-	}
- 
-	error = krpc_portmap(sin, RPCPROG_MNT, RPCMNT_VER1,
-			     &sin->sin_port, curthread);
-	if (error) { 
-		printf("failed to find port number for mountd\n");
-		return error;
-	}
-	m = xdr_string_encode(path, strlen(path));
-    
-	/* Do RPC to mountd */
-	error = krpc_call(sin, RPCPROG_MNT, RPCMNT_VER1,
-			  RPCMNT_MOUNT, &m, NULL, curthread);
-	if (error) {
-		printf("call to mountd failed\n");
-		return error;
-	}
-    
-	if (xdr_opaque_decode(&m, fhp, NFSX_V2FH) != 0) {
-		printf("failed to decode nfs file handle\n");
-		return error;
-	}
-
-	setenv("boot.nfsroot.nfshandle", fhp);
-
-	return 0;
-}
-#endif
 void
 ni_cli(void)
 {
@@ -575,6 +349,8 @@
 extern unsigned long *SMPpt;
 extern  struct user	*proc0uarea;
 extern  vm_offset_t	proc0kstack;
+char *bootmem_start, *bootmem_current, *bootmem_end; 
+
 pteinfo_t *pteinfo_list;
 void initvalues(start_info_t *startinfo);
 
@@ -587,7 +363,32 @@
 #define PFNTOV(x) (((unsigned long)(x)  << PAGE_SHIFT) + KERNBASE)
 #define PG_KERNEL  (PG_V | PG_A | PG_RW | PG_M)
 
+void *
+bootmem_alloc(unsigned int size) 
+{
+	char *retptr;
+	
+	retptr = bootmem_current;
+	PANIC_IF(retptr + size > bootmem_end);
+	bootmem_current += size;
 
+	return retptr;
+}
+
+void 
+bootmem_free(void *ptr, unsigned int size) 
+{
+	char *tptr;
+	
+	tptr = ptr;
+	PANIC_IF(tptr != bootmem_current - size ||
+		bootmem_current - size < bootmem_start);	
+
+	bootmem_current -= size;
+}
+
+
+
 void
 initvalues(start_info_t *startinfo)
 { 
@@ -639,6 +440,11 @@
 	ldt = (union descriptor *)PFNTOV(tmpindex);
 	tmpindex++; 
 
+	/* allocate 4 pages for bootmem allocator */
+	bootmem_start = bootmem_current = (char *)PFNTOV(tmpindex);
+	tmpindex += 4;
+	bootmem_end = (char *)PFNTOV(tmpindex);
+	
 	/* initialize page directory shadow page */
 	pdir_shadow = (vm_offset_t *)PFNTOV(tmpindex);
 	i686_pagezero(pdir_shadow);
@@ -775,41 +581,3 @@
 
 	panic("xen_failsafe_handler called!\n");
 }
-
-
-
-
-#if defined(XENDEBUG)
-static void
-xpmap_dump_pt(pt_entry_t *ptp, int p)
-{
-	pt_entry_t pte;
-	int j;
-	int bufpos;
-
-	pte = xpmap_ptom((uint32_t)ptp - KERNTEXTOFF);
-	PRINTK(("%03x: %p(%p) %08x\n", p, ptp, (void *)pte, p << PDRSHIFT));
-
-	bufpos = 0;
-	for (j = 0; j < PTES_PER_PTP; j++) {
-		if ((ptp[j] & PG_V) == 0)
-			continue;
-		pte = ptp[j] /* & PG_FRAME */;
-		bufpos += sprintf(XBUF + bufpos, "%x:%03x:%08x ",
-				  p, j, pte);
-		if (bufpos > 70) {
-			int k;
-			sprintf(XBUF + bufpos, "\n");
-			PRINTK((XBUF));
-			bufpos = 0;
-			for (k = 0; k < 1000000; k++);
-		}
-	}
-	if (bufpos) {
-		PRINTK((XBUF));
-		bufpos = 0;
-	}
-}
-#endif
-
-

==== //depot/projects/xen3/src/sys/i386-xen/include/xen-os.h#2 (text+ko) ====

@@ -38,32 +38,12 @@
 
 #define per_cpu(var, cpu)           (*((void)cpu, &per_cpu__##var))
 
-
-/*
- * These are the segment descriptors provided for us by the hypervisor.
- * For now, these are hardwired -- guest OSes cannot update the GDT
- * or LDT.
- * 
- * It shouldn't be hard to support descriptor-table frobbing -- let me 
- * know if the BSD or XP ports require flexibility here.
+/* crude memory allocator for memory allocation early in 
+ *  boot
  */
-
+void *bootmem_alloc(unsigned int size);
+void bootmem_free(void *ptr, unsigned int size);
 
-/*
- * these are also defined in hypervisor-if.h but can't be pulled in as
- * they are used in start of day assembly. Need to clean up the .h files
- * a bit more...
- */
-#if 0
-#ifndef FLAT_RING1_CS
-#define FLAT_RING1_CS		0x0819
-#define FLAT_RING1_DS		0x0821
-#define FLAT_RING3_CS		0x082b
-#define FLAT_RING3_DS		0x0833
-#endif
-#endif
-#define __KERNEL_CS        FLAT_RING1_CS
-#define __KERNEL_DS        FLAT_RING1_DS
 
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef __ASSEMBLY__


More information about the p4-projects mailing list