1/* $NetBSD: support.S,v 1.6 2009/11/03 05:07:26 snj Exp $ */ 2 3/* $OpenBSD: locore.S,v 1.46 2001/09/20 18:33:03 mickey Exp $ */ 4 5/* 6 * Copyright (c) 1998-2004 Michael Shalayeff 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 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portitions of this file are derived from other sources, see 31 * the copyrights and acknowledgements below. 32 */ 33/* 34 * Copyright (c) 1990,1991,1992,1994 The University of Utah and 35 * the Computer Systems Laboratory (CSL). All rights reserved. 36 * 37 * THE UNIVERSITY OF UTAH AND CSL PROVIDE THIS SOFTWARE IN ITS "AS IS" 38 * CONDITION, AND DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES 39 * WHATSOEVER RESULTING FROM ITS USE. 40 * 41 * CSL requests users of this software to return to csl-dist@cs.utah.edu any 42 * improvements that they make and grant CSL redistribution rights. 43 * 44 * Utah $Hdr: locore.s 1.62 94/12/15$ 45 */ 46/* 47 * (c) Copyright 1988 HEWLETT-PACKARD COMPANY 48 * 49 * To anyone who acknowledges that this file is provided "AS IS" 50 * without any express or implied warranty: 51 * permission to use, copy, modify, and distribute this file 52 * for any purpose is hereby granted without fee, provided that 53 * the above copyright notice and this notice appears in all 54 * copies, and that the name of Hewlett-Packard Company not be 55 * used in advertising or publicity pertaining to distribution 56 * of the software without specific, written prior permission. 57 * Hewlett-Packard Company makes no representations about the 58 * suitability of this software for any purpose. 59 */ 60 61/* 62 * NOTICE: This is not a standalone file. To use it, #include it in 63 * your port's locore.S, like so: 64 * 65 * #include <hppa/hppa/support.S> 66 */ 67 68/* 69 * Miscellaneous support routines common to all hppa ports. 70 */ 71 72/* 73 * void fdcache(pa_space_t sp, vaddr_t va, vsize_t size); 74 */ 75 .import dcache_stride, data 76LEAF_ENTRY(fdcache) 77 ldil L%dcache_stride,%t1 78 ldw R%dcache_stride(%t1), %arg3 79 80 comb,=,n %arg2, %r0, fdc_none /* no bytes, no flush */ 81 82 mtsp %arg0, %sr1 /* move the space register to sr1 */ 83 add %arg1, %arg2, %arg0 /* get the last byte to flush in arg0 */ 84 85 zdep %arg3, 27, 28, %t1 /* get size of a 16X loop in t1 */ 86 comb,< %arg2, %t1, fdc_short /* check for count < 16 * stride */ 87 addi -1, %t1, %t1 /* compute size of large loop - 1 */ 88 89 andcm %arg2, %t1, %t1 /* L = count - (count mod lenbigloop) */ 90 add %arg1, %t1, %t1 /* ub for big loop is lb + L */ 91 92 fdc,m %arg3(%sr1, %arg1) /* Start flushing first cache line. */ 93fdc_long: 94 fdc,m %arg3(%sr1, %arg1) 95 fdc,m %arg3(%sr1, %arg1) 96 fdc,m %arg3(%sr1, %arg1) 97 fdc,m %arg3(%sr1, %arg1) 98 fdc,m %arg3(%sr1, %arg1) 99 fdc,m %arg3(%sr1, %arg1) 100 fdc,m %arg3(%sr1, %arg1) 101 fdc,m %arg3(%sr1, %arg1) 102 fdc,m %arg3(%sr1, %arg1) 103 fdc,m %arg3(%sr1, %arg1) 104 fdc,m %arg3(%sr1, %arg1) 105 fdc,m %arg3(%sr1, %arg1) 106 fdc,m %arg3(%sr1, %arg1) 107 fdc,m %arg3(%sr1, %arg1) 108 fdc,m %arg3(%sr1, %arg1) 109 comb,<<,n %arg1, %t1, fdc_long 110 fdc,m %arg3(%sr1, %arg1) 111fdc_short: /* flush one line at a time */ 112 comb,<<,n %arg1, %arg0, fdc_short 113 fdc,m %arg3(%sr1, %arg1) 114 115 addi -1, %arg0, %arg1 116 fdc %r0(%sr1, %arg1) 117 118fdc_none: 119 sync 120 syncdma 121 bv %r0(%rp) 122 sync 123EXIT(fdcache) 124 125/* 126 * void pdcache(pa_space_t sp, vaddr_t va, vsize_t size); 127 */ 128 .import dcache_stride, data 129LEAF_ENTRY(pdcache) 130 ldil L%dcache_stride,%t1 131 ldw R%dcache_stride(%t1), %arg3 132 133 comb,= %arg2, %r0, pdc_none /* no bytes, no purge */ 134 135 mtsp %arg0, %sr1 /* move the space register to sr1 */ 136 add %arg1, %arg2, %arg0 /* get the last byte to flush in arg0 */ 137 138 zdep %arg3, 27, 28, %t1 /* get size of a 16X loop in t1 */ 139 comb,< %arg2, %t1, pdc_short /* check for count < 16 * stride */ 140 addi -1, %t1, %t1 /* compute size of large loop - 1 */ 141 142 andcm %arg2, %t1, %t1 /* L = count - (count mod lenbigloop) */ 143 add %arg1, %t1, %t1 /* ub for big loop is lb + L */ 144 145 pdc,m %arg3(%sr1, %arg1) /* Start flushing first cache line. */ 146pdc_long: 147 pdc,m %arg3(%sr1, %arg1) 148 pdc,m %arg3(%sr1, %arg1) 149 pdc,m %arg3(%sr1, %arg1) 150 pdc,m %arg3(%sr1, %arg1) 151 pdc,m %arg3(%sr1, %arg1) 152 pdc,m %arg3(%sr1, %arg1) 153 pdc,m %arg3(%sr1, %arg1) 154 pdc,m %arg3(%sr1, %arg1) 155 pdc,m %arg3(%sr1, %arg1) 156 pdc,m %arg3(%sr1, %arg1) 157 pdc,m %arg3(%sr1, %arg1) 158 pdc,m %arg3(%sr1, %arg1) 159 pdc,m %arg3(%sr1, %arg1) 160 pdc,m %arg3(%sr1, %arg1) 161 pdc,m %arg3(%sr1, %arg1) 162 comb,<<,n %arg1, %t1, pdc_long 163 pdc,m %arg3(%sr1, %arg1) 164pdc_short: /* flush one line at a time */ 165 comb,<<,n %arg1, %arg0, pdc_short 166 pdc,m %arg3(%sr1, %arg1) 167 168 addi -1, %arg0, %arg1 169 pdc %r0(%sr1, %arg1) 170 171pdc_none: 172 sync 173 syncdma 174 bv %r0(%rp) 175 sync 176EXIT(pdcache) 177 178/* 179 * void ficache(pa_space_t sp, vaddr_t va, vsize_t size); 180 */ 181 .import icache_stride, data 182LEAF_ENTRY(ficache) 183 ldil L%icache_stride,%t1 184 ldw R%icache_stride(%t1), %arg3 185 186 comb,= %arg2, %r0, fic_none /* no bytes, no flush */ 187 188 mtsp %arg0, %sr1 /* move the space register to sr1 */ 189 add %arg1, %arg2, %arg0 /* get the last byte to flush in arg0 */ 190 191 zdep %arg3, 27, 28, %t1 /* get size of a 16X loop in t1 */ 192 comb,< %arg2, %t1, fic_short /* check for count < 16 * stride */ 193 addi -1, %t1, %t1 /* compute size of large loop - 1 */ 194 195 andcm %arg2, %t1, %t1 /* L = count - (count mod lenbigloop) */ 196 add %arg1, %t1, %t1 /* ub for big loop is lb + L */ 197 198 fic,m %arg3(%sr1, %arg1) /* Start flushing first cache line. */ 199fic_long: 200 fic,m %arg3(%sr1, %arg1) 201 fic,m %arg3(%sr1, %arg1) 202 fic,m %arg3(%sr1, %arg1) 203 fic,m %arg3(%sr1, %arg1) 204 fic,m %arg3(%sr1, %arg1) 205 fic,m %arg3(%sr1, %arg1) 206 fic,m %arg3(%sr1, %arg1) 207 fic,m %arg3(%sr1, %arg1) 208 fic,m %arg3(%sr1, %arg1) 209 fic,m %arg3(%sr1, %arg1) 210 fic,m %arg3(%sr1, %arg1) 211 fic,m %arg3(%sr1, %arg1) 212 fic,m %arg3(%sr1, %arg1) 213 fic,m %arg3(%sr1, %arg1) 214 fic,m %arg3(%sr1, %arg1) 215 comb,<<,n %arg1, %t1, fic_long 216 fic,m %arg3(%sr1, %arg1) 217fic_short: /* flush one line at a time */ 218 comb,<<,n %arg1, %arg0, fic_short 219 fic,m %arg3(%sr1, %arg1) 220 221 addi -1, %arg0, %arg1 222 fic %r0(%sr1, %arg1) 223 224fic_none: 225 sync 226 syncdma 227 bv %r0(%rp) 228 sync 229EXIT(ficache) 230 231#ifdef HP7300LC_CPU 232 .section .bss 233eaio_l2_mask: 234 .block 4 235 .text 236LEAF_ENTRY(eaio_l2) 237 ldil L%eaio_l2_mask, %t2 238 ldw R%eaio_l2_mask(%t2), %t1 239 or %t1, %arg0, %t1 240 MTCPU_C(22, DR0_PCXL2_ACCEL_IO) 241 nop 242 nop 243 bv 0(%rp) 244 stw %t1, R%eaio_l2_mask(%t2) 245EXIT(eaio_l2) 246#endif /* HP7300LC_CPU */ 247 248LEAF_ENTRY(setjmp) 249/* 250 * Save the other general registers whose contents are expected to remain 251 * across function calls. According to the "HP9000 Series 800 Assembly 252 * Language Reference Manual", procedures can use general registers 19-26, 253 * 28, 29, 1, and 31 without restoring them. Hence, we do not save these. 254 */ 255 stwm %r3,4(%arg0) 256 stwm %r4,4(%arg0) 257 stwm %r5,4(%arg0) 258 stwm %r6,4(%arg0) 259 stwm %r7,4(%arg0) 260 stwm %r8,4(%arg0) 261 stwm %r9,4(%arg0) 262 stwm %r10,4(%arg0) 263 stwm %r11,4(%arg0) 264 stwm %r12,4(%arg0) 265 stwm %r13,4(%arg0) 266 stwm %r14,4(%arg0) 267 stwm %r15,4(%arg0) 268 stwm %r16,4(%arg0) 269 stwm %r17,4(%arg0) 270 stwm %r18,4(%arg0) 271 stwm %r27,4(%arg0) /* Good idea to save the data pointer (dp) */ 272 stwm %rp,4(%arg0) /* Save the return pointer */ 273 stwm %sp,4(%arg0) /* Save the original stack pointer */ 274 275 bv %r0(%rp) 276 copy %r0, %ret0 277EXIT(setjmp) 278 279LEAF_ENTRY(longjmp) 280/* 281 * Restore general registers. 282 */ 283 ldwm 4(%arg0),%r3 284 ldwm 4(%arg0),%r4 285 ldwm 4(%arg0),%r5 286 ldwm 4(%arg0),%r6 287 ldwm 4(%arg0),%r7 288 ldwm 4(%arg0),%r8 289 ldwm 4(%arg0),%r9 290 ldwm 4(%arg0),%r10 291 ldwm 4(%arg0),%r11 292 ldwm 4(%arg0),%r12 293 ldwm 4(%arg0),%r13 294 ldwm 4(%arg0),%r14 295 ldwm 4(%arg0),%r15 296 ldwm 4(%arg0),%r16 297 ldwm 4(%arg0),%r17 298 ldwm 4(%arg0),%r18 299 ldwm 4(%arg0),%r27 300 ldwm 4(%arg0),%rp /* Restore return address pointer, */ 301 ldwm 4(%arg0),%sp /* stack pointer, */ 302 303 bv %r0(%rp) 304 copy %arg1,%ret0 /* Move return value to where it belongs. */ 305EXIT(longjmp) 306 307