Index: boot/arch/arm32/meson.build
===================================================================
--- boot/arch/arm32/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/arm32/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -65,6 +65,6 @@
 	'src/mm.c',
 	'src/putchar.c',
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/division.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/arm32/src/main.c
===================================================================
--- boot/arch/arm32/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/arm32/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -40,5 +40,5 @@
 #include <halt.h>
 #include <printf.h>
-#include <memstr.h>
+#include <mem.h>
 #include <version.h>
 #include <macros.h>
Index: boot/arch/arm64/meson.build
===================================================================
--- boot/arch/arm64/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/arm64/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -48,9 +48,9 @@
 	'src/main.c',
 	'src/relocate.c',
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/efi.c',
 	'../../generic/src/gzip.c',
 	'../../generic/src/inflate.c',
 	'../../generic/src/kernel.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/payload.c',
 	'../../generic/src/printf.c',
Index: boot/arch/arm64/src/main.c
===================================================================
--- boot/arch/arm64/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/arm64/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -46,5 +46,5 @@
 #include <kernel.h>
 #include <macros.h>
-#include <memstr.h>
+#include <mem.h>
 #include <payload.h>
 #include <printf.h>
Index: boot/arch/ia64/meson.build
===================================================================
--- boot/arch/ia64/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/ia64/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -41,8 +41,8 @@
 	'src/pal_asm.S',
 	'src/putchar.c',
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/efi.c',
 	'../../genarch/src/division.c',
 	'../../generic/src/balloc.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/ia64/src/main.c
===================================================================
--- boot/arch/ia64/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/ia64/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -37,5 +37,5 @@
 #include <halt.h>
 #include <printf.h>
-#include <memstr.h>
+#include <mem.h>
 #include <version.h>
 #include <macros.h>
Index: boot/arch/mips32/meson.build
===================================================================
--- boot/arch/mips32/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/mips32/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -42,7 +42,7 @@
 	'src/main.c',
 	'src/putchar.c',
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/division.c',
 	'../../genarch/src/multiplication.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/mips32/src/main.c
===================================================================
--- boot/arch/mips32/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/mips32/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -33,5 +33,5 @@
 #include <halt.h>
 #include <printf.h>
-#include <memstr.h>
+#include <mem.h>
 #include <version.h>
 #include <macros.h>
Index: boot/arch/ppc32/meson.build
===================================================================
--- boot/arch/ppc32/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/ppc32/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -37,4 +37,5 @@
 	'src/ofw.c',
 
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/ofw.c',
 	'../../genarch/src/ofw_tree.c',
@@ -42,5 +43,4 @@
 	'../../genarch/src/multiplication.c',
 	'../../generic/src/balloc.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/ppc32/src/main.c
===================================================================
--- boot/arch/ppc32/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/ppc32/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -35,5 +35,5 @@
 #include <halt.h>
 #include <printf.h>
-#include <memstr.h>
+#include <mem.h>
 #include <version.h>
 #include <macros.h>
Index: boot/arch/riscv64/meson.build
===================================================================
--- boot/arch/riscv64/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/riscv64/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -37,5 +37,6 @@
 	'src/ucb.c',
 	'src/putchar.c',
-	'../../generic/src/memstr.c',
+
+	'../../../common/stdc/mem.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/sparc64/meson.build
===================================================================
--- boot/arch/sparc64/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/sparc64/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -37,8 +37,8 @@
 	'src/ofw.c',
 
+	'../../../common/stdc/mem.c',
 	'../../genarch/src/ofw.c',
 	'../../genarch/src/ofw_tree.c',
 	'../../generic/src/balloc.c',
-	'../../generic/src/memstr.c',
 	'../../generic/src/printf_core.c',
 	'../../generic/src/vprintf.c',
Index: boot/arch/sparc64/src/main.c
===================================================================
--- boot/arch/sparc64/src/main.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/arch/sparc64/src/main.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -36,5 +36,5 @@
 #include <halt.h>
 #include <printf.h>
-#include <memstr.h>
+#include <mem.h>
 #include <version.h>
 #include <macros.h>
Index: boot/genarch/src/ofw_tree.c
===================================================================
--- boot/genarch/src/ofw_tree.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/genarch/src/ofw_tree.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -33,5 +33,5 @@
 #include <str.h>
 #include <balloc.h>
-#include <memstr.h>
+#include <mem.h>
 
 static char path[OFW_TREE_PATH_MAX_LEN + 1];
Index: boot/generic/include/memstr.h
===================================================================
--- boot/generic/include/memstr.h	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ 	(revision )
@@ -1,49 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @file
- */
-
-#ifndef BOOT_MEMSTR_H_
-#define BOOT_MEMSTR_H_
-
-#include <stddef.h>
-
-extern void *memcpy(void *, const void *, size_t)
-    __attribute__((nonnull(1, 2)))
-    __attribute__((optimize("-fno-tree-loop-distribute-patterns")));
-extern void *memset(void *, int, size_t)
-    __attribute__((nonnull(1)))
-    __attribute__((optimize("-fno-tree-loop-distribute-patterns")));
-extern void *memmove(void *, const void *, size_t)
-    __attribute__((nonnull(1, 2)));
-
-#endif
-
-/** @}
- */
Index: boot/generic/src/gzip.c
===================================================================
--- boot/generic/src/gzip.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/generic/src/gzip.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -32,5 +32,5 @@
 #include <stddef.h>
 #include <errno.h>
-#include <memstr.h>
+#include <mem.h>
 #include <byteorder.h>
 #include <gzip.h>
Index: boot/generic/src/inflate.c
===================================================================
--- boot/generic/src/inflate.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/generic/src/inflate.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -69,5 +69,5 @@
 #include <stdint.h>
 #include <errno.h>
-#include <memstr.h>
+#include <mem.h>
 #include <inflate.h>
 
Index: boot/generic/src/memstr.c
===================================================================
--- boot/generic/src/memstr.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/*
- * Copyright (c) 2010 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <memstr.h>
-#include <stddef.h>
-#include <stdint.h>
-
-/** Move memory block without overlapping.
- *
- * Copy cnt bytes from src address to dst address. The source
- * and destination memory areas cannot overlap.
- *
- * @param dst Destination address to copy to.
- * @param src Source address to copy from.
- * @param cnt Number of bytes to copy.
- *
- * @return Destination address.
- *
- */
-void *memcpy(void *dst, const void *src, size_t cnt)
-{
-	uint8_t *dp = (uint8_t *) dst;
-	const uint8_t *sp = (uint8_t *) src;
-
-	while (cnt-- != 0)
-		*dp++ = *sp++;
-
-	return dst;
-}
-
-/** Fill block of memory.
- *
- * Fill cnt bytes at dst address with the value val.
- *
- * @param dst Destination address to fill.
- * @param val Value to fill.
- * @param cnt Number of bytes to fill.
- *
- * @return Destination address.
- *
- */
-void *memset(void *dst, int val, size_t cnt)
-{
-	uint8_t *dp = (uint8_t *) dst;
-
-	while (cnt-- != 0)
-		*dp++ = val;
-
-	return dst;
-}
-
-/** Move memory block with possible overlapping.
- *
- * Copy cnt bytes from src address to dst address. The source
- * and destination memory areas may overlap.
- *
- * @param dst Destination address to copy to.
- * @param src Source address to copy from.
- * @param cnt Number of bytes to copy.
- *
- * @return Destination address.
- *
- */
-void *memmove(void *dst, const void *src, size_t cnt)
-{
-	/* Nothing to do? */
-	if (src == dst)
-		return dst;
-
-	/* Non-overlapping? */
-	if ((dst >= src + cnt) || (src >= dst + cnt))
-		return memcpy(dst, src, cnt);
-
-	uint8_t *dp;
-	const uint8_t *sp;
-
-	/* Which direction? */
-	if (src > dst) {
-		/* Forwards. */
-		dp = dst;
-		sp = src;
-
-		while (cnt-- != 0)
-			*dp++ = *sp++;
-	} else {
-		/* Backwards. */
-		dp = dst + (cnt - 1);
-		sp = src + (cnt - 1);
-
-		while (cnt-- != 0)
-			*dp-- = *sp--;
-	}
-
-	return dst;
-}
-
-/** @}
- */
Index: boot/generic/src/payload.c
===================================================================
--- boot/generic/src/payload.c	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/generic/src/payload.c	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -36,5 +36,5 @@
 #include <gzip.h>
 #include <stdbool.h>
-#include <memstr.h>
+#include <mem.h>
 #include <errno.h>
 #include <str.h>
Index: boot/meson.build
===================================================================
--- boot/meson.build	(revision c89ae2562f477e91a8041f1bdff7ef9c6bec68b8)
+++ boot/meson.build	(revision b1696194837e19c7e4d446880d20ede25043bad4)
@@ -78,4 +78,5 @@
 		'../abi/arch'/BARCH/'include',
 		'../abi/include',
+		'../common/include',
 	)
 
