Home | History | Annotate | Line # | Download | only in arm32
setstack.S revision 1.1.2.3
      1  1.1.2.3  jdolecek /*	$NetBSD: setstack.S,v 1.1.2.3 2002/09/06 08:32:28 jdolecek Exp $	*/
      2  1.1.2.2     lukem 
      3  1.1.2.2     lukem /*
      4  1.1.2.2     lukem  * Copyright (c) 1994 Mark Brinicombe.
      5  1.1.2.2     lukem  * Copyright (c) 1994 Brini.
      6  1.1.2.2     lukem  * All rights reserved.
      7  1.1.2.2     lukem  *
      8  1.1.2.2     lukem  * This code is derived from software written for Brini by Mark Brinicombe
      9  1.1.2.2     lukem  *
     10  1.1.2.2     lukem  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2     lukem  * modification, are permitted provided that the following conditions
     12  1.1.2.2     lukem  * are met:
     13  1.1.2.2     lukem  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2     lukem  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2     lukem  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2     lukem  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2     lukem  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2     lukem  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2     lukem  *    must display the following acknowledgement:
     20  1.1.2.2     lukem  *	This product includes software developed by Brini.
     21  1.1.2.2     lukem  * 4. The name of the company nor the name of the author may be used to
     22  1.1.2.2     lukem  *    endorse or promote products derived from this software without specific
     23  1.1.2.2     lukem  *    prior written permission.
     24  1.1.2.2     lukem  *
     25  1.1.2.2     lukem  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26  1.1.2.2     lukem  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27  1.1.2.2     lukem  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28  1.1.2.2     lukem  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29  1.1.2.2     lukem  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30  1.1.2.2     lukem  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31  1.1.2.2     lukem  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1.2.2     lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1.2.2     lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1.2.2     lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1.2.2     lukem  * SUCH DAMAGE.
     36  1.1.2.2     lukem  *
     37  1.1.2.2     lukem  * RiscBSD kernel project
     38  1.1.2.2     lukem  *
     39  1.1.2.2     lukem  * setstack.S
     40  1.1.2.2     lukem  *
     41  1.1.2.2     lukem  * Miscellaneous routine to play with the stack pointer in different CPU modes
     42  1.1.2.2     lukem  *
     43  1.1.2.2     lukem  * Eventually this routine can be inline assembly.
     44  1.1.2.2     lukem  *
     45  1.1.2.2     lukem  * Created      : 17/09/94
     46  1.1.2.2     lukem  *
     47  1.1.2.2     lukem  * Based of kate/display/setstack.s
     48  1.1.2.2     lukem  */
     49  1.1.2.2     lukem 
     50  1.1.2.2     lukem #include <machine/cpu.h>
     51  1.1.2.2     lukem #include <machine/asm.h>
     52  1.1.2.2     lukem 
     53  1.1.2.2     lukem /* To set the stack pointer for a particular mode we must switch
     54  1.1.2.2     lukem  * to that mode update the banked r13 and then switch back.
     55  1.1.2.2     lukem  * This routine provides an easy way of doing this for any mode
     56  1.1.2.2     lukem  *
     57  1.1.2.2     lukem  * r0 = CPU mode
     58  1.1.2.2     lukem  * r1 = stackptr
     59  1.1.2.2     lukem  */
     60  1.1.2.2     lukem 
     61  1.1.2.2     lukem ENTRY(set_stackptr)
     62  1.1.2.3  jdolecek         mrs	r3, cpsr		/* Switch to the appropriate mode */
     63  1.1.2.2     lukem 	bic	r2, r3, #(PSR_MODE)
     64  1.1.2.2     lukem 	orr	r2, r2, r0
     65  1.1.2.2     lukem         msr	cpsr_all, r2
     66  1.1.2.2     lukem 
     67  1.1.2.2     lukem 	mov	sp, r1			/* Set the stack pointer */
     68  1.1.2.2     lukem 
     69  1.1.2.2     lukem         msr	cpsr_all, r3		/* Restore the old mode */
     70  1.1.2.2     lukem 
     71  1.1.2.2     lukem 	mov	pc, lr			/* Exit */
     72  1.1.2.2     lukem 
     73  1.1.2.2     lukem /* To get the stack pointer for a particular mode we must switch
     74  1.1.2.2     lukem  * to that mode copy the banked r13 and then switch back.
     75  1.1.2.2     lukem  * This routine provides an easy way of doing this for any mode
     76  1.1.2.2     lukem  *
     77  1.1.2.2     lukem  * r0 = CPU mode
     78  1.1.2.2     lukem  */
     79  1.1.2.2     lukem 
     80  1.1.2.2     lukem ENTRY(get_stackptr)
     81  1.1.2.3  jdolecek         mrs	r3, cpsr		/* Switch to the appropriate mode */
     82  1.1.2.2     lukem 	bic	r2, r3, #(PSR_MODE)
     83  1.1.2.2     lukem 	orr	r2, r2, r0
     84  1.1.2.2     lukem         msr	cpsr_all, r2
     85  1.1.2.2     lukem 
     86  1.1.2.2     lukem 	mov	r0, sp			/* Set the stack pointer */
     87  1.1.2.2     lukem 
     88  1.1.2.2     lukem         msr	cpsr_all, r3		/* Restore the old mode */
     89  1.1.2.2     lukem 
     90  1.1.2.2     lukem 	mov	pc, lr			/* Exit */
     91  1.1.2.2     lukem 
     92  1.1.2.2     lukem /* End of setstack.S */
     93