source: mainline/kernel/generic/src/lib/mem.c

Last change on this file was b169619, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 20 months ago

Deduplicate mem functions

There are a number of functions which are copied between
kernel, libc, and potentially boot too. mem*() functions
are first such offenders. All this duplicate code will
be moved to directory 'common'.

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[f761f1eb]1/*
[df4ed85]2 * Copyright (c) 2001-2004 Jakub Jermar
[ac48fef]3 * Copyright (c) 2008 Jiri Svoboda
[f761f1eb]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[174156fd]30/** @addtogroup kernel_generic
[b45c443]31 * @{
32 */
33
[cf26ba9]34/**
[b45c443]35 * @file
[cb4f078]36 * @brief Memory string operations.
[cf26ba9]37 *
[cb4f078]38 * This file provides architecture independent functions to manipulate blocks
39 * of memory. These functions are optimized as much as generic functions of
40 * this type can be.
[cf26ba9]41 */
42
[b169619]43#include <memw.h>
[d99c1d2]44#include <typedefs.h>
[f761f1eb]45
[cb4f078]46/** Fill block of memory.
[d34657e]47 *
[cb4f078]48 * Fill cnt bytes at dst address with the value val.
[d34657e]49 *
[cb4f078]50 * @param dst Destination address to fill.
51 * @param cnt Number of bytes to fill.
52 * @param val Value to fill.
[d34657e]53 *
54 */
[cb4f078]55void memsetb(void *dst, size_t cnt, uint8_t val)
[f761f1eb]56{
[3abfe9a8]57 memset(dst, val, cnt);
[cb4f078]58}
59
60/** Fill block of memory.
[d34657e]61 *
[cb4f078]62 * Fill cnt words at dst address with the value val. The filling
63 * is done word-by-word.
[d34657e]64 *
[cb4f078]65 * @param dst Destination address to fill.
66 * @param cnt Number of words to fill.
67 * @param val Value to fill.
[d34657e]68 *
69 */
[cb4f078]70void memsetw(void *dst, size_t cnt, uint16_t val)
[f761f1eb]71{
[cb4f078]72 size_t i;
73 uint16_t *ptr = (uint16_t *) dst;
[a35b458]74
[cb4f078]75 for (i = 0; i < cnt; i++)
76 ptr[i] = val;
[f761f1eb]77}
78
[cc73a8a1]79/** @}
[b45c443]80 */
Note: See TracBrowser for help on using the repository browser.