[BACK]Return to copystr.S CVS log [TXT][DIR] Up to [local] / sys / arch / arm / arm

Annotation of sys/arch/arm/arm/copystr.S, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: copystr.S,v 1.2 2006/11/15 19:48:29 miod Exp $        */
        !             2: /*     $NetBSD: copystr.S,v 1.8 2002/10/13 14:54:48 bjh21 Exp $        */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1995 Mark Brinicombe.
        !             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
        !            10:  * are met:
        !            11:  * 1. Redistributions of source code must retain the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer.
        !            13:  * 2. Redistributions in binary form must reproduce the above copyright
        !            14:  *    notice, this list of conditions and the following disclaimer in the
        !            15:  *    documentation and/or other materials provided with the distribution.
        !            16:  * 3. All advertising materials mentioning features or use of this software
        !            17:  *    must display the following acknowledgement:
        !            18:  *     This product includes software developed by Mark Brinicombe.
        !            19:  * 4. The name of the company nor the name of the author may be used to
        !            20:  *    endorse or promote products derived from this software without specific
        !            21:  *    prior written permission.
        !            22:  *
        !            23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
        !            24:  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
        !            25:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            26:  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
        !            27:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            28:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            29:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            33:  * SUCH DAMAGE.
        !            34:  *
        !            35:  * copystr.S
        !            36:  *
        !            37:  * optimised and fault protected copystr functions
        !            38:  *
        !            39:  * Created      : 16/05/95
        !            40:  */
        !            41:
        !            42: #include "assym.h"
        !            43: #include <machine/asm.h>
        !            44: #include <sys/errno.h>
        !            45:
        !            46:        .text
        !            47:        .align  0
        !            48: #ifdef MULTIPROCESSOR
        !            49: .Lcpu_info:
        !            50:        .word   _C_LABEL(cpu_info)
        !            51: #else
        !            52: .Lcurpcb:
        !            53:        .word   _C_LABEL(curpcb)
        !            54: #endif
        !            55:
        !            56: /*
        !            57:  * r0 - from
        !            58:  * r1 - to
        !            59:  * r2 - maxlens
        !            60:  * r3 - lencopied
        !            61:  *
        !            62:  * Copy string from r0 to r1
        !            63:  */
        !            64: ENTRY(copystr)
        !            65:        stmfd   sp!, {r4-r5}                    /* stack is 8 byte aligned */
        !            66:        teq     r2, #0x00000000
        !            67:        mov     r5, #0x00000000
        !            68:        moveq   r0, #ENAMETOOLONG
        !            69:        beq     2f
        !            70:
        !            71: 1:     ldrb    r4, [r0], #0x0001
        !            72:        add     r5, r5, #0x00000001
        !            73:        teq     r4, #0x00000000
        !            74:        strb    r4, [r1], #0x0001
        !            75:        teqne   r5, r2
        !            76:        bne     1b
        !            77:
        !            78:        teq     r4, #0x00000000
        !            79:        moveq   r0, #0x00000000
        !            80:        movne   r0, #ENAMETOOLONG
        !            81:
        !            82: 2:     teq     r3, #0x00000000
        !            83:        strne   r5, [r3]
        !            84:
        !            85:        ldmfd   sp!, {r4-r5}                    /* stack is 8 byte aligned */
        !            86:        mov     pc, lr
        !            87:
        !            88: #ifdef __PROG32
        !            89: #define SAVE_REGS      stmfd   sp!, {r4-r6}
        !            90: #define RESTORE_REGS   ldmfd   sp!, {r4-r6}
        !            91: #else
        !            92: /* Need to save R14_svc because it'll get trampled if we take a page fault. */
        !            93: #define SAVE_REGS      stmfd   sp!, {r4-r6, r14}
        !            94: #define RESTORE_REGS   ldmfd   sp!, {r4-r6, r14}
        !            95: #endif
        !            96:
        !            97: /*
        !            98:  * r0 - user space address
        !            99:  * r1 - kernel space address
        !           100:  * r2 - maxlens
        !           101:  * r3 - lencopied
        !           102:  *
        !           103:  * Copy string from user space to kernel space
        !           104:  */
        !           105: ENTRY(copyinstr)
        !           106:        SAVE_REGS
        !           107:
        !           108:        teq     r2, #0x00000000
        !           109:        mov     r6, #0x00000000
        !           110:        moveq   r0, #ENAMETOOLONG
        !           111:        beq     2f
        !           112:
        !           113: #ifdef MULTIPROCESSOR
        !           114:        /* XXX Probably not appropriate for non-Hydra SMPs */
        !           115:        stmfd   sp!, {r0-r3, r14}
        !           116:        bl      _C_LABEL(cpu_number)
        !           117:        ldr     r4, .Lcpu_info
        !           118:        ldr     r4, [r4, r0, lsl #2]
        !           119:        ldr     r4, [r4, #CI_CURPCB]
        !           120:        ldmfd   sp!, {r0-r3, r14}
        !           121: #else
        !           122:        ldr     r4, .Lcurpcb
        !           123:        ldr     r4, [r4]
        !           124: #endif
        !           125:
        !           126: #ifdef DEBUG
        !           127:        teq     r4, #0x00000000
        !           128:        beq     .Lcopystrpcbfault
        !           129: #endif
        !           130:
        !           131:        adr     r5, .Lcopystrfault
        !           132:        str     r5, [r4, #PCB_ONFAULT]
        !           133:
        !           134: 1:     ldrbt   r5, [r0], #0x0001
        !           135:        add     r6, r6, #0x00000001
        !           136:        teq     r5, #0x00000000
        !           137:        strb    r5, [r1], #0x0001
        !           138:        teqne   r6, r2
        !           139:        bne     1b
        !           140:
        !           141:        mov     r0, #0x00000000
        !           142:        str     r0, [r4, #PCB_ONFAULT]
        !           143:
        !           144:        teq     r5, #0x00000000
        !           145:        moveq   r0, #0x00000000
        !           146:        movne   r0, #ENAMETOOLONG
        !           147:
        !           148: 2:     teq     r3, #0x00000000
        !           149:        strne   r6, [r3]
        !           150:
        !           151:        RESTORE_REGS
        !           152:        mov     pc, lr
        !           153:
        !           154: /*
        !           155:  * r0 - kernel space address
        !           156:  * r1 - user space address
        !           157:  * r2 - maxlens
        !           158:  * r3 - lencopied
        !           159:  *
        !           160:  * Copy string from kernel space to user space
        !           161:  */
        !           162: ENTRY(copyoutstr)
        !           163:        SAVE_REGS
        !           164:
        !           165:        teq     r2, #0x00000000
        !           166:        mov     r6, #0x00000000
        !           167:        moveq   r0, #ENAMETOOLONG
        !           168:        beq     2f
        !           169:
        !           170: #ifdef MULTIPROCESSOR
        !           171:        /* XXX Probably not appropriate for non-Hydra SMPs */
        !           172:        stmfd   sp!, {r0-r3, r14}
        !           173:        bl      _C_LABEL(cpu_number)
        !           174:        ldr     r4, .Lcpu_info
        !           175:        ldr     r4, [r4, r0, lsl #2]
        !           176:        ldr     r4, [r4, #CI_CURPCB]
        !           177:        ldmfd   sp!, {r0-r3, r14}
        !           178: #else
        !           179:        ldr     r4, .Lcurpcb
        !           180:        ldr     r4, [r4]
        !           181: #endif
        !           182:
        !           183: #ifdef DEBUG
        !           184:        teq     r4, #0x00000000
        !           185:        beq     .Lcopystrpcbfault
        !           186: #endif
        !           187:
        !           188:        adr     r5, .Lcopystrfault
        !           189:        str     r5, [r4, #PCB_ONFAULT]
        !           190:
        !           191: 1:     ldrb    r5, [r0], #0x0001
        !           192:        add     r6, r6, #0x00000001
        !           193:        teq     r5, #0x00000000
        !           194:        strbt   r5, [r1], #0x0001
        !           195:        teqne   r6, r2
        !           196:        bne     1b
        !           197:
        !           198:        mov     r0, #0x00000000
        !           199:        str     r0, [r4, #PCB_ONFAULT]
        !           200:
        !           201:        teq     r5, #0x00000000
        !           202:        moveq   r0, #0x00000000
        !           203:        movne   r0, #ENAMETOOLONG
        !           204:
        !           205: 2:     teq     r3, #0x00000000
        !           206:        strne   r6, [r3]
        !           207:
        !           208:        RESTORE_REGS
        !           209:        mov     pc, lr
        !           210:
        !           211: /* A fault occurred during the copy */
        !           212: .Lcopystrfault:
        !           213:        mov     r1, #0x00000000
        !           214:        str     r1, [r4, #PCB_ONFAULT]
        !           215:        RESTORE_REGS
        !           216:        mov     pc, lr
        !           217:
        !           218: #ifdef DEBUG
        !           219: .Lcopystrpcbfault:
        !           220:        mov     r2, r1
        !           221:        mov     r1, r0
        !           222:        adr     r0, Lcopystrpcbfaulttext
        !           223:        bic     sp, sp, #7                      /* align stack to 8 bytes */
        !           224:        b       _C_LABEL(panic)
        !           225:
        !           226: Lcopystrpcbfaulttext:
        !           227:        .asciz  "No valid PCB during copyinoutstr() addr1=%08x addr2=%08x\n"
        !           228:        .align  0
        !           229: #endif

CVSweb