| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * Hypervisor Software File: __align_cpy_2.s |
| 5 | * |
| 6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 7 | * |
| 8 | * - Do no alter or remove copyright notices |
| 9 | * |
| 10 | * - Redistribution and use of this software in source and binary forms, with |
| 11 | * or without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistribution of source code must retain the above copyright notice, |
| 15 | * this list of conditions and the following disclaimer. |
| 16 | * |
| 17 | * - Redistribution in binary form must reproduce the above copyright notice, |
| 18 | * this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * |
| 21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors |
| 22 | * may be used to endorse or promote products derived from this software |
| 23 | * without specific prior written permission. |
| 24 | * |
| 25 | * This software is provided "AS IS," without a warranty of any kind. |
| 26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, |
| 27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A |
| 28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN |
| 29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR |
| 30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR |
| 31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN |
| 32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR |
| 33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE |
| 34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, |
| 35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF |
| 36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| 37 | * |
| 38 | * You acknowledge that this software is not designed, licensed or |
| 39 | * intended for use in the design, construction, operation or maintenance of |
| 40 | * any nuclear facility. |
| 41 | * |
| 42 | * ========== Copyright Header End ============================================ |
| 43 | */ |
| 44 | /* |
| 45 | * Copyright (c) 1997, Sun Microsystems, Inc. |
| 46 | * All rights reserved. |
| 47 | */ |
| 48 | |
| 49 | .ident "@(#)__align_cpy_2.s 1.1 97/02/10 SMI" |
| 50 | |
| 51 | .file "__align_cpy_2.s" |
| 52 | |
| 53 | /* |
| 54 | * __align_cpy_2(s1, s2, len) |
| 55 | * |
| 56 | * Copy s2 to s1, always copy n bytes. |
| 57 | * Note: this does not work for overlapped copies, bcopy() does |
| 58 | * This routine is copied from memcpy.s, with all values doubled. |
| 59 | * No attempt has been made to improve the comments or performance. |
| 60 | * |
| 61 | */ |
| 62 | |
| 63 | #include <sys/asm_linkage.h> |
| 64 | |
| 65 | !#include "synonyms.h" |
| 66 | |
| 67 | ENTRY(__align_cpy_2) |
| 68 | cmp %o0, %o1 |
| 69 | be,pn %xcc, .done ! Identical addresses--done. |
| 70 | mov %o0, %g5 ! save des address for return val |
| 71 | cmp %o2, 18 ! for small counts copy bytes |
| 72 | ble,pn %xcc, .dbytecp |
| 73 | andcc %o1, 6, %o5 ! is src 8-byte aligned |
| 74 | bz,pn %xcc, .aldst |
| 75 | cmp %o5, 4 ! is src 4-byte aligned |
| 76 | be,pt %xcc, .s2algn |
| 77 | cmp %o5, 6 ! src is 2-byte aligned |
| 78 | .s1algn:lduh [%o1], %o3 ! move 2 or 6 bytes to align it |
| 79 | inc 2, %o1 |
| 80 | sth %o3, [%g5] ! move 2 bytes to align src |
| 81 | inc 2, %g5 |
| 82 | bne,pt %xcc, .s2algn |
| 83 | dec 2, %o2 |
| 84 | b .ald ! now go align dest |
| 85 | andcc %g5, 6, %o5 |
| 86 | |
| 87 | .s2algn:lduw [%o1], %o3 ! know src is 4-byte aligned |
| 88 | inc 4, %o1 |
| 89 | srlx %o3, 16, %o4 |
| 90 | sth %o4, [%g5] ! have to do 2-bytes, |
| 91 | sth %o3, [%g5 + 2] ! don't know dst alignment |
| 92 | inc 4, %g5 |
| 93 | dec 4, %o2 |
| 94 | |
| 95 | .aldst: andcc %g5, 6, %o5 ! align the destination address |
| 96 | .ald: bz,pn %xcc, .w4cp |
| 97 | cmp %o5, 4 |
| 98 | bz,pn %xcc, .w2cp |
| 99 | cmp %o5, 6 |
| 100 | .w3cp: ldx [%o1], %o4 |
| 101 | inc 8, %o1 |
| 102 | srlx %o4, 48, %o5 |
| 103 | sth %o5, [%g5] |
| 104 | bne,pt %xcc, .w1cp |
| 105 | inc 2, %g5 |
| 106 | dec 2, %o2 |
| 107 | andn %o2, 6, %o3 ! o3 is aligned word count |
| 108 | sub %o1, %g5, %o1 ! g5 gets the difference |
| 109 | |
| 110 | 1: sllx %o4, 16, %g1 ! save residual bytes |
| 111 | ldx [%o1+%g5], %o4 |
| 112 | deccc 8, %o3 |
| 113 | srlx %o4, 48, %o5 ! merge with residual |
| 114 | or %o5, %g1, %g1 |
| 115 | stx %g1, [%g5] |
| 116 | bnz,pt %xcc, 1b |
| 117 | inc 8, %g5 |
| 118 | sub %o1, 6, %o1 ! used two bytes of last word read |
| 119 | b 7f |
| 120 | and %o2, 6, %o2 |
| 121 | |
| 122 | .w1cp: srlx %o4, 16, %o5 |
| 123 | st %o5, [%g5] |
| 124 | inc 4, %g5 |
| 125 | dec 6, %o2 |
| 126 | andn %o2, 6, %o3 |
| 127 | sub %o1, %g5, %o1 ! g5 gets the difference |
| 128 | |
| 129 | 2: sllx %o4, 48, %g1 ! save residual bytes |
| 130 | ldx [%o1+%g5], %o4 |
| 131 | deccc 8, %o3 |
| 132 | srlx %o4, 16, %o5 ! merge with residual |
| 133 | or %o5, %g1, %g1 |
| 134 | stx %g1, [%g5] |
| 135 | bnz,pt %xcc, 2b |
| 136 | inc 8, %g5 |
| 137 | sub %o1, 2, %o1 ! used six bytes of last word read |
| 138 | b 7f |
| 139 | and %o2, 6, %o2 |
| 140 | |
| 141 | .w2cp: ldx [%o1], %o4 |
| 142 | inc 8, %o1 |
| 143 | srlx %o4, 32, %o5 |
| 144 | st %o5, [%g5] |
| 145 | inc 4, %g5 |
| 146 | dec 4, %o2 |
| 147 | andn %o2, 6, %o3 ! o3 is aligned word count |
| 148 | sub %o1, %g5, %o1 ! g5 gets the difference |
| 149 | |
| 150 | 3: sllx %o4, 32, %g1 ! save residual bytes |
| 151 | ldx [%o1+%g5], %o4 |
| 152 | deccc 8, %o3 |
| 153 | srlx %o4, 32, %o5 ! merge with residual |
| 154 | or %o5, %g1, %g1 |
| 155 | stx %g1, [%g5] |
| 156 | bnz,pt %xcc, 3b |
| 157 | inc 8, %g5 |
| 158 | sub %o1, 4, %o1 ! used four bytes of last word read |
| 159 | b 7f |
| 160 | and %o2, 6, %o2 |
| 161 | |
| 162 | .w4cp: andn %o2, 6, %o3 ! o3 is aligned word count |
| 163 | sub %o1, %g5, %o1 ! g5 gets the difference |
| 164 | |
| 165 | 1: ldx [%o1+%g5], %o4 ! read from address |
| 166 | deccc 8, %o3 ! decrement count |
| 167 | stx %o4, [%g5] ! write at destination address |
| 168 | bg,pt %xcc, 1b |
| 169 | inc 8, %g5 ! increment to address |
| 170 | b 7f |
| 171 | and %o2, 6, %o2 ! number of leftover bytes, if any |
| 172 | |
| 173 | ! |
| 174 | ! differenced byte copy, works with any alignment |
| 175 | ! |
| 176 | .dbytecp: |
| 177 | b 7f |
| 178 | sub %o1, %g5, %o1 ! g5 gets the difference |
| 179 | |
| 180 | 4: sth %o4, [%g5] ! write to address |
| 181 | inc 2, %g5 ! inc to address |
| 182 | 7: deccc 2, %o2 ! decrement count |
| 183 | bge,a,pt %xcc,4b ! loop till done |
| 184 | lduh [%o1+%g5], %o4 ! read from address |
| 185 | .done: |
| 186 | retl |
| 187 | nop |
| 188 | |
| 189 | SET_SIZE(__align_cpy_2) |