TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crt_memset.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "crt_impl_private.h"
9 
10 void *memset(void *s, int c, size_t n)
11 {
12  union tfm_mem_addr_t p_mem;
13  uint32_t quad_pattern;
14 
15  p_mem.p_byte = (uint8_t *)s;
16  quad_pattern = (((uint8_t)c) << 24) | (((uint8_t)c) << 16) |
17  (((uint8_t)c) << 8) | ((uint8_t)c);
18 
19  while (n && (p_mem.uint_addr & (sizeof(uint32_t) - 1))) {
20  *p_mem.p_byte++ = (uint8_t)c;
21  n--;
22  }
23 
24  while (n >= sizeof(uint32_t)) {
25  *p_mem.p_qbyte++ = quad_pattern;
26  n -= sizeof(uint32_t);
27  }
28 
29  while (n--) {
30  *p_mem.p_byte++ = (uint8_t)c;
31  }
32 
33  return s;
34 }
uintptr_t uint_addr
uint32_t * p_qbyte
void * memset(void *s, int c, size_t n)
Definition: crt_memset.c:10