source: trunk/packages/xen-3.1/xen-3.1/xen/arch/powerpc/of_handler/memset.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 1.7 KB
Line 
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 *
16 * Copyright (C) IBM Corp. 2005
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 */
20
21#include <xen/string.h>
22
23void *
24memset(void *s, int c, size_t n)
25{
26    uint8_t *ss = (uint8_t *)s;
27
28    if (n == 0) {
29        return s;
30    }
31
32    /* yes, I pulled the 2 out of this air */
33    if (n >= (2 * sizeof (ulong))) {
34        ulong val = 0;
35        ulong i;
36
37        /* construct val assignment from c */
38        if (c != 0) {
39            for (i = 0; i < sizeof (ulong); i++) {
40                val = (val << 8) | c;
41            }
42        }
43
44        /* do by character until aligned */
45        while (((ulong)ss & (sizeof (ulong) - 1)) > 0) {
46            *ss = c;
47            ++ss;
48            --n;
49        }
50
51        /* now do the aligned stores */
52        while (n >= sizeof (ulong)) {
53            *(ulong *)ss = val;
54            ss += sizeof (ulong);
55            n -= sizeof (ulong);
56        }
57    }
58    /* do that last unaligned bit */
59    while (n > 0) {
60        *ss = c;
61        ++ss;
62        --n;
63
64    }         
65
66    return s;
67}
Note: See TracBrowser for help on using the repository browser.