1/* $OpenBSD: bcopy_page.S,v 1.3 2018/08/06 18:39:13 kettenis Exp $ */ 2/* $NetBSD: bcopy_page.S,v 1.7 2003/10/13 21:03:13 scw Exp $ */ 3 4 5/* 6 * Copyright (c) 1995 Scott Stevens 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Scott Stevens. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * RiscBSD kernel project 35 * 36 * bcopy_page.S 37 * 38 * page optimised bcopy and bzero routines 39 * 40 * Created : 08/04/95 41 */ 42 43#include "assym.h" 44 45#include <machine/asm.h> 46 47/* #define BIG_LOOPS */ 48 49/* 50 * bcopy_page(src, dest) 51 * 52 * Optimised copy page routine. 53 * 54 * On entry: 55 * r0 - src address 56 * r1 - dest address 57 * 58 * Requires: 59 * number of bytes per page (PAGE_SIZE) is a multiple of 512 (BIG_LOOPS), 128 60 * otherwise. 61 */ 62 63#define CHUNK_SIZE 32 64 65#define PREFETCH_FIRST_CHUNK /* nothing */ 66#define PREFETCH_NEXT_CHUNK /* nothing */ 67 68#ifndef COPY_CHUNK 69#define COPY_CHUNK \ 70 PREFETCH_NEXT_CHUNK ; \ 71 ldmia r0!, {r3-r8,ip,lr} ; \ 72 stmia r1!, {r3-r8,ip,lr} 73#endif /* ! COPY_CHUNK */ 74 75#ifndef SAVE_REGS 76#define SAVE_REGS stmfd sp!, {r4-r8, lr} 77#define RESTORE_REGS ldmfd sp!, {r4-r8, pc} 78#endif 79 80ENTRY(bcopy_page) 81 PREFETCH_FIRST_CHUNK 82 SAVE_REGS 83#ifdef BIG_LOOPS 84 mov r2, #(PAGE_SIZE >> 9) 85#else 86 mov r2, #(PAGE_SIZE >> 7) 87#endif 88 891: 90 COPY_CHUNK 91 COPY_CHUNK 92 COPY_CHUNK 93 COPY_CHUNK 94 95#ifdef BIG_LOOPS 96 /* There is little point making the loop any larger; unless we are 97 running with the cache off, the load/store overheads will 98 completely dominate this loop. */ 99 COPY_CHUNK 100 COPY_CHUNK 101 COPY_CHUNK 102 COPY_CHUNK 103 104 COPY_CHUNK 105 COPY_CHUNK 106 COPY_CHUNK 107 COPY_CHUNK 108 109 COPY_CHUNK 110 COPY_CHUNK 111 COPY_CHUNK 112 COPY_CHUNK 113#endif 114 subs r2, r2, #1 115 bne 1b 116 117 RESTORE_REGS /* ...and return. */ 118 119/* 120 * bzero_page(dest) 121 * 122 * Optimised zero page routine. 123 * 124 * On entry: 125 * r0 - dest address 126 * 127 * Requires: 128 * number of bytes per page (PAGE_SIZE) is a multiple of 512 (BIG_LOOPS), 128 129 * otherwise 130 */ 131 132ENTRY(bzero_page) 133 stmfd sp!, {r4-r8, lr} 134#ifdef BIG_LOOPS 135 mov r2, #(PAGE_SIZE >> 9) 136#else 137 mov r2, #(PAGE_SIZE >> 7) 138#endif 139 mov r3, #0 140 mov r4, #0 141 mov r5, #0 142 mov r6, #0 143 mov r7, #0 144 mov r8, #0 145 mov ip, #0 146 mov lr, #0 147 1481: 149 stmia r0!, {r3-r8,ip,lr} 150 stmia r0!, {r3-r8,ip,lr} 151 stmia r0!, {r3-r8,ip,lr} 152 stmia r0!, {r3-r8,ip,lr} 153 154#ifdef BIG_LOOPS 155 /* There is little point making the loop any larger; unless we are 156 running with the cache off, the load/store overheads will 157 completely dominate this loop. */ 158 stmia r0!, {r3-r8,ip,lr} 159 stmia r0!, {r3-r8,ip,lr} 160 stmia r0!, {r3-r8,ip,lr} 161 stmia r0!, {r3-r8,ip,lr} 162 163 stmia r0!, {r3-r8,ip,lr} 164 stmia r0!, {r3-r8,ip,lr} 165 stmia r0!, {r3-r8,ip,lr} 166 stmia r0!, {r3-r8,ip,lr} 167 168 stmia r0!, {r3-r8,ip,lr} 169 stmia r0!, {r3-r8,ip,lr} 170 stmia r0!, {r3-r8,ip,lr} 171 stmia r0!, {r3-r8,ip,lr} 172 173#endif 174 175 subs r2, r2, #1 176 bne 1b 177 178 ldmfd sp!, {r4-r8, pc} 179