xref: /netbsd-src/sys/arch/arm/arm32/setstack.S (revision ab152917fb47fdea0738028292e422fc44cddffb)
1*ab152917Smatt/*	$NetBSD: setstack.S,v 1.6 2013/08/18 06:29:29 matt Exp $	*/
227f96e84Schris
327f96e84Schris/*
427f96e84Schris * Copyright (c) 1994 Mark Brinicombe.
527f96e84Schris * Copyright (c) 1994 Brini.
627f96e84Schris * All rights reserved.
727f96e84Schris *
827f96e84Schris * This code is derived from software written for Brini by Mark Brinicombe
927f96e84Schris *
1027f96e84Schris * Redistribution and use in source and binary forms, with or without
1127f96e84Schris * modification, are permitted provided that the following conditions
1227f96e84Schris * are met:
1327f96e84Schris * 1. Redistributions of source code must retain the above copyright
1427f96e84Schris *    notice, this list of conditions and the following disclaimer.
1527f96e84Schris * 2. Redistributions in binary form must reproduce the above copyright
1627f96e84Schris *    notice, this list of conditions and the following disclaimer in the
1727f96e84Schris *    documentation and/or other materials provided with the distribution.
1827f96e84Schris * 3. All advertising materials mentioning features or use of this software
1927f96e84Schris *    must display the following acknowledgement:
2027f96e84Schris *	This product includes software developed by Brini.
2127f96e84Schris * 4. The name of the company nor the name of the author may be used to
2227f96e84Schris *    endorse or promote products derived from this software without specific
2327f96e84Schris *    prior written permission.
2427f96e84Schris *
2527f96e84Schris * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
2627f96e84Schris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2727f96e84Schris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2827f96e84Schris * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2927f96e84Schris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3027f96e84Schris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3127f96e84Schris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3227f96e84Schris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3327f96e84Schris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3427f96e84Schris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3527f96e84Schris * SUCH DAMAGE.
3627f96e84Schris *
3727f96e84Schris * RiscBSD kernel project
3827f96e84Schris *
3927f96e84Schris * setstack.S
4027f96e84Schris *
4127f96e84Schris * Miscellaneous routine to play with the stack pointer in different CPU modes
4227f96e84Schris *
4327f96e84Schris * Eventually this routine can be inline assembly.
4427f96e84Schris *
4527f96e84Schris * Created      : 17/09/94
4627f96e84Schris *
4727f96e84Schris * Based of kate/display/setstack.s
4827f96e84Schris */
492d3665a7Schristos#include <arm/armreg.h>
5027f96e84Schris#include <machine/asm.h>
5127f96e84Schris
52*ab152917Smatt	RCSID("$NetBSD: setstack.S,v 1.6 2013/08/18 06:29:29 matt Exp $")
53825088edSmatt
5427f96e84Schris/* To set the stack pointer for a particular mode we must switch
5527f96e84Schris * to that mode update the banked r13 and then switch back.
5627f96e84Schris * This routine provides an easy way of doing this for any mode
5727f96e84Schris *
5827f96e84Schris * r0 = CPU mode
5927f96e84Schris * r1 = stackptr
6027f96e84Schris */
6127f96e84Schris
6227f96e84SchrisENTRY(set_stackptr)
63fa81e3d7Sbriggs        mrs	r3, cpsr		/* Switch to the appropriate mode */
6427f96e84Schris	bic	r2, r3, #(PSR_MODE)
6527f96e84Schris	orr	r2, r2, r0
660d9c87e4Schris        msr	cpsr_c, r2
6727f96e84Schris
6827f96e84Schris	mov	sp, r1			/* Set the stack pointer */
6927f96e84Schris
700d9c87e4Schris        msr	cpsr_c, r3		/* Restore the old mode */
7127f96e84Schris
72*ab152917Smatt	RET				/* Exit */
73*ab152917SmattEND(set_stackptr)
7427f96e84Schris
7527f96e84Schris/* To get the stack pointer for a particular mode we must switch
7627f96e84Schris * to that mode copy the banked r13 and then switch back.
7727f96e84Schris * This routine provides an easy way of doing this for any mode
7827f96e84Schris *
7927f96e84Schris * r0 = CPU mode
8027f96e84Schris */
8127f96e84Schris
8227f96e84SchrisENTRY(get_stackptr)
83fa81e3d7Sbriggs        mrs	r3, cpsr		/* Switch to the appropriate mode */
8427f96e84Schris	bic	r2, r3, #(PSR_MODE)
8527f96e84Schris	orr	r2, r2, r0
860d9c87e4Schris        msr	cpsr_c, r2
8727f96e84Schris
88*ab152917Smatt	mov	r0, sp			/* Get the stack pointer */
8927f96e84Schris
900d9c87e4Schris        msr	cpsr_c, r3		/* Restore the old mode */
9127f96e84Schris
92*ab152917Smatt	RET				/* Exit */
93*ab152917SmattEND(get_stackptr)
9427f96e84Schris
9527f96e84Schris/* End of setstack.S */
96