[sw/device] Implement memcpy()

This is a basic implementations, if desired it can be optimised in the
future (for ROM it doesn't seem too important and simplicity seems
more important).

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
diff --git a/sw/device/lib/common.h b/sw/device/lib/common.h
index f7f2840..b334fb8 100644
--- a/sw/device/lib/common.h
+++ b/sw/device/lib/common.h
@@ -6,6 +6,7 @@
 #define _COMMON_H_
 
 #include <stdbool.h>
+#include <stddef.h>
 #include <stdint.h>
 
 #ifdef SIMULATION
@@ -41,4 +42,6 @@
 #define BITLENGTH(X) \
   ((BITLENGTH_5(BITLENGTH_4(BITLENGTH_3(BITLENGTH_2(BITLENGTH_1(X)))))) & 0x7f)
 
+void *memcpy(void *restrict dest, const void *restrict src, size_t n);
+
 #endif
diff --git a/sw/device/lib/memcpy.c b/sw/device/lib/memcpy.c
new file mode 100644
index 0000000..8fd7401
--- /dev/null
+++ b/sw/device/lib/memcpy.c
@@ -0,0 +1,16 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+
+#include "sw/device/lib/common.h"
+
+void *memcpy(void *dest, const void *src, size_t n) {
+  char *dest_c = (char *)dest;
+  char *src_c = (char *)src;
+
+  for (; n > 0; n--) {
+    *dest_c++ = *src_c++;
+  }
+
+  return dest;
+}
diff --git a/sw/device/lib/meson.build b/sw/device/lib/meson.build
index d961c7f..d31292b 100644
--- a/sw/device/lib/meson.build
+++ b/sw/device/lib/meson.build
@@ -2,6 +2,16 @@
 # Licensed under the Apache License, Version 2.0, see LICENSE for details.
 # SPDX-License-Identifier: Apache-2.0
 
+# Memory Operations library (sw_lib_mem)
+sw_lib_mem = declare_dependency(
+  link_with: static_library(
+    'mem_ot',
+    sources: [
+      'memcpy.c',
+    ],
+  )
+)
+
 # UART library (sw_lib_uart)
 sw_lib_uart = declare_dependency(
   sources: [hw_ip_uart_reg_h],
@@ -60,6 +70,9 @@
       hw_ip_hmac_reg_h,
       'hw_sha256.c',
       'hmac.c',
+    ],
+    dependencies: [
+      sw_lib_mem,
     ]
   )
 )
@@ -75,6 +88,7 @@
     ],
     dependencies: [
       sw_lib_uart,
+      sw_lib_mem,
     ]
   )
 )
diff --git a/sw/device/lib/srcs.mk b/sw/device/lib/srcs.mk
index 3542f3f..9fdac3b 100644
--- a/sw/device/lib/srcs.mk
+++ b/sw/device/lib/srcs.mk
@@ -7,6 +7,6 @@
 
 GEN_HEADERS       += $(LIB_LOC_DIF_SRCS:.c=_regs.h)
 LIB_LOC_DIF_SRCS  += uart.c gpio.c spi_device.c flash_ctrl.c hmac.c usbdev.c rv_timer.c pinmux.c
-LIB_LOC_EXT_SRCS  += usb_controlep.c usb_simpleserial.c irq.c handler.c print_log.c irq_vectors.S
+LIB_LOC_EXT_SRCS  += usb_controlep.c usb_simpleserial.c irq.c handler.c print_log.c irq_vectors.S memcpy.c
 
 LIB_SRCS          += $(addprefix $(LIB_DIR)/, $(LIB_LOC_DIF_SRCS) $(LIB_LOC_EXT_SRCS))