~ubuntu-branches/ubuntu/lucid/avr-libc/lucid

« back to all changes in this revision

Viewing changes to libc/pmstring/strlcpy_P.S

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2005-03-19 11:16:14 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050319111614-4g01s2ftv5x5nxf3
Tags: 1:1.2.3-3
* Added build depends on netpbm
* Added build depends on tetex-extra

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   AVR LIBC
 
3
   strlcpy_P()
 
4
 
 
5
   Copyright (c) 2003, Eric B. Weddington
 
6
   All rights reserved.
 
7
 
 
8
   Redistribution and use in source and binary forms, with or without
 
9
   modification, are permitted provided that the following conditions are met:
 
10
 
 
11
   * Redistributions of source code must retain the above copyright
 
12
     notice, this list of conditions and the following disclaimer.
 
13
   * Redistributions in binary form must reproduce the above copyright
 
14
     notice, this list of conditions and the following disclaimer in
 
15
     the documentation and/or other materials provided with the
 
16
     distribution.
 
17
   * Neither the name of the copyright holders nor the names of
 
18
     contributors may be used to endorse or promote products derived
 
19
     from this software without specific prior written permission.
 
20
 
 
21
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
22
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
23
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
24
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
25
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
26
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
27
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
28
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
29
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
30
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
31
  POSSIBILITY OF SUCH DAMAGE.
 
32
 
 
33
*/
 
34
 
 
35
 
 
36
/** \ingroup avr_pgmspace
 
37
    \fn size_t strlcpy_P (char *dst, PGM_P, size_t siz)
 
38
    \brief Copy a string from progmem to RAM.
 
39
 
 
40
    Copy src to string dst of size siz.  At most siz-1 characters will be
 
41
    copied.  Always NULL terminates (unless siz == 0).
 
42
 
 
43
    \returns The strlcpy_P() function returns strlen(src). If retval >= siz,
 
44
    truncation occurred.  */
 
45
 
 
46
#if !defined(DOXYGEN)
 
47
 
 
48
#include "gasava.inc"
 
49
#include "macros.inc"
 
50
 
 
51
#define dst_hi          r25
 
52
#define dst_lo          r24
 
53
#define src_hi          r23
 
54
#define src_lo          r22
 
55
#define siz_hi          r21
 
56
#define siz_lo          r20
 
57
#define rWord           r24
 
58
#define rWord_hi        r25
 
59
#define rWord_lo        r24
 
60
#define Z_hi            r31
 
61
#define Z_lo            r30
 
62
 
 
63
        .text
 
64
        .global _U(strlcpy_P)
 
65
        .type   _U(strlcpy_P), @function
 
66
 
 
67
_U(strlcpy_P):
 
68
        LOAD_X  (dst_lo, dst_hi)        ; X = dst
 
69
        LOAD_Z  (src_lo, src_hi)        ; Z = src
 
70
        cp      siz_lo, __zero_reg__
 
71
        cpc     siz_hi, __zero_reg__    ; size == 0 ?
 
72
        breq    .strlcpy_P_truncated
 
73
 
 
74
.strlcpy_P_copy_loop:                   ; copy src to dst
 
75
        subi    siz_lo, lo8(-(-1))
 
76
        sbci    siz_hi, hi8(-(-1))      ; decrement siz
 
77
        breq    1f                      ; --> siz chars copied
 
78
        LPM_R0_ZP                       ; get next src char
 
79
        st      X+, __tmp_reg__         ; copy char
 
80
        tst     __tmp_reg__             ; end of src string ?
 
81
        breq    .strlcpy_P_len          ; --> all src chars copied
 
82
        rjmp    .strlcpy_P_copy_loop    ; next char
 
83
1:      st      X, __zero_reg__         ; truncate dst string
 
84
 
 
85
.strlcpy_P_truncated:                   ; find Z = end of src string
 
86
        LPM_R0_ZP                       ; get next char from src
 
87
        tst     __tmp_reg__             ; end of src string ?
 
88
        brne    .strlcpy_P_truncated    ; next char
 
89
 
 
90
.strlcpy_P_len:                         ; calculate strlen(src)
 
91
        sub     Z_lo, src_lo
 
92
        sbc     Z_hi, src_hi            ; Z points past \0
 
93
        sbiw    Z_lo, 1
 
94
        #if __AVR_ENHANCED__
 
95
        movw    rWord, Z_lo
 
96
        #else
 
97
        mov     rWord_lo, Z_lo
 
98
        mov     rWord_hi, Z_hi
 
99
        #endif
 
100
        ret
 
101
 
 
102
.strlcpy_P_end:
 
103
        .size   _U(strlcpy_P), .strlcpy_P_end - _U(strlcpy_P)
 
104
 
 
105
#endif /* not DOXYGEN */