Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Sep 2006 23:16:43 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 106124 for review
Message-ID:  <200609142316.k8ENGhHs092409@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=106124

Change 106124 by imp@imp_lighthouse on 2006/09/14 23:16:11

	Replace p_memcpy and p_strcpy from the versions in boot2.c.  They
	are smaller and save between 24 and 140 bytes in various boot loaders
	depending on how heavily they were used.
	
	# boot2 is back up to a respectible 888 bytes free after this.  I'd
	# love to find another 136...

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/boot0spi/main.c#18 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/boot2/boot2.c#17 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/env_vars.c#15 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootiic/loader_prompt.c#18 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/loader_prompt.c#21 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#29 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac_init.c#4 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/lib.h#18 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/p_string.c#9 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/boot0spi/main.c#18 (text) ====

@@ -44,7 +44,7 @@
 	while ((len = xmodem_rx(addr)) == -1)
 		continue;
 	printf("\nDownloaded %u bytes.\n", len);
-	p_memcpy(addr3, addr, (len + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE * FLASH_PAGE_SIZE);
+	memcpy(addr3, addr, (len + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE * FLASH_PAGE_SIZE);
 	printf("Writing %u bytes to flash at %u\n", len, OFFSET);
 	for (i = 0; i < len; i+= FLASH_PAGE_SIZE) {
 		for (j = 0; j < 10; j++) {

==== //depot/projects/arm/src/sys/boot/arm/at91/boot2/boot2.c#17 (text+ko) ====

@@ -98,24 +98,6 @@
 static int dskread(void *, unsigned, unsigned);
 static int drvread(void *, unsigned, unsigned);
 
-static void memcpy(void *, const void *, int);
-static void
-memcpy(void *dst, const void *src, int len)
-{
-    const char *s = src;
-    char *d = dst;
-
-    while (len--)
-        *d++ = *s++;
-}
-
-static inline int
-strcmp(const char *s1, const char *s2)
-{
-    for (; *s1 == *s2 && *s1; s1++, s2++);
-    return (unsigned char)*s1 - (unsigned char)*s2;
-}
-
 #include "ufsread.c"
 
 static inline int

==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/env_vars.c#15 (text+ko) ====

@@ -93,7 +93,7 @@
 		if (size < 0) {
 			continue;
 		}
-		p_memcpy(cPtr, boot_commands[i], copySize);
+		memcpy(cPtr, boot_commands[i], copySize);
 		cPtr += copySize;
 		*cPtr++ = 0;
 	}

==== //depot/projects/arm/src/sys/boot/arm/at91/bootiic/loader_prompt.c#18 (text+ko) ====

@@ -93,7 +93,7 @@
 	int	i;
 
 	for (i = 0; CommandTable[i].command != COMMAND_FINAL_FLAG; ++i)
-		if (!p_strcmp(CommandTable[i].c_string, cPtr))
+		if (!strcmp(CommandTable[i].c_string, cPtr))
 			return (CommandTable[i].command);
 
 	return (COMMAND_INVALID);
@@ -188,7 +188,7 @@
 			to = (char *)p_ASCIIToHex(argv[1]);
 			from = (char *)p_ASCIIToHex(argv[2]);
 			size = p_ASCIIToHex(argv[3]);
-			p_memcpy(to, from, size);
+			memcpy(to, from, size);
 		}
 		break;
 	}

==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/loader_prompt.c#21 (text+ko) ====

@@ -125,7 +125,7 @@
 	int	i;
 
 	for (i = 0; CommandTable[i].command != COMMAND_FINAL_FLAG; ++i)
-		if (!p_strcmp(CommandTable[i].c_string, cPtr))
+		if (!strcmp(CommandTable[i].c_string, cPtr))
 			return (CommandTable[i].command);
 
 	return (COMMAND_INVALID);

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac.c#29 (text+ko) ====

@@ -75,7 +75,7 @@
 
 	p_memset((char*)p_ARP->dest_mac, 0xFF, 6);
 
-	p_memcpy((char*)p_ARP->src_mac, (char*)localMACAddr, 6);
+	memcpy(p_ARP->src_mac, localMACAddr, 6);
 
 	p_ARP->frame_type = SWAP16(PROTOCOL_ARP);
 	p_ARP->hard_type  = SWAP16(1);
@@ -84,13 +84,10 @@
 	p_ARP->prot_size  = 4;
 	p_ARP->operation  = SWAP16(ARP_REQUEST);
 
-	p_memcpy((char*)p_ARP->sender_mac, (char*)localMACAddr, 6);
-
-	p_memcpy((char*)p_ARP->sender_ip, (char*)localIPAddr, 4);
-
+	memcpy(p_ARP->sender_mac, localMACAddr, 6);
+	memcpy(p_ARP->sender_ip, localIPAddr, 4);
 	p_memset((char*)p_ARP->target_mac, 0, 6);
-
-	p_memcpy((char*)p_ARP->target_ip, (char*)serverIPAddr, 4);
+	memcpy(p_ARP->target_ip, serverIPAddr, 4);
 
 	// wait until transmit is available
 	while (!(*AT91C_EMAC_TSR & AT91C_EMAC_BNQ)) ;
@@ -115,10 +112,8 @@
 	udp_header_t		*udpHdr;
 	unsigned		t_checksum;
 
-	p_memcpy((char*)macHdr->dest_mac, (char*)serverMACAddr, 6);
-
-	p_memcpy((char*)macHdr->src_mac, (char*)localMACAddr, 6);
-
+	memcpy(macHdr->dest_mac, serverMACAddr, 6);
+	memcpy(macHdr->src_mac, localMACAddr, 6);
 	macHdr->proto_mac = SWAP16(PROTOCOL_IP);
 
 	ipHdr = (ip_header_t*)&macHdr->packet_length;
@@ -132,10 +127,9 @@
 	ipHdr->ip_p = PROTOCOL_UDP;
 	ipHdr->ip_sum = 0;
 
-	p_memcpy((char*)ipHdr->ip_src, (char*)localIPAddr, 4);
+	memcpy(ipHdr->ip_src, localIPAddr, 4);
+	memcpy(ipHdr->ip_dst, serverIPAddr, 4);
 
-	p_memcpy((char*)ipHdr->ip_dst, (char*)serverIPAddr, 4);
-
 	ipHdr->ip_sum = SWAP16(IP_checksum((unsigned short*)ipHdr, 20));
 
 	udpHdr = (udp_header_t*)(ipHdr + 1);
@@ -145,7 +139,7 @@
 	udpHdr->udp_len   = SWAP16(8 + tftpLength);
 	udpHdr->udp_cksum = 0;
 
-	p_memcpy((char*)udpHdr+8, tftpData, tftpLength);
+	memcpy(udpHdr+8, tftpData, tftpLength);
 
 	t_checksum = IP_checksum((unsigned short*)ipHdr + 6, (16 + tftpLength));
 
@@ -205,7 +199,7 @@
 
 	if (block_num == (ackBlock + 1)) {
 		++ackBlock;
-		p_memcpy(dlAddress, data, len);
+		memcpy(dlAddress, data, len);
 		dlAddress += len;
 		lastSize += len;
 		if (ackBlock % 128 == 0)
@@ -267,8 +261,7 @@
 
 				serverMACSet = 1;
 
-				p_memcpy((char*)serverMACAddr,
-					(char*)p_ARP->sender_mac, 6);
+				memcpy(serverMACAddr, p_ARP->sender_mac, 6);
 			}
 		} else if (p_ARP->operation == SWAP16(ARP_REQUEST)) {
 			// ARP REPLY operation
@@ -299,7 +292,7 @@
 		break;
 	case SWAP16(PROTOCOL_IP):
 		pIpHeader = (ip_header_t*)(pData + 14);			
-		p_memcpy((char*)pHeader, (char*)pIpHeader,sizeof(ip_header_t));
+		memcpy(pHeader, pIpHeader, sizeof(ip_header_t));
 		
 		if (pIpHeader->ip_p == PROTOCOL_UDP) {
 			udp_header_t	*udpHdr;

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/emac_init.c#4 (text+ko) ====

@@ -82,7 +82,7 @@
 	/* enable the peripheral clock before using EMAC */
 	pPMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_EMAC);
 
-	p_memcpy(localMACAddr, mac, 6);
+	memcpy(localMACAddr, mac, 6);
 	localMAClow = (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5];
 	localMAChigh = (mac[0] << 8) | mac[1];
 	localMACSet = 1;

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/lib.h#18 (text) ====

@@ -58,8 +58,8 @@
 void p_memset(char *buffer, char value, int size);
 int p_strlen(const char *buffer);
 char *p_strcpy(char *to, const char *from);
-void p_memcpy(char *to, const char *from, unsigned size);
+void memcpy(void *to, const void *from, unsigned size);
 int p_memcmp(const char *to, const char *from, unsigned size);
-int p_strcmp(const char *to, const char *from);
+int strcmp(const char *to, const char *from);
 
 #endif

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/p_string.c#9 (text+ko) ====

@@ -74,21 +74,16 @@
 	return (to);
 }
 
-/*
- * .KB_C_FN_DEFINITION_START
- * void p_memcpy(char *, char *, unsigned)
- *  This global function copies data from the first pointer to the second
- * pointer for the specified number of bytes.
- * .KB_C_FN_DEFINITION_END
- */
 void
-p_memcpy(char *to, const char *from, unsigned size)
+memcpy(void *dst, const void *src, unsigned len)
 {
-	while (size--)
-		*to++ = *from++;
+    const char *s = src;
+    char *d = dst;
+
+    while (len--)
+        *d++ = *s++;
 }
 
-
 /*
  * .KB_C_FN_DEFINITION_START
  * int p_memcmp(char *to, char *from, unsigned size)
@@ -109,19 +104,14 @@
 
 /*
  * .KB_C_FN_DEFINITION_START
- * int p_strcmp(char *to, char *from)
+ * int strcmp(char *to, char *from)
  *  This global function compares string at to against string at from.
  * Returns 0 if the locations are equal.
  * .KB_C_FN_DEFINITION_END
  */
 int
-p_strcmp(const char *to, const char *from)
+strcmp(const char *s1, const char *s2)
 {
-
-	while (*to && *from && (*to == *from)) {
-		++to;
-		++from;
-	}
-
-	return (!((!*to) && (*to == *from)));
+    for (; *s1 == *s2 && *s1; s1++, s2++);
+    return (unsigned char)*s1 - (unsigned char)*s2;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609142316.k8ENGhHs092409>