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