linker.ld: use all .data* and .bss* sections
[marionette.git] / libc / strcpy.S
blobd21fd7ddea01e3c2ddf4f5989fb60542d914be42
1 /*
2  *    Copyright (c) 2008 Joshua Phillips. All rights reserved.
3  *  
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions are
6  *  met:
7  *  
8  *    1. Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *    2. Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in
12  *       the documentation and/or other materials provided with the
13  *       distribution.
14  *  
15  *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  *  DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  *  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  *  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 .global strcpy
29 .global strncpy
31 .section .text.strcpy
32 strcpy:
33     pushl $-1
34     pushl 12(%esp)
35     pushl 12(%esp)
36     call strncpy
37     addl $12,%esp
38     ret
40 .section .text.strncpy
41 strncpy:
42     pushl %ebp
43     movl %esp,%ebp
44     pushl %esi
45     pushl %edi
46     cld
47     movl 8(%ebp),%edi
48     movl 12(%ebp),%esi
49     movl 16(%ebp),%ecx
51     lodsb
52     testb %al,%al
53     jz 1f
54     stosb
55     decl %ecx
56     jnz 1b
58     // pad the rest with null bytes
59     testl %ecx,%ecx
60     jz 2f
61     xorl %eax,%eax
63     stosb
64     decl %ecx
65     jnz 1b
67     // we're done
68     movl 8(%ebp),%eax
69     popl %edi
70     popl %esi
71     movl %ebp,%esp
72     popl %ebp
73     ret