SPM: Restructure memory operation functions

SPM calls spm_memcpy/spm_memset, and SP just calls memset, memcpy,
memmove and memcmp. SPM has its own header files for
spm_memcpy/spm_memset prototypes, while SP relies on toolchain headers
string.h for prototypes.
As -fno-builtin is applied, our memcpy would replace the same function
in toolchain library.

Change-Id: Iab240c96e06d55144daa0125b2d17574b648f9e1
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/partitions/lib/sprt/crt_memset.c b/secure_fw/partitions/lib/sprt/crt_memset.c
new file mode 100644
index 0000000..92dd5a1
--- /dev/null
+++ b/secure_fw/partitions/lib/sprt/crt_memset.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "crt_impl_private.h"
+
+void *memset(void *s, int c, size_t n)
+{
+    union tfm_mem_addr_t p_mem;
+    uint32_t quad_pattern;
+
+    p_mem.p_byte = (uint8_t *)s;
+    quad_pattern = (((uint8_t)c) << 24) | (((uint8_t)c) << 16) |
+                   (((uint8_t)c) << 8) | ((uint8_t)c);
+
+    while (n && (p_mem.uint_addr & (sizeof(uint32_t) - 1))) {
+        *p_mem.p_byte++ = (uint8_t)c;
+        n--;
+    }
+
+    while (n >= sizeof(uint32_t)) {
+        *p_mem.p_qbyte++ = quad_pattern;
+        n -= sizeof(uint32_t);
+    }
+
+    while (n--) {
+        *p_mem.p_byte++ = (uint8_t)c;
+    }
+
+    return s;
+}