lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1996-2015 Free Software Foundation, Inc. |
| 2 | Contributed by Richard Henderson (rth@tamu.edu) |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library. If not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | /* Copy no more than COUNT bytes of the null-terminated string from |
| 20 | SRC to DST. If SRC does not cover all of COUNT, the balance is |
| 21 | zeroed. */ |
| 22 | |
| 23 | #include <sysdep.h> |
| 24 | |
| 25 | .set noat |
| 26 | .set noreorder |
| 27 | |
| 28 | .text |
| 29 | |
| 30 | ENTRY(strncpy) |
| 31 | ldgp gp, 0(pv) |
| 32 | #ifdef PROF |
| 33 | lda AT, _mcount |
| 34 | jsr AT, (AT), _mcount |
| 35 | #endif |
| 36 | .prologue 1 |
| 37 | |
| 38 | mov a0, v0 # set return value now |
| 39 | beq a2, $zerocount |
| 40 | jsr t9, __stxncpy # do the work of the copy |
| 41 | |
| 42 | bne a2, $multiword # do we have full words left? |
| 43 | |
| 44 | .align 3 |
| 45 | subq t8, 1, t2 # e0 : guess not |
| 46 | subq t10, 1, t3 # .. e1 : |
| 47 | or t2, t8, t2 # e0 : clear the bits between the last |
| 48 | or t3, t10, t3 # .. e1 : written byte and the last byte in |
| 49 | andnot t3, t2, t3 # e0 : COUNT |
| 50 | zap t0, t3, t0 # e1 : |
| 51 | stq_u t0, 0(a0) # e0 : |
| 52 | ret # .. e1 : |
| 53 | |
| 54 | $multiword: |
| 55 | subq t8, 1, t7 # e0 : clear the final bits in the prev |
| 56 | or t7, t8, t7 # e1 : word |
| 57 | zapnot t0, t7, t0 # e0 : |
| 58 | subq a2, 1, a2 # .. e1 : |
| 59 | stq_u t0, 0(a0) # e0 : |
| 60 | addq a0, 8, a0 # .. e1 : |
| 61 | |
| 62 | beq a2, 1f # e1 : |
| 63 | blbc a2, 0f # e1 : |
| 64 | |
| 65 | stq_u zero, 0(a0) # e0 : zero one word |
| 66 | subq a2, 1, a2 # .. e1 : |
| 67 | addq a0, 8, a0 # e0 : |
| 68 | beq a2, 1f # .. e1 : |
| 69 | |
| 70 | 0: stq_u zero, 0(a0) # e0 : zero two words |
| 71 | subq a2, 2, a2 # .. e1 : |
| 72 | stq_u zero, 8(a0) # e0 : |
| 73 | addq a0, 16, a0 # .. e1 : |
| 74 | bne a2, 0b # e1 : |
| 75 | unop |
| 76 | |
| 77 | 1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final |
| 78 | subq t10, 1, t7 # .. e1 : word |
| 79 | or t7, t10, t7 # e0 : |
| 80 | zap t0, t7, t0 # e1 (stall) |
| 81 | stq_u t0, 0(a0) # e0 : |
| 82 | |
| 83 | $zerocount: |
| 84 | ret # .. e1 : |
| 85 | |
| 86 | END(strncpy) |
| 87 | libc_hidden_builtin_def (strncpy) |