Home | History | Annotate | Line # | Download | only in ibm4xx
      1  1.8    andvar /*	$NetBSD: 4xx_locore.S,v 1.8 2022/05/31 08:43:15 andvar Exp $	*/
      2  1.1       scw 
      3  1.1       scw /*
      4  1.1       scw  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1       scw  * All rights reserved.
      6  1.1       scw  *
      7  1.1       scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8  1.1       scw  *
      9  1.1       scw  * Redistribution and use in source and binary forms, with or without
     10  1.1       scw  * modification, are permitted provided that the following conditions
     11  1.1       scw  * are met:
     12  1.1       scw  * 1. Redistributions of source code must retain the above copyright
     13  1.1       scw  *    notice, this list of conditions and the following disclaimer.
     14  1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     16  1.1       scw  *    documentation and/or other materials provided with the distribution.
     17  1.1       scw  * 3. All advertising materials mentioning features or use of this software
     18  1.1       scw  *    must display the following acknowledgement:
     19  1.1       scw  *      This product includes software developed for the NetBSD Project by
     20  1.1       scw  *      Wasabi Systems, Inc.
     21  1.1       scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1       scw  *    or promote products derived from this software without specific prior
     23  1.1       scw  *    written permission.
     24  1.1       scw  *
     25  1.1       scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1       scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1       scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1       scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1       scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1       scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1       scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1       scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1       scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1       scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1       scw  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1       scw  */
     37  1.1       scw 
     38  1.1       scw /*
     39  1.1       scw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40  1.1       scw  * Copyright (C) 1995, 1996 TooLs GmbH.
     41  1.1       scw  * All rights reserved.
     42  1.1       scw  *
     43  1.1       scw  * Redistribution and use in source and binary forms, with or without
     44  1.1       scw  * modification, are permitted provided that the following conditions
     45  1.1       scw  * are met:
     46  1.1       scw  * 1. Redistributions of source code must retain the above copyright
     47  1.1       scw  *    notice, this list of conditions and the following disclaimer.
     48  1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     50  1.1       scw  *    documentation and/or other materials provided with the distribution.
     51  1.1       scw  * 3. All advertising materials mentioning features or use of this software
     52  1.1       scw  *    must display the following acknowledgement:
     53  1.1       scw  *	This product includes software developed by TooLs GmbH.
     54  1.1       scw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55  1.1       scw  *    derived from this software without specific prior written permission.
     56  1.1       scw  *
     57  1.1       scw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58  1.1       scw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  1.1       scw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  1.1       scw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61  1.1       scw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62  1.1       scw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63  1.1       scw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64  1.1       scw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65  1.1       scw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66  1.1       scw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67  1.1       scw  */
     68  1.1       scw 
     69  1.1       scw /*
     70  1.8    andvar  * This is not a standalone file. To use it, #include it at
     71  1.1       scw  * the end of your port's locore.S
     72  1.1       scw  */
     73  1.1       scw 
     74  1.1       scw /*
     75  1.2   thorpej  * Pull in common PowerPC locore subroutines.
     76  1.1       scw  */
     77  1.2   thorpej #include <powerpc/powerpc/locore_subr.S>
     78  1.1       scw 
     79  1.1       scw /*
     80  1.1       scw  * Pull in common trap vector code.
     81  1.1       scw  */
     82  1.1       scw #include <powerpc/ibm4xx/trap_subr.S>
     83  1.1       scw #include <powerpc/ibm4xx/4xx_trap_subr.S>
     84  1.3       scw 
     85  1.3       scw /*
     86  1.3       scw  * Include PIO routines
     87  1.3       scw  */
     88  1.3       scw #include <powerpc/powerpc/pio_subr.S>
     89  1.1       scw 
     90  1.1       scw 	.globl	_C_LABEL(ppc4xx_reset)
     91  1.1       scw _C_LABEL(ppc4xx_reset):
     92  1.4       eeh 	mfspr	%r3,SPR_DBCR0
     93  1.6   tsutsui 	oris	%r3,%r3,DBCR0_RST_SYSTEM@h
     94  1.4       eeh 	mtspr	SPR_DBCR0,%r3
     95  1.1       scw 	ba	0
     96  1.1       scw 
     97  1.1       scw #if 0
     98  1.1       scw /*
     99  1.1       scw  * XXXX the following doesn't quite work right yet.
    100  1.1       scw  */
    101  1.1       scw /*
    102  1.1       scw  * void bcopy(const void *src, void *dst, size_t len);
    103  1.1       scw  *
    104  1.4       eeh  * swap %r3 and %r4 and fall through to memcopy.
    105  1.1       scw  */
    106  1.1       scw 	.globl _C_LABEL(bcopy)
    107  1.1       scw _C_LABEL(bcopy):
    108  1.4       eeh 	mr	%r0,%r3
    109  1.4       eeh 	mr	%r3,%r4
    110  1.4       eeh 	mr	%r4,%r0
    111  1.1       scw 	/* FALLTHROUGH */
    112  1.1       scw 
    113  1.1       scw /*
    114  1.7  christos  * void *memcpy(void *dst (%r3), const void *src (%r4), size_t len (%r5));
    115  1.1       scw  *
    116  1.1       scw  * Copy memory (obviously)
    117  1.1       scw  *
    118  1.1       scw  * We will try to do data cache block aligned stores so we
    119  1.1       scw  * can use block allocate and not have to read from the
    120  1.1       scw  * destination.
    121  1.1       scw  *
    122  1.1       scw  * Register use:
    123  1.1       scw  *
    124  1.4       eeh  *	%r1		stack (of course)
    125  1.4       eeh  *	%r3		dst
    126  1.4       eeh  *	%r4		src
    127  1.4       eeh  *	%r5		len
    128  1.4       eeh  *	%r6		tmp
    129  1.4       eeh  *	%r7		holds 32
    130  1.4       eeh  *	%r8		holds dst
    131  1.4       eeh  *	%r24-%r31	block move regs
    132  1.1       scw  *
    133  1.1       scw  */
    134  1.1       scw 
    135  1.1       scw ENTRY(memcpy)
    136  1.4       eeh 	stwu	%r1,-(10*4)(%r1)	/* Allocate some RAM to save 8 regs to. */
    137  1.4       eeh 	cmpwi	%r5, 32		/* Less than 32 bytes ? */
    138  1.4       eeh 	stmw	%r24,8(%r1)	/* Save ALL regs (could be optimized) */
    139  1.1       scw 
    140  1.4       eeh 	mr	%r8,%r3		/* save dst */
    141  1.4       eeh 	li	%r7,32
    142  1.1       scw 
    143  1.4       eeh 	dcbt	%r0,%r4		/* Start bringing in cache line. */
    144  1.1       scw 	blt	1f		/* Finish up */
    145  1.1       scw 
    146  1.4       eeh 	neg	%r6,%r3		/* Find how far unaligned we are... */
    147  1.4       eeh 	andi.	%r6,%r6,31	/* Cache-align dest. */
    148  1.4       eeh 	mtxer	%r6
    149  1.4       eeh 	sub	%r5,%r5,%r6	/* subtract count */
    150  1.4       eeh 	lswx	%r24,%r0,%r4	/* Load some. */
    151  1.4       eeh 	add	%r4,%r4,%r6
    152  1.4       eeh 	dcbt	%r0,%r4		/* Fetch next line */
    153  1.4       eeh 	stswx	%r24,%r0,%r3	/* Store some */
    154  1.4       eeh 	add	%r3,%r3,%r6
    155  1.4       eeh 	addic.	%r6,%r5,-32	/* Pre-decrement next line */
    156  1.1       scw 	ble	1f		/* Less than 32-bytes? finishup */
    157  1.1       scw 
    158  1.1       scw 	/* Dest should not be cache line aligned. */
    159  1.1       scw 	/* XXX need gas 2.11 to grok dcba insn */
    160  1.1       scw #ifdef GAS_2_11
    161  1.4       eeh 	dcba	%r0,%r3		/* Allocate a line */
    162  1.1       scw #else
    163  1.1       scw 	.long	0x7c001dec	/* dcba	0,r3 */
    164  1.1       scw #endif
    165  1.1       scw 0:
    166  1.4       eeh 	dcbt	%r7,%r4		/* Bring in the next line, too */
    167  1.1       scw 
    168  1.4       eeh 	lswi	%r24,%r4,32
    169  1.4       eeh 	addi	%r4,%r4,32	/* Inc src */
    170  1.4       eeh 	mr	%r5,%r6
    171  1.4       eeh 
    172  1.4       eeh 	addic.	%r6,%r5,-32
    173  1.4       eeh 	stswi	%r24,%r3,32
    174  1.4       eeh 	addi	%r3,%r3,32	/* Inc dst */
    175  1.1       scw #ifdef GAS_2_11
    176  1.4       eeh 	dcba	0,%r3		/* Allocate another line */
    177  1.1       scw #else
    178  1.4       eeh 	.long	0x7c071dec	/* dcba	%r7,%r3 */
    179  1.1       scw #endif
    180  1.1       scw 	bgt	0b
    181  1.1       scw 1:
    182  1.4       eeh 	mtxer	%r5		/* Store byte count */
    183  1.4       eeh 	lswx	%r24,%r0,%r4	/* Load up to 32 bytes */
    184  1.4       eeh 	stswx	%r24,%r0,%r3	/* Store up to 32 bytes */
    185  1.1       scw 
    186  1.4       eeh 	mr	%r3,%r8		/* Return dst */
    187  1.1       scw 
    188  1.4       eeh 	lmw	%r24,8(%r1)
    189  1.4       eeh 	addi	%r1,%r1,(10*4)
    190  1.1       scw 	blr
    191  1.1       scw #endif
    192